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-19 18:03:18 +01:00
|
|
|
#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
|
|
|
|
|
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-19 18:03:18 +01:00
|
|
|
Initialize_Slider(400,300,Scalar_width,Bar_width,Scalar_height,&BV);
|
|
|
|
Initialize_Slider(450,520,40,600,60,&BS);
|
|
|
|
Initialize_Slider(400,700,Scalar_width,Bar_width,Scalar_height,&BT);
|
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_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){
|
2018-01-19 18:03:18 +01:00
|
|
|
SDL_SetRenderDrawColor(renderer,255,255,255,255);
|
2018-01-18 22:01:09 +01:00
|
|
|
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-19 18:03:18 +01:00
|
|
|
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))){
|
2018-01-18 22:01:09 +01:00
|
|
|
SDL_RenderFillRect(renderer,&beta->Scalar_rect);
|
|
|
|
SDL_RenderDrawRect(renderer,&beta->Scalar_rect);
|
2018-01-19 18:03:18 +01:00
|
|
|
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->Slider_value=(beta->x+beta->bw-(beta->sw)/2);
|
2018-01-18 15:44:34 +01:00
|
|
|
}
|
2018-01-19 18:03:18 +01:00
|
|
|
else if(x<beta->x+(beta->sw)/2){
|
|
|
|
beta->Scalar_rect.x=beta->x;
|
|
|
|
beta->Slider_value=beta->x+(beta->sw)/2;
|
2018-01-18 16:11:43 +01:00
|
|
|
}
|
2018-01-18 15:44:34 +01:00
|
|
|
else{
|
2018-01-19 18:03:18 +01:00
|
|
|
beta->Scalar_rect.x=x-(beta->Scalar_rect.w/2);
|
|
|
|
beta->Slider_value=x;
|
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-19 18:03:18 +01:00
|
|
|
printf("%f",beta->Slider_value);
|
2018-01-18 15:59:24 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-19 18:03:18 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|