Filter:   InfoImg
download in_ggi.c
Language: C
License: GPL
Copyright: (C) 1999 Marcus Sundberg [mackan@stacken.kth.se] (C) 1996-1997 Id Software, Inc.
LOC: 386
Project Info
QuakeForge(quake)
Server: SourceForge
Type: cvs
...ake\quake\newtree32\source\
   .cvsignore
   .gdbinit
   .indent.pro
   buildnum.c
   cd_dos.c
   cd_linux.c
   cd_null.c
   cd_sdl.c
   cd_sgi.c
   cd_win.c
   checksum.c
   cl_cam.c
   cl_cmd.c
   cl_cvar.c
   cl_demo.c
   cl_ents.c
   cl_input.c
   cl_main.c
   cl_misc.c
   cl_parse.c
   cl_pred.c
   cl_slist.c
   cl_sys_sdl.c
   cl_sys_unix.c
   cl_sys_win.c
   cl_tent.c
   cmd.c
   com.c
   console.c
   context_x11.c
   crc.c
   cvar.c
   d_edge.c
   d_fill.c
   d_init.c
   d_modech.c
   d_part.c
   d_polyse.c
   d_scan.c
   d_sky.c
   d_sprite.c
   d_surf.c
   d_vars.c
   d_zpoint.c
   dga_check.c
   dirent.c
   draw.c
   fbset.c
   fbset_modes_y.y
   fnmatch.c
   fractalnoise.c
   gl_draw.c
   gl_dyn_fires.c
   gl_dyn_part.c
   gl_dyn_textures.c
   gl_mesh.c
   gl_model_alias.c
   gl_model_brush.c
   gl_model_fullbright.c
   gl_model_sprite.c
   gl_ngraph.c
   gl_rlight.c
   gl_rmain.c
   gl_rmisc.c
   gl_rsurf.c
   gl_screen.c
   gl_skin.c
   gl_sky.c
   gl_sky_clip.c
   gl_view.c
   gl_warp.c
   hash.c
   in_fbdev.c
   in_ggi.c
   in_null.c
   in_sdl.c
   in_svgalib.c
   in_win.c
   in_x11.c
   info.c
   joy_linux.c
   joy_null.c
   joy_win.c
   keys.c
   link.c
   locs.c
   Makefile.am
   makefile.mgw
   makefile.win
   mathlib.c
   mdfour.c
   menu.c
   model.c
   model_alias.c
   model_brush.c
   model_sprite.c
   msg.c
   net_chan.c
   net_com.c
   net_packetlog.c
   net_udp.c
   net_udp6.c
   nonintel.c
   pcx.c
   pmove.c
   pmovetst.c
   pr_edict.c
   pr_exec.c
   pr_offs.c
   qargs.c
   qendian.c
   qfgl_ext.c
   quakefs.c
   quakeio.c
   r_aclip.c
   r_alias.c
   r_bsp.c
   r_draw.c
   r_edge.c
   r_efrag.c
   r_light.c
   r_main.c
   r_misc.c
   r_part.c
   r_sky.c
   r_sprite.c
   r_surf.c
   r_vars.c
   r_view.c
   sbar.c
   screen.c
   sizebuf.c
   skin.c
   snd_alsa_0_5.c
   snd_alsa_0_6.c
   snd_disk.c
   snd_dma.c
   snd_mem.c
   snd_mix.c
   snd_null.c
   snd_oss.c
   snd_sdl.c
   snd_sgi.c
   snd_sun.c
   snd_win.c
   sv_ccmds.c
   sv_cvar.c
   sv_ents.c
   sv_init.c
   sv_main.c
   sv_misc.c
   sv_model.c
   sv_move.c
   sv_nchan.c
   sv_phys.c
   sv_pr_cmds.c
   sv_progs.c
   sv_send.c
   sv_sys_unix.c
   sv_sys_win.c
   sv_user.c
   sw_model_alias.c
   sw_model_brush.c
   sw_model_sprite.c
   sw_skin.c
   sw_view.c
   sys_null.c
   sys_unix.c
   sys_win.c
   teamplay.c
   tga.c
   va.c
   ver_check.c
   vid.c
   vid_3dfxsvga.c
   vid_common_gl.c
   vid_fbdev.c
   vid_ggi.c
   vid_glx.c
   vid_mgl.c
   vid_null.c
   vid_sdl.c
   vid_sgl.c
   vid_svgalib.c
   vid_wgl.c
   vid_win.c
   vid_x11.c
   wad.c
   world.c
   zone.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
/*
	in_ggi.c

	Input handling for ggi renderer.

	Copyright (C) 1996-1997  Id Software, Inc.
	Copyright (C) 1999       Marcus Sundberg [mackan@stacken.kth.se]

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

	See the GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to:

		Free Software Foundation, Inc.
		59 Temple Place - Suite 330
		Boston, MA  02111-1307, USA

	$Id: in_ggi.c,v 1.1.1.1 2001/03/06 09:40:49 lordhavoc Exp $
*/

#define _BSD

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif

#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <ggi/ggi.h>

#include "cl_input.h"
#include "client.h"
#include "cmd.h"
#include "console.h"
#include "cvar.h"
#include "host.h"
#include "input.h"
#include "joystick.h"
#include "keys.h"
#include "qargs.h"
#include "sys.h"
#include "view.h"

cvar_t     *m_filter;
cvar_t     *_windowed_mouse;

#define NUM_STDBUTTONS	3
#define NUM_BUTTONS	10

static qboolean mouse_avail;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int  p_mouse_x, p_mouse_y;
static float old_windowed_mouse;

static ggi_visual_t ggivis = NULL;


static int
XLateKey (ggi_key_event * ev)
{
	int         key = 0;

	if (GII_KTYP (ev->label) == GII_KT_DEAD) {
		ev->label = GII_KVAL (ev->label);
	}
	switch (ev->label) {
		case GIIK_P9:
			key = KP_PGUP;
			break;
		case GIIK_PageUp:
			key = K_PGUP;
			break;

		case GIIK_P3:
			key = KP_PGDN;
			break;
		case GIIK_PageDown:
			key = K_PGDN;
			break;

		case GIIK_P7:
			key = KP_HOME;
			break;
		case GIIK_Home:
			key = K_HOME;
			break;

		case GIIK_P1:
			key = KP_END;
			break;
		case GIIK_End:
			key = K_END;
			break;

		case GIIK_P4:
			key = KP_LEFTARROW;
			break;
		case GIIK_Left:
			key = K_LEFTARROW;
			break;

		case GIIK_P6:
			key = KP_RIGHTARROW;
			break;
		case GIIK_Right:
			key = K_RIGHTARROW;
			break;

		case GIIK_P2:
			key = KP_DOWNARROW;
			break;
		case GIIK_Down:
			key = K_DOWNARROW;
			break;

		case GIIK_P8:
			key = KP_UPARROW;
			break;
		case GIIK_Up:
			key = K_UPARROW;
			break;

		case GIIK_P5:
			key = KP_5;
			break;
		case GIIK_PBegin:
			key = K_AUX32;
			break;

		case GIIK_P0:
			key = KP_INS;
			break;
		case GIIK_Insert:
			key = K_INS;
			break;

		case GIIK_PSeparator:
		case GIIK_PDecimal:
			key = KP_DEL;
			break;
		case GIIUC_Delete:
			key = K_DEL;
			break;

		case GIIK_PStar:
			key = KP_MULTIPLY;
			break;
		case GIIK_PPlus:
			key = KP_PLUS;
			break;
		case GIIK_PMinus:
			key = KP_MINUS;
			break;
		case GIIK_PSlash:
			key = KP_DIVIDE;
			break;

		case GIIK_PEnter:
			key = KP_ENTER;
			break;
		case GIIUC_Return:
			key = K_ENTER;
			break;

		case GIIUC_Escape:
			key = K_ESCAPE;
			break;

		case GIIUC_Tab:
			key = K_TAB;
			break;

		case GIIK_F1:
			key = K_F1;
			break;
		case GIIK_F2:
			key = K_F2;
			break;
		case GIIK_F3:
			key = K_F3;
			break;
		case GIIK_F4:
			key = K_F4;
			break;
		case GIIK_F5:
			key = K_F5;
			break;
		case GIIK_F6:
			key = K_F6;
			break;
		case GIIK_F7:
			key = K_F7;
			break;
		case GIIK_F8:
			key = K_F8;
			break;
		case GIIK_F9:
			key = K_F9;
			break;
		case GIIK_F10:
			key = K_F10;
			break;
		case GIIK_F11:
			key = K_F11;
			break;
		case GIIK_F12:
			key = K_F12;
			break;

		case GIIUC_BackSpace:
			key = K_BACKSPACE;
			break;

		case GIIK_ShiftL:
		case GIIK_ShiftR:
			key = K_SHIFT;
			break;

		case GIIK_Execute:
		case GIIK_CtrlL:
		case GIIK_CtrlR:
			key = K_CTRL;
			break;

		case GIIK_AltL:
		case GIIK_MetaL:
		case GIIK_AltR:
		case GIIK_MetaR:
		case GIIK_AltGr:
		case GIIK_ModeSwitch:
			key = K_ALT;
			break;

		case GIIK_Caps:
			key = K_CAPSLOCK;
			break;
		case GIIK_PrintScreen:
			key = K_PRNTSCR;
			break;
		case GIIK_ScrollLock:
			key = K_SCRLCK;
			break;
		case GIIK_Pause:
			key = K_PAUSE;
			break;
		case GIIK_NumLock:
			key = KP_NUMLCK;
			break;

		case GIIUC_Comma:
		case GIIUC_Minus:
		case GIIUC_Period:
			key = ev->label;
			break;
		case GIIUC_Section:
			key = '~';
			break;

		default:
			if (ev->label >= 0 && ev->label <= 9)
				return ev->label;
			if (ev->label >= 'A' && ev->label <= 'Z') {
				return ev->label - 'A' + 'a';
			}
			if (ev->label >= 'a' && ev->label <= 'z')
				return ev->label;

			if (ev->sym <= 0x7f) {
				key = ev->sym;
				if (key >= 'A' && key <= 'Z') {
					key = key - 'A' + 'a';
				}
				return key;
			}
			if (ev->label <= 0x7f) {
				return ev->label;
			}
			break;
	}

	return key;
}

static void
GetEvent (void)
{
	ggi_event   ev;
	uint32      b;

	ggiEventRead (ggivis, &ev, emAll);
	switch (ev.any.type) {
		case evKeyPress:
			Key_Event (XLateKey (&ev.key), 0, true);
			break;

		case evKeyRelease:
			Key_Event (XLateKey (&ev.key), 0, false);
			break;

		case evPtrRelative:
			mouse_x += (float) ev.pmove.x;
			mouse_y += (float) ev.pmove.y;
			break;

		case evPtrAbsolute:
			mouse_x += (float) (ev.pmove.x - p_mouse_x);
			mouse_y += (float) (ev.pmove.y - p_mouse_y);
			p_mouse_x = ev.pmove.x;
			p_mouse_y = ev.pmove.y;
			break;

		case evPtrButtonPress:
			if (!mouse_avail)
				return;

			b = ev.pbutton.button - 1;

			if (b < NUM_STDBUTTONS) {
				Key_Event (K_MOUSE1 + b, 0, true);
			} else if (b < NUM_STDBUTTONS + 2) {
				b -= 3;
				if (b)
					Key_Event (K_MWHEELDOWN, 0, true);
				else
					Key_Event (K_MWHEELUP, 0, true);
			} else if (b < NUM_BUTTONS) {
				Key_Event (K_AUX32 - NUM_BUTTONS + b, 0, true);
			}
			break;

		case evPtrButtonRelease:
			if (!mouse_avail)
				return;

			b = ev.pbutton.button - 1;

			if (b < NUM_STDBUTTONS) {
				Key_Event (K_MOUSE1 + b, 0, false);
			} else if (b < NUM_STDBUTTONS + 2) {
				b -= 3;
				if (b)
					Key_Event (K_MWHEELDOWN, 0, false);
				else
					Key_Event (K_MWHEELUP, 0, false);
			} else if (b < NUM_BUTTONS) {
				Key_Event (K_AUX32 - NUM_BUTTONS + b, 0, false);
			}
			break;

#if 0
		case ConfigureNotify:
//printf("config notify\n");
			config_notify_width = ev.xconfigure.width;
			config_notify_height = ev.xconfigure.height;
			config_notify = 1;
			break;

		default:
#endif
	}
}


void
IN_SendKeyEvents (void)
{
	/* Get events from LibGGI */
	if (ggivis) {
		struct timeval t = { 0, 0 };

		if (ggiEventPoll (ggivis, emAll, &t)) {
			int         i = ggiEventsQueued (ggivis, emAll);

			while (i--)
				GetEvent ();
		}
	}
}


void
IN_Init (void)
{
	JOY_Init ();

	old_windowed_mouse = -1;			/* Force update */
	if (COM_CheckParm ("-nomouse"))
		return;

	mouse_x = mouse_y = 0.0;
	mouse_avail = 1;
}

void
IN_Init_Cvars (void)
{
	JOY_Init_Cvars ();

	_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, "Have Quake grab the mouse from X when you play");
	m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, "Mouse input filtering");
}


void
IN_Shutdown (void)
{
	JOY_Shutdown ();

	Con_Printf ("IN_Shutdown\n");
	mouse_avail = 0;
}


void
IN_Commands (void)
{
	JOY_Command ();

	/* Only supported by LibGII 0.7 or later. */
#ifdef GII_CMDCODE_PREFER_RELPTR
	if (old_windowed_mouse != _windowed_mouse->int_val) {
		gii_event   ev;

		old_windowed_mouse = _windowed_mouse->int_val;

		ev.cmd.size = sizeof (gii_cmd_nodata_event);
		ev.cmd.type = evCommand;
		ev.cmd.target = GII_EV_TARGET_ALL;
		ev.cmd.code = _windowed_mouse->int_val ? GII_CMDCODE_PREFER_RELPTR
			: GII_CMDCODE_PREFER_ABSPTR;

		ggiEventSend (ggivis, &ev);
	}
#endif
}


void
IN_Move (usercmd_t *cmd)
{
	JOY_Move (cmd);

	if (!mouse_avail)
		return;

	if (m_filter->int_val) {
		mouse_x = (mouse_x + old_mouse_x) * 0.5;
		mouse_y = (mouse_y + old_mouse_y) * 0.5;
	}

	old_mouse_x = mouse_x;
	old_mouse_y = mouse_y;

	mouse_x *= sensitivity->value;
	mouse_y *= sensitivity->value;

	if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
		cmd->sidemove += m_side->value * mouse_x;
	else
		cl.viewangles[YAW] -= m_yaw->value * mouse_x;
	if (freelook)
		V_StopPitchDrift ();

	if (freelook && !(in_strafe.state & 1)) {
		cl.viewangles[PITCH] += m_pitch->value * mouse_y;
		cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
	} else {
		if ((in_strafe.state & 1) && noclip_anglehack)
			cmd->upmove -= m_forward->value * mouse_y;
		else
			cmd->forwardmove -= m_forward->value * mouse_y;
	}
	mouse_x = mouse_y = 0.0;
}