Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated OS X libs & OF code style

  • Loading branch information...
commit c3961a75c6cc90dc402d3cf5b80f9647b3f5e756 1 parent f7a3372
Philip Whitfield authored
View
BIN  libs/glfw/lib/osx/libglfw.a
Binary file not shown
View
BIN  libs/glfw/lib/osx/libglfw3.a
Binary file not shown
View
471 libs/openFrameworks/window/ofWindow.cpp
@@ -12,106 +12,112 @@
#include "ofWindowManager.h"
/********** ofWindowDefinitions *****************/
int ofWindow::lastWindowID = 0;
-ofWindow::ofWindow():mouseX(0),mouseY(0),oldMouseX(0),oldMouseY(0),isFocused(false),title("ofTestApp"),isInitialized(false) {
+ofWindow::ofWindow() : mouseX(0),
+ mouseY(0),
+ oldMouseX(0),
+ oldMouseY(0),
+ isFocused(false),
+ title("ofTestApp"),
+ isInitialized(false){
id = lastWindowID;
lastWindowID++;
width = 800;
height = 600;
window = NULL;
- for(unsigned int i=0;i<OF_MAX_NUM_KEYS;i++){
+ for(unsigned int i = 0; i < OF_MAX_NUM_KEYS; i++){
keyState[i] = false;
}
-};
-ofWindow::~ofWindow() {
+}
+ofWindow::~ofWindow(){
ofRemoveListener(ofEvents().update, this, &ofWindow::update);
ofRemoveListener(ofEvents().draw, this, &ofWindow::draw);
-};
-void ofWindow::initializeWindow() {
- ofLogNotice("CREATING WINDOW AT "+ofToString(x)+"/"+ofToString(y)+" SIZE "+ofToString(width)+" x "+ofToString(height));
- window = glfwCreateWindow( width, height, GLFW_WINDOWED, title.c_str(), NULL );
+}
+void ofWindow::initializeWindow(){
+ ofLogNotice("CREATING WINDOW AT " + ofToString(x) + "/" + ofToString(y) + " SIZE " + ofToString(width) + " x " + ofToString(height));
+ window = glfwCreateWindow(width, height, GLFW_WINDOWED, title.c_str(), NULL);
isInitialized = true;
setWindowPositionAndShape(x, y, width, height);
}
-void ofWindow::addListener(ofWindowListener* listener) {
-#ifdef OF_USING_POCO
- ofAddListener(events.update, listener, &ofWindowListener::update);
- ofAddListener(events.draw, listener, &ofWindowListener::draw);
-
- ofAddListener(events.mouseMoved, listener, &ofWindowListener::mouseMoved);
- ofAddListener(events.mousePressed, listener, &ofWindowListener::mousePressed);
- ofAddListener(events.mouseDragged, listener, &ofWindowListener::mouseDragged);
- ofAddListener(events.mouseReleased, listener, &ofWindowListener::mouseReleased);
-
- ofAddListener(events.keyPressed, listener, &ofWindowListener::keyPressed);
- ofAddListener(events.keyReleased, listener, &ofWindowListener::keyReleased);
+void ofWindow::addListener(ofWindowListener * listener){
+ #ifdef OF_USING_POCO
+ ofAddListener(events.update, listener, &ofWindowListener::update);
+ ofAddListener(events.draw, listener, &ofWindowListener::draw);
+
+ ofAddListener(events.mouseMoved, listener, &ofWindowListener::mouseMoved);
+ ofAddListener(events.mousePressed, listener, &ofWindowListener::mousePressed);
+ ofAddListener(events.mouseDragged, listener, &ofWindowListener::mouseDragged);
+ ofAddListener(events.mouseReleased, listener, &ofWindowListener::mouseReleased);
- ofAddListener(events.windowResized, listener, &ofWindowListener::windowResized);
- ofAddListener(events.windowMoved, listener, &ofWindowListener::windowMoved);
- ofAddListener(events.windowClosed, listener, &ofWindowListener::windowClosed);
-#endif
-#ifndef OF_USING_POCO
- listeners.push_back(listener);
-#endif
-}
-void ofWindow::addListener(ofBaseApp* app) {
+ ofAddListener(events.keyPressed, listener, &ofWindowListener::keyPressed);
+ ofAddListener(events.keyReleased, listener, &ofWindowListener::keyReleased);
+
+ ofAddListener(events.windowResized, listener, &ofWindowListener::windowResized);
+ ofAddListener(events.windowMoved, listener, &ofWindowListener::windowMoved);
+ ofAddListener(events.windowClosed, listener, &ofWindowListener::windowClosed);
+ #endif
+ #ifndef OF_USING_POCO
+ listeners.push_back(listener);
+ #endif
+}
+void ofWindow::addListener(ofBaseApp * app){
addListener(new ofWindowToOfBaseApp(app));
}
-GLFWwindow ofWindow::getGlfwWindow() {
+GLFWwindow ofWindow::getGlfwWindow(){
return window;
}
-void ofWindow::enableContext() {
+void ofWindow::enableContext(){
glfwMakeContextCurrent(window);
}
-void ofWindow::setup() {
+void ofWindow::setup(){
glClearColor(.55, .55, .55, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
ofAddListener(ofEvents().update, this, &ofWindow::update);
ofAddListener(ofEvents().draw, this, &ofWindow::draw);
}
-void ofWindow::update(ofEventArgs& e) {
+void ofWindow::update(ofEventArgs & e){
update();
}
-void ofWindow::update() {
+void ofWindow::update(){
ofGetWindowManager()->setActiveWindow(this);
-#ifdef OF_USING_POCO
- ofWindowEventArgs e;
- e.window = this;
- ofNotifyEvent(events.update, e);
-#endif
-#ifndef OF_USING_POCO
- ofWindowListenerList::iterator it=listeners.begin();
- while(it!=listeners.end()) {
- (*it)->update(this);
- ++it;
- }
-#endif
-}
-void ofWindow::draw(ofEventArgs& e) {
+ #ifdef OF_USING_POCO
+ ofWindowEventArgs e;
+ e.window = this;
+ ofNotifyEvent(events.update, e);
+ #endif
+ #ifndef OF_USING_POCO
+ ofWindowListenerList::iterator it = listeners.begin();
+ while(it != listeners.end()){
+ (*it)->update(this);
+ ++it;
+ }
+ #endif
+}
+void ofWindow::draw(ofEventArgs & e){
draw();
}
-void ofWindow::draw() {
+void ofWindow::draw(){
ofGetWindowManager()->setActiveWindow(this);
float * bgPtr = ofBgColorPtr();
- ofViewport(0, 0, width, height, false); // used to be glViewport( 0, 0, width, height );
- ofClear(bgPtr[0]*255,bgPtr[1]*255,bgPtr[2]*255, bgPtr[3]*255);
+ ofViewport(0, 0, width, height, false); // used to be glViewport( 0, 0, width, height );
+ ofClear(bgPtr[0] * 255, bgPtr[1] * 255, bgPtr[2] * 255, bgPtr[3] * 255);
//ofGetCurrentRenderer()->setupScreenPerspective(800, 600);
ofSetupScreenPerspective(width, height, OF_ORIENTATION_DEFAULT);
-#ifdef OF_USING_POCO
- ofWindowEventArgs e;
- e.window = this;
- ofNotifyEvent(events.draw, e);
-#endif
-#ifndef OF_USING_POCO
- ofWindowListenerList::iterator it=listeners.begin();
- while(it!=listeners.end()) {
- (*it)->draw(this);
- ++it;
- }
-#endif
+ #ifdef OF_USING_POCO
+ ofWindowEventArgs e;
+ e.window = this;
+ ofNotifyEvent(events.draw, e);
+ #endif
+ #ifndef OF_USING_POCO
+ ofWindowListenerList::iterator it = listeners.begin();
+ while(it != listeners.end()){
+ (*it)->draw(this);
+ ++it;
+ }
+ #endif
glfwSwapBuffers(window);
}
-void ofWindow::destroy() {
+void ofWindow::destroy(){
ofRemoveListener(ofEvents().update, this, &ofWindow::update);
ofRemoveListener(ofEvents().draw, this, &ofWindow::draw);
//getWindowPosition();
@@ -119,143 +125,145 @@ void ofWindow::destroy() {
window = NULL;
}
//USER INTERACTION EVENTS
-void ofWindow::mouseMoved(int mX, int mY) {
+void ofWindow::mouseMoved(int mX, int mY){
mouseX = mX;
mouseY = mY;
ofNotifyMouseMoved(mouseX, mouseY);
-#ifdef OF_USING_POCO
- ofMouseEventArgs e;
- e.x = mX;
- e.y = mY;
- e.window = this;
- ofNotifyEvent(events.mouseMoved, e);
-#endif
-#ifndef OF_USING_POCO
- ofWindowListenerList::iterator it=listeners.begin();
- while(it!=listeners.end()) {
- (*it)->mouseMoved(mouseX, mouseY, this);
- ++it;
- }
-#endif
-}
-void ofWindow::mousePressed(int button) {
+ #ifdef OF_USING_POCO
+ ofMouseEventArgs e;
+ e.x = mX;
+ e.y = mY;
+ e.window = this;
+ ofNotifyEvent(events.mouseMoved, e);
+ #endif
+ #ifndef OF_USING_POCO
+ ofWindowListenerList::iterator it = listeners.begin();
+ while(it != listeners.end()){
+ (*it)->mouseMoved(mouseX, mouseY, this);
+ ++it;
+ }
+ #endif
+}
+void ofWindow::mousePressed(int button){
mousePressed(mouseX, mouseY, button);
}
-void ofWindow::mousePressed(int mX, int mY, int button) {
+void ofWindow::mousePressed(int mX, int mY, int button){
mouseX = mX;
mouseY = mY;
ofNotifyMousePressed(mouseX, mouseY, button);
-#ifdef OF_USING_POCO
- ofMouseEventArgs e;
- e.x = mX;
- e.y = mY;
- e.button = button;
- e.window = this;
- ofNotifyEvent(events.mousePressed, e);
-#endif
-#ifndef OF_USING_POCO
- ofWindowListenerList::iterator it=listeners.begin();
- while(it!=listeners.end()) {
- (*it)->mousePressed(mouseX, mouseY, button, this);
- ++it;
- }
-#endif
-}
-void ofWindow::mouseReleased(int button) {
+ #ifdef OF_USING_POCO
+ ofMouseEventArgs e;
+ e.x = mX;
+ e.y = mY;
+ e.button = button;
+ e.window = this;
+ ofNotifyEvent(events.mousePressed, e);
+ #endif
+ #ifndef OF_USING_POCO
+ ofWindowListenerList::iterator it = listeners.begin();
+ while(it != listeners.end()){
+ (*it)->mousePressed(mouseX, mouseY, button, this);
+ ++it;
+ }
+ #endif
+}
+void ofWindow::mouseReleased(int button){
mouseReleased(mouseX, mouseY, button);
}
-void ofWindow::mouseReleased(int mX, int mY, int button) {
+void ofWindow::mouseReleased(int mX, int mY, int button){
mouseX = mX;
mouseY = mY;
ofNotifyMouseReleased(mouseX, mouseY, button);
-#ifdef OF_USING_POCO
- ofMouseEventArgs e;
- e.x = mX;
- e.y = mY;
- e.button = button;
- e.window = this;
- ofNotifyEvent(events.mouseReleased, e);
-#endif
-#ifndef OF_USING_POCO
- ofWindowListenerList::iterator it=listeners.begin();
- while(it!=listeners.end()) {
- (*it)->mouseReleased(mouseX, mouseY, button, this);
- ++it;
- }
-#endif
-}
-void ofWindow::mouseDragged(int mX, int mY, int button) {
+ #ifdef OF_USING_POCO
+ ofMouseEventArgs e;
+ e.x = mX;
+ e.y = mY;
+ e.button = button;
+ e.window = this;
+ ofNotifyEvent(events.mouseReleased, e);
+ #endif
+ #ifndef OF_USING_POCO
+ ofWindowListenerList::iterator it = listeners.begin();
+ while(it != listeners.end()){
+ (*it)->mouseReleased(mouseX, mouseY, button, this);
+ ++it;
+ }
+ #endif
+}
+void ofWindow::mouseDragged(int mX, int mY, int button){
mouseX = mX;
mouseY = mY;
-
+
ofNotifyMouseDragged(mouseX, mouseY, button);
-
-#ifdef OF_USING_POCO
- ofMouseEventArgs e;
- e.x = mouseX;
- e.y = mouseY;
- e.button = button;
- e.window = this;
- ofNotifyEvent(events.mouseDragged, e);
-#endif
-#ifndef OF_USING_POCO
- ofWindowListenerList::iterator it=listeners.begin();
- while(it!=listeners.end()) {
- (*it)->mouseDragged(mouseX, mouseY, button, this);
- ++it;
- }
-#endif
+
+ #ifdef OF_USING_POCO
+ ofMouseEventArgs e;
+ e.x = mouseX;
+ e.y = mouseY;
+ e.button = button;
+ e.window = this;
+ ofNotifyEvent(events.mouseDragged, e);
+ #endif
+ #ifndef OF_USING_POCO
+ ofWindowListenerList::iterator it = listeners.begin();
+ while(it != listeners.end()){
+ (*it)->mouseDragged(mouseX, mouseY, button, this);
+ ++it;
+ }
+ #endif
}
void ofWindow::scrolled(float deltaX, float deltaY){
//ofNotifyMouseDragged(mouseX, mouseY, button);
/*ofWindowListenerList::iterator it=listeners.begin();
while(it!=listeners.end()) {
- (*it)->scrolled(deltaX, deltaY, this);
- ++it;
+ (*it)->scrolled(deltaX, deltaY, this);
+ ++it;
}*/
}
void ofWindow::keyPressed(int key){
- if(key<OF_MAX_NUM_KEYS)
+ if(key < OF_MAX_NUM_KEYS){
keyState[key] = true;
+ }
ofNotifyKeyPressed(key);
-#ifdef OF_USING_POCO
- ofKeyEventArgs e;
- e.key = key;
- e.window = this;
- ofNotifyEvent(events.keyPressed, e);
-#endif
-#ifndef OF_USING_POCO
- ofWindowListenerList::iterator it=listeners.begin();
- while(it!=listeners.end()) {
- (*it)->keyPressed(key, this);
- ++it;
- }
-#endif
+ #ifdef OF_USING_POCO
+ ofKeyEventArgs e;
+ e.key = key;
+ e.window = this;
+ ofNotifyEvent(events.keyPressed, e);
+ #endif
+ #ifndef OF_USING_POCO
+ ofWindowListenerList::iterator it = listeners.begin();
+ while(it != listeners.end()){
+ (*it)->keyPressed(key, this);
+ ++it;
+ }
+ #endif
}
void ofWindow::keyReleased(int key){
- if(key<OF_MAX_NUM_KEYS)
+ if(key < OF_MAX_NUM_KEYS){
keyState[key] = false;
- ofNotifyKeyReleased(key);
-
-#ifdef OF_USING_POCO
- ofKeyEventArgs e;
- e.key = key;
- e.window = this;
- ofNotifyEvent(events.keyReleased, e);
-#endif
-#ifndef OF_USING_POCO
- ofWindowListenerList::iterator it=listeners.begin();
- while(it!=listeners.end()) {
- (*it)->keyReleased(key, this);
- ++it;
}
-#endif
+ ofNotifyKeyReleased(key);
+
+ #ifdef OF_USING_POCO
+ ofKeyEventArgs e;
+ e.key = key;
+ e.window = this;
+ ofNotifyEvent(events.keyReleased, e);
+ #endif
+ #ifndef OF_USING_POCO
+ ofWindowListenerList::iterator it = listeners.begin();
+ while(it != listeners.end()){
+ (*it)->keyReleased(key, this);
+ ++it;
+ }
+ #endif
}
bool ofWindow::isKeyPressed(int key){
@@ -264,39 +272,40 @@ bool ofWindow::isKeyPressed(int key){
//WINDOW SPECIFIC EVENT
-void ofWindow::windowFocused() {
+void ofWindow::windowFocused(){
isFocused = true;
-};
-void ofWindow::windowUnfocused() {
+}
+void ofWindow::windowUnfocused(){
isFocused = false;
-};
-void ofWindow::windowClosed() {
+}
+void ofWindow::windowClosed(){
window = NULL;
-#ifdef OF_USING_POCO
- ofWindowEventArgs e;
- e.window = this;
- ofNotifyEvent(events.windowClosed, e);
-#endif
-#ifndef OF_USING_POCO
- ofWindowListenerList::iterator it=listeners.begin();
- while(it!=listeners.end()) {
- (*it)->windowClosed(this);
- ++it;
- }
-#endif
-};
-ofPoint ofWindow::getWindowPosition() {
- if(window != NULL)
+ #ifdef OF_USING_POCO
+ ofWindowEventArgs e;
+ e.window = this;
+ ofNotifyEvent(events.windowClosed, e);
+ #endif
+ #ifndef OF_USING_POCO
+ ofWindowListenerList::iterator it = listeners.begin();
+ while(it != listeners.end()){
+ (*it)->windowClosed(this);
+ ++it;
+ }
+ #endif
+}
+ofPoint ofWindow::getWindowPosition(){
+ if(window != NULL){
glfwGetWindowPos(window, &x, &y);
+ }
return ofPoint(x, y);
}
-ofPoint ofWindow::getWindowSize() {
+ofPoint ofWindow::getWindowSize(){
return ofPoint(width, height);
}
-int ofWindow::getWidth() {
+int ofWindow::getWidth(){
return width;
}
-int ofWindow::getHeight() {
+int ofWindow::getHeight(){
return height;
}
int ofWindow::getX(){
@@ -313,24 +322,25 @@ int ofWindow::setY(int _y){
setWindowPosition(x, _y);
}
-void ofWindow::setWindowPositionAndShape(int _x, int _y, int w, int h) {
- if (!isInitialized) {
+void ofWindow::setWindowPositionAndShape(int _x, int _y, int w, int h){
+ if(!isInitialized){
x = _x;
y = _y;
width = w;
height = h;
- } else {
+ }
+ else{
setWindowPosition(_x, _y);
setWindowShape(w, h);
}
}
-void ofWindow::setWindowPosition(int x, int y) {
+void ofWindow::setWindowPosition(int x, int y){
glfwSetWindowPos(window, x, y);
}
-void ofWindow::setWindowPosition(ofPoint pos) {
+void ofWindow::setWindowPosition(ofPoint pos){
setWindowPosition(pos.x, pos.y);
}
-void ofWindow::setWindowShape(int w, int h) {
+void ofWindow::setWindowShape(int w, int h){
glfwSetWindowSize(window, w, h);
}
@@ -340,59 +350,62 @@ void ofWindow::setWidth(int w){
void ofWindow::setHeight(int h){
glfwSetWindowSize(window, width, h);
}
-void ofWindow::windowResized(int w, int h) {
- if(width == w && height == h)
+void ofWindow::windowResized(int w, int h){
+ if(width == w && height == h){
return;
+ }
previousShape.width = width;
previousShape.height = height;
width = w;
height = h;
ofNotifyWindowResized(width, height);
-#ifdef OF_USING_POCO
- ofResizeEventArgs e;
- e.width = width;
- e.height = height;
- ofNotifyEvent(events.windowResized, e);
-#endif
-#ifndef OF_USING_POCO
- ofWindowListenerList::iterator it=listeners.begin();
- while(it!=listeners.end()) {
- (*it)->windowResized(width, height, this);
- ++it;
- }
-#endif
+ #ifdef OF_USING_POCO
+ ofResizeEventArgs e;
+ e.width = width;
+ e.height = height;
+ ofNotifyEvent(events.windowResized, e);
+ #endif
+ #ifndef OF_USING_POCO
+ ofWindowListenerList::iterator it = listeners.begin();
+ while(it != listeners.end()){
+ (*it)->windowResized(width, height, this);
+ ++it;
+ }
+ #endif
draw();
}
-void ofWindow::windowMoved(int _x, int _y) {
- if(x == _x && y == _y)
+void ofWindow::windowMoved(int _x, int _y){
+ if(x == _x && y == _y){
return;
+ }
previousShape.x = x;
previousShape.y = y;
x = _x;
y = _y;
-#ifdef OF_USING_POCO
- ofMoveEventArgs e;
- e.x = x;
- e.y = y;
- ofNotifyEvent(events.windowMoved, e);
-#endif
-#ifndef OF_USING_POCO
-
- ofWindowListenerList::iterator it=listeners.begin();
- while(it!=listeners.end()) {
- (*it)->windowMoved(x, y, this);
- ++it;
- }
-#endif
-}
-void ofWindow::setTitle(string t) {
- if (isInitialized)
+ #ifdef OF_USING_POCO
+ ofMoveEventArgs e;
+ e.x = x;
+ e.y = y;
+ ofNotifyEvent(events.windowMoved, e);
+ #endif
+ #ifndef OF_USING_POCO
+
+ ofWindowListenerList::iterator it = listeners.begin();
+ while(it != listeners.end()){
+ (*it)->windowMoved(x, y, this);
+ ++it;
+ }
+ #endif
+}
+void ofWindow::setTitle(string t){
+ if(isInitialized){
glfwSetWindowTitle(window, t.c_str());
+ }
title = t;
}
-string ofWindow::getTitle() {
+string ofWindow::getTitle(){
return title;
}
View
542 libs/openFrameworks/window/ofWindow.h
@@ -11,277 +11,297 @@
/ WINDOW LISTENER
*******************/
-class ofWindowListener: public ofBaseApp
-{
-public:
- virtual void setup(ofWindow* f) {
- setup();
- }
- virtual void setup() {};
- virtual void update(ofWindow* f) {
- update();
- }
- virtual void update(ofWindowEventArgs& f) {
- update(f.window);
- }
- virtual void update() {};
-
- virtual void draw(ofWindow* f) {
- draw();
- }
- virtual void draw(ofWindowEventArgs& e) {
- draw(e.window);
- }
- virtual void draw() {};
-
- //KEY
- virtual void keyPressed(int key) {};
- virtual void keyReleased(int key, ofWindow* f) {
- keyReleased(key);
- }
- virtual void keyReleased(ofKeyEventArgs& e) {
- keyReleased(e.key, e.window);
- }
- virtual void keyReleased(int key) {};
- virtual void keyPressed(int key, ofWindow* f) {
- keyPressed(key);
- }
- virtual void keyPressed(ofKeyEventArgs& e) {
- keyPressed(e.key, e.window);
- }
-
- //WINDOW
- virtual void windowMoved(int x, int y, ofWindow* f) {
- windowMoved(x, y);
- }
- virtual void windowMoved(ofMoveEventArgs& e) {
- windowMoved(e.x, e.y, e.window);
- }
- virtual void windowMoved(int x, int y) {};
-
- virtual void windowResized(int w, int h, ofWindow* f) {
- windowResized(w, h);
- }
- virtual void windowResized(ofResizeEventArgs& e) {
- windowResized(e.width, e.height, e.window);
- }
- virtual void windowResized(int w, int h) {};
- virtual void windowClosed(ofWindowEventArgs& e){windowClosed(e.window);}
- virtual void windowClosed(ofWindow* window){windowClosed();}
- virtual void windowClosed(){}
-
- //MOUSE
- virtual void mouseMoved(int x, int y, ofWindow* f) {
- mouseMoved(x, y);
- }
- virtual void mouseMoved(ofMouseEventArgs& e){
- mouseMoved(e.x, e.y, e.window);
- }
- virtual void mouseMoved(int x, int y) {};
- virtual void mouseDragged(int x, int y, int button, ofWindow* f) {
- mouseDragged(x, y, button);
- }
- virtual void mouseDragged(ofMouseEventArgs& e){
- mouseDragged(e.x, e.y, e.button, e.window);
- }
- virtual void mouseDragged(int x, int y, int button) {};
- virtual void mousePressed(int x, int y, int btn, ofWindow* f) {
- mousePressed(x, y, btn);
- }
- virtual void mousePressed(ofMouseEventArgs& e){
- mousePressed(e.x, e.y, e.button, e.window);
- }
- virtual void mousePressed(int x, int y, int btn) {};
- virtual void mouseReleased(int x, int y, int btn, ofWindow* f) {
- mouseReleased(x, y, btn);
- mouseReleased();
- }
- virtual void mouseReleased(ofMouseEventArgs& e){
- mouseReleased(e.x, e.y, e.button, e.window);
- }
- virtual void mouseReleased(int x, int y, int btn) {}
- virtual void mouseReleased() {};
-
- virtual void scrolled(ofScrollEventArgs& e){
- scrolled(e.deltaX, e.deltaY, e.window);
- }
- virtual void scrolled(float deltaX, float deltaY, ofWindow* win){
- scrolled(deltaX, deltaY);
- }
- virtual void scrolled(float deltaX, float deltaY){};
-
- virtual void dragEvent(ofDragInfo info, ofWindow* f){dragEvent(info);}
- virtual void dragEvent(ofDragInfo info){}
-
- bool isUpdated;
+class ofWindowListener : public ofBaseApp {
+ public:
+ virtual void setup(ofWindow * f){
+ setup();
+ }
+ virtual void setup(){
+ }
+ virtual void update(ofWindow * f){
+ update();
+ }
+ virtual void update(ofWindowEventArgs & f){
+ update(f.window);
+ }
+ virtual void update(){
+ }
+
+ virtual void draw(ofWindow * f){
+ draw();
+ }
+ virtual void draw(ofWindowEventArgs & e){
+ draw(e.window);
+ }
+ virtual void draw(){
+ }
+
+ //KEY
+ virtual void keyPressed(int key){
+ }
+ virtual void keyReleased(int key, ofWindow * f){
+ keyReleased(key);
+ }
+ virtual void keyReleased(ofKeyEventArgs & e){
+ keyReleased(e.key, e.window);
+ }
+ virtual void keyReleased(int key){
+ }
+ virtual void keyPressed(int key, ofWindow * f){
+ keyPressed(key);
+ }
+ virtual void keyPressed(ofKeyEventArgs & e){
+ keyPressed(e.key, e.window);
+ }
+
+ //WINDOW
+ virtual void windowMoved(int x, int y, ofWindow * f){
+ windowMoved(x, y);
+ }
+ virtual void windowMoved(ofMoveEventArgs & e){
+ windowMoved(e.x, e.y, e.window);
+ }
+ virtual void windowMoved(int x, int y){
+ }
+
+ virtual void windowResized(int w, int h, ofWindow * f){
+ windowResized(w, h);
+ }
+ virtual void windowResized(ofResizeEventArgs & e){
+ windowResized(e.width, e.height, e.window);
+ }
+ virtual void windowResized(int w, int h){
+ }
+ virtual void windowClosed(ofWindowEventArgs & e){
+ windowClosed(e.window);
+ }
+ virtual void windowClosed(ofWindow * window){
+ windowClosed();
+ }
+ virtual void windowClosed(){
+ }
+
+ //MOUSE
+ virtual void mouseMoved(int x, int y, ofWindow * f){
+ mouseMoved(x, y);
+ }
+ virtual void mouseMoved(ofMouseEventArgs & e){
+ mouseMoved(e.x, e.y, e.window);
+ }
+ virtual void mouseMoved(int x, int y){
+ }
+ virtual void mouseDragged(int x, int y, int button, ofWindow * f){
+ mouseDragged(x, y, button);
+ }
+ virtual void mouseDragged(ofMouseEventArgs & e){
+ mouseDragged(e.x, e.y, e.button, e.window);
+ }
+ virtual void mouseDragged(int x, int y, int button){
+ }
+ virtual void mousePressed(int x, int y, int btn, ofWindow * f){
+ mousePressed(x, y, btn);
+ }
+ virtual void mousePressed(ofMouseEventArgs & e){
+ mousePressed(e.x, e.y, e.button, e.window);
+ }
+ virtual void mousePressed(int x, int y, int btn){
+ }
+ virtual void mouseReleased(int x, int y, int btn, ofWindow * f){
+ mouseReleased(x, y, btn);
+ mouseReleased();
+ }
+ virtual void mouseReleased(ofMouseEventArgs & e){
+ mouseReleased(e.x, e.y, e.button, e.window);
+ }
+ virtual void mouseReleased(int x, int y, int btn){
+ }
+ virtual void mouseReleased(){
+ }
+
+ virtual void scrolled(ofScrollEventArgs & e){
+ scrolled(e.deltaX, e.deltaY, e.window);
+ }
+ virtual void scrolled(float deltaX, float deltaY, ofWindow * win){
+ scrolled(deltaX, deltaY);
+ }
+ virtual void scrolled(float deltaX, float deltaY){
+ }
+
+ virtual void dragEvent(ofDragInfo info, ofWindow * f){
+ dragEvent(info);
+ }
+ virtual void dragEvent(ofDragInfo info){
+ }
+
+ bool isUpdated;
};
///////////////////////////////////////////
// HELPERS FOR ofRunFensterApp
-class ofWindowToOfBaseApp: public ofWindowListener{
-
-public:
- ofWindowToOfBaseApp(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;
+class ofWindowToOfBaseApp : public ofWindowListener {
+
+ public:
+ ofWindowToOfBaseApp(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 std::vector<ofWindowListener*> ofWindowListenerList;
+typedef std::vector <ofWindowListener *> ofWindowListenerList;
/*****************
/ WINDOW
*******************/
-class ofWindow: public ofAppBaseWindow{
-public:
- ofWindow();
- ~ofWindow();
-
- void enableContext();
- void initializeWindow();
-
- void setWindowPositionAndShape(ofRectangle rect);
- void setWindowPositionAndShape(int x, int y, int width, int height);
-
- void addListener(ofWindowListener* listener);
- void addListener(ofBaseApp* app);
-
- void setup();
-
- void update(ofEventArgs& e);
- void update();
- void draw(ofEventArgs& e);
- void draw();
-
- ofPoint getWindowPosition();
- void setWindowPosition(int x, int y);
- void setWindowPosition(ofPoint pos);
-
- ofPoint getWindowSize();
- void setWindowShape(int x, int y);
- void setWidth(int w);
- void setHeight(int h);
-
- int getWidth();
- int getHeight();
-
- int getX();
- int getY();
- int setX(int x);
- int setY(int y);
-
- bool isKeyPressed(int key);
- bool isClosed();
-
- void setTitle(string title);
- string getTitle();
-
- void close();
-
- ofWindowEvents events;
-
- static int lastWindowID;
-
- int mouseX, mouseY;
- int oldMouseX, oldMouseY;
-
-private:
- GLFWwindow getGlfwWindow();
-
- void destroy();
-
- void mouseMoved(int mouseX, int mouseY);
- void mouseDragged(int mouseX, int mouseY, int button);
- void mousePressed(int button);
- void mousePressed(int mouseX, int mouseY, int button);
- void mouseReleased(int button);
- void mouseReleased(int mouseX, int mouseY, int button);
-
- void keyPressed(int key);
- void keyReleased(int key);
-
- void scrolled(float deltaX, float deltaY);
-
- void windowMoved(int x, int y);
- void windowFocused();
- void windowUnfocused();
- void windowClosed();
- void windowResized(int w, int h);
-
- ofWindowListenerList listeners;
- ofRectangle previousShape;
- bool isFocused;
- string title;
- GLFWwindow window;
-
- bool isInitialized;
- int id;
- int width;
- int height;
- int x;
- int y;
-
- bool keyState[OF_MAX_NUM_KEYS];
-
- friend class ofWindowManager;
+class ofWindow : public ofAppBaseWindow {
+ public:
+ ofWindow();
+ ~ofWindow();
+
+ void enableContext();
+ void initializeWindow();
+
+ void setWindowPositionAndShape(ofRectangle rect);
+ void setWindowPositionAndShape(int x, int y, int width, int height);
+
+ void addListener(ofWindowListener * listener);
+ void addListener(ofBaseApp * app);
+
+ void setup();
+
+ void update(ofEventArgs & e);
+ void update();
+ void draw(ofEventArgs & e);
+ void draw();
+
+ ofPoint getWindowPosition();
+ void setWindowPosition(int x, int y);
+ void setWindowPosition(ofPoint pos);
+
+ ofPoint getWindowSize();
+ void setWindowShape(int x, int y);
+ void setWidth(int w);
+ void setHeight(int h);
+
+ int getWidth();
+ int getHeight();
+
+ int getX();
+ int getY();
+ int setX(int x);
+ int setY(int y);
+
+ bool isKeyPressed(int key);
+ bool isClosed();
+
+ void setTitle(string title);
+ string getTitle();
+
+ void close();
+
+ ofWindowEvents events;
+
+ static int lastWindowID;
+
+ int mouseX, mouseY;
+ int oldMouseX, oldMouseY;
+
+ private:
+ GLFWwindow getGlfwWindow();
+
+ void destroy();
+
+ void mouseMoved(int mouseX, int mouseY);
+ void mouseDragged(int mouseX, int mouseY, int button);
+ void mousePressed(int button);
+ void mousePressed(int mouseX, int mouseY, int button);
+ void mouseReleased(int button);
+ void mouseReleased(int mouseX, int mouseY, int button);
+
+ void keyPressed(int key);
+ void keyReleased(int key);
+
+ void scrolled(float deltaX, float deltaY);
+
+ void windowMoved(int x, int y);
+ void windowFocused();
+ void windowUnfocused();
+ void windowClosed();
+ void windowResized(int w, int h);
+
+ ofWindowListenerList listeners;
+ ofRectangle previousShape;
+ bool isFocused;
+ string title;
+ GLFWwindow window;
+
+ bool isInitialized;
+ int id;
+ int width;
+ int height;
+ int x;
+ int y;
+
+ bool keyState[OF_MAX_NUM_KEYS];
+
+ friend class ofWindowManager;
};
View
429 libs/openFrameworks/window/ofWindowManager.cpp
@@ -14,7 +14,7 @@
/********** GLFW CALLBACKS **********************************************************/
-void glfwErrorCallback(int type, const char* err){
+void glfwErrorCallback(int type, const char * err){
ofLog(OF_LOG_ERROR, err);
}
@@ -66,28 +66,28 @@ void glfwCharCallback(GLFWwindow glfwWin, int character){
/********* C STYLE FUNCTION DEFINTIONS ************************************************/
-ofWindowManager* windowManager = NULL;
+ofWindowManager * windowManager = NULL;
-ofWindowManager* ofGetWindowManager() {
- if(windowManager == NULL) {
+ofWindowManager * ofGetWindowManager(){
+ if(windowManager == NULL){
windowManager = new ofWindowManager();
}
return windowManager;
}
-ofWindow* ofCreateWindow(int x, int y, int width, int height){
+ofWindow * ofCreateWindow(int x, int y, int width, int height){
return ofGetWindowManager()->createWindow(x, y, width, height);
}
-ofWindow* ofCreateWindow(int width, int height){
+ofWindow * ofCreateWindow(int width, int height){
return ofCreateWindow(0, 0, width, height);
}
-ofWindow* ofGetMainWindow(){
+ofWindow * ofGetMainWindow(){
return ofGetWindowManager()->getMainWindow();
}
-ofWindow* ofGetLastCreatedWindow(){
+ofWindow * ofGetLastCreatedWindow(){
return ofGetWindowManager()->getLastCreatedWindow();
}
@@ -95,38 +95,37 @@ ofWindow* ofGetLastCreatedWindow(){
/********** ofWindowManager DEFINITIONS ******************************************/
-static float timeNow, timeThen, fps;
-static int nFramesForFPS;
-static int nFrameCount;
-static bool bFrameRateSet;
-static int millisForFrame;
-static int prevMillis;
-static int diffMillis;
-static float frameRate;
-static double lastFrameTime;
-
-ofWindowManager::ofWindowManager() {
- timeNow = 0;
- timeThen = 0;
- fps = 60.0; //give a realistic starting value - win32 issues
- frameRate = 60.0;
- millisForFrame = 0;
- prevMillis = 0;
- diffMillis = 0;
+static float timeNow, timeThen, fps;
+static int nFramesForFPS;
+static int nFrameCount;
+static bool bFrameRateSet;
+static int millisForFrame;
+static int prevMillis;
+static int diffMillis;
+static float frameRate;
+static double lastFrameTime;
+
+ofWindowManager::ofWindowManager(){
+ timeNow = 0;
+ timeThen = 0;
+ fps = 60.0; //give a realistic starting value - win32 issues
+ frameRate = 60.0;
+ millisForFrame = 0;
+ prevMillis = 0;
+ diffMillis = 0;
setFrameRate(60);
-};
+}
-ofWindowManager::~ofWindowManager() {
+ofWindowManager::~ofWindowManager(){
glfwTerminate();
-};
+}
-ofWindow* ofWindowManager::createWindow(int w, int h){
+ofWindow * ofWindowManager::createWindow(int w, int h){
return createWindow(0, 0, w, h);
}
-ofWindow* ofWindowManager::createWindow(int x, int y, int width, int height)
-{
- ofWindow* win = new ofWindow();
+ofWindow * ofWindowManager::createWindow(int x, int y, int width, int height){
+ ofWindow * win = new ofWindow();
win->setWindowPositionAndShape(x, y, width, height);
addWindow(win);
win->initializeWindow();
@@ -134,38 +133,40 @@ ofWindow* ofWindowManager::createWindow(int x, int y, int width, int height)
return win;
}
-void ofWindowManager::addWindow(ofWindow* win) {
+void ofWindowManager::addWindow(ofWindow * win){
windows.push_back(ofWindowPtr(win));
}
-void ofWindowManager::deleteWindow(ofWindow* win){
+void ofWindowManager::deleteWindow(ofWindow * win){
win->destroy();
}
-void ofWindowManager::removeWindow(ofWindow* win){
-
- ofWindowList::iterator it=windows.begin();
- while(it!=windows.end()) {
- if((*it).get() == win) {
+void ofWindowManager::removeWindow(ofWindow * win){
+
+ ofWindowList::iterator it = windows.begin();
+ while(it != windows.end()){
+ if((*it).get() == win){
win->windowClosed();
windows.erase(it);
break;
}
++it;
}
- if(windows.size()==0)
+ if(windows.size() == 0){
ofExit();
+ }
}
void ofWindowManager::deleteWindow(int id){
deleteWindow(getWindowById(id));
}
-ofWindow* ofWindowManager::getWindowById(int id){
+ofWindow * ofWindowManager::getWindowById(int id){
ofWindowList::iterator it = windows.begin();
- while (it != windows.end()) {
- if((*it)->id == id)
+ while(it != windows.end()){
+ if((*it)->id == id){
return (*it).get();
+ }
++it;
}
ofLogWarning("ofWindowManager::getWindowById - ID was not found, returning mainWindow instead");
@@ -173,11 +174,12 @@ ofWindow* ofWindowManager::getWindowById(int id){
}
-ofWindow* ofWindowManager::getWindowByGlfw(GLFWwindow win){
+ofWindow * ofWindowManager::getWindowByGlfw(GLFWwindow win){
ofWindowList::iterator it = windows.begin();
- while (it != windows.end()) {
- if((*it)->getGlfwWindow() == win)
+ while(it != windows.end()){
+ if((*it)->getGlfwWindow() == win){
return (*it).get();
+ }
++it;
}
ofLogWarning("ofWindowManager::getWindowById - GLFWwindow was not found, returning mainWindow instead");
@@ -185,24 +187,22 @@ ofWindow* ofWindowManager::getWindowByGlfw(GLFWwindow win){
}
void ofWindowManager::initializeGLFW(){
- if( !glfwInit() )
- {
- ofLogError("Failed to initialize GLFW");
- ofExit(0);
- }
+ if(!glfwInit()){
+ ofLogError("Failed to initialize GLFW");
+ ofExit(0);
+ }
}
-void ofWindowManager::setupOpenGL(int w, int h, int screenMode) {
+void ofWindowManager::setupOpenGL(int w, int h, int screenMode){
initializeGLFW();
-
+
glfwWindowHint(GLFW_DEPTH_BITS, 16);
-
+
mainWindow = createWindow(w, h);
activeWindow = mainWindow;
}
-void ofWindowManager::initializeWindow()
-{
+void ofWindowManager::initializeWindow(){
//define all callbacks now, so there won't happen anything before OF is fully initialized
glfwSetErrorCallback(&glfwErrorCallback);
glfwSetWindowSizeCallback(&glfwWindowSizeCallback);
@@ -216,57 +216,58 @@ void ofWindowManager::initializeWindow()
glfwSetScrollCallback(&glfwScrollCallback);
glfwSetKeyCallback(&glfwKeyCallback);
glfwSetCharCallback(&glfwCharCallback);
-
+
mainWindow->setup();
}
-void ofWindowManager::runAppViaInfiniteLoop(ofBaseApp * appPtr) {
+void ofWindowManager::runAppViaInfiniteLoop(ofBaseApp * appPtr){
mainWindow->addListener(appPtr);
appPtr->setup();
-
+
//run the main loop
- while (true) {
+ while(true){
glfwPollEvents();
update();
draw();
}
}
-void ofWindowManager::update() {
+void ofWindowManager::update(){
// thanks to jorge for the fix:
// http://www.openframeworks.cc/forum/viewtopic.php?t=515&highlight=frame+rate
- if (nFrameCount != 0 && bFrameRateSet == true) {
+ if(nFrameCount != 0 && bFrameRateSet == true){
diffMillis = ofGetElapsedTimeMillis() - prevMillis;
- if (diffMillis > millisForFrame) {
- ; // we do nothing, we are already slower than target frame
- } else {
+ if(diffMillis > millisForFrame){
+ // we do nothing, we are already slower than target frame
+ }
+ else{
int waitMillis = millisForFrame - diffMillis;
-#ifdef TARGET_WIN32
- Sleep(waitMillis); //windows sleep in milliseconds
-#else
- usleep(waitMillis * 1000); //mac sleep in microseconds - cooler :)
-#endif
+ #ifdef TARGET_WIN32
+ Sleep(waitMillis); //windows sleep in milliseconds
+ #else
+ usleep(waitMillis * 1000); //mac sleep in microseconds - cooler :)
+ #endif
}
}
prevMillis = ofGetElapsedTimeMillis(); // you have to measure here
- // -------------- fps calculation:
- // theo - now moved from display to idle_cb
- // discuss here: http://github.com/openframeworks/openFrameworks/issues/labels/0062#issue/187
+ // -------------- fps calculation:
+ // theo - now moved from display to idle_cb
+ // discuss here: http://github.com/openframeworks/openFrameworks/issues/labels/0062#issue/187
//
//
// theo - please don't mess with this without letting me know.
// there was some very strange issues with doing ( timeNow-timeThen ) producing different values to: double diff = timeNow-timeThen;
// http://www.openframeworks.cc/forum/viewtopic.php?f=7&t=1892&p=11166#p11166
timeNow = ofGetElapsedTimef();
- double diff = timeNow-timeThen;
- if( diff > 0.00001 ) {
- fps = 1.0 / diff;
- frameRate *= 0.9f;
- frameRate += 0.1f*fps;
+ double diff = timeNow - timeThen;
+ if(diff > 0.00001){
+ fps = 1.0 / diff;
+ frameRate *= 0.9f;
+ frameRate += 0.1f * fps;
}
- lastFrameTime = diff;
- timeThen = timeNow;
-
+ lastFrameTime = diff;
+ timeThen = timeNow;
+
// --------------
ofNotifyUpdate();
}
@@ -275,167 +276,229 @@ void ofWindowManager::draw(){
ofNotifyDraw();
}
-ofWindow* ofWindowManager::getLastCreatedWindow()
-{
+ofWindow * ofWindowManager::getLastCreatedWindow(){
return windows.back().get();
}
-ofWindow* ofWindowManager::getMainWindow()
-{
+ofWindow * ofWindowManager::getMainWindow(){
return mainWindow;
}
void ofWindowManager::setFrameRate(float targetRate){
// given this FPS, what is the amount of millis per frame
// that should elapse?
-
+
// --- > f / s
-
- if (targetRate == 0){
+
+ if(targetRate == 0){
bFrameRateSet = false;
return;
}
-
- bFrameRateSet = true;
- float durationOfFrame = 1.0f / (float)targetRate;
- millisForFrame = (int)(1000.0f * durationOfFrame);
-
- frameRate = targetRate;
-
+
+ bFrameRateSet = true;
+ float durationOfFrame = 1.0f / (float)targetRate;
+ millisForFrame = (int)(1000.0f * durationOfFrame);
+
+ frameRate = targetRate;
+
}
-float ofWindowManager::getFrameRate()
-{
+float ofWindowManager::getFrameRate(){
return frameRate;
}
-void ofWindowManager::setActiveWindow(ofWindow* win)
-{
+void ofWindowManager::setActiveWindow(ofWindow * win){
activeWindow = win;
activeWindow->enableContext();
}
-ofPoint ofWindowManager::getWindowPosition() {return activeWindow->getWindowPosition(); }
-ofPoint ofWindowManager::getWindowSize(){return activeWindow->getWindowSize(); }
+ofPoint ofWindowManager::getWindowPosition(){
+ return activeWindow->getWindowPosition();
+}
+ofPoint ofWindowManager::getWindowSize(){
+ return activeWindow->getWindowSize();
+}
//this is used by ofGetWidth and now determines the window width based on orientation
-int ofWindowManager::getWidth(){ return activeWindow->getWidth(); }
-int ofWindowManager::getHeight(){ return activeWindow->getHeight(); }
+int ofWindowManager::getWidth(){
+ return activeWindow->getWidth();
+}
+int ofWindowManager::getHeight(){
+ return activeWindow->getHeight();
+}
////GLFW CALLBACKS
void ofWindowManager::glfwWindowFocus(GLFWwindow glfwWin, int action){
- ofWindow* win = getWindowByGlfw(glfwWin);
+ ofWindow * win = getWindowByGlfw(glfwWin);
}
void ofWindowManager::glfwWindowSize(GLFWwindow glfwWin, int w, int h){
- ofWindow* win = getWindowByGlfw(glfwWin);
+ ofWindow * win = getWindowByGlfw(glfwWin);
win->windowResized(w, h);
}
int ofWindowManager::glfwWindowClose(GLFWwindow glfwWin){
- ofWindow* win = getWindowByGlfw(glfwWin);
+ ofWindow * win = getWindowByGlfw(glfwWin);
removeWindow(win);
return 1;
}
void ofWindowManager::glfwWindowRefresh(GLFWwindow glfwWin){
- ofWindow* win = getWindowByGlfw(glfwWin);
-}
+ ofWindow * win = getWindowByGlfw(glfwWin);
+}
void ofWindowManager::glfwWindowIconify(GLFWwindow glfwWin, int action){
- ofWindow* win = getWindowByGlfw(glfwWin);
+ ofWindow * win = getWindowByGlfw(glfwWin);
}
void ofWindowManager::glfwMouseButton(GLFWwindow glfwWin, int button, int action){
- ofWindow* win = getWindowByGlfw(glfwWin);
+ ofWindow * win = getWindowByGlfw(glfwWin);
if(action == GLFW_PRESS){
win->mousePressed(button);
- }else{
+ }
+ else{
win->mouseReleased(button);
}
}
void ofWindowManager::glfwMousePos(GLFWwindow glfwWin, int mouseX, int mouseY){
- ofWindow* win = getWindowByGlfw(glfwWin);
+ ofWindow * win = getWindowByGlfw(glfwWin);
win->mouseMoved(mouseX, mouseY);
}
void ofWindowManager::glfwCursorEnter(GLFWwindow glfwWin, int action){
- ofWindow* win = getWindowByGlfw(glfwWin);
+ ofWindow * win = getWindowByGlfw(glfwWin);
}
void ofWindowManager::glfwScroll(GLFWwindow glfwWin, float deltaX, float deltaY){
- ofWindow* win = getWindowByGlfw(glfwWin);
+ ofWindow * win = getWindowByGlfw(glfwWin);
win->scrolled(deltaX, deltaY);
}
void ofWindowManager::glfwKey(GLFWwindow glfwWin, int key, int action){
- ofWindow* win = getWindowByGlfw(glfwWin);
-
+ ofWindow * win = getWindowByGlfw(glfwWin);
+
//TODO: I'm sure there is some way to do this more efficient than a case statement (Philip)
- switch(key){
- case GLFW_KEY_ENTER:
- key = OF_KEY_RETURN;break;
- case GLFW_KEY_ESC:
- key = OF_KEY_ESC;break;
- case GLFW_KEY_LEFT_CONTROL:
- case GLFW_KEY_RIGHT_CONTROL:
- key = OF_KEY_CTRL;break;
- case GLFW_KEY_RIGHT_ALT:
- case GLFW_KEY_LEFT_ALT:
- key = OF_KEY_ALT;break;
- case GLFW_KEY_RIGHT_SHIFT:
- case GLFW_KEY_LEFT_SHIFT:
- key = OF_KEY_SHIFT;break;
- case GLFW_KEY_BACKSPACE:
- key = OF_KEY_BACKSPACE;break;
- case GLFW_KEY_DELETE:
- key = OF_KEY_DEL;break;
- case GLFW_KEY_F1:
- key = OF_KEY_F1;break;
- case GLFW_KEY_F2:
- key = OF_KEY_F2;break;
- case GLFW_KEY_F3:
- key = OF_KEY_F3;break;
- case GLFW_KEY_F4:
- key = OF_KEY_F4;break;
- case GLFW_KEY_F5:
- key = OF_KEY_F5;break;
- case GLFW_KEY_F6:
- key = OF_KEY_F6;break;
- case GLFW_KEY_F7:
- key = OF_KEY_F7;break;
- case GLFW_KEY_F8:
- key = OF_KEY_F8;break;
- case GLFW_KEY_F9:
- key = OF_KEY_F9;break;
- case GLFW_KEY_F10:
- key = OF_KEY_F10;break;
- case GLFW_KEY_F11:
- key = OF_KEY_F11;break;
- case GLFW_KEY_F12:
- key = OF_KEY_F12;break;
- case GLFW_KEY_LEFT:
- key = OF_KEY_LEFT;break;
- case GLFW_KEY_RIGHT:
- key = OF_KEY_RIGHT;break;
- case GLFW_KEY_DOWN:
- key = OF_KEY_DOWN;break;
- case GLFW_KEY_UP:
- key = OF_KEY_UP;break;
- case GLFW_KEY_PAGEUP:
- key = OF_KEY_PAGE_UP;break;
- case GLFW_KEY_PAGEDOWN:
- key = OF_KEY_PAGE_DOWN;break;
- case GLFW_KEY_HOME:
- key = OF_KEY_HOME;break;
- case GLFW_KEY_END:
- key = OF_KEY_END;break;
- case GLFW_KEY_INSERT:
- key = OF_KEY_INSERT;break;
+ switch(key){
+ case GLFW_KEY_ENTER:
+ key = OF_KEY_RETURN;
+ break;
+
+ case GLFW_KEY_ESC:
+ key = OF_KEY_ESC;
+ break;
+
+ case GLFW_KEY_LEFT_CONTROL:
+ case GLFW_KEY_RIGHT_CONTROL:
+ key = OF_KEY_CTRL;
+ break;
+
+ case GLFW_KEY_RIGHT_ALT:
+ case GLFW_KEY_LEFT_ALT:
+ key = OF_KEY_ALT;
+ break;
+
+ case GLFW_KEY_RIGHT_SHIFT:
+ case GLFW_KEY_LEFT_SHIFT:
+ key = OF_KEY_SHIFT;
+ break;
+
+ case GLFW_KEY_BACKSPACE:
+ key = OF_KEY_BACKSPACE;
+ break;
+
+ case GLFW_KEY_DELETE:
+ key = OF_KEY_DEL;
+ break;
+
+ case GLFW_KEY_F1:
+ key = OF_KEY_F1;
+ break;
+
+ case GLFW_KEY_F2:
+ key = OF_KEY_F2;
+ break;
+
+ case GLFW_KEY_F3:
+ key = OF_KEY_F3;
+ break;
+
+ case GLFW_KEY_F4:
+ key = OF_KEY_F4;
+ break;
+
+ case GLFW_KEY_F5:
+ key = OF_KEY_F5;
+ break;
+
+ case GLFW_KEY_F6:
+ key = OF_KEY_F6;
+ break;
+
+ case GLFW_KEY_F7:
+ key = OF_KEY_F7;
+ break;
+
+ case GLFW_KEY_F8:
+ key = OF_KEY_F8;
+ break;
+
+ case GLFW_KEY_F9:
+ key = OF_KEY_F9;
+ break;
+
+ case GLFW_KEY_F10:
+ key = OF_KEY_F10;
+ break;
+
+ case GLFW_KEY_F11:
+ key = OF_KEY_F11;
+ break;
+
+ case GLFW_KEY_F12:
+ key = OF_KEY_F12;
+ break;
+
+ case GLFW_KEY_LEFT:
+ key = OF_KEY_LEFT;
+ break;
+
+ case GLFW_KEY_RIGHT:
+ key = OF_KEY_RIGHT;
+ break;
+
+ case GLFW_KEY_DOWN:
+ key = OF_KEY_DOWN;
+ break;
+
+ case GLFW_KEY_UP:
+ key = OF_KEY_UP;
+ break;
+
+ case GLFW_KEY_PAGEUP:
+ key = OF_KEY_PAGE_UP;
+ break;
+
+ case GLFW_KEY_PAGEDOWN:
+ key = OF_KEY_PAGE_DOWN;
+ break;
+
+ case GLFW_KEY_HOME:
+ key = OF_KEY_HOME;
+ break;
+
+ case GLFW_KEY_END:
+ key = OF_KEY_END;
+ break;
+
+ case GLFW_KEY_INSERT:
+ key = OF_KEY_INSERT;
+ break;
}
-
- if(action == GLFW_RELEASE)
+
+ if(action == GLFW_RELEASE){
win->keyReleased(key);
- else
+ }
+ else{
win->keyPressed(key);
-
-
+ }
+
+
}
void ofWindowManager::glfwChar(GLFWwindow glfwWin, int key){
- ofWindow* win = getWindowByGlfw(glfwWin);
+ ofWindow * win = getWindowByGlfw(glfwWin);
}
View
120 libs/openFrameworks/window/ofWindowManager.h
@@ -3,68 +3,68 @@
#include "ofWindow.h"
#include "ofBaseTypes.h"
-typedef ofPtr<ofWindow> ofWindowPtr;
-typedef vector< ofWindowPtr > ofWindowList;
+typedef ofPtr <ofWindow> ofWindowPtr;
+typedef vector <ofWindowPtr> ofWindowList;
-class ofWindowManager: public ofAppBaseWindow{
-public:
- ofWindowManager();
- ~ofWindowManager();
-
- ofWindow* createWindow(int w=800, int h=600);
- ofWindow* createWindow(int x, int y, int width, int height);
- void deleteWindow(ofWindow* win);
- void deleteWindow(int id);
-
- void initializeWindow();
- void setupOpenGL(int w, int h, int screenMode);
- void runAppViaInfiniteLoop(ofBaseApp * appPtr);
-
- void update();
- void draw();
-
- ofWindow* getLastCreatedWindow();
- ofWindow* getMainWindow();
- ofWindow* getWindowById(int id);
-
- void setFrameRate(float targetRate);
- float getFrameRate();
- void setActiveWindow(ofWindow* win);
-
- ofPoint getWindowPosition();
- ofPoint getWindowSize();
-
- int getWidth();
- int getHeight();
-
- //would like to have these functions private. but don't know how...
- void glfwWindowFocus(GLFWwindow glfwWin, int action);
- void glfwWindowSize(GLFWwindow glfwWin, int w, int h);
- int glfwWindowClose(GLFWwindow glfwWin);
- void glfwWindowRefresh(GLFWwindow glfwWin);
- void glfwWindowIconify(GLFWwindow glfwWin, int action);
- void glfwMouseButton(GLFWwindow glfwWin, int button, int action);
- void glfwMousePos(GLFWwindow glfwWin, int mouseX, int mouseY);
- void glfwCursorEnter(GLFWwindow glfwWin, int action);
- void glfwScroll(GLFWwindow glfwWin, float deltaX, float deltaY);
- void glfwKey(GLFWwindow glfwWin, int key, int action);
- void glfwChar(GLFWwindow glfwWin, int key);
-
-private:
- ofWindow* getWindowByGlfw(GLFWwindow win);
- void initializeGLFW();
- void addWindow(ofWindow* win);
- void removeWindow(ofWindow* win);
-
- ofWindowList windows;
- ofWindow* mainWindow;
- ofWindow* activeWindow;
+class ofWindowManager : public ofAppBaseWindow {
+ public:
+ ofWindowManager();
+ ~ofWindowManager();
+
+ ofWindow * createWindow(int w = 800, int h = 600);
+ ofWindow * createWindow(int x, int y, int width, int height);
+ void deleteWindow(ofWindow * win);
+ void deleteWindow(int id);
+
+ void initializeWindow();
+ void setupOpenGL(int w, int h, int screenMode);
+ void runAppViaInfiniteLoop(ofBaseApp * appPtr);
+
+ void update();
+ void draw();
+
+ ofWindow * getLastCreatedWindow();
+ ofWindow * getMainWindow();
+ ofWindow * getWindowById(int id);
+
+ void setFrameRate(float targetRate);
+ float getFrameRate();
+ void setActiveWindow(ofWindow * win);
+
+ ofPoint getWindowPosition();
+ ofPoint getWindowSize();
+
+ int getWidth();
+ int getHeight();
+
+ //would like to have these functions private. but don't know how...
+ void glfwWindowFocus(GLFWwindow glfwWin, int action);
+ void glfwWindowSize(GLFWwindow glfwWin, int w, int h);
+ int glfwWindowClose(GLFWwindow glfwWin);
+ void glfwWindowRefresh(GLFWwindow glfwWin);
+ void glfwWindowIconify(GLFWwindow glfwWin, int action);
+ void glfwMouseButton(GLFWwindow glfwWin, int button, int action);
+ void glfwMousePos(GLFWwindow glfwWin, int mouseX, int mouseY);
+ void glfwCursorEnter(GLFWwindow glfwWin, int action);
+ void glfwScroll(GLFWwindow glfwWin, float deltaX, float deltaY);
+ void glfwKey(GLFWwindow glfwWin, int key, int action);
+ void glfwChar(GLFWwindow glfwWin, int key);
+
+ private:
+ ofWindow * getWindowByGlfw(GLFWwindow win);
+ void initializeGLFW();
+ void addWindow(ofWindow * win);
+ void removeWindow(ofWindow * win);
+
+ ofWindowList windows;
+ ofWindow * mainWindow;
+ ofWindow * activeWindow;
};
/* OF C-STYLE FUNCTIONS */
-ofWindowManager* ofGetWindowManager();
-ofWindow* ofCreateWindow(int x, int y, int width, int height);
-ofWindow* ofCreateWindow(int width=800, int height=600);
-ofWindow* ofGetMainWindow();
-ofWindow* ofGetLastCreatedWindow();
+ofWindowManager * ofGetWindowManager();
+ofWindow * ofCreateWindow(int x, int y, int width, int height);
+ofWindow * ofCreateWindow(int width = 800, int height = 600);
+ofWindow * ofGetMainWindow();
+ofWindow * ofGetLastCreatedWindow();
Please sign in to comment.
Something went wrong with that request. Please try again.