Added mousePos scaling
This commit is contained in:
parent
15b0846787
commit
9982290d77
@ -3,9 +3,12 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
|
extern float XScale, YScale;
|
||||||
|
|
||||||
#define Slider_height 100
|
#define Slider_height 100
|
||||||
#define Scalar_width 20
|
#define Scalar_width 20
|
||||||
#define Bar_width 400
|
#define Bar_width 400
|
||||||
@ -82,6 +85,8 @@ 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;
|
||||||
Mousestate = SDL_GetMouseState(&x, &y);
|
Mousestate = SDL_GetMouseState(&x, &y);
|
||||||
|
x = round((float)x / XScale);
|
||||||
|
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))) {
|
||||||
SDL_RenderFillRect(renderer, &beta->Scalar_rect);
|
SDL_RenderFillRect(renderer, &beta->Scalar_rect);
|
||||||
SDL_RenderDrawRect(renderer, &beta->Scalar_rect);
|
SDL_RenderDrawRect(renderer, &beta->Scalar_rect);
|
||||||
@ -115,6 +120,8 @@ void Initialize_Slider(int x, int y, int sw, int bw, int h, double min, double m
|
|||||||
void Settings_Return(){
|
void Settings_Return(){
|
||||||
int x,y;
|
int x,y;
|
||||||
Mousestate=SDL_GetMouseState(&x,&y);
|
Mousestate=SDL_GetMouseState(&x,&y);
|
||||||
|
x = round((float)x / XScale);
|
||||||
|
y = round((float)y / YScale);
|
||||||
if((distance(x,y,237,237)<=37)&&(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT)))
|
if((distance(x,y,237,237)<=37)&&(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT)))
|
||||||
GAME_ChangeState(MainMenu);
|
GAME_ChangeState(MainMenu);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user