mirror of
https://github.com/kr15h/ofxPiMapper.git
synced 2026-06-16 12:31:49 +02:00
Move state change keyboard mappings to Application to handle
This commit is contained in:
@@ -4,14 +4,62 @@
|
||||
namespace ofx {
|
||||
namespace piMapper {
|
||||
|
||||
Application::Application(){
|
||||
Application::Application(ofxPiMapper * opm) {
|
||||
_ofxPiMapper = opm;
|
||||
setState(PresentationState::instance());
|
||||
ofAddListener(ofEvents().keyPressed, this, &Application::onKeyPressed);
|
||||
}
|
||||
|
||||
Application::~Application() {
|
||||
_ofxPiMapper = 0;
|
||||
setState(0);
|
||||
ofRemoveListener(ofEvents().keyPressed, this, &Application::onKeyPressed);
|
||||
}
|
||||
|
||||
void Application::draw(){
|
||||
_state->draw(this);
|
||||
}
|
||||
|
||||
// Here we handle application state changes only
|
||||
void Application::onKeyPressed(ofKeyEventArgs & args) {
|
||||
switch (args.key) {
|
||||
case '1':
|
||||
ofLogNotice("Application::onKeyPressed()") << "Switching to Presentation State";
|
||||
if (_ofxPiMapper->getGui().getMode() != ofx::piMapper::GuiMode::NONE) {
|
||||
_ofxPiMapper->getCmdManager().exec(
|
||||
new ofx::piMapper::SetGuiModeCmd(&_ofxPiMapper->getGui(),
|
||||
ofx::piMapper::GuiMode::NONE));
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
ofLogNotice("Application::onKeyPressed()") << "Switching to Projection Mapping State";
|
||||
if (_ofxPiMapper->getGui().getMode() != ofx::piMapper::GuiMode::PROJECTION_MAPPING) {
|
||||
_ofxPiMapper->getCmdManager().exec(
|
||||
new ofx::piMapper::SetGuiModeCmd(&_ofxPiMapper->getGui(),
|
||||
ofx::piMapper::GuiMode::PROJECTION_MAPPING));
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
ofLogNotice("Application::onKeyPressed()") << "Switching to Source Selection State";
|
||||
if (_ofxPiMapper->getGui().getMode() != ofx::piMapper::GuiMode::SOURCE_SELECTION) {
|
||||
_ofxPiMapper->getCmdManager().exec(
|
||||
new ofx::piMapper::SetGuiModeCmd(&_ofxPiMapper->getGui(),
|
||||
ofx::piMapper::GuiMode::SOURCE_SELECTION));
|
||||
}
|
||||
break;
|
||||
case '4':
|
||||
ofLogNotice("Application::onKeyPressed()") << "Switching to Texture Mapping State";
|
||||
if (_ofxPiMapper->getGui().getMode() != ofx::piMapper::GuiMode::TEXTURE_MAPPING) {
|
||||
_ofxPiMapper->getCmdManager().exec(
|
||||
new ofx::piMapper::SetGuiModeCmd(&_ofxPiMapper->getGui(),
|
||||
ofx::piMapper::GuiMode::TEXTURE_MAPPING));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::setState(ApplicationBaseState * st){
|
||||
_state = st;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include "ofEvents.h"
|
||||
#include "ofLog.h"
|
||||
#include "ApplicationBaseState.h"
|
||||
#include "ofxPiMapper.h"
|
||||
|
||||
class ofxPiMapper;
|
||||
|
||||
namespace ofx {
|
||||
namespace piMapper {
|
||||
@@ -11,8 +14,11 @@ namespace ofx {
|
||||
|
||||
class Application {
|
||||
public:
|
||||
Application();
|
||||
Application(ofxPiMapper * opm);
|
||||
~Application();
|
||||
|
||||
void draw();
|
||||
void onKeyPressed(ofKeyEventArgs & args);
|
||||
|
||||
protected:
|
||||
void setState(ApplicationBaseState * st);
|
||||
@@ -20,6 +26,7 @@ namespace ofx {
|
||||
private:
|
||||
friend class ApplicationBaseState;
|
||||
ApplicationBaseState * _state;
|
||||
ofxPiMapper * _ofxPiMapper;
|
||||
};
|
||||
|
||||
} // namespace piMapper
|
||||
|
||||
@@ -12,6 +12,9 @@ namespace ofx {
|
||||
public:
|
||||
virtual void draw(Application * app){};
|
||||
virtual void setState(Application * app, ApplicationBaseState * st);
|
||||
|
||||
// Event handler virtual methods
|
||||
virtual void keyPressed(){};
|
||||
};
|
||||
|
||||
} // namespace piMapper
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
#include "Keyboard.h"
|
||||
|
||||
namespace ofx {
|
||||
namespace piMapper {
|
||||
|
||||
Keyboard::Keyboard(ofxPiMapper * opm) {
|
||||
_ofxPiMapper = opm;
|
||||
ofLogNotice("Keyboard event handler");
|
||||
ofAddListener(ofEvents().keyPressed, this, &Keyboard::onKeyPressed);
|
||||
}
|
||||
|
||||
Keyboard::~Keyboard() {
|
||||
_ofxPiMapper = 0;
|
||||
ofRemoveListener(ofEvents().keyPressed, this, &Keyboard::onKeyPressed);
|
||||
}
|
||||
|
||||
void Keyboard::onKeyPressed(ofKeyEventArgs & args) {
|
||||
ofLogNotice("Keyboard::onKeyPressed");
|
||||
ofLog() << args.keycode;
|
||||
|
||||
// Choose what command to create here
|
||||
// depending on the key pressed
|
||||
switch (args.key) {
|
||||
case '1':
|
||||
ofLogNotice("Keyboard::onKeyPressed") << "1";
|
||||
if (_ofxPiMapper->getGui().getMode() != ofx::piMapper::GuiMode::NONE) {
|
||||
_ofxPiMapper->getCmdManager().exec(
|
||||
new ofx::piMapper::SetGuiModeCmd(&_ofxPiMapper->getGui(),
|
||||
ofx::piMapper::GuiMode::NONE));
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
ofLogNotice("Keyboard::onKeyPressed") << "2";
|
||||
if (_ofxPiMapper->getGui().getMode() != ofx::piMapper::GuiMode::PROJECTION_MAPPING) {
|
||||
_ofxPiMapper->getCmdManager().exec(new ofx::piMapper::SetGuiModeCmd(
|
||||
&_ofxPiMapper->getGui(),
|
||||
ofx::piMapper::GuiMode::PROJECTION_MAPPING));
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
ofLogNotice("Keyboard::onKeyPressed") << "3";
|
||||
if (_ofxPiMapper->getGui().getMode() != ofx::piMapper::GuiMode::SOURCE_SELECTION) {
|
||||
_ofxPiMapper->getCmdManager().exec(new ofx::piMapper::SetGuiModeCmd(
|
||||
&_ofxPiMapper->getGui(),
|
||||
ofx::piMapper::GuiMode::SOURCE_SELECTION));
|
||||
}
|
||||
break;
|
||||
case '4':
|
||||
ofLogNotice("Keyboard::onKeyPressed") << "4";
|
||||
if (_ofxPiMapper->getGui().getMode() != ofx::piMapper::GuiMode::TEXTURE_MAPPING) {
|
||||
_ofxPiMapper->getCmdManager().exec(new ofx::piMapper::SetGuiModeCmd(
|
||||
&_ofxPiMapper->getGui(),
|
||||
ofx::piMapper::GuiMode::TEXTURE_MAPPING));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// TODO: Forward it to the application state for it to decide.
|
||||
ofLogNotice("Keyboard::onKeyPressed") << "default case";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
// Keyboard
|
||||
// Keyboard input handler
|
||||
// Creates commands on keyboard input and forwards them to the CommandManager
|
||||
// Created by Krisjanis Rijnieks on 2015-09-17
|
||||
#pragma once
|
||||
|
||||
#include "ofEvents.h"
|
||||
#include "ofEventUtils.h"
|
||||
#include "ofLog.h"
|
||||
#include "ofxPiMapper.h"
|
||||
#include "SetGuiModeCmd.h"
|
||||
#include "GuiMode.h"
|
||||
|
||||
class ofxPiMapper;
|
||||
|
||||
namespace ofx {
|
||||
namespace piMapper {
|
||||
|
||||
class Keyboard {
|
||||
public:
|
||||
Keyboard(ofxPiMapper * opm);
|
||||
~Keyboard();
|
||||
|
||||
void onKeyPressed(ofKeyEventArgs & args);
|
||||
|
||||
private:
|
||||
ofxPiMapper * _ofxPiMapper;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -32,8 +32,7 @@ void ofxPiMapper::setup(){
|
||||
|
||||
ofLogNotice("ofxPiMapper") << "Done setting up";
|
||||
|
||||
_application = new ofx::piMapper::Application();
|
||||
_keyboard = new ofx::piMapper::Keyboard(this);
|
||||
_application = new ofx::piMapper::Application(this);
|
||||
}
|
||||
|
||||
void ofxPiMapper::stateSetup() {
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
// Main view with state design pattern
|
||||
#include "Application.h" // Main application entry point
|
||||
#include "Keyboard.h"
|
||||
|
||||
#define PIMAPPER_DEF_SURFACES_XML_FILE "defaultSurfaces.xml"
|
||||
#define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml"
|
||||
@@ -73,5 +72,4 @@ class ofxPiMapper{
|
||||
|
||||
|
||||
ofx::piMapper::Application * _application;
|
||||
ofx::piMapper::Keyboard * _keyboard;
|
||||
};
|
||||
Reference in New Issue
Block a user