30#include <portability.h>
50 if (callback == NULL) {
54 return [userData, callback] {
87 const int BUFSIZE = 1024;
106 for (j = 0; j < 4; j++) {
116 glutSetCursor(GLUT_CURSOR_NONE);
179 glDisable(GL_DEPTH_TEST);
180 glDisable(GL_LIGHTING);
181 glDisable(GL_TEXTURE_2D);
182 glDisable(GL_CULL_FACE);
183 glDisable(GL_ALPHA_TEST);
185 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
190 glMatrixMode(GL_PROJECTION);
193 glMatrixMode(GL_MODELVIEW);
201 glClear(GL_COLOR_BUFFER_BIT);
204 if (glIsTexture(
GfuiScreen->bgImage) == GL_TRUE) {
205 GLfloat tx1 = 0.0f, tx2 = 1.0f, ty1 = 0.0f, ty2 = 1.0f;
211 if (rfactor >= 1.0f) {
213 tdble tdx = (1.0f-1.0f/rfactor)/2.0f;
218 tdble tdy = (1.0f-rfactor)/2.0f;
224 glEnable(GL_TEXTURE_2D);
225 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
226 glColor3f(0.0, 0.0, 1.0);
227 glBindTexture(GL_TEXTURE_2D,
GfuiScreen->bgImage);
229 glTexCoord2f(tx1, ty1); glVertex3f(0.0, 0.0, 0.0);
230 glTexCoord2f(tx1, ty2); glVertex3f(0.0,
GfuiScreen->height, 0.0);
232 glTexCoord2f(tx2, ty1); glVertex3f(
GfuiScreen->width, 0.0, 0.0);
234 glDisable(GL_TEXTURE_2D);
241 curObj = curObj->
next;
290 modifier = glutGetModifiers();
301 curKey = curKey->
next;
302 if ((curKey->
key == key) && ((curKey->
modifier == 0) || (curKey->
modifier & modifier) != 0)) {
327 modifier = glutGetModifiers();
338 curKey = curKey->
next;
363 modifier = glutGetModifiers();
374 curKey = curKey->
next;
375 if ((curKey->
key == key) && ((curKey->
modifier == 0) || (curKey->
modifier & modifier) != 0)) {
391 modifier = glutGetModifiers();
402 curKey = curKey->
next;
432 glutWarpPointer(x,
y);
440 if (button > -1 && button < 3) {
448 if (state == GLUT_DOWN) {
449 if (button == GLUT_RIGHT_BUTTON) {
461 if (button != GLUT_RIGHT_BUTTON) {
523 glutIdleFunc((
void(*)(
void))NULL);
571 glutKeyboardFunc((
void(*)(
unsigned char,
int,
int))NULL);
572 glutSpecialFunc((
void(*)(
int,
int,
int))NULL);
573 glutKeyboardUpFunc((
void(*)(
unsigned char,
int,
int))NULL);
574 glutSpecialUpFunc((
void(*)(
int,
int,
int))NULL);
575 glutMouseFunc((
void(*)(
int,
int,
int,
int))NULL);
576 glutMotionFunc((
void(*)(
int,
int))NULL);
577 glutPassiveMotionFunc((
void(*)(
int,
int))NULL);
578 glutIdleFunc((
void(*)(
void))NULL);
594 screen->
width = 640.0;
597 screen->
bgColor = (
float*)calloc(4,
sizeof(
float));
599 for(i = 0; i < 4; i++) {
607 return (
void*)screen;
629 screen->
width = 640.0;
632 screen->
bgColor = (
float*)calloc(4,
sizeof(
float));
633 for(i = 0; i < 4; i++) {
634 if (bgColor != NULL) {
635 screen->
bgColor[i] = bgColor[i];
648 return (
void*)screen;
682 if (glIsTexture(screen->
bgImage) == GL_TRUE) {
683 glDeleteTextures(1, &screen->
bgImage);
694 if (curObject != NULL) {
696 nextObject = curObject->
next;
698 curObject = nextObject;
699 }
while (curObject != screen->
objects);
703 if (curKey != NULL) {
705 nextKey = curKey->
next;
712 }
while (curKey != screen->
userKeys);
715 if (curKey != NULL) {
717 nextKey = curKey->
next;
744 return (
void*)screen;
813 const int BUFSIZE = 16;
822 curKey->
descr = strdup(
"");
824 curKey->
descr = strdup(descr);
829 curKey->
name = strdup(
"backspace");
832 curKey->
name = strdup(
"tab");
835 curKey->
name = strdup(
"enter");
838 curKey->
name = strdup(
"esc");
841 curKey->
name = strdup(
"space");
844 snprintf(buf, BUFSIZE,
"%c", key);
845 curKey->
name = strdup(buf);
851 curKey->
next = curKey;
906 curKey->
descr = strdup(
"");
908 curKey->
descr = strdup(descr);
913 curKey->
name = strdup(
"F1");
916 curKey->
name = strdup(
"F2");
919 curKey->
name = strdup(
"F3");
922 curKey->
name = strdup(
"F4");
925 curKey->
name = strdup(
"F5");
928 curKey->
name = strdup(
"F6");
931 curKey->
name = strdup(
"F7");
934 curKey->
name = strdup(
"F8");
937 curKey->
name = strdup(
"F9");
940 curKey->
name = strdup(
"F10");
943 curKey->
name = strdup(
"F11");
946 curKey->
name = strdup(
"F12");
949 curKey->
name = strdup(
"Left Arrow");
952 curKey->
name = strdup(
"Up Arrow");
955 curKey->
name = strdup(
"Right Arrow");
958 curKey->
name = strdup(
"Down Arrow");
960 case GLUT_KEY_PAGE_UP:
961 curKey->
name = strdup(
"Page Up");
963 case GLUT_KEY_PAGE_DOWN:
964 curKey->
name = strdup(
"Page Down");
967 curKey->
name = strdup(
"Home");
970 curKey->
name = strdup(
"End");
972 case GLUT_KEY_INSERT:
973 curKey->
name = strdup(
"Insert");
980 curKey->
next = curKey;
1001 const int BUFSIZE = 1024;
1009 len = snprintf(path, BUFSIZE,
"%sscreenshots",
GetLocalDir());
1010 if ((len < 0) || (len >= BUFSIZE)) {
1011 GfError(
"GfuiScreenShot: screenshot directory path too long\n");
1018 img = (
unsigned char*)malloc(vw * vh * 3);
1023 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
1024 glPixelStorei(GL_PACK_ALIGNMENT, 1);
1025 glReadBuffer(GL_FRONT);
1026 glReadPixels((sw-vw)/2, (sh-vh)/2, vw, vh, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)img);
1029 stm = localtime(&t);
1030 len = snprintf(buf, BUFSIZE,
"%s/torcs-%4d%02d%02d%02d%02d%02d.png",
1038 if ((len < 0) || (len >= BUFSIZE)) {
1039 GfError(
"GfuiScreenShot: screenshot file path too long\n");
1065 const int BUFSIZE = 1024;
1068 if (glIsTexture(screen->
bgImage) == GL_TRUE) {
1069 glDeleteTextures(1, &screen->
bgImage);
1075 tex = (GLbyte*)
GfImgReadPng(filename, &w, &h, screen_gamma);
1081 glGenTextures(1, &screen->
bgImage);
1082 glBindTexture(GL_TEXTURE_2D, screen->
bgImage);
1083 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1084 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1085 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)(tex));
static int onKeyAction(unsigned char key, int, int state)
static int onSKeyAction(int key, int, int state)
static void onActivate(void)
void GfuiMouseSetHWPresent(void)
Force the hardware mouse pointer.
float tdble
Floating point type used in TORCS.
void GfuiKeyEventRegisterCurrent(tfuiKeyCallback onKeyAction)
Set the ordinary-key interceptor on the currently active screen.
void * GfuiScreenCreateExAction(float *bgColor, const tGfuiAction &onActivate, const tGfuiAction &onDeactivate, int mouseAllowed)
Create a screen.
void GfuiMouseHide(void)
Disallow the software mouse cursor on the active screen.
void GfuiHookRelease(void *hook)
Release the given hook.
void * GfuiHookCreate(void *userDataOnActivate, tfuiCallback onActivate)
Create a callback-only screen hook.
void GfuiScreenRelease(void *scr)
Release the given screen.
void GfuiAddKeyAction(void *scr, unsigned char key, const char *descr, const tGfuiAction &onKeyPressed, const tGfuiAction &onKeyReleased)
Add a Keyboard callback to a screen.
void GfuiScreenAddBgImg(void *scr, const char *filename)
Add an image background to a screen.
void GfuiSKeyEventRegisterCurrent(tfuiSKeyCallback onSKeyAction)
Set the special-key interceptor on the currently active screen.
void GfuiIdle(void)
Process held-mouse-button repeat actions on the active screen.
void GfuiDisplay(void)
Draw the active GUI screen and swap the GLUT buffers.
void GfuiAddSKeyAction(void *scr, int key, const char *descr, const tGfuiAction &onKeyPressed, const tGfuiAction &onKeyReleased)
Add a Special Keyboard shortcut to the screen.
void * GfuiScreenCreateEx(float *bgColor, void *userDataOnActivate, tfuiCallback onActivate, void *userDataOnDeactivate, tfuiCallback onDeactivate, int mouseAllowed)
Create a screen using callbacks with caller-supplied data.
void GfuiRegisterKey(unsigned char key, char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased)
Bind an ordinary key on the currently active screen.
void * GfuiHookCreateAction(const tGfuiAction &onActivate)
Create a callback hook.
void GfuiScreenReplace(void *screen)
Activate a screen and make it current plus release the current screen.
void GfuiKeyEventRegister(void *scr, tfuiKeyCallback onKeyAction)
Set the ordinary-key event interceptor for a screen.
void GfuiAddKey(void *scr, unsigned char key, const char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased)
Bind an ordinary key on a screen using callbacks with caller-supplied data.
tMouseInfo * GfuiMouseInfo(void)
Get the GUI's current mouse state.
void GfuiMouseShow(void)
Allow the software mouse cursor on the active screen.
void GfuiRegisterKeyAction(unsigned char key, char *descr, const tGfuiAction &onKeyPressed, const tGfuiAction &onKeyReleased)
Add a Keyboard callback to the current screen.
void GfuiAddSKey(void *scr, int key, const char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased)
Bind a GLUT special key, such as an arrow or function key, on a screen.
void * GfuiScreenCreate(void)
Create a new screen.
int GfuiScreenIsActive(void *screen)
Tell if the screen is active or not.
void GfuiScreenActivate(void *screen)
Activate a screen and make it current.
void GfuiSKeyEventRegister(void *scr, tfuiSKeyCallback onSKeyAction)
Set the special-key event interceptor for a screen.
void GfuiDisplayNothing(void)
GLUT display callback that performs no drawing or buffer swap.
void GfuiScreenDeactivate(void)
Deactivate the current screen.
void GfuiMouseSetPos(int x, int y)
Set the mouse position.
int GfImgWritePngNoGamma(unsigned char *img, const char *filename, int width, int height)
Write a framebuffer capture to a png image on disk without gamma metadata.
unsigned char * GfImgReadPng(const char *filename, int *widthp, int *heightp, float screen_gamma)
Load an image from disk to a buffer in RGBA mode.
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
void GfuiScreenShot(void *)
Save a screen shot in png format.
void GfScrGetSize(int *scrw, int *scrh, int *vieww, int *viewh)
Get the screen and viewport sizes.
static void gfuiSpecial(int key, int, int)
void gfuiReleaseAction(tGfuiAction *action)
static void gfuiKeyboard(unsigned char key, int, int)
static void gfuiKeyboardUp(unsigned char key, int, int)
tGfuiAction gfuiMakeAction(void *userData, tfuiCallback callback)
static void gfuiPassiveMotion(int x, int y)
float GfuiColor[GFUI_COLORNB][4]
tGfuiAction * gfuiCreateAction(const tGfuiAction &action)
static double LastTimeClick
void gfuiRunAction(const tGfuiAction *action)
static void gfuiMotion(int x, int y)
static void gfuiColorInit(void)
static void gfuiSpecialUp(int key, int, int)
static void gfuiMouse(int button, int state, int x, int y)
static int GfuiMouseVisible
void gfuiEditboxKey(tGfuiObject *obj, int key, int modifier)
void GfuiDraw(tGfuiObject *obj)
void gfuiSelectNext(void *)
void gfuiReleaseObject(tGfuiObject *curObject)
void gfuiButtonInit(void)
struct GfuiObject tGfuiObject
void gfuiObjectInit(void)
void gfuiMouseAction(int action)
double GfTimeClock(void)
Get the time in seconds.
#define GFSCR_ELT_EDITCURSORCLR
#define GFSCR_ELT_BGSELSCROLLIST
#define GFSCR_ELT_BGBTNFOCUS
#define GFSCR_ELT_BTNCLICK
#define GFSCR_ELT_BTNENABLED
#define GFSCR_ELT_BGSCROLLIST
#define GFSCR_ELT_TITLECOLOR
#define GFSCR_ELT_LABELCOLOR
#define GFSCR_ELT_BGBTNCLICK
#define GFSCR_ELT_BGBTNENABLED
#define GFSCR_ELT_HELPCOLOR2
#define GFSCR_ELT_TIPCOLOR
#define GFSCR_ELT_BTNFOCUS
#define GFSCR_ELT_BGCOLOR
#define GFSCR_ELT_SCROLLIST
#define GFSCR_ELT_MOUSECOLOR2
#define GFSCR_SECT_MENUCOL
#define GFSCR_LIST_COLORS
#define GFSCR_ELT_MOUSECOLOR1
#define GFSCR_ELT_HELPCOLOR1
#define GFSCR_ELT_BGBTNDISABLED
#define GFSCR_ELT_SELSCROLLIST
#define GFSCR_ELT_BTNDISABLED
tGfuiAction * onReleaseAction
tGfuiAction * onPressAction
tfuiKeyCallback onKeyAction
tGfuiAction * onActivateAction
tGfuiAction * onDeactivateAction
tfuiSKeyCallback onSKeyAction
int GfCreateDir(char *path)
Create directory for given path recursively, so all missing parent directories are created as well.
#define GFPARM_RMODE_CREAT
Allow an empty in-memory set on file-open failure; does not write a file.
#define GFPARM_RMODE_STD
Return a new handle sharing cached data for this filename, if available.
The Gaming Framework API (client part).
void(* tfuiCallback)(void *)
struct MouseInfo tMouseInfo
int(* tfuiKeyCallback)(unsigned char key, int modifier, int state)
return 1 to prevent normal key computing
int(* tfuiSKeyCallback)(int key, int modifier, int state)
return 1 to prevent normal key computing
std::function< void()> tGfuiAction