ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gui_object.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 AGS_SHARED_GUI_GUI_OBJECT_H
23 #define AGS_SHARED_GUI_GUI_OBJECT_H
24 
25 #include "ags/shared/core/types.h"
26 #include "ags/shared/gfx/bitmap.h"
27 #include "ags/shared/gui/gui_defines.h"
28 #include "ags/shared/util/string.h"
29 #include "ags/globals.h"
30 
31 namespace AGS3 {
32 
33 struct KeyInput;
34 
35 namespace AGS {
36 namespace Shared {
37 
38 enum LegacyGUIAlignment {
39  kLegacyGUIAlign_Left = 0,
40  kLegacyGUIAlign_Right = 1,
41  kLegacyGUIAlign_Center = 2
42 };
43 
44 class GUIObject {
45 public:
46  GUIObject();
47  virtual ~GUIObject() {}
48 
49  String GetScriptName() const;
50 
51  String GetEventArgs(int event) const;
52  int GetEventCount() const;
53  String GetEventName(int event) const;
54  bool IsClickable() const { return (Flags & kGUICtrl_Clickable) != 0; }
55  bool IsDeleted() const { return (Flags & kGUICtrl_Deleted) != 0; }
56  bool IsEnabled() const { return (Flags & kGUICtrl_Enabled) != 0; }
57  bool IsTranslated() const { return (Flags & kGUICtrl_Translated) != 0; }
58  bool IsVisible() const { return (Flags & kGUICtrl_Visible) != 0; }
59  // overridable routine to determine whether the mouse is over the control
60  virtual bool IsOverControl(int x, int y, int leeway) const;
61  Size GetSize() const { return Size(_width, _height); }
62  int GetWidth() const { return _width; }
63  int GetHeight() const { return _height; }
64  int GetTransparency() const { return _transparency; }
65  // Compatibility: should the control's graphic be clipped to its x,y,w,h
66  virtual bool IsContentClipped() const { return true; }
67  // Tells if the object image supports alpha channel
68  virtual bool HasAlphaChannel() const { return false; }
69 
70  // Operations
71  // Returns the (untransformed!) visual rectangle of this control,
72  // in *relative* coordinates, optionally clipped by the logical size
73  virtual Rect CalcGraphicRect(bool /*clipped*/) {
74  return RectWH(0, 0, _width, _height);
75  }
76  virtual void Draw(Bitmap *ds, int x = 0, int y = 0) {
77  (void)ds; (void)x; (void)y;
78  }
79  void SetClickable(bool on);
80  void SetEnabled(bool on);
81  void SetSize(int width, int height);
82  inline void SetWidth(int width) { SetSize(width, _height); }
83  inline void SetHeight(int height) { SetSize(_width, height); }
84  void SetTranslated(bool on);
85  void SetVisible(bool on);
86  void SetTransparency(int trans);
87 
88  // Events
89  // Key pressed for control
90  virtual void OnKeyPress(const KeyInput &) {}
91  // Mouse button down - return 'True' to lock focus
92  virtual bool OnMouseDown() {
93  return false;
94  }
95  // Mouse moves onto control
96  virtual void OnMouseEnter() {
97  }
98  // Mouse moves off control
99  virtual void OnMouseLeave() {
100  }
101  // Mouse moves over control - x,y relative to gui
102  virtual void OnMouseMove(int /*x*/, int /*y*/) {
103  }
104  // Mouse button up
105  virtual void OnMouseUp() {
106  }
107  // Control was resized
108  virtual void OnResized() { MarkPositionChanged(true); }
109 
110  // Serialization
111  virtual void ReadFromFile(Shared::Stream *in, GuiVersion gui_version);
112  virtual void WriteToFile(Shared::Stream *out) const;
113  virtual void ReadFromSavegame(Shared::Stream *in, GuiSvgVersion svg_ver);
114  virtual void WriteToSavegame(Shared::Stream *out) const;
115 
116  // TODO: these members are currently public; hide them later
117 public:
118  // Manually marks GUIObject as graphically changed
119  // NOTE: this only matters if control's own graphic changes, but not its
120  // logical (visible, clickable, etc) or visual (e.g. transparency) state.
121  void MarkChanged();
122  // Notifies parent GUI that this control has changed its visual state
123  void MarkParentChanged();
124  // Notifies parent GUI that this control has changed its location (pos, size)
125  void MarkPositionChanged(bool self_changed);
126  // Notifies parent GUI that this control's interactive state has changed
127  void MarkStateChanged(bool self_changed, bool parent_changed);
128  bool HasChanged() const { return _hasChanged; };
129  void ClearChanged();
130 
131  int32_t Id; // GUI object's identifier
132  int32_t ParentId; // id of parent GUI
133  String Name; // script name
134 
135  int32_t X;
136  int32_t Y;
137  int32_t ZOrder;
138  bool IsActivated; // signals user interaction
139 
140  String EventHandlers[MAX_GUIOBJ_EVENTS]; // script function names
141 
142 protected:
143  uint32_t Flags; // generic style and behavior flags
144  int32_t _width;
145  int32_t _height;
146  int32_t _transparency; // "incorrect" alpha (in legacy 255-range units)
147  bool _hasChanged;
148 
149  // TODO: explicit event names & handlers for every event
150  // FIXME: these must be static!! per type
151  int32_t _scEventCount; // number of supported script events
152  String _scEventNames[MAX_GUIOBJ_EVENTS]; // script event names
153  String _scEventArgs[MAX_GUIOBJ_EVENTS]; // script handler params
154 };
155 
156 // Converts legacy alignment type used in GUI Label/ListBox data (only left/right/center)
157 HorAlignment ConvertLegacyGUIAlignment(LegacyGUIAlignment align);
158 LegacyGUIAlignment GetLegacyGUIAlignment(HorAlignment align);
159 
160 } // namespace Shared
161 } // namespace AGS
162 
163 // Tells if all controls are disabled
164 
165 // Tells if the given control is considered enabled, taking global flag into account
166 inline bool IsGUIEnabled(AGS::Shared::GUIObject *g) {
167  return (_G(all_buttons_disabled) < 0) && g->IsEnabled();
168 }
169 
170 } // namespace AGS3
171 
172 #endif
Definition: achievements_tables.h:27
Definition: allegro_bitmap.h:44
Definition: gui_object.h:44
Definition: geometry.h:219
Definition: string.h:62
Definition: geometry.h:148
Definition: keycode.h:281
Definition: stream.h:52
Definition: ags.h:40