ScummVM API documentation
popup.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 GUI_WIDGETS_POPUP_H
23#define GUI_WIDGETS_POPUP_H
24
25#include "gui/dialog.h"
26#include "gui/widget.h"
27#include "common/str.h"
28#include "common/array.h"
29
30namespace GUI {
31
39class PopUpWidget : public Widget, public CommandSender {
40 struct Entry {
42 uint32 tag;
43 };
45protected:
46 EntryList _entries;
47 int _selectedItem;
48
49 int _leftPadding;
50 int _rightPadding;
51 uint32 _cmd;
52
53public:
54 PopUpWidget(GuiObject *boss, const Common::String &name, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
55 PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
56
57 void handleMouseDown(int x, int y, int button, int clickCount) override;
58 void handleMouseWheel(int x, int y, int direction) override;
59
60 void appendEntry(const Common::U32String &entry, uint32 tag = (uint32)-1);
61 void appendEntry(const Common::String &entry, uint32 tag = (uint32)-1);
62 void clearEntries();
63 int numEntries() { return _entries.size(); }
64
66 void setSelected(int item);
67
69 void setSelectedTag(uint32 tag);
70
71 int getSelected() const { return _selectedItem; }
72 uint32 getSelectedTag() const { return (_selectedItem >= 0) ? _entries[_selectedItem].tag : (uint32)-1; }
73// const String& getSelectedString() const { return (_selectedItem >= 0) ? _entries[_selectedItem].name : String::emptyString; }
74
75 void handleMouseEntered(int button) override { if (_selectedItem != -1) read(_entries[_selectedItem].name); setFlags(WIDGET_HILITED); markAsDirty(); }
76 void handleMouseLeft(int button) override { clearFlags(WIDGET_HILITED); markAsDirty(); }
77
78 void reflowLayout() override;
79protected:
80 void drawWidget() override;
81};
82
88class PopUpDialog : public Dialog {
89protected:
90 Widget *_boss;
91 int _clickX, _clickY;
92 int _selection;
93 int _initialSelection;
94 uint32 _openTime;
95 bool _twoColumns;
96 int _entriesPerColumn;
97
98 int _leftPadding;
99 int _rightPadding;
100 int _lineHeight;
101
102 int _lastRead;
103
105 EntryList _entries;
106
107public:
108 PopUpDialog(Widget *boss, const Common::String &name, int clickX, int clickY);
109
110 void open() override;
111 void reflowLayout() override;
112 void drawDialog(DrawLayer layerToDraw, bool resetClipping = true) override;
113
114 void handleMouseUp(int x, int y, int button, int clickCount) override;
115 void handleMouseWheel(int x, int y, int direction) override; // Scroll through entries with scroll wheel
116 void handleMouseMoved(int x, int y, int button) override; // Redraw selections depending on mouse position
117 void handleMouseLeft(int button) override;
118 void handleKeyDown(Common::KeyState state) override; // Scroll through entries with arrow keys etc.
119
120 void setPosition(int x, int y);
121 void setPadding(int left, int right);
122 void setLineHeight(int lineHeight);
123 void setWidth(uint16 width);
124
125 void appendEntry(const Common::U32String &entry);
126 void clearEntries();
127 void setSelection(int item);
128
129protected:
130 void drawMenuEntry(int entry, bool hilite);
131
132 int findItem(int x, int y) const;
133 bool isMouseDown();
134
135 void moveUp();
136 void moveDown();
137 void read(const Common::U32String &str);
138};
139
140} // End of namespace GUI
141
142#endif
size_type size() const
Definition: array.h:316
Definition: str.h:59
Definition: ustr.h:57
Definition: object.h:40
Definition: dialog.h:49
Definition: object.h:60
Definition: popup.h:88
void drawDialog(DrawLayer layerToDraw, bool resetClipping=true) override
Definition: popup.h:39
void setSelectedTag(uint32 tag)
void setSelected(int item)
Definition: widget.h:99
virtual void markAsDirty()
Definition: keyboard.h:294