/********************************************************************* * Function: BtnMsgDefault(WORD translatedMsg, BUTTON *pB, GOL_MSG* pMsg) * * * Notes: This the default operation to change the state of the button. * Called inside GOLMsg() when GOLMsgCallback() returns a 1. * ********************************************************************/ void BtnMsgDefault(WORD translatedMsg, BUTTON *pB, GOL_MSG* pMsg){ #ifdef USE_FOCUS #ifdef USE_TOUCHSCREEN if(pMsg->type == TYPE_TOUCHSCREEN){ if(!GetState(pB,BTN_FOCUSED)){ GOLSetFocus((OBJ_HEADER*)pB); } } #endif #endif switch(translatedMsg){ case BTN_MSG_PRESSED: SetState(pB, BTN_PRESSED|BTN_DRAW); // set pressed and redraw break; case BTN_MSG_RELEASED: ClrState(pB, BTN_PRESSED); // reset pressed SetState(pB, BTN_DRAW); // redraw break; } }
/********************************************************************* * Function: BUTTON *BtnCreate(WORD ID, SHORT left, SHORT top, SHORT right, * SHORT bottom, SHORT radius, void *pBitmap, XCHAR *pText, * GOL_SCHEME *pScheme) * * * Notes: Creates a BUTTON object and adds it to the current active list. * If the creation is successful, the pointer to the created Object * is returned. If not successful, NULL is returned. * ********************************************************************/ BUTTON *BtnCreate( WORD ID, SHORT left, SHORT top, SHORT right, SHORT bottom, SHORT radius, WORD state, void *pBitmap, XCHAR *pText, GOL_SCHEME *pScheme) { BUTTON *pB = NULL; pB = malloc(sizeof(BUTTON)); if (pB == NULL) return NULL; pB->hdr.ID = ID; // unique id assigned for referencing pB->hdr.pNxtObj = NULL; // initialize pointer to NULL pB->hdr.type = OBJ_BUTTON; // set object type pB->hdr.left = left; // left position pB->hdr.top = top; // top position pB->hdr.right = right; // right position pB->hdr.bottom = bottom; // bottom position pB->radius = radius; // radius pB->pBitmap = pBitmap; // location of bitmap pB->pText = pText; // location of the text pB->hdr.state = state; // state // Set the color scheme to be used if (pScheme == NULL) pB->hdr.pGolScheme = _pDefaultGolScheme; else pB->hdr.pGolScheme = (GOL_SCHEME *)pScheme; pB->textWidth = 0; pB->textHeight = 0; if (pB->pText != NULL) { // Calculate the text width & height pB->textWidth = GetTextWidth(pText, pB->hdr.pGolScheme->pFont); pB->textHeight = GetTextHeight(pB->hdr.pGolScheme->pFont); } GOLAddObject((OBJ_HEADER*) pB); #ifdef USE_FOCUS if(GetState(pB,BTN_FOCUSED)) GOLSetFocus((OBJ_HEADER*)pB); #endif return pB; }
/********************************************************************* * Function: CbMsgDefault(WORD translatedMsg, CHECKBOX *pCb, GOL_MSG* pMsg) * * Overview: Changes the state of the check box by default. * ********************************************************************/ void CbMsgDefault(WORD translatedMsg, CHECKBOX* pCb, GOL_MSG* pMsg) { #ifdef USE_FOCUS #ifdef USE_TOUCHSCREEN if(pMsg->type == TYPE_TOUCHSCREEN) { if(!GetState(pCb,CB_FOCUSED)) { GOLSetFocus((OBJ_HEADER*)pCb); } } #endif #endif switch(translatedMsg) { case CB_MSG_CHECKED: SetState(pCb, CB_CHECKED|CB_DRAW_CHECK); // Set checked and redraw break; case CB_MSG_UNCHECKED: ClrState(pCb, CB_CHECKED); // Reset check SetState(pCb, CB_DRAW_CHECK); // Redraw break; } }
/************************************************************************ * Function: void SideButtonsMsg(GOL_MSG* msg) * * Overview: this function checks buttons state and creates GOL messages. * S3 and S4 are used for ARROW UP PRESSED and ARROW DOWN PRESSED * messages. S6 moves focus to the next control. * S5 creates CARRIGE RETURN PRESSED/RELEASED messages. * * Input: pointer to the GOL message structure * * Output: none * ************************************************************************/ void SideButtonsMsg(GOL_MSG *msg) { // Previous states of the buttons static char S3 = 1; static char S4 = 1; static char S5 = 1; static char S6 = 1; char state; OBJ_HEADER *obj; msg->uiEvent = EVENT_INVALID; /** * Change Focus button * Explorer 16 + GFX PICTail - S6 (8 bit PMP) * Starter Kit + GFX PICTail - S1 or S2 (8 bit PMP) * Multimedia Expansion Board - left or right * DA210 Developement Board - S2 or S3 **/ state = GetHWButtonFocus(); if(S6 != state) { if(S6) { // Get pointer to the next object should be focused obj = GOLGetFocusNext(); if(obj != NULL) { GOLSetFocus(obj); Beep(); } } S6 = state; return; } /** * Carriage Return button * Explorer 16 + GFX PICTail - S3 (8 bit PMP) * Explorer 16 + GFX PICTail - S5 (16 bit PMP) * Starter Kit + GFX PICTail - S0 (8 bit PMP) * Multimedia Expansion Board - Fire Button * DA210 Developement Board - S1 * NOTE: Starter Kit + GFX PICTail will switches are shared * with the 16 bit PMP data bus. **/ state = GetHWButtonCR(); if(S5 != state) { // Get pointer to the focused object obj = GOLGetFocus(); if(obj != NULL) { if(S5) { msg->type = TYPE_KEYBOARD; msg->uiEvent = EVENT_KEYSCAN; msg->param1 = obj->ID; msg->param2 = SCAN_CR_PRESSED; } else { msg->type = TYPE_KEYBOARD; msg->uiEvent = EVENT_KEYSCAN; msg->param1 = obj->ID; msg->param2 = SCAN_CR_RELEASED; } } S5 = state; return; } /** * Scan down button * Explorer 16 + GFX PICTail - S4 (8 bit PMP) * Multimedia Expansion Board - Down joystick Button **/ state = GetHWButtonScanDown(); if(S3 != state) { // Get pointer to the focused object obj = GOLGetFocus(); if(obj != NULL) { if(S3) { msg->type = TYPE_KEYBOARD; msg->uiEvent = EVENT_KEYSCAN; msg->param1 = obj->ID; msg->param2 = SCAN_DOWN_PRESSED; } } S3 = state; return; } /** * Scan up button * Explorer 16 + GFX PICTail - S5 (8 bit PMP) * Multimedia Expansion Board - Up joystick Button **/ state = GetHWButtonScanUp(); if(S4 != state) { // Get pointer to the focused object obj = GOLGetFocus(); if(obj != NULL) { if(S4) { msg->type = TYPE_KEYBOARD; msg->uiEvent = EVENT_KEYSCAN; msg->param1 = obj->ID; msg->param2 = SCAN_UP_PRESSED; } } S4 = state; return; } }
void AN1227ProcessKeyBoard(void) { // Keyboard driver if(GOLGetFocus() != NULL) // if there’s a widget in focus send a message { // check if the button has changed its state if(GetHWButtonCR() != previousKey1State) { if(previousKey1State) { // if GetHWButtonCR equals zero it means the button is pressed AN1227msg.type = TYPE_KEYBOARD; AN1227msg.uiEvent = EVENT_KEYSCAN; // the focused button will receive the message AN1227msg.param1 = GetObjID(GOLGetFocus()); AN1227msg.param2 = SCAN_CR_PRESSED; } else { // if GetHWButtonCR equals one it means the button is released AN1227msg.type = TYPE_KEYBOARD; AN1227msg.uiEvent = EVENT_KEYSCAN; // the focused button will receive the message AN1227msg.param1 = GetObjID(GOLGetFocus()); AN1227msg.param2 = SCAN_CR_RELEASED; } // end of else // state of the button was changed previousKey1State = !previousKey1State; // pass the message to the graphics library GOLMsg(&AN1227msg); } // end of if } // end of if // check if the button has changed its state if(GetHWButtonFocus() != previousKey2State) { if(previousKey2State) { // if GetHWButtonFocus() equals zero it means the button is pressed // get the object can be focused next pFocusedObj = GOLGetFocusNext(); // move focus GOLSetFocus(pFocusedObj); } else { // if GetHWButtonFocus()equals one it means the button is released } // end of else // state of the button was changed previousKey2State = !previousKey2State; // pass the message to the graphics library GOLMsg(&AN1227msg); } // end of if }