| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 32 | kaklik | /***************************************************************************** |
| 2 | * Module for Microchip Graphics Library |
||
| 3 | * GOL Layer |
||
| 4 | * Group Box |
||
| 5 | ***************************************************************************** |
||
| 6 | * FileName: GroupBox.c |
||
| 7 | * Dependencies: |
||
| 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 | * Paolo A. Tamayo 11/12/07 Version 1.0 release |
||
| 40 | *****************************************************************************/ |
||
| 41 | #include "Graphics\Graphics.h" |
||
| 42 | |||
| 43 | #ifdef USE_GROUPBOX |
||
| 44 | |||
| 45 | /********************************************************************* |
||
| 46 | * Function: GROUPBOX *GbCreate(WORD ID, SHORT left, SHORT top, SHORT right, |
||
| 47 | * SHORT bottom, WORD state, XCHAR *pText, |
||
| 48 | * GOL_SCHEME *pScheme) |
||
| 49 | * |
||
| 50 | * Notes: Creates a GROUPBOX 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 | GROUPBOX *GbCreate |
||
| 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 | GROUPBOX *pGb = NULL; |
||
| 68 | |||
| 69 | pGb = (GROUPBOX *)GFX_malloc(sizeof(GROUPBOX)); |
||
| 70 | if(pGb == NULL) |
||
| 71 | return (pGb); |
||
| 72 | |||
| 73 | pGb->hdr.ID = ID; // unique id assigned for referencing |
||
| 74 | pGb->hdr.pNxtObj = NULL; |
||
| 75 | pGb->hdr.type = OBJ_GROUPBOX; // set object type |
||
| 76 | pGb->hdr.left = left; |
||
| 77 | pGb->hdr.top = top; |
||
| 78 | pGb->hdr.right = right; |
||
| 79 | pGb->hdr.bottom = bottom; |
||
| 80 | pGb->hdr.state = state; |
||
| 81 | pGb->pText = pText; |
||
| 82 | |||
| 83 | // Set the color scheme and font to be used |
||
| 84 | if(pScheme == NULL) |
||
| 85 | pGb->hdr.pGolScheme = _pDefaultGolScheme; |
||
| 86 | else |
||
| 87 | pGb->hdr.pGolScheme = (GOL_SCHEME *)pScheme; |
||
| 88 | |||
| 89 | pGb->textWidth = 0; |
||
| 90 | pGb->textHeight = 0; |
||
| 91 | if(pText != NULL) |
||
| 92 | { |
||
| 93 | |||
| 94 | // Set the text width & height |
||
| 95 | pGb->textWidth = GetTextWidth(pText, pGb->hdr.pGolScheme->pFont); |
||
| 96 | pGb->textHeight = GetTextHeight(pGb->hdr.pGolScheme->pFont); |
||
| 97 | } |
||
| 98 | |||
| 99 | GOLAddObject((OBJ_HEADER *)pGb); |
||
| 100 | return (pGb); |
||
| 101 | } |
||
| 102 | |||
| 103 | /********************************************************************* |
||
| 104 | * Function: WORD GbTranslateMsg(GROUPBOX *pGb, GOL_MSG *pMsg) |
||
| 105 | * |
||
| 106 | * Notes: Evaluates the message if the object will be affected by the |
||
| 107 | * message or not. |
||
| 108 | * |
||
| 109 | ********************************************************************/ |
||
| 110 | WORD GbTranslateMsg(GROUPBOX *pGb, GOL_MSG *pMsg) |
||
| 111 | { |
||
| 112 | |||
| 113 | // Evaluate if the message is for the button |
||
| 114 | // Check if disabled first |
||
| 115 | if(!GetState(pGb, GB_DISABLED)) |
||
| 116 | { |
||
| 117 | #ifdef USE_TOUCHSCREEN |
||
| 118 | if(pMsg->type == TYPE_TOUCHSCREEN) |
||
| 119 | { |
||
| 120 | |||
| 121 | // Check if it falls to the left or right of the center of the thumb's face |
||
| 122 | if |
||
| 123 | ( |
||
| 124 | (pGb->hdr.left < pMsg->param1) && |
||
| 125 | (pGb->hdr.right > pMsg->param1) && |
||
| 126 | (pGb->hdr.top < pMsg->param2) && |
||
| 127 | (pGb->hdr.bottom > pMsg->param2) |
||
| 128 | ) |
||
| 129 | { |
||
| 130 | if((pMsg->uiEvent == EVENT_PRESS) || (pMsg->uiEvent == EVENT_RELEASE)) |
||
| 131 | return (GB_MSG_SELECTED); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | #endif |
||
| 136 | } |
||
| 137 | |||
| 138 | return (OBJ_MSG_INVALID); |
||
| 139 | } |
||
| 140 | |||
| 141 | /********************************************************************* |
||
| 142 | * Function: WORD GbDraw(GROUPBOX *pGb); |
||
| 143 | * |
||
| 144 | * Notes: This is the state machine to draw the button. |
||
| 145 | * |
||
| 146 | ********************************************************************/ |
||
| 147 | #if (COLOR_DEPTH == 1) |
||
| 148 | #define THREE_D_EFFECT 0 |
||
| 149 | #else |
||
| 150 | #define THREE_D_EFFECT 1 |
||
| 151 | #endif |
||
| 152 | |||
| 153 | /* */ |
||
| 154 | WORD GbDraw(GROUPBOX *pGb) |
||
| 155 | { |
||
| 156 | typedef enum |
||
| 157 | { |
||
| 158 | GB_STATE_IDLE, |
||
| 159 | GB_STATE_HIDETEXT, |
||
| 160 | GB_STATE_SETDIMENSION, |
||
| 161 | GB_STATE_DRAWTEXT, |
||
| 162 | GB_STATE_DRAWTOPRIGHT, |
||
| 163 | GB_STATE_DRAWTOPLEFT, |
||
| 164 | GB_STATE_DRAWSIDELEFT, |
||
| 165 | GB_STATE_DRAWSIDERIGHT, |
||
| 166 | GB_STATE_DRAWBOTTOM, |
||
| 167 | #if (COLOR_DEPTH != 1) |
||
| 168 | GB_STATE_2DRAWTOPRIGHT, |
||
| 169 | GB_STATE_2DRAWTOPLEFT, |
||
| 170 | GB_STATE_2DRAWSIDELEFT, |
||
| 171 | GB_STATE_2DRAWSIDERIGHT, |
||
| 172 | GB_STATE_2DRAWBOTTOM, |
||
| 173 | #endif |
||
| 174 | } GB_DRAW_STATES; |
||
| 175 | |||
| 176 | static GB_DRAW_STATES state = GB_STATE_IDLE; |
||
| 177 | static SHORT textLeft, textRight, top; // used to draw lines that start/stops at text. |
||
| 178 | if(IsDeviceBusy()) |
||
| 179 | return (0); |
||
| 180 | |||
| 181 | switch(state) |
||
| 182 | { |
||
| 183 | case GB_STATE_IDLE: |
||
| 184 | |||
| 185 | if(GetState(pGb, GB_HIDE)) |
||
| 186 | { // Hide the Group Box (remove from screen) |
||
| 187 | SetColor(pGb->hdr.pGolScheme->CommonBkColor); |
||
| 188 | if(!Bar(pGb->hdr.left, pGb->hdr.top, pGb->hdr.right, pGb->hdr.bottom)) |
||
| 189 | return 0; |
||
| 190 | return (1); |
||
| 191 | } |
||
| 192 | |||
| 193 | state = GB_STATE_HIDETEXT; |
||
| 194 | |||
| 195 | case GB_STATE_HIDETEXT: // hide the text first |
||
| 196 | if(pGb->pText != NULL) |
||
| 197 | { // needed when dynamically changing |
||
| 198 | SetColor(pGb->hdr.pGolScheme->CommonBkColor); // the alignement of text |
||
| 199 | if(!Bar(pGb->hdr.left, pGb->hdr.top, pGb->hdr.right, pGb->hdr.top + pGb->textHeight)) |
||
| 200 | return 0; |
||
| 201 | } |
||
| 202 | |||
| 203 | state = GB_STATE_SETDIMENSION; |
||
| 204 | |||
| 205 | case GB_STATE_SETDIMENSION: |
||
| 206 | if(IsDeviceBusy()) |
||
| 207 | return (0); |
||
| 208 | |||
| 209 | if(GetState(pGb, GB_DISABLED)) |
||
| 210 | { // set color to inactive color |
||
| 211 | SetColor(pGb->hdr.pGolScheme->TextColorDisabled); |
||
| 212 | } |
||
| 213 | else |
||
| 214 | { |
||
| 215 | SetColor(pGb->hdr.pGolScheme->TextColor0); // active color |
||
| 216 | } |
||
| 217 | |||
| 218 | if(pGb->pText == NULL) |
||
| 219 | { // there is no text, use full dimensions |
||
| 220 | top = pGb->hdr.top; |
||
| 221 | textLeft = pGb->hdr.left + 1; |
||
| 222 | textRight = textLeft; |
||
| 223 | state = GB_STATE_DRAWTOPRIGHT; // go to drawing of right top line |
||
| 224 | goto gb_state_draw_lines; |
||
| 225 | } |
||
| 226 | else |
||
| 227 | { // text is present, set up dimensions with text |
||
| 228 | SetFont(pGb->hdr.pGolScheme->pFont); |
||
| 229 | top = pGb->hdr.top + (pGb->textHeight >> 1); // adjust lines on top |
||
| 230 | if(pGb->hdr.state & GB_RIGHT_ALIGN) |
||
| 231 | { |
||
| 232 | |||
| 233 | // do right aligned |
||
| 234 | textLeft = pGb->hdr.right - pGb->textWidth - 2; |
||
| 235 | textRight = pGb->hdr.right - 2; |
||
| 236 | } |
||
| 237 | else if(pGb->hdr.state & GB_CENTER_ALIGN) |
||
| 238 | { |
||
| 239 | |||
| 240 | // do center aligned |
||
| 241 | textLeft = (pGb->hdr.left + pGb->hdr.right - pGb->textWidth) >> 1; |
||
| 242 | textRight = textLeft + pGb->textWidth; |
||
| 243 | } |
||
| 244 | else |
||
| 245 | { |
||
| 246 | |||
| 247 | // do left aligned |
||
| 248 | textLeft = pGb->hdr.left + 2; |
||
| 249 | textRight = pGb->hdr.left + 2 + pGb->textWidth; |
||
| 250 | } |
||
| 251 | |||
| 252 | MoveTo(textLeft, pGb->hdr.top); // move cursor to start of text |
||
| 253 | state = GB_STATE_DRAWTEXT; |
||
| 254 | } |
||
| 255 | |||
| 256 | case GB_STATE_DRAWTEXT: |
||
| 257 | if(!OutText(pGb->pText)) |
||
| 258 | return (0); |
||
| 259 | #if (COLOR_DEPTH == 1) |
||
| 260 | SetColor(WHITE); |
||
| 261 | #else |
||
| 262 | SetColor(pGb->hdr.pGolScheme->EmbossDkColor); |
||
| 263 | #endif |
||
| 264 | state = GB_STATE_DRAWTOPRIGHT; |
||
| 265 | |||
| 266 | gb_state_draw_lines: |
||
| 267 | |||
| 268 | case GB_STATE_DRAWTOPRIGHT: |
||
| 269 | if(!Line(textRight, top + THREE_D_EFFECT, pGb->hdr.right, top + THREE_D_EFFECT)) |
||
| 270 | return 0; // top line at right |
||
| 271 | state = GB_STATE_DRAWTOPLEFT; |
||
| 272 | |||
| 273 | case GB_STATE_DRAWTOPLEFT: |
||
| 274 | if(!Line(pGb->hdr.left + THREE_D_EFFECT, top + THREE_D_EFFECT, textLeft, top + THREE_D_EFFECT)) |
||
| 275 | return 0; // top line at left |
||
| 276 | state = GB_STATE_DRAWSIDELEFT; |
||
| 277 | |||
| 278 | case GB_STATE_DRAWSIDELEFT: |
||
| 279 | if(!Line(pGb->hdr.left + THREE_D_EFFECT, top + THREE_D_EFFECT, pGb->hdr.left + THREE_D_EFFECT, pGb->hdr.bottom)) |
||
| 280 | return 0; // side line at left |
||
| 281 | state = GB_STATE_DRAWSIDERIGHT; |
||
| 282 | |||
| 283 | case GB_STATE_DRAWSIDERIGHT: |
||
| 284 | if(!Line(pGb->hdr.right, top + THREE_D_EFFECT, pGb->hdr.right, pGb->hdr.bottom)) |
||
| 285 | return 0; // side line at right |
||
| 286 | state = GB_STATE_DRAWBOTTOM; |
||
| 287 | |||
| 288 | case GB_STATE_DRAWBOTTOM: |
||
| 289 | if(!Line(pGb->hdr.left + THREE_D_EFFECT, pGb->hdr.bottom, pGb->hdr.right, pGb->hdr.bottom)) |
||
| 290 | return 0; // bottom line |
||
| 291 | #if (COLOR_DEPTH == 1) |
||
| 292 | state = GB_STATE_IDLE; |
||
| 293 | #else |
||
| 294 | state = GB_STATE_2DRAWTOPLEFT; |
||
| 295 | #endif |
||
| 296 | #if (COLOR_DEPTH != 1) |
||
| 297 | |||
| 298 | case GB_STATE_2DRAWTOPLEFT: |
||
| 299 | SetColor(pGb->hdr.pGolScheme->EmbossLtColor); // 2nd line top line at left |
||
| 300 | if(!Line(pGb->hdr.left, top, textLeft, top)) |
||
| 301 | return 0; |
||
| 302 | state = GB_STATE_2DRAWTOPRIGHT; |
||
| 303 | |||
| 304 | case GB_STATE_2DRAWTOPRIGHT: |
||
| 305 | if(!Line(textRight, top, pGb->hdr.right, top)) |
||
| 306 | return 0; // 2nd line top line at right |
||
| 307 | state = GB_STATE_2DRAWSIDELEFT; |
||
| 308 | |||
| 309 | case GB_STATE_2DRAWSIDELEFT: |
||
| 310 | if(!Line(pGb->hdr.left, top, pGb->hdr.left, pGb->hdr.bottom - 1)) |
||
| 311 | return 0; // 2nd line left |
||
| 312 | state = GB_STATE_2DRAWSIDERIGHT; |
||
| 313 | |||
| 314 | case GB_STATE_2DRAWSIDERIGHT: |
||
| 315 | if(!Line(pGb->hdr.right - 1, top + 2, pGb->hdr.right - 1, pGb->hdr.bottom - 1)) |
||
| 316 | return 0; // 2nd line right |
||
| 317 | state = GB_STATE_2DRAWBOTTOM; |
||
| 318 | |||
| 319 | case GB_STATE_2DRAWBOTTOM: |
||
| 320 | if(!Line(pGb->hdr.left + 2, pGb->hdr.bottom - 1, pGb->hdr.right - 1, pGb->hdr.bottom - 1)) |
||
| 321 | return 0; // 2nd line bottom |
||
| 322 | state = GB_STATE_IDLE; |
||
| 323 | #endif |
||
| 324 | } |
||
| 325 | |||
| 326 | return (1); |
||
| 327 | } |
||
| 328 | |||
| 329 | #endif // USE_GROUPBOX |
Powered by WebSVN v2.8.3