TORCS  1.3.9
The Open Racing Car Simulator
guimenu.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  menu.cpp -- menu management
3  -------------------
4  created : Fri Aug 13 22:23:19 CEST 1999
5  copyright : (C) 1999 by Eric Espie
6  email : torcs@free.fr
7  version : $Id$
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 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #ifdef WIN32
30 #include <windows.h>
31 #endif
32 #include <GL/glut.h>
33 
34 #include <tgfclient.h>
35 #include "gui.h"
36 #include "guimenu.h"
37 
38 void
40 {
41 }
42 
54 void
56 {
57  GfuiAddKey(scr, 9, "Select Next Entry", NULL, gfuiSelectNext, NULL);
58  GfuiAddKey(scr, 13, "Perform Action", (void*)2, gfuiMouseAction, NULL);
59  GfuiAddSKey(scr, GLUT_KEY_UP, "Select Previous Entry", NULL, gfuiSelectPrev, NULL);
60  GfuiAddSKey(scr, GLUT_KEY_DOWN, "Select Next Entry", NULL, gfuiSelectNext, NULL);
61  GfuiAddSKey(scr, GLUT_KEY_PAGE_UP, "Select Previous Entry", NULL, gfuiSelectPrev, NULL);
62  GfuiAddSKey(scr, GLUT_KEY_PAGE_DOWN, "Select Next Entry", NULL, gfuiSelectNext, NULL);
63  GfuiAddSKey(scr, GLUT_KEY_F1, "Help", scr, GfuiHelpScreen, NULL);
64  GfuiAddSKey(scr, GLUT_KEY_F12, "Screen-Shot", NULL, GfuiScreenShot, NULL);
65 
66 }
67 
75 void *
76 GfuiMenuScreenCreate(const char *title)
77 {
78  void *scr;
79 
80  scr = GfuiScreenCreate();
81  GfuiTitleCreate(scr, title, strlen(title));
82 
84 
85  return scr;
86 }
87 
88 static void
89 dispInfo(void *cbinfo)
90 {
91  GfuiVisibilitySet(((tMnuCallbackInfo*)cbinfo)->screen, ((tMnuCallbackInfo*)cbinfo)->labelId, 1);
92 }
93 static void
94 remInfo(void *cbinfo)
95 {
96  GfuiVisibilitySet(((tMnuCallbackInfo*)cbinfo)->screen, ((tMnuCallbackInfo*)cbinfo)->labelId, 0);
97 }
98 
99 
109 int
110 GfuiMenuButtonCreate(void *scr, const char *text, const char *tip, void *userdata, tfuiCallback onpush)
111 {
112  tMnuCallbackInfo *cbinfo;
113  int xpos, ypos;
114  int nbItems = ((tGfuiScreen*)scr)->nbItems++;
115  int bId;
116 
117  if (nbItems < 11) {
118  xpos = 320;
119  ypos = 380 - 30 * nbItems;
120  } else {
121  if (nbItems > 22) {
122  GfTrace("Too many items in that menu !!!\n");
123  return -1;
124  }
125  xpos = 380;
126  ypos = 380 - 30 * (nbItems - 11);
127  }
128 
129  cbinfo = (tMnuCallbackInfo*)calloc(1, sizeof(tMnuCallbackInfo));
130  cbinfo->screen = scr;
131  cbinfo->labelId = GfuiTipCreate(scr, tip, strlen(tip));
132 
133  GfuiVisibilitySet(scr, cbinfo->labelId, 0);
134 
135  bId = GfuiButtonCreate(scr,
136  text,
138  xpos, ypos, GFUI_BTNSZ, GFUI_ALIGN_HC_VB, 0,
139  userdata, onpush,
140  (void*)cbinfo, dispInfo,
141  remInfo);
142 
143  return bId;
144 }
145 
155 int
156 GfuiMenuBackQuitButtonCreate(void *scr, const char *text, const char *tip, void *userdata, tfuiCallback onpush)
157 {
158  tMnuCallbackInfo *cbinfo;
159  int xpos, ypos;
160  int bId;
161 
162  xpos = 320;
163  ypos = 40;
164 
165  cbinfo = (tMnuCallbackInfo*)calloc(1, sizeof(tMnuCallbackInfo));
166  cbinfo->screen = scr;
167  cbinfo->labelId = GfuiTipCreate(scr, tip, strlen(tip));
168 
169  GfuiVisibilitySet(scr, cbinfo->labelId, 0);
170 
171  bId = GfuiButtonCreate(scr,
172  text,
174  xpos, ypos, GFUI_BTNSZ, GFUI_ALIGN_HC_VB, 0,
175  userdata, onpush,
176  (void*)cbinfo, dispInfo,
177  remInfo);
178 
179  GfuiAddKey(scr, (unsigned char)27, tip, userdata, onpush, NULL);
180 
181  return bId;
182 }
183 
184 
int GfuiButtonCreate(void *scr, const char *text, int font, int x, int y, int width, int align, int mouse, void *userDataOnPush, tfuiCallback onPush, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost)
Add a button to a screen.
Definition: guibutton.cpp:248
int GfuiMenuButtonCreate(void *scr, const char *text, const char *tip, void *userdata, tfuiCallback onpush)
Add a button to a menu screen.
Definition: guimenu.cpp:110
void * screen
Definition: guimenu.h:26
#define GFUI_BTNSZ
Definition: tgfclient.h:192
void GfuiAddKey(void *scr, unsigned char key, const char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased)
Add a Keyboard callback to a screen.
Definition: gui.cpp:742
void * GfuiMenuScreenCreate(const char *title)
Create a new menu screen.
Definition: guimenu.cpp:76
The Gaming Framework API (client part).
#define GFUI_FONT_LARGE
Definition: tgfclient.h:168
static void remInfo(void *cbinfo)
Definition: guimenu.cpp:94
void GfuiMenuDefaultKeysAdd(void *scr)
Add the default menu keyboard callback to a screen.
Definition: guimenu.cpp:55
void(* tfuiCallback)(void *)
Definition: tgfclient.h:105
void GfuiAddSKey(void *scr, int key, const char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased)
Add a Special Keyboard shortcut to the screen.
Definition: gui.cpp:816
void gfuiSelectPrev(void *)
Definition: guiobject.cpp:344
#define GFUI_ALIGN_HC_VB
Definition: tgfclient.h:72
void GfuiHelpScreen(void *prevScreen)
Generate a help screen.
Definition: guihelp.cpp:48
void GfuiScreenShot(void *)
Save a screen shot in png format.
Definition: gui.cpp:913
int GfuiTitleCreate(void *scr, const char *text, int maxlen)
Add a Title to the screen.
Definition: guilabel.cpp:170
void * GfuiScreenCreate(void)
Create a new screen.
Definition: gui.cpp:543
static void dispInfo(void *cbinfo)
Definition: guimenu.cpp:89
#define GfTrace
Definition: tgf.h:336
void gfuiMouseAction(void *action)
Definition: guiobject.cpp:456
void gfMenuInit(void)
Definition: guimenu.cpp:39
int GfuiVisibilitySet(void *scr, int id, int visible)
Set/unset the visibility attribute of an object.
Definition: guiobject.cpp:404
int GfuiTipCreate(void *scr, const char *text, int maxlen)
Add a Tip (generally associated with a button).
Definition: guilabel.cpp:155
int GfuiMenuBackQuitButtonCreate(void *scr, const char *text, const char *tip, void *userdata, tfuiCallback onpush)
Add the "Back" or "Quit" button at the bottom of the menu screen.
Definition: guimenu.cpp:156
void gfuiSelectNext(void *)
Definition: guiobject.cpp:311