ソースを参照

Mouse support for menu

Thomas Buck 10年前
コミット
355253f9b0
6個のファイルの変更63行の追加4行の削除
  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 ファイルの表示

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

+ 2
- 0
include/OpenRaider.h ファイルの表示

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

+ 6
- 0
include/Window.h ファイルの表示

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

+ 38
- 3
src/Menu.cpp ファイルの表示

@@ -23,6 +23,7 @@
23 23
 Menu::Menu() {
24 24
     mVisible = false;
25 25
     mCursor = 0;
26
+    mMin = 0;
26 27
 
27 28
     mainText.text = bufferString(VERSION);
28 29
     mainText.color[0] = 0xFF;
@@ -89,15 +90,17 @@ void Menu::displayMapList() {
89 90
     while ((max - min) < items) {
90 91
         if (min > 0)
91 92
             min--;
92
-        else if (max < (gOpenRaider->mMapList.size()))
93
+        else if (max < ((int)gOpenRaider->mMapList.size()))
93 94
             max++;
94 95
         else
95 96
             break;
96 97
     }
97 98
 
99
+    mMin = min;
100
+
98 101
     for (int i = 0; i < (max - min); i++) {
99 102
         char *map = gOpenRaider->mMapList[i + min];
100
-        if ((i + min) == mCursor) {
103
+        if ((i + min) == (int)mCursor) {
101 104
             // Less greem & red --> highlight in red
102 105
             tempText.color[1] = 0x42;
103 106
             tempText.color[2] = 0x42;
@@ -126,7 +129,24 @@ void Menu::display() {
126 129
         if (!gOpenRaider->mMapListFilled) {
127 130
             drawText(25, (window->mHeight / 2) - 20, 0.75f, "Generating map list...");
128 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,3 +182,18 @@ void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
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 ファイルの表示

@@ -578,3 +578,9 @@ void OpenRaider::handleText(char *text, bool notFinished) {
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 ファイルの表示

@@ -175,7 +175,14 @@ void WindowSDL::eventHandling() {
175 175
 
176 176
             case SDL_MOUSEBUTTONDOWN:
177 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 186
                 break;
180 187
 
181 188
             case SDL_TEXTINPUT:

読み込み中…
キャンセル
保存