1
0
Fork 0
forked from len0rd/rockbox

Make some more games touchscreen compatible.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17707 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Maurus Cuelenaere 2008-06-09 20:59:55 +00:00
parent fb573630b8
commit 50763d512c
2 changed files with 111 additions and 36 deletions

View file

@ -446,6 +446,20 @@ enum menu_items {
#endif #endif
#ifdef HAVE_TOUCHPAD
#include "lib/touchscreen.h"
static struct ts_mapping main_menu_items[4] =
{
{MENU_ITEMXOFS, BMPYOFS_start, MENU_ITEMWIDTH, MENU_ITEMHEIGHT},
{MENU_ITEMXOFS, BMPYOFS_resume, MENU_ITEMWIDTH, MENU_ITEMHEIGHT},
{MENU_ITEMXOFS, BMPYOFS_help, MENU_ITEMWIDTH, MENU_ITEMHEIGHT},
{MENU_ITEMXOFS, BMPYOFS_quit, MENU_ITEMWIDTH, MENU_ITEMHEIGHT}
};
static struct ts_mappings main_menu = {main_menu_items, 4};
#endif
int levels_num = 29; int levels_num = 29;
static unsigned char levels[29][8][10] = { static unsigned char levels[29][8][10] = {
@ -1008,6 +1022,18 @@ int game_menu(int when)
rb->lcd_update(); rb->lcd_update();
button = rb->button_get(true); button = rb->button_get(true);
#ifdef HAVE_TOUCHPAD
if(button & BUTTON_TOUCHPAD)
{
unsigned int result = touchscreen_map(&main_menu, rb->button_get_data() >> 16, rb->button_get_data() & 0xffff);
if(result != (unsigned)-1 && button & BUTTON_REL)
{
if(cur == (signed)result)
button = SELECT;
cur = result;
}
}
#endif
switch(button) { switch(button) {
case UP: case UP:
case UP | BUTTON_REPEAT: case UP | BUTTON_REPEAT:
@ -1147,6 +1173,9 @@ int help(int when)
switch (button) { switch (button) {
#ifdef RC_QUIT #ifdef RC_QUIT
case RC_QUIT: case RC_QUIT:
#endif
#ifdef HAVE_TOUCHPAD
case BUTTON_TOUCHPAD:
#endif #endif
case QUIT: case QUIT:
switch (game_menu(when)) { switch (game_menu(when)) {
@ -1840,46 +1869,74 @@ int game_loop(void)
button = QUIT; button = QUIT;
#endif #endif
move_button=rb->button_status(); #ifdef HAVE_TOUCHPAD
#ifdef ALTRIGHT if(button & BUTTON_TOUCHPAD)
button_right=((move_button & RIGHT) || (move_button & ALTRIGHT)); {
button_left=((move_button & LEFT) || (move_button & ALTLEFT)); short touch_x, touch_y;
#else touch_x = rb->button_get_data() >> 16;
button_right=((move_button & RIGHT) || (SCROLL_FWD(button))); touch_y = rb->button_get_data() & 0xffff;
button_left=((move_button & LEFT) || (SCROLL_BACK(button))); if(touch_y >= PAD_POS_Y && touch_y <= PAD_POS_Y+PAD_HEIGHT)
#endif {
if ((con_game== 1 && start_game!=1) && (button_right || button_left)) pad_pos_x += (flip_sides ? -1 : 1) * ( (touch_x-pad_pos_x-PAD_WIDTH/2) / 4 );
continue;
if ((button_right && flip_sides==false) || if(pad_pos_x < 0)
(button_left && flip_sides==true)) { pad_pos_x = 0;
if (pad_pos_x+8+PAD_WIDTH > LCD_WIDTH) { else if(pad_pos_x+PAD_WIDTH > LCD_WIDTH)
for(k=0;k<used_balls;k++) pad_pos_x = LCD_WIDTH-PAD_WIDTH;
if (start_game==1 || ball[k].glue)
ball[k].pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
pad_pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
}
else {
for(k=0;k<used_balls;k++) for(k=0;k<used_balls;k++)
if ((start_game==1 || ball[k].glue)) if ((start_game==1 || ball[k].glue))
ball[k].pos_x+=8; ball[k].pos_x = pad_pos_x+PAD_WIDTH/2;
pad_pos_x+=8;
} }
if(button & BUTTON_REL)
button = SELECT;
} }
else if ((button_left && flip_sides==false) || else
(button_right && flip_sides==true)) { {
if (pad_pos_x-8 < 0) { #endif
for(k=0;k<used_balls;k++) move_button=rb->button_status();
if (start_game==1 || ball[k].glue) #ifdef ALTRIGHT
ball[k].pos_x-=pad_pos_x; button_right=((move_button & RIGHT) || (move_button & ALTRIGHT));
pad_pos_x-=pad_pos_x; button_left=((move_button & LEFT) || (move_button & ALTLEFT));
#else
button_right=((move_button & RIGHT) || (SCROLL_FWD(button)));
button_left=((move_button & LEFT) || (SCROLL_BACK(button)));
#endif
if ((con_game== 1 && start_game!=1) && (button_right || button_left))
continue;
if ((button_right && flip_sides==false) ||
(button_left && flip_sides==true)) {
if (pad_pos_x+8+PAD_WIDTH > LCD_WIDTH) {
for(k=0;k<used_balls;k++)
if (start_game==1 || ball[k].glue)
ball[k].pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
pad_pos_x+=LCD_WIDTH-pad_pos_x-PAD_WIDTH;
}
else {
for(k=0;k<used_balls;k++)
if ((start_game==1 || ball[k].glue))
ball[k].pos_x+=8;
pad_pos_x+=8;
}
} }
else { else if ((button_left && flip_sides==false) ||
for(k=0;k<used_balls;k++) (button_right && flip_sides==true)) {
if (start_game==1 || ball[k].glue) if (pad_pos_x-8 < 0) {
ball[k].pos_x-=8; for(k=0;k<used_balls;k++)
pad_pos_x-=8; if (start_game==1 || ball[k].glue)
ball[k].pos_x-=pad_pos_x;
pad_pos_x-=pad_pos_x;
}
else {
for(k=0;k<used_balls;k++)
if (start_game==1 || ball[k].glue)
ball[k].pos_x-=8;
pad_pos_x-=8;
}
} }
#ifdef HAVE_TOUCHPAD
} }
#endif
switch(button) { switch(button) {

View file

@ -199,10 +199,9 @@ void singlepad(int x, int y, int set)
} }
} }
static int xpos[2]={0, LCD_WIDTH-PAD_WIDTH};
void pad(struct pong *p, int pad) void pad(struct pong *p, int pad)
{ {
static int xpos[2]={0, LCD_WIDTH-PAD_WIDTH};
/* clear existing pad */ /* clear existing pad */
singlepad(xpos[pad], p->e_pad[pad], 0); singlepad(xpos[pad], p->e_pad[pad], 0);
@ -396,12 +395,31 @@ int keys(struct pong *p)
static bool pause = false; static bool pause = false;
#endif #endif
int time = 4; /* number of ticks this function will loop reading keys */ /* number of ticks this function will loop reading keys */
#ifndef HAVE_TOUCHPAD
int time = 4;
#else
int time = 1;
#endif
int start = *rb->current_tick; int start = *rb->current_tick;
int end = start + time; int end = start + time;
while(end > *rb->current_tick) { while(end > *rb->current_tick) {
key = rb->button_get_w_tmo(end - *rb->current_tick); key = rb->button_get_w_tmo(end - *rb->current_tick);
#ifdef HAVE_TOUCHPAD
short touch_x, touch_y;
if(key & BUTTON_TOUCHPAD)
{
touch_x = rb->button_get_data() >> 16;
touch_y = rb->button_get_data() & 0xFFFF;
if(touch_x >= xpos[0] && touch_x <= xpos[0]+(PAD_WIDTH*4))
padmove(&p->w_pad[0], touch_y-(p->e_pad[0]*2+PAD_HEIGHT)/2);
if(touch_x >= xpos[1]-(PAD_WIDTH*4) && touch_x <= xpos[1])
padmove(&p->w_pad[1], touch_y-(p->e_pad[1]*2+PAD_HEIGHT)/2);
}
#endif
#ifdef HAS_BUTTON_HOLD #ifdef HAS_BUTTON_HOLD
if (rb->button_hold()) if (rb->button_hold())