summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/target/hosted/sdl/button-sdl.c211
-rw-r--r--firmware/target/hosted/sdl/system-sdl.c13
-rw-r--r--firmware/target/hosted/sdl/system-sdl.h2
3 files changed, 127 insertions, 99 deletions
diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c
index 837c16c2ea..6890aae0ec 100644
--- a/firmware/target/hosted/sdl/button-sdl.c
+++ b/firmware/target/hosted/sdl/button-sdl.c
@@ -101,119 +101,148 @@ static void touchscreen_event(int x, int y)
101} 101}
102#endif 102#endif
103 103
104bool gui_message_loop(void) 104static void mouse_event(SDL_MouseButtonEvent *event, bool button_up)
105{ 105{
106 SDL_Event event; 106#define SQUARE(x) ((x)*(x))
107 static int x,y,xybutton = 0; 107 static int x,y;
108#ifdef SIMULATOR
109 static int xybutton = 0;
110#endif
108 111
109 while (SDL_WaitEvent(&event)) 112 if(button_up) {
110 { 113 switch ( event->button )
111 sim_enter_irq_handler();
112 switch(event.type)
113 { 114 {
114 case SDL_KEYDOWN: 115 /* The scrollwheel button up events are ignored as they are queued immediately */
115 case SDL_KEYUP: 116 case SDL_BUTTON_LEFT:
116 button_event(event.key.keysym.sym, event.type == SDL_KEYDOWN); 117 case SDL_BUTTON_MIDDLE:
117 break; 118 if ( mapping && background ) {
119 printf(" { SDLK_, %d, %d, %d, \"\" },\n", x, y,
120 (int)sqrt( SQUARE(x-(int)event->x) + SQUARE(y-(int)event->y))
121 );
122 }
123#ifdef SIMULATOR
124 if ( background && xybutton ) {
125 button_event( xybutton, false );
126 xybutton = 0;
127 }
128#endif
118#ifdef HAVE_TOUCHSCREEN 129#ifdef HAVE_TOUCHSCREEN
119 case SDL_MOUSEMOTION: 130 else
120 if (event.motion.state & SDL_BUTTON(1)) 131 button_event(BUTTON_TOUCHSCREEN, false);
121 touchscreen_event(event.motion.x, event.motion.y);
122 break;
123#endif 132#endif
124 case SDL_MOUSEBUTTONDOWN: 133 break;
125 switch ( event.button.button ) { 134 }
135 } else { /* button down */
136 switch ( event->button )
137 {
126#ifdef HAVE_SCROLLWHEEL 138#ifdef HAVE_SCROLLWHEEL
127 case SDL_BUTTON_WHEELUP: 139 case SDL_BUTTON_WHEELUP:
128 button_event( SDLK_UP, true ); 140 button_event( SDLK_UP, true );
129 break; 141 break;
130 case SDL_BUTTON_WHEELDOWN: 142 case SDL_BUTTON_WHEELDOWN:
131 button_event( SDLK_DOWN, true ); 143 button_event( SDLK_DOWN, true );
132 break; 144 break;
133#endif 145#endif
134 case SDL_BUTTON_LEFT: 146 case SDL_BUTTON_LEFT:
135 case SDL_BUTTON_MIDDLE: 147 case SDL_BUTTON_MIDDLE:
136 if ( mapping && background ) { 148 if ( mapping && background ) {
137 x = event.button.x; 149 x = event->x;
138 y = event.button.y; 150 y = event->y;
139 } 151 }
140#ifdef SIMULATOR 152#ifdef SIMULATOR
141 if ( background ) { 153 if ( background ) {
142 xybutton = xy2button( event.button.x, event.button.y ); 154 xybutton = xy2button( event->x, event->y );
143 if( xybutton ) { 155 if( xybutton ) {
144 button_event( xybutton, true ); 156 button_event( xybutton, true );
145 break; 157 break;
146 } 158 }
147 }
148#endif 159#endif
160 }
149#ifdef HAVE_TOUCHSCREEN 161#ifdef HAVE_TOUCHSCREEN
150 touchscreen_event(event.button.x, event.button.y); 162 touchscreen_event(event->x, event->y);
151#endif 163#endif
152 break; 164 break;
165 }
153 166
154 default: 167 if (debug_wps && event->button == BUTTON_LEFT)
155 break; 168 {
156 } 169 int m_x, m_y;
157 170
158 if (debug_wps && event.button.button == 1) 171 if ( background )
159 { 172 {
160 if ( background ) 173 m_x = event->x - 1;
161#ifdef HAVE_REMOTE 174 m_y = event->y - 1;
162 if ( event.button.y < UI_REMOTE_POSY ) /* Main Screen */
163 printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
164 else
165 printf("Mouse at: (%d, %d)\n", event.button.x - UI_REMOTE_POSX -1 , event.button.y - UI_REMOTE_POSY - 1 );
166#else
167 printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
168#endif
169 else
170 if ( event.button.y/display_zoom < LCD_HEIGHT ) /* Main Screen */
171 printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom );
172#ifdef HAVE_REMOTE 175#ifdef HAVE_REMOTE
173 else 176 if ( event->y >= UI_REMOTE_POSY ) /* Remote Screen */
174 printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom - LCD_HEIGHT ); 177 {
175#endif 178 m_x -= UI_REMOTE_POSX;
179 m_y -= UI_REMOTE_POSY;
176 } 180 }
177 break; 181 else
178 case SDL_MOUSEBUTTONUP:
179 switch ( event.button.button ) {
180 /* The scrollwheel button up events are ignored as they are queued immediately */
181 case SDL_BUTTON_LEFT:
182 case SDL_BUTTON_MIDDLE:
183 if ( mapping && background ) {
184 printf(" { SDLK_, %d, %d, %d, \"\" },\n", x,
185#define SQUARE(x) ((x)*(x))
186 y, (int)sqrt( SQUARE(x-(int)event.button.x)
187 + SQUARE(y-(int)event.button.y)) );
188 }
189 if ( background && xybutton ) {
190 button_event( xybutton, false );
191 xybutton = 0;
192 }
193#ifdef HAVE_TOUCHSCREEN
194 else
195 button_event(BUTTON_TOUCHSCREEN, false);
196#endif 182#endif
197 break; 183 {
198 default: 184 m_x -= UI_LCD_POSX;
199 break; 185 m_y -= UI_LCD_POSY;
200 } 186 }
201 break; 187 }
202 188 else
203
204 case SDL_QUIT:
205 { 189 {
206 sim_exit_irq_handler(); 190 m_x = event->x / display_zoom;
207 return false; 191 m_y = event->y / display_zoom;
192#ifdef HAVE_REMOTE
193 if ( m_y >= LCD_HEIGHT ) /* Remote Screen */
194 m_y -= LCD_HEIGHT;
195#endif
208 } 196 }
209 default: 197
210 /*printf("Unhandled event\n"); */ 198 printf("Mouse at: (%d, %d)\n", m_x, m_y);
211 break;
212 } 199 }
213 sim_exit_irq_handler();
214 } 200 }
201#undef SQUARE
202}
203
204static bool event_handler(SDL_Event *event)
205{
206 switch(event->type)
207 {
208 case SDL_KEYDOWN:
209 case SDL_KEYUP:
210 button_event(event->key.keysym.sym, event->type == SDL_KEYDOWN);
211 break;
212#ifdef HAVE_TOUCHSCREEN
213 case SDL_MOUSEMOTION:
214 if (event->motion.state & SDL_BUTTON(1))
215 touchscreen_event(event->motion.x, event->motion.y);
216 break;
217#endif
218
219 case SDL_MOUSEBUTTONUP:
220 case SDL_MOUSEBUTTONDOWN:
221 mouse_event(&event->button, event->type == SDL_MOUSEBUTTONUP);
222 break;
223
224 case SDL_QUIT:
225 return true;
226 }
227
228 return false;
229}
230
231void gui_message_loop(void)
232{
233 SDL_Event event;
234 bool quit;
235
236 do {
237 /* wait for the next event */
238 while(SDL_WaitEvent(&event) == 0)
239 printf("SDL_WaitEvent() error\n");
240
241 sim_enter_irq_handler();
242 quit = event_handler(&event);
243 sim_exit_irq_handler();
215 244
216 return true; 245 } while(!quit);
217} 246}
218 247
219static void button_event(int key, bool pressed) 248static void button_event(int key, bool pressed)
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c
index ff4fe6570e..6937c373e3 100644
--- a/firmware/target/hosted/sdl/system-sdl.c
+++ b/firmware/target/hosted/sdl/system-sdl.c
@@ -26,6 +26,7 @@
26#include <inttypes.h> 26#include <inttypes.h>
27#include "system.h" 27#include "system.h"
28#include "thread-sdl.h" 28#include "thread-sdl.h"
29#include "system-sdl.h"
29#include "sim-ui-defines.h" 30#include "sim-ui-defines.h"
30#include "lcd-sdl.h" 31#include "lcd-sdl.h"
31#ifdef HAVE_LCD_BITMAP 32#ifdef HAVE_LCD_BITMAP
@@ -69,10 +70,6 @@ void sys_poweroff(void)
69} 70}
70 71
71/* 72/*
72 * Button read loop */
73bool gui_message_loop(void);
74
75/*
76 * This thread will read the buttons in an interrupt like fashion, and 73 * This thread will read the buttons in an interrupt like fashion, and
77 * also initializes SDL_INIT_VIDEO and the surfaces 74 * also initializes SDL_INIT_VIDEO and the surfaces
78 * 75 *
@@ -85,7 +82,7 @@ static int sdl_event_thread(void * param)
85{ 82{
86 SDL_InitSubSystem(SDL_INIT_VIDEO); 83 SDL_InitSubSystem(SDL_INIT_VIDEO);
87 84
88 SDL_Surface *picture_surface; 85 SDL_Surface *picture_surface = NULL;
89 int width, height; 86 int width, height;
90 87
91 /* Try and load the background image. If it fails go without */ 88 /* Try and load the background image. If it fails go without */
@@ -134,7 +131,10 @@ static int sdl_event_thread(void * param)
134 131
135 /* 132 /*
136 * finally enter the button loop */ 133 * finally enter the button loop */
137 while(gui_message_loop()); 134 gui_message_loop();
135
136 if(picture_surface)
137 SDL_FreeSurface(picture_surface);
138 138
139 /* Order here is relevent to prevent deadlocks and use of destroyed 139 /* Order here is relevent to prevent deadlocks and use of destroyed
140 sync primitives by kernel threads */ 140 sync primitives by kernel threads */
@@ -151,7 +151,6 @@ void sim_do_exit(void)
151 151
152 SDL_Quit(); 152 SDL_Quit();
153 exit(EXIT_SUCCESS); 153 exit(EXIT_SUCCESS);
154 while(1);
155} 154}
156 155
157void system_init(void) 156void system_init(void)
diff --git a/firmware/target/hosted/sdl/system-sdl.h b/firmware/target/hosted/sdl/system-sdl.h
index dcb21f36bb..01952e50a0 100644
--- a/firmware/target/hosted/sdl/system-sdl.h
+++ b/firmware/target/hosted/sdl/system-sdl.h
@@ -44,7 +44,7 @@ void sim_exit_irq_handler(void);
44void sim_kernel_shutdown(void); 44void sim_kernel_shutdown(void);
45void sys_poweroff(void); 45void sys_poweroff(void);
46void sys_handle_argv(int argc, char *argv[]); 46void sys_handle_argv(int argc, char *argv[]);
47bool gui_message_loop(void); 47void gui_message_loop(void);
48void sim_do_exit(void); 48void sim_do_exit(void);
49 49
50extern bool background; /* True if the background image is enabled */ 50extern bool background; /* True if the background image is enabled */