Tied in my recent Android flick gesture addition to a Scroll() function. GameState now has a virtual function OnScroll() call that, by default is a no-op; each game state can choose to override how to respond to flick gestures. I've added one such override in the Deck Editor so that a flick up/down acts like the psp button up/down for scrolling between color filters.

This commit is contained in:
wrenczes@gmail.com
2011-06-15 09:52:11 +00:00
parent e1dc1afa74
commit 741f662bb0
9 changed files with 298 additions and 240 deletions
+2
View File
@@ -82,6 +82,8 @@ public:
///
//////////////////////////////////////////////////////////////////////////
virtual void Resume() = 0;
virtual void OnScroll(int inXVelocity, int inYVelocity) = 0;
};
+4
View File
@@ -319,6 +319,10 @@ class JGE
// Returns false if nothing has been clicked, true otherwise
bool GetLeftClickCoordinates(int& x, int& y);
// Scroll events - currently triggered by SDL JOYBALL events
void Scroll(int inXVelocity, int inYVelocity);
//////////////////////////////////////////////////////////////////////////
/// Get if the system is ended/paused or not.
///
+32 -9
View File
@@ -78,7 +78,8 @@ void JGE::PressKey(const LocalKeySym sym)
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
if (rng.first == rng.second)
keyBuffer.push(triplet(sym, JGE_BTN_NONE, false));
else for (keycodes_it it = rng.first; it != rng.second; ++it) {
else for (keycodes_it it = rng.first; it != rng.second; ++it)
{
#if defined (WIN32) || defined (LINUX)
if (JGE_BTN_FULLSCREEN == it->second) JGEToggleFullscreen();
#endif
@@ -185,10 +186,17 @@ void JGE::Update(float dt)
{
for (map<JButton, float>::iterator it = holds.begin(); it != holds.end(); ++it)
{
if (it->second < 0) { keyBuffer.push(triplet(LOCAL_KEY_NONE, it->first, true)); it->second = REPEAT_PERIOD; }
if (it->second < 0)
{
keyBuffer.push(triplet(LOCAL_KEY_NONE, it->first, true));
it->second = REPEAT_PERIOD;
}
it->second -= dt;
}
if (mApp != NULL) mApp->Update();
if (mApp != NULL)
mApp->Update();
oldHolds = holds;
}
@@ -259,8 +267,15 @@ void JGE::ResetBindings()
}
JGE::keybindings_it JGE::KeyBindings_begin() { return keyBinds.begin(); }
JGE::keybindings_it JGE::KeyBindings_end() { return keyBinds.end(); }
JGE::keybindings_it JGE::KeyBindings_begin()
{
return keyBinds.begin();
}
JGE::keybindings_it JGE::KeyBindings_end()
{
return keyBinds.end();
}
void JGE::ResetInput()
{
@@ -478,14 +493,16 @@ void JGE::Destroy()
}
}
void JGE::SetARGV(int argc, char * argv[]){
void JGE::SetARGV(int argc, char * argv[])
{
for (int i = 0; i < argc; ++i){
string s = argv[i];
mArgv.push_back(s);
}
}
std::vector<std::string> JGE::GetARGV() {
std::vector<std::string> JGE::GetARGV()
{
return mArgv;
}
@@ -515,7 +532,6 @@ void JGE::printf(const char *format, ...)
va_start(list, format);
vsprintf(mDebuggingMsg, format, list);
va_end(list);
}
void JGE::Pause()
@@ -526,7 +542,6 @@ void JGE::Pause()
if (mApp != NULL) mApp->Pause();
}
void JGE::Resume()
{
if (mPaused)
@@ -544,5 +559,13 @@ void JGE::Assert(const char *filename, long lineNumber)
mCriticalAssert = true;
}
void JGE::Scroll(int inXVelocity, int inYVelocity)
{
if (mApp != NULL)
{
mApp->OnScroll(inXVelocity, inYVelocity);
}
}
std::queue< pair< pair<LocalKeySym, JButton>, bool> > JGE::keyBuffer;
std::multimap<LocalKeySym, JButton> JGE::keyBinds;
+12 -8
View File
@@ -45,6 +45,17 @@ const int kHitzonePliancy = 50;
// tick value equates to ms
const int kTapEventTimeout = 250;
uint64_t lastTickCount;
JGE* g_engine = NULL;
JApp* g_app = NULL;
JGameLauncher* g_launcher = NULL;
class SdlApp;
SdlApp *g_SdlApp = NULL;
class SdlApp
{
public: /* For easy interfacing with JGE static functions */
@@ -215,6 +226,7 @@ public:
case SDL_JOYBALLMOTION:
DebugTrace("Flick gesture detected, x: " << Event->jball.xrel << ", y: " << Event->jball.yrel);
g_engine->Scroll(Event->jball.xrel, Event->jball.yrel);
break;
}
}
@@ -228,14 +240,6 @@ public:
}
};
uint64_t lastTickCount;
JGE* g_engine = NULL;
JApp* g_app = NULL;
JGameLauncher* g_launcher = NULL;
SdlApp *g_SdlApp = NULL;
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
{
/* windows controls */
+2
View File
@@ -89,6 +89,8 @@ public:
virtual void Pause();
virtual void Resume();
virtual void OnScroll(int inXVelocity, int inYVelocity);
void LoadGameStates();
void SetNextState(int state);
void DoTransition(int trans, int tostate, float dur = -1, bool animonly = false);
+4
View File
@@ -55,6 +55,10 @@ public:
virtual void Start(){}
virtual void End(){}
virtual void OnScroll(int inXVelocity, int inYVelocity)
{
}
virtual void Update(float dt) = 0;
virtual void Render() = 0;
@@ -141,6 +141,8 @@ public:
int loadDeck(int deckid);
void LoadDeckStatistics(int deckId);
void OnScroll(int inXVelocity, int inYVelocity);
void buildEditorMenu();
virtual void ButtonPressed(int controllerId, int controlId);
};
+8
View File
@@ -424,6 +424,14 @@ void GameApp::Render()
}
void GameApp::OnScroll(int inXVelocity, int inYVelocity)
{
if (mCurrentState != NULL)
{
mCurrentState->OnScroll(inXVelocity, inYVelocity);
}
}
void GameApp::SetNextState(int state)
{
mNextState = mGameStates[state];
+9
View File
@@ -1668,3 +1668,12 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
}
}
void GameStateDeckViewer::OnScroll(int inXVelocity, int inYVelocity)
{
if (abs(inYVelocity) > 300)
{
bool flickUpwards = (inYVelocity < 0);
mEngine->HoldKey_NoRepeat(flickUpwards ? JGE_BTN_DOWN : JGE_BTN_UP);
}
}