2010-03-18 18:29:18 +03:00
|
|
|
//
|
|
|
|
// "$Id$"
|
|
|
|
//
|
2010-03-25 16:59:00 +03:00
|
|
|
// implementation of Fl_Device class for the Fast Light Tool Kit (FLTK).
|
2010-03-18 18:29:18 +03:00
|
|
|
//
|
2017-04-25 15:42:22 +03:00
|
|
|
// Copyright 2010-2017 by Bill Spitzak and others.
|
2010-03-18 18:29:18 +03:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// 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
|
2010-03-18 18:29:18 +03:00
|
|
|
//
|
|
|
|
// Please report all bugs and problems to:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
|
|
|
//
|
2010-03-14 21:07:24 +03:00
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
2016-01-31 14:47:49 +03:00
|
|
|
#include "config_lib.h"
|
2010-03-14 21:07:24 +03:00
|
|
|
#include <FL/Fl_Device.H>
|
2016-02-09 21:25:02 +03:00
|
|
|
#include <FL/Fl_Graphics_Driver.H>
|
|
|
|
|
2018-05-10 12:55:29 +03:00
|
|
|
/* Inheritance diagram.
|
2016-02-25 20:56:48 +03:00
|
|
|
|
2016-02-09 21:25:02 +03:00
|
|
|
+- Fl_Surface_Device: any kind of surface that we can draw onto -> uses an Fl_Graphics_Driver
|
|
|
|
|
|
2018-05-10 12:55:29 +03:00
|
|
|
+- Fl_Display_Device: some kind of video device (one object per app)
|
|
|
|
+- Fl_Widget_Surface: any FLTK widget can be drawn to it
|
2016-02-09 21:25:02 +03:00
|
|
|
|
|
2018-05-10 12:55:29 +03:00
|
|
|
+- Fl_Copy_Surface: draw into the clipboard (in vectorial form if the platform supports it)
|
|
|
|
+- Fl_Copy_Surface_Driver: helper class interfacing FLTK with draw-to-clipboard operations
|
|
|
|
|
|
|
|
|
+- Fl_..._Copy_Surface_Driver: platform-specific implementation of Fl_Copy_Surface_Driver
|
|
|
|
+- Fl_Image_Surface: draw into an RGB Image
|
|
|
|
+- Fl_Image_Surface_Driver: helper class interfacing FLTK with draw-to-image operations
|
|
|
|
|
|
|
|
|
+- Fl_..._Image_Surface_Driver: platform-specific implementation of Fl_Image_Surface_Driver
|
|
|
|
+- Fl_Paged_Device: output to a page-structured surface
|
2016-02-09 21:25:02 +03:00
|
|
|
|
|
2018-05-10 12:55:29 +03:00
|
|
|
+- Fl_Printer: user can instantiate this to gain access to a printer
|
|
|
|
+- Fl_..._Printer_Driver: platform-specific helper class interfacing FLTK with print operations
|
|
|
|
+- Fl_PostScript_File_Device: draw into a PostScript file
|
|
|
|
|
|
|
|
|
+- Fl_Posix_Printer_Driver: Fl_Printer uses that under Posix platforms
|
2016-02-25 20:56:48 +03:00
|
|
|
|
2018-05-10 12:55:29 +03:00
|
|
|
+- Fl_Graphics_Driver -> directed to an Fl_Surface_Device object
|
2016-02-09 21:25:02 +03:00
|
|
|
|
|
2018-05-10 12:55:29 +03:00
|
|
|
+- Fl_PostScript_Graphics_Driver: platform-independent graphics driver for PostScript drawing
|
|
|
|
+- Fl_..._Graphics_Driver: platform-specific graphics driver (MacOS, Android, Pico)
|
|
|
|
+- Fl_Quartz_Printer_Graphics_Driver: MacOS-specific, for drawing to printers
|
|
|
|
+- Fl_Scalable_Graphics_Driver: helper class to support GUI scaling
|
|
|
|
+- Fl_Xlib_Graphics_Driver: X11-specific graphics driver
|
|
|
|
+- Fl_GDI_Graphics_Driver: Windows-specific graphics driver
|
|
|
|
+- Fl_GDI_Printer_Graphics_Driver: re-implements a few member functions especially for output to printer
|
|
|
|
+- Fl_OpenGL_Graphics_Driver: draw to an Fl_Gl_Window (only very partial implementation)
|
2016-02-09 21:25:02 +03:00
|
|
|
|
|
|
|
*/
|
2010-03-14 21:07:24 +03:00
|
|
|
|
2016-12-07 18:09:52 +03:00
|
|
|
/** Make this surface the current drawing surface.
|
|
|
|
This surface will receive all future graphics requests.
|
|
|
|
\p Starting from FLTK 1.4.0, another convenient API to set/unset the current drawing surface
|
|
|
|
is Fl_Surface_Device::push_current( ) / Fl_Surface_Device::pop_current().*/
|
2010-05-27 21:20:18 +04:00
|
|
|
void Fl_Surface_Device::set_current(void)
|
2010-03-14 21:07:24 +03:00
|
|
|
{
|
2018-05-01 20:09:15 +03:00
|
|
|
if (surface_) surface_->end_current_();
|
2016-03-07 23:50:18 +03:00
|
|
|
fl_graphics_driver = pGraphicsDriver;
|
2016-12-01 09:40:17 +03:00
|
|
|
surface_ = this;
|
2016-03-07 23:50:18 +03:00
|
|
|
pGraphicsDriver->global_gc();
|
2017-08-24 15:40:29 +03:00
|
|
|
driver()->set_current_();
|
2010-03-14 21:07:24 +03:00
|
|
|
}
|
2010-03-18 18:29:18 +03:00
|
|
|
|
2016-12-01 09:40:17 +03:00
|
|
|
Fl_Surface_Device* Fl_Surface_Device::surface_; // the current target surface of graphics operations
|
2012-03-18 22:48:29 +04:00
|
|
|
|
2016-02-02 02:06:14 +03:00
|
|
|
|
2016-03-03 03:07:17 +03:00
|
|
|
Fl_Surface_Device::~Fl_Surface_Device()
|
|
|
|
{
|
2016-12-07 18:09:52 +03:00
|
|
|
if (surface_ == this) surface_ = NULL;
|
2016-03-03 03:07:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-29 01:02:48 +03:00
|
|
|
/** A constructor that sets the graphics driver used by the display */
|
|
|
|
Fl_Display_Device::Fl_Display_Device(Fl_Graphics_Driver *graphics_driver) : Fl_Surface_Device(graphics_driver) {
|
2015-12-15 11:31:20 +03:00
|
|
|
this->set_current();
|
2011-03-01 14:58:36 +03:00
|
|
|
};
|
|
|
|
|
2011-02-18 16:39:48 +03:00
|
|
|
|
2016-04-26 08:44:54 +03:00
|
|
|
/** Returns a pointer to the unique display device */
|
2015-04-29 01:02:48 +03:00
|
|
|
Fl_Display_Device *Fl_Display_Device::display_device() {
|
2016-02-09 15:33:49 +03:00
|
|
|
static Fl_Display_Device *display = new Fl_Display_Device(Fl_Graphics_Driver::newMainGraphicsDriver());
|
2015-04-29 01:02:48 +03:00
|
|
|
return display;
|
|
|
|
};
|
|
|
|
|
2015-12-16 10:18:34 +03:00
|
|
|
|
|
|
|
Fl_Surface_Device *Fl_Surface_Device::default_surface()
|
|
|
|
{
|
|
|
|
return Fl_Display_Device::display_device();
|
|
|
|
}
|
|
|
|
|
2016-12-12 23:50:16 +03:00
|
|
|
static unsigned int surface_stack_height = 0;
|
2016-12-07 18:09:52 +03:00
|
|
|
static Fl_Surface_Device *surface_stack[16];
|
|
|
|
|
|
|
|
/** Pushes \p new_current on top of the stack of current drawing surfaces, and makes it current.
|
|
|
|
\p new_current will receive all future graphics requests.
|
|
|
|
\version 1.4.0 */
|
|
|
|
void Fl_Surface_Device::push_current(Fl_Surface_Device *new_current)
|
|
|
|
{
|
|
|
|
if (surface_stack_height < sizeof(surface_stack)/sizeof(void*)) {
|
|
|
|
surface_stack[surface_stack_height++] = surface();
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "FLTK Fl_Surface_Device::push_current Stack overflow error\n");
|
|
|
|
}
|
|
|
|
new_current->set_current();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Removes the top element from the current drawing surface stack, and makes the new top element current.
|
|
|
|
\return A pointer to the new current drawing surface.
|
|
|
|
\version 1.4.0 */
|
|
|
|
Fl_Surface_Device *Fl_Surface_Device::pop_current()
|
|
|
|
{
|
|
|
|
if (surface_stack_height > 0) surface_stack[--surface_stack_height]->set_current();
|
|
|
|
return surface_;
|
|
|
|
}
|
|
|
|
|
2010-03-18 18:29:18 +03:00
|
|
|
//
|
|
|
|
// End of "$Id$".
|
|
|
|
//
|