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
30namespace Ultima {
31namespace Ultima4 {
32
33class Menu;
34class TextView;
35
36class MenuEvent {
37public:
38 enum Type {
39 ACTIVATE,
40 INCREMENT,
41 DECREMENT,
42 SELECT,
43 RESET
44 };
45
46 MenuEvent(const Menu *menu, Type type, const MenuItem *item = nullptr) {
47 this->_menu = menu;
48 this->_type = type;
49 this->_item = item;
50 }
51
52 const Menu *getMenu() {
53 return _menu;
54 }
55 Type getType() {
56 return _type;
57 }
58 const MenuItem *getMenuItem() {
59 return _item;
60 }
61
62private:
63 const Menu *_menu;
64 Type _type;
65 const MenuItem *_item;
66};
67
71class Menu : public Observable<Menu *, MenuEvent &> {
72public:
74
75public:
76 Menu();
77 ~Menu();
78
79 void removeAll();
80
84 void add(int id, Common::String text, short x, short y, int shortcutKey = -1);
85
86 MenuItem *add(int id, MenuItem *item);
87 void addShortcutKey(int id, int shortcutKey);
88 void setClosesMenu(int id);
89
94
99 void setCurrent(int id);
100 void show(TextView *view);
101
107 bool isVisible();
108
112 void next();
113
117 void prev();
118
122 void highlight(MenuItem *item);
123
128
133
138
145 void reset(bool highlightFirst = true);
146
151
156
161
169 void activateItem(int id, MenuEvent::Type action);
170
175 bool activateItemByShortcut(int key, MenuEvent::Type action);
176
180 bool getClosed() const;
181
185 void setClosed(bool closed);
186
187 void setTitle(const Common::String &text, int x, int y);
188
189private:
190 MenuItemList _items;
191 MenuItemList::iterator _selected;
192 bool _closed;
193 Common::String _title;
194 int _titleX, _titleY;
195};
196
197} // End of namespace Ultima4
198} // End of namespace Ultima
199
200#endif
Definition: str.h:59
Definition: menu.h:36
Definition: menu.h:71
MenuItemList::iterator begin()
MenuItemList::iterator getCurrent()
MenuItemList::iterator getById(int id)
void setCurrent(MenuItemList::iterator i)
bool getClosed() const
bool activateItemByShortcut(int key, MenuEvent::Type action)
void highlight(MenuItem *item)
void activateItem(int id, MenuEvent::Type action)
void add(int id, Common::String text, short x, short y, int shortcutKey=-1)
MenuItemList::iterator begin_visible()
MenuItem * getItemById(int id)
void reset(bool highlightFirst=true)
void activateItemAtPos(TextView *view, const Common::Point &pt)
void setClosed(bool closed)
MenuItemList::iterator end()
Definition: menuitem.h:46
Definition: observable.h:45
Definition: textview.h:41
Definition: list_intern.h:54
Definition: rect.h:144