openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.97k stars 2.55k forks source link

Proposal : ofAppGLFWWindow, set position and shape at the same time #6950

Open dimitre opened 2 years ago

dimitre commented 2 years ago

reading the code I've noticed some hacks to make things work like this:

    setWindowPosition(pos.x, pos.y);
    setWindowShape(screenSize.x, screenSize.y);
    setWindowPosition(pos.x, pos.y);

and inside function setWindowShape we have another setWindowPosition going. I'm proposing the creation of a function who does the two things at the same time, only to be used when position and shape (dimensions) are set at once.

//------------------------------------------------------------
void ofAppGLFWWindow::setWindowRectangle(ofRectangle rect) {
    if(settings.windowMode == OF_WINDOW){
        windowW = rect.width;
        windowH = rect.height;
    }
    currentW = rect.width/pixelScreenCoordScale;
    currentH = rect.height/pixelScreenCoordScale;

//  cout << "glfwSetWindowSize " << ofGetFrameNum() << endl;
    glfwSetWindowSize(windowP,currentW,currentH);
    glfwSetWindowPos(windowP,rect.x/pixelScreenCoordScale,rect.y/pixelScreenCoordScale);
}
roymacdonald commented 2 years ago

+1. I would just use a const reference for the argument void ofAppGLFWWindow::setWindowRectangle(const ofRectangle& rect)