OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tk/] [xlib/] [xgc.c] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * xgc.c --
3
 *
4
 *      This file contains generic routines for manipulating X graphics
5
 *      contexts.
6
 *
7
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
8
 *
9
 * See the file "license.terms" for information on usage and redistribution
10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
 *
12
 * RCS: @(#) $Id: xgc.c,v 1.1.1.1 2002-01-16 10:26:04 markom Exp $
13
 */
14
 
15
#include <tkInt.h>
16
 
17
#ifdef MAC_TCL
18
#       include <Xlib.h>
19
#else
20
#       include <X11/Xlib.h>
21
#endif
22
 
23
 
24
/*
25
 *----------------------------------------------------------------------
26
 *
27
 * XCreateGC --
28
 *
29
 *      Allocate a new GC, and initialize the specified fields.
30
 *
31
 * Results:
32
 *      Returns a newly allocated GC.
33
 *
34
 * Side effects:
35
 *      None.
36
 *
37
 *----------------------------------------------------------------------
38
 */
39
 
40
GC
41
XCreateGC(display, d, mask, values)
42
    Display* display;
43
    Drawable d;
44
    unsigned long mask;
45
    XGCValues* values;
46
{
47
    GC gp;
48
 
49
    gp = (XGCValues *)ckalloc(sizeof(XGCValues));
50
    if (!gp) {
51
        return None;
52
    }
53
 
54
    gp->function =      (mask & GCFunction)     ?values->function       :GXcopy;
55
    gp->plane_mask =    (mask & GCPlaneMask)    ?values->plane_mask     :~0;
56
    gp->foreground =    (mask & GCForeground)   ?values->foreground     :0;
57
    gp->background =    (mask & GCBackground)   ?values->background     :0xffffff;
58
    gp->line_width =    (mask & GCLineWidth)    ?values->line_width     :0;
59
    gp->line_style =    (mask & GCLineStyle)    ?values->line_style     :LineSolid;
60
    gp->cap_style =     (mask & GCCapStyle)     ?values->cap_style      :0;
61
    gp->join_style =    (mask & GCJoinStyle)    ?values->join_style     :0;
62
    gp->fill_style =    (mask & GCFillStyle)    ?values->fill_style     :FillSolid;
63
    gp->fill_rule =     (mask & GCFillRule)     ?values->fill_rule      :WindingRule;
64
    gp->arc_mode =      (mask & GCArcMode)      ?values->arc_mode       :ArcPieSlice;
65
    gp->tile =          (mask & GCTile)         ?values->tile           :None;
66
    gp->stipple =       (mask & GCStipple)      ?values->stipple        :None;
67
    gp->ts_x_origin =   (mask & GCTileStipXOrigin)      ?values->ts_x_origin:0;
68
    gp->ts_y_origin =   (mask & GCTileStipYOrigin)      ?values->ts_y_origin:0;
69
    gp->font =          (mask & GCFont)         ?values->font           :None;
70
    gp->subwindow_mode = (mask & GCSubwindowMode)?values->subwindow_mode:ClipByChildren;
71
    gp->graphics_exposures = (mask & GCGraphicsExposures)?values->graphics_exposures:True;
72
    gp->clip_x_origin = (mask & GCClipXOrigin)  ?values->clip_x_origin  :0;
73
    gp->clip_y_origin = (mask & GCClipYOrigin)  ?values->clip_y_origin  :0;
74
    gp->dash_offset =   (mask & GCDashOffset)   ?values->dash_offset    :0;
75
    gp->dashes =        (mask & GCDashList)     ?values->dashes         :4;
76
 
77
    if (mask & GCClipMask) {
78
        gp->clip_mask = (Pixmap)ckalloc(sizeof(TkpClipMask));
79
        ((TkpClipMask*)gp->clip_mask)->type = TKP_CLIP_PIXMAP;
80
        ((TkpClipMask*)gp->clip_mask)->value.pixmap = values->clip_mask;
81
    } else {
82
        gp->clip_mask = None;
83
    }
84
 
85
    return gp;
86
}
87
 
88
/*
89
 *----------------------------------------------------------------------
90
 *
91
 * XChangeGC --
92
 *
93
 *      Changes the GC components specified by valuemask for the
94
 *      specified GC.
95
 *
96
 * Results:
97
 *      None.
98
 *
99
 * Side effects:
100
 *      Updates the specified GC.
101
 *
102
 *----------------------------------------------------------------------
103
 */
104
 
105
void
106
XChangeGC(d, gc, mask, values)
107
    Display * d;
108
    GC gc;
109
    unsigned long mask;
110
    XGCValues *values;
111
{
112
    if (mask & GCFunction) { gc->function = values->function; }
113
    if (mask & GCPlaneMask) { gc->plane_mask = values->plane_mask; }
114
    if (mask & GCForeground) { gc->foreground = values->foreground; }
115
    if (mask & GCBackground) { gc->background = values->background; }
116
    if (mask & GCLineWidth) { gc->line_width = values->line_width; }
117
    if (mask & GCLineStyle) { gc->line_style = values->line_style; }
118
    if (mask & GCCapStyle) { gc->cap_style = values->cap_style; }
119
    if (mask & GCJoinStyle) { gc->join_style = values->join_style; }
120
    if (mask & GCFillStyle) { gc->fill_style = values->fill_style; }
121
    if (mask & GCFillRule) { gc->fill_rule = values->fill_rule; }
122
    if (mask & GCArcMode) { gc->arc_mode = values->arc_mode; }
123
    if (mask & GCTile) { gc->tile = values->tile; }
124
    if (mask & GCStipple) { gc->stipple = values->stipple; }
125
    if (mask & GCTileStipXOrigin) { gc->ts_x_origin = values->ts_x_origin; }
126
    if (mask & GCTileStipYOrigin) { gc->ts_y_origin = values->ts_y_origin; }
127
    if (mask & GCFont) { gc->font = values->font; }
128
    if (mask & GCSubwindowMode) { gc->subwindow_mode = values->subwindow_mode; }
129
    if (mask & GCGraphicsExposures) { gc->graphics_exposures = values->graphics_exposures; }
130
    if (mask & GCClipXOrigin) { gc->clip_x_origin = values->clip_x_origin; }
131
    if (mask & GCClipYOrigin) { gc->clip_y_origin = values->clip_y_origin; }
132
    if (mask & GCClipMask) { XSetClipMask(d, gc, values->clip_mask); }
133
    if (mask & GCDashOffset) { gc->dash_offset = values->dash_offset; }
134
    if (mask & GCDashList) { gc->dashes = values->dashes; }
135
}
136
 
137
/*
138
 *----------------------------------------------------------------------
139
 *
140
 * XFreeGC --
141
 *
142
 *      Deallocates the specified graphics context.
143
 *
144
 * Results:
145
 *      None.
146
 *
147
 * Side effects:
148
 *      None.
149
 *
150
 *----------------------------------------------------------------------
151
 */
152
 
153
void
154
XFreeGC(d, gc)
155
    Display * d;
156
    GC gc;
157
{
158
    if (gc != None) {
159
        if (gc->clip_mask != None) {
160
            ckfree((char*) gc->clip_mask);
161
        }
162
        ckfree((char *) gc);
163
    }
164
}
165
 
166
/*
167
 *----------------------------------------------------------------------
168
 *
169
 * XSetForeground, etc. --
170
 *
171
 *      The following functions are simply accessor functions for
172
 *      the GC slots.
173
 *
174
 * Results:
175
 *      None.
176
 *
177
 * Side effects:
178
 *      Each function sets some slot in the GC.
179
 *
180
 *----------------------------------------------------------------------
181
 */
182
 
183
void
184
XSetForeground(display, gc, foreground)
185
    Display *display;
186
    GC gc;
187
    unsigned long foreground;
188
{
189
    gc->foreground = foreground;
190
}
191
 
192
void
193
XSetBackground(display, gc, background)
194
    Display *display;
195
    GC gc;
196
    unsigned long background;
197
{
198
    gc->background = background;
199
}
200
 
201
void
202
XSetFunction(display, gc, function)
203
    Display *display;
204
    GC gc;
205
    int function;
206
{
207
    gc->function = function;
208
}
209
 
210
void
211
XSetFillRule(display, gc, fill_rule)
212
    Display *display;
213
    GC gc;
214
    int fill_rule;
215
{
216
    gc->fill_rule = fill_rule;
217
}
218
 
219
void
220
XSetFillStyle(display, gc, fill_style)
221
    Display *display;
222
    GC gc;
223
    int fill_style;
224
{
225
    gc->fill_style = fill_style;
226
}
227
 
228
void
229
XSetTSOrigin(display, gc, x, y)
230
    Display *display;
231
    GC gc;
232
    int x, y;
233
{
234
    gc->ts_x_origin = x;
235
    gc->ts_y_origin = y;
236
}
237
 
238
void
239
XSetFont(display, gc, font)
240
    Display *display;
241
    GC gc;
242
    Font font;
243
{
244
    gc->font = font;
245
}
246
 
247
void
248
XSetArcMode(display, gc, arc_mode)
249
    Display *display;
250
    GC gc;
251
    int arc_mode;
252
{
253
    gc->arc_mode = arc_mode;
254
}
255
 
256
void
257
XSetStipple(display, gc, stipple)
258
    Display *display;
259
    GC gc;
260
    Pixmap stipple;
261
{
262
    gc->stipple = stipple;
263
}
264
 
265
void
266
XSetLineAttributes(display, gc, line_width, line_style, cap_style,
267
        join_style)
268
    Display *display;
269
    GC gc;
270
    unsigned int line_width;
271
    int line_style;
272
    int cap_style;
273
    int join_style;
274
{
275
    gc->line_width = line_width;
276
    gc->line_style = line_style;
277
    gc->cap_style = cap_style;
278
    gc->join_style = join_style;
279
}
280
 
281
void
282
XSetClipOrigin(display, gc, clip_x_origin, clip_y_origin)
283
    Display* display;
284
    GC gc;
285
    int clip_x_origin;
286
    int clip_y_origin;
287
{
288
    gc->clip_x_origin = clip_x_origin;
289
    gc->clip_y_origin = clip_y_origin;
290
}
291
 
292
/*
293
 *----------------------------------------------------------------------
294
 *
295
 * TkSetRegion, XSetClipMask --
296
 *
297
 *      Sets the clipping region/pixmap for a GC.
298
 *
299
 *      Note that unlike the Xlib equivalent, it is not safe to delete
300
 *      the region after setting it into the GC.  The only use of
301
 *      TkSetRegion is currently in ImgPhotoDisplay, which uses the GC
302
 *      immediately.
303
 *
304
 * Results:
305
 *      None.
306
 *
307
 * Side effects:
308
 *      Allocates or dealloates a TkpClipMask.
309
 *
310
 *----------------------------------------------------------------------
311
 */
312
 
313
void
314
TkSetRegion(display, gc, r)
315
    Display* display;
316
    GC gc;
317
    TkRegion r;
318
{
319
    if (r == None) {
320
        if (gc->clip_mask) {
321
            ckfree((char*) gc->clip_mask);
322
            gc->clip_mask = None;
323
        }
324
        return;
325
    }
326
 
327
    if (gc->clip_mask == None) {
328
        gc->clip_mask = (Pixmap)ckalloc(sizeof(TkpClipMask));
329
    }
330
    ((TkpClipMask*)gc->clip_mask)->type = TKP_CLIP_REGION;
331
    ((TkpClipMask*)gc->clip_mask)->value.region = r;
332
}
333
 
334
void
335
XSetClipMask(display, gc, pixmap)
336
    Display* display;
337
    GC gc;
338
    Pixmap pixmap;
339
{
340
    if (pixmap == None) {
341
        if (gc->clip_mask) {
342
            ckfree((char*) gc->clip_mask);
343
            gc->clip_mask = None;
344
        }
345
        return;
346
    }
347
 
348
    if (gc->clip_mask == None) {
349
        gc->clip_mask = (Pixmap)ckalloc(sizeof(TkpClipMask));
350
    }
351
    ((TkpClipMask*)gc->clip_mask)->type = TKP_CLIP_PIXMAP;
352
    ((TkpClipMask*)gc->clip_mask)->value.pixmap = pixmap;
353
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.