1 /*************************************************************************** 2 gui.h -- Interface file for GUI 3 ------------------- 4 created : Fri Aug 13 22:15:46 CEST 1999 5 copyright : (C) 1999 by Eric Espie 6 email : torcs@free.fr 7 version : $Id: gui.h,v 1.2.2.3 2011/12/29 16:14:21 berniw Exp $ 8 ***************************************************************************/ 9 10 /*************************************************************************** 11 * * 12 * This program is free software; you can redistribute it and/or modify * 13 * it under the terms of the GNU General Public License as published by * 14 * the Free Software Foundation; either version 2 of the License, or * 15 * (at your option) any later version. * 16 * * 17 ***************************************************************************/ 18 19 #ifndef _GUI_H__ 20 #define _GUI_H__ 21 22 #include "guifont.h" 23 24 #define GFUI_COLORNB 21 25 extern float GfuiColor[GFUI_COLORNB][4]; 26 27 #define GFUI_BGCOLOR 0 28 #define GFUI_TITLECOLOR 1 29 #define GFUI_BGBTNFOCUS 2 30 #define GFUI_BGBTNCLICK 3 31 #define GFUI_BGBTNENABLED 4 32 #define GFUI_BGBTNDISABLED 5 33 #define GFUI_BTNFOCUS 6 34 #define GFUI_BTNCLICK 7 35 #define GFUI_BTNENABLED 8 36 #define GFUI_BTNDISABLED 9 37 #define GFUI_LABELCOLOR 10 38 #define GFUI_TIPCOLOR 11 39 #define GFUI_MOUSECOLOR1 12 40 #define GFUI_MOUSECOLOR2 13 41 #define GFUI_HELPCOLOR1 14 42 #define GFUI_HELPCOLOR2 15 43 #define GFUI_BGSCROLLIST 16 44 #define GFUI_FGSCROLLIST 17 45 #define GFUI_BGSELSCROLLIST 18 46 #define GFUI_FGSELSCROLLIST 19 47 #define GFUI_EDITCURSORCLR 20 48 #define GFUI_IMAGE 21 49 50 class ForeGroundColor { 51 public: 52 /*ForeGroundColor(const float pr, const float pg, const float pb, const float pa) : 53 r(pr), g(pg), b(pb), a(pa) 54 {} 55 ForeGroundColor(const float prgba[4]) : 56 r(prgba[0]), g(prgba[1]), b(prgba[2]), a(prgba[3]) 57 {} 58 ForeGroundColor() : 59 r(0.0f), g(0.0f), b(0.0f), a(0.0f) 60 {} 61 virtual ~ForeGroundColor() {} 62 */ setRGBA(const float prgba[4])63 void setRGBA(const float prgba[4]) { 64 r = prgba[0]; 65 g = prgba[1]; 66 b = prgba[2]; 67 a = prgba[3]; 68 } getRGBA()69 const float* getRGBA() { return rgba; } 70 71 union { 72 struct { float r, g, b, a; }; 73 float rgba[4]; 74 }; 75 }; 76 77 78 typedef struct 79 { 80 char *text; /* text */ 81 float *bgColor; /* RGBA */ 82 ForeGroundColor fgColor; 83 GfuiFontClass *font; /* ttf font */ 84 int x, y; /* label position */ 85 int align; 86 int maxlen; 87 } tGfuiLabel; 88 89 /* button state */ 90 #define GFUI_BTN_DISABLE 0 91 #define GFUI_BTN_RELEASED 1 92 #define GFUI_BTN_PUSHED 2 93 94 /* Button type */ 95 #define GFUI_BTN_PUSH 0 96 #define GFUI_BTN_STATE 1 97 98 typedef struct 99 { 100 tGfuiLabel label; 101 float *bgColor[3]; 102 float *fgColor[3]; 103 float *bgFocusColor[3]; 104 float *fgFocusColor[3]; 105 unsigned int state; 106 int buttonType; 107 int mouseBehaviour; 108 void *userDataOnPush; 109 tfuiCallback onPush; 110 void *userDataOnFocus; 111 tfuiCallback onFocus; 112 tfuiCallback onFocusLost; 113 } tGfuiButton; 114 115 typedef struct 116 { 117 unsigned int state; 118 unsigned char *disabled; 119 unsigned char *enabled; 120 unsigned char *focused; 121 unsigned char *pushed; 122 int width, height; 123 int buttonType; 124 int mouseBehaviour; 125 void *userDataOnPush; 126 tfuiCallback onPush; 127 void *userDataOnFocus; 128 tfuiCallback onFocus; 129 tfuiCallback onFocusLost; 130 } tGfuiGrButton; 131 132 #define GFUI_FOCUS_NONE 0 133 #define GFUI_FOCUS_MOUSE_MOVE 1 134 #define GFUI_FOCUS_MOUSE_CLICK 2 135 136 typedef struct GfuiListElement 137 { 138 char *name; 139 char *label; 140 void *userData; 141 int selected; 142 int index; 143 struct GfuiListElement *next; 144 struct GfuiListElement *prev; 145 } tGfuiListElement; 146 147 typedef struct 148 { 149 int sbPos; 150 float *bgColor[3]; 151 float *fgColor[3]; 152 float *bgSelectColor[3]; 153 float *fgSelectColor[3]; 154 GfuiFontClass *font; 155 tGfuiListElement *elts; 156 int nbElts; 157 int firstVisible; 158 int nbVisible; 159 int selectedElt; 160 int scrollBar; 161 tfuiCallback onSelect; 162 void *userDataOnSelect; 163 } tGfuiScrollList; 164 165 typedef struct 166 { 167 tScrollBarInfo info; 168 int min, max, len, pos; 169 int orientation; 170 void *userData; 171 tfuiSBCallback onScroll; 172 } tGfuiScrollBar; 173 174 typedef struct 175 { 176 tGfuiLabel label; 177 float *cursorColor[3]; 178 float *bgColor[3]; 179 float *fgColor[3]; 180 float *bgFocusColor[3]; 181 float *fgFocusColor[3]; 182 int state; 183 int cursorx; 184 int cursory1; 185 int cursory2; 186 int cursorIdx; 187 void *userDataOnFocus; 188 tfuiCallback onFocus; 189 tfuiCallback onFocusLost; 190 } tGfuiEditbox; 191 192 typedef struct 193 { 194 GLuint texture; 195 } tGfuiImage; 196 197 typedef struct GfuiObject 198 { 199 int widget; 200 int id; 201 int visible; 202 int focusMode; 203 int focus; 204 int state; /* enable / disable */ 205 int xmin, ymin; /* bounding box for focus */ 206 int xmax, ymax; 207 union 208 { 209 tGfuiLabel label; 210 tGfuiButton button; 211 tGfuiGrButton grbutton; 212 tGfuiScrollList scrollist; 213 tGfuiScrollBar scrollbar; 214 tGfuiEditbox editbox; 215 tGfuiImage image; 216 } u; 217 struct GfuiObject *next; 218 struct GfuiObject *prev; 219 } tGfuiObject; 220 221 /* Keyboard key assignment */ 222 typedef struct GfuiKey 223 { 224 unsigned char key; 225 char *name; 226 char *descr; 227 int specialkey; 228 int modifier; 229 void *userData; 230 tfuiCallback onPress; 231 tfuiCallback onRelease; 232 struct GfuiKey *next; 233 } tGfuiKey; 234 235 /* screen definition */ 236 typedef struct 237 { 238 float width, height; 239 float *bgColor; /* RGBA */ 240 GLuint bgImage; 241 242 /* sub-objects */ 243 tGfuiObject *objects; 244 tGfuiObject *hasFocus; /* in order to speed up focus management */ 245 int curId; 246 247 /* users keys definition */ 248 tGfuiKey *userKeys; 249 tGfuiKey *userSpecKeys; 250 void *userActData; 251 tfuiCallback onActivate; 252 void *userDeactData; 253 tfuiCallback onDeactivate; 254 255 /* key callback functions */ 256 tfuiKeyCallback onKeyAction; 257 tfuiSKeyCallback onSKeyAction; 258 259 /* mouse handling */ 260 int mouse; 261 int mouseAllowed; 262 float *mouseColor[2]; 263 264 /* menu specific */ 265 int nbItems; 266 267 /* Screen type */ 268 int onlyCallback; 269 } tGfuiScreen; 270 271 272 extern tGfuiScreen *GfuiScreen; 273 extern tMouseInfo GfuiMouse; 274 extern int GfuiMouseHW; 275 276 extern void gfuiReleaseObject(tGfuiObject *curObject); 277 278 extern void GfuiDrawCursor(); 279 extern void GfuiDraw(tGfuiObject *obj);; 280 extern void gfuiUpdateFocus(); 281 extern void gfuiPrintString(int x, int y, GfuiFontClass *font, const char *string); 282 extern void gfuiMouseAction(void *action); 283 extern void gfuiSelectNext(void *); 284 extern void gfuiSelectPrev(void *); 285 extern void gfuiSelectId(void *scr, int id); 286 extern void gfuiAddObject(tGfuiScreen *screen, tGfuiObject *object); 287 extern tGfuiObject *gfuiGetObject(void *scr, int id); 288 289 extern void gfuiSetLabelText(tGfuiObject *object, tGfuiLabel *label, const char *text); 290 291 extern void gfuiDrawLabel(tGfuiObject *obj); 292 extern void gfuiDrawButton(tGfuiObject *obj); 293 extern void gfuiButtonAction(int action); 294 extern void gfuiDrawGrButton(tGfuiObject *obj); 295 extern void gfuiGrButtonAction(int action); 296 extern void gfuiDrawScrollist(tGfuiObject *obj); 297 extern void gfuiScrollListAction(int mouse); 298 extern void gfuiDrawEditbox(tGfuiObject *obj); 299 extern void gfuiEditboxAction(int action); 300 301 extern void gfuiInit(void); 302 extern void gfuiButtonInit(void); 303 extern void gfuiHelpInit(void); 304 extern void gfuiLabelInit(void); 305 extern void gfuiObjectInit(void); 306 extern void gfuiEditboxInit(void); 307 308 extern void gfuiReleaseLabel(tGfuiObject *obj); 309 extern void gfuiReleaseButton(tGfuiObject *obj); 310 extern void gfuiReleaseGrButton(tGfuiObject *obj); 311 extern void gfuiReleaseScrollist(tGfuiObject *curObject); 312 extern void gfuiReleaseScrollbar(tGfuiObject *curObject); 313 extern void gfuiReleaseEditbox(tGfuiObject *curObject); 314 315 extern void gfuiLoadFonts(void); 316 317 extern void gfuiEditboxKey(tGfuiObject *obj, int key, int modifier); 318 319 320 extern void gfuiScrollListNextElt (tGfuiObject *object); 321 extern void gfuiScrollListPrevElt (tGfuiObject *object); 322 323 extern void gfuiReleaseImage(tGfuiObject *obj); 324 extern void gfuiDrawImage(tGfuiObject *obj); 325 326 327 #endif /* _GUI_H__ */ 328 329 330 331