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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
#ifndef __EZ_BUTTON_H__
#define __EZ_BUTTON_H__
/*
Copyright (C) 2007 ezQuake team
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 2
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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
$Id: ez_button.h,v 1.55 2007-10-27 14:51:15 cokeman1982 Exp $
*/
#include "ez_controls.h"
#include "ez_label.h"
// =========================================================================================
// Button
// =========================================================================================
#define EZ_BUTTON_DEFAULT_NORMAL_IMAGE "gfx/ui/ez_button_normal"
#define EZ_BUTTON_DEFAULT_HOVER_IMAGE "gfx/ui/ez_button_hover"
#define EZ_BUTTON_DEFAULT_PRESSED_IMAGE "gfx/ui/ez_button_pressed"
#define EZ_BUTTON_DEFAULT_PRESSED_HOVER_IMAGE "gfx/ui/ez_button_pressed_hover"
typedef struct ez_button_eventcount_s
{
int OnAction;
int OnTextAlignmentChanged;
int OnToggled;
} ez_button_eventcount_t;
typedef struct ez_button_events_s
{
ez_event_fp OnAction; // The event that's raised when the button is clicked / activated via a button.
ez_event_fp OnTextAlignmentChanged; // Text alignment changed.
ez_event_fp OnToggled; // The button was toggled.
} ez_button_events_t;
typedef struct ez_button_eventhandlers_s
{
ez_eventhandler_t *OnAction;
ez_eventhandler_t *OnTextAlignmentChanged;
ez_eventhandler_t *OnToggled;
} ez_button_eventhandlers_t;
typedef enum ez_button_iflags_e
{
button_toggled = (1 << 0)
} ez_button_iflags_t;
typedef enum ez_button_flags_e
{
button_use_images = (1 << 0),
button_is_toggleable = (1 << 1)
} ez_button_flags_t;
typedef enum ez_textalign_e
{
top_left,
top_center,
top_right,
middle_left,
middle_center,
middle_right,
bottom_left,
bottom_center,
bottom_right
} ez_textalign_t;
typedef struct ez_button_s
{
ez_control_t super; // The super class.
ez_button_events_t events; // Specific events for the button control.
ez_button_eventhandlers_t event_handlers; // Specific event handlers for the button control.
ez_button_eventcount_t inherit_levels;
ez_button_eventcount_t override_counts;
ez_label_t *text_label; // The buttons text label.
mpic_t *focused_image; // The image for the button when it is focused.
mpic_t *normal_image; // The normal image used for the button.
mpic_t *hover_image; // The image that is shown for the button when the mouse is over it.
mpic_t *pressed_image; // The image that is shown when the button is pressed.
mpic_t *toggled_hover_image; // The image that is shown for the button when the mouse is over it while toggled.
byte color_focused[4]; // Color of the focus indicator of the button.
byte color_normal[4]; // The normal color of the button.
byte color_hover[4]; // Color when the button is hovered.
byte color_pressed[4]; // Color when the button is pressed.
byte color_toggled_hover[4]; // Color when the button is hovered while toggled.
ez_button_iflags_t int_flags; // Internal flags.
ez_button_flags_t ext_flags; // External flags.
int padding_top;
int padding_left;
int padding_right;
int padding_bottom;
ez_textalign_t text_alignment; // Text alignment.
clrinfo_t focused_text_color; // Text color when the button is focused.
clrinfo_t normal_text_color; // Text color when the button is in it's normal state.
clrinfo_t hover_text_color; // Text color when the button is hovered.
clrinfo_t pressed_text_color; // Text color when the button is pressed.
int override_count; // These are needed so that subclasses can override button specific events.
int inheritance_level;
} ez_button_t;
//
// Button - Creates a new button and initializes it.
//
ez_button_t *EZ_button_Create(ez_tree_t *tree, ez_control_t *parent,
char *name, char *description,
int x, int y, int width, int height,
ez_control_flags_t flags);
//
// Button - Initializes a button.
//
void EZ_button_Init(ez_button_t *button, ez_tree_t *tree, ez_control_t *parent,
char *name, char *description,
int x, int y, int width, int height,
ez_control_flags_t flags);
//
// Button - Destroys the button.
//
void EZ_button_Destroy(ez_control_t *self, qbool destroy_children);
//
// Button - OnTextAlignmentChanged event.
//
int EZ_button_OnTextAlignmentChanged(ez_control_t *self, void *ext_event_info);
//
// Button - OnAction event handler.
//
int EZ_button_OnAction(ez_control_t *self, void *ext_event_info);
//
// Button - OnResize event handler.
//
int EZ_button_OnResize(ez_control_t *self, void *ext_event_info);
//
// Button - Use images for the button?
//
void EZ_button_SetUseImages(ez_button_t *button, qbool useimages);
//
// Button - Sets if the button is toggleable.
//
void EZ_button_SetToggleable(ez_button_t *button, qbool toggleable);
//
// Button - Gets if the button is toggled.
//
qbool EZ_button_GetIsToggled(ez_button_t *button);
//
// Button - Set the text of the button.
//
void EZ_button_SetText(ez_button_t *button, const char *text);
//
// Button - Set the text of the button.
//
void EZ_button_SetTextAlignment(ez_button_t *button, ez_textalign_t text_alignment);
//
// Button - Set if the edges of the button should be tiled or stretched.
//
void EZ_button_SetTileCenter(ez_button_t *button, qbool tileedges);
//
// Button - Set if the center of the button should be tiled or stretched.
//
void EZ_button_SetTileCenter(ez_button_t *button, qbool tilecenter);
//
// Button - Set the event handler for the OnTextAlignmentChanged event.
//
void EZ_button_AddOnTextAlignmentChanged(ez_button_t *button, ez_eventhandler_fp OnTextAlignmentChanged, void *payload);
//
// Button - Set the normal image for the button.
//
void EZ_button_SetNormalImage(ez_button_t *button, const char *normal_image);
//
// Button - Set the hover image for the button.
//
void EZ_button_SetHoverImage(ez_button_t *button, const char *hover_image);
//
// Button - Set the hover image for the button.
//
void EZ_button_SetPressedImage(ez_button_t *button, const char *pressed_image);
//
// Button - Set the hover image for the button when it is toggled.
//
void EZ_button_SetToggledHoverImage(ez_button_t *button, const char *toggled_hover_image);
//
// Button - Sets the normal color of the button.
//
void EZ_button_SetNormalColor(ez_button_t *self, byte r, byte g, byte b, byte alpha);
//
// Button - Sets the pressed color of the button.
//
void EZ_button_SetPressedColor(ez_button_t *self, byte r, byte g, byte b, byte alpha);
//
// Button - Sets the hover color of the button.
//
void EZ_button_SetHoverColor(ez_button_t *self, byte r, byte g, byte b, byte alpha);
//
// Button - Sets the toggled hover color of the button.
//
void EZ_button_SetToggledHoverColor(ez_button_t *self, byte r, byte g, byte b, byte alpha);
//
// Button - Sets the focused color of the button.
//
void EZ_button_SetFocusedColor(ez_button_t *self, byte r, byte g, byte b, byte alpha);
//
// Button - Sets the OnAction event handler.
//
void EZ_button_AddOnAction(ez_button_t *self, ez_eventhandler_fp OnAction, void *payload);
//
// Button - Sets the OnAction event handler.
//
void EZ_button_AddOnToggled(ez_button_t *self, ez_eventhandler_fp OnToggled, void *payload);
//
// Button - OnDraw event.
//
int EZ_button_OnDraw(ez_control_t *self, void *ext_event_info);
//
// Button - OnMouseClick event.
//
int EZ_button_OnMouseClick(ez_control_t *self, mouse_state_t *mouse_state);
//
// Button - OnToggled event. The button was toggled.
//
int EZ_button_OnToggled(ez_control_t *self, void *ext_event_info);
//
// Button - OnMouseEnter event.
//
int EZ_button_OnMouseEnter(ez_control_t *self, mouse_state_t *mouse_state);
//
// Button - OnMouseLeave event.
//
int EZ_button_OnMouseLeave(ez_control_t *self, mouse_state_t *mouse_state);
//
// Button - OnMouseDown event.
//
int EZ_button_OnMouseDown(ez_control_t *self, mouse_state_t *mouse_state);
//
// Button - OnMouseDown event.
//
int EZ_button_OnMouseUp(ez_control_t *self, mouse_state_t *mouse_state);
#endif // __EZ_BUTTON_H__
|