Mercurial > sdl-ios-xcode
comparison src/video/dc/SDL_dcevents.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | 11134dc42da8 |
children | e1da92da346c |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
29 | 29 |
30 #include <dc/maple.h> | 30 #include <dc/maple.h> |
31 #include <dc/maple/mouse.h> | 31 #include <dc/maple/mouse.h> |
32 #include <dc/maple/keyboard.h> | 32 #include <dc/maple/keyboard.h> |
33 | 33 |
34 const static unsigned short sdl_key[]= { | 34 const static unsigned short sdl_key[] = { |
35 /*0*/ 0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', | 35 /*0 */ 0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', |
36 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', | 36 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', |
37 'u', 'v', 'w', 'x', 'y', 'z', | 37 'u', 'v', 'w', 'x', 'y', 'z', |
38 /*1e*/ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', | 38 /*1e */ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', |
39 /*28*/ SDLK_RETURN, SDLK_ESCAPE, SDLK_BACKSPACE, SDLK_TAB, SDLK_SPACE, SDLK_MINUS, SDLK_PLUS, SDLK_LEFTBRACKET, | 39 /*28 */ SDLK_RETURN, SDLK_ESCAPE, SDLK_BACKSPACE, SDLK_TAB, SDLK_SPACE, |
40 SDLK_RIGHTBRACKET, SDLK_BACKSLASH , 0, SDLK_SEMICOLON, SDLK_QUOTE, | 40 SDLK_MINUS, SDLK_PLUS, SDLK_LEFTBRACKET, |
41 /*35*/ '~', SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH, SDLK_CAPSLOCK, | 41 SDLK_RIGHTBRACKET, SDLK_BACKSLASH, 0, SDLK_SEMICOLON, SDLK_QUOTE, |
42 SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_F11, SDLK_F12, | 42 /*35 */ '~', SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH, SDLK_CAPSLOCK, |
43 /*46*/ SDLK_PRINT, SDLK_SCROLLOCK, SDLK_PAUSE, SDLK_INSERT, SDLK_HOME, SDLK_PAGEUP, SDLK_DELETE, SDLK_END, SDLK_PAGEDOWN, SDLK_RIGHT, SDLK_LEFT, SDLK_DOWN, SDLK_UP, | 43 SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, SDLK_F7, SDLK_F8, |
44 /*53*/ SDLK_NUMLOCK, SDLK_KP_DIVIDE, SDLK_KP_MULTIPLY, SDLK_KP_MINUS, SDLK_KP_PLUS, SDLK_KP_ENTER, | 44 SDLK_F9, SDLK_F10, SDLK_F11, SDLK_F12, |
45 SDLK_KP1, SDLK_KP2, SDLK_KP3, SDLK_KP4, SDLK_KP5, SDLK_KP6, | 45 /*46 */ SDLK_PRINT, SDLK_SCROLLOCK, SDLK_PAUSE, SDLK_INSERT, SDLK_HOME, |
46 /*5f*/ SDLK_KP7, SDLK_KP8, SDLK_KP9, SDLK_KP0, SDLK_KP_PERIOD, 0 /* S3 */ | 46 SDLK_PAGEUP, SDLK_DELETE, SDLK_END, SDLK_PAGEDOWN, SDLK_RIGHT, |
47 SDLK_LEFT, SDLK_DOWN, SDLK_UP, | |
48 /*53 */ SDLK_NUMLOCK, SDLK_KP_DIVIDE, SDLK_KP_MULTIPLY, SDLK_KP_MINUS, | |
49 SDLK_KP_PLUS, SDLK_KP_ENTER, | |
50 SDLK_KP1, SDLK_KP2, SDLK_KP3, SDLK_KP4, SDLK_KP5, SDLK_KP6, | |
51 /*5f */ SDLK_KP7, SDLK_KP8, SDLK_KP9, SDLK_KP0, SDLK_KP_PERIOD, 0 | |
52 /* S3 */ | |
47 }; | 53 }; |
48 | 54 |
49 const static unsigned short sdl_shift[] = { | 55 const static unsigned short sdl_shift[] = { |
50 SDLK_LCTRL,SDLK_LSHIFT,SDLK_LALT,0 /* S1 */, | 56 SDLK_LCTRL, SDLK_LSHIFT, SDLK_LALT, 0 /* S1 */ , |
51 SDLK_RCTRL,SDLK_RSHIFT,SDLK_RALT,0 /* S2 */, | 57 SDLK_RCTRL, SDLK_RSHIFT, SDLK_RALT, 0 /* S2 */ , |
52 }; | 58 }; |
53 | 59 |
54 #define MOUSE_WHEELUP (1<<4) | 60 #define MOUSE_WHEELUP (1<<4) |
55 #define MOUSE_WHEELDOWN (1<<5) | 61 #define MOUSE_WHEELDOWN (1<<5) |
56 | 62 |
57 static void mouse_update(void) | 63 static void |
64 mouse_update(void) | |
58 { | 65 { |
59 const static char sdl_mousebtn[] = { | 66 const static char sdl_mousebtn[] = { |
60 MOUSE_LEFTBUTTON, | 67 MOUSE_LEFTBUTTON, |
61 MOUSE_RIGHTBUTTON, | 68 MOUSE_RIGHTBUTTON, |
62 MOUSE_SIDEBUTTON, | 69 MOUSE_SIDEBUTTON, |
63 MOUSE_WHEELUP, | 70 MOUSE_WHEELUP, |
64 MOUSE_WHEELDOWN | 71 MOUSE_WHEELDOWN |
65 }; | 72 }; |
66 | 73 |
67 uint8 addr; | 74 uint8 addr; |
68 mouse_cond_t cond; | 75 mouse_cond_t cond; |
69 | 76 |
70 static int prev_buttons; | 77 static int prev_buttons; |
71 int buttons,changed; | 78 int buttons, changed; |
72 int i; | 79 int i; |
73 | 80 |
74 if ((addr = maple_first_mouse())==0 || mouse_get_cond(addr, &cond)<0) return; | 81 if ((addr = maple_first_mouse()) == 0 || mouse_get_cond(addr, &cond) < 0) |
82 return; | |
75 | 83 |
76 buttons = cond.buttons^0xff; | 84 buttons = cond.buttons ^ 0xff; |
77 if (cond.dz<0) buttons|=MOUSE_WHEELUP; | 85 if (cond.dz < 0) |
78 if (cond.dz>0) buttons|=MOUSE_WHEELDOWN; | 86 buttons |= MOUSE_WHEELUP; |
87 if (cond.dz > 0) | |
88 buttons |= MOUSE_WHEELDOWN; | |
79 | 89 |
80 if (cond.dx||cond.dy) SDL_PrivateMouseMotion(0,1,cond.dx,cond.dy); | 90 if (cond.dx || cond.dy) |
91 SDL_PrivateMouseMotion(0, 1, cond.dx, cond.dy); | |
81 | 92 |
82 changed = buttons^prev_buttons; | 93 changed = buttons ^ prev_buttons; |
83 for(i=0;i<sizeof(sdl_mousebtn);i++) { | 94 for (i = 0; i < sizeof(sdl_mousebtn); i++) { |
84 if (changed & sdl_mousebtn[i]) { | 95 if (changed & sdl_mousebtn[i]) { |
85 SDL_PrivateMouseButton((buttons & sdl_mousebtn[i])?SDL_PRESSED:SDL_RELEASED,i,0,0); | 96 SDL_PrivateMouseButton((buttons & sdl_mousebtn[i]) ? |
86 } | 97 SDL_PRESSED : SDL_RELEASED, i, 0, 0); |
87 } | 98 } |
88 prev_buttons = buttons; | 99 } |
100 prev_buttons = buttons; | |
89 } | 101 } |
90 | 102 |
91 static void keyboard_update(void) | 103 static void |
104 keyboard_update(void) | |
92 { | 105 { |
93 static kbd_state_t old_state; | 106 static kbd_state_t old_state; |
94 static uint8 old_addr; | 107 static uint8 old_addr; |
95 | 108 |
96 kbd_state_t *state; | 109 kbd_state_t *state; |
97 uint8 addr; | 110 uint8 addr; |
98 int port,unit; | 111 int port, unit; |
99 | 112 |
100 int shiftkeys; | 113 int shiftkeys; |
101 SDL_keysym keysym; | 114 SDL_keysym keysym; |
102 | 115 |
103 int i; | 116 int i; |
104 | 117 |
105 addr = maple_first_kb(); | 118 addr = maple_first_kb(); |
106 | 119 |
107 if (addr==0) return; | 120 if (addr == 0) |
121 return; | |
108 | 122 |
109 if (addr!=old_addr) { | 123 if (addr != old_addr) { |
110 old_addr = addr; | 124 old_addr = addr; |
111 SDL_memset(&old_state,0,sizeof(old_state)); | 125 SDL_memset(&old_state, 0, sizeof(old_state)); |
112 } | 126 } |
113 | 127 |
114 maple_raddr(addr,&port,&unit); | 128 maple_raddr(addr, &port, &unit); |
115 | 129 |
116 state = maple_dev_state(port,unit); | 130 state = maple_dev_state(port, unit); |
117 if (!state) return; | 131 if (!state) |
132 return; | |
118 | 133 |
119 shiftkeys = state->shift_keys ^ old_state.shift_keys; | 134 shiftkeys = state->shift_keys ^ old_state.shift_keys; |
120 for(i=0;i<sizeof(sdl_shift);i++) { | 135 for (i = 0; i < sizeof(sdl_shift); i++) { |
121 if ((shiftkeys>>i)&1) { | 136 if ((shiftkeys >> i) & 1) { |
122 keysym.sym = sdl_shift[i]; | 137 keysym.sym = sdl_shift[i]; |
123 SDL_PrivateKeyboard(((state->shift_keys>>i)&1)?SDL_PRESSED:SDL_RELEASED,&keysym); | 138 SDL_PrivateKeyboard(((state-> |
124 } | 139 shift_keys >> i) & 1) ? SDL_PRESSED : |
125 } | 140 SDL_RELEASED, &keysym); |
141 } | |
142 } | |
126 | 143 |
127 for(i=0;i<sizeof(sdl_key);i++) { | 144 for (i = 0; i < sizeof(sdl_key); i++) { |
128 if (state->matrix[i]!=old_state.matrix[i]) { | 145 if (state->matrix[i] != old_state.matrix[i]) { |
129 int key = sdl_key[i]; | 146 int key = sdl_key[i]; |
130 if (key) { | 147 if (key) { |
131 keysym.sym = key; | 148 keysym.sym = key; |
132 SDL_PrivateKeyboard(state->matrix[i]?SDL_PRESSED:SDL_RELEASED,&keysym); | 149 SDL_PrivateKeyboard(state-> |
133 } | 150 matrix[i] ? SDL_PRESSED : |
134 } | 151 SDL_RELEASED, &keysym); |
135 } | 152 } |
153 } | |
154 } | |
136 | 155 |
137 old_state = *state; | 156 old_state = *state; |
138 } | 157 } |
139 | 158 |
140 void DC_PumpEvents(_THIS) | 159 void |
160 DC_PumpEvents(_THIS) | |
141 { | 161 { |
142 keyboard_update(); | 162 keyboard_update(); |
143 mouse_update(); | 163 mouse_update(); |
144 } | 164 } |
145 | 165 |
146 void DC_InitOSKeymap(_THIS) | 166 void |
167 DC_InitOSKeymap(_THIS) | |
147 { | 168 { |
148 /* do nothing. */ | 169 /* do nothing. */ |
149 } | 170 } |
150 | 171 |
151 /* end of SDL_dcevents.c ... */ | 172 /* end of SDL_dcevents.c ... */ |
152 | 173 /* vi: set ts=4 sw=4 expandtab: */ |