int hgeGUI::Update(float dt) { bool bDone; int key; hgeGUIObject *ctrl; // Update the mouse variables g_hgegui_hge->Input_GetMousePos(&m_mouse_x, &m_mouse_y); m_lpressed = g_hgegui_hge->Input_KeyDown(HGEK_LBUTTON); m_lreleased = g_hgegui_hge->Input_KeyUp(HGEK_LBUTTON); m_rpressed = g_hgegui_hge->Input_KeyDown(HGEK_RBUTTON); m_rreleased = g_hgegui_hge->Input_KeyUp(HGEK_RBUTTON); m_wheel = g_hgegui_hge->Input_GetMouseWheel(); // Update all controls ctrl = m_controls; while (ctrl) { ctrl->Update(dt); ctrl = ctrl->next; } // Handle Enter/Leave if (m_enter_leave) { ctrl = m_controls; bDone = true; while (ctrl) { if (!ctrl->IsDone()) { bDone = false; break; } ctrl = ctrl->next; } if (!bDone) return 0; else { if (m_enter_leave == 1) return -1; else m_enter_leave = 0; } } // Handle keys key = g_hgegui_hge->Input_GetKey(); if (((m_navmode & HGEGUI_LEFTRIGHT) && key == HGEK_LEFT) || ((m_navmode & HGEGUI_UPDOWN) && key == HGEK_UP)) { ctrl = m_ctrl_focus; if (!ctrl) { ctrl = m_controls; if (!ctrl) return 0; } do { ctrl = ctrl->prev; if (!ctrl && ((m_navmode & HGEGUI_CYCLED) || !m_ctrl_focus)) { ctrl = m_controls; while (ctrl->next) ctrl = ctrl->next; } if (!ctrl || ctrl == m_ctrl_focus) break; } while (ctrl->m_is_static == true || ctrl->m_is_visible == false || ctrl->m_is_enabled == false); if (ctrl && ctrl != m_ctrl_focus) { if (m_ctrl_focus) m_ctrl_focus->Focus(false); if (ctrl) ctrl->Focus(true); m_ctrl_focus = ctrl; } } else if (((m_navmode & HGEGUI_LEFTRIGHT) && key == HGEK_RIGHT) || ((m_navmode & HGEGUI_UPDOWN) && key == HGEK_DOWN)) { ctrl = m_ctrl_focus; if (!ctrl) { ctrl = m_controls; if (!ctrl) return 0; while (ctrl->next) ctrl = ctrl->next; } do { ctrl = ctrl->next; if (!ctrl && ((m_navmode & HGEGUI_CYCLED) || !m_ctrl_focus)) ctrl = m_controls; if (!ctrl || ctrl == m_ctrl_focus) break; } while (ctrl->m_is_static == true || ctrl->m_is_visible == false || ctrl->m_is_enabled == false); if (ctrl && ctrl != m_ctrl_focus) { if (m_ctrl_focus) m_ctrl_focus->Focus(false); if (ctrl) ctrl->Focus(true); m_ctrl_focus = ctrl; } } else if (m_ctrl_focus && key && key != HGEK_LBUTTON && key != HGEK_RBUTTON) { if (m_ctrl_focus->KeyClick(key, g_hgegui_hge->Input_GetChar())) return m_ctrl_focus->m_object_id; } // Handle mouse bool bLDown = g_hgegui_hge->Input_GetKeyState(HGEK_LBUTTON); bool bRDown = g_hgegui_hge->Input_GetKeyState(HGEK_RBUTTON); if (m_ctrl_lock) { ctrl = m_ctrl_lock; if (!bLDown && !bRDown) m_ctrl_lock = nullptr; if (ProcessCtrl(ctrl)) return ctrl->m_object_id; } else { // Find last (topmost) control ctrl = m_controls; if (ctrl) while (ctrl->next) ctrl = ctrl->next; while (ctrl) { if (ctrl->m_rect.TestPoint(m_mouse_x, m_mouse_y) && ctrl->m_is_enabled) { if (m_ctrl_over != ctrl) { if (m_ctrl_over) m_ctrl_over->MouseOver(false); ctrl->MouseOver(true); m_ctrl_over = ctrl; } if (ProcessCtrl(ctrl)) return ctrl->m_object_id; else return 0; } ctrl = ctrl->prev; } if (m_ctrl_over) { m_ctrl_over->MouseOver(false); m_ctrl_over = nullptr; } } return 0; }
int hgeGUI::Update(float dt) { bool bDone; int key; hgeGUIObject *ctrl; // Update the mouse variables hge->Input_GetMousePos(&mx, &my); bLPressed = hge->Input_KeyDown(HGEK_LBUTTON); bLReleased = hge->Input_KeyUp(HGEK_LBUTTON); bRPressed = hge->Input_KeyDown(HGEK_RBUTTON); bRReleased = hge->Input_KeyUp(HGEK_RBUTTON); nWheel=hge->Input_GetMouseWheel(); // Update all controls ctrl=ctrls; while(ctrl) { ctrl->Update(dt); ctrl=ctrl->next; } // Handle Enter/Leave if(nEnterLeave) { ctrl=ctrls; bDone=true; while(ctrl) { if(!ctrl->IsDone()) { bDone=false; break; } ctrl=ctrl->next; } if(!bDone) return 0; else { if(nEnterLeave==1) return -1; else nEnterLeave=0; } } // Handle keys key=hge->Input_GetKey(); if(((navmode & HGEGUI_LEFTRIGHT) && key==HGEK_LEFT) || ((navmode & HGEGUI_UPDOWN) && key==HGEK_UP)) { ctrl=ctrlFocus; if(!ctrl) { ctrl=ctrls; if(!ctrl) return 0; } do { ctrl=ctrl->prev; if(!ctrl && ((navmode & HGEGUI_CYCLED) || !ctrlFocus)) { ctrl=ctrls; while(ctrl->next) ctrl=ctrl->next; } if(!ctrl || ctrl==ctrlFocus) break; } while(ctrl->bStatic==true || ctrl->bVisible==false || ctrl->bEnabled==false); if(ctrl && ctrl!=ctrlFocus) { if(ctrlFocus) ctrlFocus->Focus(false); if(ctrl) ctrl->Focus(true); ctrlFocus=ctrl; } } else if(((navmode & HGEGUI_LEFTRIGHT) && key==HGEK_RIGHT) || ((navmode & HGEGUI_UPDOWN) && key==HGEK_DOWN)) { ctrl=ctrlFocus; if(!ctrl) { ctrl=ctrls; if(!ctrl) return 0; while(ctrl->next) ctrl=ctrl->next; } do { ctrl=ctrl->next; if(!ctrl && ((navmode & HGEGUI_CYCLED) || !ctrlFocus)) ctrl=ctrls; if(!ctrl || ctrl==ctrlFocus) break; } while(ctrl->bStatic==true || ctrl->bVisible==false || ctrl->bEnabled==false); if(ctrl && ctrl!=ctrlFocus) { if(ctrlFocus) ctrlFocus->Focus(false); if(ctrl) ctrl->Focus(true); ctrlFocus=ctrl; } } else if(ctrlFocus && key && key!=HGEK_LBUTTON && key!=HGEK_RBUTTON) { if(ctrlFocus->KeyClick(key, hge->Input_GetChar())) return ctrlFocus->id; } // Handle mouse bool bLDown = hge->Input_GetKeyState(HGEK_LBUTTON); bool bRDown = hge->Input_GetKeyState(HGEK_RBUTTON); if(ctrlLock) { ctrl=ctrlLock; if(!bLDown && !bRDown) ctrlLock=0; if(ProcessCtrl(ctrl)) return ctrl->id; } else { // Find last (topmost) control ctrl=ctrls; if(ctrl) while(ctrl->next) ctrl=ctrl->next; while(ctrl) { if(ctrl->rect.TestPoint(mx,my) && ctrl->bEnabled) { if(ctrlOver != ctrl) { if(ctrlOver) ctrlOver->MouseOver(false); ctrl->MouseOver(true); ctrlOver=ctrl; } if(ProcessCtrl(ctrl)) return ctrl->id; else return 0; } ctrl=ctrl->prev; } if(ctrlOver) {ctrlOver->MouseOver(false); ctrlOver=0;} } return 0; }
int CGUI::Update(float fDelta) { BOOL bLPressed=m_pApp->Input_KeyPressed(VK_LBUTTON), bRPressed=m_pApp->Input_KeyPressed(VK_RBUTTON); m_fOldX=m_fCurX; m_fOldY=m_fCurY; m_pApp->Input_GetMousePos(&m_fCurX, &m_fCurY); m_nWheel=m_pApp->Input_GetMouseWheel(); for (CControl *p=m_pCtrlList; p!=NULL; p=p->m_pNext) p->Update(fDelta); if (m_nEnterExit>0) { BOOL bDone=TRUE; for (CControl *p=m_pCtrlList; p!=NULL; p=p->m_pNext) { if (!p->IsDone()) { bDone=FALSE; break; } } if (!bDone) return 0; else { if (m_nEnterExit==1) return -1; else m_nEnterExit=0; } } int nVKey=m_pApp->Input_GetKey(); if ((m_dwNavMode&NAV_LEFTRIGHT) && nVKey==VK_LEFT || (m_dwNavMode&NAV_UPDOWN) && nVKey==VK_UP) { CControl *pCtrl=m_pCtrlFocus; if (pCtrl==NULL) { pCtrl=m_pCtrlList; if (pCtrl==NULL) return 0; } do { pCtrl=pCtrl->m_pPrev; if (pCtrl==NULL && ((m_dwNavMode&NAV_CYCLED) || m_pCtrlFocus==NULL)) { pCtrl=m_pCtrlList; while (pCtrl->m_pNext!=NULL) pCtrl=pCtrl->m_pNext; } if (pCtrl==NULL || pCtrl==m_pCtrlFocus) break; } while (pCtrl->m_bStatic==TRUE || pCtrl->m_bVisible==FALSE || pCtrl->m_bEnabled==FALSE); if (pCtrl!=NULL && pCtrl!=m_pCtrlFocus) { if (m_pCtrlFocus!=NULL) m_pCtrlFocus->Focus(FALSE); pCtrl->Focus(TRUE); m_pCtrlFocus=pCtrl; } } else if ((m_dwNavMode&NAV_LEFTRIGHT) && nVKey==VK_RIGHT || (m_dwNavMode&NAV_UPDOWN) && nVKey==VK_DOWN) { CControl *pCtrl=m_pCtrlFocus; if (pCtrl==NULL) { pCtrl=m_pCtrlList; if (pCtrl==NULL) return 0; while (pCtrl->m_pNext!=NULL) pCtrl=pCtrl->m_pNext; } do { pCtrl=pCtrl->m_pNext; if (pCtrl==NULL && ((m_dwNavMode&NAV_CYCLED) || m_pCtrlFocus==NULL)) pCtrl=m_pCtrlList; if (pCtrl==NULL || pCtrl==m_pCtrlFocus) break; } while (pCtrl->m_bStatic==TRUE || pCtrl->m_bVisible==FALSE || pCtrl->m_bEnabled==FALSE); if (pCtrl!=NULL && pCtrl!=m_pCtrlFocus) { if (m_pCtrlFocus!=NULL) m_pCtrlFocus->Focus(FALSE); pCtrl->Focus(TRUE); m_pCtrlFocus=pCtrl; } } else if (m_pCtrlFocus!=NULL && nVKey!=0 && nVKey!=VK_LBUTTON && nVKey!=VK_RBUTTON) { if (m_pCtrlFocus->KeyClick(nVKey, m_pApp->Input_GetChar())) return m_pCtrlFocus->m_nID; } if (m_pCtrlLock!=NULL) { CControl *pCtrl=m_pCtrlLock; if (!bLPressed && !bRPressed) m_pCtrlLock=NULL; if (ProcessCtrl(pCtrl)) return pCtrl->m_nID; } else { CControl *pCtrl=m_pCtrlList; BOOL bOver=FALSE; if (pCtrl!=NULL) { while (pCtrl->m_pNext!=NULL) pCtrl=pCtrl->m_pNext; } for ( ; pCtrl!=NULL; pCtrl=pCtrl->m_pPrev) { if (pCtrl->m_Rect.TestPoint(m_fCurX, m_fCurY) && pCtrl->m_bEnabled) { bOver=TRUE; if (pCtrl!=m_pCtrlOver) { if (m_pCtrlOver!=NULL) m_pCtrlOver->MouseOver(FALSE); pCtrl->MouseOver(TRUE); m_pCtrlOver=pCtrl; } if (ProcessCtrl(pCtrl)) return pCtrl->m_nID; } } if (!bOver && m_pCtrlOver!=NULL) { m_pCtrlOver->MouseOver(FALSE); m_pCtrlOver=NULL; } } return 0; }