// Calculate the zoom ratio required to fit the whole image on the screen.
float UI_calcZoomToFitScreen(GtkWindow* window, GtkWidget* drawingArea, uint32_t imageWidth, uint32_t imageHeight)
{
	int windowWidth, windowHeight;
	int drawingWidth, drawingHeight;
	uint32_t screenWidth, screenHeight;
	
	gtk_window_get_size(window, &windowWidth, &windowHeight);
	gtk_widget_get_size_request(drawingArea, &drawingWidth, &drawingHeight);

	UI_getPhysicalScreenSize(window, &screenWidth, &screenHeight);

	// Take drawing area out of the equation, how much extra do we need for additional controls?
	windowWidth -= drawingWidth;
	windowHeight -= drawingHeight;

	// Take borders and captions into consideration (GTK doesn't seem to support this so we'll have to guess)
	windowWidth += 10;
	windowHeight += 40;

	// This is the true amount of screen real estate we can work with
	screenWidth -= windowWidth;
	screenHeight -= windowHeight;

	// Calculate zoom ratio
	if (imageWidth > screenWidth || imageHeight > screenHeight)
	{
		if ((int)(imageWidth - screenWidth) > (int)(imageHeight - screenHeight))
			return (float)screenWidth / (float)imageWidth;
		else
			return (float)screenHeight / (float)imageHeight;
	}
	else
		return 1;
}
Example #2
0
// Calculate the zoom ratio required to fit the whole image on the screen.
float UI_calcZoomToFitScreen(QWidget* window, QWidget* canvas, uint32_t imageWidth, uint32_t imageHeight)
{
	int windowWidth, windowHeight;
	int drawingWidth, drawingHeight;
	uint32_t screenWidth, screenHeight;

	windowWidth = window->frameSize().width();
	windowHeight = window->frameSize().height();

	drawingWidth = canvas->frameSize().width();
	drawingHeight = canvas->frameSize().height();

	UI_getPhysicalScreenSize(window, &screenWidth, &screenHeight);

	// Take drawing area out of the equation, how much extra do we need for additional controls?
	windowWidth -= drawingWidth;
	windowHeight -= drawingHeight;

	// This is the true amount of screen real estate we can work with
	screenWidth -= windowWidth;
	screenHeight -= windowHeight;

	// Calculate zoom ratio
	if (imageWidth > screenWidth || imageHeight > screenHeight)
	{
            //return 1;
        }
        float widthRatio = (float)screenWidth / (float)imageWidth;
        float heightRatio = (float)screenHeight / (float)imageHeight;

        float r= (widthRatio < heightRatio ? widthRatio : heightRatio);
        return r;
		
}
///
///	Create main window and bind to it
///
uint8_t initGUI( void )
{
uint8_t ret=0;
uint32_t w,h;
		// create top window
		guiRootWindow=create_mainWindow();
		
		if(!guiRootWindow) return 0;

#ifdef ENABLE_WINDOW_SIZING_HACK
                do_tmpwin_hack();
#endif

		gtk_register_dialog(guiRootWindow);
					
		// and seek global sub entity
		ret= bindGUI();		
		if(ret) gtk_widget_show(guiRootWindow);
                UI_purge();
		// Set it as always low level
		//gtk_window_set_keep_below(GTK_WINDOW(guiRootWindow), 1);
		renderInit();
		GUI_initCursor(  );
    
                
                UI_getPhysicalScreenSize(guiRootWindow, &w, &h);
                printf("The screen seems to be %u x %u px\n",w,h);
 
                GUI_gtk_grow_off(1);
#ifdef USE_JOG
                physical_jog_shuttle = &(PhysicalJogShuttle::getInstance());
                physical_jog_shuttle->registerCBs (NULL, jogButton, jogDial, jogRing);
#endif 
	return ret;
}
	bool eventFilter(QObject *obj, QEvent *event)
	{
		if (event->type() == QEvent::Show && !recomputed)
		{
			recomputed = true;
			QWidget* parent = (QWidget*)obj;
			uint32_t screenWidth, screenHeight;

			UI_getPhysicalScreenSize(parent, &screenWidth, &screenHeight);
			flyDialog->recomputeSize();
			QCoreApplication::processEvents();
			parent->move((((int)screenWidth) - parent->frameSize().width()) / 2, (((int)screenHeight) - parent->frameSize().height()) / 2);
		}
		
		return QObject::eventFilter(obj, event);
	};