private void MouseMove(object sender, MouseEventArgs e) { if (!_mouseCaptured) { return; } var frameworkElement = _adorner as FrameworkElement; if (frameworkElement == null) { return; } var deltaY = e.GetPosition(null).Y - _mouseY; var deltaX = e.GetPosition(null).X - _mouseX; var offset = new Point(_adorner.Offset.X + deltaX, _adorner.Offset.Y + deltaY); // constrain the popup to the bounds of the window if (_adorner.ChildPosition.Y + offset.Y < 0) { offset.Y = -_adorner.ChildPosition.Y; } if (_adorner.ChildPosition.X + offset.X < 0) { offset.X = -_adorner.ChildPosition.X; } var boundariesSize = ScreenHelper.GetWindowSize(null); var adornedElement = _adorner.AdornedElement as FrameworkElement; if (adornedElement != null) { boundariesSize = new Size(adornedElement.ActualWidth, adornedElement.ActualHeight); } var maxY = boundariesSize.Height - frameworkElement.ActualHeight; if (_adorner.ChildPosition.Y + offset.Y > maxY) { offset.Y = maxY - _adorner.ChildPosition.Y; } var maxX = boundariesSize.Width - frameworkElement.ActualWidth; if (_adorner.ChildPosition.X + offset.X > maxX) { offset.X = maxX - _adorner.ChildPosition.X; } _adorner.Offset = offset; _mouseY = e.GetPosition(null).Y; _mouseX = e.GetPosition(null).X; }
static FontImage() { RegisterFont("Segoe UI Symbol", new FontFamily("Segoe UI Symbol")); DefaultFontFamily = "Segoe UI Symbol"; DefaultBrush = Brushes.Black; var dpi = ScreenHelper.GetDpi().Width; RenderingEmSize = dpi / 96d; }
private void MouseMove(object sender, MouseEventArgs e) { if (!_mouseCaptured) { return; } var frameworkElement = _popup.Child as FrameworkElement; if (frameworkElement == null) { return; } var deltaY = e.GetPosition(null).Y - _mouseY; var deltaX = e.GetPosition(null).X - _mouseX; _popup.VerticalOffset += deltaY; _popup.HorizontalOffset += deltaX; // constrain the popup to the bounds of the silverlight window if (_popup.VerticalOffset < 0) { _popup.VerticalOffset = 0; } if (_popup.HorizontalOffset < 0) { _popup.HorizontalOffset = 0; } var windowSize = ScreenHelper.GetWindowSize(null); var maxY = windowSize.Height - frameworkElement.ActualHeight; if (_popup.VerticalOffset > maxY) { _popup.VerticalOffset = maxY; } var maxX = windowSize.Width - frameworkElement.ActualWidth; if (_popup.HorizontalOffset > maxX) { _popup.HorizontalOffset = maxX; } _mouseY = e.GetPosition(null).Y; _mouseX = e.GetPosition(null).X; }
/// <summary> /// The on root visual mouse left button down. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private static void OnRootVisualMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { lock (Locker) { foreach (var toolTip in ElementsAndToolTips.Values.Where(toolTip => toolTip != null && !toolTip.IsPinned)) { if (ScreenHelper.IsParentOf(toolTip, e.OriginalSource as DependencyObject)) { continue; } toolTip.Hide(); } } }
public Point GetPosition() { var position = new Point(); var mousePosition = PinnableToolTipService.MousePosition; var rootVisual = PinnableToolTipService.RootVisual; var horizontalOffset = HorizontalOffset; var verticalOffset = VerticalOffset; //using this code for non UIElements if (_owner == null) { mousePosition = Mouse.GetPosition(_userDefinedAdorner); if ((_userDefinedAdorner as FrameworkElement) == null) { rootVisual = System.Windows.Interop.BrowserInteropHelper.IsBrowserHosted ? null : (Application.Current.MainWindow.Content as FrameworkElement) != null ? Application.Current.MainWindow.Content as FrameworkElement : Application.Current.MainWindow; } else { rootVisual = _userDefinedAdorner as FrameworkElement; } if (rootVisual == null) { position = _isPositionCalculated ? _lastPosition : mousePosition; return(position); } if (_isPositionCalculated) { if (_lastPosition.Y + DesiredSize.Height > rootVisual.ActualHeight) { _lastPosition.Y = rootVisual.ActualHeight - DesiredSize.Height; } if (_lastPosition.X + DesiredSize.Width > rootVisual.ActualWidth) { _lastPosition.X = rootVisual.ActualWidth - DesiredSize.Width; } position = _lastPosition; return(position); } var offsetX = mousePosition.X + horizontalOffset; var offsetY = mousePosition.Y + verticalOffset; //offsetX = Math.Max(2.0, offsetX); //offsetY = Math.Max(2.0, offsetY); var actualHeight = rootVisual.ActualHeight; var actualWidth = rootVisual.ActualWidth; var lastHeight = _lastSize.Height; var lastWidth = _lastSize.Width; var lastRectangle = new Rect(offsetX, offsetY, lastWidth, lastHeight); var actualRectangle = new Rect(0.0, 0.0, actualWidth, actualHeight); actualRectangle.Intersect(lastRectangle); if ((offsetY + DesiredSize.Height) > actualHeight) { offsetY = (actualHeight - DesiredSize.Height) - 2.0; } if (offsetY < 0.0) { offsetY = 0.0; } if ((offsetX + DesiredSize.Width) > actualWidth) { offsetX = (actualWidth - DesiredSize.Width) - 2.0; } if (offsetX < 0.0) { offsetX = 0.0; } position.Y = offsetY; position.X = offsetX; _isPositionCalculated = DesiredSize.Height > 0; if (_isPositionCalculated) { _lastPosition = position; } return(position); } var placementMode = PinnableToolTipService.GetPlacement(_owner); var placementTarget = PinnableToolTipService.GetPlacementTarget(_owner) ?? _owner; switch (placementMode) { case PlacementMode.Mouse: if (_isPositionCalculated) { position = _lastPosition; return(position); } var offsetX = mousePosition.X + horizontalOffset; var offsetY = mousePosition.Y + new TextBlock().FontSize + verticalOffset; offsetX = Math.Max(2.0, offsetX); offsetY = Math.Max(2.0, offsetY); var actualHeight = rootVisual.ActualHeight; var actualWidth = rootVisual.ActualWidth; var lastHeight = _lastSize.Height; var lastWidth = _lastSize.Width; var lastRectangle = new Rect(offsetX, offsetY, lastWidth, lastHeight); var actualRectangle = new Rect(0.0, 0.0, actualWidth, actualHeight); actualRectangle.Intersect(lastRectangle); if ((Math.Abs(actualRectangle.Width - lastRectangle.Width) < 2.0) && (Math.Abs(actualRectangle.Height - lastRectangle.Height) < 2.0)) { position.Y = offsetY; position.X = offsetX; } else { if ((offsetY + lastRectangle.Height) > actualHeight) { offsetY = (actualHeight - lastRectangle.Height) - 2.0; } if (offsetY < 0.0) { offsetY = 0.0; } if ((offsetX + lastRectangle.Width) > actualWidth) { offsetX = (actualWidth - lastRectangle.Width) - 2.0; } if (offsetX < 0.0) { offsetX = 0.0; } position.Y = offsetY; position.X = offsetX; } _lastPosition = position; _isPositionCalculated = true; break; case PlacementMode.Bottom: case PlacementMode.Right: case PlacementMode.Left: case PlacementMode.Top: var windowSize = ScreenHelper.GetWindowSize(null); var plugin = new Rect(0.0, 0.0, windowSize.Width, windowSize.Height); var translatedPoints = GetTranslatedPoints((FrameworkElement)placementTarget); var toolTipPoints = GetTranslatedPoints(this); var popupLocation = PlacePopup(plugin, translatedPoints, toolTipPoints, placementMode); position.Y = popupLocation.Y + verticalOffset; position.X = popupLocation.X + horizontalOffset; break; } return(position); }