Release s3d 0.2.2
[s3d.git] / server / user_sdl.c
blobefeb90bdc7a1f627e195b3619108e27cec7ce6c4
1 /*
2 * user_sdl.c
4 * Copyright (C) 2004-2011 Simon Wunderlich <dotslash@packetmixer.de>
6 * This file is part of s3d, a 3d network display server.
7 * See http://s3d.berlios.de/ for more updates.
9 * s3d is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * s3d is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with s3d; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "global.h"
25 #include <SDL.h>
26 /* this file reads user input */
27 /* this is done right now by SDL-polling */
29 int user_init_sdl(void)
31 SDL_EnableUNICODE(1);
32 return 0;
35 int user_main_sdl(void)
37 SDL_Event event;
38 while (SDL_PollEvent(&event)) {
39 switch (event.type) {
40 case SDL_MOUSEMOTION:
41 /* s3dprintf(VLOW,"Current mouse position is: (%d, %d),button %d", event.motion.x, event.motion.y,event.button.button); */
42 switch (event.button.button) {
43 case SDL_BUTTON_LEFT:
44 user_mouse(0, 2, event.motion.x, event.motion.y);
45 break;
46 case SDL_BUTTON_MIDDLE:
47 user_mouse(1, 2, event.motion.x, event.motion.y);
48 break;
49 case SDL_BUTTON_RIGHT:
50 case SDL_BUTTON_RMASK:
51 user_mouse(2, 2, event.motion.x, event.motion.y);
52 break;
53 case 0:
54 user_mouse(-1, -1, event.motion.x, event.motion.y);
55 break;
56 /* no button ... */
57 default:
58 s3dprintf(LOW, "don't know button %d", event.button.button);
61 break;
62 case SDL_MOUSEBUTTONDOWN:
63 switch (event.button.button) {
64 case SDL_BUTTON_LEFT:
65 user_mouse(0, 0, event.motion.x, event.motion.y);
66 break;
67 case SDL_BUTTON_MIDDLE:
68 user_mouse(1, 0, event.motion.x, event.motion.y);
69 break;
70 case SDL_BUTTON_RIGHT:
71 user_mouse(2, 0, event.motion.x, event.motion.y);
72 break;
73 case SDL_BUTTON_WHEELUP:
74 user_mouse(3, 0, event.motion.x, event.motion.y);
75 break;
76 case SDL_BUTTON_WHEELDOWN:
77 user_mouse(4, 0, event.motion.x, event.motion.y);
78 break;
79 default:
80 s3dprintf(LOW, "don't know button %d", event.button.button);
82 break;
83 case SDL_MOUSEBUTTONUP:
84 switch (event.button.button) {
85 case SDL_BUTTON_LEFT:
86 user_mouse(0, 1, event.motion.x, event.motion.y);
87 break;
88 case SDL_BUTTON_MIDDLE:
89 user_mouse(1, 1, event.motion.x, event.motion.y);
90 break;
91 case SDL_BUTTON_RIGHT:
92 user_mouse(2, 1, event.motion.x, event.motion.y);
93 break;
94 case SDL_BUTTON_WHEELUP:
95 user_mouse(3, 1, event.motion.x, event.motion.y);
96 break;
97 case SDL_BUTTON_WHEELDOWN:
98 user_mouse(4, 1, event.motion.x, event.motion.y);
99 break;
100 default:
101 s3dprintf(LOW, "don't know button %d", event.button.button);
103 break;
105 case SDL_KEYDOWN:
106 user_key(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod, 0);
107 break;
108 case SDL_KEYUP:
109 user_key(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod, 1);
110 break;
111 case SDL_QUIT:
112 s3dprintf(HIGH, "SDL_QUIT");
113 quit();
114 break;
115 /* these events are not processed right now ... */
116 case SDL_ACTIVEEVENT:
117 s3dprintf(VLOW, "SDL_ACTIVEEVENT");
118 break;
119 case SDL_SYSWMEVENT:
120 s3dprintf(VLOW, "SDL_SYSWMEVENT");
121 break;
122 case SDL_VIDEORESIZE:
123 if (SDL_SetVideoMode(event.resize.w, event.resize.h, 16, SDLFlags) == NULL)
124 errsf("SDL_SetVideoMode()", SDL_GetError());
125 graphics_reshape(event.resize.w, event.resize.h);
126 break;
127 case SDL_VIDEOEXPOSE:
128 s3dprintf(VLOW, "SDL_VIDEOEXPOSE");
129 break;
130 case SDL_USEREVENT:
131 s3dprintf(VLOW, "SDL_USEREVENT");
132 break;
133 case SDL_JOYAXISMOTION:
134 s3dprintf(VLOW, "SDL_JOYAXISMOTION");
135 break;
136 case SDL_JOYBALLMOTION:
137 s3dprintf(VLOW, "SDL_JOYBALLMOTION");
138 break;
139 case SDL_JOYHATMOTION:
140 s3dprintf(VLOW, "SDL_JOYHATMOTION");
141 break;
142 case SDL_JOYBUTTONDOWN:
143 s3dprintf(VLOW, "SDL_JOYBUTTONDOWN");
144 break;
145 case SDL_JOYBUTTONUP:
146 s3dprintf(VLOW, "SDL_JOYBUTTONUP");
147 break;
148 default:
149 s3dprintf(MED, "SDL_PollEvent(): unhandled event");
150 break;
153 return 0;
157 int user_quit_sdl(void)
159 return 0;