File: user_sdl.c

package info (click to toggle)
s3d 0.2.2-10
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,544 kB
  • ctags: 5,243
  • sloc: ansic: 20,861; python: 488; perl: 98; makefile: 39; sh: 29
file content (160 lines) | stat: -rw-r--r-- 4,457 bytes parent folder | download | duplicates (3)
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
/*
 * user_sdl.c
 *
 * Copyright (C) 2004-2011  Simon Wunderlich <sw@simonwunderlich.de>
 *
 * This file is part of s3d, a 3d network display server.
 * See http://s3d.berlios.de/ for more updates.
 *
 * s3d 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.
 *
 * s3d 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 s3d; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "global.h"
#include <SDL.h>
/*  this file reads user input */
/*  this is done right now by SDL-polling */

int user_init_sdl(void)
{
	SDL_EnableUNICODE(1);
	return 0;
}

int user_main_sdl(void)
{
	SDL_Event event;
	while (SDL_PollEvent(&event)) {
		switch (event.type) {
		case SDL_MOUSEMOTION:
			/*    s3dprintf(VLOW,"Current mouse position is: (%d, %d),button %d", event.motion.x, event.motion.y,event.button.button); */
			switch (event.button.button) {
			case SDL_BUTTON_LEFT:
				user_mouse(0, 2, event.motion.x, event.motion.y);
				break;
			case SDL_BUTTON_MIDDLE:
				user_mouse(1, 2, event.motion.x, event.motion.y);
				break;
			case SDL_BUTTON_RIGHT:
			case SDL_BUTTON_RMASK:
				user_mouse(2, 2, event.motion.x, event.motion.y);
				break;
			case 0:
				user_mouse(-1, -1, event.motion.x, event.motion.y);
				break;
				/*  no button ... */
			default:
				s3dprintf(LOW, "don't know button %d", event.button.button);

			}
			break;
		case SDL_MOUSEBUTTONDOWN:
			switch (event.button.button) {
			case SDL_BUTTON_LEFT:
				user_mouse(0, 0, event.motion.x, event.motion.y);
				break;
			case SDL_BUTTON_MIDDLE:
				user_mouse(1, 0, event.motion.x, event.motion.y);
				break;
			case SDL_BUTTON_RIGHT:
				user_mouse(2, 0, event.motion.x, event.motion.y);
				break;
			case SDL_BUTTON_WHEELUP:
				user_mouse(3, 0, event.motion.x, event.motion.y);
				break;
			case SDL_BUTTON_WHEELDOWN:
				user_mouse(4, 0, event.motion.x, event.motion.y);
				break;
			default:
				s3dprintf(LOW, "don't know button %d", event.button.button);
			}
			break;
		case SDL_MOUSEBUTTONUP:
			switch (event.button.button) {
			case SDL_BUTTON_LEFT:
				user_mouse(0, 1, event.motion.x, event.motion.y);
				break;
			case SDL_BUTTON_MIDDLE:
				user_mouse(1, 1, event.motion.x, event.motion.y);
				break;
			case SDL_BUTTON_RIGHT:
				user_mouse(2, 1, event.motion.x, event.motion.y);
				break;
			case SDL_BUTTON_WHEELUP:
				user_mouse(3, 1, event.motion.x, event.motion.y);
				break;
			case SDL_BUTTON_WHEELDOWN:
				user_mouse(4, 1, event.motion.x, event.motion.y);
				break;
			default:
				s3dprintf(LOW, "don't know button %d", event.button.button);
			}
			break;

		case SDL_KEYDOWN:
			user_key(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod, 0);
			break;
		case SDL_KEYUP:
			user_key(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod, 1);
			break;
		case SDL_QUIT:
			s3dprintf(HIGH, "SDL_QUIT");
			quit();
			break;
			/*  these events are not processed right now ... */
		case SDL_ACTIVEEVENT:
			s3dprintf(VLOW, "SDL_ACTIVEEVENT");
			break;
		case SDL_SYSWMEVENT:
			s3dprintf(VLOW, "SDL_SYSWMEVENT");
			break;
		case SDL_VIDEORESIZE:
			if (SDL_SetVideoMode(event.resize.w, event.resize.h, 16, SDLFlags) == NULL)
				errsf("SDL_SetVideoMode()", SDL_GetError());
			graphics_reshape(event.resize.w, event.resize.h);
			break;
		case SDL_VIDEOEXPOSE:
			s3dprintf(VLOW, "SDL_VIDEOEXPOSE");
			break;
		case SDL_USEREVENT:
			s3dprintf(VLOW, "SDL_USEREVENT");
			break;
		case SDL_JOYAXISMOTION:
			s3dprintf(VLOW, "SDL_JOYAXISMOTION");
			break;
		case SDL_JOYBALLMOTION:
			s3dprintf(VLOW, "SDL_JOYBALLMOTION");
			break;
		case SDL_JOYHATMOTION:
			s3dprintf(VLOW, "SDL_JOYHATMOTION");
			break;
		case SDL_JOYBUTTONDOWN:
			s3dprintf(VLOW, "SDL_JOYBUTTONDOWN");
			break;
		case SDL_JOYBUTTONUP:
			s3dprintf(VLOW, "SDL_JOYBUTTONUP");
			break;
		default:
			s3dprintf(MED, "SDL_PollEvent(): unhandled event");
			break;
		}
	}
	return 0;

}

int user_quit_sdl(void)
{
	return 0;
}