From 2cf81a1eac66dd42ca8d5096939d5523a575b23e Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sat, 6 Feb 2016 14:50:11 +0100 Subject: [PATCH] Add shift key handling in `Application` --- src/Application/Application.cpp | 15 +++++++++++++++ src/Application/Application.h | 8 ++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index d8896c1..f682fcc 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -12,6 +12,7 @@ Application::Application(){ setState(PresentationState::instance()); ofAddListener(ofEvents().keyPressed, this, &Application::onKeyPressed); + ofAddListener(ofEvents().keyReleased, this, &Application::onKeyReleased); } void Application::setup(){ @@ -39,6 +40,10 @@ void Application::onKeyPressed(ofKeyEventArgs & args){ // before it is completely ported to the state system. switch(args.key){ + case OF_KEY_SHIFT: + _shiftKeyDown = true; + break; + case '1': _cmdManager.exec( new ofx::piMapper::SetApplicationStateCmd( @@ -91,6 +96,12 @@ void Application::onKeyPressed(ofKeyEventArgs & args){ } } +void Application::onKeyReleased(ofKeyEventArgs & args){ + if(args.key == OF_KEY_SHIFT){ + _shiftKeyDown = false; + } +} + void Application::addFboSource(FboSource & fboSource){ _mediaServer.addFboSource(fboSource); } @@ -99,6 +110,10 @@ void Application::setState(ApplicationBaseState * st){ _state = st; } +bool Application::isShiftKeyDown(){ + return _shiftKeyDown; +} + bool Application::loadXmlSettings(string fileName){ if(!ofFile::doesFileExist(fileName)){ ofLogError("Application::loadXmlSettings()") << fileName << " does not exist"; diff --git a/src/Application/Application.h b/src/Application/Application.h index 49dfeaa..93d9adf 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -36,17 +36,19 @@ class Application { void setup(); void draw(); void onKeyPressed(ofKeyEventArgs & args); + void onKeyReleased(ofKeyEventArgs & args); void addFboSource(FboSource & fboSource); bool loadXmlSettings(string fileName); + bool isShiftKeyDown(); SurfaceManagerGui * getGui(){ return &_gui; }; SurfaceManager * getSurfaceManager(){ return &_surfaceManager; }; CmdManager * getCmdManager(){ return &_cmdManager; }; - + protected: void setState(ApplicationBaseState * st); - + private: friend class ApplicationBaseState; friend class SetApplicationStateCmd; @@ -58,6 +60,8 @@ class Application { MediaServer _mediaServer; SurfaceManager _surfaceManager; Info _info; + + bool _shiftKeyDown; };