コード例 #1
0
ファイル: UIManager.cpp プロジェクト: Bromvlieg/TomatoLib
	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;
	}
コード例 #2
0
ファイル: UIBase.cpp プロジェクト: edunad/TomatoLib
	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);
	}