Amazing Slider Upgrade

This commit is contained in:
Andreas Neumann 2018-01-25 21:45:48 +01:00
parent 9982290d77
commit bb156995cd
5 changed files with 34 additions and 9 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -19,6 +19,9 @@ SDL_Texture * Settings_Texture;
SDL_Texture * Settings_Ball_Texture; SDL_Texture * Settings_Ball_Texture;
SDL_Texture * Settings_Skins_Texture; SDL_Texture * Settings_Skins_Texture;
SDL_Texture * Return_Button_Texture; SDL_Texture * Return_Button_Texture;
SDL_Texture * Bar_Texture;
SDL_Texture * Scalar_Button_Texture0;
SDL_Texture * Scalar_Button_Texture1;
SDL_Rect Settings_rect; SDL_Rect Settings_rect;
SDL_Rect Settings_Ball_rect; SDL_Rect Settings_Ball_rect;
@ -32,6 +35,7 @@ Slider BT;
Uint32 Mousestate; Uint32 Mousestate;
bool Settings_IsInit = false; bool Settings_IsInit = false;
bool IsLock=false;
void Settings_Initialize (SDL_Renderer* renderer,Scenery* scenery) { void Settings_Initialize (SDL_Renderer* renderer,Scenery* scenery) {
Initialize_Slider(400,300,Scalar_width,Bar_width,Slider_height,1,2,&BV,1.5); Initialize_Slider(400,300,Scalar_width,Bar_width,Slider_height,1,2,&BV,1.5);
@ -48,21 +52,27 @@ void Settings_Initialize (SDL_Renderer* renderer,Scenery* scenery) {
Return_Button_Texture = IMG_LoadTexture(renderer, "assets/images/return_button.png"); Return_Button_Texture = IMG_LoadTexture(renderer, "assets/images/return_button.png");
Return_Button_rect = (SDL_Rect){.x = 200, .y = 200, .w=75, .h=75}; Return_Button_rect = (SDL_Rect){.x = 200, .y = 200, .w=75, .h=75};
Bar_Texture = IMG_LoadTexture(renderer, "assets/images/bar_texture.png");
Scalar_Button_Texture0 = IMG_LoadTexture(renderer, "assets/images/scalar_button_unpressed.png");
Scalar_Button_Texture1 = IMG_LoadTexture(renderer, "assets/images/scalar_button_pressed.png");
Settings_IsInit = true; Settings_IsInit = true;
} }
void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery) { void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery) {
double x; double x;
if(!(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))){
IsLock=BV.IsLock=BS.IsLock=BT.IsLock=false;
}
Draw_Slider(renderer, &BV);
Draw_Slider(renderer, &BS);
Draw_Slider(renderer, &BT);
SDL_RenderCopy(renderer, Settings_Texture, NULL, &Settings_rect); SDL_RenderCopy(renderer, Settings_Texture, NULL, &Settings_rect);
SDL_RenderCopy(renderer, Return_Button_Texture, NULL, &Return_Button_rect); SDL_RenderCopy(renderer, Return_Button_Texture, NULL, &Return_Button_rect);
SDL_RenderCopy(renderer, Settings_Skins_Texture, NULL, &Settings_Skins_rect); SDL_RenderCopy(renderer, Settings_Skins_Texture, NULL, &Settings_Skins_rect);
BALL_DrawTexture(renderer, &Settings_Ball_rect, scenery->ball.TextureIndex); BALL_DrawTexture(renderer, &Settings_Ball_rect, scenery->ball.TextureIndex);
Settings_Return(); Settings_Return();
Draw_Slider(renderer, &BV);
Draw_Slider(renderer, &BS);
Draw_Slider(renderer, &BT);
mapping(&x, &BS); mapping(&x, &BS);
scenery->ball.TargetRect.w = x; scenery->ball.TargetRect.w = x;
scenery->ball.TargetRect.h = x; scenery->ball.TargetRect.h = x;
@ -76,20 +86,29 @@ void Settings_Deinitialize(){
if (Settings_IsInit) { if (Settings_IsInit) {
SDL_DestroyTexture(Settings_Texture); SDL_DestroyTexture(Settings_Texture);
SDL_DestroyTexture(Settings_Ball_Texture); SDL_DestroyTexture(Settings_Ball_Texture);
SDL_DestroyTexture(Bar_Texture);
SDL_DestroyTexture(Return_Button_Texture);
SDL_DestroyTexture(Settings_Skins_Texture);
Settings_IsInit = false; Settings_IsInit = false;
} }
} }
void Draw_Slider(SDL_Renderer * renderer, Slider * beta){ void Draw_Slider(SDL_Renderer * renderer, Slider * beta){
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderDrawRect(renderer, &beta->Bar_rect); SDL_RenderCopy(renderer, Bar_Texture, NULL, &beta->Bar_rect);
int x, y; int x, y;
Mousestate = SDL_GetMouseState(&x, &y); Mousestate = SDL_GetMouseState(&x, &y);
x = round((float)x / XScale); x = round((float)x / XScale);
y = round((float)y / YScale); y = round((float)y / YScale);
if (y <= ((beta->Bar_rect.y) + (beta->Bar_rect.h)) && y >= (beta->Bar_rect.y) && x <= (beta->Bar_rect.w + beta->Bar_rect.x) && x >= (beta->Bar_rect.x) && (Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))) { if ((y <= ((beta->Bar_rect.y) + (beta->Bar_rect.h)) && y >= (beta->Bar_rect.y) && x <= (beta->Bar_rect.w + beta->Bar_rect.x) && x >= (beta->Bar_rect.x) && (Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT)))||beta->IsLock) {
SDL_RenderFillRect(renderer, &beta->Scalar_rect); if(!IsLock){
SDL_RenderDrawRect(renderer, &beta->Scalar_rect); beta->IsLock=true;
IsLock=true;
}
if(beta->IsLock){
// SDL_RenderFillRect(renderer, &beta->Scalar_rect);
// SDL_RenderDrawRect(renderer, &beta->Scalar_rect);
SDL_RenderCopy(renderer, Scalar_Button_Texture1, NULL, &beta->Scalar_rect);
if (x > (beta->Bar_rect.x + beta->Bar_rect.w - (beta->Scalar_rect.w) / 2)) { if (x > (beta->Bar_rect.x + beta->Bar_rect.w - (beta->Scalar_rect.w) / 2)) {
beta->Scalar_rect.x = (beta->Bar_rect.x + beta->Bar_rect.w - (beta->Scalar_rect.w)); beta->Scalar_rect.x = (beta->Bar_rect.x + beta->Bar_rect.w - (beta->Scalar_rect.w));
beta->Slider_value = (beta->Bar_rect.x + beta->Bar_rect.w - (beta->Scalar_rect.w) / 2); beta->Slider_value = (beta->Bar_rect.x + beta->Bar_rect.w - (beta->Scalar_rect.w) / 2);
@ -100,8 +119,13 @@ void Draw_Slider(SDL_Renderer * renderer, Slider * beta){
beta->Scalar_rect.x = x - (beta->Scalar_rect.w / 2); beta->Scalar_rect.x = x - (beta->Scalar_rect.w / 2);
beta->Slider_value = x; beta->Slider_value = x;
} }
} else {
// SDL_RenderDrawRect(renderer, &beta->Scalar_rect);
SDL_RenderCopy(renderer, Scalar_Button_Texture0, NULL, &beta->Scalar_rect);
}
} else { } else {
SDL_RenderDrawRect(renderer, &beta->Scalar_rect); // SDL_RenderDrawRect(renderer, &beta->Scalar_rect);
SDL_RenderCopy(renderer, Scalar_Button_Texture0, NULL, &beta->Scalar_rect);
} }
} /* Draw_Slider */ } /* Draw_Slider */

View File

@ -14,6 +14,7 @@
typedef struct sliderstruct { typedef struct sliderstruct {
SDL_Rect Bar_rect; SDL_Rect Bar_rect;
SDL_Rect Scalar_rect; SDL_Rect Scalar_rect;
bool IsLock;
double Slider_value,min,max; double Slider_value,min,max;
} Slider; } Slider;