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
|
//*****************************************************************************
//
// rectangle.c - Routines for drawing and filling rectangles.
//
// Copyright (c) 2007-2014 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2.1.0.12573 of the Tiva Graphics Library.
//
//*****************************************************************************
#include <stdint.h>
#include <stdbool.h>
#include "driverlib/debug.h"
#include "grlib/grlib.h"
//*****************************************************************************
//
//! \addtogroup primitives_api
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
// Make sure min and max are defined.
//
//*****************************************************************************
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef max
#define max(a, b) (((a) < (b)) ? (b) : (a))
#endif
//*****************************************************************************
//
//! Draws a rectangle.
//!
//! \param pContext is a pointer to the drawing context to use.
//! \param pRect is a pointer to the structure containing the extents of the
//! rectangle.
//!
//! This function draws a rectangle. The rectangle will extend from \e i32XMin
//! to \e i32XMax and \e i32YMin to \e i32YMax, inclusive.
//!
//! \return None.
//
//*****************************************************************************
void
GrRectDraw(const tContext *pContext, const tRectangle *pRect)
{
//
// Check the arguments.
//
ASSERT(pContext);
ASSERT(pRect);
//
// Draw a line across the top of the rectangle.
//
GrLineDrawH(pContext, pRect->i16XMin, pRect->i16XMax, pRect->i16YMin);
//
// Return if the rectangle is one pixel tall.
//
if(pRect->i16YMin == pRect->i16YMax)
{
return;
}
//
// Draw a line down the right side of the rectangle.
//
GrLineDrawV(pContext, pRect->i16XMax, pRect->i16YMin + 1, pRect->i16YMax);
//
// Return if the rectangle is one pixel wide.
//
if(pRect->i16XMin == pRect->i16XMax)
{
return;
}
//
// Draw a line across the bottom of the rectangle.
//
GrLineDrawH(pContext, pRect->i16XMax - 1, pRect->i16XMin, pRect->i16YMax);
//
// Return if the rectangle is two pixels tall.
//
if((pRect->i16YMin + 1) == pRect->i16YMax)
{
return;
}
//
// Draw a line up the left side of the rectangle.
//
GrLineDrawV(pContext, pRect->i16XMin, pRect->i16YMax - 1,
pRect->i16YMin + 1);
}
//*****************************************************************************
//
//! Draws a filled rectangle.
//!
//! \param pContext is a pointer to the drawing context to use.
//! \param pRect is a pointer to the structure containing the extents of the
//! rectangle.
//!
//! This function draws a filled rectangle. The rectangle will extend from
//! \e i32XMin to \e i32XMax and \e i32YMin to \e i32YMax, inclusive. The
//! clipping of the rectangle to the clipping rectangle is performed within
//! this routine; the display driver's rectangle fill routine is used to
//! perform the actual rectangle fill.
//!
//! \return None.
//
//*****************************************************************************
void
GrRectFill(const tContext *pContext, const tRectangle *pRect)
{
tRectangle sTemp;
//
// Check the arguments.
//
ASSERT(pContext);
ASSERT(pRect);
//
// Swap the X coordinates if i16XMin is greater than i16XMax.
//
if(pRect->i16XMin > pRect->i16XMax)
{
sTemp.i16XMin = pRect->i16XMax;
sTemp.i16XMax = pRect->i16XMin;
}
else
{
sTemp.i16XMin = pRect->i16XMin;
sTemp.i16XMax = pRect->i16XMax;
}
//
// Swap the Y coordinates if i16YMin is greater than i16YMax.
//
if(pRect->i16YMin > pRect->i16YMax)
{
sTemp.i16YMin = pRect->i16YMax;
sTemp.i16YMax = pRect->i16YMin;
}
else
{
sTemp.i16YMin = pRect->i16YMin;
sTemp.i16YMax = pRect->i16YMax;
}
//
// Now that the coordinates are ordered, return without drawing anything if
// the entire rectangle is out of the clipping region.
//
if((sTemp.i16XMin > pContext->sClipRegion.i16XMax) ||
(sTemp.i16XMax < pContext->sClipRegion.i16XMin) ||
(sTemp.i16YMin > pContext->sClipRegion.i16YMax) ||
(sTemp.i16YMax < pContext->sClipRegion.i16YMin))
{
return;
}
//
// Clip the X coordinates to the edges of the clipping region if necessary.
//
if(sTemp.i16XMin < pContext->sClipRegion.i16XMin)
{
sTemp.i16XMin = pContext->sClipRegion.i16XMin;
}
if(sTemp.i16XMax > pContext->sClipRegion.i16XMax)
{
sTemp.i16XMax = pContext->sClipRegion.i16XMax;
}
//
// Clip the Y coordinates to the edges of the clipping region if necessary.
//
if(sTemp.i16YMin < pContext->sClipRegion.i16YMin)
{
sTemp.i16YMin = pContext->sClipRegion.i16YMin;
}
if(sTemp.i16YMax > pContext->sClipRegion.i16YMax)
{
sTemp.i16YMax = pContext->sClipRegion.i16YMax;
}
//
// Call the low level rectangle fill routine.
//
DpyRectFill(pContext->psDisplay, &sTemp, pContext->ui32Foreground);
}
//*****************************************************************************
//
//! Determines if two rectangles overlap.
//!
//! \param psRect1 is a pointer to the first rectangle.
//! \param psRect2 is a pointer to the second rectangle.
//!
//! This function determines whether two rectangles overlap. It assumes that
//! rectangles \e psRect1 and \e psRect2 are valid with \e i16XMin <
//! \e i16XMax and \e i16YMin < \e i16YMax.
//!
//! \return Returns 1 if there is an overlap or 0 if not.
//
//*****************************************************************************
int32_t
GrRectOverlapCheck(tRectangle *psRect1, tRectangle *psRect2)
{
if((psRect1->i16XMax < psRect2->i16XMin) ||
(psRect2->i16XMax < psRect1->i16XMin) ||
(psRect1->i16YMax < psRect2->i16YMin) ||
(psRect2->i16YMax < psRect1->i16YMin))
{
return(0);
}
else
{
return(1);
}
}
//*****************************************************************************
//
//! Determines the intersection of two rectangles.
//!
//! \param psRect1 is a pointer to the first rectangle.
//! \param psRect2 is a pointer to the second rectangle.
//! \param psIntersect is a pointer to a rectangle which will be written with
//! the intersection of \e psRect1 and \e psRect2.
//!
//! This function determines if two rectangles overlap and, if they do,
//! calculates the rectangle representing their intersection. If the rectangles
//! do not overlap, 0 is returned and \e psIntersect is not written.
//!
//! \return Returns 1 if there is an overlap or 0 if not.
//
//*****************************************************************************
int32_t
GrRectIntersectGet(tRectangle *psRect1, tRectangle *psRect2,
tRectangle *psIntersect)
{
//
// Make sure we were passed valid rectangles.
//
if((psRect1->i16XMax <= psRect1->i16XMin) ||
(psRect1->i16YMax <= psRect1->i16YMin) ||
(psRect2->i16XMax <= psRect2->i16XMin) ||
(psRect2->i16YMax <= psRect2->i16YMin))
{
return(0);
}
//
// Make sure that there is an intersection between the two rectangles.
//
if(!GrRectOverlapCheck(psRect1, psRect2))
{
return(0);
}
//
// The rectangles do intersect so determine the rectangle of the
// intersection.
//
psIntersect->i16XMin = max(psRect1->i16XMin, psRect2->i16XMin);
psIntersect->i16XMax = min(psRect1->i16XMax, psRect2->i16XMax);
psIntersect->i16YMin = max(psRect1->i16YMin, psRect2->i16YMin);
psIntersect->i16YMax = min(psRect1->i16YMax, psRect2->i16YMax);
return(1);
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
|