Procházet zdrojové kódy

Split Menu into interface and MenuFolder

Thomas Buck před 9 roky
rodič
revize
b86e65bd4e
7 změnil soubory, kde provedl 323 přidání a 244 odebrání
  1. 2
    0
      ChangeLog.md
  2. 23
    33
      include/Menu.h
  3. 56
    0
      include/MenuFolder.h
  4. 1
    0
      src/CMakeLists.txt
  5. 36
    209
      src/Menu.cpp
  6. 203
    0
      src/MenuFolder.cpp
  7. 2
    2
      src/main.cpp

+ 2
- 0
ChangeLog.md Zobrazit soubor

@@ -5,6 +5,8 @@
5 5
     [ 20140811 ]
6 6
     * New Font API, allows drawing strings with line-wrapping
7 7
     * Added ability to Menu to show info dialogs
8
+    * Split Menu into interface and implementations, like Sound/Window/Font
9
+    * Menu now interface and dialog code, MenuFolder is file browser
8 10
 
9 11
     [ 20140810 ]
10 12
     * Removed recursive Folder access method implementations

+ 23
- 33
include/Menu.h Zobrazit soubor

@@ -1,6 +1,6 @@
1 1
 /*!
2 2
  * \file include/Menu.h
3
- * \brief Menu 'overlay'
3
+ * \brief Menu 'overlay' interface
4 4
  *
5 5
  * \author xythobuz
6 6
  */
@@ -9,9 +9,6 @@
9 9
 #define _MENU_H_
10 10
 
11 11
 #include <functional>
12
-#include <memory>
13
-
14
-#include "utils/Folder.h"
15 12
 
16 13
 /*!
17 14
  * \brief Menu 'overlay'
@@ -19,54 +16,47 @@
19 16
 class Menu {
20 17
 public:
21 18
 
22
-    /*!
23
-     * \brief Constructs an object of Menu
24
-     */
25
-    Menu();
26
-
27
-    /*!
28
-     * \brief Deconstructs an object of Menu
29
-     */
30
-    ~Menu();
19
+    virtual ~Menu() { }
31 20
 
32
-    int initialize();
33
-    int initialize(std::string folder);
34
-    int initialize(Folder *folder);
21
+    virtual void setVisible(bool visible);
35 22
 
36
-    void setVisible(bool visible);
23
+    virtual bool isVisible();
37 24
 
38
-    bool isVisible();
25
+    virtual int initialize() = 0;
39 26
 
40
-    void display();
27
+    virtual void display() = 0;
41 28
 
42
-    void handleKeyboard(KeyboardButton key, bool pressed);
29
+    virtual void handleKeyboard(KeyboardButton key, bool pressed) = 0;
43 30
 
44
-    void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
31
+    virtual void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) = 0;
45 32
 
46
-    void handleMouseScroll(int xrel, int yrel);
33
+    virtual void handleMouseScroll(int xrel, int yrel) = 0;
47 34
 
48
-private:
35
+protected:
49 36
 
50
-    void loadOrOpen();
51
-    void showDialog(std::string msg, std::string btn1, std::string btn2,
37
+    virtual void showDialog(std::string msg, std::string btn1, std::string btn2,
52 38
             std::function<int (bool state)> callback = std::function<int (bool)>());
53
-    void ackDialog();
54
-    void displayDialog();
55 39
 
56
-    bool mVisible;
57
-    long mCursor;
58
-    long mMin;
40
+    virtual void ackDialog();
41
+
42
+    virtual bool handleKeyboardDialog(KeyboardButton key, bool pressed);
43
+
44
+    virtual bool handleMouseClickDialog(unsigned int x, unsigned int y,
45
+            KeyboardButton button, bool released);
59 46
 
60
-    Folder *mapFolder;
61
-    bool hiddenState;
47
+    virtual bool handleMouseScrollDialog(int xrel, int yrel);
62 48
 
49
+    virtual void displayDialog();
50
+
51
+    bool mVisible;
52
+    bool dialogState;
63 53
     std::string dialogText;
64 54
     std::string dialogButton1;
65 55
     std::string dialogButton2;
66
-    bool dialogState;
67 56
     std::function<int (bool state)> dialogFunction;
68 57
 };
69 58
 
70 59
 Menu &getMenu();
71 60
 
72 61
 #endif
62
+

+ 56
- 0
include/MenuFolder.h Zobrazit soubor

@@ -0,0 +1,56 @@
1
+/*!
2
+ * \file include/MenuFolder.h
3
+ * \brief File-Explorer like Menu
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _MENU_FOLDER_H_
9
+#define _MENU_FOLDER_H_
10
+
11
+#include "Menu.h"
12
+#include "utils/Folder.h"
13
+
14
+/*!
15
+ * \brief Menu 'overlay'
16
+ */
17
+class MenuFolder : public Menu {
18
+public:
19
+
20
+    /*!
21
+     * \brief Constructs an object of MenuFolder
22
+     */
23
+    MenuFolder();
24
+
25
+    /*!
26
+     * \brief Deconstructs an object of MenuFolder
27
+     */
28
+    virtual ~MenuFolder();
29
+
30
+    virtual int initialize();
31
+
32
+    virtual void display();
33
+
34
+    virtual void handleKeyboard(KeyboardButton key, bool pressed);
35
+
36
+    virtual void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
37
+
38
+    virtual void handleMouseScroll(int xrel, int yrel);
39
+
40
+private:
41
+
42
+    virtual int initialize(std::string s);
43
+
44
+    virtual int initialize(Folder *folder, bool filter = true);
45
+
46
+    virtual void loadOrOpen();
47
+
48
+    long mCursor;
49
+    long mMin;
50
+
51
+    Folder *mapFolder;
52
+    bool hiddenState;
53
+};
54
+
55
+#endif
56
+

+ 1
- 0
src/CMakeLists.txt Zobrazit soubor

@@ -58,6 +58,7 @@ set (SRCS ${SRCS} "FontTRLE.cpp")
58 58
 set (SRCS ${SRCS} "Game.cpp")
59 59
 set (SRCS ${SRCS} "main.cpp")
60 60
 set (SRCS ${SRCS} "Menu.cpp")
61
+set (SRCS ${SRCS} "MenuFolder.cpp")
61 62
 set (SRCS ${SRCS} "Mesh.cpp")
62 63
 set (SRCS ${SRCS} "OpenRaider.cpp")
63 64
 set (SRCS ${SRCS} "Render.cpp")

+ 36
- 209
src/Menu.cpp Zobrazit soubor

@@ -5,73 +5,12 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
-#include <cctype>
9
-#include <cstring>
10
-
11 8
 #include "global.h"
12 9
 #include "Console.h"
13 10
 #include "Font.h"
14
-#include "OpenRaider.h"
15
-#include "utils/strings.h"
16
-#include "TombRaider.h"
17 11
 #include "Window.h"
18 12
 #include "Menu.h"
19 13
 
20
-Menu::Menu() {
21
-    mVisible = false;
22
-    mCursor = 0;
23
-    mMin = 0;
24
-    mapFolder = nullptr;
25
-    hiddenState = false;
26
-    dialogState = false;
27
-}
28
-
29
-Menu::~Menu() {
30
-    delete mapFolder;
31
-    mapFolder = nullptr;
32
-}
33
-
34
-int Menu::initialize() {
35
-    return initialize(getOpenRaider().mPakDir);
36
-}
37
-
38
-int Menu::initialize(std::string folder) {
39
-    return initialize(new Folder(folder, hiddenState));
40
-}
41
-
42
-int Menu::initialize(Folder *folder) {
43
-    if (mapFolder != nullptr)
44
-        delete mapFolder;
45
-    mapFolder = folder;
46
-    mMin = mCursor = 0;
47
-
48
-    mapFolder->executeRemoveFiles([](File &f) {
49
-        // Filter files based on file name
50
-        if ((f.getName().length() > 4)
51
-            && (f.getName().compare(f.getName().length() - 4, 4, ".phd") != 0)
52
-            && (f.getName().compare(f.getName().length() - 4, 4, ".tr2") != 0)
53
-            && (f.getName().compare(f.getName().length() - 4, 4, ".tr4") != 0)
54
-            && (f.getName().compare(f.getName().length() - 4, 4, ".trc") != 0)) {
55
-            return true; // delete file from list
56
-        }
57
-
58
-        // Check maps for validity
59
-        int error = TombRaider::checkMime(f.getPath().c_str());
60
-        if (error != 0) {
61
-            getConsole() << "Error: pak file '" << f.getName().c_str()
62
-                << "' " << ((error == -1) ? "not found" : "invalid") << Console::endl;
63
-            return true; // delete file from list
64
-        }
65
-
66
-        return false; // keep file on list
67
-    });
68
-
69
-    if ((mapFolder->fileCount() + mapFolder->folderCount()) > 0)
70
-        mCursor = 1; // Don't select ".." by default
71
-
72
-    return 0;
73
-}
74
-
75 14
 void Menu::setVisible(bool visible) {
76 15
     mVisible = visible;
77 16
 }
@@ -80,62 +19,43 @@ bool Menu::isVisible() {
80 19
     return mVisible;
81 20
 }
82 21
 
83
-void Menu::display() {
84
-    if (!mVisible)
85
-        return;
86
-
87
-    // Draw half-transparent overlay
88
-    glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
89
-    glDisable(GL_TEXTURE_2D);
90
-    glRecti(0, 0, (GLint)getWindow().getWidth(), (GLint)getWindow().getHeight());
91
-    glEnable(GL_TEXTURE_2D);
92
-
93
-    // Draw heading
94
-    getFont().drawTextCentered(0, 10, 1.2f, BLUE, getWindow().getWidth(), VERSION);
22
+void Menu::showDialog(std::string msg, std::string btn1, std::string btn2,
23
+        std::function<int (bool state)> callback) {
24
+    // Only show one dialog at a time
25
+    assert(dialogText.length() == 0);
26
+    assert(dialogButton1.length() == 0);
27
+    assert(dialogButton2.length() == 0);
95 28
 
96
-    // Estimate displayable number of items
97
-    int items = (getWindow().getHeight() - 60) / 25;
29
+    assert(msg.length() > 0);
30
+    assert(btn1.length() > 0);
98 31
 
99
-    // Print list of "..", folders, files
100
-    for (long i = mMin; (i < (mMin + items))
101
-                && (i < (mapFolder->folderCount() + mapFolder->fileCount() + 1)); i++) {
102
-        if (i == 0) {
103
-            getFont().drawText(25, 50, 0.75f, (mCursor == i) ? RED : BLUE, "..");
104
-        } else {
105
-            getFont().drawText(25, (unsigned int)(50 + (25 * (i - mMin))), 0.75f,
106
-                (mCursor == i) ? RED : BLUE,
107
-                ((i - 1) < mapFolder->folderCount()) ?
108
-                    (mapFolder->getFolder(i - 1).getName() + "/")
109
-                    : mapFolder->getFile(i - 1 - mapFolder->folderCount()).getName());
110
-        }
111
-    }
32
+    dialogText = msg;
33
+    dialogButton1 = btn1;
34
+    dialogButton2 = btn2;
35
+    dialogState = false;
36
+    dialogFunction = callback;
112 37
 
113
-    displayDialog();
38
+    getConsole() << dialogText << Console::endl;
114 39
 }
115 40
 
116
-void Menu::loadOrOpen() {
117
-    if (mCursor == 0) {
118
-        if (initialize(mapFolder->getParent().getPath()) != 0) {
119
-            showDialog("Error reading parent folder!", "OK", "");
120
-        }
121
-    } else if ((mCursor - 1) < mapFolder->folderCount()) {
122
-        if (initialize(mapFolder->getFolder(mCursor - 1).getPath()) != 0) {
123
-            showDialog("Error reading subfolder!", "OK", "");
124
-        }
125
-    } else {
126
-        std::string tmp = "load ";
127
-        tmp += mapFolder->getFile((unsigned long)mCursor - 1 - mapFolder->folderCount()).getPath();
128
-        if (getOpenRaider().command(tmp.c_str()) == 0) {
129
-            setVisible(false);
130
-        } else {
131
-            showDialog("Error loading map!", "OK", "");
41
+void Menu::ackDialog() {
42
+    dialogText = "";
43
+    dialogButton1 = "";
44
+    dialogButton2 = "";
45
+
46
+    if (dialogFunction) {
47
+        int error = dialogFunction(dialogState);
48
+        if (error != 0) {
49
+            showDialog("Error processing dialog callback!", "OK", "");
132 50
         }
133 51
     }
52
+
53
+    dialogState = false;
134 54
 }
135 55
 
136
-void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
56
+bool Menu::handleKeyboardDialog(KeyboardButton key, bool pressed) {
137 57
     if (!pressed)
138
-        return;
58
+        return (dialogText.length() > 0);
139 59
 
140 60
     if (dialogText.length() > 0) {
141 61
         if (dialogButton2.length() == 0) {
@@ -155,114 +75,21 @@ void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
155 75
                 dialogState = !dialogState;
156 76
             }
157 77
         }
158
-        return;
159
-    }
160
-
161
-    assert(mapFolder != nullptr);
162
-    int items = (getWindow().getHeight() - 60) / 25;
163
-
164
-    if (key == upKey) {
165
-        if (mCursor > 0)
166
-            mCursor--;
167
-        else
168
-            mCursor = (long)(mapFolder->folderCount() + mapFolder->fileCount());
169
-    } else if (key == downKey) {
170
-        if (mCursor < (long)(mapFolder->folderCount() + mapFolder->fileCount()))
171
-            mCursor++;
172
-        else
173
-            mCursor = 0;
174
-    } else if (key == enterKey) {
175
-        loadOrOpen();
176
-    } else if (key == dotKey) {
177
-        hiddenState = !hiddenState;
178
-        initialize(mapFolder->getPath());
78
+        return true;
179 79
     }
180 80
 
181
-    if (mCursor > (mMin + items - 1)) {
182
-        mMin = mCursor - items + 1;
183
-    } else if (mCursor < mMin) {
184
-        mMin = mCursor;
185
-    }
186
-}
187
-
188
-void Menu::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
189
-    int items = (getWindow().getHeight() - 60) / 25;
190
-
191
-    if (released || (button != leftmouseKey))
192
-        return;
193
-
194
-    if (dialogText.length() > 0) {
195
-        //!< \todo Allow mouse usage of Menu dialogs!
196
-        return;
197
-    }
198
-
199
-    if ((y >= 50) && (y <= (unsigned int)(50 + (25 * items)))
200
-            && ((mMin + (y / 25)) <= (mapFolder->folderCount() + mapFolder->fileCount() + 2))) {
201
-        y -= 50;
202
-        if (mCursor == (mMin + (y / 25)))
203
-            loadOrOpen();
204
-        else
205
-            mCursor = mMin + (y / 25);
206
-    }
81
+    return false;
207 82
 }
208 83
 
209
-void Menu::handleMouseScroll(int xrel, int yrel) {
210
-    if (dialogText.length() > 0)
211
-        return;
212
-
213
-    assert((xrel != 0) || (yrel != 0));
214
-    assert(mapFolder != nullptr);
215
-    int items = (getWindow().getHeight() - 60) / 25;
216
-
217
-    if ((mapFolder->folderCount() + mapFolder->fileCount() + 1) > items) {
218
-        if (yrel < 0) {
219
-            if (mMin < (mapFolder->folderCount() + mapFolder->fileCount() + 1 - items))
220
-                mMin++;
221
-        } else if (yrel > 0) {
222
-            if (mMin > 0)
223
-                mMin--;
224
-        }
225
-
226
-        if (mCursor < mMin) {
227
-            mCursor = mMin;
228
-        } else if (mCursor > (mMin + items - 1)) {
229
-            mCursor = mMin + items - 1;
230
-        }
231
-    }
84
+bool Menu::handleMouseClickDialog(unsigned int x, unsigned int y,
85
+            KeyboardButton button, bool released) {
86
+    //! \todo Allow mouse usage of Menu dialogs!
87
+    return (dialogText.length() > 0);
232 88
 }
233 89
 
234
-void Menu::showDialog(std::string msg, std::string btn1, std::string btn2,
235
-        std::function<int (bool state)> callback) {
236
-    // Only show one dialog at a time
237
-    assert(dialogText.length() == 0);
238
-    assert(dialogButton1.length() == 0);
239
-    assert(dialogButton2.length() == 0);
240
-
241
-    assert(msg.length() > 0);
242
-    assert(btn1.length() > 0);
243
-
244
-    dialogText = msg;
245
-    dialogButton1 = btn1;
246
-    dialogButton2 = btn2;
247
-    dialogState = false;
248
-    dialogFunction = callback;
249
-
250
-    getConsole() << dialogText << Console::endl;
251
-}
252
-
253
-void Menu::ackDialog() {
254
-    dialogText = "";
255
-    dialogButton1 = "";
256
-    dialogButton2 = "";
257
-
258
-    if (dialogFunction) {
259
-        int error = dialogFunction(dialogState);
260
-        if (error != 0) {
261
-            showDialog("Error processing dialog callback!", "OK", "");
262
-        }
263
-    }
264
-
265
-    dialogState = false;
90
+bool Menu::handleMouseScrollDialog(int xrel, int yrel) {
91
+    //! \todo Allow mouse usage of Menu dialogs!
92
+    return (dialogText.length() > 0);
266 93
 }
267 94
 
268 95
 void Menu::displayDialog() {

+ 203
- 0
src/MenuFolder.cpp Zobrazit soubor

@@ -0,0 +1,203 @@
1
+/*!
2
+ * \file src/MenuFolder.cpp
3
+ * \brief File-Explorer like menu
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "global.h"
9
+#include "Console.h"
10
+#include "Font.h"
11
+#include "OpenRaider.h"
12
+#include "TombRaider.h"
13
+#include "Window.h"
14
+#include "MenuFolder.h"
15
+
16
+MenuFolder::MenuFolder() {
17
+    mVisible = false;
18
+    mCursor = 0;
19
+    mMin = 0;
20
+    mapFolder = nullptr;
21
+    hiddenState = false;
22
+    dialogState = false;
23
+}
24
+
25
+MenuFolder::~MenuFolder() {
26
+    delete mapFolder;
27
+    mapFolder = nullptr;
28
+}
29
+
30
+int MenuFolder::initialize() {
31
+    return initialize(getOpenRaider().mPakDir);
32
+}
33
+
34
+int MenuFolder::initialize(std::string s) {
35
+    return initialize(new Folder(s));
36
+}
37
+
38
+int MenuFolder::initialize(Folder *folder, bool filter) {
39
+    if (mapFolder != nullptr)
40
+        delete mapFolder;
41
+    mapFolder = folder;
42
+    mMin = mCursor = 0;
43
+
44
+    if (filter) {
45
+        mapFolder->executeRemoveFiles([](File &f) {
46
+            // Filter files based on file name
47
+            if ((f.getName().length() > 4)
48
+                && (f.getName().compare(f.getName().length() - 4, 4, ".phd") != 0)
49
+                && (f.getName().compare(f.getName().length() - 4, 4, ".tr2") != 0)
50
+                && (f.getName().compare(f.getName().length() - 4, 4, ".tr4") != 0)
51
+                && (f.getName().compare(f.getName().length() - 4, 4, ".trc") != 0)) {
52
+                return true; // delete file from list
53
+            }
54
+
55
+            // Check maps for validity
56
+            int error = TombRaider::checkMime(f.getPath().c_str());
57
+            if (error != 0) {
58
+                getConsole() << "Error: pak file '" << f.getName().c_str()
59
+                    << "' " << ((error == -1) ? "not found" : "invalid") << Console::endl;
60
+                return true; // delete file from list
61
+            }
62
+
63
+            return false; // keep file on list
64
+        });
65
+    }
66
+
67
+    if ((mapFolder->fileCount() + mapFolder->folderCount()) > 0)
68
+        mCursor = 1; // Don't select ".." by default
69
+
70
+    return 0;
71
+}
72
+
73
+void MenuFolder::display() {
74
+    if (!mVisible)
75
+        return;
76
+
77
+    // Draw half-transparent overlay
78
+    glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
79
+    glDisable(GL_TEXTURE_2D);
80
+    glRecti(0, 0, (GLint)getWindow().getWidth(), (GLint)getWindow().getHeight());
81
+    glEnable(GL_TEXTURE_2D);
82
+
83
+    // Draw heading
84
+    getFont().drawTextCentered(0, 10, 1.2f, BLUE, getWindow().getWidth(), VERSION);
85
+
86
+    // Estimate displayable number of items
87
+    int items = (getWindow().getHeight() - 60) / 25;
88
+
89
+    // Print list of "..", folders, files
90
+    for (long i = mMin; (i < (mMin + items))
91
+                && (i < (mapFolder->folderCount() + mapFolder->fileCount() + 1)); i++) {
92
+        if (i == 0) {
93
+            getFont().drawText(25, 50, 0.75f, (mCursor == i) ? RED : BLUE, "..");
94
+        } else {
95
+            getFont().drawText(25, (unsigned int)(50 + (25 * (i - mMin))), 0.75f,
96
+                (mCursor == i) ? RED : BLUE,
97
+                ((i - 1) < mapFolder->folderCount()) ?
98
+                    (mapFolder->getFolder(i - 1).getName() + "/")
99
+                    : mapFolder->getFile(i - 1 - mapFolder->folderCount()).getName());
100
+        }
101
+    }
102
+
103
+    displayDialog();
104
+}
105
+
106
+void MenuFolder::loadOrOpen() {
107
+    if (mCursor == 0) {
108
+        if (initialize(mapFolder->getParent().getPath()) != 0) {
109
+            showDialog("Error reading parent folder!", "OK", "");
110
+        }
111
+    } else if ((mCursor - 1) < mapFolder->folderCount()) {
112
+        if (initialize(mapFolder->getFolder(mCursor - 1).getPath()) != 0) {
113
+            showDialog("Error reading subfolder!", "OK", "");
114
+        }
115
+    } else {
116
+        std::string tmp = "load ";
117
+        tmp += mapFolder->getFile((unsigned long)mCursor - 1 - mapFolder->folderCount()).getPath();
118
+        if (getOpenRaider().command(tmp.c_str()) == 0) {
119
+            setVisible(false);
120
+        } else {
121
+            showDialog("Error loading map!", "OK", "");
122
+        }
123
+    }
124
+}
125
+
126
+void MenuFolder::handleKeyboard(KeyboardButton key, bool pressed) {
127
+    if (handleKeyboardDialog(key, pressed))
128
+        return;
129
+
130
+    if (!pressed)
131
+        return;
132
+
133
+    assert(mapFolder != nullptr);
134
+    int items = (getWindow().getHeight() - 60) / 25;
135
+
136
+    if (key == upKey) {
137
+        if (mCursor > 0)
138
+            mCursor--;
139
+        else
140
+            mCursor = (long)(mapFolder->folderCount() + mapFolder->fileCount());
141
+    } else if (key == downKey) {
142
+        if (mCursor < (long)(mapFolder->folderCount() + mapFolder->fileCount()))
143
+            mCursor++;
144
+        else
145
+            mCursor = 0;
146
+    } else if (key == enterKey) {
147
+        loadOrOpen();
148
+    } else if (key == dotKey) {
149
+        hiddenState = !hiddenState;
150
+        initialize(mapFolder->getPath());
151
+    }
152
+
153
+    if (mCursor > (mMin + items - 1)) {
154
+        mMin = mCursor - items + 1;
155
+    } else if (mCursor < mMin) {
156
+        mMin = mCursor;
157
+    }
158
+}
159
+
160
+void MenuFolder::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
161
+    if (handleMouseClickDialog(x, y, button, released))
162
+        return;
163
+
164
+    int items = (getWindow().getHeight() - 60) / 25;
165
+
166
+    if (released || (button != leftmouseKey))
167
+        return;
168
+
169
+    if ((y >= 50) && (y <= (unsigned int)(50 + (25 * items)))
170
+            && ((mMin + (y / 25)) <= (mapFolder->folderCount() + mapFolder->fileCount() + 2))) {
171
+        y -= 50;
172
+        if (mCursor == (mMin + (y / 25)))
173
+            loadOrOpen();
174
+        else
175
+            mCursor = mMin + (y / 25);
176
+    }
177
+}
178
+
179
+void MenuFolder::handleMouseScroll(int xrel, int yrel) {
180
+    if (handleMouseScrollDialog(xrel, yrel));
181
+        return;
182
+
183
+    assert((xrel != 0) || (yrel != 0));
184
+    assert(mapFolder != nullptr);
185
+    int items = (getWindow().getHeight() - 60) / 25;
186
+
187
+    if ((mapFolder->folderCount() + mapFolder->fileCount() + 1) > items) {
188
+        if (yrel < 0) {
189
+            if (mMin < (mapFolder->folderCount() + mapFolder->fileCount() + 1 - items))
190
+                mMin++;
191
+        } else if (yrel > 0) {
192
+            if (mMin > 0)
193
+                mMin--;
194
+        }
195
+
196
+        if (mCursor < mMin) {
197
+            mCursor = mMin;
198
+        } else if (mCursor > (mMin + items - 1)) {
199
+            mCursor = mMin + items - 1;
200
+        }
201
+    }
202
+}
203
+

+ 2
- 2
src/main.cpp Zobrazit soubor

@@ -15,7 +15,7 @@
15 15
 #include "Exception.h"
16 16
 #include "FontManager.h"
17 17
 #include "Game.h"
18
-#include "Menu.h"
18
+#include "MenuFolder.h"
19 19
 #include "OpenRaider.h"
20 20
 #include "Render.h"
21 21
 #include "TextureManager.h"
@@ -59,7 +59,7 @@ Game &getGame() {
59 59
 }
60 60
 
61 61
 Menu &getMenu() {
62
-    static Menu gMenu;
62
+    static MenuFolder gMenu;
63 63
     return gMenu;
64 64
 }
65 65
 

Loading…
Zrušit
Uložit