forked from len0rd/rockbox
SDL enhancements:
- remove infinite loop after exit() - make sure picture_surface is initialized, and free it - split gui_message_loop() in 3 functions and change prototype - some code is only used in simulator git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27366 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
2f271ac54a
commit
1edfe3fd47
3 changed files with 141 additions and 113 deletions
|
@ -101,28 +101,40 @@ static void touchscreen_event(int x, int y)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool gui_message_loop(void)
|
static void mouse_event(SDL_MouseButtonEvent *event, bool button_up)
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
#define SQUARE(x) ((x)*(x))
|
||||||
static int x,y,xybutton = 0;
|
static int x,y;
|
||||||
|
#ifdef SIMULATOR
|
||||||
while (SDL_WaitEvent(&event))
|
static int xybutton = 0;
|
||||||
{
|
|
||||||
sim_enter_irq_handler();
|
|
||||||
switch(event.type)
|
|
||||||
{
|
|
||||||
case SDL_KEYDOWN:
|
|
||||||
case SDL_KEYUP:
|
|
||||||
button_event(event.key.keysym.sym, event.type == SDL_KEYDOWN);
|
|
||||||
break;
|
|
||||||
#ifdef HAVE_TOUCHSCREEN
|
|
||||||
case SDL_MOUSEMOTION:
|
|
||||||
if (event.motion.state & SDL_BUTTON(1))
|
|
||||||
touchscreen_event(event.motion.x, event.motion.y);
|
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
|
||||||
switch ( event.button.button ) {
|
if(button_up) {
|
||||||
|
switch ( event->button )
|
||||||
|
{
|
||||||
|
/* The scrollwheel button up events are ignored as they are queued immediately */
|
||||||
|
case SDL_BUTTON_LEFT:
|
||||||
|
case SDL_BUTTON_MIDDLE:
|
||||||
|
if ( mapping && background ) {
|
||||||
|
printf(" { SDLK_, %d, %d, %d, \"\" },\n", x, y,
|
||||||
|
(int)sqrt( SQUARE(x-(int)event->x) + SQUARE(y-(int)event->y))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#ifdef SIMULATOR
|
||||||
|
if ( background && xybutton ) {
|
||||||
|
button_event( xybutton, false );
|
||||||
|
xybutton = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
else
|
||||||
|
button_event(BUTTON_TOUCHSCREEN, false);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else { /* button down */
|
||||||
|
switch ( event->button )
|
||||||
|
{
|
||||||
#ifdef HAVE_SCROLLWHEEL
|
#ifdef HAVE_SCROLLWHEEL
|
||||||
case SDL_BUTTON_WHEELUP:
|
case SDL_BUTTON_WHEELUP:
|
||||||
button_event( SDLK_UP, true );
|
button_event( SDLK_UP, true );
|
||||||
|
@ -134,86 +146,103 @@ bool gui_message_loop(void)
|
||||||
case SDL_BUTTON_LEFT:
|
case SDL_BUTTON_LEFT:
|
||||||
case SDL_BUTTON_MIDDLE:
|
case SDL_BUTTON_MIDDLE:
|
||||||
if ( mapping && background ) {
|
if ( mapping && background ) {
|
||||||
x = event.button.x;
|
x = event->x;
|
||||||
y = event.button.y;
|
y = event->y;
|
||||||
}
|
}
|
||||||
#ifdef SIMULATOR
|
#ifdef SIMULATOR
|
||||||
if ( background ) {
|
if ( background ) {
|
||||||
xybutton = xy2button( event.button.x, event.button.y );
|
xybutton = xy2button( event->x, event->y );
|
||||||
if( xybutton ) {
|
if( xybutton ) {
|
||||||
button_event( xybutton, true );
|
button_event( xybutton, true );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
#ifdef HAVE_TOUCHSCREEN
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
touchscreen_event(event.button.x, event.button.y);
|
touchscreen_event(event->x, event->y);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug_wps && event.button.button == 1)
|
if (debug_wps && event->button == BUTTON_LEFT)
|
||||||
{
|
{
|
||||||
if ( background )
|
int m_x, m_y;
|
||||||
#ifdef HAVE_REMOTE
|
|
||||||
if ( event.button.y < UI_REMOTE_POSY ) /* Main Screen */
|
|
||||||
printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
|
|
||||||
else
|
|
||||||
printf("Mouse at: (%d, %d)\n", event.button.x - UI_REMOTE_POSX -1 , event.button.y - UI_REMOTE_POSY - 1 );
|
|
||||||
#else
|
|
||||||
printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
|
|
||||||
#endif
|
|
||||||
else
|
|
||||||
if ( event.button.y/display_zoom < LCD_HEIGHT ) /* Main Screen */
|
|
||||||
printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom );
|
|
||||||
#ifdef HAVE_REMOTE
|
|
||||||
else
|
|
||||||
printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom - LCD_HEIGHT );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
switch ( event.button.button ) {
|
|
||||||
/* The scrollwheel button up events are ignored as they are queued immediately */
|
|
||||||
case SDL_BUTTON_LEFT:
|
|
||||||
case SDL_BUTTON_MIDDLE:
|
|
||||||
if ( mapping && background ) {
|
|
||||||
printf(" { SDLK_, %d, %d, %d, \"\" },\n", x,
|
|
||||||
#define SQUARE(x) ((x)*(x))
|
|
||||||
y, (int)sqrt( SQUARE(x-(int)event.button.x)
|
|
||||||
+ SQUARE(y-(int)event.button.y)) );
|
|
||||||
}
|
|
||||||
if ( background && xybutton ) {
|
|
||||||
button_event( xybutton, false );
|
|
||||||
xybutton = 0;
|
|
||||||
}
|
|
||||||
#ifdef HAVE_TOUCHSCREEN
|
|
||||||
else
|
|
||||||
button_event(BUTTON_TOUCHSCREEN, false);
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
if ( background )
|
||||||
|
{
|
||||||
|
m_x = event->x - 1;
|
||||||
|
m_y = event->y - 1;
|
||||||
|
#ifdef HAVE_REMOTE
|
||||||
|
if ( event->y >= UI_REMOTE_POSY ) /* Remote Screen */
|
||||||
|
{
|
||||||
|
m_x -= UI_REMOTE_POSX;
|
||||||
|
m_y -= UI_REMOTE_POSY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
m_x -= UI_LCD_POSX;
|
||||||
|
m_y -= UI_LCD_POSY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_x = event->x / display_zoom;
|
||||||
|
m_y = event->y / display_zoom;
|
||||||
|
#ifdef HAVE_REMOTE
|
||||||
|
if ( m_y >= LCD_HEIGHT ) /* Remote Screen */
|
||||||
|
m_y -= LCD_HEIGHT;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Mouse at: (%d, %d)\n", m_x, m_y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#undef SQUARE
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool event_handler(SDL_Event *event)
|
||||||
|
{
|
||||||
|
switch(event->type)
|
||||||
|
{
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
case SDL_KEYUP:
|
||||||
|
button_event(event->key.keysym.sym, event->type == SDL_KEYDOWN);
|
||||||
|
break;
|
||||||
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
case SDL_MOUSEMOTION:
|
||||||
|
if (event->motion.state & SDL_BUTTON(1))
|
||||||
|
touchscreen_event(event->motion.x, event->motion.y);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
mouse_event(&event->button, event->type == SDL_MOUSEBUTTONUP);
|
||||||
|
break;
|
||||||
|
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
{
|
return true;
|
||||||
sim_exit_irq_handler();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
/*printf("Unhandled event\n"); */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sim_exit_irq_handler();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_message_loop(void)
|
||||||
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
bool quit;
|
||||||
|
|
||||||
|
do {
|
||||||
|
/* wait for the next event */
|
||||||
|
while(SDL_WaitEvent(&event) == 0)
|
||||||
|
printf("SDL_WaitEvent() error\n");
|
||||||
|
|
||||||
|
sim_enter_irq_handler();
|
||||||
|
quit = event_handler(&event);
|
||||||
|
sim_exit_irq_handler();
|
||||||
|
|
||||||
|
} while(!quit);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void button_event(int key, bool pressed)
|
static void button_event(int key, bool pressed)
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "thread-sdl.h"
|
#include "thread-sdl.h"
|
||||||
|
#include "system-sdl.h"
|
||||||
#include "sim-ui-defines.h"
|
#include "sim-ui-defines.h"
|
||||||
#include "lcd-sdl.h"
|
#include "lcd-sdl.h"
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
|
@ -68,10 +69,6 @@ void sys_poweroff(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Button read loop */
|
|
||||||
bool gui_message_loop(void);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This thread will read the buttons in an interrupt like fashion, and
|
* This thread will read the buttons in an interrupt like fashion, and
|
||||||
* also initializes SDL_INIT_VIDEO and the surfaces
|
* also initializes SDL_INIT_VIDEO and the surfaces
|
||||||
|
@ -85,7 +82,7 @@ static int sdl_event_thread(void * param)
|
||||||
{
|
{
|
||||||
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
||||||
|
|
||||||
SDL_Surface *picture_surface;
|
SDL_Surface *picture_surface = NULL;
|
||||||
int width, height;
|
int width, height;
|
||||||
|
|
||||||
/* Try and load the background image. If it fails go without */
|
/* Try and load the background image. If it fails go without */
|
||||||
|
@ -134,7 +131,10 @@ static int sdl_event_thread(void * param)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* finally enter the button loop */
|
* finally enter the button loop */
|
||||||
while(gui_message_loop());
|
gui_message_loop();
|
||||||
|
|
||||||
|
if(picture_surface)
|
||||||
|
SDL_FreeSurface(picture_surface);
|
||||||
|
|
||||||
/* Order here is relevent to prevent deadlocks and use of destroyed
|
/* Order here is relevent to prevent deadlocks and use of destroyed
|
||||||
sync primitives by kernel threads */
|
sync primitives by kernel threads */
|
||||||
|
@ -151,7 +151,6 @@ void sim_do_exit(void)
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
while(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void system_init(void)
|
void system_init(void)
|
||||||
|
|
|
@ -44,7 +44,7 @@ void sim_exit_irq_handler(void);
|
||||||
void sim_kernel_shutdown(void);
|
void sim_kernel_shutdown(void);
|
||||||
void sys_poweroff(void);
|
void sys_poweroff(void);
|
||||||
void sys_handle_argv(int argc, char *argv[]);
|
void sys_handle_argv(int argc, char *argv[]);
|
||||||
bool gui_message_loop(void);
|
void gui_message_loop(void);
|
||||||
void sim_do_exit(void);
|
void sim_do_exit(void);
|
||||||
|
|
||||||
extern bool background; /* True if the background image is enabled */
|
extern bool background; /* True if the background image is enabled */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue