summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/sdl/button-sdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/sdl/button-sdl.c')
-rw-r--r--firmware/target/hosted/sdl/button-sdl.c211
1 files changed, 120 insertions, 91 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)