| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 32 | kaklik | /***************************************************************************** |
| 2 | * Module for Microchip Graphics Library |
||
| 3 | * GOL Layer |
||
| 4 | * Button |
||
| 5 | ***************************************************************************** |
||
| 6 | * FileName: Button.h |
||
| 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 | * Paolo A. Tamayo 11/12/07 Version 1.0 release |
||
| 40 | *****************************************************************************/ |
||
| 41 | #ifndef _BUTTON_H |
||
| 42 | #define _BUTTON_H |
||
| 43 | |||
| 44 | #include <Graphics\GOL.h> |
||
| 45 | |||
| 46 | /********************************************************************* |
||
| 47 | * Object States Definition: |
||
| 48 | *********************************************************************/ |
||
| 49 | #define BTN_FOCUSED 0x0001 // Bit for focus state. |
||
| 50 | #define BTN_DISABLED 0x0002 // Bit for disabled state. |
||
| 51 | #define BTN_PRESSED 0x0004 // Bit for press state. |
||
| 52 | #define BTN_TOGGLE 0x0008 // Bit to indicate button will have a toggle behavior. |
||
| 53 | #define BTN_TEXTRIGHT 0x0010 // Bit to indicate text is right aligned. |
||
| 54 | #define BTN_TEXTLEFT 0x0020 // Bit to indicate text is left aligned. |
||
| 55 | #define BTN_TEXTBOTTOM 0x0040 // Bit to indicate text is top aligned. |
||
| 56 | #define BTN_TEXTTOP 0x0080 // Bit to indicate text is bottom aligned. |
||
| 57 | #define BTN_TWOTONE 0x0100 // Bit to indicate the button is a two tone type. |
||
| 58 | |||
| 59 | // Note that if bits[7:4] are all zero text is centered. |
||
| 60 | #define BTN_DRAW_FOCUS 0x2000 // Bit to indicate focus must be redrawn. |
||
| 61 | #define BTN_DRAW 0x4000 // Bit to indicate button must be redrawn. |
||
| 62 | #define BTN_HIDE 0x8000 // Bit to indicate button must be removed from screen. |
||
| 63 | #define BTN_REMOVE 0x8000 |
||
| 64 | |||
| 65 | /********************************************************************* |
||
| 66 | * Overview: Defines the parameters required for a button Object. |
||
| 67 | * The following relationships of the parameters determines |
||
| 68 | * the general shape of the button: |
||
| 69 | * 1. Width is determined by right - left. |
||
| 70 | * 2. Height is determined by top - bottom. |
||
| 71 | * 3. Radius - specifies if the button will have a rounded |
||
| 72 | * edge. If zero then the button will have |
||
| 73 | * sharp (cornered) edge. |
||
| 74 | * 4. If 2*radius = height = width, the button is a circular button. |
||
| 75 | * |
||
| 76 | *********************************************************************/ |
||
| 77 | typedef struct |
||
| 78 | { |
||
| 79 | OBJ_HEADER hdr; // Generic header for all Objects (see OBJ_HEADER). |
||
| 80 | SHORT radius; // Radius for rounded buttons. |
||
| 81 | SHORT textWidth; // Computed text width, done at creation. |
||
| 82 | SHORT textHeight; // Computed text height, done at creation. |
||
| 83 | XCHAR *pText; // Pointer to the text used. |
||
| 84 | void *pBitmap; // Pointer to bitmap used. |
||
| 85 | } BUTTON; |
||
| 86 | |||
| 87 | /********************************************************************* |
||
| 88 | * Macros: BtnSetBitmap(pB, pBitmap) |
||
| 89 | * |
||
| 90 | * Overview: This macro sets the bitmap used in the object. |
||
| 91 | * The size of the bitmap must match the face of the button. |
||
| 92 | * |
||
| 93 | * PreCondition: none |
||
| 94 | * |
||
| 95 | * Input: pB - Pointer to the object. |
||
| 96 | * pBitmap - Pointer to the bitmap to be used. |
||
| 97 | * |
||
| 98 | * Output: none |
||
| 99 | * |
||
| 100 | * Example: |
||
| 101 | * <CODE> |
||
| 102 | * extern BITMAP_FLASH myIcon; |
||
| 103 | * BUTTON *pButton; |
||
| 104 | * |
||
| 105 | * BtnSetBitmap(pButton , &myIcon); |
||
| 106 | * </CODE> |
||
| 107 | * |
||
| 108 | * Side Effects: none |
||
| 109 | * |
||
| 110 | ********************************************************************/ |
||
| 111 | #define BtnSetBitmap(pB, pBtmap) ((BUTTON *)pB)->pBitmap = pBtmap |
||
| 112 | |||
| 113 | /********************************************************************* |
||
| 114 | * Macros: BtnGetBitmap(pB) |
||
| 115 | * |
||
| 116 | * Overview: This macro returns the location of the currently |
||
| 117 | * used bitmap for the object. |
||
| 118 | * |
||
| 119 | * PreCondition: none |
||
| 120 | * |
||
| 121 | * Input: pB - Pointer to the object. |
||
| 122 | * |
||
| 123 | * Output: Returns the pointer to the current bitmap used. |
||
| 124 | * |
||
| 125 | * Example: |
||
| 126 | * <CODE> |
||
| 127 | * BUTTON *pButton; |
||
| 128 | * BITMAP_FLASH *pUsedBitmap; |
||
| 129 | * |
||
| 130 | * pUsedbitmap = BtnGetBitmap(pButton); |
||
| 131 | * </CODE> |
||
| 132 | * |
||
| 133 | * Side Effects: none |
||
| 134 | * |
||
| 135 | ********************************************************************/ |
||
| 136 | #define BtnGetBitmap(pB) ((BUTTON *)pB)->pBitmap |
||
| 137 | |||
| 138 | /********************************************************************* |
||
| 139 | * Macros: BtnGetText(pB) |
||
| 140 | * |
||
| 141 | * Overview: This macro returns the address of the current |
||
| 142 | * text string used for the object. |
||
| 143 | * |
||
| 144 | * PreCondition: none |
||
| 145 | * |
||
| 146 | * Input: pB - Pointer to the object. |
||
| 147 | * |
||
| 148 | * Output: Returns pointer to the text string being used. |
||
| 149 | * |
||
| 150 | * Example: |
||
| 151 | * <CODE> |
||
| 152 | * XCHAR *pChar; |
||
| 153 | * BUTTON Button[2]; |
||
| 154 | * |
||
| 155 | * pChar = BtnGetText(Button[0]); |
||
| 156 | * </CODE> |
||
| 157 | * |
||
| 158 | * Side Effects: none |
||
| 159 | * |
||
| 160 | ********************************************************************/ |
||
| 161 | #define BtnGetText(pB) ((BUTTON *)pB)->pText |
||
| 162 | |||
| 163 | /********************************************************************* |
||
| 164 | * Function: BtnSetText(BUTTON *pB, XCHAR *pText) |
||
| 165 | * |
||
| 166 | * Overview: This function sets the string used for the object. |
||
| 167 | * |
||
| 168 | * PreCondition: none |
||
| 169 | * |
||
| 170 | * Input: pB - The pointer to the object whose text will be modified. |
||
| 171 | * pText - Pointer to the text that will be used. |
||
| 172 | * |
||
| 173 | * Output: none |
||
| 174 | * |
||
| 175 | * Example: |
||
| 176 | * <CODE> |
||
| 177 | * XCHAR Label0[] = ON; |
||
| 178 | * XCHAR Label1[] = OFF; |
||
| 179 | * BUTTON Button[2]; |
||
| 180 | * |
||
| 181 | * BtnSetText(Button[0], Label0); |
||
| 182 | * BtnSetText(Button[1], Label1); |
||
| 183 | * </CODE> |
||
| 184 | * |
||
| 185 | * Side Effects: none |
||
| 186 | * |
||
| 187 | ********************************************************************/ |
||
| 188 | void BtnSetText(BUTTON * pB, XCHAR * pText); |
||
| 189 | |||
| 190 | /********************************************************************* |
||
| 191 | * Function: BUTTON *BtnCreate(WORD ID, SHORT left, SHORT top, SHORT right, |
||
| 192 | * SHORT bottom, SHORT radius, void *pBitmap, XCHAR *pText, |
||
| 193 | * GOL_SCHEME *pScheme) |
||
| 194 | * |
||
| 195 | * Overview: This function creates a BUTTON object with the parameters given. |
||
| 196 | * It automatically attaches the new object into a global linked list of |
||
| 197 | * objects and returns the address of the object. |
||
| 198 | * |
||
| 199 | * PreCondition: none |
||
| 200 | * |
||
| 201 | * Input: ID - Unique user defined ID for the object instance. |
||
| 202 | * left - Left most position of the object. |
||
| 203 | * top - Top most position of the object. |
||
| 204 | * right - Right most position of the object. |
||
| 205 | * bottom - Bottom most position of the object. |
||
| 206 | * radius - Radius of the rounded edge. |
||
| 207 | * state - Sets the initial state of the object. |
||
| 208 | * pBitmap - Pointer to the bitmap used on the face of the button |
||
| 209 | * dimension of the bitmap must match the dimension of the |
||
| 210 | * button. |
||
| 211 | * pText - Pointer to the text of the button. |
||
| 212 | * pScheme - Pointer to the style scheme used. |
||
| 213 | * |
||
| 214 | * Output: Returns the pointer to the object created. |
||
| 215 | * |
||
| 216 | * Example: |
||
| 217 | * <CODE> |
||
| 218 | * GOL_SCHEME *pScheme; |
||
| 219 | * BUTTON *buttons[3]; |
||
| 220 | * WORD state; |
||
| 221 | * |
||
| 222 | * pScheme = GOLCreateScheme(); |
||
| 223 | * state = BTN_DRAW; |
||
| 224 | * |
||
| 225 | * buttons[0] = BtnCreate(1,20,64,50,118,0, state, NULL, "ON", pScheme); |
||
| 226 | * // check if button 0 is created |
||
| 227 | * if (buttons[0] == NULL) |
||
| 228 | * return 0; |
||
| 229 | * |
||
| 230 | * buttons[1] = BtnCreate(2,52,64,82,118,0, state, NULL, "OFF", pScheme); |
||
| 231 | * // check if button 1 is created |
||
| 232 | * if (buttons[1] == NULL) |
||
| 233 | * return 0; |
||
| 234 | * |
||
| 235 | * buttons[2] = BtnCreate(3,84,64,114,118,0, state, NULL, "HI", pScheme); |
||
| 236 | * // check if button 2 is created |
||
| 237 | * if (buttons[2] == NULL) |
||
| 238 | * return 0; |
||
| 239 | * |
||
| 240 | * return 1; |
||
| 241 | * </CODE> |
||
| 242 | * |
||
| 243 | * Side Effects: none |
||
| 244 | * |
||
| 245 | ********************************************************************/ |
||
| 246 | BUTTON *BtnCreate |
||
| 247 | ( |
||
| 248 | WORD ID, |
||
| 249 | SHORT left, |
||
| 250 | SHORT top, |
||
| 251 | SHORT right, |
||
| 252 | SHORT bottom, |
||
| 253 | SHORT radius, |
||
| 254 | WORD state, |
||
| 255 | void *pBitmap, |
||
| 256 | XCHAR *pText, |
||
| 257 | GOL_SCHEME *pScheme |
||
| 258 | ); |
||
| 259 | |||
| 260 | /********************************************************************* |
||
| 261 | * Function: BtnTranslateMsg(BUTTON *pB, GOL_MSG *pMsg) |
||
| 262 | * |
||
| 263 | * Overview: This function evaluates the message from a user if the |
||
| 264 | * message will affect the object or not. The table below enumerates the translated |
||
| 265 | * messages for each event of the touch screen and keyboard inputs. |
||
| 266 | * |
||
| 267 | * <TABLE> |
||
| 268 | * Translated Message Input Source Set/Clear State Bit Description |
||
| 269 | * ################## ############ ####################### ################################################################################################################################################################## |
||
| 270 | * BTN_MSG_PRESSED Touch Screen EVENT_PRESS, EVENT_MOVE If events occurs and the x,y position falls in the face of the button while the button is not pressed. |
||
| 271 | * Keyboard EVENT_KEYSCAN If event occurs and parameter1 passed matches the objects ID and parameter 2 passed matches SCAN_CR_PRESSED or SCAN_SPACE_PRESSED while the button is not pressed. |
||
| 272 | * BTN_MSG_STILLPRESSED Touch Screen EVENT_STILLPRESS If event occurs and and the x,y position falls in the face of the button. Current state of the button is not checked. |
||
| 273 | * BTN_MSG_RELEASED Touch Screen EVENT_RELEASE If the event occurs and the x,y position falls in the face of the button while the button is pressed. |
||
| 274 | * Keyboard EVENT_KEYSCAN If event occurs and parameter1 passed matches the objects ID and parameter 2 passed matches SCAN_CR_RELEASED or SCAN_SPACE_RELEASED while the button is pressed. |
||
| 275 | * BTN_MSG_CANCELPRESS Touch Screen EVENT_MOVE If the event occurs outside the face of the button and the button is currently pressed. |
||
| 276 | * OBJ_MSG_INVALID Any Any If the message did not affect the object. |
||
| 277 | * </TABLE> |
||
| 278 | * |
||
| 279 | * PreCondition: none |
||
| 280 | * |
||
| 281 | * Input: pB - The pointer to the object where the message will be |
||
| 282 | * evaluated to check if the message will affect the object. |
||
| 283 | * pMsg - Pointer to the message struct containing the message from |
||
| 284 | * the user interface. |
||
| 285 | * |
||
| 286 | * Output: Returns the translated message depending on the received GOL message: |
||
| 287 | * - BTN_MSG_PRESSED Button is pressed |
||
| 288 | * - BTN_MSG_RELEASED Button is released |
||
| 289 | * - BTN_MSG_CANCELPRESS Button will be released, user cancels press action on the button |
||
| 290 | * - OBJ_MSG_INVALID Button is not affected |
||
| 291 | * |
||
| 292 | * Example: |
||
| 293 | * <CODE> |
||
| 294 | * void MyGOLMsg(GOL_MSG *pMsg){ |
||
| 295 | * |
||
| 296 | * OBJ_HEADER *pCurrentObj; |
||
| 297 | * WORD objMsg; |
||
| 298 | * |
||
| 299 | * if(pMsg->uiEvent == EVENT_INVALID) |
||
| 300 | * return; |
||
| 301 | * pCurrentObj = GOLGetList(); |
||
| 302 | * |
||
| 303 | * while(pCurrentObj != NULL){ |
||
| 304 | * // If the object must be redrawn |
||
| 305 | * // It cannot accept message |
||
| 306 | * if(!IsObjUpdated(pCurrentObj)){ |
||
| 307 | * switch(pCurrentObj->type){ |
||
| 308 | * case OBJ_BUTTON: |
||
| 309 | * objMsg = BtnTranslateMsg((BUTTON*)pCurrentObj, pMsg); |
||
| 310 | * if(objMsg == OBJ_MSG_INVALID) |
||
| 311 | * break; |
||
| 312 | * if(GOLMsgCallback(objMsg,pCurrentObj,pMsg)) |
||
| 313 | * BtnMsgDefault(objMsg,(BUTTON*)pCurrentObj); |
||
| 314 | * break; |
||
| 315 | * case OBJ_SLIDER: |
||
| 316 | * objMsg = SldTranslateMsg((SLIDER*)pCurrentObj, pMsg); |
||
| 317 | * if(objMsg == OBJ_MSG_INVALID) |
||
| 318 | * break; |
||
| 319 | * if(GOLMsgCallback(objMsg,pCurrentObj,pMsg)) |
||
| 320 | * SldMsgDefault(objMsg,(SLIDER*)pCurrentObj); |
||
| 321 | * break; |
||
| 322 | * default: break; |
||
| 323 | * } |
||
| 324 | * } |
||
| 325 | * } |
||
| 326 | * pCurrentObj = pCurrentObj->pNxtObj; |
||
| 327 | * } |
||
| 328 | * </CODE> |
||
| 329 | * |
||
| 330 | * Side Effects: none |
||
| 331 | * |
||
| 332 | ********************************************************************/ |
||
| 333 | WORD BtnTranslateMsg(BUTTON *pB, GOL_MSG *pMsg); |
||
| 334 | |||
| 335 | /********************************************************************* |
||
| 336 | * Function: BtnMsgDefault(WORD translatedMsg, BUTTON *pB, GOL_MSG* pMsg) |
||
| 337 | * |
||
| 338 | * Overview: This function performs the actual state change |
||
| 339 | * based on the translated message given. The following state changes |
||
| 340 | * are supported: |
||
| 341 | * <TABLE> |
||
| 342 | * Translated Message Input Source Set/Clear State Bit Description |
||
| 343 | * ################## ############ ###### ########### |
||
| 344 | * BTN_MSG_PRESSED Touch Screen, Set BTN_PRESSED Button will be redrawn in the pressed state. |
||
| 345 | * Keyboard |
||
| 346 | * BTN_MSG_RELEASED Touch Screen, Clear BTN_PRESSED Button will be redrawn in the unpressed state. |
||
| 347 | * Keyboard |
||
| 348 | * BTN_MSG_CANCELPRESS Touch Screen, Clear BTN_PRESSED Button will be redrawn in the unpressed state. |
||
| 349 | * |
||
| 350 | * </TABLE> |
||
| 351 | * |
||
| 352 | * PreCondition: none |
||
| 353 | * |
||
| 354 | * Input: translatedMsg - The translated message. |
||
| 355 | * pB - The pointer to the object whose state will be modified. |
||
| 356 | * pMsg - The pointer to the GOL message. |
||
| 357 | * |
||
| 358 | * Output: none |
||
| 359 | * |
||
| 360 | * Example: |
||
| 361 | * See BtnTranslateMsg() example. |
||
| 362 | * |
||
| 363 | * Side Effects: none |
||
| 364 | * |
||
| 365 | ********************************************************************/ |
||
| 366 | void BtnMsgDefault(WORD translatedMsg, BUTTON *pB, GOL_MSG *pMsg); |
||
| 367 | |||
| 368 | /********************************************************************* |
||
| 369 | * Function: WORD BtnDraw(BUTTON *pB) |
||
| 370 | * |
||
| 371 | * Overview: This function renders the object on the screen using |
||
| 372 | * the current parameter settings. Location of the object is |
||
| 373 | * determined by the left, top, right and bottom parameters. |
||
| 374 | * The colors used are dependent on the state of the object. |
||
| 375 | * The font used is determined by the style scheme set. |
||
| 376 | * |
||
| 377 | * The text on the face of the button is drawn on top of |
||
| 378 | * the bitmap. Text is always rendered centered on the face |
||
| 379 | * of the button. |
||
| 380 | * |
||
| 381 | * When rendering objects of the same type, each object |
||
| 382 | * must be rendered completely before the rendering of the |
||
| 383 | * next object is started. This is to avoid incomplete |
||
| 384 | * object rendering. |
||
| 385 | * |
||
| 386 | * PreCondition: Object must be created before this function is called. |
||
| 387 | * |
||
| 388 | * Input: pB - Pointer to the object to be rendered. |
||
| 389 | * |
||
| 390 | * Output: Returns the status of the drawing |
||
| 391 | * - 1 - If the rendering was completed and |
||
| 392 | * - 0 - If the rendering is not yet finished. |
||
| 393 | * Next call to the function will resume the |
||
| 394 | * rendering on the pending drawing state. |
||
| 395 | * |
||
| 396 | * Example: |
||
| 397 | * <CODE> |
||
| 398 | * void MyGOLDraw(){ |
||
| 399 | * static OBJ_HEADER *pCurrentObj = NULL; |
||
| 400 | * int done; |
||
| 401 | * |
||
| 402 | * // There are no objects |
||
| 403 | * if(GOLGetList() == NULL) |
||
| 404 | * return; |
||
| 405 | * |
||
| 406 | * // If it's last object jump to head |
||
| 407 | * if(pCurrentObj == NULL) |
||
| 408 | * pCurrentObj = GOLGetList(); |
||
| 409 | * |
||
| 410 | * done = 0; |
||
| 411 | * |
||
| 412 | * // this only process Button and Window |
||
| 413 | * while(pCurrentObj != NULL){ |
||
| 414 | * // check if object state indicates redrawing |
||
| 415 | * if(pCurrentObj->state&0xFC00) { |
||
| 416 | * switch(pCurrentObj->type){ |
||
| 417 | * case OBJ_BUTTON: |
||
| 418 | * done = BtnDraw((BUTTON*)pCurrentObj); |
||
| 419 | * break; |
||
| 420 | * case OBJ_WINDOW: |
||
| 421 | * done = WndDraw((WINDOW*)pCurrentObj); |
||
| 422 | * break; |
||
| 423 | * default: |
||
| 424 | * done = 1; |
||
| 425 | * break; |
||
| 426 | * } |
||
| 427 | * if(done){ |
||
| 428 | * // reset only the state if drawing was finished |
||
| 429 | * pCurrentObj->state = 0; |
||
| 430 | * }else{ |
||
| 431 | * // done processing the list |
||
| 432 | * return; |
||
| 433 | * } |
||
| 434 | * } |
||
| 435 | * // go to next object |
||
| 436 | * pCurrentObj = pCurrentObj->pNxtObj; |
||
| 437 | * } |
||
| 438 | * } |
||
| 439 | * </CODE> |
||
| 440 | * |
||
| 441 | * Side Effects: none |
||
| 442 | * |
||
| 443 | ********************************************************************/ |
||
| 444 | WORD BtnDraw(BUTTON *pB); |
||
| 445 | #endif // _BUTTON_H |
Powered by WebSVN v2.8.3