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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
/*
* xgc.c --
*
* This file contains generic routines for manipulating X graphics
* contexts.
*
* Copyright (c) 1995-1996 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: xgc.c,v 1.1.4.2 1999/04/06 02:48:30 redman Exp $
*/
#include <tkInt.h>
#ifdef MAC_TCL
# include <Xlib.h>
#else
# include <X11/Xlib.h>
#endif
/*
*----------------------------------------------------------------------
*
* XCreateGC --
*
* Allocate a new GC, and initialize the specified fields.
*
* Results:
* Returns a newly allocated GC.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
GC
XCreateGC(display, d, mask, values)
Display* display;
Drawable d;
unsigned long mask;
XGCValues* values;
{
GC gp;
gp = (XGCValues *)ckalloc(sizeof(XGCValues));
if (!gp) {
return None;
}
gp->function = (mask & GCFunction) ?values->function :GXcopy;
gp->plane_mask = (mask & GCPlaneMask) ?values->plane_mask :~0;
gp->foreground = (mask & GCForeground) ?values->foreground :0;
gp->background = (mask & GCBackground) ?values->background :0xffffff;
gp->line_width = (mask & GCLineWidth) ?values->line_width :0;
gp->line_style = (mask & GCLineStyle) ?values->line_style :LineSolid;
gp->cap_style = (mask & GCCapStyle) ?values->cap_style :0;
gp->join_style = (mask & GCJoinStyle) ?values->join_style :0;
gp->fill_style = (mask & GCFillStyle) ?values->fill_style :FillSolid;
gp->fill_rule = (mask & GCFillRule) ?values->fill_rule :WindingRule;
gp->arc_mode = (mask & GCArcMode) ?values->arc_mode :ArcPieSlice;
gp->tile = (mask & GCTile) ?values->tile :None;
gp->stipple = (mask & GCStipple) ?values->stipple :None;
gp->ts_x_origin = (mask & GCTileStipXOrigin) ?values->ts_x_origin:0;
gp->ts_y_origin = (mask & GCTileStipYOrigin) ?values->ts_y_origin:0;
gp->font = (mask & GCFont) ?values->font :None;
gp->subwindow_mode = (mask & GCSubwindowMode)?values->subwindow_mode:ClipByChildren;
gp->graphics_exposures = (mask & GCGraphicsExposures)?values->graphics_exposures:True;
gp->clip_x_origin = (mask & GCClipXOrigin) ?values->clip_x_origin :0;
gp->clip_y_origin = (mask & GCClipYOrigin) ?values->clip_y_origin :0;
gp->dash_offset = (mask & GCDashOffset) ?values->dash_offset :0;
gp->dashes = (mask & GCDashList) ?values->dashes :4;
if (mask & GCClipMask) {
gp->clip_mask = (Pixmap)ckalloc(sizeof(TkpClipMask));
((TkpClipMask*)gp->clip_mask)->type = TKP_CLIP_PIXMAP;
((TkpClipMask*)gp->clip_mask)->value.pixmap = values->clip_mask;
} else {
gp->clip_mask = None;
}
return gp;
}
/*
*----------------------------------------------------------------------
*
* XChangeGC --
*
* Changes the GC components specified by valuemask for the
* specified GC.
*
* Results:
* None.
*
* Side effects:
* Updates the specified GC.
*
*----------------------------------------------------------------------
*/
void
XChangeGC(d, gc, mask, values)
Display * d;
GC gc;
unsigned long mask;
XGCValues *values;
{
if (mask & GCFunction) { gc->function = values->function; }
if (mask & GCPlaneMask) { gc->plane_mask = values->plane_mask; }
if (mask & GCForeground) { gc->foreground = values->foreground; }
if (mask & GCBackground) { gc->background = values->background; }
if (mask & GCLineWidth) { gc->line_width = values->line_width; }
if (mask & GCLineStyle) { gc->line_style = values->line_style; }
if (mask & GCCapStyle) { gc->cap_style = values->cap_style; }
if (mask & GCJoinStyle) { gc->join_style = values->join_style; }
if (mask & GCFillStyle) { gc->fill_style = values->fill_style; }
if (mask & GCFillRule) { gc->fill_rule = values->fill_rule; }
if (mask & GCArcMode) { gc->arc_mode = values->arc_mode; }
if (mask & GCTile) { gc->tile = values->tile; }
if (mask & GCStipple) { gc->stipple = values->stipple; }
if (mask & GCTileStipXOrigin) { gc->ts_x_origin = values->ts_x_origin; }
if (mask & GCTileStipYOrigin) { gc->ts_y_origin = values->ts_y_origin; }
if (mask & GCFont) { gc->font = values->font; }
if (mask & GCSubwindowMode) { gc->subwindow_mode = values->subwindow_mode; }
if (mask & GCGraphicsExposures) { gc->graphics_exposures = values->graphics_exposures; }
if (mask & GCClipXOrigin) { gc->clip_x_origin = values->clip_x_origin; }
if (mask & GCClipYOrigin) { gc->clip_y_origin = values->clip_y_origin; }
if (mask & GCClipMask) { XSetClipMask(d, gc, values->clip_mask); }
if (mask & GCDashOffset) { gc->dash_offset = values->dash_offset; }
if (mask & GCDashList) { gc->dashes = values->dashes; }
}
/*
*----------------------------------------------------------------------
*
* XFreeGC --
*
* Deallocates the specified graphics context.
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void XFreeGC(d, gc)
Display * d;
GC gc;
{
if (gc != None) {
if (gc->clip_mask != None) {
ckfree((char*) gc->clip_mask);
}
ckfree((char *) gc);
}
}
/*
*----------------------------------------------------------------------
*
* XSetForeground, etc. --
*
* The following functions are simply accessor functions for
* the GC slots.
*
* Results:
* None.
*
* Side effects:
* Each function sets some slot in the GC.
*
*----------------------------------------------------------------------
*/
void
XSetForeground(display, gc, foreground)
Display *display;
GC gc;
unsigned long foreground;
{
gc->foreground = foreground;
}
void
XSetBackground(display, gc, background)
Display *display;
GC gc;
unsigned long background;
{
gc->background = background;
}
void
XSetFunction(display, gc, function)
Display *display;
GC gc;
int function;
{
gc->function = function;
}
void
XSetFillRule(display, gc, fill_rule)
Display *display;
GC gc;
int fill_rule;
{
gc->fill_rule = fill_rule;
}
void
XSetFillStyle(display, gc, fill_style)
Display *display;
GC gc;
int fill_style;
{
gc->fill_style = fill_style;
}
void
XSetTSOrigin(display, gc, x, y)
Display *display;
GC gc;
int x, y;
{
gc->ts_x_origin = x;
gc->ts_y_origin = y;
}
void
XSetFont(display, gc, font)
Display *display;
GC gc;
Font font;
{
gc->font = font;
}
void
XSetArcMode(display, gc, arc_mode)
Display *display;
GC gc;
int arc_mode;
{
gc->arc_mode = arc_mode;
}
void
XSetStipple(display, gc, stipple)
Display *display;
GC gc;
Pixmap stipple;
{
gc->stipple = stipple;
}
void
XSetLineAttributes(display, gc, line_width, line_style, cap_style,
join_style)
Display *display;
GC gc;
unsigned int line_width;
int line_style;
int cap_style;
int join_style;
{
gc->line_width = line_width;
gc->line_style = line_style;
gc->cap_style = cap_style;
gc->join_style = join_style;
}
void
XSetClipOrigin(display, gc, clip_x_origin, clip_y_origin)
Display* display;
GC gc;
int clip_x_origin;
int clip_y_origin;
{
gc->clip_x_origin = clip_x_origin;
gc->clip_y_origin = clip_y_origin;
}
/*
*----------------------------------------------------------------------
*
* TkSetRegion, XSetClipMask --
*
* Sets the clipping region/pixmap for a GC.
*
* Note that unlike the Xlib equivalent, it is not safe to delete
* the region after setting it into the GC. The only use of
* TkSetRegion is currently in ImgPhotoDisplay, which uses the GC
* immediately.
*
* Results:
* None.
*
* Side effects:
* Allocates or dealloates a TkpClipMask.
*
*----------------------------------------------------------------------
*/
void
TkSetRegion(display, gc, r)
Display* display;
GC gc;
TkRegion r;
{
if (r == None) {
if (gc->clip_mask) {
ckfree((char*) gc->clip_mask);
gc->clip_mask = None;
}
return;
}
if (gc->clip_mask == None) {
gc->clip_mask = (Pixmap)ckalloc(sizeof(TkpClipMask));
}
((TkpClipMask*)gc->clip_mask)->type = TKP_CLIP_REGION;
((TkpClipMask*)gc->clip_mask)->value.region = r;
}
void
XSetClipMask(display, gc, pixmap)
Display* display;
GC gc;
Pixmap pixmap;
{
if (pixmap == None) {
if (gc->clip_mask) {
ckfree((char*) gc->clip_mask);
gc->clip_mask = None;
}
return;
}
if (gc->clip_mask == None) {
gc->clip_mask = (Pixmap)ckalloc(sizeof(TkpClipMask));
}
((TkpClipMask*)gc->clip_mask)->type = TKP_CLIP_PIXMAP;
((TkpClipMask*)gc->clip_mask)->value.pixmap = pixmap;
}
|