From: Alberto Mardegan Date: Fri, 8 Jul 2011 08:47:28 +0000 (+0300) Subject: Use touchscreen to rotate the view left/right X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=d961d25e3758e97ed61db61d2a397be759605ec2;p=neverball Use touchscreen to rotate the view left/right --- diff --git a/ball/st_play.c b/ball/st_play.c index 6fe1a5d..59077bb 100644 --- a/ball/st_play.c +++ b/ball/st_play.c @@ -384,9 +384,63 @@ static void play_loop_timer(int id, float dt) } } +#ifdef __MAEMO__ +#define TOUCH_SENSITIVITY 20 +static int button_pressed = 0; +static int button_pressed_x = 0; +static int button_pressed_y = 0; +static int dragging = 0; + +static void maemo_play_loop_point(int id, int x, int y, int dx, int dy) +{ + if (!dragging && button_pressed) + { + /* check how much we've moved */ + if (abs(x - button_pressed_x) > TOUCH_SENSITIVITY || + abs(y - button_pressed_y) > TOUCH_SENSITIVITY) + dragging = 1; + } + + if (dragging) + { + if (dx > 0) + { + view_rotate.d = DIR_R; + view_rotate.R = dx / 15.0; + } + else + { + view_rotate.d = DIR_L; + view_rotate.L = dx / 15.0; + } + } +} + +static void maemo_play_loop_click(int b, int d) +{ + if (d) + { + int y; + SDL_GetMouseState(&button_pressed_x, &y); + button_pressed_y = -y + config_get_d(CONFIG_HEIGHT); + } + else + { + VIEWR_SET_R(0); + VIEWR_SET_L(0); + } + button_pressed = d; + dragging = 0; +} +#endif + static void play_loop_point(int id, int x, int y, int dx, int dy) { +#ifndef __MAEMO__ game_set_pos(dx, dy); +#else + maemo_play_loop_point(id, x, y, dx, dy); +#endif } static void play_loop_stick(int id, int a, float v, int bump) @@ -407,6 +461,7 @@ static void play_loop_stick(int id, int a, float v, int bump) static int play_loop_click(int b, int d) { +#ifndef __MAEMO__ if (d) { if (config_tst_d(CONFIG_MOUSE_CAMERA_R, b)) @@ -423,6 +478,9 @@ static int play_loop_click(int b, int d) if (config_tst_d(CONFIG_MOUSE_CAMERA_L, b)) VIEWR_SET_L(0); } +#else + maemo_play_loop_click(b, d); +#endif return 1; }