summaryrefslogtreecommitdiff
path: root/uisimulator/buttonmap/touchscreen.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/buttonmap/touchscreen.c')
-rw-r--r--uisimulator/buttonmap/touchscreen.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/uisimulator/buttonmap/touchscreen.c b/uisimulator/buttonmap/touchscreen.c
new file mode 100644
index 0000000000..746a6d5f20
--- /dev/null
+++ b/uisimulator/buttonmap/touchscreen.c
@@ -0,0 +1,103 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 Jonathan Gordon
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23#include <stdio.h>
24#include <SDL.h>
25#include "button.h"
26#include "buttonmap.h"
27#include "touchscreen.h"
28
29int key_to_touch(int keyboard_button)
30{
31 int new_btn = BUTTON_NONE;
32 switch (keyboard_button)
33 {
34 case BUTTON_TOUCHSCREEN:
35 switch (touchscreen_get_mode())
36 {
37 case TOUCHSCREEN_POINT:
38 new_btn = BUTTON_TOUCHSCREEN;
39 break;
40 case TOUCHSCREEN_BUTTON:
41 {
42 static const int touchscreen_buttons[3][3] = {
43 {BUTTON_TOPLEFT, BUTTON_TOPMIDDLE, BUTTON_TOPRIGHT},
44 {BUTTON_MIDLEFT, BUTTON_CENTER, BUTTON_MIDRIGHT},
45 {BUTTON_BOTTOMLEFT, BUTTON_BOTTOMMIDDLE, BUTTON_BOTTOMRIGHT},
46 };
47 int px_x = ((mouse_coords&0xffff0000)>>16);
48 int px_y = ((mouse_coords&0x0000ffff));
49 new_btn = touchscreen_buttons[px_y/(LCD_HEIGHT/3)][px_x/(LCD_WIDTH/3)];
50 break;
51 }
52 }
53 break;
54 case SDLK_KP7:
55 case SDLK_7:
56 new_btn = BUTTON_TOPLEFT;
57 break;
58 case SDLK_KP8:
59 case SDLK_8:
60 case SDLK_UP:
61 new_btn = BUTTON_TOPMIDDLE;
62 break;
63 case SDLK_KP9:
64 case SDLK_9:
65 new_btn = BUTTON_TOPRIGHT;
66 break;
67 case SDLK_KP4:
68 case SDLK_u:
69 case SDLK_LEFT:
70 new_btn = BUTTON_MIDLEFT;
71 break;
72 case SDLK_KP5:
73 case SDLK_i:
74 new_btn = BUTTON_CENTER;
75 break;
76 case SDLK_KP6:
77 case SDLK_o:
78 case SDLK_RIGHT:
79 new_btn = BUTTON_MIDRIGHT;
80 break;
81 case SDLK_KP1:
82 case SDLK_j:
83 new_btn = BUTTON_BOTTOMLEFT;
84 break;
85 case SDLK_KP2:
86 case SDLK_k:
87 case SDLK_DOWN:
88 new_btn = BUTTON_BOTTOMMIDDLE;
89 break;
90 case SDLK_KP3:
91 case SDLK_l:
92 new_btn = BUTTON_BOTTOMRIGHT;
93 break;
94 case SDLK_F4:
95 if(pressed)
96 {
97 touchscreen_set_mode(touchscreen_get_mode() == TOUCHSCREEN_POINT ? TOUCHSCREEN_BUTTON : TOUCHSCREEN_POINT);
98 printf("Touchscreen mode: %s\n", touchscreen_get_mode() == TOUCHSCREEN_POINT ? "TOUCHSCREEN_POINT" : "TOUCHSCREEN_BUTTON");
99 }
100 break;
101 }
102 return new_btn;
103}