11 unsigned short x2, y2;
16 #define TOUCH_BUTTON_INITIALIZER(name, x, y, w, h) \
17 {SNES_##name##_MASK, 0, 0, 0, 0, x, y, w, h}
19 static TouchButton touchbuttons[] = {
20 TOUCH_BUTTON_INITIALIZER(TL, 0, 0, 0.375, 0.0833),
21 TOUCH_BUTTON_INITIALIZER(TR, 0.625, 0, 0.375, 0.0833),
22 TOUCH_BUTTON_INITIALIZER(UP, 0.125, 0.0833, 0.125, 0.2777), //2
23 TOUCH_BUTTON_INITIALIZER(LEFT, 0.0, 0.3611, 0.125, 0.2777), //3
24 TOUCH_BUTTON_INITIALIZER(RIGHT, 0.25, 0.3611, 0.125, 0.2777), //4
25 TOUCH_BUTTON_INITIALIZER(DOWN, 0.125, 0.6388, 0.125, 0.2777), //5
26 TOUCH_BUTTON_INITIALIZER(START, 0, 0.9166, 0.375, 0.0833),
27 TOUCH_BUTTON_INITIALIZER(Y, 0.75, 0.0833, 0.125, 0.2777),
28 TOUCH_BUTTON_INITIALIZER(X, 0.625, 0.3611, 0.125, 0.2777),
29 TOUCH_BUTTON_INITIALIZER(A, 0.875, 0.3611, 0.125, 0.2777),
30 TOUCH_BUTTON_INITIALIZER(B, 0.75, 0.6388, 0.125, 0.2777),
31 TOUCH_BUTTON_INITIALIZER(SELECT, 0.625, 0.9166, 0.375, 0.0833),
34 static TouchButton* current = 0;
36 static uint32 joypads[2];
40 bool enabled, pressed;
43 static TouchButton* getButtonFor(unsigned int x, unsigned int y) {
46 for (i = 0; i < sizeof(touchbuttons)/sizeof(TouchButton); i++) {
47 if (x > touchbuttons[i].x && x < touchbuttons[i].x2 &&
48 y > touchbuttons[i].y && y < touchbuttons[i].y2) {
50 return &touchbuttons[i];
57 static inline void unpress(TouchButton* b) {
58 joypads[0] &= ~b->mask;
60 static inline void press(TouchButton* b) {
61 joypads[0] |= b->mask;
64 static void processMouse(unsigned int x, unsigned int y, int pressed = 0)
66 if (Config.touchscreenInput) {
75 // Button down, or mouse motion.
76 TouchButton* b = getButtonFor(x, y);
77 if (current && b && current != b) {
78 // Moving from button to button
82 } else if (current && !b) {
86 } else if (!current && b) {
92 } else if (mouse.enabled) {
96 if (mouse.x < GUI.RenderX) mouse.x = 0;
98 mouse.x -= GUI.RenderX;
99 if (mouse.x > GUI.RenderW) mouse.x = GUI.RenderW;
102 if (mouse.y < GUI.RenderY) mouse.y = 0;
104 mouse.y -= GUI.RenderY;
105 if (mouse.y > GUI.RenderH) mouse.y = GUI.RenderH;
109 // Remember RenderH, RenderW is 2x if using Xsp.
117 mouse.pressed = true;
118 else if (pressed < 0)
119 mouse.pressed = false;
123 static void processEvent(const SDL_Event& event)
128 if (Config.action[event.key.keysym.scancode])
129 S9xDoAction(Config.action[event.key.keysym.scancode]);
130 joypads[0] |= Config.joypad1Mapping[event.key.keysym.scancode];
133 joypads[0] &= ~Config.joypad1Mapping[event.key.keysym.scancode];
135 case SDL_MOUSEBUTTONUP:
136 case SDL_MOUSEBUTTONDOWN:
137 processMouse(event.button.x, event.button.y,
138 (event.button.state == SDL_PRESSED) ? 1 : - 1);
140 case SDL_MOUSEMOTION:
141 processMouse(event.motion.x, event.motion.y);
144 Config.quitting = true;
149 uint32 S9xReadJoypad (int which)
151 if (which < 0 || which > 2) {
155 return joypads[which];
158 bool8 S9xReadMousePosition(int which1, int& x, int& y, uint32& buttons)
160 if (which1 != 0) return FALSE;
164 buttons = mouse.pressed ? 1 : 0;
169 bool8 S9xReadSuperScopePosition(int& x, int& y, uint32& buttons)
173 buttons = mouse.pressed ? 8 : 0;
178 void S9xProcessEvents(bool8_32 block)
183 SDL_WaitEvent(&event);
186 while(SDL_PollEvent(&event))
193 void S9xInitInputDevices()
198 switch (Settings.ControllerOption) {
200 joypads[0] = 0x80000000UL;
201 printf("Input: 1 joypad, keyboard only\n");
204 joypads[0] = 0x80000000UL;
205 mouse.enabled = true;
206 printf("Input: 1 joypad + mouse\n");
208 case SNES_MOUSE_SWAPPED:
209 printf("Input: mouse\n");
210 mouse.enabled = true;
212 case SNES_SUPERSCOPE:
213 joypads[0] = 0x80000000UL;
214 mouse.enabled = true;
215 printf("Input: 1 joypad + superscope\n");
218 printf("Input: unknown\n");
222 S9xInputScreenChanged();
225 void S9xDeinitInputDevices()
230 void S9xInputScreenChanged()
233 const unsigned int w = GUI.Width, h = GUI.Height;
234 for (i = 0; i < sizeof(touchbuttons)/sizeof(TouchButton); i++) {
235 touchbuttons[i].x = (unsigned)round(touchbuttons[i].fx * w);
236 touchbuttons[i].y = (unsigned)round(touchbuttons[i].fy * h);
237 touchbuttons[i].x2 = (unsigned)round(touchbuttons[i].x + touchbuttons[i].fw * w);
238 touchbuttons[i].y2 = (unsigned)round(touchbuttons[i].y + touchbuttons[i].fh * h);