Skip to content

Commit

Permalink
added ofxFenster::addListener(ofBaseApp*)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Whitfield committed Nov 7, 2011
1 parent 1384b08 commit 30bd2ae
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 76 deletions.
9 changes: 5 additions & 4 deletions example/src/testApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,20 @@ void testApp::draw()
//--------------------------------------------------------------
void testApp::keyPressed(int key)
{
if(key == 'c')
cout << "CLIPBOARD DATA: " << ofxFensterManager::get()->getClipboard() << endl;

}

//--------------------------------------------------------------
void testApp::keyReleased(int key, ofxFenster* win)
void testApp::keyReleased(int key)
{
//cout << (0x0400) << endl;
//cout << (101 | OF_KEY_MODIFIER) << " " << key << endl;
if(key=='f')
win->toggleFullscreen();
ofxFensterManager::get()->getPrimaryWindow()->toggleFullscreen();
if(key==' ')
ofxFensterManager::get()->createFenster(0, 0, 400, 300, OF_WINDOW)->addListener(&imgWin);
if(key == 'c')
cout << "CLIPBOARD DATA: " << ofxFensterManager::get()->getClipboard() << endl;
}

//this only works if testApp is extending ofxFensterListener and not ofBaseApp
Expand Down
6 changes: 5 additions & 1 deletion example/src/testApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class imageWindow: public ofxFensterListener {
void keyReleased(int key, ofxFenster* window) {
if(key==' ')
ofxFensterManager::get()->deleteFenster(window);
if(key == 'm'){ //this is to test set and get window position
ofPoint winPos = window->getWindowPosition();
window->setWindowPosition(winPos.x + 10, winPos.y);
}
}

ofImage img;
Expand Down Expand Up @@ -66,7 +70,7 @@ class testApp : public ofBaseApp {
void draw();

void keyPressed (int key);
void keyReleased(int key, ofxFenster* win);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseMoved(int x, int y, ofxFenster* win);
void mouseDragged(int x, int y, int button);
Expand Down
Binary file modified libs/ghost/lib/linux64/libGhost64.a
Binary file not shown.
6 changes: 6 additions & 0 deletions src/ofxFenster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ void ofxFenster::addListener(ofxFensterListener* listener) {
updateListenersMousePos();
}

void ofxFenster::addListener(ofBaseApp* app){
ofxFensterToOfBaseApp* appWrapper = new ofxFensterToOfBaseApp(app);
addListener(appWrapper);
}

void ofxFenster::dragEvent(ofDragInfo dragInfo) {

}
Expand Down Expand Up @@ -500,3 +505,4 @@ void ofxFenster::setDraggable(bool d) {
void ofxFenster::setDragAndDrop(bool on) {
win->setAcceptDragOperation(on);
}

1 change: 1 addition & 0 deletions src/ofxFenster.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class ofxFenster
GHOST_IWindow* getWindow();

void addListener(ofxFensterListener* listener);
void addListener(ofBaseApp* app);
void onTimer(GHOST_ITimerTask* task, GHOST_TUns64 time);

void setDragAndDrop(bool on);
Expand Down
71 changes: 0 additions & 71 deletions src/ofxFensterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,76 +11,6 @@
#include "GHOST_SystemX11.h"
#endif

///////////////////////////////////////////
// HELPERS FOR ofRunFensterApp

class ofxFensterToOfBaseApp: public ofxFensterListener{

public:
ofxFensterToOfBaseApp(ofBaseApp* base){
mouseX = mouseY = 0;
baseApp = base;
}

void setup(){
baseApp->setup();
}
void update(){
baseApp->update();
}
void draw(){
baseApp->draw();
}
void exit(){
baseApp->exit();
}

void windowResized(int w, int h){
baseApp->windowResized(w, h);
}

void keyPressed( int key ){
baseApp->keyPressed(key);
}
void keyReleased( int key ){
baseApp->keyReleased(key);
}

void mouseMoved( int x, int y ){
baseApp->mouseX = x;
baseApp->mouseY = y;
baseApp->mouseMoved(x, y);
}
void mouseDragged( int x, int y, int button ){
baseApp->mouseX = x;
baseApp->mouseY = y;
baseApp->mouseDragged(x, y, button);
}
void mousePressed( int x, int y, int button ){
baseApp->mouseX = x;
baseApp->mouseY = y;
baseApp->mousePressed(x, y, button);
}
void mouseReleased(){
baseApp->mouseReleased();
}
void mouseReleased(int x, int y, int button ){
baseApp->mouseX = x;
baseApp->mouseY = y;
baseApp->mouseReleased(x, y, button);
}

void dragEvent(ofDragInfo dragInfo) {
baseApp->dragEvent(dragInfo);
}
void gotMessage(ofMessage msg){
baseApp->gotMessage(msg);
}

private:
ofBaseApp* baseApp;
};

void ofRunFensterApp(ofxFensterListener* app){
ofxFensterManager::get()->getPrimaryWindow()->addListener(app);
ofRunApp(app);
Expand All @@ -91,7 +21,6 @@ void ofRunFensterApp(ofBaseApp* app){
ofRunFensterApp(appWrapper);
}


///////////////////////////////////////

static ofBaseApp* baseApp;
Expand Down
70 changes: 70 additions & 0 deletions src/ofxFensterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,76 @@ void ofRunFensterApp(ofBaseApp* app);

class ofxFensterManager;

///////////////////////////////////////////
// HELPERS FOR ofRunFensterApp

class ofxFensterToOfBaseApp: public ofxFensterListener{

public:
ofxFensterToOfBaseApp(ofBaseApp* base){
mouseX = mouseY = 0;
baseApp = base;
}

void setup(){
baseApp->setup();
}
void update(){
baseApp->update();
}
void draw(){
baseApp->draw();
}
void exit(){
baseApp->exit();
}

void windowResized(int w, int h){
baseApp->windowResized(w, h);
}

void keyPressed( int key ){
baseApp->keyPressed(key);
}
void keyReleased( int key ){
baseApp->keyReleased(key);
}

void mouseMoved( int x, int y ){
baseApp->mouseX = x;
baseApp->mouseY = y;
baseApp->mouseMoved(x, y);
}
void mouseDragged( int x, int y, int button ){
baseApp->mouseX = x;
baseApp->mouseY = y;
baseApp->mouseDragged(x, y, button);
}
void mousePressed( int x, int y, int button ){
baseApp->mouseX = x;
baseApp->mouseY = y;
baseApp->mousePressed(x, y, button);
}
void mouseReleased(){
baseApp->mouseReleased();
}
void mouseReleased(int x, int y, int button ){
baseApp->mouseX = x;
baseApp->mouseY = y;
baseApp->mouseReleased(x, y, button);
}

void dragEvent(ofDragInfo dragInfo) {
baseApp->dragEvent(dragInfo);
}
void gotMessage(ofMessage msg){
baseApp->gotMessage(msg);
}

private:
ofBaseApp* baseApp;
};

typedef ofPtr<ofxFenster> ofxFensterPtr;
typedef std::vector<ofxFensterPtr> fensterList;
typedef ofxFensterManager* ofxFensterManagerPtr;
Expand Down

0 comments on commit 30bd2ae

Please sign in to comment.