summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2018-08-08 20:08:10 +0000
committerManolo Gouy <Manolo>2018-08-08 20:08:10 +0000
commitcd399d989897e650cc7928c4ebd9bf89892d7995 (patch)
treed0e6d7f02a53a9ead62c88c34cb84580a24a3fc2 /src
parentfb0f940c517d4f0f0f2f22f92acc54c9f5b37242 (diff)
Support for GUI scaling: add API to get/set the scaling factor value.
Also, define an FLTK event triggered when the scaling is changed and an option to disable the transient window showing the new scaling factor. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@13011 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl.cxx35
-rw-r--r--src/Fl_Screen_Driver.cxx5
-rw-r--r--src/Fl_cocoa.mm2
3 files changed, 39 insertions, 3 deletions
diff --git a/src/Fl.cxx b/src/Fl.cxx
index 3a682c039..8d99d679e 100644
--- a/src/Fl.cxx
+++ b/src/Fl.cxx
@@ -16,6 +16,10 @@
// http://www.fltk.org/str.php
//
+/** \file
+ Implementation of the member functions of class Fl.
+ */
+
#include "config_lib.h"
#include <FL/Fl.H>
@@ -1860,8 +1864,11 @@ bool Fl::option(Fl_Option opt)
options_[OPTION_DND_TEXT] = tmp;
opt_prefs.get("ShowTooltips", tmp, 1); // default: on
options_[OPTION_SHOW_TOOLTIPS] = tmp;
- opt_prefs.get("FNFCUsesGTK", tmp, 1); // default: on
+ opt_prefs.get("FNFCUsesGTK", tmp, 1); // default: on
options_[OPTION_FNFC_USES_GTK] = tmp;
+
+ opt_prefs.get("ShowZoomFactor", tmp, 1); // default: on
+ options_[OPTION_SHOW_SCALING] = tmp;
}
{ // next, check the user preferences
// override system options only, if the option is set ( >= 0 )
@@ -1881,6 +1888,9 @@ bool Fl::option(Fl_Option opt)
if (tmp >= 0) options_[OPTION_SHOW_TOOLTIPS] = tmp;
opt_prefs.get("FNFCUsesGTK", tmp, -1);
if (tmp >= 0) options_[OPTION_FNFC_USES_GTK] = tmp;
+
+ opt_prefs.get("ShowZoomFactor", tmp, -1);
+ if (tmp >= 0) options_[OPTION_SHOW_SCALING] = tmp;
}
{ // now, if the developer has registered this app, we could as for per-application preferences
}
@@ -2058,6 +2068,11 @@ void Fl::disable_im()
Fl::screen_driver()->disable_im();
}
+/**
+ Opens the display.
+ Automatically called by the library when the first window is show()'n.
+ Does nothing if the display is already open.
+ */
void fl_open_display()
{
Fl::screen_driver()->open_display();
@@ -2110,6 +2125,24 @@ float Fl::screen_scale(int n) {
return Fl::screen_driver()->scale(n);
}
+/** Set the value of the GUI scaling factor for screen number \p n.
+Call this function before the fist window is show()'n and after
+a call to fl_open_display() to set the application's initial scaling factor value. */
+void Fl::screen_scale(int n, float factor) {
+ Fl::screen_driver()->scale(n, factor);
+ Fl_Graphics_Driver::default_driver().scale(factor);
+}
+
+/**
+ See if scaling factors are supported by this platform.
+ \return 0 if scaling factors are not supported by this platform,
+ 1 if a single scaling factor value is shared by all screens, 2 if each screen
+ can have its own scaling factor value.
+ \see Fl::screen_scale(int)
+ */
+int Fl::screen_scaling_supported() {
+ return Fl::screen_driver()->rescalable();
+}
// Pointers you can use to change FLTK to another language.
// Note: Similar pointers are defined in FL/fl_ask.H and src/fl_ask.cxx
diff --git a/src/Fl_Screen_Driver.cxx b/src/Fl_Screen_Driver.cxx
index d04db7094..9c0857972 100644
--- a/src/Fl_Screen_Driver.cxx
+++ b/src/Fl_Screen_Driver.cxx
@@ -336,7 +336,9 @@ static void del_transient_window(void *data) {
}
void Fl_Screen_Driver::transient_scale_display(float f, int nscreen)
-{ // transiently show the new scaling value using a shaped window
+{
+ if (!Fl::option(Fl::OPTION_SHOW_SCALING)) return;
+ // transiently show the new scaling value using a shaped window
int w = 150;
// draw a white rounded box on black background
Fl_Screen_Driver *d = Fl::screen_driver();
@@ -427,6 +429,7 @@ int Fl_Screen_Driver::scale_handler(int event)
screen_dr->rescale_all_windows_from_screen(screen, f*initial_scale);
Fl_Screen_Driver::transient_scale_display(f, screen);
screen_dr->init_workarea();
+ Fl::handle(FL_ZOOM_EVENT, NULL);
return 1;
}
return 0;
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index e2ad85728..1371d7a67 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -2146,7 +2146,7 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
fl_lock_function();
FLWindow *cw = (FLWindow*)[self window];
Fl_Window *window = [cw getFl_Window];
- float scale = fl_graphics_driver->scale();
+ float scale = Fl::screen_driver()->scale(0);
if ( !window->parent() && window->border() && fabs(rect.size.height - window->h() * scale) > 5. ) { // this happens with tabbed windows
window->resize([cw frame].origin.x/scale,
(main_screen_height - ([cw frame].origin.y + rect.size.height))/scale,