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
This commit is contained in:
parent
fb0f940c51
commit
cd399d9898
@ -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
|
||||
};
|
||||
|
||||
|
||||
17
FL/Fl.H
17
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();
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 ...
|
||||
|
||||
35
src/Fl.cxx
35
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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user