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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [tix/] [unix/] [tixUnixDraw.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tixUnixDraw.c --
3
 *
4
 *      Implement the Unix specific function calls for drawing.
5
 *
6
 * Copyright (c) 1996, Expert Interface Technologies
7
 *
8
 * See the file "license.terms" for information on usage and redistribution
9
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
 *
11
 */
12
 
13
#include <tixPort.h>
14
#include <tixUnixInt.h>
15
 
16
 
17
/*
18
 *----------------------------------------------------------------------
19
 * TixpDrawTmpLine --
20
 *
21
 *      Draws a "temporary" line between the two points. The line can be
22
 *      removed by calling the function again with the same parameters.
23
 *
24
 * Results:
25
 *      Standard Tcl result.
26
 *
27
 * Side effects:
28
 *      A line is XOR'ed onto the screen.
29
 *----------------------------------------------------------------------
30
 */
31
void
32
TixpDrawTmpLine(x1, y1, x2, y2, tkwin)
33
    int x1;
34
    int y1;
35
    int x2;
36
    int y2;
37
    Tk_Window tkwin;
38
{
39
    GC gc;
40
    XGCValues values;
41
    unsigned long valuemask = GCForeground | GCSubwindowMode | GCFunction;
42
    Window winId;               /* The Window to draw into. */
43
    Tk_Window toplevel;         /* Toplevel containing the tkwin. */
44
    int rootx1, rooty1;         /* Root x and y of the toplevel window. */
45
    int rootx2, rooty2;
46
 
47
    for (toplevel=tkwin; !Tk_IsTopLevel(toplevel);
48
            toplevel=Tk_Parent(toplevel)) {
49
        ;
50
    }
51
 
52
    Tk_GetRootCoords(toplevel, &rootx1, &rooty1);
53
    rootx2 = rootx1 + Tk_Width(toplevel)  - 1;
54
    rooty2 = rooty1 + Tk_Height(toplevel) - 1;
55
 
56
    if (x1 >= rootx1 && x2 <= rootx2 && y1 >= rooty1 && y2 <= rooty2) {
57
        /*
58
         * The line is completely inside the toplevel containing
59
         * tkwin. It's better to draw into this window because on some
60
         * X servers, especially PC X Servers running on Windows,
61
         * drawing into the root window shows no effect.
62
         */
63
        winId = Tk_WindowId(toplevel);
64
        x1 -= rootx1;
65
        y1 -= rooty1;
66
        x2 -= rootx1;
67
        y2 -= rooty1;
68
    } else {
69
        winId = XRootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
70
    }
71
 
72
    values.foreground     = 0xff;
73
    values.subwindow_mode = IncludeInferiors;
74
    values.function       = GXxor;
75
 
76
    gc = XCreateGC(Tk_Display(tkwin), winId, valuemask, &values);
77
    XDrawLine(Tk_Display(tkwin), winId, gc, x1, y1, x2, y2);
78
    XFreeGC(Tk_Display(tkwin), gc);
79
}
80
 
81
/*----------------------------------------------------------------------
82
 * TixpDrawAnchorLines --
83
 *
84
 *      See comments near Tix_DrawAnchorLines.
85
 *----------------------------------------------------------------------
86
 */
87
 
88
void TixpDrawAnchorLines(display, drawable, gc, x, y, w, h)
89
    Display *display;
90
    Drawable drawable;
91
    GC gc;
92
    int x;
93
    int y;
94
    int w;
95
    int h;
96
{
97
    XPoint points[4];
98
 
99
    if (w < 1) {
100
        w = 1;
101
    }
102
    if (h < 1) {
103
        h = 1;
104
    }
105
 
106
    XDrawRectangle(display, drawable, gc, x, y, w-1, h-1);
107
 
108
    /*
109
     * Draw these points so that the corners will not be rounded
110
     */
111
    points[0].x = x;
112
    points[0].y = y;
113
    points[1].x = x + w - 1;
114
    points[1].y = y;
115
    points[2].x = x;
116
    points[2].y = y + h - 1;
117
    points[3].x = x + w - 1;
118
    points[3].y = y + h - 1;
119
 
120
    XDrawPoints(display, drawable, gc, points, 4, CoordModeOrigin);
121
}
122
 
123
/*----------------------------------------------------------------------
124
 * TixpStartSubRegionDraw --
125
 *
126
 *      Limits the subsequent drawing operations into the prescribed
127
 *      rectangle region. This takes effect up to a matching
128
 *      TixEndSubRegionDraw() call.
129
 *
130
 * Return value:
131
 *      none.
132
 *----------------------------------------------------------------------
133
 */
134
 
135
void
136
TixpStartSubRegionDraw(display, drawable, gc, subRegPtr, origX, origY,
137
        x, y, width, height, needWidth, needHeight)
138
    Display *display;
139
    Drawable drawable;
140
    GC gc;
141
    TixpSubRegion * subRegPtr;
142
    int origX;
143
    int origY;
144
    int x;
145
    int y;
146
    int width;
147
    int height;
148
    int needWidth;
149
    int needHeight;
150
{
151
    if ((width < needWidth) || (height < needHeight)) {
152
        subRegPtr->rectUsed    = 1;
153
        subRegPtr->rect.x      = (short)x;
154
        subRegPtr->rect.y      = (short)y;
155
        subRegPtr->rect.width  = (short)width;
156
        subRegPtr->rect.height = (short)height;
157
 
158
        XSetClipRectangles(display, gc, origX, origY, &subRegPtr->rect,
159
                1, Unsorted);
160
    } else {
161
        subRegPtr->rectUsed    = 0;
162
    }
163
}
164
 
165
/*----------------------------------------------------------------------
166
 * TixpEndSubRegionDraw --
167
 *
168
 *
169
 *----------------------------------------------------------------------
170
 */
171
void
172
TixpEndSubRegionDraw(display, drawable, gc, subRegPtr)
173
    Display *display;
174
    Drawable drawable;
175
    GC gc;
176
    TixpSubRegion * subRegPtr;
177
{
178
    if (subRegPtr->rectUsed) {
179
        subRegPtr->rect.x      = (short)0;
180
        subRegPtr->rect.y      = (short)0;
181
        subRegPtr->rect.width  = (short)20000;
182
        subRegPtr->rect.height = (short)20000;
183
        XSetClipRectangles(display, gc, 0, 0, &subRegPtr->rect, 1, Unsorted);
184
    }
185
}
186
 
187
/*
188
 *----------------------------------------------------------------------
189
 *
190
 * TixpSubRegDisplayText --
191
 *
192
 *      Display a text string on one or more lines in a sub region.
193
 *
194
 * Results:
195
 *      See TkDisplayText
196
 *
197
 * Side effects:
198
 *      See TkDisplayText
199
 *
200
 *----------------------------------------------------------------------
201
 */
202
 
203
void
204
TixpSubRegDisplayText(display, drawable, gc, subRegPtr, font, string,
205
        numChars, x, y, length, justify, underline)
206
    Display *display;           /* X display to use for drawing text. */
207
    Drawable drawable;          /* Window or pixmap in which to draw the
208
                                 * text. */
209
    GC gc;                      /* Graphics context to use for drawing text. */
210
    TixpSubRegion * subRegPtr;  /* Information about the subregion */
211
    TixFont font;               /* Font that determines geometry of text
212
                                 * (should be same as font in gc). */
213
    char *string;               /* String to display;  may contain embedded
214
                                 * newlines. */
215
    int numChars;               /* Number of characters to use from string. */
216
    int x, y;                   /* Pixel coordinates within drawable of
217
                                 * upper left corner of display area. */
218
    int length;                 /* Line length in pixels;  used to compute
219
                                 * word wrap points and also for
220
                                 * justification.   Must be > 0. */
221
    Tk_Justify justify;         /* How to justify lines. */
222
    int underline;              /* Index of character to underline, or < 0
223
                                 * for no underlining. */
224
{
225
    TixDisplayText(display, drawable, font, string,
226
        numChars, x, y, length, justify, underline, gc);
227
}
228
 
229
/*----------------------------------------------------------------------
230
 * TixpSubRegFillRectangle --
231
 *
232
 *
233
 *----------------------------------------------------------------------
234
 */
235
void
236
TixpSubRegFillRectangle(display, drawable, gc, subRegPtr, x, y, width, height)
237
    Display *display;           /* X display to use for drawing rectangle. */
238
    Drawable drawable;          /* Window or pixmap in which to draw the
239
                                 * rectangle. */
240
    GC gc;                      /* Graphics context to use for drawing. */
241
    TixpSubRegion * subRegPtr;  /* Information about the subregion */
242
    int x, y;                   /* Pixel coordinates within drawable of
243
                                 * upper left corner of display area. */
244
    int width, height;          /* Size of the rectangle. */
245
{
246
    XFillRectangle(display, drawable, gc, x, y, width, height);
247
}
248
 
249
/*----------------------------------------------------------------------
250
 * TixpSubRegDrawImage  --
251
 *
252
 *      Draws a Tk image in a subregion.
253
 *----------------------------------------------------------------------
254
 */
255
void
256
TixpSubRegDrawImage(subRegPtr, image, imageX, imageY, width, height,
257
        drawable, drawableX, drawableY)
258
    TixpSubRegion * subRegPtr;
259
    Tk_Image image;
260
    int imageX;
261
    int imageY;
262
    int width;
263
    int height;
264
    Drawable drawable;
265
    int drawableX;
266
    int drawableY;
267
{
268
    if (subRegPtr->rectUsed) {
269
        if (drawableX < subRegPtr->rect.x) {
270
            width  -= subRegPtr->rect.x - drawableX;
271
            imageX += subRegPtr->rect.x - drawableX;
272
            drawableX = subRegPtr->rect.x;
273
        }
274
        if (drawableX + width > subRegPtr->rect.x + subRegPtr->rect.width) {
275
            width = subRegPtr->rect.x - drawableX + subRegPtr->rect.width;
276
        }
277
 
278
        if (drawableY < subRegPtr->rect.y) {
279
            height -= subRegPtr->rect.y - drawableY;
280
            imageY += subRegPtr->rect.y - drawableY;
281
            drawableY = subRegPtr->rect.y;
282
        }
283
        if (drawableY + height > subRegPtr->rect.y + subRegPtr->rect.height) {
284
            height = subRegPtr->rect.y - drawableY + subRegPtr->rect.height;
285
        }
286
    }
287
 
288
    Tk_RedrawImage(image, imageX, imageY, width, height, drawable,
289
            drawableX, drawableY);
290
}
291
 
292
void
293
TixpSubRegDrawBitmap(display, drawable, gc, subRegPtr, bitmap, src_x, src_y,
294
        width, height, dest_x, dest_y, plane)
295
    Display *display;
296
    Drawable drawable;
297
    GC gc;
298
    TixpSubRegion * subRegPtr;
299
    Pixmap bitmap;
300
    int src_x, src_y;
301
    int width, height;
302
    int dest_x, dest_y;
303
    unsigned long plane;
304
{
305
    XCopyPlane(display, bitmap, drawable, gc, src_x, src_y, width, height,
306
            dest_x, dest_y, plane);
307
}

powered by: WebSVN 2.1.0

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