1 | /******************************************************************************************* |
2 | * |
3 | * raylib [core] example - Mouse input |
4 | * |
5 | * This example has been created using raylib 1.0 (www.raylib.com) |
6 | * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) |
7 | * |
8 | * Copyright (c) 2014 Ramon Santamaria (@raysan5) |
9 | * |
10 | ********************************************************************************************/ |
11 | |
12 | #include "raylib.h" |
13 | |
14 | int main(void) |
15 | { |
16 | // Initialization |
17 | //-------------------------------------------------------------------------------------- |
18 | const int screenWidth = 800; |
19 | const int screenHeight = 450; |
20 | |
21 | InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input" ); |
22 | |
23 | Vector2 ballPosition = { -100.0f, -100.0f }; |
24 | Color ballColor = DARKBLUE; |
25 | |
26 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
27 | //--------------------------------------------------------------------------------------- |
28 | |
29 | // Main game loop |
30 | while (!WindowShouldClose()) // Detect window close button or ESC key |
31 | { |
32 | // Update |
33 | //---------------------------------------------------------------------------------- |
34 | ballPosition = GetMousePosition(); |
35 | |
36 | if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ballColor = MAROON; |
37 | else if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) ballColor = LIME; |
38 | else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE; |
39 | //---------------------------------------------------------------------------------- |
40 | |
41 | // Draw |
42 | //---------------------------------------------------------------------------------- |
43 | BeginDrawing(); |
44 | |
45 | ClearBackground(RAYWHITE); |
46 | |
47 | DrawCircleV(ballPosition, 40, ballColor); |
48 | |
49 | DrawText("move ball with mouse and click mouse button to change color" , 10, 10, 20, DARKGRAY); |
50 | |
51 | EndDrawing(); |
52 | //---------------------------------------------------------------------------------- |
53 | } |
54 | |
55 | // De-Initialization |
56 | //-------------------------------------------------------------------------------------- |
57 | CloseWindow(); // Close window and OpenGL context |
58 | //-------------------------------------------------------------------------------------- |
59 | |
60 | return 0; |
61 | } |