Added mappING
This commit is contained in:
parent
2ac26e990c
commit
39e5b1bff9
39
settings.c
39
settings.c
@ -6,13 +6,15 @@
|
|||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
#define Slider_height 120
|
#define Slider_height 100
|
||||||
#define Scalar_width 20
|
#define Scalar_width 20
|
||||||
#define Bar_width 400
|
#define Bar_width 400
|
||||||
|
|
||||||
SDL_Texture* Setting_Texture;
|
SDL_Texture* Settings_Texture;
|
||||||
|
SDL_Texture* Settings_Ball_Texture;
|
||||||
|
|
||||||
SDL_Rect Settings_rect;
|
SDL_Rect Settings_rect;
|
||||||
|
SDL_Rect Settings_Ball_rect;
|
||||||
Slider BV;
|
Slider BV;
|
||||||
Slider BS;
|
Slider BS;
|
||||||
Slider BT;
|
Slider BT;
|
||||||
@ -20,24 +22,30 @@ Slider BT;
|
|||||||
bool Settings_IsInit=false;
|
bool Settings_IsInit=false;
|
||||||
|
|
||||||
void Settings_Initialize (SDL_Renderer* renderer) {
|
void Settings_Initialize (SDL_Renderer* renderer) {
|
||||||
Initialize_Slider(400,300,Scalar_width,Bar_width,Slider_height,&BV);
|
Initialize_Slider(400,300,Scalar_width,Bar_width,Slider_height,1,2,&BV);
|
||||||
Initialize_Slider(450,520,40,600,60,&BS);
|
Initialize_Slider(400,500,Scalar_width,Bar_width,Slider_height,1,2,&BS);
|
||||||
Initialize_Slider(400,700,Scalar_width,Bar_width,Slider_height,&BT);
|
Initialize_Slider(400,700,Scalar_width,Bar_width,Slider_height,1,2,&BT);
|
||||||
Setting_Texture = IMG_LoadTexture(renderer, "assets/images/settings_title.png");
|
Settings_Texture = IMG_LoadTexture(renderer, "assets/images/settings_title.png");
|
||||||
Settings_rect = (SDL_Rect){.x = 800, .y = 180, .w=313, .h=100};
|
Settings_rect = (SDL_Rect){.x = 800, .y = 180, .w=313, .h=100};
|
||||||
|
Settings_Ball_Texture = IMG_LoadTexture(renderer, "assets/images/ball.png");
|
||||||
|
Settings_Ball_rect = (SDL_Rect){.x = 1200, .y = 300, .w=100, .h=100};
|
||||||
Settings_IsInit = true;
|
Settings_IsInit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings_Draw (SDL_Renderer* renderer) {
|
void Settings_Draw (SDL_Renderer* renderer) {
|
||||||
SDL_RenderCopy(renderer, Setting_Texture, NULL, &Settings_rect);
|
double x;
|
||||||
|
SDL_RenderCopy(renderer, Settings_Texture, NULL, &Settings_rect);
|
||||||
|
SDL_RenderCopy(renderer, Settings_Ball_Texture, NULL, &Settings_Ball_rect);
|
||||||
Draw_Slider(renderer,&BV);
|
Draw_Slider(renderer,&BV);
|
||||||
Draw_Slider(renderer,&BS);
|
Draw_Slider(renderer,&BS);
|
||||||
Draw_Slider(renderer,&BT);
|
Draw_Slider(renderer,&BT);
|
||||||
|
mapping(&x,&BT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings_Deinitialize(){
|
void Settings_Deinitialize(){
|
||||||
if(Settings_IsInit){
|
if(Settings_IsInit){
|
||||||
SDL_DestroyTexture(Setting_Texture);
|
SDL_DestroyTexture(Settings_Texture);
|
||||||
|
SDL_DestroyTexture(Settings_Ball_Texture);
|
||||||
Settings_IsInit=false;
|
Settings_IsInit=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,11 +55,11 @@ void Draw_Slider(SDL_Renderer* renderer,Slider* beta){
|
|||||||
SDL_RenderDrawRect(renderer,&beta->Bar_rect);
|
SDL_RenderDrawRect(renderer,&beta->Bar_rect);
|
||||||
int x,y;
|
int x,y;
|
||||||
Uint32 Mousestate=SDL_GetMouseState(&x,&y);
|
Uint32 Mousestate=SDL_GetMouseState(&x,&y);
|
||||||
if(y<=((beta->Scalar_rect.y)+(beta->h))&&y>=(beta->Scalar_rect.y)&&x<=(beta->bw+beta->x)&&x>=(beta->x)&&(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))){
|
if(y<=((beta->y)+(beta->h))&&y>=(beta->y)&&x<=(beta->bw+beta->x)&&x>=(beta->x)&&(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))){
|
||||||
SDL_RenderFillRect(renderer,&beta->Scalar_rect);
|
SDL_RenderFillRect(renderer,&beta->Scalar_rect);
|
||||||
SDL_RenderDrawRect(renderer,&beta->Scalar_rect);
|
SDL_RenderDrawRect(renderer,&beta->Scalar_rect);
|
||||||
if(x>(beta->x+beta->bw-(beta->sw)/2)){
|
if(x>(beta->x+beta->bw-(beta->sw)/2)){
|
||||||
beta->Scalar_rect.x=(beta->x+beta->bw-(beta->sw)/2)-(beta->Scalar_rect.w)/2;
|
beta->Scalar_rect.x=(beta->x+beta->bw-(beta->sw));
|
||||||
beta->Slider_value=(beta->x+beta->bw-(beta->sw)/2);
|
beta->Slider_value=(beta->x+beta->bw-(beta->sw)/2);
|
||||||
}
|
}
|
||||||
else if(x<beta->x+(beta->sw)/2){
|
else if(x<beta->x+(beta->sw)/2){
|
||||||
@ -59,7 +67,7 @@ void Draw_Slider(SDL_Renderer* renderer,Slider* beta){
|
|||||||
beta->Slider_value=beta->x+(beta->sw)/2;
|
beta->Slider_value=beta->x+(beta->sw)/2;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
beta->Scalar_rect.x=x-(beta->Scalar_rect.w/2);
|
beta->Scalar_rect.x=x-(beta->sw/2);
|
||||||
beta->Slider_value=x;
|
beta->Slider_value=x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,11 +76,11 @@ void Draw_Slider(SDL_Renderer* renderer,Slider* beta){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mapping(int *px,int *py,Slider* beta){
|
void mapping(double *x,Slider* beta){
|
||||||
|
*x=((beta->max-beta->min)/(beta->bw-(beta->sw)))*(beta->Slider_value-beta->x-beta->sw/2)+beta->min;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Initialize_Slider(int x,int y,int sw,int bw,int h,Slider* beta){
|
void Initialize_Slider(int x,int y,int sw,int bw,int h,double min,double max,Slider* beta){
|
||||||
beta->Scalar_rect = (SDL_Rect){.x=x,.y=y,.w=sw,.h=h};
|
beta->Scalar_rect = (SDL_Rect){.x=x,.y=y,.w=sw,.h=h};
|
||||||
beta->Bar_rect = (SDL_Rect){.x=x,.y=y,.w=bw,.h=h};
|
beta->Bar_rect = (SDL_Rect){.x=x,.y=y,.w=bw,.h=h};
|
||||||
beta->x=x;
|
beta->x=x;
|
||||||
@ -80,4 +88,7 @@ void Initialize_Slider(int x,int y,int sw,int bw,int h,Slider* beta){
|
|||||||
beta->sw=sw;
|
beta->sw=sw;
|
||||||
beta->bw=bw;
|
beta->bw=bw;
|
||||||
beta->h=h;
|
beta->h=h;
|
||||||
|
beta->max=max;
|
||||||
|
beta->min=min;
|
||||||
|
beta->Slider_value=x+sw/2;
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@ void Settings_Deinitialize();
|
|||||||
|
|
||||||
void Draw_Slider(SDL_Renderer* renderer,Slider* beta);
|
void Draw_Slider(SDL_Renderer* renderer,Slider* beta);
|
||||||
|
|
||||||
void mapping(int *px,int *py,Slider* beta);
|
void mapping(double *x,Slider* beta);
|
||||||
|
|
||||||
void Initialize_Slider(int x,int y,int sw,int bw,int h,Slider* beta);
|
void Initialize_Slider(int x,int y,int sw,int bw,int h,double min,double max,Slider* beta);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user