示例#1
0
	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
	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();
	}