1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * Declares Button widget, for displaying buttons in the GUI
24 * @author GemRB Development Team
41 // NOTE: keep these synchronized with GUIDefines.py!!!
42 #define IE_GUI_BUTTON_UNPRESSED 0
43 #define IE_GUI_BUTTON_PRESSED 1
44 #define IE_GUI_BUTTON_SELECTED 2
45 #define IE_GUI_BUTTON_DISABLED 3
46 // Like DISABLED, but processes MouseOver events and draws UNPRESSED bitmap
47 #define IE_GUI_BUTTON_LOCKED 4
48 // Draws the disabled bitmap, but otherwise works like unpressed
49 #define IE_GUI_BUTTON_THIRD 5
50 #define IE_GUI_BUTTON_SECOND 6
51 #define IE_GUI_BUTTON_LOCKED_PRESSED 7 //all the same as LOCKED
53 #define IE_GUI_BUTTON_NO_IMAGE 0x00000001 // don't draw image (BAM)
54 #define IE_GUI_BUTTON_PICTURE 0x00000002 // draw picture (BMP, MOS, ...)
55 #define IE_GUI_BUTTON_SOUND 0x00000004
56 #define IE_GUI_BUTTON_ALT_SOUND 0x00000008
57 #define IE_GUI_BUTTON_CHECKBOX 0x00000010 // or radio button
58 #define IE_GUI_BUTTON_RADIOBUTTON 0x00000020 // sticks in a state
59 #define IE_GUI_BUTTON_DEFAULT 0x00000040 // enter key triggers it
60 #define IE_GUI_BUTTON_ANIMATED 0x00000080
62 //these bits are hardcoded in the .chu structure
63 #define IE_GUI_BUTTON_ALIGN_LEFT 0x00000100
64 #define IE_GUI_BUTTON_ALIGN_RIGHT 0x00000200
65 #define IE_GUI_BUTTON_ALIGN_TOP 0x00000400
66 #define IE_GUI_BUTTON_ALIGN_BOTTOM 0x00000800
67 #define IE_GUI_BUTTON_ANCHOR 0x00001000 //not implemented yet
68 #define IE_GUI_BUTTON_LOWERCASE 0x00002000
69 //end of hardcoded part
70 #define IE_GUI_BUTTON_DRAGGABLE 0x00004000
71 #define IE_GUI_BUTTON_MULTILINE 0x00008000 // don't set the single line flag
72 #define IE_GUI_BUTTON_NO_TEXT 0x00010000 // don't draw button label
73 #define IE_GUI_BUTTON_PLAYRANDOM 0x00020000
74 #define IE_GUI_BUTTON_PLAYONCE 0x00040000
76 #define IE_GUI_BUTTON_CENTER_PICTURES 0x00080000 // center button's PictureList
77 #define IE_GUI_BUTTON_BG1_PAPERDOLL 0x00100000 // BG1-style paperdoll PictureList
78 #define IE_GUI_BUTTON_HORIZONTAL 0x00200000 // horizontal clipping of overlay
79 #define IE_GUI_BUTTON_CANCEL 0x00400000 // cancel key triggers it
80 #define IE_GUI_BUTTON_CAPS 0x00800000 // convert text to uppercase
82 #define IE_GUI_BUTTON_NORMAL 0x00000004 // default button, doesn't stick
84 // !!! Keep these synchronized with GUIDefines.py !!!
85 #define IE_GUI_BUTTON_ON_PRESS 0x00000000
86 #define IE_GUI_MOUSE_OVER_BUTTON 0x00000001
87 #define IE_GUI_MOUSE_ENTER_BUTTON 0x00000002
88 #define IE_GUI_MOUSE_LEAVE_BUTTON 0x00000003
89 #define IE_GUI_BUTTON_ON_SHIFT_PRESS 0x00000004
90 #define IE_GUI_BUTTON_ON_RIGHT_PRESS 0x00000005
91 #define IE_GUI_BUTTON_ON_DRAG_DROP 0x00000006
92 #define IE_GUI_BUTTON_ON_DRAG_DROP_PORTRAIT 0x00000007
93 #define IE_GUI_BUTTON_ON_DRAG 0x00000008
94 #define IE_GUI_BUTTON_ON_DOUBLE_PRESS 0x00000009
96 /** Border/frame settings for a button */
107 #define MAX_NUM_BORDERS 3
112 * Button widget, used mainly for buttons, but also for PixMaps (static images)
113 * or for Toggle Buttons.
116 class GEM_EXPORT Button
: public Control
{
120 /** Sets the 'type' Image of the Button to 'img'.
121 'type' may assume the following values:
122 - IE_GUI_BUTTON_UNPRESSED
123 - IE_GUI_BUTTON_PRESSED
124 - IE_GUI_BUTTON_SELECTED
125 - IE_GUI_BUTTON_DISABLED */
126 void SetImage(unsigned char type
, Sprite2D
* img
);
127 /** Draws the Control on the Output Display */
128 void Draw(unsigned short x
, unsigned short y
);
129 /** Sets the Button State */
130 void SetState(unsigned char state
);
131 /** Sets the Text of the current control */
132 int SetText(const char* string
, int pos
= 0);
133 /** Sets the Picture */
134 void SetPicture(Sprite2D
* Picture
);
135 /** Clears the list of Pictures */
136 void ClearPictureList();
137 /** Add picture to the end of the list of Pictures */
138 void StackPicture(Sprite2D
* Picture
);
139 /** Sets border/frame parameters */
140 void SetBorder(int index
, int dx1
, int dy1
, int dx2
, int dy2
, const Color
&color
, bool enabled
= false, bool filled
= false);
141 /** Sets horizontal overlay, used in portrait hp overlay */
142 void SetHorizontalOverlay(double clip
, const Color
&src
, const Color
&dest
);
143 /** Sets font used for drawing button label */
144 void SetFont(Font
* newfont
);
145 /** Enables or disables specified border/frame */
146 void EnableBorder(int index
, bool enabled
);
147 public: // Public Events
149 void OnMouseEnter(unsigned short x
, unsigned short y
);
151 void OnMouseLeave(unsigned short x
, unsigned short y
);
153 void OnMouseOver(unsigned short x
, unsigned short y
);
154 /** Mouse Button Down */
155 void OnMouseDown(unsigned short x
, unsigned short y
, unsigned short Button
,
157 /** Mouse Button Up */
158 void OnMouseUp(unsigned short x
, unsigned short y
, unsigned short Button
,
160 /** A special key has been pressed */
161 void OnSpecialKeyPress(unsigned char Key
);
162 /** Set handler for specified event */
163 bool SetEvent(int eventType
, const char *handler
);
164 /** Button Pressed Event Script Function Name */
165 EventHandler ButtonOnPress
;
166 EventHandler ButtonOnShiftPress
;
167 EventHandler ButtonOnRightPress
;
168 EventHandler ButtonOnDoublePress
;
169 EventHandler ButtonOnDragDrop
;
170 EventHandler ButtonOnDragDropPortrait
;
171 EventHandler ButtonOnDrag
;
172 EventHandler MouseEnterButton
;
173 EventHandler MouseLeaveButton
;
174 EventHandler MouseOverButton
;
175 /** Refreshes the button from a radio group */
176 void RedrawButton(const char* VariableName
, unsigned int Sum
);
177 /** Set palette used for drawing button label in normal state. */
178 void SetTextColor(const Color
&fore
, const Color
&back
);
179 /** Sets percent (0-1.0) of width for clipping picture */
180 void SetPictureClipping(double clip
) { Clipping
= clip
; }
181 private: // Private attributes
186 Palette
* normal_palette
;
187 Palette
* disabled_palette
;
188 /** Button Unpressed Image */
190 /** Button Pressed Image */
192 /** Button Selected Image */
194 /** Button Disabled Image */
196 /** Pictures to Apply when the hasPicture flag is set */
198 /** If non-empty, list of Pictures to draw when hasPicture is set */
199 std::list
<Sprite2D
*> PictureList
;
200 /** The current state of the Button */
204 /** HP Bar over portraits */
205 unsigned long starttime
;
206 Color SourceRGB
, DestRGB
;
207 /** frame settings */
208 ButtonBorder borders
[MAX_NUM_BORDERS
];
209 bool IsPixelTransparent (unsigned short x
, unsigned short y
);