TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
mouseconfig.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 file : mouseconfig.cpp
4 created : Thu Mar 13 21:27:03 CET 2003
5 copyright : (C) 2003-2026 by Eric EspiƩ, Bernhard Wymann
6 email : berniw@blueiwn.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
24
25#include <stdio.h>
26#include <stdlib.h>
27
28#include <tgfclient.h>
29#include <track.h>
30#include <robot.h>
31#include <playerpref.h>
32#include <plib/js.h>
33
34#include "controlconfig.h"
35#include "mouseconfig.h"
36
37static void *scrHandle2 = NULL;
38
40
41// TODO: refactor, this is horrible, depends on the order in controlconfig.cpp, static tCmdInfo Cmd[]
42#define CMD_OFFSET 7
43
44/*
45 * Mouse calibration
46 */
47static int InstId;
48static int CalState;
49static int scrw, scrh;
50
51static tCmdInfo *Cmd;
52static int maxCmd;
53
54static const char *Instructions[] = {
55 "Move Mouse for maximum left steer then press a button",
56 "Move Mouse for maximum right steer then press a button",
57 "Move Mouse for full throttle then press a button",
58 "Move Mouse for full brake then press a button",
59 "Calibration terminated",
60 "Calibration failed"
61};
62
63static void Idle2(void);
64
65static int
67{
68 int i;
69
70 for (i = CalState; i < 4; i++) {
71 if (Cmd[CMD_OFFSET + i].ref.type == GFCTRL_TYPE_MOUSE_AXIS) {
72 return i;
73 }
74 }
75 return i;
76}
77
78
79static void
81{
82 float axv;
83
84 switch (CalState) {
85 case 0:
86 case 1:
88 axv = mouseInfo.ax[Cmd[CMD_OFFSET + CalState].ref.index];
89 if (fabs(axv) < 0.01) {
90 return; /* ignore no move input */
91 }
92 Cmd[CMD_OFFSET + CalState].max = axv;
93 Cmd[CMD_OFFSET + CalState].pow = 1.0 / axv;
94 break;
95
96 case 2:
97 case 3:
99 axv = mouseInfo.ax[Cmd[CMD_OFFSET + CalState].ref.index];
100 if (fabs(axv) < 0.01) {
101 return; /* ignore no move input */
102 }
103 Cmd[CMD_OFFSET + CalState].max = axv;
104 Cmd[CMD_OFFSET + CalState].pow = 1.0 / axv;
105 break;
106 }
107
108 CalState++;
111 if (CalState < 4) {
112 glutIdleFunc(Idle2);
113 } else {
114 glutIdleFunc(GfuiIdle);
115 }
116}
117
118static void
119Idle2(void)
120{
121 int i;
122
124
125 /* Check for a mouse button pressed */
126 for (i = 0; i < 3; i++) {
127 if (mouseInfo.edgedn[i]) {
129 return;
130 }
131 }
132}
133
134static void
136{
137 /* Get the center mouse position */
138 memset(&mouseInfo, 0, sizeof(mouseInfo));
141 glutIdleFunc(Idle2);
142}
143
144static void
146{
147 int dummy;
148
149 GfScrGetSize(&scrw, &scrh, &dummy, &dummy);
150 CalState = 0;
151 GetNextAxis();
153 if (CalState < 4) {
154 glutIdleFunc(IdleMouseInit);
156 }
157}
158
159void *
160MouseCalMenuInit(void *prevMenu, tCmdInfo *cmd, int maxcmd)
161{
162 //int x, y, dy;
163
164 Cmd = cmd;
165 maxCmd = maxcmd;
166
167 if (scrHandle2) {
168 return scrHandle2;
169 }
170
172 GfuiTitleCreate(scrHandle2, "Mouse Calibration", 0);
174
175 GfuiScreenAddBgImg(scrHandle2, "data/img/splash-mousecal.png");
176
177 //x = 128;
178 //y = 300;
179 //dy = 50;
180
182
184 [prevMenu] { GfuiScreenActivate(prevMenu); }, tGfuiAction(), tGfuiAction());
185
188
189 return scrHandle2;
190}
static tCtrlMouseInfo mouseInfo
static tCmdInfo Cmd[]
static int maxCmd
int GfctrlMouseGetCurrent(tCtrlMouseInfo *mouseInfo)
Get the mouse current values.
Definition control.cpp:425
void GfctrlMouseInitCenter(void)
Get the reference position.
Definition control.cpp:485
void GfctrlMouseCenter(void)
Recentre the mouse on the screen.
Definition control.cpp:473
void * GfuiScreenCreateExAction(float *bgColor, const tGfuiAction &onActivate, const tGfuiAction &onDeactivate, int mouseAllowed)
Create a screen.
Definition gui.cpp:619
void GfuiMenuDefaultKeysAdd(void *scr)
Add the default menu keyboard callback to a screen.
Definition guimenu.cpp:56
void GfuiLabelSetText(void *scr, int id, const char *text)
Change the text of a label.
Definition guilabel.cpp:193
int GfuiTitleCreate(void *scr, const char *text, int maxlen)
Add a Title to the screen.
Definition guilabel.cpp:150
void GfuiScreenAddBgImg(void *scr, const char *filename)
Add an image background to a screen.
Definition gui.cpp:1058
void GfuiIdle(void)
Process held-mouse-button repeat actions on the active screen.
Definition gui.cpp:152
int GfuiLabelCreate(void *scr, const char *text, int font, int x, int y, int align, int maxlen)
Add a label to a screen.
Definition guilabel.cpp:121
void GfuiScreenActivate(void *screen)
Activate a screen and make it current.
Definition gui.cpp:508
int GfuiButtonCreateAction(void *scr, const char *text, int font, int x, int y, int width, int align, int mouse, const tGfuiAction &onPush, const tGfuiAction &onFocus, const tGfuiAction &onFocusLost)
Add a button to a screen.
void GfScrGetSize(int *scrw, int *scrh, int *vieww, int *viewh)
Get the screen and viewport sizes.
Definition screen.cpp:529
static const char * Instructions[]
static void * scrHandle2
static void Idle2(void)
static int InstId
static int CalState
static int scrh
static int scrw
void * MouseCalMenuInit(void *prevMenu, tCmdInfo *cmd, int maxcmd)
static int GetNextAxis(void)
static void onActivate2(void)
static void Idle2(void)
static void IdleMouseInit(void)
static void MouseCalAutomaton(void)
#define CMD_OFFSET
Mouse information structure.
Definition tgfclient.h:502
#define GFUI_FONT_LARGE
Definition tgfclient.h:248
#define GFUI_FONT_MEDIUM
Definition tgfclient.h:249
@ GFCTRL_TYPE_MOUSE_AXIS
Definition tgfclient.h:467
#define GFUI_MOUSE_UP
Definition tgfclient.h:82
std::function< void()> tGfuiAction
Definition tgfclient.h:107
#define GFUI_ALIGN_HC_VB
Definition tgfclient.h:74