1 /*************************************************************************** 2 tgfclient.h -- Interface file for The Gaming Framework 3 ------------------- 4 created : Fri Aug 13 22:32:14 CEST 1999 5 copyright : (C) 1999-2014 by Eric Espie, Bernhard Wymann 6 email : torcs@free.fr 7 version : $Id: tgfclient.h,v 1.3.2.7 2015/04/18 11:04:54 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 /** @file 20 The Gaming Framework API (client part). 21 @author <a href=mailto:torcs@free.fr>Eric Espie</a> 22 @version $Id: tgfclient.h,v 1.3.2.7 2015/04/18 11:04:54 berniw Exp $ 23 */ 24 25 26 27 #ifndef __TGFCLIENT__H__ 28 #define __TGFCLIENT__H__ 29 30 #include <tgf.h> 31 #include <GL/glut.h> 32 #include <plib/js.h> 33 #include <screen_properties.h> 34 35 #define NUM_JOY 8 36 37 extern void GfInitClient(void); 38 39 /******************** 40 * Screen Interface * 41 ********************/ 42 43 extern unsigned char *GfImgReadPng(const char *filename, int *widthp, int *heightp, float gamma); 44 extern int GfImgWritePng(unsigned char *img, const char *filename, int width, int height); 45 extern void GfImgFreeTex(GLuint tex); 46 extern GLuint GfImgReadTex(char *filename); 47 48 extern void GfScrInit(int argc, char *argv[]); 49 extern void GfScrShutdown(void); 50 extern void *GfScrMenuInit(void *precMenu); 51 extern void GfTime2Str(char *result, int resultSize, tdble sec, int sgn); 52 extern void GfScrGetSize(int *ScrW, int *ScrH, int *ViewW, int *ViewH); 53 extern void GfScrReinit(void*); 54 55 56 /***************************** 57 * GUI interface (low-level) * 58 *****************************/ 59 60 /* Widget type */ 61 #define GFUI_LABEL 0 62 #define GFUI_BUTTON 1 63 #define GFUI_GRBUTTON 2 64 #define GFUI_SCROLLIST 3 65 #define GFUI_SCROLLBAR 4 66 #define GFUI_EDITBOX 5 67 68 /* Alignment */ 69 #define GFUI_ALIGN_HL_VB 0x00 70 #define GFUI_ALIGN_HL_VC 0x01 71 #define GFUI_ALIGN_HL_VT 0x02 72 #define GFUI_ALIGN_HC_VB 0x10 73 #define GFUI_ALIGN_HC_VC 0x11 74 #define GFUI_ALIGN_HC_VT 0x12 75 #define GFUI_ALIGN_HR_VB 0x20 76 #define GFUI_ALIGN_HR_VC 0x21 77 #define GFUI_ALIGN_HR_VT 0x22 78 79 /* Mouse action */ 80 #define GFUI_MOUSE_UP 0 81 #define GFUI_MOUSE_DOWN 1 82 83 /* Keyboard action */ 84 #define GFUI_KEY_UP 0 85 #define GFUI_KEY_DOWN 1 86 87 /* Scroll Bar position */ 88 #define GFUI_SB_NONE 0 89 #define GFUI_SB_RIGHT 1 90 #define GFUI_SB_LEFT 2 91 #define GFUI_SB_TOP 3 92 #define GFUI_SB_BOTTOM 4 93 94 /* Scroll bar orientation */ 95 #define GFUI_HORI_SCROLLBAR 0 96 #define GFUI_VERT_SCROLLBAR 1 97 98 /** Scroll bar call-back information */ 99 typedef struct ScrollBarInfo 100 { 101 int pos; /**< Current scroll bar position */ 102 void *userData; /**< Associated user data */ 103 } tScrollBarInfo; 104 105 typedef void (*tfuiCallback)(void * /* userdata */); 106 typedef void (*tfuiSBCallback)(tScrollBarInfo *); 107 typedef int (*tfuiKeyCallback)(unsigned char key, int modifier, int state); /**< return 1 to prevent normal key computing */ 108 typedef int (*tfuiSKeyCallback)(int key, int modifier, int state); /**< return 1 to prevent normal key computing */ 109 110 111 /* GLUT Callback functions */ 112 /* should be called explicitely if */ 113 /* the corresponding GLUT Func is overriden */ 114 /* after a call to GfuiActivateScreen */ 115 extern void GfuiDisplay(void); 116 extern void GfuiDisplayNothing(void); 117 extern void GfuiIdle(void); 118 119 /* Screen management */ 120 extern void *GfuiScreenCreate(void); 121 extern void *GfuiScreenCreateEx(float *bgColor, 122 void *userDataOnActivate, tfuiCallback onActivate, 123 void *userDataOnDeactivate, tfuiCallback onDeactivate, 124 int mouseAllowed); 125 extern void GfuiScreenRelease(void *screen); 126 extern void GfuiScreenActivate(void *screen); 127 extern int GfuiScreenIsActive(void *screen); 128 extern void GfuiScreenReplace(void *screen); 129 extern void GfuiScreenDeactivate(void); 130 extern void *GfuiHookCreate(void *userDataOnActivate, tfuiCallback onActivate); 131 extern void GfuiHookRelease(void *hook); 132 extern void GfuiAddKey(void *scr, unsigned char key, const char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased); 133 extern void GfuiRegisterKey(unsigned char key, char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased); 134 extern void GfuiAddSKey(void *scr, int key, const char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased); 135 extern void GfuiHelpScreen(void *prevScreen); 136 extern void GfuiScreenShot(void *notused); 137 extern void GfuiScreenAddBgImg(void *scr, const char *filename); 138 extern void GfuiKeyEventRegister(void *scr, tfuiKeyCallback onKeyAction); 139 extern void GfuiSKeyEventRegister(void *scr, tfuiSKeyCallback onSKeyAction); 140 extern void GfuiKeyEventRegisterCurrent(tfuiKeyCallback onKeyAction); 141 extern void GfuiSKeyEventRegisterCurrent(tfuiSKeyCallback onSKeyAction); 142 143 /* mouse */ 144 typedef struct MouseInfo 145 { 146 int X; 147 int Y; 148 int button[3]; 149 } tMouseInfo; 150 151 extern tMouseInfo *GfuiMouseInfo(void); 152 extern void GfuiMouseSetPos(int x, int y); 153 extern void GfuiMouseHide(void); 154 extern void GfuiMouseShow(void); 155 extern void GfuiMouseSetHWPresent(void); 156 157 /* all widgets */ 158 #define GFUI_VISIBLE 1 /**< Object visibility flag */ 159 #define GFUI_INVISIBLE 0 /**< Object invisibility flag */ 160 extern int GfuiVisibilitySet(void *scr, int id, int visible); 161 #define GFUI_DISABLE 1 162 #define GFUI_ENABLE 0 163 extern int GfuiEnable(void *scr, int id, int flag); 164 extern void GfuiUnSelectCurrent(void); 165 166 /* labels */ 167 #define GFUI_FONT_BIG 0 168 #define GFUI_FONT_LARGE 1 169 #define GFUI_FONT_MEDIUM 2 170 #define GFUI_FONT_SMALL 3 171 #define GFUI_FONT_BIG_C 4 172 #define GFUI_FONT_LARGE_C 5 173 #define GFUI_FONT_MEDIUM_C 6 174 #define GFUI_FONT_SMALL_C 7 175 #define GFUI_FONT_DIGIT 8 176 extern int GfuiLabelCreate(void *scr, const char *text, 177 int font, int x, int y, int align, int maxlen); 178 extern int GfuiLabelCreateEx(void *scr, const char *text, float *fgColor, int font, int x, int y, int align, int maxlen); 179 180 extern int GfuiTipCreate(void *scr, const char *text, int maxlen); 181 extern int GfuiTitleCreate(void *scr, const char *text, int maxlen); 182 183 extern void GfuiLabelSetText(void *scr, int id, const char *text); 184 extern void GfuiLabelSetColor(void *scr, int id, float *color); 185 186 extern void GfuiPrintString(const char *text, float *fgColor, int font, int x, int y, int align); 187 extern int GfuiFontHeight(int font); 188 extern int GfuiFontWidth(int font, const char *text); 189 190 191 /* buttons */ 192 #define GFUI_BTNSZ 300 193 extern int GfuiButtonCreate(void *scr, const char *text, int font, 194 int x, int y, int width, int align, int mouse, 195 void *userDataOnPush, tfuiCallback onPush, 196 void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost); 197 extern int GfuiLeanButtonCreate(void *scr, const char *text, int font, 198 int x, int y, int width, int align, int mouse, 199 void *userDataOnPush, tfuiCallback onPush, 200 void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost); 201 extern int GfuiButtonStateCreate(void *scr, const char *text, int font, int x, int y, int width, int align, int mouse, 202 void *userDataOnPush, tfuiCallback onPush, 203 void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost); 204 extern int GfuiGrButtonCreate(void *scr, const char *disabled, const char *enabled, const char *focused, const char *pushed, 205 int x, int y, int align, int mouse, 206 void *userDataOnPush, tfuiCallback onPush, 207 void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost); 208 209 extern void GfuiButtonSetText(void *scr, int id, const char *text); 210 extern int GfuiButtonGetFocused(void); 211 212 /* Edit Box */ 213 extern int GfuiEditboxCreate(void *scr, const char *text, int font, int x, int y, int width, int maxlen, 214 void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost, int margin = 10); 215 extern int GfuiEditboxGetFocused(void); 216 extern char *GfuiEditboxGetString(void *scr, int id); 217 extern void GfuiEditboxSetString(void *scr, int id, const char *text); 218 219 /* Scrolling lists */ 220 extern int GfuiScrollListCreate(void *scr, int font, int x, int y, int align, 221 int width, int height, int scrollbar, void *userDataOnSelect, tfuiCallback onSelect); 222 extern int GfuiScrollListInsertElement(void *scr, int Id, char *element, int index, void *userData); 223 extern int GfuiScrollListMoveSelectedElement(void *scr, int Id, int delta); 224 extern char *GfuiScrollListExtractSelectedElement(void *scr, int Id, void **userData); 225 extern char *GfuiScrollListExtractElement(void *scr, int Id, int index, void **userData); 226 extern char *GfuiScrollListGetSelectedElement(void *scr, int Id, void **userData); 227 extern char *GfuiScrollListGetElement(void *scr, int Id, int index, void **userData); 228 229 /* scroll bars */ 230 extern int GfuiScrollBarCreate(void *scr, int x, int y, int align, int width, int orientation, 231 int min, int max, int len, int start, 232 void *userData, tfuiSBCallback onScroll); 233 extern void GfuiScrollBarPosSet(void *scr, int id, int min, int max, int len, int start); 234 extern int GfuiScrollBarPosGet(void *scr, int id); 235 236 /* Images */ 237 extern int GfuiStaticImageCreate(void *scr, int x, int y, int w, int h, char *name); 238 extern void GfuiStaticImageSet(void *scr, int id, char *name); 239 240 /***************************** 241 * Menu Management Interface * 242 *****************************/ 243 244 extern void *GfuiMenuScreenCreate(const char *title); 245 extern void GfuiMenuDefaultKeysAdd(void *scr); 246 extern int GfuiMenuButtonCreate(void *menu, const char *text, const char *tip, void *userdata, tfuiCallback onpush); 247 extern int GfuiMenuBackQuitButtonCreate(void *menu, const char *text, const char *tip, void *userdata, tfuiCallback onpush); 248 249 250 /********************* 251 * Control interface * 252 *********************/ 253 254 typedef enum { 255 GFCTRL_TYPE_NOT_AFFECTED = 0, 256 GFCTRL_TYPE_JOY_AXIS = 1, 257 GFCTRL_TYPE_JOY_BUT = 2, 258 GFCTRL_TYPE_KEYBOARD = 3, 259 GFCTRL_TYPE_MOUSE_BUT = 4, 260 GFCTRL_TYPE_MOUSE_AXIS = 5, 261 GFCTRL_TYPE_SKEYBOARD = 6 262 } GfCtrlType; 263 264 typedef struct 265 { 266 int index; 267 GfCtrlType type; 268 } tCtrlRef; 269 270 271 #define GFCTRL_JOY_UNTESTED -1 272 #define GFCTRL_JOY_NONE 0 273 #define GFCTRL_JOY_PRESENT 1 274 275 #define GFCTRL_JOY_MAXBUTTON 32 /* Size of integer so don't change please */ 276 277 /** Joystick Information Structure */ 278 typedef struct 279 { 280 int oldb[NUM_JOY]; 281 float ax[_JS_MAX_AXES * NUM_JOY]; /**< Axis values */ 282 int edgeup[GFCTRL_JOY_MAXBUTTON * NUM_JOY]; /**< Button transition from down (pressed) to up */ 283 int edgedn[GFCTRL_JOY_MAXBUTTON * NUM_JOY]; /**< Button transition from up to down */ 284 int levelup[GFCTRL_JOY_MAXBUTTON * NUM_JOY];/**< Button state (1 = up) */ 285 } tCtrlJoyInfo; 286 287 extern tCtrlJoyInfo *GfctrlJoyInit(void); 288 extern int GfctrlJoyIsPresent(void); 289 extern int GfctrlJoyGetCurrent(tCtrlJoyInfo *joyInfo); 290 extern void GfctrlJoyRelease(tCtrlJoyInfo *joyInfo); 291 292 293 /** Mouse information structure */ 294 typedef struct 295 { 296 int edgeup[3]; /**< Button transition from down (pressed) to up */ 297 int edgedn[3]; /**< Button transition from up to down */ 298 int button[3]; /**< Button state (1 = up) */ 299 float ax[4]; /**< mouse axis position (mouse considered as a joystick) */ 300 } tCtrlMouseInfo; 301 302 extern tCtrlMouseInfo *GfctrlMouseInit(void); 303 extern int GfctrlMouseGetCurrent(tCtrlMouseInfo *mouseInfo); 304 extern void GfctrlMouseRelease(tCtrlMouseInfo *mouseInfo); 305 extern void GfctrlMouseCenter(void); 306 extern void GfctrlMouseInitCenter(void); 307 extern void GfctrlGetRefByName(const char *name, tCtrlRef* ref); 308 extern const char *GfctrlGetNameByRef(GfCtrlType type, int index); 309 extern const char *GfctrlGetDefaultSection(GfCtrlType type); 310 extern bool GfctrlIsEventBlacklisted(void *parmHandle, const char* driversSection, const char* event); 311 312 extern int GfuiGlutExtensionSupported(const char *str); 313 314 315 #endif /* __TGFCLIENT__H__ */ 316 317 318