Fix rubber band drawing to respect DPI scale (eg. on macOS)

This commit is contained in:
Wojtek Figat
2025-03-16 11:38:17 +01:00
parent 87e423ed48
commit 56a8bb777b
2 changed files with 16 additions and 25 deletions

View File

@@ -11,7 +11,7 @@ namespace FlaxEngine.Gizmo;
/// <summary>
/// Class for adding viewport rubber band selection.
/// </summary>
public class ViewportRubberBandSelector
public sealed class ViewportRubberBandSelector
{
private bool _isMosueCaptured;
private bool _isRubberBandSpanning;
@@ -232,30 +232,15 @@ public class ViewportRubberBandSelector
}
/// <summary>
/// Used to draw the rubber band. Begins render 2D.
/// Draws the ruber band during owner viewport UI drawing.
/// </summary>
/// <param name="context">The GPU Context.</param>
/// <param name="target">The GPU texture target.</param>
/// <param name="targetDepth">The GPU texture target depth.</param>
public void Draw(GPUContext context, GPUTexture target, GPUTexture targetDepth)
{
// Draw RubberBand for rect selection
if (!_isRubberBandSpanning)
return;
Render2D.Begin(context, target, targetDepth);
Draw2D();
Render2D.End();
}
/// <summary>
/// Used to draw the rubber band. Use if already rendering 2D context.
/// </summary>
public void Draw2D()
public void Draw()
{
if (!_isRubberBandSpanning)
return;
Render2D.FillRectangle(_rubberBandRect, Style.Current.Selection);
Render2D.DrawRectangle(_rubberBandRect, Style.Current.SelectionBorder);
var style = Style.Current;
Render2D.FillRectangle(_rubberBandRect, style.Selection);
Render2D.DrawRectangle(_rubberBandRect, style.SelectionBorder);
}
/// <summary>

View File

@@ -375,10 +375,7 @@ namespace FlaxEditor.Viewport
{
Gizmos[i].Draw(ref renderContext);
}
// Draw RubberBand for rect selection
_rubberBandSelector.Draw(context, target, targetDepth);
// Draw selected objects debug shapes and visuals
if (DrawDebugDraw && (renderContext.View.Flags & ViewFlags.DebugDraw) == ViewFlags.DebugDraw)
{
@@ -594,6 +591,15 @@ namespace FlaxEditor.Viewport
}
}
/// <inheritdoc />
public override void Draw()
{
base.Draw();
// Draw rubber band for rectangle selection
_rubberBandSelector.Draw();
}
/// <inheritdoc />
protected override void OrientViewport(ref Quaternion orientation)
{