fltk/src/fl_vertex.cxx

144 lines
3.2 KiB
C++
Raw Normal View History

//
// "$Id$"
//
// Portable drawing routines for the Fast Light Tool Kit (FLTK).
//
Introduce HiDPI + rescaling support for the X11 platform (+ partial support for WIN32) Corresponds to STR #3320 1) HiDPI support consists in detecting the adequate scaling factor for the screen on which FLTK maps a window, and scaling all FLTK units by this factor. FLTK tries to detect the correct value of this factor at startup (see more details below). Environment variable FLTK_SCALING_FACTOR can also be used to set this value. 2) Rescaling support consists in changing the scaling factor of all FLTK windows in reply to ctrl/+/-/0/ keystrokes. More details for the various platforms : - X11: Support is very advanced. Some details need still to be improved. Automatic detection of the correct starting value of the scaling factor works well with the gnome desktop. The present code contains no support for this on other desktops. FLTK_SCALING_FACTOR provides a workaround. -WIN32: Support is incomplete at this point, although many test applications have partial or complete HiDPI and scaling support. The current value of the system's scaling factor is correctly detected at application startup. Apps respond to changes of this value in real time. Support needs to define the FLTK_HIDPI_SUPPORT preprocessor variable at compile time. This way, standard builds produce a code with the default WIN32 HiDPI support, that is, where all graphics goes to an internal buffer that gets enlarged by the system and then mapped to the HiDPI display. To experiment with (or develop) the new HiDPI support requires a modified build procedure in which FLTK_HIDPI_SUPPORT is defined at compile time. When the support will be complete, the requirement for the definition of this preprocessor variable will be removed. The present commit contains support for a single scaling factor. Eventually, per-screen scaling factors should be implemented, as done for X11. - MacOS: this commit does not give new HiDPI for this platform. Eventually, window rescaling in reply to command/+/-/0/ is desirable. Per-screen scaling factor makes no sense on this platform because the OS itself takes care of the difference between the resolutions of traditional and retina displays. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12239 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2017-05-17 11:54:18 +00:00
// Copyright 1998-2017 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// http://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
/**
\file fl_vertex.cxx
\brief Portable drawing code for drawing arbitrary shapes with
simple 2D transformations.
*/
// Portable code for drawing arbitrary shapes with simple 2D transformations.
// See also fl_arc.cxx
// matt: the Quartz implementation purposely doesn't use the Quartz matrix
// operations for reasons of compatibility and maintainability
// -----------------------------------------------------------------------------
// all driver code is now in drivers/XXX/Fl_XXX_Graphics_Driver_xyz.cxx
// -----------------------------------------------------------------------------
#include <FL/Fl_Graphics_Driver.H>
#include <FL/Fl.H>
#include <FL/math.h>
#include <stdlib.h>
/**
\cond DriverDev
\addtogroup DriverDeveloper
\{
*/
/** see fl_push_matrix() */
void Fl_Graphics_Driver::push_matrix() {
if (sptr==matrix_stack_size)
Fl::error("fl_push_matrix(): matrix stack overflow.");
else
stack[sptr++] = m;
}
/** see fl_pop_matrix() */
void Fl_Graphics_Driver::pop_matrix() {
if (sptr==0)
Fl::error("fl_pop_matrix(): matrix stack underflow.");
else
m = stack[--sptr];
}
/** see fl_mult_matrix() */
void Fl_Graphics_Driver::mult_matrix(double a, double b, double c, double d, double x, double y) {
matrix o;
o.a = a*m.a + b*m.c;
o.b = a*m.b + b*m.d;
o.c = c*m.a + d*m.c;
o.d = c*m.b + d*m.d;
o.x = x*m.a + y*m.c + m.x;
o.y = x*m.b + y*m.d + m.y;
m = o;
}
/** see fl_rotate() */
void Fl_Graphics_Driver::rotate(double d) {
if (d) {
double s, c;
if (d == 0) {s = 0; c = 1;}
else if (d == 90) {s = 1; c = 0;}
else if (d == 180) {s = 0; c = -1;}
else if (d == 270 || d == -90) {s = -1; c = 0;}
else {s = sin(d*M_PI/180); c = cos(d*M_PI/180);}
mult_matrix(c,-s,s,c,0,0);
}
}
/** see fl_translate() */
void Fl_Graphics_Driver::translate(double x,double y) {
mult_matrix(1,0,0,1,x,y);
}
/** see fl_begin_points() */
void Fl_Graphics_Driver::begin_points() {
n = 0;
what = POINT_;
}
/** see fl_begin_line() */
void Fl_Graphics_Driver::begin_line() {
n = 0;
what = LINE;
}
/** see fl_begin_loop() */
void Fl_Graphics_Driver::begin_loop() {
n = 0;
what = LOOP;
}
/** see fl_begin_polygon() */
void Fl_Graphics_Driver::begin_polygon() {
n = 0;
what = POLYGON;
}
/** see fl_transform_x() */
double Fl_Graphics_Driver::transform_x(double x, double y) {
return x*m.a + y*m.c + m.x;
}
/** see fl_transform_y() */
double Fl_Graphics_Driver::transform_y(double x, double y) {
return x*m.b + y*m.d + m.y;
}
/** see fl_transform_dx() */
double Fl_Graphics_Driver::transform_dx(double x, double y) {
return x*m.a + y*m.c;
}
/** see fl_transform_dy() */
double Fl_Graphics_Driver::transform_dy(double x, double y) {
return x*m.b + y*m.d;
}
/**
\}
\endcond
*/
//
// End of "$Id$".
//