summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2020-12-18 18:36:04 +0100
committerRay <[email protected]>2020-12-18 18:36:04 +0100
commit893a64712e6702ac14d2001c064b56da0538b1ce (patch)
tree7edb1c8150d9a410363ac202a8fb19ef6708d16c
parent0987507ef581a423aa304ed0d816cddbb7795fcd (diff)
downloadraylib-893a64712e6702ac14d2001c064b56da0538b1ce.tar.gz
raylib-893a64712e6702ac14d2001c064b56da0538b1ce.zip
Support mouse input on example #1465
-rw-r--r--examples/textures/textures_image_processing.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/examples/textures/textures_image_processing.c b/examples/textures/textures_image_processing.c
index 14442290..46d8354d 100644
--- a/examples/textures/textures_image_processing.c
+++ b/examples/textures/textures_image_processing.c
@@ -57,9 +57,10 @@ int main(void)
int currentProcess = NONE;
bool textureReload = false;
- Rectangle selectRecs[NUM_PROCESSES] = { 0 };
+ Rectangle toggleRecs[NUM_PROCESSES] = { 0 };
+ int mouseHoverRec = -1;
- for (int i = 0; i < NUM_PROCESSES; i++) selectRecs[i] = (Rectangle){ 40.0f, (float)(50 + 32*i), 150.0f, 30.0f };
+ for (int i = 0; i < NUM_PROCESSES; i++) toggleRecs[i] = (Rectangle){ 40.0f, (float)(50 + 32*i), 150.0f, 30.0f };
SetTargetFPS(60);
//---------------------------------------------------------------------------------------
@@ -69,6 +70,25 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
+
+ // Mouse toggle group logic
+ for (int i = 0; i < NUM_PROCESSES; i++)
+ {
+ if (CheckCollisionPointRec(GetMousePosition(), toggleRecs[i]))
+ {
+ mouseHoverRec = i;
+
+ if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
+ {
+ currentProcess = i;
+ textureReload = true;
+ }
+ break;
+ }
+ else mouseHoverRec = -1;
+ }
+
+ // Keyboard toggle group logic
if (IsKeyPressed(KEY_DOWN))
{
currentProcess++;
@@ -82,6 +102,7 @@ int main(void)
textureReload = true;
}
+ // Reload texture when required
if (textureReload)
{
UnloadImage(image); // Unload current image data
@@ -121,9 +142,9 @@ int main(void)
// Draw rectangles
for (int i = 0; i < NUM_PROCESSES; i++)
{
- DrawRectangleRec(selectRecs[i], (i == currentProcess) ? SKYBLUE : LIGHTGRAY);
- DrawRectangleLines((int)selectRecs[i].x, (int) selectRecs[i].y, (int) selectRecs[i].width, (int) selectRecs[i].height, (i == currentProcess) ? BLUE : GRAY);
- DrawText( processText[i], (int)( selectRecs[i].x + selectRecs[i].width/2 - MeasureText(processText[i], 10)/2), (int) selectRecs[i].y + 11, 10, (i == currentProcess) ? DARKBLUE : DARKGRAY);
+ DrawRectangleRec(toggleRecs[i], ((i == currentProcess) || (i == mouseHoverRec)) ? SKYBLUE : LIGHTGRAY);
+ DrawRectangleLines((int)toggleRecs[i].x, (int) toggleRecs[i].y, (int) toggleRecs[i].width, (int) toggleRecs[i].height, ((i == currentProcess) || (i == mouseHoverRec)) ? BLUE : GRAY);
+ DrawText( processText[i], (int)( toggleRecs[i].x + toggleRecs[i].width/2 - MeasureText(processText[i], 10)/2), (int) toggleRecs[i].y + 11, 10, ((i == currentProcess) || (i == mouseHoverRec)) ? DARKBLUE : DARKGRAY);
}
DrawTexture(texture, screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, WHITE);