File: user_sdl.c

package info (click to toggle)
s3d 0.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,708 kB
  • sloc: ansic: 23,609; python: 488; perl: 98; makefile: 31; sh: 29
file content (137 lines) | stat: -rw-r--r-- 3,624 bytes parent folder | download
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
// SPDX-License-Identifier: GPL-2.0-or-later
/* SPDX-FileCopyrightText: 2004-2015  Simon Wunderlich <sw@simonwunderlich.de>
 */

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

int user_init_sdl(void)
{
	return 0;
}

int user_main_sdl(void)
{
	SDL_Event event;
	uint32_t unicode = 0;

	while (SDL_PollEvent(&event)) {
		switch (event.type) {
		case SDL_EVENT_MOUSE_MOTION :
			/*    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_EVENT_MOUSE_BUTTON_DOWN :
			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;
			default:
				s3dprintf(LOW, "don't know button %d", event.button.button);
			}
			break;
		case SDL_EVENT_MOUSE_BUTTON_UP :
			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;
			default:
				s3dprintf(LOW, "don't know button %d", event.button.button);
			}
			break;
		case SDL_EVENT_MOUSE_WHEEL :
			if (event.wheel.y > 0) {
				user_mouse(3, 0, event.motion.x, event.motion.y);
				user_mouse(3, 1, event.motion.x, event.motion.y);
			}
			if (event.wheel.y < 0) {
				user_mouse(4, 0, event.motion.x, event.motion.y);
				user_mouse(4, 1, event.motion.x, event.motion.y);
			}
			break;
		case SDL_EVENT_KEY_DOWN :
		case SDL_EVENT_KEY_UP :
			unicode = 0;
			if (event.key.key < 256) {
				unicode = event.key.key;
				if (unicode >= 'a' && unicode <= 'z') {
					int shifted = !!(event.key.mod & SDL_KMOD_SHIFT);
					int capslock = !!(event.key.mod & SDL_KMOD_CAPS);
					if ((shifted ^ capslock) != 0) {
						unicode = SDL_toupper(unicode);
					}
				}
			}
			user_key(event.key.key, unicode, event.key.mod,
				 (event.type == SDL_EVENT_KEY_UP) ? 1 : 0);
			break;
		case SDL_EVENT_QUIT :
			s3dprintf(HIGH, "SDL_QUIT");
			quit();
			break;
		case SDL_EVENT_WINDOW_RESIZED :
			graphics_reshape(event.window.data1, event.window.data2);
			break;
		case SDL_EVENT_USER :
			s3dprintf(VLOW, "SDL_USEREVENT");
			break;
		case SDL_EVENT_JOYSTICK_AXIS_MOTION :
			s3dprintf(VLOW, "SDL_JOYAXISMOTION");
			break;
		case SDL_EVENT_JOYSTICK_BALL_MOTION :
			s3dprintf(VLOW, "SDL_JOYBALLMOTION");
			break;
		case SDL_EVENT_JOYSTICK_HAT_MOTION :
			s3dprintf(VLOW, "SDL_JOYHATMOTION");
			break;
		case SDL_EVENT_JOYSTICK_BUTTON_DOWN :
			s3dprintf(VLOW, "SDL_JOYBUTTONDOWN");
			break;
		case SDL_EVENT_JOYSTICK_BUTTON_UP :
			s3dprintf(VLOW, "SDL_JOYBUTTONUP");
			break;
		default:
			s3dprintf(MED, "SDL_PollEvent(): unhandled event");
			break;
		}
	}
	return 0;

}

int user_quit_sdl(void)
{
	return 0;
}