Scaling & Mouse Input (ofxUI related)

I’m working with a 1920x1080 resolution application but I only have a 1366x768 sized monitor. I’m scaling the application with ofScale(0.71, 0.71). The result is that all of the images scale properly but the mouse input doesn’t. Is there any way I can scale the mouse input to match the image?

In my case I’m using ofxUI. I draw the GUI, defer the draw, scale the draw loop, and then draw the GUI. The button clicks are located in the original location, not the new scaled location.

I’m also wondering, in Qt Creator there’s a compiler flag which scales the entire application. Is there anything similar in oF?

Any assistance would be much appreciated.

This is a bit of a temporary hack, but you can always alter ofAppGlutWindow::mouse_cb() and just multiply the mouse coordinates by the inverse of your scaling factor. That will ensure that they’re correctly passed to ofxUI. Since what you’re doing is temporary, that seems like the simplest thing to do, unless there’s something more than simple coordinates that you need.

Many thanks, that worked perfectly. And you’re correct, it’s only for temporary use.

I also had to adjust the ofAppGlutWindow::passive_motion_cb() to handle the mouse movements in addition to the button presses.

Cool! Just don’t forget that you’ve done it once you’re done with the project :slight_smile:

Hehe, good point. I just created an ofScaleMouse(float scale) method and added it to ofAppGlutWindow. At least this way I’ll have to explicitly call it.

I don’t know if you still need the code but meeeh I think this will work :slight_smile:

  
  
#define SCALE_FACTOR .71  
  
//--------------------------------------------------------------  
void testApp::mouseMoved(int x, int y){  
	x *= SCALE_FACTOR;  
	y *= SCALE_FACTOR;  
}  
  
//--------------------------------------------------------------  
void testApp::mouseDragged(int x, int y, int button){  
	x *= SCALE_FACTOR;  
	y *= SCALE_FACTOR;  
}  
  
//--------------------------------------------------------------  
void testApp::mousePressed(int x, int y, int button){  
	x *= SCALE_FACTOR;  
	y *= SCALE_FACTOR;  
}  
  
//--------------------------------------------------------------  
void testApp::mouseReleased(int x, int y, int button){  
	x *= SCALE_FACTOR;  
	y *= SCALE_FACTOR;  
}