Skip to content

Commit

Permalink
Remove unused properties and fix a render parameters update trigger bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sandermvanvliet committed Jul 10, 2023
1 parent 06aa28f commit 4a8f55e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 74 deletions.
1 change: 1 addition & 0 deletions .idea/.idea.RoadCaptain.Windows/.idea/avalonia.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/RoadCaptain.App.RouteBuilder/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
Segments="{Binding Path=Segments}"
Route="{Binding Path=Route,Mode=OneWay,Converter={StaticResource RouteViewModelConverter}}"
RiderPosition="{Binding Path=RiderPosition}"
ShowClimbs="{Binding Path=ShowClimbs}"
Markers="{Binding Path=Markers}"
IsVisible="{Binding Path=ShowElevationProfile}"
RenderMode="All"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See LICENSE or https://choosealicense.com/licenses/artistic-2.0/

using System.Collections.Generic;
using RoadCaptain.App.Shared.Controls;
using RoadCaptain.GameStates;
using RoadCaptain.Ports;

Expand Down Expand Up @@ -38,6 +39,8 @@ public DesignTimeElevationProfileWindowViewModel()
0,
0,
0));

RenderMode = RenderMode.Moving;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
Segments="{Binding Path=Segments}"
Route="{Binding Path=Route}"
RiderPosition="{Binding Path=RiderPosition}"
ShowClimbs="True"
Markers="{Binding Path=Markers}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Expand Down
47 changes: 0 additions & 47 deletions src/RoadCaptain.App.Shared/Controls/ElevationProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class ElevationProfile : UserControl
public static readonly DirectProperty<ElevationProfile, List<Segment>?> SegmentsProperty = AvaloniaProperty.RegisterDirect<ElevationProfile, List<Segment>?>(nameof(Segments), map => map.Segments, (map, value) => map.Segments = value);
public static readonly DirectProperty<ElevationProfile, TrackPoint?> RiderPositionProperty = AvaloniaProperty.RegisterDirect<ElevationProfile, TrackPoint?>(nameof(RiderPosition), map => map.RiderPosition, (map, value) => map.RiderPosition = value);
public static readonly DirectProperty<ElevationProfile, List<Segment>?> MarkersProperty = AvaloniaProperty.RegisterDirect<ElevationProfile, List<Segment>?>(nameof(Markers), map => map.Markers, (map, value) => map.Markers = value);
public static readonly DirectProperty<ElevationProfile, bool> ShowClimbsProperty = AvaloniaProperty.RegisterDirect<ElevationProfile, bool>(nameof(ShowClimbs), map => map.ShowClimbs, (map, value) => map.ShowClimbs = value);
public static readonly DirectProperty<ElevationProfile, RenderMode> RenderModeProperty = AvaloniaProperty.RegisterDirect<ElevationProfile, RenderMode>(nameof(RenderMode), map => map.RenderMode, (map, value) => map.RenderMode = value);

private RenderTargetBitmap? _renderTarget;
Expand Down Expand Up @@ -76,52 +75,6 @@ public class ElevationProfile : UserControl
}
}

public bool ShowClimbs
{
get => _renderOperation.ShowClimbs;
set
{
_renderOperation.ShowClimbs = value;

InvalidateVisual();
}
}

public bool ZoomOnCurrentPosition
{
get => _renderOperation.ZoomOnCurrentPosition;
set
{
_renderOperation.ZoomOnCurrentPosition = value;

InvalidateVisual();
}
}

public int ZoomWindowDistance
{
get => _renderOperation.ZoomWindowDistance;
set
{
_renderOperation.ZoomWindowDistance = value;

InvalidateVisual();
}
}

public bool ZoomToClimb
{
get => _renderOperation.ZoomToClimb;
set
{
if (value == _renderOperation.ZoomToClimb) return;

_renderOperation.ZoomToClimb = value;

InvalidateVisual();
}
}

public RenderMode RenderMode
{
get => _renderOperation.RenderMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public class ElevationProfileLayeredRenderOperation: ICustomDrawOperation
private PlannedRoute? _route;
private TrackPoint? _riderPosition;
private int _previousIndex;
private int _zoomWindowMetersBehind;
private int _zoomWindowMetersAhead;
private CalculatedElevationProfile? _elevationProfile;
private RenderParameters? _renderParameters;
private RenderMode _renderMode = RenderMode.All;
Expand Down Expand Up @@ -94,9 +92,16 @@ public Rect Bounds
{
if (_bounds == value) return;
_bounds = value;
_elevationProfile = CalculatedElevationProfile.From(Route, Segments);
_renderParameters = RenderParameters.From(RenderMode, Bounds, _elevationProfile, RiderPosition, Markers);
_elevationProfile.CalculatePathsForElevationGroups(_renderParameters);
if (_elevationProfile != null)
{
_renderParameters = RenderParameters.From(RenderMode, Bounds, _elevationProfile, RiderPosition, Markers);
_elevationProfile.CalculatePathsForElevationGroups(_renderParameters);
}
else
{
// Clear render parameters
_renderParameters = null;
}
}
}

Expand All @@ -111,12 +116,18 @@ public RenderMode RenderMode
}

_renderMode = value;

_renderParameters = RenderParameters.From(RenderMode, Bounds, _elevationProfile, RiderPosition, Markers);

if (_elevationProfile != null)
{
_renderParameters = RenderParameters.From(RenderMode, Bounds, _elevationProfile, RiderPosition, Markers);
_elevationProfile.CalculatePathsForElevationGroups(_renderParameters);
}
}
}

public List<Segment>? Segments { get; set; }

public List<Segment>? Markers { get; set; }

public TrackPoint? RiderPosition
{
Expand All @@ -139,24 +150,6 @@ public RenderMode RenderMode
}
}

public bool ShowClimbs { get; set; }
public List<Segment>? Markers { get; set; }
public bool ZoomOnCurrentPosition { get; set; }

public int ZoomWindowDistance
{
get => _zoomWindowMetersBehind + _zoomWindowMetersAhead;
set
{
var x = (int)Math.Round(value * 0.05, 0, MidpointRounding.AwayFromZero);

_zoomWindowMetersBehind = x;
_zoomWindowMetersAhead = value - x;
}
}

public bool ZoomToClimb { get; set; }

public void Dispose()
{
// Nop
Expand Down

0 comments on commit 4a8f55e

Please sign in to comment.