Skip to content
Prev Previous commit
Next Next commit
Extracted helper method
  • Loading branch information
Lehonti committed Sep 5, 2025
commit ee6d7bf6357f3a8e2de47ea3bb61c36df79077fc
16 changes: 13 additions & 3 deletions Pinta.Gui.Widgets/Widgets/Ruler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Cairo;
using Pinta.Core;

Expand Down Expand Up @@ -271,7 +272,7 @@ private RulerDrawSettings CreateSettings (Size preliminarySize)
UnitsPerTick: unitsPerTick,
Start: (int) Math.Floor (scaledLower * ticksPerUnit),
End: (int) Math.Ceiling (scaledUpper * ticksPerUnit),
MarkerPosition: (Position - Lower) * (effectiveSize.Width / (Upper - Lower)),
MarkerPosition: GetPositionOnRuler (Position, effectiveSize.Width),
RulerOuterLine: rulerOuterLine,
EffectiveSize: effectiveSize,
Color: color,
Expand All @@ -293,8 +294,8 @@ private void Draw (Context cr, Size preliminarySize)
if (selection_start < selection_end) {

// Convert selection coordinates to ruler widget coordinates
double p1 = (selection_start - Lower) * (settings.EffectiveSize.Width / (Upper - Lower));
double p2 = (selection_end - Lower) * (settings.EffectiveSize.Width / (Upper - Lower));
double p1 = GetPositionOnRuler (selection_start, settings.EffectiveSize.Width);
double p2 = GetPositionOnRuler (selection_end, settings.EffectiveSize.Width);

cr.SetSourceRgba (0.5, 0.7, 1.0, 0.5); // Semi-transparent blue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it look with the same color that's used for selections on the canvas?

Gdk.RGBA fillColor = new () { Red = 0.7f, Green = 0.8f, Blue = 0.9f, Alpha = 0.2f };


Expand Down Expand Up @@ -391,6 +392,15 @@ private ImageSurface CreateBaseRuler (in RulerDrawSettings settings, Size prelim
return result;
}

[MethodImpl (MethodImplOptions.AggressiveInlining)]
private double GetPositionOnRuler (double position, double width)
{
double range = Upper - Lower;
double scaledWidth = width / range;
double positionFromLower = position - Lower;
return positionFromLower * scaledWidth;
}

private static int GetFontSize (Pango.FontDescription font, int scaleFactor)
{
int fontSize = PangoExtensions.UnitsToPixels (font.GetSize ());
Expand Down
Loading