Prepare new maemo release
[maemo-rb.git] / apps / plugins / test_touchscreen.c
blobb0804f7d06c251ae418cbd879232e764e4f56cd7
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 Rob Purchase
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "plugin.h"
25 #if (CONFIG_KEYPAD == COWON_D2_PAD)
26 #define TOUCHSCREEN_QUIT BUTTON_POWER
27 #define TOUCHSCREEN_TOGGLE BUTTON_MENU
28 #elif (CONFIG_KEYPAD == MROBE500_PAD)
29 #define TOUCHSCREEN_QUIT BUTTON_POWER
30 #define TOUCHSCREEN_TOGGLE BUTTON_RC_MODE
31 #elif (CONFIG_KEYPAD == ONDAVX747_PAD)
32 #define TOUCHSCREEN_QUIT BUTTON_POWER
33 #define TOUCHSCREEN_TOGGLE BUTTON_MENU
34 #elif (CONFIG_KEYPAD == ANDROID_PAD)
35 #define TOUCHSCREEN_QUIT BUTTON_BACK
36 #define TOUCHSCREEN_TOGGLE BUTTON_MENU
37 #elif (CONFIG_KEYPAD == SDL_PAD)
38 #define TOUCHSCREEN_QUIT BUTTON_MIDLEFT
39 #define TOUCHSCREEN_TOGGLE BUTTON_CENTER
40 #endif
42 /* plugin entry point */
43 enum plugin_status plugin_start(const void* parameter)
45 int button = 0;
46 enum touchscreen_mode mode = TOUCHSCREEN_BUTTON;
48 /* standard stuff */
49 (void)parameter;
51 rb->touchscreen_set_mode(mode);
53 /* wait until user closes plugin */
56 short x = 0;
57 short y = 0;
58 bool draw_rect = false;
60 button = rb->button_get(true);
62 if (button & BUTTON_TOPLEFT)
64 draw_rect = true;
65 x = 0; y = 0;
67 else if (button & BUTTON_TOPMIDDLE)
69 draw_rect = true;
70 x = LCD_WIDTH/3; y = 0;
72 else if (button & BUTTON_TOPRIGHT)
74 draw_rect = true;
75 x = 2*(LCD_WIDTH/3); y = 0;
77 else if (button & BUTTON_MIDLEFT)
79 draw_rect = true;
80 x = 0; y = LCD_HEIGHT/3;
82 else if (button & BUTTON_CENTER)
84 draw_rect = true;
85 x = LCD_WIDTH/3; y = LCD_HEIGHT/3;
87 else if (button & BUTTON_MIDRIGHT)
89 draw_rect = true;
90 x = 2*(LCD_WIDTH/3); y = LCD_HEIGHT/3;
92 else if (button & BUTTON_BOTTOMLEFT)
94 draw_rect = true;
95 x = 0; y = 2*(LCD_HEIGHT/3);
97 else if (button & BUTTON_BOTTOMMIDDLE)
99 draw_rect = true;
100 x = LCD_WIDTH/3; y = 2*(LCD_HEIGHT/3);
102 else if (button & BUTTON_BOTTOMRIGHT)
104 draw_rect = true;
105 x = 2*(LCD_WIDTH/3); y = 2*(LCD_HEIGHT/3);
108 if (button & TOUCHSCREEN_TOGGLE && (button & BUTTON_REL))
110 mode = (mode == TOUCHSCREEN_POINT) ? TOUCHSCREEN_BUTTON : TOUCHSCREEN_POINT;
111 rb->touchscreen_set_mode(mode);
114 if (button & BUTTON_REL) draw_rect = false;
116 rb->lcd_clear_display();
118 if (draw_rect)
120 rb->lcd_set_foreground(LCD_RGBPACK(0xc0, 0, 0));
121 rb->lcd_fillrect(x, y, LCD_WIDTH/3, LCD_HEIGHT/3);
124 if (draw_rect || button & BUTTON_TOUCHSCREEN)
126 intptr_t button_data = rb->button_get_data();
127 x = button_data >> 16;
128 y = button_data & 0xffff;
130 rb->lcd_set_foreground(LCD_RGBPACK(0, 0, 0xc0));
131 rb->lcd_fillrect(x-7, y-7, 14, 14);
133 /* in stylus mode, show REL position in black */
134 if (mode == TOUCHSCREEN_POINT && (button & BUTTON_REL))
135 rb->lcd_set_foreground(LCD_BLACK);
136 else
137 rb->lcd_set_foreground(LCD_WHITE);
139 rb->lcd_hline(x-5, x+5, y);
140 rb->lcd_vline(x, y-5, y+5);
142 rb->lcd_update();
144 } while (button != TOUCHSCREEN_QUIT);
146 return PLUGIN_OK;