void UIBase::UnFocus() { List<UIBase*> childs; childs.Add(this); bool found = false; UIBase* c = nullptr; while (childs.Count > 0) { c = childs[childs.Count - 1]; childs.RemoveAt(childs.Count - 1); if (this->UIMan != nullptr && c == this->UIMan->FocusPanel) { found = true; break; } else { for (unsigned int i = 0; i < c->Children.size(); i++) { childs.Add(c->Children[i]); } } } if (!found) return; if (this->UIMan != nullptr) this->UIMan->FocusPanel = nullptr; c->OnFocus(false); }
bool UIManager::HandleScrollInteraction(int scrollx, int scrolly) { if (this->OnBeforeScrollInteracton(scrollx, scrolly)) return true; if (this->ShowCursor) { Vector2 mpos = this->LastMousePosition; int x = (int)mpos.X; int y = (int)mpos.Y; this->HoldPanel = null; for (int i = (int)this->Children.size() - 1; i > -1; i--) { UIBase* Pan = this->Children[i]; if (this->HoldPanel != null) break; if (Pan->ShouldRender == false) continue; if (Pan->PassTrough) continue; if (Pan->X <= x && Pan->Y <= y && (Pan->X + Pan->W) > x && (Pan->Y + Pan->H) > y) { if (!Pan->CanClick) break; this->_CheckClick(Pan, x - Pan->X, y - Pan->Y); } } if (this->HoldPanel != null) { UIBase* catcher = this->HoldPanel; while (!catcher->CanCatchScroll && catcher->Parent != null) { catcher = catcher->Parent; } catcher->OnScroll(scrollx, scrolly); return true; } } return false; }
void BatUITextBox::OnItemSelected(void) { UIBase* pUIHumMain = gBattleUIMgr.GetUI(BATUI_HUMAN_MAIN); UIBase* pUITankMain = gBattleUIMgr.GetUI(BATUI_TANK_MAIN); CloseUI(); if(mbIsOnLoad) { if(gBattleMgr.GetBattleMode() == BM_HUMAN) { pUIHumMain->CloseUI(); pUITankMain->OpenUI(); gBattleMgr.SetBattleMode(BM_TANK); } else if(gBattleMgr.GetBattleMode() == BM_TANK) { pUITankMain->CloseUI(); pUIHumMain->OpenUI(); gBattleMgr.SetBattleMode(BM_HUMAN); } FmodSound::PlaySnd(SND_GOTOTANK); } else { if(gBattleMgr.GetBattleMode() == BM_HUMAN) pUIHumMain->SetOnFocus(true); else if(gBattleMgr.GetBattleMode() == BM_TANK) pUITankMain->SetOnFocus(true); } }
bool UIManager::HandleMouseInteraction(int x, int y, int button, bool pressed, int mods) { if (this->OnBeforeMouseInteracton(x, y, button, pressed, mods)) return true; if (this->ShowCursor) { if (pressed) { this->HoldPanel = null; for (int i = (int)this->Children.size() - 1; i > -1; i--) { UIBase* Pan = this->Children[i]; if (this->HoldPanel != null) break; if (Pan->ShouldRender == false) continue; if (Pan->PassTrough) continue; if (Pan->X <= x && Pan->Y <= y && (Pan->X + Pan->W) > x && (Pan->Y + Pan->H) > y) { if (!Pan->CanClick) continue; this->_CheckClick(Pan, x - Pan->X, y - Pan->Y); } } if (this->HoldPanel != null) { if (this->FocusPanel != this->HoldPanel) { if (this->FocusPanel != null) { UIBase* tmp = this->FocusPanel; this->FocusPanel = this->HoldPanel; // override already so that it knows. tmp->OnFocus(false); } this->HoldPanel->SetFocus(); } Vector2 apos = this->HoldPanel->GetAbsoluteLocation(); this->HoldPanel->OnPress(x - (int)apos.X, y - (int)apos.Y, button); return true; } else { if (this->FocusPanel != null) { UIBase* tmp = this->FocusPanel; this->FocusPanel = null; tmp->OnFocus(false); } } } else { if (this->HoldPanel != null) { UIBase* tmp = this->HoldPanel; this->HoldPanel = null; Vector2 apos = tmp->GetAbsoluteLocation(); tmp->OnRelease(x - (int)apos.X, y - (int)apos.Y, button); if (x >= apos.X && x <= apos.X + tmp->W && y >= apos.Y && y <= apos.Y + tmp->H) { tmp->OnClick(x - (int)apos.X, y - (int)apos.Y, button); } } } } return false; }
void UIBase::_InternalDraw(Render& drawer) { if (!this->ShouldRender) return; Vector2 oldoffset = drawer.GetDrawingOffset(); Vector2 pos = this->GetAbsoluteLocation(); drawer.SetDrawingOffset((int)pos.X, (int)pos.Y); drawer.EnableClipping((int)pos.X, (int)pos.Y, this->W, this->H); bool recorderstarted = false; if (this->ShouldRedraw) { drawer.RecorderStart(); recorderstarted = true; } if (!this->Frozen && (this->ShouldRedraw || this->AlwaysRedraw)) { this->OnDraw(drawer); } else if(this->Buffer != nullptr) { drawer.Buffer(this->Buffer); } if (recorderstarted) { if (this->Buffer != nullptr) delete this->Buffer; this->Buffer = drawer.RecorderStop(); this->ShouldRedraw = false; } for (unsigned int i = 0; i < this->Children.size(); i++) { UIBase* p = this->Children[i]; Vector2 pos2 = p->GetAbsoluteLocation(); if (pos2.X + p->W < drawer._ClippingPos.X) continue; if (pos2.Y + p->H < drawer._ClippingPos.Y) continue; if (pos2.X > drawer._ClippingPos.X + drawer._ClippingSize.X) continue; if (pos2.Y > drawer._ClippingPos.Y + drawer._ClippingSize.Y) continue; p->_InternalDraw(drawer); } drawer.SetDrawingOffset((int)oldoffset.X, (int)oldoffset.Y); drawer.DisableClipping(); }
bool CheckName(const UIBase& ui, const string& name)//解决android移植问题 { return ui.isUI(name); }
UIBase::UIBase(UIBase* parent) { this->DrawColor = Color::White; this->Parent = nullptr; this->UIMan = UIBase::DefaultUImanager; this->X = 0; this->Y = 0; this->W = 0; this->H = 0; this->ShouldRender = parent != nullptr; this->CanClick = true; this->Dock = 0; this->TabIndex = -1; this->CanAcceptInput = false; this->TopMost = false; this->PassTrough = false; this->PassTroughSelfOnly = false; this->CanCatchScroll = false; this->Frozen = false; this->AlwaysRedraw = true; this->ShouldRedraw = true; this->Buffer = nullptr; this->SetParent(parent); this->OnKill = [this]() { }; this->OnFocus = [this](bool focus) { }; this->OnKeyUp = [this](int key) { }; this->OnKeyDown = [this](int key) { }; this->OnScroll = [this](int x, int y) { }; this->OnCharInput = [this](int key) { }; this->OnClick = [this](int x, int y, int button) { }; this->OnPress = [this](int x, int y, int button) {}; this->OnRelease = [this](int x, int y, int button) {}; this->OnInvalidateLayout = [this]() { }; this->OnShow = [this]() { }; this->OnHide = [this]() {}; this->OnDraw = [this](Render& drawer) { this->Draw(drawer); }; this->OnUpdate = [this]() { }; this->OnInput = [this](int key, int mods) { if (key == GLFW_KEY_TAB) { if (this->TabIndex == -1 || this->Parent == nullptr) return; int lowesttab = this->TabIndex + 1; int lowestID = -1; for (unsigned int i = 0; i < this->Parent->Children.size(); i++) { UIBase* c = this->Parent->Children[i]; if (c->TabIndex > -1) { if (c->TabIndex == this->TabIndex + 1) { c->SetFocus(); return; } if (c->TabIndex < lowesttab) { lowesttab = c->TabIndex; lowestID = i; } } } if (lowestID > -1) { this->Parent->Children[lowestID]->SetFocus(); } } }; }