/**************************************************************************/ /*! * @brief The function activate the new screen * @param pNewScreen - the pointer to new screen * @param bReplaceCurrent - the flag to tell function if the new screen should replace previous one in screen buffer * @return None * @note Enter new screen, remember the history if not only replacing *******************************************************************************/ void D4D_ActivateScreen(D4D_SCREEN* pNewScreen, D4D_BOOL bReplaceCurrent) { D4D_SCREEN* pOldScreen; // can not activate screen (no space left in history array) if(d4d_screenHistoryIndex >= D4D_SCREEN_HISTORY && !bReplaceCurrent) return ; if(!pNewScreen) return; // cancel key capture D4D_CaptureKeys(NULL); // deactivate current screen (if any) pOldScreen = D4D_GetActiveScreen(); if(pOldScreen != NULL) { // replacing this screen in history? if(bReplaceCurrent) d4d_screenHistoryIndex--; // note that we are sure this is >0 } // set the new screen as the active one d4d_screenHistory[d4d_screenHistoryIndex] = pNewScreen; d4d_screenHistoryIndex++; D4D_ChangeScreen(pNewScreen, pOldScreen); }
/**************************************************************************/ /*! * @brief Function invokes calibrate screen of touch screen * @return none * @note Clears the event buffer *******************************************************************************/ void D4D_CalibrateTouchScreen(void) { D4D_MouseShow(D4D_FALSE); D4D_TCH_Calibrate(D4D_COLOR_SYSTEM_FORE, D4D_COLOR_SYSTEM_BCKG); D4D_MouseShow(D4D_TRUE); D4D_InvalidateScreen(D4D_GetActiveScreen(), D4D_TRUE); }
/**************************************************************************/ /*! * @brief Function find out if the object (including compounded objects) is focused * @param pObject - pointer to the object * @return <D4D_TRUE - object has focus, D4D_FALSE - object hasn't focus>. * @note This function gets the focused object and check if it belong this object or any other * object in compounded set. *******************************************************************************/ D4D_BOOL D4D_IsMineFocus(D4D_OBJECT* pObject) { D4D_OBJECT * pFocused; if(pObject == NULL) return D4D_FALSE; if((D4D_SCREEN*)(pObject->pData->pScreen) != D4D_GetActiveScreen()) return D4D_FALSE; pFocused = (D4D_OBJECT*)D4D_GetFocusedObject((D4D_SCREEN*)(pObject->pData->pScreen)); if(pFocused == pObject) return D4D_TRUE; if((pObject->pRelations) && (pFocused->pRelations)) { // Lok for all parents - step by step while((pFocused = D4D_GetParentObject(pFocused))) { if(pObject == pFocused) return D4D_TRUE; } } return D4D_FALSE; }
/**************************************************************************/ /*! * @brief Main eGUI function. Must be periodically called in main loop/task loop. * @return none * @note This is the main function that is handling all eGUI inputs and also drawings. *******************************************************************************/ void D4D_Poll(void) { // get active screen D4D_SCREEN* pScreen; // handle keys (may change active screen) D4D_HandleKeys(); #ifdef D4D_LLD_TCH // handle Touch screen events - if any if(d4d_TouchScreen_Status & D4D_TCHSCR_STATUS_EVENTS) { D4D_ManageTouchScreenEvents(); d4d_TouchScreen_Status &= ~D4D_TCHSCR_STATUS_EVENTS; } pScreen = D4D_GetActiveScreen(); if(pScreen == NULL) return; // Handle Touch screen to screen and objects D4D_HandleTouchScreen(pScreen); #endif #ifdef D4D_LLD_MOUSE pScreen = D4D_GetActiveScreen(); if(pScreen == NULL) return; // handle mouse events D4D_HandleMouse(); #endif pScreen = D4D_GetActiveScreen(); if(pScreen == NULL) return; // call screen's main function if(pScreen->OnMain) pScreen->OnMain(); // Handle the timeticks of D4D pScreen = D4D_GetActiveScreen(); D4D_HandleTimeTicks(pScreen); // redraw all objects on active screen pScreen = D4D_GetActiveScreen(); D4D_RedrawScreen(pScreen); }
/**************************************************************************/ /*! * @brief Function switch on capturing the keys to objects * @param pObj - pointer to the object. if the parameter is handled as NULL, * the function switch off the capturing the keys to object. * @return none. * @note This function sets the object to the capture keys state. In this state the object obtains all the * keys inputs including system navigation keys (escape, up, and down). In this state the object is using * capture colors from a color scheme. To switch off from this state the active screen has to be changed or * this function has to be called with the input parameter set to NULL. *******************************************************************************/ void D4D_CaptureKeys(D4D_OBJECT_PTR pObj) { // NOTE: we need to send message, but we may just be in the middle of // message processing (very likely). This may cause problem with // the global d4d_msg object as we are changing it... // We better use the temporary memory to instanitate the message D4D_MESSAGE* pMsg = (D4D_MESSAGE*) d4d_scratchPad; if(d4d_pKeysCapturer == pObj) return; pMsg->pScreen = D4D_GetActiveScreen(); if(d4d_pKeysCapturer) { D4D_SetObjectFlags(d4d_pKeysCapturer, D4D_OBJECT_F_REDRAWSTATE, D4D_FALSE); pMsg->nMsgId = D4D_MSG_KILLCAPTURE; pMsg->pObject = d4d_pKeysCapturer; D4D_SendMessage(pMsg); d4d_pKeysCapturer = NULL; } if(pObj != NULL) { if((pObj->pData->flags & (D4D_OBJECT_F_VISIBLE | D4D_OBJECT_F_ENABLED | D4D_OBJECT_F_TABSTOP)) == (D4D_OBJECT_F_VISIBLE | D4D_OBJECT_F_ENABLED | D4D_OBJECT_F_TABSTOP)) { if(D4D_IsEnabled((D4D_OBJECT*)pObj)) { D4D_FocusSet(D4D_GetActiveScreen(), pObj); d4d_pKeysCapturer = (D4D_OBJECT*) pObj; D4D_SetObjectFlags(d4d_pKeysCapturer, D4D_OBJECT_F_REDRAWSTATE, D4D_FALSE); pMsg->nMsgId = D4D_MSG_SETCAPTURE; pMsg->pObject = d4d_pKeysCapturer; D4D_SendMessage(pMsg); } } } }
/**************************************************************************/ /*! * @brief The function return to base screen recorded in the history * @return None * @note Recall the base (first) screen in screen history buffer *******************************************************************************/ void D4D_EscapeToBaseScreen(void) { D4D_SCREEN* pOldScreen; // can not escape current screen, it is the top one if(d4d_screenHistoryIndex == 0) return; // cancel key capture D4D_CaptureKeys(NULL); // I can be sure this is not NULL pOldScreen = D4D_GetActiveScreen(); // pop the history stack d4d_screenHistoryIndex = 1; D4D_ChangeScreen(D4D_GetActiveScreen(), pOldScreen); }
/**************************************************************************/ /*! * @brief The function return to previous screen recorded in the history * @return None * @note Recall the previous screen in screen history buffer *******************************************************************************/ void D4D_EscapeScreen(void) { D4D_SCREEN* pOldScreen; // can not escape current screen, it is the top one if(d4d_screenHistoryIndex <= 1) return; // cancel key capture D4D_CaptureKeys(NULL); pOldScreen = D4D_GetActiveScreen(); // pop the history stack if(d4d_screenHistoryIndex > 1) d4d_screenHistoryIndex--; D4D_ChangeScreen(D4D_GetActiveScreen(), pOldScreen); }
/**************************************************************************/ /*! * @brief Set screen orientation function. * @param orient - the requested new orientation * @return none * @note Function change the orientation of screen, invoke complete redraw *******************************************************************************/ void D4D_SetOrientation(D4D_ORIENTATION orient) { // get active screen D4D_SCREEN* pScreen = D4D_GetActiveScreen(); D4D_LCD_SetOrientation(orient); #ifdef D4D_LLD_MOUSE D4D_MouseCenterCursor(); #endif if(pScreen) D4D_InvalidateScreen(pScreen, D4D_TRUE); }
/**************************************************************************/ /*! * @brief The function changes the current language * @param stringId - the id of new string * @return none * @note The function change to new string table if it's available. *******************************************************************************/ void D4D_ChangeStringTable(LWord stringId) { LWord i = 0; while(d4d_StringTable[i].stringTable != NULL) { if(d4d_StringTable[i].stringId == stringId) { d4d_strTableIndex = i; D4D_InvalidateScreen(D4D_GetActiveScreen(), D4D_TRUE); return; } i++; } }
/**************************************************************//*! * * Handle the keys (part of main poll call) * ******************************************************************/ void D4D_HandleKeys(void) { // get active screen D4D_SCREEN* pScreen = D4D_GetActiveScreen(); D4D_OBJECT* pFocus; D4D_KEY_SCANCODE scanCode; D4D_BOOL tmp_release; // TODO what about sending keys to Child objects?? // Check the buffer of input keys changes if(d4d_KeysBuff.writePos == d4d_KeysBuff.readPos) return; // Read the latest record in the buffer of input key event scanCode = d4d_KeysBuff.buff[d4d_KeysBuff.readPos++]; // Check the overflow of the read pointer of readed input keys if(d4d_KeysBuff.readPos >= D4D_KEYS_BUFF_LENGTH) d4d_KeysBuff.readPos = 0; tmp_release = (D4D_BOOL)(scanCode & D4D_KEY_SCANCODE_RELEASEMASK); scanCode &= ~D4D_KEY_SCANCODE_RELEASEMASK; // do we handle the keys ourselves (to navigate across the screen) ? if(!d4d_pKeysCapturer) { if((scanCode & D4D_KEY_SCANCODE_RELEASEMASK) == 0) { // escape the screen? if(scanCode == D4D_KEY_SCANCODE_ESC) { if(tmp_release == 0) D4D_EscapeScreen(); return; } // focus previous object on the screen? else if(scanCode == D4D_KEY_FUNC_FOCUS_PREV) { if(tmp_release == 0) D4D_FocusPrevObject(pScreen); return; } // focus next object on the screen? else if(scanCode == D4D_KEY_FUNC_FOCUS_NEXT) { if(tmp_release == 0) D4D_FocusNextObject(pScreen, D4D_FALSE); return; } } } // does the object get the key events? // yes, invoke the key events to the active object pFocus = (D4D_OBJECT*) (d4d_pKeysCapturer ? d4d_pKeysCapturer : D4D_GetFocusedObject(pScreen)); if((pFocus->pData->flags & (D4D_OBJECT_F_VISIBLE | D4D_OBJECT_F_ENABLED | D4D_OBJECT_F_TABSTOP)) == (D4D_OBJECT_F_VISIBLE | D4D_OBJECT_F_ENABLED | D4D_OBJECT_F_TABSTOP)) { if(D4D_IsEnabled(pFocus)) { // prepare the message d4d_msg.pScreen = pScreen; d4d_msg.pObject = pFocus; if(tmp_release == 0) d4d_msg.nMsgId = D4D_MSG_KEYDOWN; // if key was pressed down? else d4d_msg.nMsgId = D4D_MSG_KEYUP; // if key was released up? d4d_msg.prm.key = (D4D_KEY_SCANCODE)(scanCode & D4D_KEY_SCANCODE_KEYMASK); D4D_SendMessageBack(&d4d_msg); } } }