Added slider individualization

This commit is contained in:
Andreas Neumann 2018-01-19 18:03:18 +01:00
parent 725ed1a7a2
commit a9119f4856
2 changed files with 41 additions and 14 deletions

View File

@ -6,6 +6,14 @@
#include "settings.h" #include "settings.h"
#define Slider_min 410
#define Slider_max 790
#define Slider_height 120
#define Scalar_width 20
#define Scalar_height Slider_height
#define Bar_width 400
#define Bar_height Slider_height
SDL_Texture* Setting_Texture; SDL_Texture* Setting_Texture;
SDL_Rect Settings_rect; SDL_Rect Settings_rect;
@ -16,19 +24,15 @@ Slider BT;
bool Settings_IsInit=false; bool Settings_IsInit=false;
void Settings_Initialize (SDL_Renderer* renderer) { void Settings_Initialize (SDL_Renderer* renderer) {
BV.Scalar_rect = (SDL_Rect){.y=300,.x=590,.w=20,.h=100}; Initialize_Slider(400,300,Scalar_width,Bar_width,Scalar_height,&BV);
BS.Scalar_rect = (SDL_Rect){.y=500,.x=590,.w=20,.h=100}; Initialize_Slider(450,520,40,600,60,&BS);
BT.Scalar_rect = (SDL_Rect){.y=700,.x=590,.w=20,.h=100}; Initialize_Slider(400,700,Scalar_width,Bar_width,Scalar_height,&BT);
BV.Bar_rect = (SDL_Rect){.y = 300,.x = 400 , .w=400, .h=100};
BS.Bar_rect = (SDL_Rect){.y = 500,.x = 400, .w=400, .h=100};
BT.Bar_rect = (SDL_Rect){.y = 700,.x = 400, .w=400, .h=100};
Setting_Texture = IMG_LoadTexture(renderer, "assets/images/settings_title.png"); Setting_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_IsInit = true; Settings_IsInit = true;
} }
void Settings_Draw (SDL_Renderer* renderer) { void Settings_Draw (SDL_Renderer* renderer) {
SDL_SetRenderDrawColor(renderer,255,255,255,255);
SDL_RenderCopy(renderer, Setting_Texture, NULL, &Settings_rect); SDL_RenderCopy(renderer, Setting_Texture, NULL, &Settings_rect);
Draw_Slider(renderer,&BV); Draw_Slider(renderer,&BV);
Draw_Slider(renderer,&BS); Draw_Slider(renderer,&BS);
@ -43,24 +47,42 @@ void Settings_Deinitialize(){
} }
void Draw_Slider(SDL_Renderer* renderer,Slider* beta){ void Draw_Slider(SDL_Renderer* renderer,Slider* beta){
SDL_SetRenderDrawColor(renderer,255,255,255,255);
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);
SDL_SetRenderDrawColor(renderer,255,255,255,255); 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->Scalar_rect.y)+100)&&y>=(beta->Scalar_rect.y)&&x<=800&&x>=400&&(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>790){ if(x>(beta->x+beta->bw-(beta->sw)/2)){
beta->Scalar_rect.x=780; beta->Scalar_rect.x=(beta->x+beta->bw-(beta->sw)/2)-(beta->Scalar_rect.w)/2;
beta->Slider_value=(beta->x+beta->bw-(beta->sw)/2);
} }
else if(x<410){ else if(x<beta->x+(beta->sw)/2){
beta->Scalar_rect.x=400; beta->Scalar_rect.x=beta->x;
beta->Slider_value=beta->x+(beta->sw)/2;
} }
else{ else{
beta->Scalar_rect.x=x-10; beta->Scalar_rect.x=x-(beta->Scalar_rect.w/2);
beta->Slider_value=x;
} }
} }
else{ else{
SDL_RenderDrawRect(renderer,&beta->Scalar_rect); SDL_RenderDrawRect(renderer,&beta->Scalar_rect);
printf("%f",beta->Slider_value);
} }
} }
void mapping(int *px,int *py,Slider* beta){
}
void Initialize_Slider(int x,int y,int sw,int bw,int h,Slider* beta){
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->x=x;
beta->y=y;
beta->sw=sw;
beta->bw=bw;
beta->h=h;
}

View File

@ -11,6 +11,7 @@
typedef struct sliderstruct { typedef struct sliderstruct {
SDL_Rect Bar_rect; SDL_Rect Bar_rect;
SDL_Rect Scalar_rect; SDL_Rect Scalar_rect;
int x,y,bw,sw,h;
double Slider_value,min,max; double Slider_value,min,max;
} Slider; } Slider;
@ -22,4 +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 Initialize_Slider(int x,int y,int sw,int bw,int h,Slider* beta);
#endif #endif