-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathevent.c
179 lines (149 loc) · 3.24 KB
/
event.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
/*
* IceBreaker
* Copyright (c) 2000-2020 Matthew Miller <[email protected]> and
* Enrico Tassi <[email protected]>
*
* <http://www.mattdm.org/icebreaker/>
*
* 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 the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <SDL.h>
#include "icebreaker.h"
#include "globals.h"
#include "event.h"
#include "options.h"
#include "laundry.h"
#include "text.h"
#include "fullscreen.h"
static void alignmouse(SDL_Event* e);
int pollevent(SDL_Event* e)
{
int result = SDL_PollEvent(e);
if ( gameflags.isfullscreen && e != NULL )
alignmouse(e);
return result;
}
Uint8 getmousestate(int* mx, int* my)
{
Uint8 rc;
rc=SDL_GetMouseState(mx, my);
if (gameflags.isfullscreen)
{
*mx -= (FULLWIDTH - WIDTH) / 2;
*my -= FULLTOPMARGIN;
}
return rc;
}
void jumpmouse(int mx, int my)
{
if (gameflags.isfullscreen)
SDL_WarpMouse(mx+(FULLWIDTH - WIDTH) / 2,my+FULLTOPMARGIN);
else
SDL_WarpMouse(mx,my);
}
KeyboardActionType translatekeyevent(SDL_Event* e)
{
if ((e->type != SDL_KEYUP) && (e->type != SDL_KEYDOWN))
return KEYNONE;
switch (e->key.keysym.sym)
{
case SDLK_ESCAPE:
return KEYCANCEL;
break;
case SDLK_m:
return KEYMENU;
break;
case SDLK_p:
case SDLK_PAUSE:
return KEYPAUSE;
break;
case SDLK_F1:
return KEYHELP;
break;
case SDLK_RETURN:
case SDLK_KP_ENTER:
case SDLK_z:
case SDLK_COMMA:
case SDLK_KP0:
return KEYSTARTLINE;
break;
case SDLK_SPACE:
case SDLK_x:
case SDLK_PERIOD:
case SDLK_KP5:
return KEYSWITCHLINE;
break;
case SDLK_LEFT:
case SDLK_h:
case SDLK_KP4:
return KEYMOVELEFT;
break;
case SDLK_RIGHT:
case SDLK_l:
case SDLK_KP6:
return KEYMOVERIGHT;
break;
case SDLK_UP:
case SDLK_k:
case SDLK_KP8:
return KEYMOVEUP;
break;
case SDLK_DOWN:
case SDLK_j:
case SDLK_KP2:
return KEYMOVEDOWN;
break;
case SDLK_KP7:
case SDLK_HOME:
return KEYMOVELEFTUP;
break;
case SDLK_KP9:
case SDLK_PAGEUP:
return KEYMOVERIGHTUP;
break;
case SDLK_KP1:
case SDLK_END:
return KEYMOVELEFTDOWN;
break;
case SDLK_KP3:
case SDLK_PAGEDOWN:
return KEYMOVERIGHTDOWN;
break;
default:
return KEYNONE;
break;
}
return KEYNONE;
}
void alignmouse(SDL_Event* e)
{
switch(e->type)
{
case SDL_MOUSEMOTION:
e->motion.x -= (FULLWIDTH - WIDTH) / 2;
e->motion.y -= FULLTOPMARGIN;
e->motion.xrel -= (FULLWIDTH - WIDTH) / 2;
e->motion.yrel -= FULLTOPMARGIN;
break;
case SDL_MOUSEBUTTONDOWN: // falls through
case SDL_MOUSEBUTTONUP:
e->button.x -= (FULLWIDTH - WIDTH) / 2;
e->button.y -= FULLTOPMARGIN;
break;
default:
return;
}
}