public override void OnMouseUp(MouseEventArgs mouseEvent) { CheckMouseCaptureStates(); base.OnMouseUp(mouseEvent); if (keyboard != null && keyboard.Visible) { CheckMouseCaptureStates(); RectangleDouble textWidgetBounds = TextWidgetScreenBounds(); if (textWidgetBounds.Contains(mouseEvent.Position)) { contentOffsetHolder.OnMouseUp(mouseEvent); } else { if (FirstWidgetUnderMouse) { UiThread.RunOnIdle(() => { CheckMouseCaptureStates(); DoHideSoftwareKeyboard(this, null); CheckMouseCaptureStates(); }); } } CheckMouseCaptureStates(); } }
private void CheckIfNeedToDisplayToolTip() { //DebugStopTimers(); double showDelayTime = InitialDelay; if ((timeSinceLastToolTipClose.IsRunning || timeSinceLastToolTipCloseWasRunning) && timeSinceLastToolTipClose.Elapsed.TotalSeconds < InitialDelay && widgetThatWantsToShowToolTip != null && widgetThatIsShowingToolTip == null) { showDelayTime = ReshowDelay; } bool didShow = false; if (widgetThatWantsToShowToolTip != null && widgetThatWantsToShowToolTip != widgetThatIsShowingToolTip && timeSinceMouseOver.Elapsed.TotalSeconds > showDelayTime) { // And lets make sure we are still over the widget RectangleDouble screenBounds = widgetThatWantsToShowToolTip.TransformToScreenSpace(widgetThatWantsToShowToolTip.LocalBounds); if (screenBounds.Contains(mousePosition)) { DoShowToolTip(); didShow = true; } } if (!didShow) { bool didRemove = false; if (timeCurrentToolTipHasBeenShowing.Elapsed.TotalSeconds > CurrentAutoPopDelay) { RemoveToolTip(); widgetThatIsShowingToolTip = null; timeCurrentToolTipHasBeenShowing.Stop(); timeCurrentToolTipHasBeenShowing.Reset(); didRemove = true; } if (!didRemove && widgetThatIsShowingToolTip != null) { RectangleDouble screenBounds = widgetThatIsShowingToolTip.TransformToScreenSpace(widgetThatIsShowingToolTip.LocalBounds); if (!screenBounds.Contains(mousePosition)) { RemoveToolTip(); widgetThatIsShowingToolTip = null; } } } // Call again in .1 s so that this is constantly being re-evaluated. UiThread.RunOnIdle(CheckIfNeedToDisplayToolTip, .05); //DebugStartTimers(); }
public override void OnMouseDown(MouseEventArgs mouseEvent) { RectangleDouble switchBounds = GetSwitchBounds(); Vector2 mousePosition = mouseEvent.Position; if (switchBounds.Contains(mousePosition)) { mouseDownOnToggle = true; } base.OnMouseDown(mouseEvent); }
public override void OnMouseUp(MouseEventArgs mouseEvent) { int boxSize = 20; // Handle errors in the touch panel that push touch event positions to the screen edge by // proxying all clicks in the target region back into the desired control RectangleDouble topRightHitbox = new RectangleDouble(this.Width - boxSize, this.Height - boxSize, this.Width, this.Height); if (topRightHitbox.Contains(mouseEvent.Position) && this.MouseCaptured) { setupButton.ClickButton(null); return; } base.OnMouseUp(mouseEvent); }
public override void OnMouseDown(MouseEventArgs mouseEvent) { valueOnMouseDown = Value; double oldValue = Value; Vector2 mousePos = mouseEvent.Position; RectangleDouble thumbBounds = GetThumbHitBounds(); if (thumbBounds.Contains(mousePos)) { if (Orientation == Orientation.Horizontal) { mouseDownOffsetFromThumbCenter = mousePos.X - PositionPixelsFromFirstValue; } else { mouseDownOffsetFromThumbCenter = mousePos.Y - PositionPixelsFromFirstValue; } downOnThumb = true; SliderGrabed?.Invoke(this, mouseEvent); } else // let's check if we are on the track { RectangleDouble trackHitBounds = GetTrackHitBounds(); if (trackHitBounds.Contains(mousePos)) { if (Orientation == Orientation.Horizontal) { PositionPixelsFromFirstValue = mousePos.X; } else { PositionPixelsFromFirstValue = mousePos.Y; } } } if (oldValue != Value) { if (ValueChanged != null) { ValueChanged(this, mouseEvent); } Invalidate(); } base.OnMouseDown(mouseEvent); }
public override void OnMouseMove(MouseEventArgs mouseEvent) { CheckMouseCaptureStates(); base.OnMouseMove(mouseEvent); CheckMouseCaptureStates(); if (keyboard != null && keyboard.Visible) { RectangleDouble textWidgetBounds = TextWidgetScreenBounds(); if (textWidgetBounds.Contains(mouseEvent.Position)) { contentOffsetHolder.OnMouseMove(mouseEvent); } CheckMouseCaptureStates(); } }
private static void AssertBorderWhereExpected(Regions region, BorderDouble border, IImageByte imageBuffer) { RectangleDouble borderBounds = RectangleDouble.ZeroIntersection; switch (region) { case Regions.Left: borderBounds = new RectangleDouble(0, 0, border.Left, imageBuffer.Height); break; case Regions.Bottom: borderBounds = new RectangleDouble(0, 0, imageBuffer.Width, border.Bottom); break; case Regions.Right: borderBounds = new RectangleDouble(imageBuffer.Width - border.Right, 0, imageBuffer.Width, imageBuffer.Height); break; case Regions.Top: borderBounds = new RectangleDouble(0, imageBuffer.Height - border.Top, imageBuffer.Width, imageBuffer.Height); break; } for (int x = 0; x < imageBuffer.Width; x++) { for (int y = 0; y < imageBuffer.Height; y++) { var pixel = imageBuffer.GetPixel(x, y); bool shouldBeRed = borderBounds.Contains(new Point2D(x + .5, y + .5)); if (shouldBeRed) { Assert.AreEqual(Color.Red, pixel); } else { Assert.AreNotEqual(Color.Red, pixel); } } } }
public override void OnMouseDown(MouseEventArgs mouseEvent) { firstValueOnMouseDown = FirstValue; secondValueOnMouseDown = SecondValue; Vector2 mousePos = mouseEvent.Position; RectangleDouble firstThumbBounds = GetFirstThumbHitBounds(); RectangleDouble secondThumbBounds = GetSecondThumbHitBounds(); if (firstThumbBounds.Contains(mousePos)) { if (Orientation == Orientation.Horizontal) { mouseDownOffsetFromFirstThumbCenter = mousePos.x - PositionPixelsFromFirstValue; } else { mouseDownOffsetFromFirstThumbCenter = mousePos.y - PositionPixelsFromFirstValue; } downOnFirstThumb = true; } else if (secondThumbBounds.Contains(mousePos)) { if (Orientation == Orientation.Horizontal) { mouseDownOffsetFromSecondThumbCenter = mousePos.x - PositionPixelsFromSecondValue; } else { mouseDownOffsetFromSecondThumbCenter = mousePos.y - PositionPixelsFromSecondValue; } downOnSecondThumb = true; } else // let's check if we are on the track { //Ignore track hits } base.OnMouseDown(mouseEvent); }
private void DoShowToolTip() { if (widgetThatWantsToShowToolTip != null && widgetThatWantsToShowToolTip != widgetThatIsShowingToolTip) { RectangleDouble screenBounds = widgetThatWantsToShowToolTip.TransformToScreenSpace(widgetThatWantsToShowToolTip.LocalBounds); if (screenBounds.Contains(mousePosition)) { RemoveToolTip(); widgetThatIsShowingToolTip = null; toolTipText = widgetThatWantsToShowToolTip.ToolTipText; toolTipWidget = new FlowLayoutWidget() { BackgroundColor = RGBA_Bytes.White, OriginRelativeParent = new Vector2((int)mousePosition.x, (int)mousePosition.y), Padding = new BorderDouble(3), Selectable = false, }; toolTipWidget.Name = "ToolTipWidget"; toolTipWidget.AfterDraw += (sender, drawEventHandler) => { drawEventHandler.graphics2D.Rectangle(toolTipWidget.LocalBounds, RGBA_Bytes.Black); }; // Make sure we wrap long text toolTipWidget.AddChild(new WrappedTextWidget(toolTipText) { Width = 350 * GuiWidget.DeviceScale, HAnchor = HAnchor.FitToChildren, }); // Increase the delay to make long text stay on screen long enough to read double RatioOfExpectedText = Math.Max(1, (widgetThatWantsToShowToolTip.ToolTipText.Length / 50.0)); CurrentAutoPopDelay = RatioOfExpectedText * AutoPopDelay; owner.AddChild(toolTipWidget); if (ToolTipShown != null) { ToolTipShown(this, new StringEventArgs(CurrentText)); } //timeCurrentToolTipHasBeenShowing.Reset(); //timeCurrentToolTipHasBeenShowingWasRunning = true; timeCurrentToolTipHasBeenShowing.Restart(); RectangleDouble toolTipBounds = toolTipWidget.LocalBounds; toolTipWidget.OriginRelativeParent = toolTipWidget.OriginRelativeParent + new Vector2(0, -toolTipBounds.Bottom - toolTipBounds.Height - 23); Vector2 offset = Vector2.Zero; RectangleDouble ownerBounds = owner.LocalBounds; RectangleDouble toolTipBoundsRelativeToParent = toolTipWidget.BoundsRelativeToParent; if (toolTipBoundsRelativeToParent.Right > ownerBounds.Right - 3) { offset.x = ownerBounds.Right - toolTipBoundsRelativeToParent.Right - 3; } if (toolTipBoundsRelativeToParent.Bottom < ownerBounds.Bottom + 3) { offset.y = ownerBounds.Bottom - toolTipBoundsRelativeToParent.Bottom + 3; } toolTipWidget.OriginRelativeParent = toolTipWidget.OriginRelativeParent + offset; widgetThatIsShowingToolTip = widgetThatWantsToShowToolTip; widgetThatWantsToShowToolTip = null; } } }
private void DoShowToolTip() { if (widgetThatWantsToShowToolTip != null && widgetThatWantsToShowToolTip != widgetThatIsShowingToolTip && widgetThatWasShowingToolTip != widgetThatWantsToShowToolTip) { RectangleDouble screenBoundsShowingTT = widgetThatWantsToShowToolTip.TransformToScreenSpace(widgetThatWantsToShowToolTip.LocalBounds); if (screenBoundsShowingTT.Contains(mousePosition)) { RemoveToolTip(); widgetThatIsShowingToolTip = null; toolTipText = widgetThatWantsToShowToolTip.ToolTipText; toolTipWidget = new FlowLayoutWidget() { OriginRelativeParent = new Vector2((int)mousePosition.X, (int)mousePosition.Y), Selectable = false, }; toolTipWidget.Name = "ToolTipWidget"; // Make sure we wrap long text toolTipWidget.AddChild(CreateToolTip(toolTipText)); // Increase the delay to make long text stay on screen long enough to read double ratioOfExpectedText = Math.Max(1, widgetThatWantsToShowToolTip.ToolTipText.Length / 50.0); CurrentAutoPopDelay = ratioOfExpectedText * AutoPopDelay; systemWindow.AddChild(toolTipWidget); ToolTipShown?.Invoke(this, new StringEventArgs(CurrentText)); // timeCurrentToolTipHasBeenShowing.Reset(); // timeCurrentToolTipHasBeenShowingWasRunning = true; timeCurrentToolTipHasBeenShowing.Restart(); RectangleDouble toolTipBounds = toolTipWidget.LocalBounds; toolTipWidget.OriginRelativeParent = toolTipWidget.OriginRelativeParent + new Vector2(0, -toolTipBounds.Bottom - toolTipBounds.Height - 23); Vector2 offset = Vector2.Zero; RectangleDouble systemWindowBounds = systemWindow.LocalBounds; RectangleDouble toolTipBoundsRelativeToParent = toolTipWidget.BoundsRelativeToParent; if (toolTipBoundsRelativeToParent.Right > systemWindowBounds.Right - 3) { offset.X = systemWindowBounds.Right - toolTipBoundsRelativeToParent.Right - 3; } if (toolTipBoundsRelativeToParent.Bottom < systemWindowBounds.Bottom + 3) { offset.Y = screenBoundsShowingTT.Top - toolTipBoundsRelativeToParent.Bottom + 3; } toolTipWidget.OriginRelativeParent = toolTipWidget.OriginRelativeParent + offset; widgetThatIsShowingToolTip = widgetThatWantsToShowToolTip; widgetThatWantsToShowToolTip = null; widgetThatWasShowingToolTip = null; } } }