@@ -31,6 +31,8 @@ int main(int argc, char* args[]) {
3131 Uint8 cursorState = 0 ; // 0 -> normal, 1 -> hover, 2 -> normal clicked, 3 -> hover clicked
3232 Cursor cursor = JsonManager::getCursor ();
3333 vector<HitBox2d> hitboxes = {HitBox2d (0 , 0 , 10 , 10 ), HitBox2d (0 , 100 , 16 , 16 )}; // Vector of all hitboxes
34+ Uint8 inHitboxes = 0 ;
35+ bool clicked = false ;
3436
3537 // Interpreter
3638 SystemBus SB;
@@ -67,14 +69,15 @@ int main(int argc, char* args[]) {
6769
6870 // Loading the textures
6971 SDL_Texture* cursorTexture = Window.loadTexture (" res/img/cursor.png" );
70- SDL_Texture* grassBlockTexture = Window.loadTexture (" res/img/grass_block.png" );
7172 SDL_Texture* fontTexture = Window.loadTexture (" res/img/font.png" );
72- vector<Entity> platforms = { Entity ( Vector2f ( 0 , 100 ), grassBlockTexture) /* ,
73- Entity(Vector2f(16, 100), grassBlockTexture),
74- Entity(Vector2f(32, 100), grassBlockTexture) */ } ;
73+ SDL_Texture* playTexture = Window. loadTexture ( " res/img/play_button.png " );
74+ SDL_Texture* nextTexture = Window. loadTexture ( " res/img/next_button.png " );
75+ SDL_Texture* pauseTexture = Window. loadTexture ( " res/img/pause_button.png " ) ;
7576 Entity cursorEntity (Vector2f (0 , 0 ), cursorTexture);
7677 TextEntity fpsCounterEntity (Vector2f (1 , 1 ), fontTexture, &font);
77- Button button1 (Vector2f (100 , 100 ), HitBox2d (100 , 100 , 8 , 8 ), grassBlockTexture);
78+ Button playButton (Vector2f (229 , 1 ), HitBox2d (229 , 1 , 7 , 7 ), playTexture);
79+ Button nextButton (Vector2f (238 , 1 ), HitBox2d (238 , 1 , 7 , 7 ), nextTexture);
80+ Button pauseButton (Vector2f (247 , 1 ), HitBox2d (247 , 1 , 7 , 7 ), pauseTexture);
7881 fpsCounter = fpsText + fpsString;
7982 fpsCounterEntity = fpsCounter;
8083 // CPU
@@ -129,6 +132,7 @@ int main(int argc, char* args[]) {
129132 }
130133 }
131134 msNext = msNow + msStep;
135+ clicked = false ;
132136 // Controls
133137 while (SDL_PollEvent (&event)) {
134138 if (event.type == SDL_QUIT) {
@@ -138,6 +142,7 @@ int main(int argc, char* args[]) {
138142 else if (event.type == SDL_MOUSEBUTTONDOWN) {
139143 if (cursorState == 0 ) cursorState = 2 ;
140144 else if (cursorState == 1 ) cursorState = 3 ;
145+ clicked = true ;
141146 }
142147 else if (event.type == SDL_MOUSEBUTTONUP) {
143148 if (cursorState == 2 ) cursorState = 0 ;
@@ -148,17 +153,28 @@ int main(int argc, char* args[]) {
148153 SDL_GetMouseState (&cursorPosition.x , &cursorPosition.y );
149154 guiCursorPosition.x = (cursorPosition.x / settings.win .scale / 4 );
150155 guiCursorPosition.y = (cursorPosition.y / settings.win .scale / 4 );
151- if (guiCursorPosition == *button1.getHitBox ()) {
152- cursorState = 1 ;
153- button1.action (randFunc);
156+ inHitboxes = 0 ;
157+ if (guiCursorPosition == *playButton.getHitBox ()) {
158+ inHitboxes++;
159+ if (clicked) playButton.action (randFunc);
160+ }
161+ if (guiCursorPosition == *nextButton.getHitBox ()) {
162+ inHitboxes++;
163+ }
164+ if (guiCursorPosition == *pauseButton.getHitBox ()) {
165+ inHitboxes++;
166+ }
167+ if (inHitboxes > 0 ) {
168+ if (cursorState == 0 ) cursorState = 1 ;
169+ else if (cursorState == 2 ) cursorState = 3 ;
170+ }
171+ else {
172+ if (cursorState == 1 ) cursorState = 0 ;
173+ else if (cursorState == 3 ) cursorState = 2 ;
154174 }
155- else if (cursorState == 1 ) cursorState = 0 ;
156175 cursorEntity.setXY (cursorPosition.x , cursorPosition.y );
157176 cursorEntity.setCurrentFrame (cursor.pointers [cursorState]);
158177 Window.clear ();
159- for (Entity& p : platforms) {
160- Window.render (p);
161- }
162178 if (settings.win .fpsCounter ) {
163179 Window.renderText (fpsCounterEntity);
164180 }
@@ -184,8 +200,10 @@ int main(int argc, char* args[]) {
184200 Window.renderText (arValue);
185201 Window.renderText (drValue);
186202 Window.renderText (spValue);
187-
188- Window.renderButton (button1);
203+ // Buttons
204+ Window.renderButton (playButton);
205+ Window.renderButton (nextButton);
206+ Window.renderButton (pauseButton);
189207 Window.renderCursor (cursorEntity);
190208 Window.display ();
191209 }
0 commit comments