]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/menu.h
Major refactoring of GUI: Phase I
[virtualjaguar] / src / gui / menu.h
1 //
2 // Menu class & supporting structs/classes
3 //
4 // by James L. Hammons
5 //
6
7 #ifndef __MENU_H__
8 #define __MENU_H__
9
10 #include <string>
11 #include <vector>
12 #include "element.h"
13 #include "guimisc.h"                                                    // Ick.
14
15 class Window;
16
17 struct NameAction
18 {
19         std::string name;
20         Window * (* action)(void);
21         SDLKey hotKey;
22
23         NameAction(std::string n, Window * (* a)(void) = NULL, SDLKey k = SDLK_UNKNOWN):
24                 name(n), action(a), hotKey(k) {}
25 };
26
27 class MenuItems
28 {
29         public:
30                 MenuItems(): charLength(0) {}
31                 // Normally, we avoid implementation in a header file but in this case
32                 // we can make an exception. ;-)
33                 bool Inside(uint32 x, uint32 y)
34                 { return (x >= (uint32)extents.x && x < (uint32)(extents.x + extents.w)
35                 && y >= (uint32)extents.y && y < (uint32)(extents.y + extents.h) ? true : false); }
36
37                 std::string title;
38                 std::vector<NameAction> item;
39                 uint32 charLength;
40                 SDL_Rect extents;
41 };
42
43 class Menu: public Element
44 {
45         public:
46 // 1CFF -> 0 001 11 00  111 1 1111
47 // 421F -> 0 100 00 10  000 1 1111
48                 Menu(uint32 x = 0, uint32 y = 0, uint32 w = 0, uint32 h = FONT_HEIGHT,
49                         uint32 fgc = 0xFF7F0000, uint32 bgc = 0xFFFF3F3F, uint32 fgch = 0xFFFF3F3F,
50                         uint32 bgch = 0xFFFF8787);
51                 virtual void HandleKey(SDLKey key);
52                 virtual void HandleMouseMove(uint32 x, uint32 y);
53                 virtual void HandleMouseButton(uint32 x, uint32 y, bool mouseDown);
54                 virtual void Draw(uint32 offsetX = 0, uint32 offsetY = 0);
55                 virtual void Notify(Element *) {}
56                 void Add(MenuItems mi);
57
58         protected:
59                 bool activated, clicked;
60                 uint32 inside, insidePopup;
61                 uint32 fgColor, bgColor, fgColorHL, bgColorHL;
62                 int menuChosen, menuItemChosen;
63
64         private:
65                 std::vector<MenuItems> itemList;
66 };
67
68 #endif  // __MENU_H__