?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik /*****************************************************************************
2 * Module for Microchip Graphics Library
3 * GOL Layer
4 * Static Text
5 *****************************************************************************
6 * FileName: StaticText.c
7 * Dependencies: None
8 * Processor: PIC24F, PIC24H, dsPIC, PIC32
9 * Compiler: MPLAB C30 V3.00, MPLAB C32
10 * Linker: MPLAB LINK30, MPLAB LINK32
11 * Company: Microchip Technology Incorporated
12 *
13 * Software License Agreement
14 *
15 * Copyright © 2008 Microchip Technology Inc. All rights reserved.
16 * Microchip licenses to you the right to use, modify, copy and distribute
17 * Software only when embedded on a Microchip microcontroller or digital
18 * signal controller, which is integrated into your product or third party
19 * product (pursuant to the sublicense terms in the accompanying license
20 * agreement).
21 *
22 * You should refer to the license agreement accompanying this Software
23 * for additional information regarding your rights and obligations.
24 *
25 * SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY
26 * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY
27 * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR
28 * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR
29 * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION,
30 * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT
31 * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL,
32 * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
33 * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY
34 * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
35 * OR OTHER SIMILAR COSTS.
36 *
37 * Author Date Comment
38 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39 * PAT 11/12/07 Version 1.0 release
40 * PAT 11/12/07 Fixed clipping enabling location
41 *****************************************************************************/
42 #include "Graphics\Graphics.h"
43  
44 #ifdef USE_STATICTEXT
45  
46 /*********************************************************************
47 * Function: STATICTEXT *StCreate(WORD ID, SHORT left, SHORT top, SHORT right, SHORT bottom,
48 * WORD state , XCHAR *pText, GOL_SCHEME *pScheme)
49 *
50 * Notes: Creates a STATICTEXT object and adds it to the current active list.
51 * If the creation is successful, the pointer to the created Object
52 * is returned. If not successful, NULL is returned.
53 *
54 ********************************************************************/
55 STATICTEXT *StCreate
56 (
57 WORD ID,
58 SHORT left,
59 SHORT top,
60 SHORT right,
61 SHORT bottom,
62 WORD state,
63 XCHAR *pText,
64 GOL_SCHEME *pScheme
65 )
66 {
67 STATICTEXT *pSt = NULL;
68  
69 pSt = (STATICTEXT *)GFX_malloc(sizeof(STATICTEXT));
70 if(pSt == NULL)
71 return (pSt);
72  
73 pSt->hdr.ID = ID; // unique id assigned for referencing
74 pSt->hdr.pNxtObj = NULL; // initialize pointer to NULL
75 pSt->hdr.type = OBJ_STATICTEXT; // set object type
76 pSt->hdr.left = left; // left,top corner
77 pSt->hdr.top = top;
78 pSt->hdr.right = right; // right buttom corner
79 pSt->hdr.bottom = bottom;
80 pSt->pText = pText; // location of the text
81 pSt->hdr.state = state;
82  
83 // Set the color scheme to be used
84 if(pScheme == NULL)
85 pSt->hdr.pGolScheme = _pDefaultGolScheme;
86 else
87 pSt->hdr.pGolScheme = (GOL_SCHEME *)pScheme;
88  
89 pSt->textHeight = 0;
90 if(pSt->pText != NULL)
91 {
92  
93 // Set the text height
94 pSt->textHeight = GetTextHeight(pSt->hdr.pGolScheme->pFont);
95 }
96  
97 GOLAddObject((OBJ_HEADER *)pSt);
98 return (pSt);
99 }
100  
101 /*********************************************************************
102 * Function: StSetText(STATICTEXT *pSt, XCHAR *pText)
103 *
104 * Notes: Sets the string that will be used.
105 *
106 ********************************************************************/
107 void StSetText(STATICTEXT *pSt, XCHAR *pText)
108 {
109 pSt->pText = pText;
110 pSt->textHeight = GetTextHeight(pSt->hdr.pGolScheme->pFont);
111 }
112  
113 /*********************************************************************
114 * Function: WORD StTranslateMsg(STATICTEXT *pSt, GOL_MSG *pMsg)
115 *
116 * Notes: Evaluates the message if the object will be affected by the
117 * message or not.
118 *
119 ********************************************************************/
120 WORD StTranslateMsg(STATICTEXT *pSt, GOL_MSG *pMsg)
121 {
122  
123 // Evaluate if the message is for the static text
124 // Check if disabled first
125 if(GetState(pSt, ST_DISABLED))
126 return (OBJ_MSG_INVALID);
127  
128 #ifdef USE_TOUCHSCREEN
129 if(pMsg->type == TYPE_TOUCHSCREEN)
130 {
131  
132 // Check if it falls in static text control borders
133 if
134 (
135 (pSt->hdr.left < pMsg->param1) &&
136 (pSt->hdr.right > pMsg->param1) &&
137 (pSt->hdr.top < pMsg->param2) &&
138 (pSt->hdr.bottom > pMsg->param2)
139 )
140 {
141 return (ST_MSG_SELECTED);
142 }
143 }
144  
145 #endif
146 return (OBJ_MSG_INVALID);
147 }
148  
149 /*********************************************************************
150 * Function: WORD StDraw(STATICTEXT *pSt)
151 *
152 * Notes: This is the state machine to draw the static text.
153 *
154 ********************************************************************/
155 WORD StDraw(STATICTEXT *pSt)
156 {
157 typedef enum
158 {
159 ST_STATE_IDLE,
160 ST_STATE_CLEANAREA,
161 ST_STATE_INIT,
162 ST_STATE_SETALIGN,
163 ST_STATE_DRAWTEXT
164 } ST_DRAW_STATES;
165  
166 static ST_DRAW_STATES state = ST_STATE_IDLE;
167 static SHORT charCtr = 0, lineCtr = 0;
168 static XCHAR *pCurLine = NULL;
169 SHORT textWidth;
170 XCHAR ch = 0;
171  
172 if(IsDeviceBusy())
173 return (0);
174  
175 switch(state)
176 {
177 case ST_STATE_IDLE:
178 SetClip(CLIP_DISABLE);
179  
180 if(GetState(pSt, ST_HIDE))
181 {
182 SetColor(pSt->hdr.pGolScheme->CommonBkColor);
183 if(!Bar(pSt->hdr.left, pSt->hdr.top, pSt->hdr.right, pSt->hdr.bottom))
184 return (0);
185  
186 // State is still IDLE STATE so no need to set
187 return (1);
188 }
189  
190 if(GetState(pSt, ST_DRAW))
191 {
192 // show frame if specified to be shown
193 SetLineType(SOLID_LINE);
194 SetLineThickness(NORMAL_LINE);
195  
196 if(GetState(pSt, ST_FRAME))
197 {
198  
199 if(!GetState(pSt, ST_DISABLED))
200 {
201  
202 // show enabled color
203 SetColor(pSt->hdr.pGolScheme->Color1);
204 if(!Rectangle(pSt->hdr.left, pSt->hdr.top, pSt->hdr.right, pSt->hdr.bottom))
205 return (0);
206 }
207 else
208 {
209  
210 // show disabled color
211 SetColor(pSt->hdr.pGolScheme->ColorDisabled);
212 if(!Rectangle(pSt->hdr.left, pSt->hdr.top, pSt->hdr.right, pSt->hdr.bottom))
213 return (0);
214 }
215 }
216 else
217 {
218 // show enabled color
219 SetColor(pSt->hdr.pGolScheme->CommonBkColor);
220 if(!Rectangle(pSt->hdr.left, pSt->hdr.top, pSt->hdr.right, pSt->hdr.bottom))
221 return (0);
222  
223 }
224 }
225  
226 state = ST_STATE_CLEANAREA;
227  
228 case ST_STATE_CLEANAREA:
229  
230 // clean area where text will be placed.
231 SetColor(pSt->hdr.pGolScheme->CommonBkColor);
232 if(!Bar(pSt->hdr.left + 1, pSt->hdr.top + 1, pSt->hdr.right - 1, pSt->hdr.bottom - 1))
233 return (0);
234  
235 // set clipping area, text will only appear inside the static text area.
236 SetClip(CLIP_ENABLE);
237 SetClipRgn(pSt->hdr.left + ST_INDENT, pSt->hdr.top, pSt->hdr.right - ST_INDENT, pSt->hdr.bottom);
238 state = ST_STATE_INIT;
239  
240 case ST_STATE_INIT:
241 if(IsDeviceBusy())
242 return (0);
243  
244 // set the text color
245 if(!GetState(pSt, ST_DISABLED))
246 {
247 SetColor(pSt->hdr.pGolScheme->TextColor0);
248 }
249 else
250 {
251 SetColor(pSt->hdr.pGolScheme->TextColorDisabled);
252 }
253  
254 // use the font specified in the object
255 SetFont(pSt->hdr.pGolScheme->pFont);
256 pCurLine = pSt->pText; // get first line of text
257 state = ST_STATE_SETALIGN; // go to drawing of text
258  
259 case ST_STATE_SETALIGN:
260 st_state_alignment : if(!charCtr)
261 {
262  
263 // set position of the next character (based on alignment and next character)
264 textWidth = GetTextWidth(pCurLine, pSt->hdr.pGolScheme->pFont);
265  
266 // Display text with center alignment
267 if(GetState(pSt, (ST_CENTER_ALIGN)))
268 {
269 MoveTo((pSt->hdr.left + pSt->hdr.right - textWidth) >> 1, pSt->hdr.top + (lineCtr * pSt->textHeight));
270 }
271  
272 // Display text with right alignment
273 else if(GetState(pSt, (ST_RIGHT_ALIGN)))
274 {
275 MoveTo((pSt->hdr.right - textWidth - ST_INDENT), pSt->hdr.top + (lineCtr * pSt->textHeight));
276 }
277  
278 // Display text with left alignment
279 else
280 {
281 MoveTo(pSt->hdr.left + ST_INDENT, pSt->hdr.top + (lineCtr * pSt->textHeight));
282 }
283 }
284  
285 state = ST_STATE_DRAWTEXT;
286  
287 case ST_STATE_DRAWTEXT:
288 ch = *(pCurLine + charCtr);
289  
290 // output one character at time until a newline character or a NULL character is sampled
291 while((0x0000 != ch) && (0x000A != ch))
292 {
293 if(!OutChar(ch))
294 return (0); // render the character
295 charCtr++; // update to next character
296 ch = *(pCurLine + charCtr);
297 }
298  
299 // pCurText is updated for the next line
300 if(ch == 0x000A)
301 { // new line character
302 pCurLine = pCurLine + charCtr + 1; // go to first char of next line
303 lineCtr++; // update line counter
304 charCtr = 0; // reset char counter
305 goto st_state_alignment; // continue to next line
306 }
307  
308 // end of text string is reached no more lines to display
309 else
310 {
311 pCurLine = NULL; // reset static variables
312 lineCtr = 0;
313 charCtr = 0;
314 SetClip(CLIP_DISABLE); // remove clipping
315 state = ST_STATE_IDLE; // go back to IDLE state
316 return (1);
317 }
318 }
319  
320 return (1);
321 }
322  
323 #endif // USE_STATICTEXT
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3