Step one for joystick handling: Centralize handling of SDL_Keys

This commit is contained in:
simon.kagstrom 2010-02-28 10:06:59 +00:00
parent 15876d1ba3
commit f790813023
17 changed files with 68 additions and 81 deletions

View File

@ -891,6 +891,7 @@ uint8 C64::poll_joystick_buttons(int port)
event_t ev = (event_t)ThePrefs.MenuJoystickButtons[i];
this->joy_button_pressed[i] = cur;
if (cur)
Gui::gui->pushEvent(ev);
if (kc == JOY_NONE)

View File

@ -186,8 +186,8 @@ void Prefs::SetupJoystickDefaults()
this->MenuJoystickButtons[12] = KEY_ESCAPE;
/* Wiimote, classic Home as enter menu */
this->MenuJoystickButtons[6] = ENTER_MENU;
this->MenuJoystickButtons[19] = ENTER_MENU;
this->MenuJoystickButtons[6] = KEY_ENTER_MENU;
this->MenuJoystickButtons[19] = KEY_ENTER_MENU;
}
/* Saitek P380 */
else if (strcmp(name, "Jess Tech Dual Analog Pad") == 0)
@ -216,6 +216,10 @@ void Prefs::SetupJoystickDefaults()
this->JoystickButtons[7] = (7 << 3) | 3;
/* Start to enter the menu */
this->MenuJoystickButtons[0] = KEY_PAGEDOWN;
this->MenuJoystickButtons[1] = KEY_PAGEUP;
this->MenuJoystickButtons[8] = KEY_ESCAPE;
this->MenuJoystickButtons[9] = KEY_ENTER_MENU;
}
}

View File

@ -442,7 +442,7 @@ public:
this->menu->runLogic();
}
void pushEvent(SDL_Event *ev)
void pushEvent(event_t ev)
{
this->menu->pushEvent(ev);
}

View File

@ -21,7 +21,7 @@ public:
~DiscView();
void pushEvent(SDL_Event *ev);
void pushEvent(event_t ev);
void loadGameInfo(const char *what);
@ -199,7 +199,7 @@ void DiscView::runLogic()
this->menu->runLogic();
}
void DiscView::pushEvent(SDL_Event *ev)
void DiscView::pushEvent(event_t ev)
{
this->menu->pushEvent(ev);
}

View File

@ -112,7 +112,7 @@ public:
this->menu->runLogic();
}
void pushEvent(SDL_Event *ev)
void pushEvent(event_t ev)
{
this->menu->pushEvent(ev);
}

View File

@ -359,6 +359,7 @@ void Gui::pushEvent(event_t ev)
return;
}
printf("Pushing event %d\n", ev);
if (this->dlg)
this->dlg->pushEvent(ev);
else if (this->kbd)
@ -369,22 +370,44 @@ void Gui::pushEvent(event_t ev)
void Gui::pushEvent(SDL_Event *ev)
{
GuiView *cur_view = this->peekView();
if (!this->is_active || !cur_view)
switch(ev->type)
{
if (this->kbd)
this->kbd->pushEvent(ev);
return;
case SDL_KEYDOWN:
switch (ev->key.keysym.sym)
{
case SDLK_UP:
this->pushEvent(KEY_UP);
break;
case SDLK_DOWN:
this->pushEvent(KEY_DOWN);
break;
case SDLK_LEFT:
this->pushEvent(KEY_LEFT);
break;
case SDLK_RIGHT:
this->pushEvent(KEY_RIGHT);
break;
case SDLK_PAGEDOWN:
this->pushEvent(KEY_PAGEDOWN);
break;
case SDLK_PAGEUP:
this->pushEvent(KEY_PAGEUP);
break;
case SDLK_RETURN:
case SDLK_SPACE:
this->pushEvent(KEY_SELECT);
break;
case SDLK_HOME:
case SDLK_ESCAPE:
this->pushEvent(KEY_ESCAPE);
break;
default:
break;
}
default:
break;
}
if (ev->type == SDL_QUIT)
exit(0);
if (this->dlg)
this->dlg->pushEvent(ev);
else if (this->kbd)
this->kbd->pushEvent(ev);
else
cur_view->pushEvent(ev);
}
void Gui::draw(SDL_Surface *where)

View File

@ -169,7 +169,7 @@ public:
this->menu->runLogic();
}
void pushEvent(SDL_Event *ev)
void pushEvent(event_t ev)
{
this->menu->pushEvent(ev);
}

View File

@ -165,7 +165,7 @@ public:
this->menu->runLogic();
}
void pushEvent(SDL_Event *ev)
void pushEvent(event_t ev)
{
this->menu->pushEvent(ev);
}

View File

@ -70,7 +70,7 @@ public:
this->menu->runLogic();
}
void pushEvent(SDL_Event *ev)
void pushEvent(event_t ev)
{
this->menu->pushEvent(ev);
}

View File

@ -233,7 +233,7 @@ void NetworkUserView::runLogic()
this->menu->runLogic();
}
void NetworkUserView::pushEvent(SDL_Event *ev)
void NetworkUserView::pushEvent(event_t ev)
{
this->menu->pushEvent(ev);
}

View File

@ -17,7 +17,7 @@ public:
void runLogic();
void pushEvent(SDL_Event *ev);
void pushEvent(event_t ev);
void setPeers(NetworkUpdateListPeers *peerList);

View File

@ -127,7 +127,7 @@ public:
this->menu->runLogic();
}
void pushEvent(SDL_Event *ev)
void pushEvent(event_t ev)
{
this->menu->pushEvent(ev);
}

View File

@ -20,7 +20,7 @@ public:
~SaveGameView();
void pushEvent(SDL_Event *ev);
void pushEvent(event_t ev);
void loadGameInfo(const char *what);
@ -193,7 +193,7 @@ void SaveGameView::runLogic()
this->menu->runLogic();
}
void SaveGameView::pushEvent(SDL_Event *ev)
void SaveGameView::pushEvent(event_t ev)
{
this->menu->pushEvent(ev);
}

View File

@ -10,7 +10,7 @@ public:
~ThemeView();
void pushEvent(SDL_Event *ev);
void pushEvent(event_t ev);
void setDirectory(const char *path);
@ -85,7 +85,7 @@ void ThemeView::runLogic()
this->menu->runLogic();
}
void ThemeView::pushEvent(SDL_Event *ev)
void ThemeView::pushEvent(event_t ev)
{
this->menu->pushEvent(ev);
}

View File

@ -439,23 +439,26 @@ void VirtualKeyboard::pushEvent(SDL_Event *ev)
if (this->buf_head > 0)
this->buf_head--;
break;
case SDLK_UP:
case SDLK_DOWN:
case SDLK_LEFT:
case SDLK_RIGHT:
case SDLK_PAGEDOWN:
case SDLK_PAGEUP:
case SDLK_HOME:
case SDLK_ESCAPE:
/* Handle via the standard widget implementation (except for space) */
this->kbd_only_input = false;
Widget::pushEvent(ev);
return;
case SDLK_UP:
this->kbd_only_input = false; Widget::pushEvent(KEY_UP); return;
case SDLK_DOWN:
this->kbd_only_input = false; Widget::pushEvent(KEY_DOWN); return;
case SDLK_LEFT:
this->kbd_only_input = false; Widget::pushEvent(KEY_LEFT); return;
case SDLK_RIGHT:
this->kbd_only_input = false; Widget::pushEvent(KEY_RIGHT); return;
case SDLK_PAGEDOWN:
this->kbd_only_input = false; Widget::pushEvent(KEY_PAGEDOWN); return;
case SDLK_PAGEUP:
this->kbd_only_input = false; Widget::pushEvent(KEY_PAGEUP); return;
case SDLK_ESCAPE:
this->kbd_only_input = false; Widget::pushEvent(KEY_ESCAPE); return;
case SDLK_RETURN:
if (this->kbd_only_input)
this->done();
else
Widget::pushEvent(ev);
Widget::pushEvent(KEY_SELECT);
return;
case SDLK_SPACE ... SDLK_z:
Widget::pushEvent((event_t)(ev->key.keysym.sym));

View File

@ -29,48 +29,6 @@ void Widget::pushEvent(event_t ev)
this->ev_tail = (this->ev_tail + 1) % 8;
}
void Widget::pushEvent(SDL_Event *ev)
{
switch(ev->type)
{
case SDL_KEYDOWN:
switch (ev->key.keysym.sym)
{
case SDLK_UP:
this->pushEvent(KEY_UP);
break;
case SDLK_DOWN:
this->pushEvent(KEY_DOWN);
break;
case SDLK_LEFT:
this->pushEvent(KEY_LEFT);
break;
case SDLK_RIGHT:
this->pushEvent(KEY_RIGHT);
break;
case SDLK_PAGEDOWN:
this->pushEvent(KEY_PAGEDOWN);
break;
case SDLK_PAGEUP:
this->pushEvent(KEY_PAGEUP);
break;
case SDLK_RETURN:
case SDLK_SPACE:
this->pushEvent(KEY_SELECT);
break;
case SDLK_HOME:
case SDLK_ESCAPE:
this->pushEvent(KEY_ESCAPE);
break;
default:
break;
}
default:
break;
}
}
void Widget::draw(SDL_Surface *where, int x, int y, int w, int h)
{
}

View File

@ -26,8 +26,6 @@ public:
virtual void pushEvent(event_t ev);
virtual void pushEvent(SDL_Event *ev);
virtual void runLogic() = 0;
virtual void draw(SDL_Surface *where,