mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 06:41:42 -05:00
ZoomWindowTool and MeasureAreaTool port the WinForms Zoom Window and Select Area actions onto the shared plate tool framework; PartHoverTip is the plate view's delayed drawing-name tooltip; PlateZoom gives the Zoom To areas. ViewTransform now scales with the viewport on resize as DrawControl does and zooms about its center by the menu's 1.5 step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.2 KiB
C#
89 lines
3.2 KiB
C#
using System;
|
|
using OpenNest.Desktop.Rendering;
|
|
|
|
namespace OpenNest.Desktop.Interaction;
|
|
|
|
/// <summary>
|
|
/// The WinForms plate view's hover tooltip, toolkit-neutral: each pointer move (in Select, no
|
|
/// button held) hides the tip and restarts a <see cref="Delay"/> timer; when the timer elapses
|
|
/// the part under the point last moved to, if any, has its drawing name shown beside the
|
|
/// pointer. The host owns the timer: it calls <see cref="Move"/>, <see cref="Clear"/> and
|
|
/// <see cref="Elapse"/>, and redraws when they return true.
|
|
/// </summary>
|
|
public sealed class PartHoverTip
|
|
{
|
|
/// <summary>How long the pointer must rest before the tip shows, as the WinForms hover timer.</summary>
|
|
public static readonly TimeSpan Delay = TimeSpan.FromSeconds(1);
|
|
|
|
private bool pending;
|
|
|
|
/// <summary>The part whose tip is shown, or null.</summary>
|
|
public Part Part { get; private set; }
|
|
|
|
/// <summary>Where the pointer rested, in screen pixels.</summary>
|
|
public ScreenPoint Anchor { get; private set; }
|
|
|
|
/// <summary>The tip's text, the part's drawing name, or null while no tip shows.</summary>
|
|
public string Text => Part?.BaseDrawing.Name;
|
|
|
|
/// <summary>Whether a move started the delay and the timer has not elapsed since.</summary>
|
|
public bool IsPending => pending;
|
|
|
|
/// <summary>The pointer moved: the tip hides and the delay starts again.</summary>
|
|
/// <returns>Whether a shown tip was hidden, so the view must redraw.</returns>
|
|
public bool Move(ScreenPoint at)
|
|
{
|
|
Anchor = at;
|
|
pending = true;
|
|
return Hide();
|
|
}
|
|
|
|
/// <summary>The pointer left, pressed a button or the view changed: no tip until the next move.</summary>
|
|
/// <returns>Whether a shown tip was hidden.</returns>
|
|
public bool Clear()
|
|
{
|
|
pending = false;
|
|
return Hide();
|
|
}
|
|
|
|
/// <summary>
|
|
/// The delay elapsed: shows the tip for the part <paramref name="partAt"/> finds at the
|
|
/// anchor. Nothing happens unless a move is pending.
|
|
/// </summary>
|
|
/// <returns>Whether a tip is now shown.</returns>
|
|
public bool Elapse(Func<ScreenPoint, Part> partAt)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(partAt);
|
|
if (!pending)
|
|
return false;
|
|
pending = false;
|
|
Part = partAt(Anchor);
|
|
return Part != null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Where the tip's box goes for text of the given size, as WinForms places it: above and to
|
|
/// the right of the anchor, flipped to the left when it would pass the view's right edge and
|
|
/// below when it would pass the top. The box is the text plus a 3 by 2 pixel padding.
|
|
/// </summary>
|
|
public static (double X, double Y, double Width, double Height) Place(
|
|
ScreenPoint anchor, double textWidth, double textHeight, double viewWidth)
|
|
{
|
|
var x = anchor.X + 16;
|
|
var y = anchor.Y - textHeight - 6;
|
|
if (x + textWidth + 8 > viewWidth)
|
|
x = anchor.X - textWidth - 8;
|
|
if (y < 0)
|
|
y = anchor.Y + 20;
|
|
return (x, y, textWidth + 6, textHeight + 4);
|
|
}
|
|
|
|
private bool Hide()
|
|
{
|
|
if (Part == null)
|
|
return false;
|
|
Part = null;
|
|
return true;
|
|
}
|
|
}
|