?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 * Slider
5 *****************************************************************************
6 * FileName: Slider.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 04/29/10 - Added OBJ_MSG_PASSIVE message to detect
41 * event on the slider but with no action.
42 * - fixed the swapped message translation
43 * in the SldTranslateMsg() when keyboard
44 * event is detected.
45 *****************************************************************************/
46 #include "Graphics\Graphics.h"
47  
48 #ifdef USE_SLIDER
49  
50 /* Internal Functions */
51 SHORT SldSetThumbSize(SLIDER *pSld, SHORT high, SHORT low);
52 void SldGetMinMaxPos(SLIDER *pSld, WORD *minPos, WORD *maxPos);
53 WORD SldGetWidth(SLIDER *pSld);
54 WORD SldGetHeight(SLIDER *pSld);
55  
56 /*********************************************************************
57 * Function: SLIDER *SldCreate(WORD ID, SHORT left, SHORT top, SHORT right,
58 * SHORT bottom, WORD state, SHORT range,
59 * SHORT page, SHORT pos, GOL_SCHEME *pScheme)
60 *
61 * Notes: Creates a SLIDER object and adds it to the current active list.
62 * If the creation is successful, the pointer to the created Object
63 * is returned. If not successful, NULL is returned.
64 *
65 ********************************************************************/
66 SLIDER *SldCreate
67 (
68 WORD ID,
69 SHORT left,
70 SHORT top,
71 SHORT right,
72 SHORT bottom,
73 WORD state,
74 WORD range,
75 WORD page,
76 WORD pos,
77 GOL_SCHEME *pScheme
78 )
79 {
80 SLIDER *pSld = NULL;
81  
82 pSld = (SLIDER *)GFX_malloc(sizeof(SLIDER));
83 if(pSld == NULL)
84 return (pSld);
85  
86 pSld->hdr.ID = ID; // unique id assigned for referencing
87 pSld->hdr.pNxtObj = NULL;
88 pSld->hdr.type = OBJ_SLIDER; // set object type
89 pSld->hdr.left = left; // left and right should be equal when oriented vertically
90 pSld->hdr.top = top; // top and bottom should be equal when oriented horizontally
91 pSld->hdr.right = right;
92 pSld->hdr.bottom = bottom;
93 pSld->hdr.state = state;
94  
95 // Parameters in the user defined range system (pos, page and range)
96 pSld->range = range; // range of the slider movement (always measured from 0 to range)
97  
98 // 0 refers to pSld->minPos and
99 // range refers to pSld->maxpos where: minPos and maxPos are
100 // the coordinate equivalent of 0 and range value
101 pSld->page = page; // set the resolution
102 pSld->pos = pos; // set the initial position
103  
104 // calculate the thumb width and height
105 pSld->thWidth = SldGetWidth(pSld);
106 pSld->thHeight = SldGetHeight(pSld);
107  
108 // Set the color scheme to be used
109 if(pScheme == NULL)
110 pSld->hdr.pGolScheme = _pDefaultGolScheme; // use default scheme
111 else
112 pSld->hdr.pGolScheme = (GOL_SCHEME *)pScheme; // user defined scheme
113 GOLAddObject((OBJ_HEADER *)pSld); // add the new object to the current list
114 return (pSld);
115 }
116  
117 /*********************************************************************
118 * Function: SHORT SldSetThumbSize(SLIDER *pSld, SHORT high, SHORT low)
119 *
120 * Notes: An INTERNAL function used to compute for the width or
121 * height of the thumb. This function is created to save
122 * code size. This function is called only to dynamically
123 * compute for the thumb size. Used only when slider is
124 * type Scrollbar. Parameter are defined as:
125 * pSld - pointer to the object
126 * high - higher value to be used
127 * low - lower value to be used
128 *
129 ********************************************************************/
130 SHORT SldSetThumbSize(SLIDER *pSld, SHORT high, SHORT low)
131 {
132 WORD temp;
133  
134 temp = (pSld->range / pSld->page);
135 temp = (high - low) / temp;
136  
137 // when size is less than half of emboss size, set the
138 // size to half the emboss size. This is to make sure
139 // thumb will always have a size.
140 if(temp < (GOL_EMBOSS_SIZE << 1))
141 temp = (GOL_EMBOSS_SIZE << 1);
142  
143 return (SHORT) temp;
144 }
145  
146 /*********************************************************************
147 * Function: WORD SldGetWidth(SLIDER *pSld)
148 *
149 * Notes: An INTERNAL function that computes for the width
150 * of the thumb. This function is created to save
151 * code size. This function is called only to dynamically
152 * compute for the thumb size.
153 *
154 ********************************************************************/
155 WORD SldGetWidth(SLIDER *pSld)
156 {
157 WORD temp;
158  
159 /*
160 Calculating the width is dependent on the mode type.
161 If type Scrollbar, width is dependent on the ratio of the
162 page/range = width/max-min (see SetThumbSize())
163 if type is Slider, width is dependent on height*3/8
164  
165 When horizontal width is dynamic, height is contant.
166  
167 */
168 if(GetState(pSld, SLD_VERTICAL))
169 {
170 temp = pSld->hdr.right - pSld->hdr.left;
171 if(GetState(pSld, SLD_SCROLLBAR))
172 {
173 temp = temp - (GOL_EMBOSS_SIZE << 1);
174 }
175 else
176 {
177 temp = temp - (GOL_EMBOSS_SIZE << 1) - 2;
178 }
179 }
180 else
181 {
182 if(GetState(pSld, SLD_SCROLLBAR))
183 {
184 temp = SldSetThumbSize(pSld, pSld->hdr.right, pSld->hdr.left);
185 }
186 else
187 {
188 temp = (((pSld->hdr.bottom - pSld->hdr.top) - (GOL_EMBOSS_SIZE << 1) - 2) * 3) >> 3;
189 }
190 }
191  
192 // to avoid calculations of dividing by two, we store half the width value
193 return (temp >> 1);
194 }
195  
196 /*********************************************************************
197 * Function: WORD SldGetHeight(SLIDER *pSld)
198 *
199 * Notes: An INTERNAL function that computes for the height
200 * of the thumb. This function is created to save
201 * code size. This function is called only to dynamically
202 * compute for the thumb size.
203 *
204 ********************************************************************/
205 WORD SldGetHeight(SLIDER *pSld)
206 {
207 WORD temp;
208  
209 /*
210 Calculating the height is dependent on the mode type.
211 If type Scrollbar, width is dependent on the ratio of the
212 page/range = width/max-min (see SetThumbSize())
213 if type is Slider, width is dependent on width*3/8
214  
215 When vertical height is dynamic, width is contant.
216 */
217 if(GetState(pSld, SLD_VERTICAL))
218 {
219 if(GetState(pSld, SLD_SCROLLBAR))
220 {
221 temp = SldSetThumbSize(pSld, pSld->hdr.bottom, pSld->hdr.top);
222 }
223 else
224 {
225 temp = (((pSld->hdr.right - pSld->hdr.left) - (GOL_EMBOSS_SIZE << 1) - 2) * 3) >> 3;
226 }
227 }
228 else
229 {
230 temp = pSld->hdr.bottom - pSld->hdr.top;
231 if(GetState(pSld, SLD_SCROLLBAR))
232 {
233 temp = temp - (GOL_EMBOSS_SIZE << 1);
234 }
235 else
236 {
237 temp = temp - (GOL_EMBOSS_SIZE << 1) - 2;
238 }
239 }
240  
241 // to avoid calculations of dividing by two, we store half the height value
242 return (temp >> 1);
243 }
244  
245 /*********************************************************************
246 * Function: void SldGetMinMaxPos(SLIDER *pSld, WORD *min, WORD *max)
247 *
248 * Notes: An INTERNAL function that computes for the minimum
249 * and maximum pixel position in the screen. This function is
250 * created to save code size. Used to define the minimum
251 * & maximum position of the thumb when sliding. Parameters
252 * used are defined as:
253 * pSld - pointer to the object
254 * min - pointer to the minimum variable
255 * max - pointer to the maximum variable
256 *
257 ********************************************************************/
258 void SldGetMinMaxPos(SLIDER *pSld, WORD *min, WORD *max)
259 {
260 WORD temp;
261  
262 // calculate maximum and minimum position
263 if(GetState(pSld, SLD_VERTICAL))
264 {
265 temp = pSld->thHeight + GOL_EMBOSS_SIZE;
266 *min = pSld->hdr.top + temp;
267 *max = pSld->hdr.bottom - temp;
268 }
269 else
270 {
271 temp = pSld->thWidth + GOL_EMBOSS_SIZE;
272 *min = pSld->hdr.left + temp;
273 *max = pSld->hdr.right - temp;
274 }
275  
276 // for aestetics.
277 if(!GetState(pSld, SLD_SCROLLBAR))
278 {
279 *min = *min + 2;
280 *max = *max - 2;
281 }
282 }
283  
284 /*********************************************************************
285 * Function: void SldSetRange(SLIDER *pSld, SHORT newRange)
286 *
287 * Notes: Sets the new range value of the slider or scrollbar.
288 * Object must be redrawn after this function is called to
289 * reflect the changes to the object.
290 *
291 ********************************************************************/
292 void SldSetRange(SLIDER *pSld, SHORT newRange)
293 {
294 WORD newPos;
295 DWORD_VAL dTemp;
296  
297 // this checks for limits of the range (minimum is 2)
298 if(newRange <= 2)
299 newRange = 2;
300  
301 if((WORD) newRange > (WORD) 0x7FFF)
302 newRange = 0x7FFF;
303  
304 dTemp.Val = newRange * pSld->pos;
305 dTemp.Val = dTemp.Val / pSld->range;
306  
307 // get new range
308 newPos = dTemp.w[0];
309  
310 // set the new range
311 pSld->range = newRange;
312  
313 // now check the page, adjust when necessary
314 // page maximum limit is range/2, minimum is 1
315 if(pSld->page > ((pSld->range) >> 1))
316 {
317 if(!((pSld->range) >> 1))
318 pSld->page = 1;
319 else
320 pSld->page = (pSld->range) >> 1;
321 }
322  
323 // calculate new thumb width and height
324 pSld->thWidth = SldGetWidth(pSld);
325 pSld->thHeight = SldGetHeight(pSld);
326 SldSetPos(pSld, newPos);
327 }
328  
329 /*********************************************************************
330 * Function: void SldSetPage(SLIDER *pSld, WORD newPage)
331 *
332 * Notes: Sets the new page value of the slider or scrollbar.
333 * The page maximum limit is range/2, minimum is 1
334 *
335 ********************************************************************/
336 void SldSetPage(SLIDER *pSld, WORD newPage)
337 {
338 if(newPage < 1)
339 newPage = 1;
340 else if(newPage > ((pSld->range) >> 1))
341 newPage = (pSld->range) >> 1;
342 pSld->page = newPage;
343  
344 // calculate new thumb width and height
345 pSld->thWidth = SldGetWidth(pSld);
346 pSld->thHeight = SldGetHeight(pSld);
347 }
348  
349 /*********************************************************************
350 * Function: SldSetPos(SLIDER *pSld, SHORT newPos)
351 *
352 * Notes: Sets the thumb to the new position. Checking is first
353 * preformed if the new position is within the range (0 to range)
354 * of the slider. Object must be redrawn after this function is called to
355 * reflect the changes to the object.
356 *
357 ********************************************************************/
358 void SldSetPos(SLIDER *pSld, SHORT newPos)
359 {
360 WORD minPos, maxPos, relPos;
361 DWORD_VAL dTemp;
362  
363 // get minimum and maximum positions
364 SldGetMinMaxPos(pSld, &minPos, &maxPos);
365 dTemp.Val = 0;
366  
367 #ifndef SLD_INVERT_VERTICAL
368  
369 // check if the new value is still in range
370 if(newPos <= 0)
371 {
372 pSld->pos = 0; // set to zero in range domain
373 if(GetState(pSld, SLD_VERTICAL))
374 { // min and max in vertical is inverted
375 pSld->currPos = maxPos; // minimum position is the bottom position in
376 } // coordinate domain
377 else
378 pSld->currPos = minPos; // minimum is left most position in coordinate domain
379 }
380 else if(newPos >= pSld->range)
381 {
382 pSld->pos = pSld->range; // set to maximum value in range domain
383 if(GetState(pSld, SLD_VERTICAL))
384 { // min and max in vertical is inverted
385 pSld->currPos = minPos; // maximum position is the top position in
386 } // coordinate domain
387 else
388 pSld->currPos = maxPos; // maximum is right most position in coordinate domain
389 }
390 else
391 {
392 pSld->pos = newPos; // get new position in range domain
393 dTemp.w[1] = newPos;
394 dTemp.Val = dTemp.Val / pSld->range;
395 dTemp.Val = (maxPos - minPos) * dTemp.Val;
396  
397 // set current position in coordinate domain
398 relPos = dTemp.w[1] + minPos;
399  
400 if(GetState(pSld, SLD_VERTICAL))
401 { // test if we need to transform min and max position
402 pSld->currPos = maxPos - (relPos - minPos); // min and max position is swapped in coordinate domain
403 }
404 else
405 pSld->currPos = relPos; // use position
406 }
407  
408 #else
409  
410 // check if the new value is still in range
411 if(newPos <= 0)
412 {
413 pSld->pos = 0; // set to zero in range domain
414 pSld->currPos = minPos; // set to minimum in coordinate domain
415 }
416 else if(newPos >= pSld->range)
417 {
418 pSld->pos = pSld->range; // set to maximum value in range domain
419 pSld->currPos = maxPos; // set to minimum in coordinate domain
420 }
421 else
422 {
423 pSld->pos = newPos; // get new position in range domain
424 dTemp.w[1] = newPos;
425 dTemp.Val = dTemp.Val / pSld->range;
426 dTemp.Val = (maxPos - minPos) * dTemp.Val;
427  
428 // set current position in coordinate domain
429 pSld->currPos = dTemp.w[1] + minPos;
430 }
431  
432 #endif // ifndef SLD_INVERT_VERTICAL
433 }
434  
435 /*********************************************************************
436 * Function: void SldMsgDefault(WORD translatedMsg, SLIDER* pSld,
437 * GOL_MSG* pMsg)
438 *
439 * Notes: This the default operation to change the state of the button.
440 * Called inside GOLMsg() when GOLMsgCallback() returns a 1.
441 *
442 ********************************************************************/
443 void SldMsgDefault(WORD translatedMsg, SLIDER *pSld, GOL_MSG *pMsg)
444 {
445 #ifdef USE_TOUCHSCREEN
446  
447 WORD newPos, minPos, maxPos;
448 DWORD_VAL dTemp;
449  
450 #ifdef USE_FOCUS
451 if(pMsg->type == TYPE_TOUCHSCREEN)
452 {
453 if(!GetState(pSld, SLD_FOCUSED))
454 {
455 GOLSetFocus((OBJ_HEADER *)pSld);
456 }
457 }
458  
459 #endif // USE_FOCUS
460  
461 // if message was passive do not do anything
462 if (translatedMsg == OBJ_MSG_PASSIVE)
463 return;
464  
465 // get the min and max positions
466 SldGetMinMaxPos(pSld, &minPos, &maxPos);
467  
468 if(pMsg->type == TYPE_TOUCHSCREEN)
469 {
470 if((translatedMsg == SLD_MSG_DEC) || (translatedMsg == SLD_MSG_INC))
471 {
472  
473 // newPos in this context is used in the coordinate domain
474 if(!GetState(pSld, SLD_VERTICAL))
475 { // check if Horizontal or Vertical orientation
476 if(pMsg->param1 <= minPos)
477 { // Horizontal orientation: test x position
478 newPos = minPos; // beyond minimum, use min position
479 }
480 else if(pMsg->param1 >= maxPos)
481 {
482 newPos = maxPos; // beyond maximum, use max position
483 }
484 else
485 {
486 newPos = pMsg->param1; // within range: use x position given
487 }
488 }
489 else
490 {
491 if(pMsg->param2 <= minPos)
492 { // Vertical orientation: test y position
493 newPos = minPos; // beyond minimum, use min position
494 }
495 else if(pMsg->param2 >= maxPos)
496 {
497 newPos = maxPos; // beyond maximum, use max position
498 }
499 else
500 {
501 newPos = pMsg->param2; // within range: use y position given
502 }
503 }
504  
505 if(newPos != pSld->currPos)
506 { // check if we need to redraw thumb
507 // yes redraw is needed, translate newPos into range domain
508 // first get new position in range domain
509 dTemp.Val = (DWORD) (newPos - minPos) * (DWORD) pSld->range;
510 dTemp.Val = dTemp.Val / (maxPos - minPos);
511 newPos = dTemp.w[0];
512  
513 #ifndef SLD_INVERT_VERTICAL
514 if(GetState(pSld, SLD_VERTICAL))
515 { // check if we need to swap min and max in vertical
516 newPos = pSld->range - newPos; // min and max is swapped in vertical orientation
517 }
518  
519 #endif
520 SldSetPos(pSld, newPos); // set to new position
521 SetState(pSld, SLD_DRAW_THUMB); // redraw the thumb only
522 }
523 else
524 return;
525 }
526 else
527 return;
528 }
529  
530 #endif // USE_TOUCHSCREEN
531 #ifdef USE_KEYBOARD
532 if(pMsg->type == TYPE_KEYBOARD)
533 { // for keyboard
534 if(translatedMsg == SLD_MSG_INC)
535 {
536 SldIncPos(pSld); // increment is requested
537 }
538 else
539 {
540 SldDecPos(pSld); // decrement is requested
541 }
542  
543 SetState(pSld, SLD_DRAW_THUMB); // redraw the thumb only
544 }
545  
546 #endif // USE_KEYBOARD
547 }
548  
549 /*********************************************************************
550 * Function: WORD SldTranslateMsg(SLIDER *pSld, GOL_MSG *pMsg)
551 *
552 * Notes: Evaluates the message if the object will be affected by the
553 * message or not.
554 *
555 ********************************************************************/
556 WORD SldTranslateMsg(SLIDER *pSld, GOL_MSG *pMsg)
557 {
558  
559 // Evaluate if the message is for the slider
560 // Check if disabled first
561 if(GetState(pSld, SLD_DISABLED))
562 return (OBJ_MSG_INVALID);
563  
564 #ifdef USE_TOUCHSCREEN
565 if(pMsg->type == TYPE_TOUCHSCREEN)
566 {
567  
568 // Check if it falls to the left or right of the center of the thumb's face
569 if((pMsg->uiEvent == EVENT_PRESS) || (pMsg->uiEvent == EVENT_MOVE))
570 {
571 if
572 (
573 (pSld->hdr.left < pMsg->param1) &&
574 (pSld->hdr.right > pMsg->param1) &&
575 (pSld->hdr.top < pMsg->param2) &&
576 (pSld->hdr.bottom > pMsg->param2)
577 )
578 {
579 if(GetState(pSld, SLD_VERTICAL))
580 {
581 if(pSld->currPos < pMsg->param2)
582 return (SLD_MSG_INC);
583 else
584 return (SLD_MSG_DEC);
585 }
586 else
587 {
588 if(pSld->currPos < pMsg->param1)
589 return (SLD_MSG_INC);
590 else
591 return (SLD_MSG_DEC);
592 }
593 }
594 } // end of if((pMsg->uiEvent == EVENT_PRESS) || (pMsg->uiEvent == EVENT_MOVE))
595  
596 // when the event is release emit OBJ_MSG_PASSIVE this can be used to
597 // detect that the release event happened on the slider.
598 if(pMsg->uiEvent == EVENT_RELEASE)
599 return OBJ_MSG_PASSIVE;
600  
601 return (OBJ_MSG_INVALID);
602 } // end of if(pMsg->type == TYPE_TOUCHSCREEN
603 #endif
604 #ifdef USE_KEYBOARD
605 if(pMsg->type == TYPE_KEYBOARD)
606 {
607 if(pMsg->param1 == pSld->hdr.ID)
608 {
609 if(pMsg->uiEvent == EVENT_KEYSCAN)
610 {
611 if((pMsg->param2 == SCAN_RIGHT_PRESSED) || (pMsg->param2 == SCAN_UP_PRESSED))
612 {
613 return (SLD_MSG_INC);
614 }
615  
616 if((pMsg->param2 == SCAN_LEFT_PRESSED) || (pMsg->param2 == SCAN_DOWN_PRESSED))
617 {
618 return (SLD_MSG_DEC);
619 }
620 }
621 }
622 }
623  
624 #endif
625 return (OBJ_MSG_INVALID);
626 }
627  
628 /*********************************************************************
629 * Function: WORD SldDraw(SLIDER *pSld)
630 *
631 * Notes: This is the state machine to draw the slider or scrollbar.
632 *
633 ********************************************************************/
634 WORD SldDraw(SLIDER *pSld)
635 {
636 typedef enum
637 {
638 SLD_STATE_IDLE,
639 SLD_STATE_PANEL,
640 SLD_STATE_THUMBPATH1,
641 SLD_STATE_THUMBPATH2,
642 SLD_STATE_CLEARTHUMB,
643 SLD_STATE_REDRAWPATH1,
644 SLD_STATE_REDRAWPATH2,
645 SLD_STATE_THUMB,
646 SLD_STATE_THUMBPANEL,
647 SLD_STATE_FOCUS
648 } SLD_DRAW_STATES;
649  
650 static WORD colorTemp = 0;
651  
652 static SLD_DRAW_STATES state = SLD_STATE_IDLE;
653 static WORD left, top, right, bottom;
654 static WORD midPoint, thWidth, thHeight;
655 static WORD minPos, maxPos;
656  
657 if(IsDeviceBusy())
658 return (0);
659  
660 switch(state)
661 {
662 case SLD_STATE_IDLE:
663 if(GetState(pSld, SLD_HIDE))
664 {
665 SetColor(pSld->hdr.pGolScheme->CommonBkColor); // set to common BK Color
666 if(!Bar(pSld->hdr.left, pSld->hdr.top, pSld->hdr.right, pSld->hdr.bottom))
667 return (0);
668 return (1);
669 }
670  
671 if(!GetState(pSld, SLD_DISABLED))
672 {
673 colorTemp = pSld->hdr.pGolScheme->Color0; // select enabled color
674 }
675 else
676 {
677 colorTemp = pSld->hdr.pGolScheme->ColorDisabled; // select disabled color
678 }
679  
680 SldGetMinMaxPos(pSld, &minPos, &maxPos);
681  
682 midPoint = GetState(pSld, SLD_VERTICAL) ? (pSld->hdr.left + pSld->hdr.right) >> 1 : (pSld->hdr.top + pSld->hdr.bottom) >> 1;
683  
684 // calculate the thumb width and height Actually gets the half value
685 // (see calculation of width and height) SldGetWidth() and SldGetHeight()
686 thWidth = pSld->thWidth; // gets half the width
687 thHeight = pSld->thHeight; // gets half the height
688 SetLineThickness(NORMAL_LINE);
689 SetLineType(SOLID_LINE);
690 if(GetState(pSld, SLD_DRAW))
691 { // draw the panel for the slider
692 // modify the color setting if scroll bar mode or slider mode
693 GOLPanelDraw
694 (
695 pSld->hdr.left,
696 pSld->hdr.top,
697 pSld->hdr.right,
698 pSld->hdr.bottom,
699 0,
700 colorTemp,
701 (GetState(pSld, SLD_SCROLLBAR)) ? pSld->hdr.pGolScheme->EmbossDkColor : pSld->hdr.pGolScheme->EmbossLtColor,
702 (GetState(pSld, SLD_SCROLLBAR)) ? pSld->hdr.pGolScheme->EmbossLtColor : pSld->hdr.pGolScheme->EmbossDkColor,
703 NULL,
704 GOL_EMBOSS_SIZE
705 );
706  
707 // initialize current and previous position
708 SldSetPos(pSld, pSld->pos);
709 pSld->prevPos = pSld->currPos;
710  
711 state = SLD_STATE_PANEL;
712 }
713 else
714 { // we do not need to draw the whole object
715 state = SLD_STATE_CLEARTHUMB; // go to thumb drawing
716 goto sld_state_clearthumb;
717 }
718  
719 case SLD_STATE_PANEL:
720 if(!GOLPanelDrawTsk()) // draw the panel of the slider
721 return (0);
722 if(GetState(pSld, SLD_SCROLLBAR))
723 { // check if slider or scroll bar
724 state = SLD_STATE_THUMB; // scrollbar: go directly to thumb drawing
725 goto sld_state_thumb; // thumb path is not drawn in scrollbar
726 }
727 else
728 {
729 state = SLD_STATE_THUMBPATH1; // slider: draw thumb path next
730 }
731  
732 case SLD_STATE_THUMBPATH1:
733 SetColor(BLACK); // draw the black line
734 if(!GetState(pSld, SLD_VERTICAL))
735 {
736 if(!Line(minPos, midPoint, maxPos, midPoint))
737 return (0);
738 }
739 else
740 {
741 if(!Line(midPoint, minPos, midPoint, maxPos))
742 return (0);
743 }
744  
745 state = SLD_STATE_THUMBPATH2;
746  
747 case SLD_STATE_THUMBPATH2:
748 SetColor(WHITE); // draw the white line
749 if(!GetState(pSld, SLD_VERTICAL))
750 {
751 if(!Line(minPos, midPoint + 1, maxPos, midPoint + 1))
752 return (0);
753 }
754 else
755 {
756 if(!Line(midPoint + 1, minPos, midPoint + 1, maxPos))
757 return (0);
758 }
759  
760 if(GetState(pSld, SLD_DRAW))
761 { // if drawing the whole slider
762 state = SLD_STATE_THUMB; // go straight to drawing the thumb
763 goto sld_state_thumb;
764 }
765 else
766 // if just drawing the thumb
767 state = SLD_STATE_CLEARTHUMB; // go to state to remove current position
768  
769 case SLD_STATE_CLEARTHUMB: // this removes the current thumb
770 sld_state_clearthumb : if(IsDeviceBusy()) return (0);
771  
772 if(!GetState(pSld, SLD_DRAW_THUMB))
773 { // SLD_DRAW_THUMB is only set when
774 state = SLD_STATE_FOCUS; // object type is SLIDER
775 goto sld_state_focus;
776 }
777  
778 SetColor(colorTemp);
779  
780 // Remove the current thumb by drawing a bar with background color
781 if(!GetState(pSld, SLD_VERTICAL))
782 {
783 if(!Bar(pSld->prevPos - thWidth, midPoint - thHeight, pSld->prevPos + thWidth, midPoint + thHeight))
784 return (0);
785 }
786 else
787 {
788 if(!Bar(midPoint - thWidth, pSld->prevPos - thHeight, midPoint + thWidth, pSld->prevPos + thHeight))
789 return (0);
790 }
791  
792 if(!GetState(pSld, SLD_SCROLLBAR))
793 { // check if slider or scroll bar
794 state = SLD_STATE_REDRAWPATH1;
795 }
796 else
797 {
798 state = SLD_STATE_THUMB; // go directly to thumb drawing
799 goto sld_state_thumb; // thumb path is not drawn in scrollbar
800 }
801  
802 case SLD_STATE_REDRAWPATH1: // redraws the lines that it covered
803 SetColor(BLACK); // redraw the black line first
804  
805 // Check if the redraw area exceeds the actual dimension. This will
806 // adjust the redrawing area to just within the parameters
807 if(!GetState(pSld, SLD_VERTICAL))
808 {
809 if(minPos + thWidth > pSld->prevPos)
810 left = minPos;
811 else
812 left = pSld->prevPos - thWidth;
813  
814 if(maxPos - thWidth < pSld->prevPos)
815 right = maxPos;
816 else
817 right = pSld->prevPos + thWidth;
818  
819 if(!Line(left, midPoint, right, midPoint))
820 return (0);
821 }
822 else
823 {
824 if(minPos + thHeight > pSld->prevPos)
825 top = minPos;
826 else
827 top = pSld->prevPos - thHeight;
828  
829 if(maxPos - thHeight < pSld->prevPos)
830 bottom = maxPos;
831 else
832 bottom = pSld->prevPos + thHeight;
833  
834 if(!Line(midPoint, top, midPoint, bottom))
835 return (0);
836 }
837  
838 state = SLD_STATE_REDRAWPATH2;
839  
840 case SLD_STATE_REDRAWPATH2:
841 SetColor(WHITE); // redraw the white line next
842 if(!GetState(pSld, SLD_VERTICAL))
843 {
844 if(!Line(left, midPoint + 1, right, midPoint + 1))
845 return (0);
846 }
847 else
848 {
849 if(!Line(midPoint + 1, top, midPoint + 1, bottom))
850 return (0);
851 }
852  
853 state = SLD_STATE_THUMB;
854  
855 case SLD_STATE_THUMB:
856 sld_state_thumb : if(IsDeviceBusy()) return (0);
857 if(!GetState(pSld, SLD_VERTICAL))
858 { // Draw the slider thumb based on the
859 // current position
860 left = pSld->currPos - thWidth;
861 top = midPoint - thHeight;
862 right = pSld->currPos + thWidth;
863 bottom = midPoint + thHeight;
864 }
865 else
866 {
867 left = midPoint - thWidth;
868 top = pSld->currPos - thHeight;
869 right = midPoint + thWidth;
870 bottom = pSld->currPos + thHeight;
871 }
872  
873 GOLPanelDraw
874 (
875 left,
876 top,
877 right,
878 bottom,
879 0, // set the parameters of the thumb
880 colorTemp,
881 pSld->hdr.pGolScheme->EmbossLtColor,
882 pSld->hdr.pGolScheme->EmbossDkColor,
883 NULL,
884 (GOL_EMBOSS_SIZE - 1) ? GOL_EMBOSS_SIZE - 1 : 1
885 );
886  
887 state = SLD_STATE_THUMBPANEL;
888  
889 case SLD_STATE_THUMBPANEL:
890 if(!GOLPanelDrawTsk()) // draw the panel of the thumb
891 return (0);
892  
893 pSld->prevPos = pSld->currPos; // record the current position as previous
894 if(GetState(pSld, SLD_SCROLLBAR))
895 { // check if scroll bar focus is not used
896 state = SLD_STATE_IDLE; // go back to idle state
897 return (1);
898 }
899  
900 if(!GetState(pSld, SLD_DRAW_FOCUS))
901 {
902 state = SLD_STATE_IDLE;
903 return (1);
904 }
905  
906 state = SLD_STATE_FOCUS;
907  
908 case SLD_STATE_FOCUS:
909 sld_state_focus : if(!GetState(pSld, SLD_SCROLLBAR))
910 { // do not draw focus when in scroll bar mode
911 SetLineType(FOCUS_LINE);
912 if(GetState(pSld, SLD_FOCUSED))
913 {
914 SetColor(pSld->hdr.pGolScheme->TextColor0); // draw the focus box
915 }
916 else
917 {
918 SetColor(colorTemp); // remove the focus box, colorTemp
919 }
920  
921 if
922 (
923 !Rectangle
924 (
925 pSld->hdr.left + GOL_EMBOSS_SIZE,
926 pSld->hdr.top + GOL_EMBOSS_SIZE,
927 pSld->hdr.right - GOL_EMBOSS_SIZE,
928 pSld->hdr.bottom - GOL_EMBOSS_SIZE
929 )
930 ) return (0);
931  
932 SetLineType(SOLID_LINE); // reset line type
933 }
934  
935 state = SLD_STATE_IDLE; // set state to idle
936 return (1); // return as done
937 }
938  
939 return (1);
940 }
941  
942 #endif // USE_SLIDER
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3