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
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #ifndef AGS_SHARED_GUI_GUI_OBJECT_H
24 #define AGS_SHARED_GUI_GUI_OBJECT_H
25
26 #include "ags/shared/core/types.h"
27 #include "ags/shared/gfx/bitmap.h"
28 #include "ags/shared/gui/gui_defines.h"
29 #include "ags/shared/util/string.h"
30 #include "ags/globals.h"
31
32 namespace AGS3 {
33
34 #define GUIDIS_GREYOUT 1
35 #define GUIDIS_BLACKOUT 2
36 #define GUIDIS_UNCHANGED 4
37 #define GUIDIS_GUIOFF 0x80
38
39 struct KeyInput;
40
41 namespace AGS {
42 namespace Shared {
43
44 enum LegacyGUIAlignment {
45 kLegacyGUIAlign_Left = 0,
46 kLegacyGUIAlign_Right = 1,
47 kLegacyGUIAlign_Center = 2
48 };
49
50 class GUIObject {
51 public:
52 GUIObject();
~GUIObject()53 virtual ~GUIObject() {}
54
55 String GetEventArgs(int event) const;
56 int GetEventCount() const;
57 String GetEventName(int event) const;
58 bool IsDeleted() const;
59 // tells if control itself is enabled
60 bool IsEnabled() const;
61 // overridable routine to determine whether the mouse is over the control
62 virtual bool IsOverControl(int x, int y, int leeway) const;
63 bool IsTranslated() const;
64 bool IsVisible() const;
65 // implemented separately in engine and editor
66 bool IsClickable() const;
67
68 // Operations
Draw(Bitmap * ds)69 virtual void Draw(Bitmap *ds) {
70 }
71 void SetClickable(bool on);
72 void SetEnabled(bool on);
73 void SetTranslated(bool on);
74 void SetVisible(bool on);
75
76 // Events
77 // Key pressed for control
OnKeyPress(const KeyInput & ki)78 virtual void OnKeyPress(const KeyInput &ki) {}
79 // Mouse button down - return 'True' to lock focus
OnMouseDown()80 virtual bool OnMouseDown() {
81 return false;
82 }
83 // Mouse moves onto control
OnMouseEnter()84 virtual void OnMouseEnter() {
85 }
86 // Mouse moves off control
OnMouseLeave()87 virtual void OnMouseLeave() {
88 }
89 // Mouse moves over control - x,y relative to gui
OnMouseMove(int x,int y)90 virtual void OnMouseMove(int x, int y) {
91 }
92 // Mouse button up
OnMouseUp()93 virtual void OnMouseUp() {
94 }
95 // Control was resized
OnResized()96 virtual void OnResized() {
97 }
98
99 // Serialization
100 virtual void ReadFromFile(Shared::Stream *in, GuiVersion gui_version);
101 virtual void WriteToFile(Shared::Stream *out) const;
102 virtual void ReadFromSavegame(Shared::Stream *in, GuiSvgVersion svg_ver);
103 virtual void WriteToSavegame(Shared::Stream *out) const;
104
105 // TODO: these members are currently public; hide them later
106 public:
107 // Notifies parent GUI that this control has changed
108 void NotifyParentChanged();
109
110 int32_t Id; // GUI object's identifier
111 int32_t ParentId; // id of parent GUI
112 String Name; // script name
113
114 int32_t X;
115 int32_t Y;
116 int32_t Width;
117 int32_t Height;
118 int32_t ZOrder;
119 bool IsActivated; // signals user interaction
120
121 String EventHandlers[MAX_GUIOBJ_EVENTS]; // script function names
122
123 protected:
124 uint32_t Flags; // generic style and behavior flags
125
126 // TODO: explicit event names & handlers for every event
127 int32_t _scEventCount; // number of supported script events
128 String _scEventNames[MAX_GUIOBJ_EVENTS]; // script event names
129 String _scEventArgs[MAX_GUIOBJ_EVENTS]; // script handler params
130 };
131
132 // Converts legacy alignment type used in GUI Label/ListBox data (only left/right/center)
133 HorAlignment ConvertLegacyGUIAlignment(LegacyGUIAlignment align);
134
135 } // namespace Shared
136 } // namespace AGS
137
138 // Tells if all controls are disabled
139
140 // Tells if the given control is considered enabled, taking global flag into account
IsGUIEnabled(AGS::Shared::GUIObject * g)141 inline bool IsGUIEnabled(AGS::Shared::GUIObject *g) {
142 return !_G(all_buttons_disabled) && g->IsEnabled();
143 }
144
145 } // namespace AGS3
146
147 #endif
148