Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed windowing/windowExample #8210

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions examples/windowing/windowExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ void ofApp::setup(){

int screenW = ofGetScreenWidth();
int screenH = ofGetScreenHeight();
ofSetWindowPosition(screenW/2-300/2, screenH/2-300/2);
posx=screenW/2-300/2;
posy=screenH/2-300/2;
ofSetWindowPosition(posx, posy);

// load our typeface
vagRounded.load("vag.ttf", 16);
Expand All @@ -24,6 +26,7 @@ void ofApp::setup(){
ballPositionY = 150;
ballVelocityX = ofRandom(-5,5);
ballVelocityY = ofRandom(-5,5);

}

//--------------------------------------------------------------
Expand All @@ -39,41 +42,39 @@ void ofApp::update(){
ofShowCursor();
}


ballPositionX += ballVelocityX;
ballPositionY += ballVelocityY;

int posx = ofGetWindowPositionX();
int posy = ofGetWindowPositionY();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this point to a bug/regression with ofGetWindowPositionX / ofGetWindowPositionY ?

This code used to work.
I appreciate the bug fix for the example, but I think the bigger fix might be to understand why ofGetWindowPosition is not working anymore.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the consideration!

If the code used to work, I agree! I can definitely dive into ofGetWindowPosition in order to understand the issue at a deeper level.

Is it ok to share the insights on this matter in this conversation? If you prefer, we close the PR and we open a new one when I find something interesting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, the following code is already an issue. Even if it looks like the window is beeing set at exactly the same position it already has, in reality the window keeps moving. Precisely, each time it's set at +6 units in x and +27 units in y, with respect to the current position.

void ofApp::update(){  
		int posx = ofGetWindowPositionX();
		int posy = ofGetWindowPositionY();		
		ofSetWindowPosition(posx, posy);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which platform are you in? it seems the dimensions of window decoration, status bar and border

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working inside WSL -Windows Subsystem for Linux- with Windows 11 and Debian.


if (ballPositionX < 0){
ballPositionX = 0;
ballVelocityX *= -1;
if (!bFullscreen){
ofSetWindowPosition(posx-10, posy);
posx-=10;
}
} else if (ballPositionX > ofGetWidth()){
ballPositionX = ofGetWidth();
ballVelocityX *= -1;
if (!bFullscreen){
ofSetWindowPosition(posx+10, posy);
posx+=10;
}
}

if (ballPositionY < 0){
ballPositionY = 0;
ballVelocityY *= -1;
if (!bFullscreen){
ofSetWindowPosition(posx, posy-10);
posy-=10;
}
} else if (ballPositionY > ofGetHeight()){
ballPositionY = ofGetHeight();
ballVelocityY *= -1;
if (!bFullscreen){
ofSetWindowPosition(posx, posy+10);
posy+=10;
}
}


ofSetWindowPosition(posx, posy);

}

//--------------------------------------------------------------
Expand All @@ -85,6 +86,7 @@ void ofApp::draw(){
// lets show our window pos in pixels
// macs actually start the Y pos from 40
vagRounded.drawString("window pos ("+ofToString(ofGetWindowPositionX())+", "+ofToString( ofGetWindowPositionY())+")", 10, 25);
// vagRounded.drawString("window pos ("+ofToString(ballPositionX)+", "+ofToString(ballPositionY)+")", 10, 25);

if(!bFullscreen){
vagRounded.drawString("press f to enter fullscreen", -140 + ofGetWidth()/2, ofGetHeight()/2);
Expand Down
3 changes: 3 additions & 0 deletions examples/windowing/windowExample/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ class ofApp : public ofBaseApp{
float ballPositionY;
float ballVelocityX;
float ballVelocityY;

float posx;
float posy;

};