Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /***************************************************************************** |
2 | * Module for Microchip Graphics Library |
||
3 | * GOL Layer |
||
4 | * Check Box |
||
5 | ***************************************************************************** |
||
6 | * FileName: CheckBox.c |
||
7 | * Dependencies: None |
||
8 | * Processor: PIC24F, PIC24H, dsPIC, PIC32 |
||
9 | * Compiler: MPLAB C30 V3.00, C32 |
||
10 | * Linker: MPLAB LINK30, 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 | * Anton Alkhimenok 11/12/07 Version 1.0 release |
||
40 | *****************************************************************************/ |
||
41 | #include "Graphics\Graphics.h" |
||
42 | |||
43 | #ifdef USE_CHECKBOX |
||
44 | |||
45 | /********************************************************************* |
||
46 | * Function: CHECKBOX *CbCreate(WORD ID, SHORT left, SHORT top, SHORT right, |
||
47 | * SHORT bottom, WORD state, XCHAR *pText, |
||
48 | * GOL_SCHEME *pScheme) |
||
49 | * |
||
50 | * Overview: Creates the check box. |
||
51 | * |
||
52 | ********************************************************************/ |
||
53 | CHECKBOX *CbCreate |
||
54 | ( |
||
55 | WORD ID, |
||
56 | SHORT left, |
||
57 | SHORT top, |
||
58 | SHORT right, |
||
59 | SHORT bottom, |
||
60 | WORD state, |
||
61 | XCHAR *pText, |
||
62 | GOL_SCHEME *pScheme |
||
63 | ) |
||
64 | { |
||
65 | CHECKBOX *pCb = NULL; |
||
66 | |||
67 | pCb = (CHECKBOX *)GFX_malloc(sizeof(CHECKBOX)); |
||
68 | if(pCb == NULL) |
||
69 | return (pCb); |
||
70 | |||
71 | pCb->hdr.ID = ID; |
||
72 | pCb->hdr.pNxtObj = NULL; |
||
73 | pCb->hdr.type = OBJ_CHECKBOX; |
||
74 | pCb->hdr.left = left; |
||
75 | pCb->hdr.top = top; |
||
76 | pCb->hdr.right = right; |
||
77 | pCb->hdr.bottom = bottom; |
||
78 | pCb->pText = pText; |
||
79 | pCb->hdr.state = state; |
||
80 | |||
81 | // Set the style scheme |
||
82 | if(pScheme == NULL) |
||
83 | pCb->hdr.pGolScheme = _pDefaultGolScheme; |
||
84 | else |
||
85 | pCb->hdr.pGolScheme = (GOL_SCHEME *)pScheme; |
||
86 | |||
87 | // Set the text height |
||
88 | pCb->textHeight = 0; |
||
89 | if(pText != NULL) |
||
90 | { |
||
91 | pCb->textHeight = GetTextHeight(pCb->hdr.pGolScheme->pFont); |
||
92 | } |
||
93 | |||
94 | GOLAddObject((OBJ_HEADER *)pCb); |
||
95 | |||
96 | return (pCb); |
||
97 | } |
||
98 | |||
99 | /********************************************************************* |
||
100 | * Function: CbSetText(CHECKBOX *pCb, char *pText) |
||
101 | * |
||
102 | * Overview: Sets the text. |
||
103 | * |
||
104 | ********************************************************************/ |
||
105 | void CbSetText(CHECKBOX *pCb, XCHAR *pText) |
||
106 | { |
||
107 | pCb->pText = pText; |
||
108 | pCb->textHeight = GetTextHeight((BYTE *)pCb->hdr.pGolScheme->pFont); |
||
109 | } |
||
110 | |||
111 | /********************************************************************* |
||
112 | * Function: CbMsgDefault(WORD translatedMsg, CHECKBOX *pCb, GOL_MSG* pMsg) |
||
113 | * |
||
114 | * Overview: Changes the state of the check box by default. |
||
115 | * |
||
116 | ********************************************************************/ |
||
117 | void CbMsgDefault(WORD translatedMsg, CHECKBOX *pCb, GOL_MSG *pMsg) |
||
118 | { |
||
119 | #ifdef USE_FOCUS |
||
120 | #ifdef USE_TOUCHSCREEN |
||
121 | if(pMsg->type == TYPE_TOUCHSCREEN) |
||
122 | { |
||
123 | if(!GetState(pCb, CB_FOCUSED)) |
||
124 | { |
||
125 | GOLSetFocus((OBJ_HEADER *)pCb); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | #endif |
||
130 | #endif |
||
131 | switch(translatedMsg) |
||
132 | { |
||
133 | case CB_MSG_CHECKED: |
||
134 | SetState(pCb, CB_CHECKED | CB_DRAW_CHECK); // Set checked and redraw |
||
135 | break; |
||
136 | |||
137 | case CB_MSG_UNCHECKED: |
||
138 | ClrState(pCb, CB_CHECKED); // Reset check |
||
139 | SetState(pCb, CB_DRAW_CHECK); // Redraw |
||
140 | break; |
||
141 | } |
||
142 | } |
||
143 | |||
144 | /********************************************************************* |
||
145 | * Function: WORD CbTranslateMsg(CHECKBOX *pCb, GOL_MSG *pMsg) |
||
146 | * |
||
147 | * Overview: Checks if the check box will be affected by the message |
||
148 | * and returns translated message. |
||
149 | * |
||
150 | ********************************************************************/ |
||
151 | WORD CbTranslateMsg(CHECKBOX *pCb, GOL_MSG *pMsg) |
||
152 | { |
||
153 | |||
154 | // Evaluate if the message is for the check box |
||
155 | // Check if disabled first |
||
156 | if(GetState(pCb, CB_DISABLED)) |
||
157 | return (OBJ_MSG_INVALID); |
||
158 | |||
159 | #ifdef USE_TOUCHSCREEN |
||
160 | if(pMsg->type == TYPE_TOUCHSCREEN) |
||
161 | { |
||
162 | |||
163 | // Check if it falls in the check box borders |
||
164 | if |
||
165 | ( |
||
166 | (pCb->hdr.left < pMsg->param1) && |
||
167 | (pCb->hdr.right > pMsg->param1) && |
||
168 | (pCb->hdr.top < pMsg->param2) && |
||
169 | (pCb->hdr.bottom > pMsg->param2) |
||
170 | ) |
||
171 | { |
||
172 | if(pMsg->uiEvent == EVENT_PRESS) |
||
173 | { |
||
174 | if(GetState(pCb, CB_CHECKED)) |
||
175 | return (CB_MSG_UNCHECKED); |
||
176 | else |
||
177 | return (CB_MSG_CHECKED); |
||
178 | } |
||
179 | } |
||
180 | |||
181 | return (OBJ_MSG_INVALID); |
||
182 | } |
||
183 | |||
184 | #endif |
||
185 | #ifdef USE_KEYBOARD |
||
186 | if(pMsg->type == TYPE_KEYBOARD) |
||
187 | { |
||
188 | if(pMsg->param1 == pCb->hdr.ID) |
||
189 | { |
||
190 | if(pMsg->uiEvent == EVENT_KEYSCAN) |
||
191 | { |
||
192 | if((pMsg->param2 == SCAN_SPACE_PRESSED) || (pMsg->param2 == SCAN_CR_PRESSED)) |
||
193 | { |
||
194 | if(GetState(pCb, CB_CHECKED)) |
||
195 | return (CB_MSG_UNCHECKED); |
||
196 | else |
||
197 | return (CB_MSG_CHECKED); |
||
198 | } |
||
199 | } |
||
200 | } |
||
201 | |||
202 | return (OBJ_MSG_INVALID); |
||
203 | } |
||
204 | |||
205 | #endif |
||
206 | return (OBJ_MSG_INVALID); |
||
207 | } |
||
208 | |||
209 | /********************************************************************* |
||
210 | * Function: WORD CbDraw(CHECKBOX *pCb) |
||
211 | * |
||
212 | * Output: returns the status of the drawing |
||
213 | * 0 - not complete |
||
214 | * 1 - done |
||
215 | * |
||
216 | * Overview: Draws check box. |
||
217 | * |
||
218 | ********************************************************************/ |
||
219 | WORD CbDraw(CHECKBOX *pCb) |
||
220 | { |
||
221 | typedef enum |
||
222 | { |
||
223 | REMOVE, |
||
224 | BOX_DRAW, |
||
225 | RUN_DRAW, |
||
226 | TEXT_DRAW, |
||
227 | TEXT_DRAW_RUN, |
||
228 | CHECK_DRAW, |
||
229 | FOCUS_DRAW |
||
230 | } CB_DRAW_STATES; |
||
231 | |||
232 | static CB_DRAW_STATES state = REMOVE; |
||
233 | |||
234 | SHORT checkIndent; |
||
235 | |||
236 | if(IsDeviceBusy()) |
||
237 | return (0); |
||
238 | |||
239 | switch(state) |
||
240 | { |
||
241 | case REMOVE: |
||
242 | if(GetState(pCb, CB_HIDE | CB_DRAW)) |
||
243 | { |
||
244 | SetColor(pCb->hdr.pGolScheme->CommonBkColor); |
||
245 | if(!Bar(pCb->hdr.left, pCb->hdr.top, pCb->hdr.right, pCb->hdr.bottom)) |
||
246 | { |
||
247 | return (0); |
||
248 | } |
||
249 | |||
250 | if(GetState(pCb, CB_HIDE)) |
||
251 | return (1); |
||
252 | } |
||
253 | |||
254 | state = BOX_DRAW; |
||
255 | |||
256 | case BOX_DRAW: |
||
257 | if(GetState(pCb, CB_DRAW)) |
||
258 | { |
||
259 | if(!GetState(pCb, CB_DISABLED)) |
||
260 | { |
||
261 | GOLPanelDraw |
||
262 | ( |
||
263 | pCb->hdr.left + CB_INDENT, |
||
264 | pCb->hdr.top + CB_INDENT, |
||
265 | pCb->hdr.left + (pCb->hdr.bottom - pCb->hdr.top) - CB_INDENT, |
||
266 | pCb->hdr.bottom - CB_INDENT, |
||
267 | 0, |
||
268 | pCb->hdr.pGolScheme->Color0, |
||
269 | pCb->hdr.pGolScheme->EmbossDkColor, |
||
270 | pCb->hdr.pGolScheme->EmbossLtColor, |
||
271 | NULL, |
||
272 | GOL_EMBOSS_SIZE |
||
273 | ); |
||
274 | } |
||
275 | else |
||
276 | { |
||
277 | GOLPanelDraw |
||
278 | ( |
||
279 | pCb->hdr.left + CB_INDENT, |
||
280 | pCb->hdr.top + CB_INDENT, |
||
281 | pCb->hdr.left + (pCb->hdr.bottom - pCb->hdr.top) - CB_INDENT, |
||
282 | pCb->hdr.bottom - CB_INDENT, |
||
283 | 0, |
||
284 | pCb->hdr.pGolScheme->ColorDisabled, |
||
285 | pCb->hdr.pGolScheme->EmbossDkColor, |
||
286 | pCb->hdr.pGolScheme->EmbossLtColor, |
||
287 | NULL, |
||
288 | GOL_EMBOSS_SIZE |
||
289 | ); |
||
290 | } |
||
291 | |||
292 | state = RUN_DRAW; |
||
293 | |||
294 | case RUN_DRAW: |
||
295 | if(!GOLPanelDrawTsk()) |
||
296 | return (0); |
||
297 | state = TEXT_DRAW; |
||
298 | |||
299 | case TEXT_DRAW: |
||
300 | if(pCb->pText != NULL) |
||
301 | { |
||
302 | SetFont(pCb->hdr.pGolScheme->pFont); |
||
303 | |||
304 | if(!GetState(pCb, CB_DISABLED)) |
||
305 | { |
||
306 | SetColor(pCb->hdr.pGolScheme->TextColor0); |
||
307 | } |
||
308 | else |
||
309 | { |
||
310 | SetColor(pCb->hdr.pGolScheme->TextColorDisabled); |
||
311 | } |
||
312 | |||
313 | MoveTo |
||
314 | ( |
||
315 | pCb->hdr.left + pCb->hdr.bottom - pCb->hdr.top + CB_INDENT, |
||
316 | (pCb->hdr.bottom + pCb->hdr.top - pCb->textHeight) >> 1 |
||
317 | ); |
||
318 | |||
319 | state = TEXT_DRAW_RUN; |
||
320 | |||
321 | case TEXT_DRAW_RUN: |
||
322 | if(!OutText(pCb->pText)) |
||
323 | return (0); |
||
324 | } |
||
325 | } |
||
326 | |||
327 | state = CHECK_DRAW; |
||
328 | |||
329 | case CHECK_DRAW: |
||
330 | if(GetState(pCb, CB_DRAW | CB_DRAW_CHECK)) |
||
331 | { |
||
332 | if(!GetState(pCb, CB_DISABLED)) |
||
333 | { |
||
334 | if(GetState(pCb, CB_CHECKED)) |
||
335 | { |
||
336 | SetColor(pCb->hdr.pGolScheme->TextColor0); |
||
337 | } |
||
338 | else |
||
339 | { |
||
340 | SetColor(pCb->hdr.pGolScheme->Color0); |
||
341 | } |
||
342 | } |
||
343 | else |
||
344 | { |
||
345 | if(GetState(pCb, CB_CHECKED)) |
||
346 | { |
||
347 | SetColor(pCb->hdr.pGolScheme->TextColorDisabled); |
||
348 | } |
||
349 | else |
||
350 | { |
||
351 | SetColor(pCb->hdr.pGolScheme->ColorDisabled); |
||
352 | } |
||
353 | } |
||
354 | |||
355 | checkIndent = (pCb->hdr.bottom - pCb->hdr.top) >> 2; |
||
356 | |||
357 | if |
||
358 | ( |
||
359 | !Bar |
||
360 | ( |
||
361 | pCb->hdr.left + checkIndent + GOL_EMBOSS_SIZE, |
||
362 | pCb->hdr.top + checkIndent + GOL_EMBOSS_SIZE, |
||
363 | pCb->hdr.left + (pCb->hdr.bottom - pCb->hdr.top) - checkIndent - GOL_EMBOSS_SIZE, |
||
364 | pCb->hdr.bottom - checkIndent - GOL_EMBOSS_SIZE |
||
365 | ) |
||
366 | ) |
||
367 | { |
||
368 | return (0); |
||
369 | } |
||
370 | } |
||
371 | |||
372 | state = FOCUS_DRAW; |
||
373 | |||
374 | case FOCUS_DRAW: |
||
375 | if(GetState(pCb, CB_DRAW | CB_DRAW_FOCUS)) |
||
376 | { |
||
377 | if(GetState(pCb, CB_FOCUSED)) |
||
378 | { |
||
379 | SetColor(pCb->hdr.pGolScheme->TextColor0); |
||
380 | } |
||
381 | else |
||
382 | { |
||
383 | SetColor(pCb->hdr.pGolScheme->CommonBkColor); |
||
384 | } |
||
385 | |||
386 | SetLineType(FOCUS_LINE); |
||
387 | if(!Rectangle(pCb->hdr.left, pCb->hdr.top, pCb->hdr.right, pCb->hdr.bottom)) |
||
388 | { |
||
389 | return (0); |
||
390 | } |
||
391 | |||
392 | SetLineType(SOLID_LINE); |
||
393 | } |
||
394 | |||
395 | state = REMOVE; |
||
396 | return (1); |
||
397 | } |
||
398 | |||
399 | return (1); |
||
400 | } |
||
401 | |||
402 | #endif // USE_CHECKBOX |
Powered by WebSVN v2.8.3