breakout/settings.c

67 lines
1.9 KiB
C
Raw Normal View History

2018-01-18 15:44:34 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
2018-01-18 15:59:24 +01:00
#include <stdbool.h>
2018-01-18 15:44:34 +01:00
2018-01-18 22:01:09 +01:00
#include "settings.h"
2018-01-18 15:44:34 +01:00
SDL_Texture* Setting_Texture;
SDL_Rect Settings_rect;
2018-01-18 22:01:09 +01:00
Slider BV;
Slider BS;
Slider BT;
2018-01-18 15:44:34 +01:00
2018-01-18 15:59:24 +01:00
bool Settings_IsInit=false;
2018-01-18 15:44:34 +01:00
void Settings_Initialize (SDL_Renderer* renderer) {
2018-01-18 22:01:09 +01:00
BV.Scalar_rect = (SDL_Rect){.y=300,.x=590,.w=20,.h=100};
BS.Scalar_rect = (SDL_Rect){.y=500,.x=590,.w=20,.h=100};
BT.Scalar_rect = (SDL_Rect){.y=700,.x=590,.w=20,.h=100};
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};
2018-01-18 15:44:34 +01:00
Setting_Texture = IMG_LoadTexture(renderer, "assets/images/settings_title.png");
Settings_rect = (SDL_Rect){.x = 800, .y = 180, .w=313, .h=100};
2018-01-18 15:59:24 +01:00
Settings_IsInit = true;
2018-01-18 15:44:34 +01:00
}
void Settings_Draw (SDL_Renderer* renderer) {
SDL_SetRenderDrawColor(renderer,255,255,255,255);
SDL_RenderCopy(renderer, Setting_Texture, NULL, &Settings_rect);
2018-01-18 22:01:09 +01:00
Draw_Slider(renderer,&BV);
Draw_Slider(renderer,&BS);
Draw_Slider(renderer,&BT);
}
void Settings_Deinitialize(){
if(Settings_IsInit){
SDL_DestroyTexture(Setting_Texture);
Settings_IsInit=false;
}
}
void Draw_Slider(SDL_Renderer* renderer,Slider* beta){
SDL_RenderDrawRect(renderer,&beta->Bar_rect);
2018-01-18 15:44:34 +01:00
int x,y;
Uint32 Mousestate=SDL_GetMouseState(&x,&y);
2018-01-18 22:01:09 +01:00
SDL_SetRenderDrawColor(renderer,255,255,255,255);
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_RenderDrawRect(renderer,&beta->Scalar_rect);
2018-01-18 16:11:43 +01:00
if(x>790){
2018-01-18 22:01:09 +01:00
beta->Scalar_rect.x=780;
2018-01-18 15:44:34 +01:00
}
2018-01-18 16:11:43 +01:00
else if(x<410){
2018-01-18 22:01:09 +01:00
beta->Scalar_rect.x=400;
2018-01-18 16:11:43 +01:00
}
2018-01-18 15:44:34 +01:00
else{
2018-01-18 22:01:09 +01:00
beta->Scalar_rect.x=x-10;
2018-01-18 15:44:34 +01:00
}
}
else{
2018-01-18 22:01:09 +01:00
SDL_RenderDrawRect(renderer,&beta->Scalar_rect);
2018-01-18 15:59:24 +01:00
}
}