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
|
//*****************************************************************************
//
// context.c - Routines for handling drawing contexts.
//
// 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
//! @{
//
//*****************************************************************************
#ifndef GRLIB_REMOVE_WIDE_FONT_SUPPORT
//*****************************************************************************
//
// A pointer to the application-passed structure containing default values for
// various text rendering properties.
//
//*****************************************************************************
static tGrLibDefaults const *g_psGrLibDefaults;
//
// Default text mapping functions. This table allows the use of 8 bit encoded
// source text with either Unicode encoded wide fonts or legacy fonts
// which are assumed to contain ISO8859-1 text (ASCII + western European).
//
const tCodePointMap g_psDefaultCodePointMapTable[] =
{
{CODEPAGE_ISO8859_1, CODEPAGE_UNICODE, GrMapISO8859_1_Unicode},
{CODEPAGE_ISO8859_1, CODEPAGE_ISO8859_1, GrMapISO8859_1_Unicode}
};
#define NUM_DEFAULT_CODEPOINT_MAPS (sizeof(g_psDefaultCodePointMapTable) / \
sizeof(tCodePointMap))
//*****************************************************************************
//
//! Initializes graphics library default text rendering values.
//!
//! \param pDefaults points to a structure containing default values to use.
//!
//! This function allows an application to set global default values that the
//! graphics library will use when initializing any graphics context. These
//! values set the source text codepage, the rendering function to use for
//! strings and mapping functions used to allow extraction of the correct
//! glyphs from fonts.
//!
//! If this function is not called by an application, the graphics library
//! assumes that text strings are ISO8859-1 encoded and that the default string
//! renderer is used.
//!
//! \return None.
//
//*****************************************************************************
void
GrLibInit(const tGrLibDefaults *pDefaults)
{
ASSERT(pDefaults);
//
// Remember the pointer to the defaults structure.
//
g_psGrLibDefaults = pDefaults;
}
#endif
//*****************************************************************************
//
//! Initializes a drawing context.
//!
//! \param psContext is a pointer to the drawing context to initialize.
//! \param psDisplay is a pointer to the tDisplayInfo structure that describes
//! the display driver to use.
//!
//! This function initializes a drawing context, preparing it for use. The
//! provided display driver will be used for all subsequent graphics
//! operations, and the default clipping region will be set to the extent of
//! the screen.
//!
//! \return None.
//
//*****************************************************************************
void
GrContextInit(tContext *psContext, const tDisplay *psDisplay)
{
//
// Check the arguments.
//
ASSERT(psContext);
ASSERT(psDisplay);
//
// Set the size of the context.
//
psContext->i32Size = sizeof(tContext);
//
// Save the pointer to the display.
//
psContext->psDisplay = psDisplay;
//
// Initialize the extent of the clipping region to the extents of the
// screen.
//
psContext->sClipRegion.i16XMin = 0;
psContext->sClipRegion.i16YMin = 0;
psContext->sClipRegion.i16XMax = psDisplay->ui16Width - 1;
psContext->sClipRegion.i16YMax = psDisplay->ui16Height - 1;
//
// Provide a default color and font.
//
psContext->ui32Foreground = 0;
psContext->ui32Background = 0;
psContext->psFont = 0;
#ifndef GRLIB_REMOVE_WIDE_FONT_SUPPORT
//
// Set defaults for all text rendering options.
//
if(g_psGrLibDefaults)
{
psContext->pfnStringRenderer = g_psGrLibDefaults->pfnStringRenderer;
psContext->pCodePointMapTable = g_psGrLibDefaults->pCodePointMapTable;
psContext->ui16Codepage = g_psGrLibDefaults->ui16Codepage;
psContext->ui8NumCodePointMaps = g_psGrLibDefaults->ui8NumCodePointMaps;
psContext->ui8Reserved = g_psGrLibDefaults->ui8Reserved;
}
else
{
psContext->pfnStringRenderer = GrDefaultStringRenderer;
psContext->pCodePointMapTable = g_psDefaultCodePointMapTable;
psContext->ui16Codepage = CODEPAGE_ISO8859_1;
psContext->ui8NumCodePointMaps = NUM_DEFAULT_CODEPOINT_MAPS;
psContext->ui8Reserved = 0;
}
psContext->ui8CodePointMap = 0;
#endif
}
//*****************************************************************************
//
//! Sets the extents of the clipping region.
//!
//! \param psContext is a pointer to the drawing context to use.
//! \param pRect is a pointer to the structure containing the extents of the
//! clipping region.
//!
//! This function sets the extents of the clipping region. The clipping region
//! is not allowed to exceed the extents of the screen, but may be a portion of
//! the screen.
//!
//! The supplied coordinate are inclusive; \e i16XMin of 1 and \e i16XMax of 1
//! will define a clipping region that will display only the pixels in the
//! X = 1 column. A consequence of this is that the clipping region must
//! contain at least one row and one column.
//!
//! \return None.
//
//*****************************************************************************
void
GrContextClipRegionSet(tContext *psContext, tRectangle *pRect)
{
uint32_t ui32W, ui32H;
//
// Check the arguments.
//
ASSERT(psContext);
ASSERT(pRect);
//
// Get the width and height of the display.
//
ui32W = DpyWidthGet(psContext->psDisplay);
ui32H = DpyHeightGet(psContext->psDisplay);
//
// Set the extents of the clipping region, forcing them to reside within
// the extents of the screen.
//
psContext->sClipRegion.i16XMin = ((pRect->i16XMin < 0) ? 0 :
((pRect->i16XMin >= ui32W) ? (ui32W - 1) :
pRect->i16XMin));
psContext->sClipRegion.i16YMin = ((pRect->i16YMin < 0) ? 0 :
((pRect->i16YMin >= ui32H) ? (ui32H - 1) :
pRect->i16YMin));
psContext->sClipRegion.i16XMax = ((pRect->i16XMax < 0) ? 0 :
((pRect->i16XMax >= ui32W) ? (ui32W - 1) :
pRect->i16XMax));
psContext->sClipRegion.i16YMax = ((pRect->i16YMax < 0) ? 0 :
((pRect->i16YMax >= ui32H) ? (ui32H - 1) :
pRect->i16YMax));
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
|