From 78128033efc29b55a369b9e7b395063fd36a3d80 Mon Sep 17 00:00:00 2001 From: Andreas Neumann Date: Thu, 25 Jan 2018 22:59:33 +0100 Subject: [PATCH] Stepslider struct,initialization,draw function and graphics added --- bin/assets/images/l_arrow_button.png | Bin 0 -> 2607 bytes bin/assets/images/r_arrow_button.png | Bin 0 -> 2589 bytes settings.c | 48 ++++++++++++++++++++++----- settings.h | 13 ++++++++ 4 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 bin/assets/images/l_arrow_button.png create mode 100644 bin/assets/images/r_arrow_button.png diff --git a/bin/assets/images/l_arrow_button.png b/bin/assets/images/l_arrow_button.png new file mode 100644 index 0000000000000000000000000000000000000000..274d37f9eedee8d5faf37f5b7f16b61016aede60 GIT binary patch literal 2607 zcmbVOYgAKL7Cz^2l^ca2A)*2T7g9i$qNpfnh+G01d;y)Z6u~i6yO37K#ZV+HP`E*+ z;E0hvREh$bN(*DHU=_tzi8>=L#R3X~GLfKCKt+NONg%*%`lsW}(s51xOLftKGCRBAzXm}L$rmIS(=lR`|wfvyh;;GC?Ee>Ke$G$G3(Z1k&rSa@abs=l8$avbGjy$C&MQ`?Z7g8I{9?W4~F`1pc{bTAoNUew0 zW22N3DuQmgLnjNnGc@5{L(ZDL`Oj#Iq8YAinz9!HPtO{bF${}vz_)aQCyUyIO@Rbs zLhHO%#ELO#Emn^SXqwNWa4&L~w>DD~ZoXuh==Nk8aRH3_--^*|@Xhn69L0evpuR%a zmJ)zDytYqY0g<+NYE19?d`?&mMmoEGHBtdaYFq|J&oA4ZlU|H4Uo&8HWS_oN=^DkL(h}LzQYQ~;d1nSDT%M;lQe*&GhbUBHVJS+?p zFo^iy&V4pR2#4y_OHREZ6IXmiC*^A=4v+d%&ImDBy_;8^v0&n`uePl*KzHBDxFGg= z_|8R`+<=#PB~RlBl|P9^_JPf}q2^OLv@qlN5gwnNj_^n3NIyt^E+RLKf7=0>Y(!Lk z{|8#|@FSv`$7L4^ILk}ZeQ?vusx)XBDVL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;C$98YkmQw`b*rgMbyoSb+N^f@i~le-R+gz=rclp z9zfhH_!udd!S&jEH|ae126!yG!;qbDUG>93!At<|x~w#adI}YHikTzw0pRiugzll6 e1pYjoi@u;JMo=quh0j2=YDHMcNoi~rLjM9p4fARM literal 0 HcmV?d00001 diff --git a/bin/assets/images/r_arrow_button.png b/bin/assets/images/r_arrow_button.png new file mode 100644 index 0000000000000000000000000000000000000000..75fc981c157779ac15fd3f931125ed773dffd2a0 GIT binary patch literal 2589 zcmbtVaa2>+8Nc`DqA!-fi=iM4Fc36!bpk~zNF=WqMa~%E3^yEV%#>12@su0|353E6 zvyzGuI#*;?0g9OuBQ5DW|y&_omhM%fMfYyWJ=@&3toZ{GcW zzwiCN`};mlO-U3i3RnaH5F~9<{2TyCLI|h@A#XS)Fb`6he444Q zFT%beG21cVAEaLa(bdJ9joeOzTViCNORAPJ;8$f2gcsXVMAEP6(KLR;zp95Y)4wDxB# zP<@_e;7SM``T8}Cbu~oV!zm%?IYEBuc@OA&FlAl6_9JRcTII{^=N{wG1e3&)$by;P z(L+oeMA=3TP)~(oHhyxg#FD~-A0&|geTb=gh(>lbN276k&4a#Y z`FEaFlILOXT7SI*Q|e;H0!4i#fPX)e{}!?le5b+Fzyv{bYS(Bc{+1+i2>ogOT7*+O z|M4AlNNQQh8mjvFiv6-g>pH^QoU#m!l5;cEcA%dkyw}BjN;OIuFe=G|xQ`^58rvM& zVgj(yXz`%6N*45emG&`LglrzPa57GBs2ZkRa)?@jsKDh6C~q&w#}wx!*3zkb@kVmlDytyWt&O(^} zA`yJnb7xEl$+_%A*=(dc@NPcWumMvn_(PDx)$R`BTl<=PNs-8~@5+R?hy+f1(S-~J z3qlj{Ct+U{6JDGCWGg^P?6s|=vlq)@82oWAY2hRnuEM8UKLs$%Az~KSKlvrXRacbY zzr5&UlNxq%l}ge%K9|0!0XsLwcav{=@V1DFQg@!DXlBulZOI@?Qa2)DK*t!reo2ch z4O8NeB33SEYd%rBdv50>PW9|{yg|_Z=I1A3u3weTkdsTFm&S<{dqL+N5i@~kX5JBJ z_YfNf;7^ts!GVRFKszrZJ{Wp>SCQ4(Vi{TzEGDb$X)TVFF=S`!*C1{6C2Cp1iSy~3-P4Tc;W*vM+iTRqMSeUFlRS=Ix zhIaJTf@{L&4;av3t0n(MqNWsM7uw+0iw<`hy?;wU zsq>2+c1%Z~ckz)^J448@M|vb|824ZZN3J{3H%-+aEiEh{M%H>B!p6#oU=tDjsQew! zb#tmLVjg9;$V$cWx;?P$sS zD&lffy|yDz{(H9_4Zc{lHOg%#_g~-Z%0$GFj!fO$-Ql*AgXz~DNBG2&lKYfjz3#S? za8*>Na=AtYE)CbUnz9;*$;#!W@495>w4kyH;YcV0u;nkh880yjBGrP!mJM#OoT;Zl z3<=a+K){I#g39zfdJxCD;n~%z68!Y$*SIOy_J%(`UVyMw_fnvH|JzVEl?@F;y#hCt zx5rNVS5SnC&!4Mzt)U5(-jePJGbby(&WRt{BW|4hBvt6J!05~@X-Bj8K&Icf&eh(od zKgjLHbB?I16=suBI4)cQ^zjH=I#uuCABczR@B*gZ2;kE*J^uQAiS5S#Y~6U0*1sUbyY#>ZESE#r1k@(rNiu3* z_@9TUnM~uHyhXxZrPznb>liLHjYOLyESHRMWVByei2Y4MH$5_^>{WLXNNuy}dn{P* qODLCZPs3TXnDvjXL9evoTv(cMV(Zger}cn5NgGlWO$q8U0R9EyP03UM literal 0 HcmV?d00001 diff --git a/settings.c b/settings.c index 4fc2d10..f94da7a 100644 --- a/settings.c +++ b/settings.c @@ -22,6 +22,9 @@ SDL_Texture * Return_Button_Texture; SDL_Texture * Bar_Texture; SDL_Texture * Scalar_Button_Texture0; SDL_Texture * Scalar_Button_Texture1; +SDL_Texture * L_Arrow_Texture; +SDL_Texture * R_Arrow_Texture; + SDL_Rect Settings_rect; SDL_Rect Settings_Ball_rect; @@ -31,6 +34,7 @@ SDL_Rect Return_Button_rect; Slider BV; Slider BS; Slider BT; +Stepslider SBT; Uint32 Mousestate; @@ -38,9 +42,10 @@ bool Settings_IsInit = false; bool IsLock=false; 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); Initialize_Slider(400,500,Scalar_width,Bar_width,Slider_height,30,100,&BS,scenery->ball.TargetRect.w); Initialize_Slider(400,700,Scalar_width,Bar_width,Slider_height,0,8,&BT,scenery->ball.TextureIndex); + Initialize_Stepslider(400,300,Scalar_width,Bar_width,Slider_height,0,8,&SBT,scenery->ball.TextureIndex); Settings_Texture = IMG_LoadTexture(renderer, "assets/images/settings_title.png"); Settings_rect = (SDL_Rect){.x = 647, .y = 50, .w=626, .h=200}; @@ -56,6 +61,9 @@ void Settings_Initialize (SDL_Renderer* renderer,Scenery* scenery) { Scalar_Button_Texture0 = IMG_LoadTexture(renderer, "assets/images/scalar_button_unpressed.png"); Scalar_Button_Texture1 = IMG_LoadTexture(renderer, "assets/images/scalar_button_pressed.png"); + R_Arrow_Texture = IMG_LoadTexture(renderer, "assets/images/r_arrow_button.png" ); + L_Arrow_Texture = IMG_LoadTexture(renderer, "assets/images/l_arrow_button.png" ); + Settings_IsInit = true; } @@ -63,10 +71,13 @@ void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery) { double x; if(!(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))){ IsLock=BV.IsLock=BS.IsLock=BT.IsLock=false; + }else{ + IsLock=true; } - Draw_Slider(renderer, &BV); + // Draw_Slider(renderer, &BV); Draw_Slider(renderer, &BS); Draw_Slider(renderer, &BT); + Draw_Stepslider(renderer, &SBT); SDL_RenderCopy(renderer, Settings_Texture, NULL, &Settings_rect); SDL_RenderCopy(renderer, Return_Button_Texture, NULL, &Return_Button_rect); SDL_RenderCopy(renderer, Settings_Skins_Texture, NULL, &Settings_Skins_rect); @@ -127,6 +138,13 @@ void Draw_Slider(SDL_Renderer * renderer, Slider * beta){ } } /* Draw_Slider */ +void Draw_Stepslider(SDL_Renderer* renderer,Stepslider* beta){ + SDL_RenderCopy(renderer, Bar_Texture, NULL, &beta->Bar_rect); + SDL_RenderCopy(renderer, Scalar_Button_Texture0, NULL, &beta->Scalar_rect); + SDL_RenderCopy(renderer, L_Arrow_Texture, NULL, &beta->L_Arrow_rect); + SDL_RenderCopy(renderer, R_Arrow_Texture, NULL, &beta->R_Arrow_rect); +} + void mapping(double * x, Slider * beta){ *x = ((beta->max - beta->min) / (beta->Bar_rect.w - (beta->Scalar_rect.w))) * (beta->Slider_value - beta->Bar_rect.x - beta->Scalar_rect.w / 2) + beta->min; } @@ -139,11 +157,23 @@ void Initialize_Slider(int x, int y, int sw, int bw, int h, double min, double m beta->Slider_value = (defaultvalue-min)/(max-min)*(bw-sw/2)+x; } -void Settings_Return(){ - int 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))) - GAME_ChangeState(MainMenu); +void Initialize_Stepslider(int x,int y,int sw,int bw,int h,double min,double max,Stepslider* beta,double defaultvalue){ + beta->Scalar_rect = (SDL_Rect) {.x = (defaultvalue-min)/(max-min)*(bw-sw/2)+x, .y = y, .w = sw, .h = h }; + beta->Bar_rect = (SDL_Rect) {.x = x, .y = y, .w = bw, .h = h }; + beta->L_Arrow_rect = (SDL_Rect) {.x = x-30-h, .y = y, .w = h, .h = h }; + beta->R_Arrow_rect = (SDL_Rect) {.x = x+bw+30, .y = y, .w = h, .h = h }; + beta->max = max; + beta->min = min; + beta->Slider_value = (defaultvalue-min)/(max-min)*(bw-sw/2)+x; +} + +void Settings_Return(){ + if(!IsLock){ + int 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))) + GAME_ChangeState(MainMenu); + } } diff --git a/settings.h b/settings.h index 40c974c..c8bef88 100644 --- a/settings.h +++ b/settings.h @@ -18,15 +18,28 @@ typedef struct sliderstruct { double Slider_value,min,max; } Slider; +typedef struct stepsliderstruct { + SDL_Rect Bar_rect; + SDL_Rect Scalar_rect; + SDL_Rect L_Arrow_rect; + SDL_Rect R_Arrow_rect; + bool IsLock; + double Slider_value,min,max; +} Stepslider; + void Settings_Draw (SDL_Renderer* renderer,Scenery* scenery); void Draw_Slider(SDL_Renderer* renderer,Slider* beta); +void Draw_Stepslider(SDL_Renderer* renderer,Stepslider* beta); + void Settings_Initialize (SDL_Renderer* renderer,Scenery* scenery); void Initialize_Slider(int x,int y,int sw,int bw,int h,double min,double max,Slider* beta,double defaultvalue); +void Initialize_Stepslider(int x,int y,int sw,int bw,int h,double min,double max,Stepslider* beta,double defaultvalue); + void Settings_Deinitialize(); void mapping(double *x,Slider* beta);