TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
guiscrollbar.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 file : guiscrollbar.cpp
4 created : Mon Aug 23 22:11:37 CEST 1999
5 copyright : (C) 1999-2026 by Eric EspiƩ, Bernhard Wymann
6 email : berniw@bluewin.ch
7
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
23
24#include <stdlib.h>
25#ifdef WIN32
26#include <windows.h>
27#endif
28#include <tgfclient.h>
29#include "gui.h"
30
31void
33{
34}
35
36static void
38{
39 tGfuiScrollBar *scrollbar;
40 tScrollBarInfo info;
41
42 if(object == NULL) {
43 return;
44 }
45
46 scrollbar = &(object->u.scrollbar);
47 scrollbar->pos++;
48
49 if(scrollbar->pos > scrollbar->max) {
50 scrollbar->pos = scrollbar->max;
51 } else if(scrollbar->onScroll != NULL) {
52 info.pos = scrollbar->pos;
53 info.userData = scrollbar->userData;
54 scrollbar->onScroll(&info);
55 }
56}
57
58static void
60{
61 tGfuiScrollBar *scrollbar;
62 tScrollBarInfo info;
63
64 if(object == NULL) {
65 return;
66 }
67
68 scrollbar = &(object->u.scrollbar);
69 scrollbar->pos--;
70
71 if(scrollbar->pos < scrollbar->min) {
72 scrollbar->pos = scrollbar->min;
73 } else if(scrollbar->onScroll != NULL) {
74 info.pos = scrollbar->pos;
75 info.userData = scrollbar->userData;
76 scrollbar->onScroll(&info);
77 }
78}
79
80static void
81gfuiScrollButtonCreate(void *scr, const char *image, const char *pushed,
82 int x, int y, int align, tGfuiObject *object,
83 void (*onPush)(tGfuiObject *))
84{
85 GfuiGrButtonCreateAction(scr, image, image, image, pushed, x, y, align, 1,
86 [object, onPush] { onPush(object); }, tGfuiAction(), tGfuiAction());
87}
88
117int
118GfuiScrollBarCreate(void *scr, int x, int y, int align, int width, int orientation,
119 int min, int max, int len, int start,
120 void *userData, tfuiSBCallback onScroll)
121{
122 tGfuiObject *object;
123 tGfuiScrollBar *scrollbar;
124 tGfuiScreen *screen = (tGfuiScreen *)scr;
125
126 object = (tGfuiObject *)calloc(1, sizeof(tGfuiObject));
127 object->widget = GFUI_SCROLLBAR;
128 object->focusMode = GFUI_FOCUS_MOUSE_CLICK;
129 object->id = screen->curId++;
130 object->visible = 1;
131
132 scrollbar = &(object->u.scrollbar);
133 scrollbar->userData = userData;
134 scrollbar->onScroll = onScroll;
135
136 switch(orientation) {
138 switch(align) {
139 case GFUI_ALIGN_HR_VB:
140 gfuiScrollButtonCreate(scr, "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", x, y, GFUI_ALIGN_HR_VB, object, gfuiScrollPlus);
141 gfuiScrollButtonCreate(scr, "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", x - width, y, GFUI_ALIGN_HL_VB, object, gfuiScrollMinus);
142 break;
143 case GFUI_ALIGN_HR_VC:
144 gfuiScrollButtonCreate(scr, "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", x, y, GFUI_ALIGN_HR_VC, object, gfuiScrollPlus);
145 gfuiScrollButtonCreate(scr, "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", x - width, y, GFUI_ALIGN_HL_VC, object, gfuiScrollMinus);
146 break;
147 case GFUI_ALIGN_HR_VT:
148 gfuiScrollButtonCreate(scr, "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", x, y, GFUI_ALIGN_HR_VT, object, gfuiScrollPlus);
149 gfuiScrollButtonCreate(scr, "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", x - width, y, GFUI_ALIGN_HL_VT, object, gfuiScrollMinus);
150 break;
151 case GFUI_ALIGN_HC_VB:
152 gfuiScrollButtonCreate(scr, "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", x + width / 2, y, GFUI_ALIGN_HR_VB, object, gfuiScrollPlus);
153 gfuiScrollButtonCreate(scr, "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", x - width / 2, y, GFUI_ALIGN_HL_VB, object, gfuiScrollMinus);
154 break;
155 case GFUI_ALIGN_HC_VC:
156 gfuiScrollButtonCreate(scr, "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", x + width / 2, y, GFUI_ALIGN_HR_VC, object, gfuiScrollPlus);
157 gfuiScrollButtonCreate(scr, "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", x - width / 2, y, GFUI_ALIGN_HL_VC, object, gfuiScrollMinus);
158 break;
159 case GFUI_ALIGN_HC_VT:
160 gfuiScrollButtonCreate(scr, "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", x + width / 2, y, GFUI_ALIGN_HR_VT, object, gfuiScrollPlus);
161 gfuiScrollButtonCreate(scr, "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", x - width / 2, y, GFUI_ALIGN_HL_VT, object, gfuiScrollMinus);
162 break;
163 case GFUI_ALIGN_HL_VB:
164 gfuiScrollButtonCreate(scr, "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", x + width, y, GFUI_ALIGN_HR_VB, object, gfuiScrollPlus);
165 gfuiScrollButtonCreate(scr, "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", x, y, GFUI_ALIGN_HL_VB, object, gfuiScrollMinus);
166 break;
167 case GFUI_ALIGN_HL_VC:
168 gfuiScrollButtonCreate(scr, "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", x + width, y, GFUI_ALIGN_HR_VC, object, gfuiScrollPlus);
169 gfuiScrollButtonCreate(scr, "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", x, y, GFUI_ALIGN_HL_VC, object, gfuiScrollMinus);
170 break;
171 case GFUI_ALIGN_HL_VT:
172 gfuiScrollButtonCreate(scr, "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", x + width, y, GFUI_ALIGN_HR_VT, object, gfuiScrollPlus);
173 gfuiScrollButtonCreate(scr, "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", x, y, GFUI_ALIGN_HL_VT, object, gfuiScrollMinus);
174 break;
175 default:
176 break;
177 }
178 break;
180 switch(align) {
181 case GFUI_ALIGN_HR_VB:
182 gfuiScrollButtonCreate(scr, "data/img/arrow-up.png", "data/img/arrow-up-pushed.png", x, y + width, GFUI_ALIGN_HR_VT, object, gfuiScrollMinus);
183 gfuiScrollButtonCreate(scr, "data/img/arrow-down.png", "data/img/arrow-down-pushed.png", x, y, GFUI_ALIGN_HR_VB, object, gfuiScrollPlus);
184 break;
185 case GFUI_ALIGN_HR_VC:
186 gfuiScrollButtonCreate(scr, "data/img/arrow-up.png", "data/img/arrow-up-pushed.png", x, y + width / 2, GFUI_ALIGN_HR_VT, object, gfuiScrollMinus);
187 gfuiScrollButtonCreate(scr, "data/img/arrow-down.png", "data/img/arrow-down-pushed.png", x, y - width / 2, GFUI_ALIGN_HR_VB, object, gfuiScrollPlus);
188 break;
189 case GFUI_ALIGN_HR_VT:
190 gfuiScrollButtonCreate(scr, "data/img/arrow-up.png", "data/img/arrow-up-pushed.png", x, y, GFUI_ALIGN_HR_VT, object, gfuiScrollMinus);
191 gfuiScrollButtonCreate(scr, "data/img/arrow-down.png", "data/img/arrow-down-pushed.png", x, y - width, GFUI_ALIGN_HR_VB, object, gfuiScrollPlus);
192 break;
193 case GFUI_ALIGN_HC_VB:
194 gfuiScrollButtonCreate(scr, "data/img/arrow-up.png", "data/img/arrow-up-pushed.png", x, y + width, GFUI_ALIGN_HC_VT, object, gfuiScrollMinus);
195 gfuiScrollButtonCreate(scr, "data/img/arrow-down.png", "data/img/arrow-down-pushed.png", x, y, GFUI_ALIGN_HC_VB, object, gfuiScrollPlus);
196 break;
197 case GFUI_ALIGN_HC_VC:
198 gfuiScrollButtonCreate(scr, "data/img/arrow-up.png", "data/img/arrow-up-pushed.png", x, y + width / 2, GFUI_ALIGN_HC_VT, object, gfuiScrollMinus);
199 gfuiScrollButtonCreate(scr, "data/img/arrow-down.png", "data/img/arrow-down-pushed.png", x, y - width / 2, GFUI_ALIGN_HC_VB, object, gfuiScrollPlus);
200 break;
201 case GFUI_ALIGN_HC_VT:
202 gfuiScrollButtonCreate(scr, "data/img/arrow-up.png", "data/img/arrow-up-pushed.png", x, y, GFUI_ALIGN_HC_VT, object, gfuiScrollMinus);
203 gfuiScrollButtonCreate(scr, "data/img/arrow-down.png", "data/img/arrow-down-pushed.png", x, y - width, GFUI_ALIGN_HC_VB, object, gfuiScrollPlus);
204 break;
205 case GFUI_ALIGN_HL_VB:
206 gfuiScrollButtonCreate(scr, "data/img/arrow-up.png", "data/img/arrow-up-pushed.png", x, y + width, GFUI_ALIGN_HL_VT, object, gfuiScrollMinus);
207 gfuiScrollButtonCreate(scr, "data/img/arrow-down.png", "data/img/arrow-down-pushed.png", x, y, GFUI_ALIGN_HL_VB, object, gfuiScrollPlus);
208 break;
209 case GFUI_ALIGN_HL_VC:
210 gfuiScrollButtonCreate(scr, "data/img/arrow-up.png", "data/img/arrow-up-pushed.png", x, y + width / 2, GFUI_ALIGN_HL_VT, object, gfuiScrollMinus);
211 gfuiScrollButtonCreate(scr, "data/img/arrow-down.png", "data/img/arrow-down-pushed.png", x, y - width / 2, GFUI_ALIGN_HL_VB, object, gfuiScrollPlus);
212 break;
213 case GFUI_ALIGN_HL_VT:
214 gfuiScrollButtonCreate(scr, "data/img/arrow-up.png", "data/img/arrow-up-pushed.png", x, y, GFUI_ALIGN_HL_VT, object, gfuiScrollMinus);
215 gfuiScrollButtonCreate(scr, "data/img/arrow-down.png", "data/img/arrow-down-pushed.png", x, y - width, GFUI_ALIGN_HL_VB, object, gfuiScrollPlus);
216 break;
217 default:
218 break;
219 }
220 break;
221 default:
222 break;
223 }
224
225
226 gfuiAddObject(screen, object);
227 GfuiScrollBarPosSet(scr, object->id, min, max, len, start);
228 return object->id;
229}
230
238int
239GfuiScrollBarPosGet(void *scr, int id)
240{
241 tGfuiObject *object;
242 tGfuiScrollBar *scrollbar;
243
244 object = gfuiGetObject(scr, id);
245
246 if(object == NULL) {
247 return -1;
248 }
249
250 scrollbar = &(object->u.scrollbar);
251
252 return scrollbar->pos;
253}
254
266void
267GfuiScrollBarPosSet(void *scr, int id, int min, int max, int len, int start)
268{
269 tGfuiObject *object;
270 tGfuiScrollBar *scrollbar;
271
272 object = gfuiGetObject(scr, id);
273
274 if(object == NULL) {
275 return;
276 }
277
278 scrollbar = &(object->u.scrollbar);
279
280 scrollbar->min = min;
281 scrollbar->max = max;
282 scrollbar->len = len;
283 scrollbar->pos = start;
284}
285
286void
288{
289 free(curObject);
290}
Scalar min(Scalar x, Scalar y)
Definition Basic.h:49
Scalar max(Scalar x, Scalar y)
Definition Basic.h:50
static Vector y[4]
Definition Convex.cpp:56
static void onPush(tCmdInfo *cmdInfo)
int GfuiScrollBarCreate(void *scr, int x, int y, int align, int width, int orientation, int min, int max, int len, int start, void *userData, tfuiSBCallback onScroll)
Create a new scroll bar.
void GfuiScrollBarPosSet(void *scr, int id, int min, int max, int len, int start)
Set new values for position.
int GfuiGrButtonCreateAction(void *scr, const char *disabled, const char *enabled, const char *focused, const char *pushed, int x, int y, int align, int mouse, const tGfuiAction &onPush, const tGfuiAction &onFocus, const tGfuiAction &onFocusLost)
Add a graphical button to a screen.
Definition guibutton.cpp:58
int GfuiScrollBarPosGet(void *scr, int id)
Get the current position of a scroll bar.
void gfuiAddObject(tGfuiScreen *screen, tGfuiObject *object)
struct GfuiObject tGfuiObject
tGfuiObject * gfuiGetObject(void *scr, int id)
#define GFUI_FOCUS_MOUSE_CLICK
Definition gui.h:130
static void gfuiScrollMinus(tGfuiObject *object)
static void gfuiScrollPlus(tGfuiObject *object)
static void gfuiScrollButtonCreate(void *scr, const char *image, const char *pushed, int x, int y, int align, tGfuiObject *object, void(*onPush)(tGfuiObject *))
void gfuiScrollBarInit(void)
void gfuiReleaseScrollbar(tGfuiObject *curObject)
int id
Definition gui.h:194
void * userData
Associated user data.
Definition tgfclient.h:104
int pos
Current scroll bar position.
Definition tgfclient.h:103
int curId
Definition gui.h:238
tfuiSBCallback onScroll
Definition gui.h:166
void * userData
Definition gui.h:165
The Gaming Framework API (client part).
struct ScrollBarInfo tScrollBarInfo
Scroll bar call-back information.
#define GFUI_HORI_SCROLLBAR
Definition tgfclient.h:97
#define GFUI_ALIGN_HC_VC
Definition tgfclient.h:75
#define GFUI_ALIGN_HL_VB
Definition tgfclient.h:71
std::function< void()> tGfuiAction
Definition tgfclient.h:107
#define GFUI_ALIGN_HR_VB
Definition tgfclient.h:77
#define GFUI_ALIGN_HR_VC
Definition tgfclient.h:78
#define GFUI_ALIGN_HL_VT
Definition tgfclient.h:73
#define GFUI_ALIGN_HC_VT
Definition tgfclient.h:76
void(* tfuiSBCallback)(tScrollBarInfo *)
Definition tgfclient.h:109
#define GFUI_ALIGN_HC_VB
Definition tgfclient.h:74
#define GFUI_ALIGN_HR_VT
Definition tgfclient.h:79
#define GFUI_SCROLLBAR
Definition tgfclient.h:67
#define GFUI_VERT_SCROLLBAR
Definition tgfclient.h:98
#define GFUI_ALIGN_HL_VC
Definition tgfclient.h:72