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
|
//
// "$Id: Fl_Pixmap.cxx,v 1.4 1998/10/21 14:20:16 mike Exp $"
//
// Pixmap drawing code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "fltk-bugs@easysw.com".
//
// Draws X pixmap data, keeping it stashed in a server pixmap so it
// redraws fast.
// See fl_draw_pixmap.C for code used to get the actual data into pixmap.
// Implemented without using the xpm library (which I can't use because
// it interferes with the color cube used by fl_draw_image).
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/x.H>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Menu_Item.H>
#include <FL/Fl_Pixmap.H>
extern uchar **fl_mask_bitmap; // used by fl_draw_pixmap.C to store mask
void fl_restore_clip(); // in fl_rect.C
void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
// ignore empty or bad pixmap data:
if (w<0) fl_measure_pixmap(data, w, h);
if (!w) return;
// account for current clip region (faster on Irix):
int X,Y,W,H; fl_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 > w) W = w-cx;
if (W <= 0) return;
if (cy < 0) {H += cy; Y -= cy; cy = 0;}
if (cy+H > h) H = h-cy;
if (H <= 0) return;
if (!id) {
id = (ulong)fl_create_offscreen(w, h);
fl_begin_offscreen((Fl_Offscreen)id);
#ifdef WIN32 // mask is nyi, instead use a constant color
fl_draw_pixmap(data, 0, 0, (Fl_Color)mask);
#else
uchar *bitmap = 0;
fl_mask_bitmap = &bitmap;
fl_draw_pixmap(data, 0, 0, FL_BLACK);
fl_mask_bitmap = 0;
if (bitmap) {
mask = XCreateBitmapFromData(fl_display, fl_window,
(const char*)bitmap, (w+7)&-8, h);
delete[] bitmap;
}
#endif
fl_end_offscreen();
}
#ifndef WIN32
if (mask) {
// I can't figure out how to combine a mask with existing region,
// so cut the image down to a clipped rectangle:
int nx, ny; fl_clip_box(X,Y,W,H,nx,ny,W,H);
cx += nx-X; X = nx;
cy += ny-Y; Y = ny;
// make X use the bitmap as a mask:
XSetClipMask(fl_display, fl_gc, mask);
int ox = X-cx; if (ox < 0) ox += w;
int oy = Y-cy; if (oy < 0) oy += h;
XSetClipOrigin(fl_display, fl_gc, X-cx, Y-cy);
}
#endif
fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
#ifndef WIN32
if (mask) {
// put the old clip region back
XSetClipOrigin(fl_display, fl_gc, 0, 0);
fl_restore_clip();
}
#endif
}
Fl_Pixmap::~Fl_Pixmap() {
if (id) fl_delete_offscreen((Fl_Offscreen)id);
#ifndef WIN32
if (mask) fl_delete_offscreen((Fl_Offscreen)mask);
#endif
}
static void pixmap_labeltype(
const Fl_Label* o, int x, int y, int w, int h, Fl_Align a)
{
Fl_Pixmap* b = (Fl_Pixmap*)(o->value);
if (b->w<0) fl_measure_pixmap(b->data, b->w, b->h);
int cx;
if (a & FL_ALIGN_LEFT) cx = 0;
else if (a & FL_ALIGN_RIGHT) cx = b->w-w;
else cx = (b->w-w)/2;
int cy;
if (a & FL_ALIGN_TOP) cy = 0;
else if (a & FL_ALIGN_BOTTOM) cy = b->h-h;
else cy = (b->h-h)/2;
b->draw(x,y,w,h,cx,cy);
}
static void pixmap_measure(const Fl_Label* o, int& w, int& h) {
Fl_Pixmap* b = (Fl_Pixmap*)(o->value);
if (b->w<0) fl_measure_pixmap(b->data, b->w, b->h);
w = b->w;
h = b->h;
}
void Fl_Pixmap::label(Fl_Widget* o) {
#ifdef WIN32
mask = o->color();
#endif
Fl::set_labeltype(_FL_PIXMAP_LABEL, pixmap_labeltype, pixmap_measure);
o->label(_FL_PIXMAP_LABEL, (const char*)this);
}
void Fl_Pixmap::label(Fl_Menu_Item* o) {
Fl::set_labeltype(_FL_PIXMAP_LABEL, pixmap_labeltype, pixmap_measure);
o->label(_FL_PIXMAP_LABEL, (const char*)this);
}
//
// End of "$Id: Fl_Pixmap.cxx,v 1.4 1998/10/21 14:20:16 mike Exp $".
//
|