File: gui_object.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (172 lines) | stat: -rw-r--r-- 6,201 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef AGS_SHARED_GUI_GUI_OBJECT_H
#define AGS_SHARED_GUI_GUI_OBJECT_H

#include "ags/shared/core/types.h"
#include "ags/shared/gfx/bitmap.h"
#include "ags/shared/gui/gui_defines.h"
#include "ags/shared/util/string.h"
#include "ags/globals.h"

namespace AGS3 {

struct KeyInput;

namespace AGS {
namespace Shared {

enum LegacyGUIAlignment {
	kLegacyGUIAlign_Left = 0,
	kLegacyGUIAlign_Right = 1,
	kLegacyGUIAlign_Center = 2
};

class GUIObject {
public:
	GUIObject();
	virtual ~GUIObject() {}

	String          GetScriptName() const;

	String          GetEventArgs(int event) const;
	int             GetEventCount() const;
	String          GetEventName(int event) const;
	bool			IsClickable() const { return (Flags & kGUICtrl_Clickable) != 0; }
	bool			IsDeleted() const { return (Flags & kGUICtrl_Deleted) != 0; }
	bool			IsEnabled() const { return (Flags & kGUICtrl_Enabled) != 0; }
	bool			IsTranslated() const { return (Flags & kGUICtrl_Translated) != 0; }
	bool			IsVisible() const { return (Flags & kGUICtrl_Visible) != 0; }
	// overridable routine to determine whether the mouse is over the control
	virtual bool    IsOverControl(int x, int y, int leeway) const;
	Size            GetSize() const { return Size(_width, _height); }
	int             GetWidth() const { return _width; }
	int             GetHeight() const { return _height; }
	int             GetTransparency() const { return _transparency; }
	// Compatibility: should the control's graphic be clipped to its x,y,w,h
    virtual bool    IsContentClipped() const { return true; }
	// Tells if the object image supports alpha channel
	virtual bool    HasAlphaChannel() const { return false; }

	// Operations
	// Returns the (untransformed!) visual rectangle of this control,
	// in *relative* coordinates, optionally clipped by the logical size
	virtual Rect    CalcGraphicRect(bool /*clipped*/) {
		return RectWH(0, 0, _width, _height);
	}
	virtual void    Draw(Bitmap *ds, int x = 0, int y = 0) {
		(void)ds; (void)x; (void)y;
	}
	void            SetClickable(bool on);
	void            SetEnabled(bool on);
	void            SetSize(int width, int height);
	inline void     SetWidth(int width) { SetSize(width, _height); }
	inline void     SetHeight(int height) { SetSize(_width, height); }
	void            SetTranslated(bool on);
	void            SetVisible(bool on);
	void            SetTransparency(int trans);

	// Events
	// Key pressed for control
	virtual void    OnKeyPress(const KeyInput &) {}
	// Mouse button down - return 'True' to lock focus
	virtual bool    OnMouseDown() {
		return false;
	}
	// Mouse moves onto control
	virtual void    OnMouseEnter() {
	}
	// Mouse moves off control
	virtual void    OnMouseLeave() {
	}
	// Mouse moves over control - x,y relative to gui
	virtual void    OnMouseMove(int /*x*/, int /*y*/) {
	}
	// Mouse button up
	virtual void    OnMouseUp() {
	}
	// Control was resized
	virtual void    OnResized() { MarkPositionChanged(true); }

	// Serialization
	virtual void    ReadFromFile(Shared::Stream *in, GuiVersion gui_version);
	virtual void    WriteToFile(Shared::Stream *out) const;
	virtual void    ReadFromSavegame(Shared::Stream *in, GuiSvgVersion svg_ver);
	virtual void    WriteToSavegame(Shared::Stream *out) const;

	// TODO: these members are currently public; hide them later
public:
	// Manually marks GUIObject as graphically changed
	// NOTE: this only matters if control's own graphic changes, but not its
	// logical (visible, clickable, etc) or visual (e.g. transparency) state.
	void	MarkChanged();
	// Notifies parent GUI that this control has changed its visual state
	void	MarkParentChanged();
	// Notifies parent GUI that this control has changed its location (pos, size)
	void	MarkPositionChanged(bool self_changed);
	// Notifies parent GUI that this control's interactive state has changed
	void	MarkStateChanged(bool self_changed, bool parent_changed);
	bool	HasChanged() const { return _hasChanged; };
	void	ClearChanged();

	int32_t  Id;         // GUI object's identifier
	int32_t  ParentId;   // id of parent GUI
	String   Name;       // script name

	int32_t  X;
	int32_t  Y;
	int32_t  ZOrder;
	bool     IsActivated; // signals user interaction

	String   EventHandlers[MAX_GUIOBJ_EVENTS]; // script function names

protected:
	uint32_t Flags;      // generic style and behavior flags
	int32_t  _width;
	int32_t  _height;
	int32_t  _transparency; // "incorrect" alpha (in legacy 255-range units)
	bool     _hasChanged;

	// TODO: explicit event names & handlers for every event
    // FIXME: these must be static!! per type
	int32_t  _scEventCount;                    // number of supported script events
	String   _scEventNames[MAX_GUIOBJ_EVENTS]; // script event names
	String   _scEventArgs[MAX_GUIOBJ_EVENTS];  // script handler params
};

// Converts legacy alignment type used in GUI Label/ListBox data (only left/right/center)
HorAlignment ConvertLegacyGUIAlignment(LegacyGUIAlignment align);
LegacyGUIAlignment GetLegacyGUIAlignment(HorAlignment align);

} // namespace Shared
} // namespace AGS

// Tells if all controls are disabled

// Tells if the given control is considered enabled, taking global flag into account
inline bool IsGUIEnabled(AGS::Shared::GUIObject *g) {
	return (_G(all_buttons_disabled) < 0) && g->IsEnabled();
}

} // namespace AGS3

#endif