static void D4D_CnslUpdateScrollbars(D4D_OBJECT* pThis) { D4D_CNSL_DATA* pData = D4D_GET_CONSOLE_DATA(pThis); if(!(D4D_GET_LIST_BOX_SCROLL_BAR_HOR(pThis)->pData->flags & D4D_OBJECT_F_VISIBLE) && !(D4D_GET_LIST_BOX_SCROLL_BAR_VER(pThis)->pData->flags & D4D_OBJECT_F_VISIBLE)) return; D4D_CnslValue2Coor(pThis); if(D4D_GET_LIST_BOX_SCROLL_BAR_HOR(pThis)->pData->flags & D4D_OBJECT_F_VISIBLE) { if(pData->cursorPos.x < _calc.charArrSize.cx) D4D_ScrlBrSetPosition(D4D_GET_LIST_BOX_SCROLL_BAR_HOR(pThis), 0); else D4D_ScrlBrSetPosition(D4D_GET_LIST_BOX_SCROLL_BAR_HOR(pThis), (D4D_INDEX)(pData->cursorPos.x - _calc.charArrSize.cx / 2)); } if(D4D_GET_LIST_BOX_SCROLL_BAR_VER(pThis)->pData->flags & D4D_OBJECT_F_VISIBLE) { if(pData->cursorPos.y < _calc.charArrSize.cy) D4D_ScrlBrSetPosition(D4D_GET_LIST_BOX_SCROLL_BAR_VER(pThis), 0); else D4D_ScrlBrSetPosition(D4D_GET_LIST_BOX_SCROLL_BAR_VER(pThis), (D4D_INDEX)(pData->cursorPos.y - _calc.charArrSize.cy + 1)); } }
/**************************************************************************/ /*! * @brief The function move the scroll bars on to new position if it's applicable * @param pObj - pointer to the console object * @param hor - new position of horizontal scroll bar * @param ver - new position of vertical scroll bar * @return none * @note none *******************************************************************************/ void D4D_CnslSetScrollBarPosition(D4D_OBJECT_PTR pObj, D4D_INDEX hor, D4D_INDEX ver) { if(pObj == NULL) return; if(D4D_GET_LIST_BOX_SCROLL_BAR_HOR(pObj)->pData->flags & D4D_OBJECT_F_VISIBLE) D4D_ScrlBrSetPosition(D4D_GET_LIST_BOX_SCROLL_BAR_HOR(pObj), hor); if(D4D_GET_LIST_BOX_SCROLL_BAR_VER(pObj)->pData->flags & D4D_OBJECT_F_VISIBLE) D4D_ScrlBrSetPosition(D4D_GET_LIST_BOX_SCROLL_BAR_VER(pObj), ver); }
/******************************************************* * * MENU object focus previous item routine * *******************************************************/ static void D4D_MenuFocusPreviousItem(D4D_OBJECT* pThis) { D4D_MENU* pMenu = D4D_GET_MENU(pThis); // Compute all tempoarary values D4D_MenuValue2Coor(pThis); pMenu->pData->ix--; if(_calc.itemsCnt >= _calc.posCnt) { if(pMenu->pData->ix < 0) { pMenu->pData->ix = (D4D_MENU_INDEX)(_calc.itemsCnt - 1); pMenu->pData->page_ix = (D4D_MENU_INDEX)(_calc.itemsCnt - _calc.posCnt); }else if(pMenu->pData->ix - pMenu->pData->page_ix < 0) { pMenu->pData->page_ix--; } D4D_ScrlBrSetPosition(D4D_GET_MENU_SCROLL_BAR_HOR(pThis), pMenu->pData->page_ix); } else { if(pMenu->pData->ix < 0) { pMenu->pData->ix = (D4D_MENU_INDEX)(_calc.itemsCnt - 1); } } }
/******************************************************* * * MENU object focus next item routine * *******************************************************/ static void D4D_MenuFocusNextItem(D4D_OBJECT* pThis) { D4D_MENU* pMenu = D4D_GET_MENU(pThis); // Compute all tempoarary values D4D_MenuValue2Coor(pThis); pMenu->pData->ix++; if(_calc.itemsCnt >= _calc.posCnt) { if(pMenu->pData->ix >= _calc.itemsCnt) { pMenu->pData->ix = 0; pMenu->pData->page_ix = 0; }else if(pMenu->pData->ix - pMenu->pData->page_ix > (_calc.posCnt - 1)) { pMenu->pData->page_ix++; } D4D_ScrlBrSetPosition(D4D_GET_MENU_SCROLL_BAR_HOR(pThis), pMenu->pData->page_ix); } else { if(pMenu->pData->ix >= _calc.itemsCnt) { pMenu->pData->ix = 0; } } }
/**************************************************************************/ /*! * @brief The function change the scroll bar position * @param pObj - pointer to the scroll_bar object * @param change - change of scroll bar position * @return none * @note none *******************************************************************************/ void D4D_ScrlBrChangePosition(D4D_OBJECT_PTR pObj, D4D_INDEX_DELTA change) { D4D_SCROLL_BAR* pScrlBr = D4D_GET_SCROLL_BAR(pObj); D4D_SCRLBAR_DATA* pData = pScrlBr->pData; D4D_INDEX_DELTA tmp_pos = (D4D_INDEX_DELTA)(change + pData->position); if(tmp_pos < 0) tmp_pos = 0; D4D_ScrlBrSetPosition(pObj, (D4D_INDEX)tmp_pos); }
/**************************************************************************/ /*! * @brief Function select new item by index * @param pThis - pointer to the menu object * @param ix - index of item that should be selected * @return none * @note none *******************************************************************************/ void D4D_MenuSetIndex(D4D_OBJECT* pThis, D4D_MENU_INDEX ix) { D4D_MENU* pMenu = D4D_GET_MENU(pThis); if(pThis == NULL) return; if(ix > D4D_GetItemsCount(pMenu)) ix = D4D_GetItemsCount(pMenu); pMenu->pData->ix = ix; pMenu->pData->page_ix = ix; D4D_ScrlBrSetPosition(D4D_GET_MENU_SCROLL_BAR_HOR(pThis), pMenu->pData->page_ix); }
static D4D_BOOL D4D_TextBoxScrollBarSetup(D4D_OBJECT* pObject) { // Try to check if the Text Box needs scroll Bar // Switch off possible scroll bar in refresh case D4D_GET_TEXTBOX_SCROLL_BAR_HOR(pObject)->pData->flags &= ~D4D_OBJECT_F_VISIBLE; D4D_TextBoxValue2Coor(pObject); if(D4D_TextBoxGetLineCount(pObject) > _calc.lineCount) { D4D_GET_TEXTBOX_SCROLL_BAR_HOR(pObject)->pData->flags |= D4D_OBJECT_F_VISIBLE; D4D_TextBoxValue2Coor(pObject); D4D_ScrlBrSetRange(D4D_GET_TEXTBOX_SCROLL_BAR_HOR(pObject), 0, D4D_TextBoxGetLineCount(pObject)); D4D_ScrlBrSetStep(D4D_GET_TEXTBOX_SCROLL_BAR_HOR(pObject), _calc.lineCount, D4D_TXTBX_SCRLBR_STEP); D4D_ScrlBrSetPosition(D4D_GET_TEXTBOX_SCROLL_BAR_HOR(pObject), 0); return D4D_TRUE; } return D4D_FALSE; }
static D4D_BOOL D4D_MenuScrollBarSetup(D4D_OBJECT* pObject) { // Try to check if the Menu needs scroll Bar D4D_MenuValue2Coor(pObject); // Switch off possible scroll bar in refresh case D4D_GET_MENU_SCROLL_BAR_HOR(pObject)->pData->flags &= ~D4D_OBJECT_F_VISIBLE; if((_calc.posCnt < _calc.itemsCnt) || (pObject->initFlags & D4D_MENU_F_SIDEBAR)) { D4D_OBJECT* pScrlBr; pScrlBr = D4D_GET_MENU_SCROLL_BAR_HOR(pObject); pScrlBr->pData->flags |= D4D_OBJECT_F_VISIBLE; // Init child objects coordinations pScrlBr->position.x = (D4D_COOR)(_calc.contentGeom.pnt.x + _calc.contentGeom.sz.cx - D4D_MENU_SCRLBR_WIDTH); pScrlBr->position.y = (D4D_COOR)(_calc.contentGeom.pnt.y + _calc.titleBar_y + 1); pScrlBr->position = D4D_GetScreenToClientPoint( pScrlBr, &pScrlBr->position); pScrlBr->size.cx = D4D_MENU_SCRLBR_WIDTH; pScrlBr->size.cy = (D4D_COOR)(_calc.contentGeom.sz.cy - _calc.titleBar_y - 1); pScrlBr->radius = D4D_LimitU(pObject->radius, 0, D4D_MENU_SCRLBR_WIDTH / 2); if(_calc.itemsCnt < _calc.posCnt) D4D_ScrlBrSetRange(pScrlBr, 0, _calc.posCnt); else D4D_ScrlBrSetRange(pScrlBr, 0, _calc.itemsCnt); D4D_ScrlBrSetStep(pScrlBr, _calc.posCnt, D4D_MENU_SCRLBR_STEP); D4D_ScrlBrSetPosition(pScrlBr, 0); return D4D_TRUE; } return D4D_FALSE; }