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

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [engine/] [devclip2.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Copyright (c) 2000 Greg Haerr <greg@censoft.com>
3
 * Copyright (c) 1991 David I. Bell
4
 * Permission is granted to use, distribute, or modify this source,
5
 * provided that this copyright notice remains intact.
6
 *
7
 * DYNAMICREGIONS Device-independent routines to set clipping regions.
8
 */
9
#include <stdio.h>
10
#include "device.h"
11
 
12
/* Clip cache rectangle information.
13
 * After calling GdClipPoint, this rectangle is guaranteed to contain the
14
 * specified point (among others), and all points in the rectangle are
15
 * plottable or not according to the value of clipresult.
16
 */
17
MWCOORD clipminx;               /* minimum x value of cache rectangle */
18
MWCOORD clipminy;               /* minimum y value of cache rectangle */
19
MWCOORD clipmaxx;               /* maximum x value of cache rectangle */
20
MWCOORD clipmaxy;               /* maximum y value of cache rectangle */
21
 
22
static MWBOOL   clipresult;     /* whether clip rectangle is plottable */
23
MWCLIPREGION *clipregion = NULL;
24
 
25
/*
26
 * Set a clip region for future drawing actions.
27
 * Each pixel will be drawn only if lies in one or more of the contained
28
 * clip rectangles.  All clip rectangles are modified
29
 * if necessary to lie within the device area.  Call only after device
30
 * has been initialized.
31
 */
32
void
33
GdSetClipRegion(PSD psd, MWCLIPREGION *reg)
34
{
35
  if(clipregion)
36
        GdDestroyRegion(clipregion);
37
 
38
  if(!reg)
39
          reg = GdAllocRegion();
40
 
41
  clipregion = reg;
42
 
43
 
44
#if 0
45
  MWRECT        rc;
46
  /* Copy the clip table to our own static array, modifying each
47
   * rectangle as necesary to fit within the device area.  If the clip
48
   * rectangle lies entirely outside of the device area, then skip it.
49
   */
50
  while (count-- > 0) {
51
        MWCLIPRECT cr;
52
        MWCLIPRECT *rp = &cr;
53
 
54
        *rp = *table++;
55
        if (rp->x < 0) {
56
                rp->width += rp->x;
57
                rp->x = 0;
58
        }
59
        if (rp->y < 0) {
60
                rp->height += rp->y;
61
                rp->y = 0;
62
        }
63
        if ((rp->x >= psd->xvirtres) || (rp->width <= 0) ||
64
            (rp->y >= psd->yvirtres) || (rp->height <= 0))
65
                continue;
66
        if (rp->x + rp->width > psd->xvirtres)
67
                rp->width = psd->xvirtres - rp->x;
68
        if (rp->y + rp->height > psd->yvirtres)
69
                rp->height = psd->yvirtres - rp->y;
70
        rc.left = rp->x;
71
        rc.top = rp->y;
72
        rc.right = rp->x+rp->width;
73
        rc.bottom = rp->y+rp->height;
74
        GdUnionRectWithRegion(&rc, clipregion);
75
  }
76
#endif
77
 
78
  /* If there were no surviving clip rectangles, then set the clip
79
   * cache to prevent all drawing.
80
   */
81
  if (clipregion->numRects == 0) {
82
        clipminx = MIN_MWCOORD;
83
        clipminy = MIN_MWCOORD;
84
        clipmaxx = MAX_MWCOORD;
85
        clipmaxy = MAX_MWCOORD;
86
        clipresult = FALSE;
87
        return;
88
  }
89
 
90
  /* There was at least one valid clip rectangle. Default the clip
91
   * cache to be the first clip rectangle.
92
   */
93
  clipminx = clipregion->rects[0].left;
94
  clipminy = clipregion->rects[0].top;
95
  clipmaxx = clipregion->rects[0].right - 1;
96
  clipmaxy = clipregion->rects[0].bottom - 1;
97
  clipresult = TRUE;
98
}
99
 
100
 
101
/* Check a point against the list of clip rectangles.
102
 * Returns TRUE if the point is within one or more rectangles and thus
103
 * can be plotted, or FALSE if the point is not within any rectangle and
104
 * thus cannot be plotted.  Also remembers the coordinates of a clip cache
105
 * rectangle containing the specified point such that every point in the
106
 * rectangle would give the same result.  By examining this clip cache
107
 * rectangle after a call to this routine, the caller can efficiently
108
 * check many nearby points without needing any further calls.  If the
109
 * point lies within the cursor, then the cursor is removed.
110
 */
111
MWBOOL
112
GdClipPoint(PSD psd,MWCOORD x,MWCOORD y)
113
{
114
  int count;
115
  MWRECT *rp;
116
  MWCOORD temp;
117
 
118
  /* First see whether the point lies within the current clip cache
119
   * rectangle.  If so, then we already know the result.
120
   */
121
  if ((x >= clipminx) && (x <= clipmaxx) &&
122
      (y >= clipminy) && (y <= clipmaxy)) {
123
        if (clipresult) GdCheckCursor(psd, x, y, x, y);
124
        return clipresult;
125
  }
126
 
127
  /* If the point is outside of the screen area, then it is not
128
   * plottable, and the clip cache rectangle is the whole half-plane
129
   * outside of the screen area.
130
   */
131
  if (x < 0) {
132
        clipminx = MIN_MWCOORD;
133
        clipmaxx = -1;
134
        clipminy = MIN_MWCOORD;
135
        clipmaxy = MAX_MWCOORD;
136
        clipresult = FALSE;
137
        return FALSE;
138
  }
139
  if (y < 0) {
140
        clipminx = MIN_MWCOORD;
141
        clipmaxx = MAX_MWCOORD;
142
        clipminy = MIN_MWCOORD;
143
        clipmaxy = -1;
144
        clipresult = FALSE;
145
        return FALSE;
146
  }
147
  if (x >= psd->xvirtres) {
148
        clipminx = psd->xvirtres;
149
        clipmaxx = MAX_MWCOORD;
150
        clipminy = MIN_MWCOORD;
151
        clipmaxy = MAX_MWCOORD;
152
        clipresult = FALSE;
153
        return FALSE;
154
  }
155
  if (y >= psd->yvirtres) {
156
        clipminx = MIN_MWCOORD;
157
        clipmaxx = MAX_MWCOORD;
158
        clipminy = psd->yvirtres;
159
        clipmaxy = MAX_MWCOORD;
160
        clipresult = FALSE;
161
        return FALSE;
162
  }
163
 
164
  /* The point is within the screen area. If there are no clip
165
   * rectangles, then the point is plottable and the rectangle is the
166
   * whole screen.
167
   */
168
  count = clipregion->numRects;
169
  if (count <= 0) {
170
        clipminx = 0;
171
        clipmaxx = psd->xvirtres - 1;
172
        clipminy = 0;
173
        clipmaxy = psd->yvirtres - 1;
174
        clipresult = TRUE;
175
        GdCheckCursor(psd, x, y, x, y);
176
        return TRUE;
177
  }
178
 
179
  /* We need to scan the list of clip rectangles to calculate a new
180
   * clip cache rectangle containing this point, and the result. First
181
   * see if the point lies within any of the clip rectangles. If so,
182
   * then it is plottable and use that clip rectangle as the cache
183
   * rectangle.  This is not necessarily the best result, but works ok
184
   * and is fast.
185
   */
186
  for (rp = clipregion->rects; count-- > 0; rp++) {
187
        if ((x >= rp->left) && (y >= rp->top) && (x < rp->right)
188
            && (y < rp->bottom)) {
189
                clipminx = rp->left;
190
                clipminy = rp->top;
191
                clipmaxx = rp->right - 1;
192
                clipmaxy = rp->bottom - 1;
193
                clipresult = TRUE;
194
                GdCheckCursor(psd, x, y, x, y);
195
                return TRUE;
196
        }
197
  }
198
 
199
  /* The point is not plottable. Scan the clip rectangles again to
200
   * determine a rectangle containing more non-plottable points.
201
   * Simply pick the largest rectangle whose area doesn't contain any
202
   * of the same coordinates as appropriate sides of the clip
203
   * rectangles.  This is not necessarily the best result, but works ok
204
   * and is fast.
205
   */
206
  clipminx = MIN_MWCOORD;
207
  clipminy = MIN_MWCOORD;
208
  clipmaxx = MAX_MWCOORD;
209
  clipmaxy = MAX_MWCOORD;
210
  count = clipregion->numRects;
211
  for (rp = clipregion->rects; count-- > 0; rp++) {
212
        if ((x < rp->left) && (rp->left <= clipmaxx)) clipmaxx = rp->left - 1;
213
        temp = rp->right - 1;
214
        if ((x > temp) && (temp >= clipminx)) clipminx = temp + 1;
215
        if ((y < rp->top) && (rp->top <= clipmaxy)) clipmaxy = rp->top - 1;
216
        temp = rp->bottom - 1;
217
        if ((y > temp) && (temp >= clipminy)) clipminy = temp + 1;
218
  }
219
  clipresult = FALSE;
220
  return FALSE;
221
}
222
 
223
 
224
/* Check the area determined by the specified pair of points against the
225
 * list of clip rectangles.  The area will either be totally visible,
226
 * totally visible, or possibly partially visible.  This routine updates
227
 * the clip cache rectangle, and returns one of the following values:
228
 *      CLIP_VISIBLE            The whole rectangle is visible
229
 *      CLIP_INVISIBLE          The whole rectangle is invisible
230
 *      CLIP_PARTIAL            The rectangle may be partially visible
231
 * In the case that the area is totally visible, the cursor is removed
232
 * if it overlaps the clip area.
233
 */
234
int
235
GdClipArea(PSD psd,MWCOORD x1, MWCOORD y1, MWCOORD x2, MWCOORD y2)
236
{
237
  if ((x1 < clipminx) || (x1 > clipmaxx) ||
238
      (y1 < clipminy) || (y1 > clipmaxy))
239
        GdClipPoint(psd, x1, y1);
240
 
241
  if ((x2 >= clipminx) && (x2 <= clipmaxx) &&
242
      (y2 >= clipminy) && (y2 <= clipmaxy)) {
243
        if (!clipresult) return CLIP_INVISIBLE;
244
        GdCheckCursor(psd, x1, y1, x2, y2);
245
        return CLIP_VISIBLE;
246
  }
247
  return CLIP_PARTIAL;
248
}

powered by: WebSVN 2.1.0

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