Selaa lähdekoodia

Mouse support for menu

Thomas Buck 10 vuotta sitten
vanhempi
commit
355253f9b0
6 muutettua tiedostoa jossa 63 lisäystä ja 4 poistoa
  1. 3
    0
      include/Menu.h
  2. 2
    0
      include/OpenRaider.h
  3. 6
    0
      include/Window.h
  4. 38
    3
      src/Menu.cpp
  5. 6
    0
      src/OpenRaider.cpp
  6. 8
    1
      src/WindowSDL.cpp

+ 3
- 0
include/Menu.h Näytä tiedosto

34
 
34
 
35
     void handleKeyboard(KeyboardButton key, bool pressed);
35
     void handleKeyboard(KeyboardButton key, bool pressed);
36
 
36
 
37
+    void handleMouseClick(unsigned int x, unsigned int y, MouseButton button, bool released);
38
+
37
 private:
39
 private:
38
 
40
 
39
     void displayMapList();
41
     void displayMapList();
42
 
44
 
43
     bool mVisible;
45
     bool mVisible;
44
     unsigned int mCursor;
46
     unsigned int mCursor;
47
+    unsigned int mMin;
45
 
48
 
46
     WindowString mainText;
49
     WindowString mainText;
47
     WindowString tempText;
50
     WindowString tempText;

+ 2
- 0
include/OpenRaider.h Näytä tiedosto

71
 
71
 
72
     void handleText(char *text, bool notFinished);
72
     void handleText(char *text, bool notFinished);
73
 
73
 
74
+    void handleMouseClick(unsigned int x, unsigned int y, MouseButton button, bool released);
75
+
74
     Window *mWindow;
76
     Window *mWindow;
75
     Sound *mSound;
77
     Sound *mSound;
76
     Menu *mMenu;
78
     Menu *mMenu;

+ 6
- 0
include/Window.h Näytä tiedosto

40
     semicolon, slash, space, tab, unknown
40
     semicolon, slash, space, tab, unknown
41
 } KeyboardButton;
41
 } KeyboardButton;
42
 
42
 
43
+typedef enum {
44
+    leftButton,
45
+    rightButton,
46
+    middleButton
47
+} MouseButton;
48
+
43
 typedef struct {
49
 typedef struct {
44
     char *text;
50
     char *text;
45
     unsigned int x;
51
     unsigned int x;

+ 38
- 3
src/Menu.cpp Näytä tiedosto

23
 Menu::Menu() {
23
 Menu::Menu() {
24
     mVisible = false;
24
     mVisible = false;
25
     mCursor = 0;
25
     mCursor = 0;
26
+    mMin = 0;
26
 
27
 
27
     mainText.text = bufferString(VERSION);
28
     mainText.text = bufferString(VERSION);
28
     mainText.color[0] = 0xFF;
29
     mainText.color[0] = 0xFF;
89
     while ((max - min) < items) {
90
     while ((max - min) < items) {
90
         if (min > 0)
91
         if (min > 0)
91
             min--;
92
             min--;
92
-        else if (max < (gOpenRaider->mMapList.size()))
93
+        else if (max < ((int)gOpenRaider->mMapList.size()))
93
             max++;
94
             max++;
94
         else
95
         else
95
             break;
96
             break;
96
     }
97
     }
97
 
98
 
99
+    mMin = min;
100
+
98
     for (int i = 0; i < (max - min); i++) {
101
     for (int i = 0; i < (max - min); i++) {
99
         char *map = gOpenRaider->mMapList[i + min];
102
         char *map = gOpenRaider->mMapList[i + min];
100
-        if ((i + min) == mCursor) {
103
+        if ((i + min) == (int)mCursor) {
101
             // Less greem & red --> highlight in red
104
             // Less greem & red --> highlight in red
102
             tempText.color[1] = 0x42;
105
             tempText.color[1] = 0x42;
103
             tempText.color[2] = 0x42;
106
             tempText.color[2] = 0x42;
126
         if (!gOpenRaider->mMapListFilled) {
129
         if (!gOpenRaider->mMapListFilled) {
127
             drawText(25, (window->mHeight / 2) - 20, 0.75f, "Generating map list...");
130
             drawText(25, (window->mHeight / 2) - 20, 0.75f, "Generating map list...");
128
         } else {
131
         } else {
129
-            displayMapList();
132
+            if (gOpenRaider->mMapList.size() == 0) {
133
+                drawText(25, (window->mHeight / 2) - 20, 0.75f, "No maps found! See README.md");
134
+            } else {
135
+                // draw *play button* above list
136
+                glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
137
+                glDisable(GL_TEXTURE_2D);
138
+                glRecti(25, 25, 100, 75);
139
+                glEnable(GL_TEXTURE_2D);
140
+                tempText.color[0] = 0x00;
141
+                tempText.color[1] = 0x00;
142
+                tempText.color[2] = 0x00;
143
+                drawText(40, 35, 0.75f, "Play");
144
+                tempText.color[0] = 0xFF;
145
+                tempText.color[1] = 0xFF;
146
+                tempText.color[2] = 0xFF;
147
+
148
+                displayMapList();
149
+            }
130
         }
150
         }
131
     }
151
     }
132
 }
152
 }
162
     }
182
     }
163
 }
183
 }
164
 
184
 
185
+void Menu::handleMouseClick(unsigned int x, unsigned int y, MouseButton button, bool released) {
186
+    int items = (gOpenRaider->mWindow->mHeight - 110) / 25;
187
+
188
+    if ((!released) || (button != leftButton))
189
+        return;
190
+
191
+    if ((y >= 100) && (y <= (100 + (25 * items)))) {
192
+        y -= 100;
193
+        mCursor = mMin + (y / 25);
194
+    } else if ((y >= 25) && (y <= 100) && (x >= 25) && (x <= 125)) {
195
+        // Play button
196
+        mCursor = 0;
197
+    }
198
+}
199
+

+ 6
- 0
src/OpenRaider.cpp Näytä tiedosto

578
 
578
 
579
 }
579
 }
580
 
580
 
581
+void OpenRaider::handleMouseClick(unsigned int x, unsigned int y, MouseButton button, bool released) {
582
+    if (mMenu->isVisible()) {
583
+        mMenu->handleMouseClick(x, y, button, released);
584
+    }
585
+}
586
+

+ 8
- 1
src/WindowSDL.cpp Näytä tiedosto

175
 
175
 
176
             case SDL_MOUSEBUTTONDOWN:
176
             case SDL_MOUSEBUTTONDOWN:
177
             case SDL_MOUSEBUTTONUP:
177
             case SDL_MOUSEBUTTONUP:
178
-
178
+                MouseButton button;
179
+                if (event.button.button == SDL_BUTTON_LEFT)
180
+                    button = leftButton;
181
+                else if (event.button.button == SDL_BUTTON_RIGHT)
182
+                    button = rightButton;
183
+                else
184
+                    button = middleButton;
185
+                gOpenRaider->handleMouseClick(event.button.x, event.button.y, button, (event.type == SDL_MOUSEBUTTONUP));
179
                 break;
186
                 break;
180
 
187
 
181
             case SDL_TEXTINPUT:
188
             case SDL_TEXTINPUT:

Loading…
Peruuta
Tallenna