1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
//
// "$Id$"
//
// implementation of Fl_Graphics_Driver class for the Fast Light Tool Kit (FLTK).
//
// Copyright 2010-2016 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 to:
//
// http://www.fltk.org/str.php
//
#include <FL/Fl.H>
#include "config_lib.h"
#include <FL/Fl_Graphics_Driver.H>
#include <FL/Fl_Screen_Driver.H>
#include <FL/Fl_Image.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Image_Surface.H>
FL_EXPORT Fl_Graphics_Driver *fl_graphics_driver; // the current driver of graphics operations
const Fl_Graphics_Driver::matrix Fl_Graphics_Driver::m0 = {1, 0, 0, 1, 0, 0};
/** Constructor */
Fl_Graphics_Driver::Fl_Graphics_Driver()
{
font_ = 0;
size_ = 0;
sptr=0; rstackptr=0;
rstack[0] = NULL;
fl_clip_state_number=0;
m = m0;
fl_matrix = &m;
font_descriptor_ = NULL;
};
/** Return the graphics driver used when drawing to the platform's display */
Fl_Graphics_Driver &Fl_Graphics_Driver::default_driver()
{
static Fl_Graphics_Driver *pMainDriver = Fl_Display_Device::display_device()->driver();
return *pMainDriver;
}
/** see fl_text_extents() */
void Fl_Graphics_Driver::text_extents(const char*t, int n, int& dx, int& dy, int& w, int& h)
{
w = (int)width(t, n);
h = - height();
dx = 0;
dy = descent();
}
/** see fl_focus_rect() */
void Fl_Graphics_Driver::focus_rect(int x, int y, int w, int h)
{
line_style(FL_DOT);
rect(x, y, w, h);
line_style(FL_SOLID);
}
/** Draws an Fl_Image scaled to width \p W & height \p H with top-left corner at \em X,Y
\return zero when the graphics driver doesn't implement scaled drawing, non-zero if it does implement it.
*/
int Fl_Graphics_Driver::draw_scaled(Fl_Image *img, int X, int Y, int W, int H) {
return 0;
}
/** see fl_copy_offscreen() */
void Fl_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy)
{
// This platform-independent version can be used by any graphics driver,
// noticeably the PostScript driver.
// More efficient platform-specific implementations exist for other graphics drivers.
Fl_Image_Surface *surface = NULL;
int px_width = w, px_height = h;
Fl::screen_driver()->offscreen_size(pixmap, px_width, px_height);
int px = srcx, py = srcy, pw = w, ph = h;
if (px < 0) {px = 0; pw += srcx; x -= srcx;}
if (py < 0) {py = 0; ph += srcy; y -= srcy;}
if (px + pw > px_width) {pw = px_width - px;}
if (py + ph > px_height) {ph = px_height - py;}
Fl_Surface_Device *current = Fl_Surface_Device::surface();
fl_begin_offscreen(pixmap);
// test whether pixmap was not created by fl_create_offscreen()
if (current == Fl_Surface_Device::surface()) {
surface = new Fl_Image_Surface(px_width, px_height, 0, pixmap);
Fl_Surface_Device::push_current(surface);
}
uchar *img = fl_read_image(NULL, px, py, pw, ph, 0);
if (surface) {
Fl_Surface_Device::pop_current();
surface->get_offscreen_before_delete(); // so deleting surface does not touch pixmap
delete surface;
} else fl_end_offscreen();
if (img) {
fl_draw_image(img, x, y, pw, ph, 3, 0);
delete[] img;
}
}
/** see fl_set_spot() */
void Fl_Graphics_Driver::set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win)
{
// nothing to do, reimplement in driver if needed
}
/** see fl_reset_spot() */
void Fl_Graphics_Driver::reset_spot()
{
// nothing to do, reimplement in driver if needed
}
/** Sets the value of the fl_gc global variable when it changes */
void Fl_Graphics_Driver::global_gc()
{
// nothing to do, reimplement in driver if needed
}
/** see Fl::set_color(Fl_Color, unsigned) */
void Fl_Graphics_Driver::set_color(Fl_Color i, unsigned c)
{
// nothing to do, reimplement in driver if needed
}
/** see Fl::free_color(Fl_Color, int) */
void Fl_Graphics_Driver::free_color(Fl_Color i, int overlay)
{
// nothing to do, reimplement in driver if needed
}
/** Add a rectangle to an Fl_Region */
void Fl_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int x, int y, int w, int h)
{
// nothing to do, reimplement in driver if needed
}
/** Create a rectangular Fl_Region */
Fl_Region Fl_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h)
{
// nothing to do, reimplement in driver if needed
return 0;
}
/** Delete an Fl_Region */
void Fl_Graphics_Driver::XDestroyRegion(Fl_Region r)
{
// nothing to do, reimplement in driver if needed
}
/** Helper function for image drawing by platform-specific graphics drivers */
int Fl_Graphics_Driver::start_image(Fl_Image *img, int XP, int YP, int WP, int HP, int &cx, int &cy,
int &X, int &Y, int &W, int &H)
{
// account for current clip region (faster on Irix):
clip_box(XP,YP,WP,HP,X,Y,W,H);
cx += X-XP; cy += Y-YP;
// clip the box down to the size of image, quit if empty:
if (cx < 0) {W += cx; X -= cx; cx = 0;}
if (cx+W > img->w()) W = img->w()-cx;
if (W <= 0) return 1;
if (cy < 0) {H += cy; Y -= cy; cy = 0;}
if (cy+H > img->h()) H = img->h()-cy;
if (H <= 0) return 1;
return 0;
}
/** Support function for image drawing */
void Fl_Graphics_Driver::uncache_pixmap(fl_uintptr_t p) {
fl_delete_offscreen((Fl_Offscreen)p);
}
//
// End of "$Id$".
//
|