Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /***************************************************************************** |
2 | * Module for Microchip Graphics Library |
||
3 | * GOL Layer |
||
4 | * Window |
||
5 | ***************************************************************************** |
||
6 | * FileName: Window.c |
||
7 | * Dependencies: Graphics.h |
||
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 | * Anton Alkhimenok 11/12/07 Version 1.0 release |
||
40 | *****************************************************************************/ |
||
41 | #include "Graphics\Graphics.h" |
||
42 | |||
43 | #ifdef USE_WINDOW |
||
44 | |||
45 | /********************************************************************* |
||
46 | * Function: WINDOW *WndCreate(WORD ID, SHORT left, SHORT top, SHORT right, |
||
47 | * SHORT bottom, WORD state, XCHAR *pText, void* pBitmap, |
||
48 | * GOL_SCHEME *pScheme) |
||
49 | * |
||
50 | * Overview: creates the window |
||
51 | * |
||
52 | ********************************************************************/ |
||
53 | WINDOW *WndCreate |
||
54 | ( |
||
55 | WORD ID, |
||
56 | SHORT left, |
||
57 | SHORT top, |
||
58 | SHORT right, |
||
59 | SHORT bottom, |
||
60 | WORD state, |
||
61 | void *pBitmap, |
||
62 | XCHAR *pText, |
||
63 | GOL_SCHEME *pScheme |
||
64 | ) |
||
65 | { |
||
66 | WINDOW *pW; |
||
67 | |||
68 | pW = (WINDOW *)GFX_malloc(sizeof(WINDOW)); |
||
69 | if(pW == NULL) |
||
70 | return (pW); |
||
71 | |||
72 | pW->hdr.ID = ID; |
||
73 | pW->hdr.pNxtObj = NULL; |
||
74 | pW->hdr.type = OBJ_WINDOW; |
||
75 | pW->hdr.left = left; |
||
76 | pW->hdr.top = top; |
||
77 | pW->hdr.right = right; |
||
78 | pW->hdr.bottom = bottom; |
||
79 | pW->pBitmap = pBitmap; |
||
80 | pW->pText = pText; |
||
81 | pW->hdr.state = state; |
||
82 | |||
83 | // Set the style scheme to be used |
||
84 | if(pScheme == NULL) |
||
85 | pW->hdr.pGolScheme = _pDefaultGolScheme; |
||
86 | else |
||
87 | pW->hdr.pGolScheme = pScheme; |
||
88 | |||
89 | pW->textHeight = 0; |
||
90 | if(pText != NULL) |
||
91 | { |
||
92 | pW->textHeight = GetTextHeight(pW->hdr.pGolScheme->pFont); |
||
93 | } |
||
94 | |||
95 | GOLAddObject((OBJ_HEADER *)pW); |
||
96 | |||
97 | return (pW); |
||
98 | } |
||
99 | |||
100 | /********************************************************************* |
||
101 | * Function: WndSetText(WINDOW *pW, XCHAR *pText) |
||
102 | * |
||
103 | * Overview: sets text |
||
104 | * |
||
105 | ********************************************************************/ |
||
106 | void WndSetText(WINDOW *pW, XCHAR *pText) |
||
107 | { |
||
108 | pW->pText = pText; |
||
109 | pW->textHeight = GetTextHeight(pW->hdr.pGolScheme->pFont); |
||
110 | } |
||
111 | |||
112 | /********************************************************************* |
||
113 | * Function: WORD WndTranslateMsg(WINDOW *pW, GOL_MSG *pMsg) |
||
114 | * |
||
115 | * Overview: translates the GOL message for the window |
||
116 | * |
||
117 | ********************************************************************/ |
||
118 | WORD WndTranslateMsg(WINDOW *pW, GOL_MSG *pMsg) |
||
119 | { |
||
120 | |||
121 | // Evaluate if the message is for the window |
||
122 | // Check if disabled first |
||
123 | if(GetState(pW, WND_DISABLED)) |
||
124 | return (OBJ_MSG_INVALID); |
||
125 | |||
126 | #ifdef USE_TOUCHSCREEN |
||
127 | if(pMsg->type == TYPE_TOUCHSCREEN) |
||
128 | { |
||
129 | |||
130 | // Check if it falls in the title bar area |
||
131 | if |
||
132 | ( |
||
133 | (pW->hdr.left < pMsg->param1) && |
||
134 | (pW->hdr.right > pMsg->param1) && |
||
135 | (pW->hdr.top < pMsg->param2) && |
||
136 | (pW->hdr.top + WND_TITLE_HEIGHT + GOL_EMBOSS_SIZE > pMsg->param2) |
||
137 | ) |
||
138 | { |
||
139 | return (WND_MSG_TITLE); |
||
140 | } |
||
141 | |||
142 | // Check if it falls in the client area |
||
143 | if |
||
144 | ( |
||
145 | (pW->hdr.left + GOL_EMBOSS_SIZE < pMsg->param1) && |
||
146 | (pW->hdr.right - GOL_EMBOSS_SIZE > pMsg->param1) && |
||
147 | (pW->hdr.top + WND_TITLE_HEIGHT + GOL_EMBOSS_SIZE < pMsg->param2) && |
||
148 | (pW->hdr.bottom - GOL_EMBOSS_SIZE > pMsg->param2) |
||
149 | ) |
||
150 | { |
||
151 | return (WND_MSG_CLIENT); |
||
152 | } |
||
153 | } |
||
154 | |||
155 | #endif |
||
156 | return (OBJ_MSG_INVALID); |
||
157 | } |
||
158 | |||
159 | /********************************************************************* |
||
160 | * Function: WORD WndDraw(WINDOW *pW) |
||
161 | * |
||
162 | * Overview: draws window |
||
163 | * |
||
164 | ********************************************************************/ |
||
165 | WORD WndDraw(WINDOW *pW) |
||
166 | { |
||
167 | typedef enum |
||
168 | { |
||
169 | WND_REMOVE, |
||
170 | WND_TITLE_BAR_DRAW, |
||
171 | WND_TITLE_BAR_BITMAP, |
||
172 | WND_TITLE_BAR_TEXT, |
||
173 | WND_TITLE_BAR_TEXT_DRAW, |
||
174 | WND_CLIENT, |
||
175 | WND_CLIENT_DRAW |
||
176 | } WND_DRAW_STATES; |
||
177 | |||
178 | SHORT temp; |
||
179 | static WND_DRAW_STATES state = WND_REMOVE; |
||
180 | |||
181 | while(1) |
||
182 | { |
||
183 | if(IsDeviceBusy()) |
||
184 | return (0); |
||
185 | |||
186 | switch(state) |
||
187 | { |
||
188 | case WND_REMOVE: |
||
189 | if(GetState(pW, WND_HIDE)) |
||
190 | { |
||
191 | SetColor(pW->hdr.pGolScheme->CommonBkColor); |
||
192 | if(!Bar(pW->hdr.left, pW->hdr.top, pW->hdr.right, pW->hdr.bottom)) |
||
193 | { |
||
194 | return (0); |
||
195 | } |
||
196 | |||
197 | return (1); |
||
198 | } |
||
199 | |||
200 | if(GetState(pW, WND_DRAW_CLIENT)) |
||
201 | { |
||
202 | state = WND_CLIENT; |
||
203 | break; |
||
204 | |||
205 | case WND_CLIENT: |
||
206 | SetLineThickness(NORMAL_LINE); |
||
207 | SetLineType(SOLID_LINE); |
||
208 | GOLPanelDraw |
||
209 | ( |
||
210 | pW->hdr.left, |
||
211 | pW->hdr.top, |
||
212 | pW->hdr.right, |
||
213 | pW->hdr.bottom, |
||
214 | 0, |
||
215 | pW->hdr.pGolScheme->CommonBkColor, |
||
216 | pW->hdr.pGolScheme->EmbossLtColor, |
||
217 | pW->hdr.pGolScheme->EmbossDkColor, |
||
218 | NULL, |
||
219 | GOL_EMBOSS_SIZE |
||
220 | ); |
||
221 | |||
222 | state = WND_CLIENT_DRAW; |
||
223 | |||
224 | case WND_CLIENT_DRAW: |
||
225 | if(!GOLPanelDrawTsk()) |
||
226 | return (0); |
||
227 | } |
||
228 | |||
229 | state = WND_TITLE_BAR_DRAW; |
||
230 | break; |
||
231 | |||
232 | case WND_TITLE_BAR_DRAW: |
||
233 | if(!GetState(pW, WND_DISABLED)) |
||
234 | { |
||
235 | if(GetState(pW, WND_FOCUSED)) |
||
236 | { |
||
237 | SetColor(pW->hdr.pGolScheme->Color1); |
||
238 | } |
||
239 | else |
||
240 | { |
||
241 | SetColor(pW->hdr.pGolScheme->Color0); |
||
242 | } |
||
243 | } |
||
244 | else |
||
245 | { |
||
246 | SetColor(pW->hdr.pGolScheme->ColorDisabled); |
||
247 | } |
||
248 | |||
249 | if |
||
250 | ( |
||
251 | !Bar |
||
252 | ( |
||
253 | pW->hdr.left + GOL_EMBOSS_SIZE, |
||
254 | pW->hdr.top + GOL_EMBOSS_SIZE, |
||
255 | pW->hdr.right - GOL_EMBOSS_SIZE, |
||
256 | pW->hdr.top + GOL_EMBOSS_SIZE + WND_TITLE_HEIGHT |
||
257 | ) |
||
258 | ) |
||
259 | { |
||
260 | return (0); |
||
261 | } |
||
262 | |||
263 | state = WND_TITLE_BAR_BITMAP; |
||
264 | |||
265 | break; |
||
266 | |||
267 | case WND_TITLE_BAR_BITMAP: |
||
268 | if(pW->pBitmap != NULL) |
||
269 | { |
||
270 | if |
||
271 | ( |
||
272 | !PutImage |
||
273 | ( |
||
274 | pW->hdr.left + GOL_EMBOSS_SIZE, |
||
275 | pW->hdr.top + GOL_EMBOSS_SIZE + ((WND_TITLE_HEIGHT - GetImageHeight(pW->pBitmap)) >> 1), |
||
276 | pW->pBitmap, |
||
277 | IMAGE_NORMAL |
||
278 | ) |
||
279 | ) |
||
280 | { |
||
281 | return (0); |
||
282 | } |
||
283 | } |
||
284 | |||
285 | if(pW->pText != NULL) |
||
286 | { |
||
287 | state = WND_TITLE_BAR_TEXT; |
||
288 | break; |
||
289 | |||
290 | case WND_TITLE_BAR_TEXT: |
||
291 | SetFont(pW->hdr.pGolScheme->pFont); |
||
292 | |||
293 | if(!GetState(pW, WND_DISABLED)) |
||
294 | { |
||
295 | if(GetState(pW, WND_FOCUSED)) |
||
296 | { |
||
297 | SetColor(pW->hdr.pGolScheme->TextColor1); |
||
298 | } |
||
299 | else |
||
300 | { |
||
301 | SetColor(pW->hdr.pGolScheme->TextColor0); |
||
302 | } |
||
303 | } |
||
304 | else |
||
305 | { |
||
306 | SetColor(pW->hdr.pGolScheme->TextColorDisabled); |
||
307 | } |
||
308 | |||
309 | temp = pW->hdr.left + GOL_EMBOSS_SIZE + WND_INDENT; |
||
310 | |||
311 | if(pW->pBitmap != NULL) |
||
312 | { |
||
313 | temp += GetImageWidth(pW->pBitmap); |
||
314 | } |
||
315 | |||
316 | if(GetState(pW, WND_TITLECENTER)) |
||
317 | { |
||
318 | temp = (temp + (pW->hdr.right - GetTextWidth(pW->pText, pW->hdr.pGolScheme->pFont))) >> 1; |
||
319 | } |
||
320 | |||
321 | MoveTo(temp, pW->hdr.top + GOL_EMBOSS_SIZE + ((WND_TITLE_HEIGHT - pW->textHeight) >> 1)); |
||
322 | |||
323 | state = WND_TITLE_BAR_TEXT_DRAW; |
||
324 | |||
325 | case WND_TITLE_BAR_TEXT_DRAW: |
||
326 | if(!OutText(pW->pText)) |
||
327 | return (0); |
||
328 | } |
||
329 | |||
330 | state = WND_REMOVE; |
||
331 | return (1); |
||
332 | } //end of switch |
||
333 | } //end of while |
||
334 | } |
||
335 | |||
336 | #endif // USE_WINDOW |
Powered by WebSVN v2.8.3