summaryrefslogtreecommitdiff
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
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
-rw-r--r--FL/Enumerations.H5
-rw-r--r--FL/Fl.H17
-rw-r--r--FL/Fl_Graphics_Driver.H4
-rw-r--r--FL/names.h2
-rw-r--r--src/Fl.cxx35
-rw-r--r--src/Fl_Screen_Driver.cxx5
-rw-r--r--src/Fl_cocoa.mm2
7 files changed, 61 insertions, 9 deletions
diff --git a/FL/Enumerations.H b/FL/Enumerations.H
index 2a1908f8e..68b38f242 100644
--- a/FL/Enumerations.H
+++ b/FL/Enumerations.H
@@ -403,8 +403,9 @@ enum Fl_Event { // events
The Fl::event_dy() method can be used to find magnification amount,
Fl::event_x() and Fl::event_y() are set as well.
*/
- FL_ZOOM_GESTURE = 26
-
+ FL_ZOOM_GESTURE = 26,
+ /** A zoom event (crtl-/+/-/0/) was processed */
+ FL_ZOOM_EVENT = 27
// DEV NOTE: Keep this list in sync with FL/names.h
};
diff --git a/FL/Fl.H b/FL/Fl.H
index 6bb1f7447..1075c3831 100644
--- a/FL/Fl.H
+++ b/FL/Fl.H
@@ -252,6 +252,10 @@ public:
/// if the GTK library is available on the platform (linux/unix only).
/// When switched off, GTK file dialogs aren't used even if the GTK library is available.
OPTION_FNFC_USES_GTK,
+ /// When switched on (default), the library shows in a transient yellow window the zoom factor
+ /// value.
+ /// When switched off, no such window gets displayed.
+ OPTION_SHOW_SCALING,
// don't change this, leave it always as the last element
/// For internal use only.
OPTION_LAST
@@ -989,7 +993,15 @@ int main() {
/** \defgroup fl_screen Screen functions
- fl global screen functions declared in <FL/Fl.H>
+ fl global screen functions declared in <FL/Fl.H>.
+ FLTK supports high-DPI screens using a screen scaling factor.
+ The scaling factor value can be changed by typing ctrl-/+/-/0/
+ (cmd-/+/-/0/ under MacOS). FLTK sends the FL_ZOOM_EVENT when the
+ factor value is changed, to which a callback can be associated with Fl::add_handler().
+ By default, FLTK also displays the new scaling factor value in a yellow, transient window.
+ This can be changed with Fl::option(OPTION_SHOW_SCALING, 0).
+ The scaling factor value is programmatically get and set with the Fl::screen_scale() functions.
+
@{ */
static int x(); // via screen driver
static int y(); // via screen driver
@@ -1009,6 +1021,9 @@ int main() {
static void screen_work_area(int &X, int &Y, int &W, int &H, int n); // via screen driver
static void screen_work_area(int &X, int &Y, int &W, int &H); // via screen driver
static float screen_scale(int n); // via screen driver
+ static void screen_scale(int n, float factor); // via screen driver
+ static int screen_scaling_supported();
+
/** @} */
diff --git a/FL/Fl_Graphics_Driver.H b/FL/Fl_Graphics_Driver.H
index 3057d127e..d21576a6a 100644
--- a/FL/Fl_Graphics_Driver.H
+++ b/FL/Fl_Graphics_Driver.H
@@ -158,8 +158,6 @@ public:
} driver_feature;
protected:
- /** Sets the current value of the scaling factor */
- virtual void scale(float f) { scale_ = f; }
int fl_clip_state_number; ///< For internal use by FLTK
static const matrix m0; ///< For internal use by FLTK
Fl_Font font_; ///< current font
@@ -256,6 +254,8 @@ public:
static Fl_Graphics_Driver &default_driver();
/** Current scale factor between FLTK and drawing units: drawing = FLTK * scale() */
float scale() { return scale_; }
+ /** Sets the current value of the scaling factor */
+ virtual void scale(float f) { scale_ = f; }
/** Return whether the graphics driver can do alpha blending */
virtual char can_do_alpha_blending() { return 0; }
// --- implementation is in src/fl_rect.cxx which includes src/drivers/xxx/Fl_xxx_Graphics_Driver_rect.cxx
diff --git a/FL/names.h b/FL/names.h
index 46525d600..7b4700fbe 100644
--- a/FL/names.h
+++ b/FL/names.h
@@ -69,7 +69,7 @@ const char * const fl_eventnames[] =
"FL_SCREEN_CONFIGURATION_CHANGED",
"FL_FULLSCREEN",
"FL_ZOOM_GESTURE",
- "FL_EVENT_27", // not yet defined, just in case it /will/ be defined ...
+ "FL_ZOOM_EVENT",
"FL_EVENT_28", // not yet defined, just in case it /will/ be defined ...
"FL_EVENT_29", // not yet defined, just in case it /will/ be defined ...
"FL_EVENT_30" // not yet defined, just in case it /will/ be defined ...
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,