Skip to content

Commit a6873f2

Browse files
committed
Renaming PixelsPerDeviceIndependentUnits to PixelDensity
1 parent cd22296 commit a6873f2

6 files changed

Lines changed: 21 additions & 18 deletions

File tree

Mapsui.UI.Android/MapControl.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public partial class MapControl : ViewGroup, IMapControl
2626
/// <summary>
2727
/// The number of pixels per device independent unit
2828
/// </summary>
29-
private float _density;
29+
private float _pixelDensity;
3030
/// <summary>
3131
/// Saver for center before last pinch movement
3232
/// </summary>
@@ -47,7 +47,7 @@ public MapControl(Context context, IAttributeSet attrs, int defStyle) :
4747
public void Initialize()
4848
{
4949
SetBackgroundColor(Color.Transparent);
50-
_density = PixelsPerDeviceIndependentUnit;
50+
_pixelDensity = PixelDensity;
5151
_canvas = new SKCanvasView(Context) { IgnorePixelScaling = true };
5252
_canvas.PaintSurface += CanvasOnPaintSurface;
5353
AddView(_canvas);
@@ -61,7 +61,7 @@ public void Initialize()
6161
_gestureDetector.DoubleTap += OnDoubleTapped;
6262
}
6363

64-
public float PixelsPerDeviceIndependentUnit => Resources.DisplayMetrics.Density;
64+
public float PixelDensity => Resources.DisplayMetrics.Density;
6565

6666
private void OnDoubleTapped(object sender, GestureDetector.DoubleTapEventArgs e)
6767
{
@@ -226,7 +226,7 @@ private List<Point> GetScreenPositions(MotionEvent motionEvent, View view)
226226
for (var i = 0; i < motionEvent.PointerCount; i++)
227227
{
228228
result.Add(new Point(motionEvent.GetX(i) - view.Left, motionEvent.GetY(i) - view.Top)
229-
.ToDeviceIndependentUnits(PixelsPerDeviceIndependentUnit));
229+
.ToDeviceIndependentUnits(PixelDensity));
230230
}
231231
return result;
232232
}
@@ -240,7 +240,7 @@ private List<Point> GetScreenPositions(MotionEvent motionEvent, View view)
240240
private Point GetScreenPosition(MotionEvent motionEvent, View view)
241241
{
242242
return GetScreenPositionInPixels(motionEvent, view)
243-
.ToDeviceIndependentUnits(PixelsPerDeviceIndependentUnit);
243+
.ToDeviceIndependentUnits(PixelDensity);
244244
}
245245

246246
/// <summary>
@@ -316,7 +316,7 @@ private void WidgetTouched(IWidget widget, Point screenPosition)
316316
/// <returns>The device pixels given as input translated to device pixels.</returns>
317317
private float ToDeviceIndependentUnits(float pixelCoordinate)
318318
{
319-
return pixelCoordinate / _density;
319+
return pixelCoordinate / _pixelDensity;
320320
}
321321

322322
public new void Dispose()

Mapsui.UI.Shared/MapControl.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ public Map Map
175175
public Point ToPixels(Point coordinateInDeviceIndependentUnits)
176176
{
177177
return new Point(
178-
coordinateInDeviceIndependentUnits.X * PixelsPerDeviceIndependentUnit,
179-
coordinateInDeviceIndependentUnits.Y * PixelsPerDeviceIndependentUnit);
178+
coordinateInDeviceIndependentUnits.X * PixelDensity,
179+
coordinateInDeviceIndependentUnits.Y * PixelDensity);
180180
}
181181

182182
/// <summary>
@@ -187,8 +187,8 @@ public Point ToPixels(Point coordinateInDeviceIndependentUnits)
187187
public Point ToDeviceIndependentUnits(Point coordinateInPixels)
188188
{
189189
return new Point(
190-
coordinateInPixels.X / PixelsPerDeviceIndependentUnit,
191-
coordinateInPixels.Y / PixelsPerDeviceIndependentUnit);
190+
coordinateInPixels.X / PixelDensity,
191+
coordinateInPixels.Y / PixelDensity);
192192
}
193193

194194
private void TryInitializeViewport(double screenWidth, double screenHeight)

Mapsui.UI.Uwp/MapControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs
286286
e.Handled = true;
287287
}
288288

289-
public float PixelsPerDeviceIndependentUnit =>
289+
public float PixelDensity =>
290290
(float)DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
291291

292292
private void WidgetTouched(IWidget widget, Geometries.Point screenPosition)

Mapsui.UI.Wpf/MapControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ private void MapControlLoaded(object sender, RoutedEventArgs e)
237237
Focusable = true;
238238
}
239239

240-
public float PixelsPerDeviceIndependentUnit => DetermineDeviceIndependentUnits();
240+
public float PixelDensity => DeterminePixelDensity();
241241

242-
private float DetermineDeviceIndependentUnits()
242+
private float DeterminePixelDensity()
243243
{
244244
var presentationSource = PresentationSource.FromVisual(this);
245245
if (presentationSource == null) throw new Exception("PresentationSource is null");

Mapsui.UI.iOS/MapControl.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public partial class MapControl : UIView, IMapControl
2121
/// <summary>
2222
/// The number of pixels per device independent unit
2323
/// </summary>
24-
private float _density;
24+
private float _pixelDensity;
2525

2626
public MapControl(CGRect frame)
2727
: base(frame)
@@ -53,7 +53,7 @@ public void Initialize()
5353
});
5454

5555
// Unfortunately the SKGLView does not have a IgnorePixelScaling property. We have to adjust for density with SKGLView.Scale.
56-
_density = PixelsPerDeviceIndependentUnit;
56+
_pixelDensity = PixelDensity;
5757

5858
TryInitializeViewport(ScreenWidth, ScreenHeight);
5959

@@ -77,7 +77,7 @@ public void Initialize()
7777
AddGestureRecognizer(tapGestureRecognizer);
7878
}
7979

80-
public float PixelsPerDeviceIndependentUnit => (float) _canvas.ContentScaleFactor;
80+
public float PixelDensity => (float) _canvas.ContentScaleFactor; // todo: Check if I need canvas
8181

8282
private void OnDoubleTapped(UITapGestureRecognizer gesture)
8383
{
@@ -102,7 +102,7 @@ void OnPaintSurface(object sender, SKPaintGLSurfaceEventArgs args)
102102
TryInitializeViewport(ScreenWidth, ScreenHeight);
103103
if (!_map.Viewport.Initialized) return;
104104

105-
args.Surface.Canvas.Scale(_density, _density); // we can only set the scale in the render loop
105+
args.Surface.Canvas.Scale(_pixelDensity, _pixelDensity); // we can only set the scale in the render loop
106106

107107
Renderer.Render(args.Surface.Canvas, _map.Viewport, _map.Layers, _map.Widgets, _map.BackColor);
108108
}

Mapsui/UI/IMapControl.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ public interface IMapControl
2323

2424
void Unsubscribe();
2525

26-
float PixelsPerDeviceIndependentUnit { get; }
26+
/// <summary>
27+
/// The number of pixel per device independent unit
28+
/// </summary>
29+
float PixelDensity { get; }
2730

2831
IRenderer Renderer { get; }
2932

0 commit comments

Comments
 (0)