ScummVM API documentation
gui.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/* This is a C++ class for handling a GUI, and associated widgets */
23
24#ifndef NUVIE_GUI_GUI_H
25#define NUVIE_GUI_GUI_H
26
27#include "ultima/nuvie/gui/gui_status.h"
28#include "ultima/nuvie/gui/gui_drag_manager.h"
29#include "ultima/nuvie/gui/widgets/gui_widget.h"
30#include "ultima/nuvie/gui/gui_font.h"
31#include "common/events.h"
32
33namespace Ultima {
34namespace Nuvie {
35
36class Configuration;
37class Screen;
38class GUI_Color;
39
40#define GUI_FULL_REDRAW true
41
42class GUI {
43
44protected:
45
46 static GUI *gui;
47 const Configuration *config;
48
49 /* The display surface */
50 Screen *screen;
51
52 GUI_Font *gui_font;
53 GUI_DragManager *gui_drag_manager;
54
55 /* Pointers for an array of widgets */
56 int maxwidgets;
57 int numwidgets;
58 GUI_Widget **widgets;
59
60 /* All input will go to this widget first. */
61 GUI_Widget *focused_widget; // SB-X
62 /* All input will go to this widget ONLY. */
63 GUI_Widget *locked_widget; // SB-X
64 /* All input will be ignored. */
65 bool block_input; // SB-X
66
67 /* Flag - whether or not the GUI is currently running */
68 int running;
69
70 /* Flag - whether or not the GUI needs to be displayed */
71 int display;
72
73 /* Flag - whether we are performing a drag and drop */
74 bool dragging;
75
76 bool full_redraw; // this forces all widgets to redraw on the next call to Display()
77
78 // some default colours
79 GUI_Color *selected_color;
80
81public:
82 static const int mouseclick_delay; /* SB-X */
83
84 GUI(const Configuration *c, Screen *s);
85 ~GUI();
86
87 /* Add a widget to the GUI.
88 The widget will be automatically deleted when the GUI is deleted.
89 This function returns 0, or -1 if the function ran out of memory.
90 */
91 int AddWidget(GUI_Widget *widget);
92
93 /* remove widget from gui system but don't delete it */
94 bool removeWidget(GUI_Widget *widget);
95
96 bool moveWidget(GUI_Widget *widget, uint32 dx, uint32 dy);
97
98 /* force everything to redraw */
99 void force_full_redraw();
100
101 /* Display the GUI manually */
102 void Display();
103
104 /* Returns will return true if the GUI is still ready to handle
105 events after a call to Run(), and false if a widget or idle
106 function requested a quit.
107 */
108 int Running(void) {
109 return running;
110 }
111
112 /* Run the GUI.
113 This returns when either a widget requests a quit, the idle
114 function requests a quit, or the SDL window has been closed.
115 If 'once' is non-zero, you need to display the GUI yourself,
116 and the GUI event loop will run once and then return.
117 If 'multitaskfriendly' is non-zero AND idle is nullptr,
118 a 'WaitEvent' will be used instead of the CPU time
119 consuming 'PollEvent'. CAVE: Any widget-'idle'-procs WON'T
120 be executed then.
121 */
122 void Run(GUI_IdleProc idle = nullptr, int once = 0, int multitaskfriendly = 0);
123
124 /* Run Idle() on all widgets. */
125 void Idle(); // SB-X
126
127 static GUI *get_gui() {
128 return gui;
129 }
130 GUI_Font *get_font();
131 Screen *get_screen() {
132 return screen;
133 }
134 GUI_Widget *get_focused_widget() {
135 return focused_widget;
136 }
137 GUI_Widget *get_locked_widget() {
138 return locked_widget;
139 }
140 bool get_block_input() {
141 return block_input;
142 }
143
144 //colors
145 GUI_Color *get_selected_color() {
146 return selected_color;
147 }
148
149 /* Function to pass an event to the GUI widgets */
150 GUI_status HandleEvent(Common::Event *event);
151
152 bool set_focus(GUI_Widget *widget);
153 void clear_focus() {
154 set_focus(nullptr);
155 }
156 void lock_input(GUI_Widget *widget);
157 void unlock_input() {
158 lock_input(nullptr);
159 unblock();
160 }
161 void block() {
162 block_input = true;
163 }
164 void unblock() {
165 block_input = false;
166 }
167 Common::Path get_data_dir() const;
168
169 uint16 get_width() const {
170 return screen->get_width();
171 }
172 uint16 get_height() const {
173 return screen->get_height();
174 }
175protected:
176
177 /* Function to handle a GUI status */
178 void HandleStatus(GUI_status status);
179
180 void CleanupDeletedWidgets(bool redraw = false);
181
182};
183
184} // End of namespace Nuvie
185} // End of namespace Ultima
186
187#endif
Definition: path.h:52
Definition: configuration.h:60
Definition: gui_types.h:47
Definition: gui_drag_manager.h:36
Definition: gui_font.h:36
Definition: gui_widget.h:38
Definition: gui.h:42
Definition: screen.h:41
Definition: events.h:218
Definition: atari-screen.h:58