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/* This is a very generic button widget - NOT ANY LONGER*/
23
24#ifndef NUVIE_GUI_GUI_BUTTON_H
25#define NUVIE_GUI_GUI_BUTTON_H
26
27#include "ultima/nuvie/gui/widgets/gui_widget.h"
28#include "ultima/nuvie/gui/gui_font.h"
29
30namespace Ultima {
31namespace Nuvie {
32
33class GUI_CallBack;
34
35/* design constants */
36#define BUTTON3D_UP 1
37#define BUTTON3D_DOWN 2
38#define BUTTON2D_UP 3
39#define BUTTON2D_DOWN 4
40
41/* alignment constants */
42enum ButtonTextAlign {
43 BUTTON_TEXTALIGN_LEFT = 1,
44 BUTTON_TEXTALIGN_CENTER = 2,
45 BUTTON_TEXTALIGN_RIGHT = 3,
46};
47
48// Callback message types
49
50static const uint16 BUTTON_CB = 0x1;
51
52/* color constants */
53
54// Button face color
55static const uint8 BF_R = 183, BF_G = 185, BF_B = 150;
56// Button light color
57static const uint8 BL_R = 245, BL_G = 247, BL_B = 201;
58// Button shadow color
59static const uint8 BS_R = 115, BS_G = 116, BS_B = 94;
60// 2D Button inverse text color
61static const uint8 BI1_R = 255, BI1_G = 255, BI1_B = 255;
62// 2D Button inverse background color
63static const uint8 BI2_R = 0, BI2_G = 0, BI2_B = 0;
64
65#define GUI_BUTTON_DONT_FREE_SURFACES false
66
67/* This is the definition of the "I've been activated" callback */
68typedef GUI_status(*GUI_ActiveProc)(void *data);
69
70class GUI_Button : public GUI_Widget {
71
72public:
73 /* Passed the button data, position, images (pressed/unpressed) and callback */
74 GUI_Button(void *data, int x, int y, Graphics::ManagedSurface *image,
75 Graphics::ManagedSurface *image2, GUI_CallBack *callback, bool free_surfaces = true);
76
77 /* I don't know what this one is for */
78 GUI_Button(void *data, int x, int y, int w, int h,
79 GUI_CallBack *callback);
80
81 /* Passed the button data, position, width, height, a caption, a font,
82 an alignment (enum above), if it should be a checkbutton (1/0),
83 the callback and a flag if it should be 2D (1) or 3D (0) */
84 GUI_Button(void *data, int x, int y, int w, int h, const char *text,
85 GUI_Font *font, ButtonTextAlign alignment, bool is_checkbutton,
86 GUI_CallBack *callback, bool flat = false);
87
88 ~GUI_Button() override;
89
90 /* change features of a text button (if one of the dimensions is negativ, it's ignored) */
91 virtual void ChangeTextButton(int x, int y, int w, int h, const char *text, ButtonTextAlign alignment);
92
93 /* Show the widget */
94 void Display(bool full_redraw) override;
95
96 /* Mouse hits activate us */
97 GUI_status MouseDown(int x, int y, Events::MouseButton button) override;
98 GUI_status MouseUp(int x, int y, Events::MouseButton button) override;
99 GUI_status MouseMotion(int x, int y, uint8 state) override;
100
101 /* Clickable or not ... */
102 virtual void Disable();
103 virtual void Enable(bool flag = true);
104
105 /* yields current state */
106 virtual bool Enabled() {
107 return enabled;
108 }
109
110 /* yields flag if button is a checkbutton */
111 virtual bool IsCheckButton() {
112 return is_checkable;
113 }
114 virtual void set_highlighted(bool val) {
115 is_highlighted = val;
116 }
117 virtual GUI_status Activate_button(int x = 0, int y = 0, Events::MouseButton button = Events::BUTTON_LEFT);
118
119protected:
120 /* yields an appropriate image */
121 virtual Graphics::ManagedSurface *CreateTextButtonImage(int style, const char *text, ButtonTextAlign alignment);
122
123 /* The button font */
124 GUI_Font *buttonFont;
125
126 /* The button images */
127 Graphics::ManagedSurface *button, *button2;
128
129 /* The activation callback */
130 GUI_CallBack *callback_object;
131
132 /* remember me! - flags */
133 bool enabled;
134 bool flatbutton;
135 bool freebutton;
136 bool freefont;
137
138 /* Checkbutton flags */
139 bool is_checkable;
140 int checked;
141 bool is_highlighted;
142};
143
144} // End of namespace Nuvie
145} // End of namespace Ultima
146
147#endif
Definition: managed_surface.h:51
Definition: gui_button.h:70
Definition: gui_callback.h:31
Definition: gui_font.h:36
Definition: gui_widget.h:38