ScummVM API documentation
gui_button.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_BUTTON_H
23#define AGS_SHARED_GUI_GUI_BUTTON_H
24
25#include "common/std/vector.h"
26#include "ags/engine/ac/button.h"
27#include "ags/shared/gui/gui_object.h"
28#include "ags/shared/util/string.h"
29
30namespace AGS3 {
31
32#define GUIBUTTON_LEGACY_TEXTLENGTH 50
33
34namespace AGS {
35namespace Shared {
36
37enum GUIClickMouseButton {
38 kGUIClickLeft = 0,
39 kGUIClickRight = 1,
40 kNumGUIClicks
41};
42
43enum GUIClickAction {
44 kGUIAction_None = 0,
45 kGUIAction_SetMode = 1,
46 kGUIAction_RunScript = 2,
47};
48
49enum LegacyButtonAlignment {
50 kLegacyButtonAlign_TopCenter = 0,
51 kLegacyButtonAlign_TopLeft = 1,
52 kLegacyButtonAlign_TopRight = 2,
53 kLegacyButtonAlign_CenterLeft = 3,
54 kLegacyButtonAlign_Centered = 4,
55 kLegacyButtonAlign_CenterRight = 5,
56 kLegacyButtonAlign_BottomLeft = 6,
57 kLegacyButtonAlign_BottomCenter = 7,
58 kLegacyButtonAlign_BottomRight = 8,
59};
60
61// Defines button placeholder mode; the mode is set
62// depending on special tags found in button text
63enum GUIButtonPlaceholder {
64 kButtonPlace_None,
65 kButtonPlace_InvItemStretch,
66 kButtonPlace_InvItemCenter,
67 kButtonPlace_InvItemAuto
68};
69
70class GUIButton : public GUIObject {
71public:
72 GUIButton();
73
74 bool HasAlphaChannel() const override;
75 int32_t GetCurrentImage() const;
76 int32_t GetNormalImage() const;
77 int32_t GetMouseOverImage() const;
78 int32_t GetPushedImage() const;
79 GUIButtonPlaceholder GetPlaceholder() const;
80 const String &GetText() const;
81 bool IsImageButton() const;
82 bool IsClippingImage() const;
83
84 // Operations
85 Rect CalcGraphicRect(bool clipped) override;
86 void Draw(Bitmap *ds, int x = 0, int y = 0) override;
87 void SetClipImage(bool on);
88 void SetCurrentImage(int32_t image);
89 void SetMouseOverImage(int32_t image);
90 void SetNormalImage(int32_t image);
91 void SetPushedImage(int32_t image);
92 void SetImages(int32_t normal, int32_t over, int32_t pushed);
93 void SetText(const String &text);
94
95 // Events
96 bool OnMouseDown() override;
97 void OnMouseEnter() override;
98 void OnMouseLeave() override;
99 void OnMouseUp() override;
100
101 // Serialization
102 void ReadFromFile(Stream *in, GuiVersion gui_version) override;
103 void WriteToFile(Stream *out) const override;
104 void ReadFromSavegame(Shared::Stream *in, GuiSvgVersion svg_ver) override;
105 void WriteToSavegame(Shared::Stream *out) const override;
106
107 // TODO: these members are currently public; hide them later
108 public:
109 int32_t Font;
110 color_t TextColor;
111 FrameAlignment TextAlignment;
112 // Click actions for left and right mouse buttons
113 // NOTE: only left click is currently in use
114 GUIClickAction ClickAction[kNumGUIClicks];
115 int32_t ClickData[kNumGUIClicks];
116
117 bool IsPushed;
118 bool IsMouseOver;
119
120private:
121 void DrawImageButton(Bitmap *ds, int x, int y, bool draw_disabled);
122 void DrawText(Bitmap *ds, int x, int y, bool draw_disabled);
123 void DrawTextButton(Bitmap *ds, int x, int y, bool draw_disabled);
124 void PrepareTextToDraw();
125 // Update current image depending on the button's state
126 void UpdateCurrentImage();
127
128 int32_t _image;
129 int32_t _mouseOverImage;
130 int32_t _pushedImage;
131 // Active displayed image
132 int32_t _currentImage;
133 // Text property set by user
134 String _text;
135 // type of content placeholder, if any
136 GUIButtonPlaceholder _placeholder;
137 // A flag indicating unnamed button; this is a convenience trick:
138 // buttons are created named "New Button" in the editor, and users
139 // often do not clear text when they want a graphic button.
140 bool _unnamed;
141 // Prepared text buffer/cache
142 String _textToDraw;
143};
144
145} // namespace Shared
146} // namespace AGS
147
148} // namespace AGS3
149
150#endif
Definition: allegro_bitmap.h:44
Definition: gui_button.h:70
Definition: gui_object.h:44
Definition: stream.h:52
Definition: string.h:60
Definition: fonts.h:43
Definition: geometry.h:219