torcs - 1.2.2

src/libs/tgfclient/tgfclient.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                     tgfclient.h -- Interface file for The Gaming Framework                                    
00003                              -------------------                                         
00004     created              : Fri Aug 13 22:32:14 CEST 1999
00005     copyright            : (C) 1999 by Eric Espie                         
00006     email                : torcs@free.fr   
00007     version              : $Id: tgfclient.h,v 1.2 2003/06/24 21:02:25 torcs Exp $                                  
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00027 #ifndef __TGFCLIENT__H__
00028 #define __TGFCLIENT__H__
00029 
00030 #include <tgf.h>
00031 #include <GL/glut.h>
00032 #include <js.h>
00033 #include <screen_properties.h>
00034 
00035 extern void GfInitClient(void);
00036 
00037 /******************** 
00038  * Screen Interface *
00039  ********************/
00040 
00041 extern unsigned char *GfImgReadPng(const char *filename, int *widthp, int *heightp, float gamma);
00042 extern int GfImgWritePng(unsigned char *img, const char *filename, int width, int height);
00043 extern void GfImgFreeTex(GLuint tex);
00044 extern GLuint GfImgReadTex(char *filename);
00045 
00046 extern void GfScrInit(int argc, char *argv[]);
00047 extern void GfScrShutdown(void);
00048 extern void *GfScrMenuInit(void *precMenu);
00049 extern char *GfTime2Str(tdble sec, int sgn);
00050 extern void GfScrGetSize(int *ScrW, int *ScrH, int *ViewW, int *ViewH);
00051 extern void GfScrReinit(void*);
00052 
00053 
00054 /*****************************
00055  * GUI interface (low-level) *
00056  *****************************/
00057 
00058 /* Widget type */
00059 #define GFUI_LABEL      0
00060 #define GFUI_BUTTON     1
00061 #define GFUI_GRBUTTON   2
00062 #define GFUI_SCROLLIST  3
00063 #define GFUI_SCROLLBAR  4
00064 #define GFUI_EDITBOX    5
00065 
00066 /* Alignment */
00067 #define GFUI_ALIGN_HL_VB        0x00
00068 #define GFUI_ALIGN_HL_VC        0x01
00069 #define GFUI_ALIGN_HL_VT        0x02
00070 #define GFUI_ALIGN_HC_VB        0x10
00071 #define GFUI_ALIGN_HC_VC        0x11
00072 #define GFUI_ALIGN_HC_VT        0x12
00073 #define GFUI_ALIGN_HR_VB        0x20
00074 #define GFUI_ALIGN_HR_VC        0x21
00075 #define GFUI_ALIGN_HR_VT        0x22
00076 
00077 /* Mouse action */
00078 #define GFUI_MOUSE_UP   0
00079 #define GFUI_MOUSE_DOWN 1
00080 
00081 /* Keyboard action */
00082 #define GFUI_KEY_UP     0
00083 #define GFUI_KEY_DOWN   1
00084 
00085 /* Scroll Bar position */
00086 #define GFUI_SB_NONE    0
00087 #define GFUI_SB_RIGHT   1
00088 #define GFUI_SB_LEFT    2
00089 #define GFUI_SB_TOP     3
00090 #define GFUI_SB_BOTTOM  4
00091 
00092 /* Scroll bar orientation */
00093 #define GFUI_HORI_SCROLLBAR     0
00094 #define GFUI_VERT_SCROLLBAR     1
00095 
00097 typedef struct ScrollBarInfo
00098 {
00099     int         pos;            
00100     void        *userData;      
00101 } tScrollBarInfo;
00102 
00103 typedef void (*tfuiCallback)(void * /* userdata */);
00104 typedef void (*tfuiSBCallback)(tScrollBarInfo *);
00105 typedef int (*tfuiKeyCallback)(unsigned char key, int modifier, int state); 
00106 typedef int (*tfuiSKeyCallback)(int key, int modifier, int state);  
00109 /* GLUT Callback functions                  */
00110 /* should be called explicitely if          */
00111 /* the corresponding GLUT Func is overriden */
00112 /* after a call to GfuiActivateScreen       */
00113 extern void GfuiDisplay(void);
00114 extern void GfuiDisplayNothing(void);
00115 extern void GfuiIdle(void);
00116 
00117 /* Screen management */
00118 extern void *GfuiScreenCreate(void);
00119 extern void *GfuiScreenCreateEx(float *bgColor, 
00120                                 void *userDataOnActivate, tfuiCallback onActivate, 
00121                                 void *userDataOnDeactivate, tfuiCallback onDeactivate, 
00122                                 int mouseAllowed);
00123 extern void GfuiScreenRelease(void *screen);
00124 extern void GfuiScreenActivate(void *screen);
00125 extern int  GfuiScreenIsActive(void *screen);
00126 extern void GfuiScreenReplace(void *screen);
00127 extern void GfuiScreenDeactivate(void);
00128 extern void *GfuiHookCreate(void *userDataOnActivate, tfuiCallback onActivate);
00129 extern void GfuiHookRelease(void *hook);
00130 extern void GfuiAddKey(void *scr, unsigned char key, char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased);
00131 extern void GfuiRegisterKey(unsigned char key, char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased);
00132 extern void GfuiAddSKey(void *scr, int key, char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased);
00133 extern void GfuiHelpScreen(void *prevScreen);
00134 extern void GfuiScreenShot(void *notused);
00135 extern void GfuiScreenAddBgImg(void *scr, char *filename);
00136 extern void GfuiKeyEventRegister(void *scr, tfuiKeyCallback onKeyAction);
00137 extern void GfuiSKeyEventRegister(void *scr, tfuiSKeyCallback onSKeyAction);
00138 extern void GfuiKeyEventRegisterCurrent(tfuiKeyCallback onKeyAction);
00139 extern void GfuiSKeyEventRegisterCurrent(tfuiSKeyCallback onSKeyAction);
00140 
00141 /* mouse */
00142 typedef struct MouseInfo
00143 {
00144     int X;
00145     int Y;
00146     int button[3];
00147 } tMouseInfo;
00148 
00149 extern tMouseInfo *GfuiMouseInfo(void);
00150 extern void GfuiMouseSetPos(int x, int y);
00151 extern void GfuiMouseHide(void);
00152 extern void GfuiMouseShow(void);
00153 extern void GfuiMouseSetHWPresent(void);
00154 
00155 /* all widgets */
00156 #define GFUI_VISIBLE    1       
00157 #define GFUI_INVISIBLE  0       
00158 extern int GfuiVisibilitySet(void *scr, int id, int visible);
00159 #define GFUI_DISABLE    1
00160 #define GFUI_ENABLE     0
00161 extern int GfuiEnable(void *scr, int id, int flag);
00162 extern void GfuiUnSelectCurrent(void);
00163 
00164 /* labels */
00165 #define GFUI_FONT_BIG           0
00166 #define GFUI_FONT_LARGE         1
00167 #define GFUI_FONT_MEDIUM        2
00168 #define GFUI_FONT_SMALL         3
00169 #define GFUI_FONT_BIG_C         4
00170 #define GFUI_FONT_LARGE_C       5
00171 #define GFUI_FONT_MEDIUM_C      6
00172 #define GFUI_FONT_SMALL_C       7
00173 #define GFUI_FONT_DIGIT         8
00174 extern int GfuiLabelCreate(void *scr, char *text, 
00175                         int font, int x, int y, int align, int maxlen);
00176 extern int GfuiLabelCreateEx(void *scr, char *text, float *fgColor, int font, int x, int y, int align, int maxlen);
00177 
00178 extern int GfuiTipCreate(void *scr, char *text, int maxlen);
00179 extern int GfuiTitleCreate(void *scr, char *text, int maxlen);
00180 
00181 extern void GfuiLabelSetText(void *scr, int id, char *text);
00182 extern void GfuiLabelSetColor(void *scr, int id, float *color);
00183 
00184 extern void GfuiPrintString(char *text, float *fgColor, int font, int x, int y, int align);
00185 extern int  GfuiFontHeight(int font);
00186 extern int  GfuiFontWidth(int font, char *text);
00187 
00188 
00189 /* buttons */
00190 #define GFUI_BTNSZ      300
00191 extern int GfuiButtonCreate(void *scr, char *text, int font,
00192                             int x, int y, int width, int align, int mouse,
00193                             void *userDataOnPush, tfuiCallback onPush, 
00194                             void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost);
00195 extern int GfuiButtonStateCreate(void *scr, char *text, int font, int x, int y, int width, int align, int mouse,
00196                                  void *userDataOnPush, tfuiCallback onPush, 
00197                                  void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost);
00198 extern int GfuiGrButtonCreate(void *scr, char *disabled, char *enabled, char *focused, char *pushed,
00199                               int x, int y, int align, int mouse,
00200                               void *userDataOnPush, tfuiCallback onPush, 
00201                               void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost);
00202 
00203 extern void GfuiButtonSetText(void *scr, int id, char *text);
00204 extern int GfuiButtonGetFocused(void);
00205 
00206 /* Edit Box */
00207 extern int GfuiEditboxCreate(void *scr, char *text, int font, int x, int y, int width, int maxlen,
00208                              void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost);
00209 extern int GfuiEditboxGetFocused(void);
00210 extern char *GfuiEditboxGetString(void *scr, int id);
00211 extern void GfuiEditboxSetString(void *scr, int id, char *text);
00212 
00213 /* Scrolling lists */
00214 extern int GfuiScrollListCreate(void *scr, int font, int x, int y, int align,
00215                                 int width, int height, int scrollbar, void *userDataOnSelect, tfuiCallback onSelect);
00216 extern int GfuiScrollListInsertElement(void *scr, int Id, char *element, int index, void *userData);
00217 extern int GfuiScrollListMoveSelectedElement(void *scr, int Id, int delta);
00218 extern char *GfuiScrollListExtractSelectedElement(void *scr, int Id, void **userData);
00219 extern char *GfuiScrollListExtractElement(void *scr, int Id, int index, void **userData);
00220 extern char *GfuiScrollListGetSelectedElement(void *scr, int Id, void **userData);
00221 extern char *GfuiScrollListGetElement(void *scr, int Id, int index, void **userData);
00222 
00223 /* scroll bars */
00224 extern int GfuiScrollBarCreate(void *scr, int x, int y, int align, int width, int orientation,
00225                                int min, int max, int len, int start, 
00226                                void *userData, tfuiSBCallback onScroll);
00227 extern void GfuiScrollBarPosSet(void *scr, int id, int min, int max, int len, int start);
00228 extern int GfuiScrollBarPosGet(void *scr, int id);
00229 
00230 /* Images */
00231 extern int GfuiStaticImageCreate(void *scr, int x, int y, int w, int h, char *name);
00232 extern void GfuiStaticImageSet(void *scr, int id, char *name);
00233 
00234 /*****************************
00235  * Menu Management Interface *
00236  *****************************/
00237 
00238 extern void *GfuiMenuScreenCreate(char *title);
00239 extern void  GfuiMenuDefaultKeysAdd(void *scr);
00240 extern int   GfuiMenuButtonCreate(void *menu, char *text, char *tip, void *userdata, tfuiCallback onpush);
00241 extern int   GfuiMenuBackQuitButtonCreate(void *menu, char *text, char *tip, void *userdata, tfuiCallback onpush);
00242 
00243 
00244 /*********************
00245  * Control interface *
00246  *********************/
00247 
00248 #define GFCTRL_TYPE_NOT_AFFECTED        0
00249 #define GFCTRL_TYPE_JOY_AXIS            1
00250 #define GFCTRL_TYPE_JOY_BUT             2
00251 #define GFCTRL_TYPE_KEYBOARD            3
00252 #define GFCTRL_TYPE_MOUSE_BUT           4
00253 #define GFCTRL_TYPE_MOUSE_AXIS          5
00254 #define GFCTRL_TYPE_SKEYBOARD           6
00255 
00256 typedef struct
00257 {
00258     int         index;
00259     int         type;
00260 } tCtrlRef;
00261 
00262 
00263 #define GFCTRL_JOY_UNTESTED     -1
00264 #define GFCTRL_JOY_NONE         0
00265 #define GFCTRL_JOY_PRESENT      1
00266 
00267 #define GFCTRL_JOY_MAXBUTTON    32 /* Size of integer so don't change please */
00268 
00270 typedef struct
00271 {
00272     int         oldb[NUM_JOY];
00273     float       ax[MAX_AXES * NUM_JOY];                 
00274     int         edgeup[GFCTRL_JOY_MAXBUTTON * NUM_JOY]; 
00275     int         edgedn[GFCTRL_JOY_MAXBUTTON * NUM_JOY]; 
00276     int         levelup[GFCTRL_JOY_MAXBUTTON * NUM_JOY];
00277 } tCtrlJoyInfo;
00278 
00279 extern tCtrlJoyInfo *GfctrlJoyInit(void);
00280 extern int GfctrlJoyIsPresent(void);
00281 extern int GfctrlJoyGetCurrent(tCtrlJoyInfo *joyInfo);
00282 extern void GfctrlJoyRelease(tCtrlJoyInfo *joyInfo);
00283 
00284 
00286 typedef struct
00287 {
00288     int         edgeup[3];      
00289     int         edgedn[3];      
00290     int         button[3];      
00291     float       ax[4];          
00292 } tCtrlMouseInfo;
00293 
00294 extern tCtrlMouseInfo *GfctrlMouseInit(void);
00295 extern int GfctrlMouseGetCurrent(tCtrlMouseInfo *mouseInfo);
00296 extern void GfctrlMouseRelease(tCtrlMouseInfo *mouseInfo);
00297 extern void GfctrlMouseCenter(void);
00298 extern void GfctrlMouseInitCenter(void);
00299 extern tCtrlRef *GfctrlGetRefByName(char *name);
00300 extern char *GfctrlGetNameByRef(int type, int index);
00301 
00302 #endif /* __TGFCLIENT__H__ */
00303 
00304 

Generated at Thu Feb 26 21:52:28 2004 for torcs by doxygen 1.3.3 written by Dimitri van Heesch, © 1997-1999
TORCS © Eric Espié 1999, 2002.