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 ULTIMA4_VIEWS_MENU_H
23 #define ULTIMA4_VIEWS_MENU_H
24 
25 #include "ultima/ultima4/events/event_handler.h"
26 #include "ultima/ultima4/views/menuitem.h"
27 #include "ultima/ultima4/core/observable.h"
28 #include "ultima/ultima4/core/types.h"
29 #include "ultima/shared/std/containers.h"
30 
31 namespace Ultima {
32 namespace Ultima4 {
33 
34 class Menu;
35 class TextView;
36 
37 class MenuEvent {
38 public:
39  enum Type {
40  ACTIVATE,
41  INCREMENT,
42  DECREMENT,
43  SELECT,
44  RESET
45  };
46 
47  MenuEvent(const Menu *menu, Type type, const MenuItem *item = nullptr) {
48  this->_menu = menu;
49  this->_type = type;
50  this->_item = item;
51  }
52 
53  const Menu *getMenu() {
54  return _menu;
55  }
56  Type getType() {
57  return _type;
58  }
59  const MenuItem *getMenuItem() {
60  return _item;
61  }
62 
63 private:
64  const Menu *_menu;
65  Type _type;
66  const MenuItem *_item;
67 };
68 
72 class Menu : public Observable<Menu *, MenuEvent &> {
73 public:
75 
76 public:
77  Menu();
78  ~Menu();
79 
80  void removeAll();
81 
85  void add(int id, Common::String text, short x, short y, int shortcutKey = -1);
86 
87  MenuItem *add(int id, MenuItem *item);
88  void addShortcutKey(int id, int shortcutKey);
89  void setClosesMenu(int id);
90 
94  MenuItemList::iterator getCurrent();
95 
99  void setCurrent(MenuItemList::iterator i);
100  void setCurrent(int id);
101  void show(TextView *view);
102 
108  bool isVisible();
109 
113  void next();
114 
118  void prev();
119 
123  void highlight(MenuItem *item);
124 
128  MenuItemList::iterator begin();
129 
134 
138  MenuItemList::iterator begin_visible();
139 
146  void reset(bool highlightFirst = true);
147 
151  MenuItemList::iterator getById(int id);
152 
156  MenuItem *getItemById(int id);
157 
161  void activateItemAtPos(TextView *view, const Common::Point &pt);
162 
170  void activateItem(int id, MenuEvent::Type action);
171 
176  bool activateItemByShortcut(int key, MenuEvent::Type action);
177 
181  bool getClosed() const;
182 
186  void setClosed(bool closed);
187 
188  void setTitle(const Common::String &text, int x, int y);
189 
190 private:
191  MenuItemList _items;
192  MenuItemList::iterator _current;
193  MenuItemList::iterator _selected;
194  bool _closed;
195  Common::String _title;
196  int _titleX, _titleY;
197 };
198 
199 } // End of namespace Ultima4
200 } // End of namespace Ultima
201 
202 #endif
Definition: str.h:59
Definition: menu.h:37
Definition: textview.h:41
Definition: detection.h:27
Definition: menu.h:72
Definition: menuitem.h:47
Definition: rect.h:45
Definition: observable.h:45
Definition: list_intern.h:51