ScummVM API documentation
menu.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ZVISION_MENU_H
23 #define ZVISION_MENU_H
24 
25 #include "common/array.h"
26 #include "common/bitarray.h"
27 #include "common/rect.h"
28 #include "graphics/surface.h"
29 #include "zvision/zvision.h"
30 #include "zvision/common/focus_list.h"
31 #include "zvision/common/scroller.h"
32 #include "zvision/scripting/script_manager.h"
33 
34 namespace ZVision {
35 
36 enum {
37  kMainMenuSave = 0,
38  kMainMenuLoad = 1,
39  kMainMenuPrefs = 2,
40  kMainMenuExit = 3,
41  kItemsMenu = 4,
42  kMagicMenu = 5
43 };
44 
45 struct MenuParams {
46  int16 wxButs[4][2]; // Widths & X positions of main menu buttons; {Save, Restore, Prefs, Quit}
47  int16 wMain; // Width of main menu background
48  int8 idleFrame; // Frame to display of unselected main menu button
49  int8 activeFrame; // Frame to display of selected main menu button when mouse is down
50  int8 clickedFrame; // Frame to display of selected main menu button when mouse is down
51  Common::Point activePos; // Fully scrolled main menu position, relative to origin of menu area
52  Common::Point idlePos; // Fully retracted main menu position, relative to origin of menu area
53  int16 period; // Duration of main menu scrolldown
54  int16 triggerHeight; // Height of menu trigger area when inactive
55  int16 buttonPeriod; // Duration of main menu button animation
56 };
57 
58 // NB - menu area is same width as working window.
59 
60 static const MenuParams nemesisParams {
61  { {120, -1}, {144, 120}, {128, 264}, {120, 392} },
62  512,
63  -1,
64  4,
65  5,
66  Common::Point(0, 0),
67  Common::Point(0, -32),
68  500,
69  2,
70  500
71 };
72 
73 static const MenuParams zgiParams {
74  { {135, 50}, {135, 185}, {135, 320}, {135, 455} },
75  580,
76  0,
77  1,
78  1,
79  Common::Point(30, 0),
80  Common::Point(30, -20),
81  250,
82  32,
83  0
84 };
85 
86 class MenuManager {
87 public:
88  MenuManager(ZVision *engine, const Common::Rect menuArea, const MenuParams params);
89  virtual ~MenuManager();
90  virtual void onMouseMove(const Common::Point &pos);
91  virtual void onMouseDown(const Common::Point &pos);
92  virtual void onMouseUp(const Common::Point &pos);
93  virtual void process(uint32 deltaTimeInMillis);
94  bool inMenu() const {
95  return _prevInMenu;
96  }
97  virtual bool inMenu(const Common::Point &pos) const {
98  return false;
99  } // For widescreen mod; used to suspend panning, tilting & scripting triggers when the mouse is within the working window but also in the menu.
100 
101  void mainMouseDown(const Common::Point &pos); // Show clicked graphic under selected button
102  bool mainMouseMove(const Common::Point &pos); // return true if selected button has changed
103 
104  void setEnable(uint16 flags);
105  uint16 getEnable() const {
106  return _menuBarFlag;
107  }
108  bool getEnable(uint8 flag) const {
109  return _enableFlags.get(flag);
110  }
111 
112 protected:
113  virtual void redrawAll() {}
114  void redrawMain();
115  int mouseOverMain(const Common::Point &pos);
116  void setFocus(int8 currentFocus);
117 
118  bool _prevInMenu = false;
119  bool _redraw = true;
120  int _mouseOnItem = -1;
121  static const uint8 _hMainMenu = 32;
122  int8 _mainClicked = -1;
123 
124  ZVision *_engine;
125  const MenuParams _params;
126  uint16 _menuBarFlag;
127  const Common::Rect _menuArea;
128  const Common::Point _menuOrigin;
129  const Common::Rect _menuTriggerArea;
130  Graphics::Surface _mainBack;
131  Graphics::Surface _mainButtons[4][6];
132  Common::BitArray _enableFlags;
133  Common::Rect _mainArea;
134  Common::Rect _menuHotspots[4];
135  int8 _mainFrames[4]; // Frame to display of each main menu button; first row is currently displayed, 2nd row is backbuffer for idle animations
136  Scroller _mainScroller;
137  FocusList<int8> _menuFocus; // Order in which menus have most recently had focus; determines current mouse focus & order in which to redraw them.
138  bool _clean = false; // Whether or not to blank
139  LinearScroller *_buttonAnim[4];
140 };
141 
142 class MenuZGI: public MenuManager {
143 public:
144  MenuZGI(ZVision *engine, Common::Rect menuArea);
145  ~MenuZGI() override;
146  void onMouseMove(const Common::Point &pos) override; // NB Pos is in screen coordinates
147  void onMouseUp(const Common::Point &pos) override;
148  void process(uint32 deltaTimeInMillis) override;
149  bool inMenu(const Common::Point &pos) const override;
150 private:
151  void redrawAll() override;
152  Graphics::Surface _menuBack[3];
153  Graphics::Surface *_items[50][2];
154  uint _itemId[50];
155 
156  Graphics::Surface *_magic[12][2];
157  uint _magicId[12];
158 // void redrawMain(bool hasFocus) override;
159  void redrawItems();
160  void redrawMagic();
161  int mouseOverItem(const Common::Point &pos, int itemCount);
162  int mouseOverMagic(const Common::Point &pos);
163 
164  static const uint16 _hSideMenu = 32;
165  static const uint16 _wSideMenu = 600;
166  static const uint16 _wSideMenuTab = 20;
167  static const int16 _magicWidth = 47;
168 
169  const int16 _sideMenuPeriod = 300;
170 
171  Scroller _itemsScroller, _magicScroller;
172 
173  const Common::Point _magicOrigin;
174  const Common::Point _itemsOrigin;
175 
176  Common::Rect _magicArea;
177  Common::Rect _itemsArea;
178 };
179 
180 class MenuNemesis: public MenuManager {
181 public:
182  MenuNemesis(ZVision *engine, Common::Rect menuArea);
183  ~MenuNemesis() override;
184  void onMouseMove(const Common::Point &pos) override;
185  bool inMenu(const Common::Point &pos) const override;
186 private:
187  void redrawAll() override;
188 };
189 
190 } // End of namespace ZVision
191 
192 #endif
Definition: scroller.h:67
Definition: menu.h:45
Definition: surface.h:67
Definition: rect.h:524
Definition: focus_list.h:27
Definition: menu.h:180
Definition: bitarray.h:29
Definition: rect.h:144
Definition: menu.h:86
Definition: scroller.h:38
Definition: menu.h:142