Skip to content

Commit

Permalink
Resolve WPF merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
BAndysc committed Jul 23, 2024
1 parent e9eab92 commit e6aff83
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 92 deletions.
26 changes: 14 additions & 12 deletions Examples/Nodify.Shapes/Canvas/CanvasView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@
BorderBrush="{x:Null}"
Margin="20">
<shared:ResizablePanel.Resources>
<Style TargetType="{x:Type shared:Resizer}">
<ControlTheme TargetType="{x:Type shared:Resizer}" BasedOn="{StaticResource {x:Type shared:Resizer}}" x:Key="{x:Type shared:Resizer}">
<Setter Property="Cursor"
Value="SizeNESW" />
Value="SizeAll" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type shared:Resizer}">
Expand All @@ -387,21 +387,21 @@
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ControlTheme>
</shared:ResizablePanel.Resources>
<Border CornerRadius="3"
BorderBrush="#1e293b"
BorderThickness="3">
<Border.Effect>
<DropShadowEffect ShadowDepth="1" />
<DropShadowDirectionEffect ShadowDepth="1" />
</Border.Effect>

<nodify:Minimap ItemsSource="{Binding ItemsSource, ElementName=Editor}"
ViewportLocation="{Binding ViewportLocation, ElementName=Editor}"
ViewportSize="{Binding ViewportSize, ElementName=Editor}"
ResizeToViewport="True"
Zoom="Minimap_Zoom">
<nodify:Minimap.Resources>
<nodify:Minimap.DataTemplates>
<DataTemplate DataType="{x:Type local:EllipseViewModel}">
<Ellipse Stretch="Fill"
Fill="{Binding Color, Converter={StaticResource ColorToSolidColorBrushConverter}}"
Expand All @@ -426,23 +426,25 @@
StrokeThickness="2"
Opacity="0.8" />
</DataTemplate>
</nodify:Minimap.Resources>
</nodify:Minimap.DataTemplates>
<nodify:Minimap.Background>
<SolidColorBrush Color="#111a2d"
Opacity="0.5" />
</nodify:Minimap.Background>
<nodify:Minimap.ItemContainerStyle>
<Style TargetType="{x:Type nodify:MinimapItem}">
<nodify:Minimap.ItemContainerTheme>
<ControlTheme TargetType="{x:Type nodify:MinimapItem}"
x:DataType="local:ShapeViewModel"
BasedOn="{StaticResource {x:Type nodify:MinimapItem}}">
<Setter Property="Location"
Value="{Binding Location}" />
<Setter Property="Width"
Value="{Binding Width}" />
<Setter Property="Height"
Value="{Binding Height}" />
</Style>
</nodify:Minimap.ItemContainerStyle>
</ControlTheme>
</nodify:Minimap.ItemContainerTheme>
<nodify:Minimap.ViewportStyle>
<Style TargetType="Rectangle">
<ControlTheme TargetType="Rectangle">
<Setter Property="StrokeThickness"
Value="3" />
<Setter Property="Fill">
Expand All @@ -451,7 +453,7 @@
Opacity="0.3" />
</Setter.Value>
</Setter>
</Style>
</ControlTheme>
</nodify:Minimap.ViewportStyle>
</nodify:Minimap>
</Border>
Expand Down
17 changes: 17 additions & 0 deletions Nodify/Minimap/Minimap.Avalonia.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Nodify;

public partial class Minimap
{
private Point viewportLocation;

protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
{
recycleKey = null;
return !IsItemItsOwnContainerOverride(item);
}

protected override Control CreateContainerForItemOverride(object? item, int index, object? recycleKey)
{
return GetContainerForItemOverride() as Control;
}
}
75 changes: 40 additions & 35 deletions Nodify/Minimap/Minimap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ namespace Nodify
/// A minimap control that can position the viewport, and zoom in and out.
/// </summary>
[StyleTypedProperty(Property = nameof(ViewportStyle), StyleTargetType = typeof(Rectangle))]
[StyleTypedProperty(Property = nameof(ItemContainerStyle), StyleTargetType = typeof(MinimapItem))]
[StyleTypedProperty(Property = nameof(ItemContainerTheme), StyleTargetType = typeof(MinimapItem))]
[TemplatePart(Name = ElementItemsHost, Type = typeof(Panel))]
public class Minimap : ItemsControl
public partial class Minimap : ItemsControl
{
protected const string ElementItemsHost = "PART_ItemsHost";

public static readonly DependencyProperty ViewportLocationProperty = NodifyEditor.ViewportLocationProperty.AddOwner(typeof(Minimap), new FrameworkPropertyMetadata(BoxValue.Point, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static readonly DependencyProperty ViewportSizeProperty = NodifyEditor.ViewportSizeProperty.AddOwner(typeof(Minimap));
public static readonly DependencyProperty ViewportStyleProperty = DependencyProperty.Register(nameof(ViewportStyle), typeof(Style), typeof(Minimap));
public static readonly DependencyProperty ExtentProperty = NodifyCanvas.ExtentProperty.AddOwner(typeof(Minimap));
public static readonly DependencyProperty ItemsExtentProperty = DependencyProperty.Register(nameof(ItemsExtent), typeof(Rect), typeof(Minimap));
public static readonly DependencyProperty MaxViewportOffsetProperty = DependencyProperty.Register(nameof(MaxViewportOffset), typeof(Size), typeof(Minimap), new FrameworkPropertyMetadata(new Size(2000, 2000)));
public static readonly DependencyProperty ResizeToViewportProperty = DependencyProperty.Register(nameof(ResizeToViewport), typeof(bool), typeof(Minimap));
public static readonly DependencyProperty IsReadOnlyProperty = TextBoxBase.IsReadOnlyProperty.AddOwner(typeof(Minimap));
public static readonly DirectProperty<Minimap, Point> ViewportLocationProperty = NodifyEditor.ViewportLocationProperty.AddOwner<Minimap>(e => e.ViewportLocation, (e, v) => e.ViewportLocation = v, default, BindingMode.TwoWay);
public static readonly StyledProperty<Size> ViewportSizeProperty = NodifyEditor.ViewportSizeProperty.AddOwner<Minimap>();
public static readonly StyledProperty<ControlTheme> ViewportStyleProperty = AvaloniaProperty.Register<Minimap, ControlTheme>(nameof(ViewportStyle));
public static readonly StyledProperty<Rect> ExtentProperty = NodifyCanvas.ExtentProperty.AddOwner<Minimap>();
public static readonly StyledProperty<Rect> ItemsExtentProperty = AvaloniaProperty.Register<Minimap, Rect>(nameof(ItemsExtent));
public static readonly StyledProperty<Size> MaxViewportOffsetProperty = AvaloniaProperty.Register<Minimap, Size>(nameof(MaxViewportOffset), new Size(2000, 2000));
public static readonly StyledProperty<bool> ResizeToViewportProperty = AvaloniaProperty.Register<Minimap, bool>(nameof(ResizeToViewport));
public static readonly StyledProperty<bool> IsReadOnlyProperty = TextBox.IsReadOnlyProperty.AddOwner<Minimap>();

public static readonly RoutedEvent ZoomEvent = EventManager.RegisterRoutedEvent(nameof(Zoom), RoutingStrategy.Bubble, typeof(ZoomEventHandler), typeof(Minimap));
public static readonly RoutedEvent ZoomEvent = RoutedEvent.Register<ZoomEventArgs>(nameof(Zoom), RoutingStrategies.Bubble, typeof(Minimap));

/// <inheritdoc cref="NodifyEditor.ViewportLocation" />
public Point ViewportLocation
{
get => (Point)GetValue(ViewportLocationProperty);
set => SetValue(ViewportLocationProperty, value);
get => viewportLocation;
set => SetAndRaise(ViewportLocationProperty, ref viewportLocation, value);
}

/// <inheritdoc cref="NodifyEditor.ViewportSize" />
Expand All @@ -45,9 +45,9 @@ public Size ViewportSize
/// <summary>
/// Gets or sets the style to use for the viewport rectangle.
/// </summary>
public Style ViewportStyle
public ControlTheme ViewportStyle
{
get => (Style)GetValue(ViewportStyleProperty);
get => (ControlTheme)GetValue(ViewportStyleProperty);
set => SetValue(ViewportStyleProperty, value);
}

Expand Down Expand Up @@ -96,29 +96,30 @@ public event ZoomEventHandler Zoom
/// <summary>
/// Gets the panel that holds all the <see cref="MinimapItem"/>s.
/// </summary>
protected internal Panel ItemsHost { get; private set; } = default!;
protected internal ItemsPresenter ItemsHost { get; private set; } = default!;

static Minimap()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Minimap), new FrameworkPropertyMetadata(typeof(Minimap)));
ClipToBoundsProperty.OverrideMetadata(typeof(Minimap), new FrameworkPropertyMetadata(BoxValue.True));
ClipToBoundsProperty.OverrideMetadata(typeof(Minimap), new StyledPropertyMetadata<bool>(BoxValue.True));
}

public override void OnApplyTemplate()
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate();
base.OnApplyTemplate(e);

ItemsHost = GetTemplateChild(ElementItemsHost) as Panel ?? throw new InvalidOperationException($"{ElementItemsHost} is missing or is not of type {nameof(Panel)}.");
ItemsHost = e.NameScope.Get<ItemsPresenter>("PART_ItemsPresenter");
}

protected bool IsDragging { get; private set; }

protected override void OnMouseDown(MouseButtonEventArgs e)
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
var gestures = EditorGestures.Mappings.Minimap;
if (!IsReadOnly && gestures.DragViewport.Matches(this, e))
{
this.CaptureMouseSafe();
e.Pointer.Capture(this);
this.PropagateMouseCapturedWithin(true);
IsDragging = true;

SetViewportLocation(e.GetPosition(ItemsHost));
Expand All @@ -127,7 +128,7 @@ protected override void OnMouseDown(MouseButtonEventArgs e)
}
}

protected override void OnMouseMove(MouseEventArgs e)
protected override void OnPointerMoved(PointerEventArgs e)
{
if (IsDragging)
{
Expand All @@ -137,40 +138,44 @@ protected override void OnMouseMove(MouseEventArgs e)

private void SetViewportLocation(Point location)
{
var position = location - new Vector(ViewportSize.Width / 2, ViewportSize.Height / 2) + (Vector)Extent.Location;
var position = location - new Vector(ViewportSize.Width / 2, ViewportSize.Height / 2) + (Vector)Extent.Position;

if (MaxViewportOffset.Width != 0 || MaxViewportOffset.Height != 0)
{
double maxRight = ResizeToViewport ? ItemsExtent.Right : Math.Max(ItemsExtent.Right, ItemsExtent.Left + ViewportSize.Width);
double maxBottom = ResizeToViewport ? ItemsExtent.Bottom : Math.Max(ItemsExtent.Bottom, ItemsExtent.Top + ViewportSize.Height);

position.X = position.X.Clamp(ItemsExtent.Left - ViewportSize.Width / 2 - MaxViewportOffset.Width, maxRight - ViewportSize.Width / 2 + MaxViewportOffset.Width);
position.Y = position.Y.Clamp(ItemsExtent.Top - ViewportSize.Height / 2 - MaxViewportOffset.Height, maxBottom - ViewportSize.Height / 2 + MaxViewportOffset.Height);
position = new Point(
position.X.Clamp(ItemsExtent.Left - ViewportSize.Width / 2 - MaxViewportOffset.Width, maxRight - ViewportSize.Width / 2 + MaxViewportOffset.Width),
position.Y.Clamp(ItemsExtent.Top - ViewportSize.Height / 2 - MaxViewportOffset.Height, maxBottom - ViewportSize.Height / 2 + MaxViewportOffset.Height)
);
}

ViewportLocation = position;
}

protected override void OnMouseUp(MouseButtonEventArgs e)
protected override void OnPointerReleased(PointerReleasedEventArgs e)
{
var gestures = EditorGestures.Mappings.Minimap;
if (IsDragging && gestures.DragViewport.Matches(this, e))
{
IsDragging = false;
}

if (IsMouseCaptured && e.RightButton == MouseButtonState.Released && e.LeftButton == MouseButtonState.Released && e.MiddleButton == MouseButtonState.Released)
var props = e.GetCurrentPoint(this).Properties;
if (/*IsMouseCaptured && */ !props.IsRightButtonPressed && !props.IsLeftButtonPressed && !props.IsMiddleButtonPressed)
{
ReleaseMouseCapture();
e.Pointer.Capture(null);
this.PropagateMouseCapturedWithin(false);
}
}

protected override void OnMouseWheel(MouseWheelEventArgs e)
protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{
if (!IsReadOnly && !e.Handled && EditorGestures.Mappings.Minimap.ZoomModifierKey == Keyboard.Modifiers)
if (!IsReadOnly && !e.Handled && EditorGestures.Mappings.Minimap.ZoomModifierKey == e.KeyModifiers)
{
double zoom = Math.Pow(2.0, e.Delta / 3.0 / Mouse.MouseWheelDeltaForOneLine);
var location = ViewportLocation + (Vector)ViewportSize / 2;
double zoom = Math.Pow(2.0, e.Delta.Length / 3.0 / NodifyEditor.MouseWheelDeltaForOneLine);
var location = ViewportLocation + ViewportSize.ToVector() / 2;

var args = new ZoomEventArgs(zoom, location)
{
Expand All @@ -183,10 +188,10 @@ protected override void OnMouseWheel(MouseWheelEventArgs e)
}
}

protected override DependencyObject GetContainerForItemOverride()
protected DependencyObject GetContainerForItemOverride()
=> new MinimapItem();

protected override bool IsItemItsOwnContainerOverride(object item)
protected bool IsItemItsOwnContainerOverride(object item)
=> item is MinimapItem;
}
}
7 changes: 6 additions & 1 deletion Nodify/Minimap/MinimapItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Nodify
{
public class MinimapItem : ContentControl
{
public static readonly DependencyProperty LocationProperty = ItemContainer.LocationProperty.AddOwner(typeof(MinimapItem), new FrameworkPropertyMetadata(BoxValue.Point, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.AffectsParentMeasure));
public static readonly StyledProperty<Point> LocationProperty = ItemContainer.LocationProperty.AddOwner<MinimapItem>(new StyledPropertyMetadata<Point>(BoxValue.Point, BindingMode.TwoWay));

/// <summary>
/// Gets or sets the location of this <see cref="MinimapItem"/> inside the <see cref="Minimap"/>.
Expand All @@ -15,5 +15,10 @@ public Point Location
get => (Point)GetValue(LocationProperty);
set => SetValue(LocationProperty, value);
}

static MinimapItem()
{
PanelUtilities.AffectsParentArrange<DecoratorContainer>(LocationProperty);
}
}
}
11 changes: 11 additions & 0 deletions Nodify/Minimap/MinimapPanel.Avalonia.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Nodify;

internal partial class MinimapPanel
{
private Point viewportLocation;

static MinimapPanel()
{
AffectsMeasure<MinimapPanel>(ViewportSizeProperty, ViewportLocationProperty);
}
}
26 changes: 13 additions & 13 deletions Nodify/Minimap/MinimapPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

namespace Nodify
{
internal class MinimapPanel : Panel
internal partial class MinimapPanel : Panel
{
public static readonly DependencyProperty ViewportLocationProperty = NodifyEditor.ViewportLocationProperty.AddOwner(typeof(MinimapPanel), new FrameworkPropertyMetadata(BoxValue.Point, FrameworkPropertyMetadataOptions.AffectsMeasure));
public static readonly DependencyProperty ViewportSizeProperty = NodifyEditor.ViewportSizeProperty.AddOwner(typeof(MinimapPanel), new FrameworkPropertyMetadata(BoxValue.Size, FrameworkPropertyMetadataOptions.AffectsMeasure));
public static readonly DependencyProperty ExtentProperty = NodifyCanvas.ExtentProperty.AddOwner(typeof(MinimapPanel));
public static readonly DependencyProperty ItemsExtentProperty = Minimap.ItemsExtentProperty.AddOwner(typeof(MinimapPanel));
public static readonly DependencyProperty ResizeToViewportProperty = Minimap.ResizeToViewportProperty.AddOwner(typeof(MinimapPanel));
public static readonly DirectProperty<MinimapPanel, Point> ViewportLocationProperty = NodifyEditor.ViewportLocationProperty.AddOwner<MinimapPanel>(e => e.ViewportLocation, (e, v) => e.ViewportLocation = v);
public static readonly StyledProperty<Size> ViewportSizeProperty = NodifyEditor.ViewportSizeProperty.AddOwner<MinimapPanel>();
public static readonly StyledProperty<Rect> ExtentProperty = NodifyCanvas.ExtentProperty.AddOwner<MinimapPanel>();
public static readonly StyledProperty<Rect> ItemsExtentProperty = Minimap.ItemsExtentProperty.AddOwner<MinimapPanel>();
public static readonly StyledProperty<bool> ResizeToViewportProperty = Minimap.ResizeToViewportProperty.AddOwner<MinimapPanel>();

/// <inheritdoc cref="Minimap.ViewportLocation" />
public Point ViewportLocation
{
get => (Point)GetValue(ViewportLocationProperty);
set => SetValue(ViewportLocationProperty, value);
get => viewportLocation;
set => SetAndRaise(ViewportLocationProperty, ref viewportLocation, value);
}

/// <inheritdoc cref="Minimap.ViewportSize" />
Expand Down Expand Up @@ -55,7 +55,7 @@ protected override Size MeasureOverride(Size availableSize)
double maxX = double.MinValue;
double maxY = double.MinValue;

UIElementCollection children = InternalChildren;
UIElementCollection children = Children;
for (int i = 0; i < children.Count; i++)
{
var item = (MinimapItem)children[i];
Expand Down Expand Up @@ -90,14 +90,14 @@ protected override Size MeasureOverride(Size availableSize)
? new Rect(0, 0, 0, 0)
: new Rect(minX, minY, maxX - minX, maxY - minY);

ItemsExtent = itemsExtent;
SetCurrentValue(ItemsExtentProperty, itemsExtent);

if (ResizeToViewport)
{
itemsExtent.Union(new Rect(ViewportLocation, ViewportSize));
}

Extent = itemsExtent;
SetCurrentValue(ExtentProperty, itemsExtent);

double width = Math.Max(itemsExtent.Size.Width, ViewportSize.Width);
double height = Math.Max(itemsExtent.Height, ViewportSize.Height);
Expand All @@ -106,11 +106,11 @@ protected override Size MeasureOverride(Size availableSize)

protected override Size ArrangeOverride(Size finalSize)
{
UIElementCollection children = InternalChildren;
UIElementCollection children = Children;
for (int i = 0; i < children.Count; i++)
{
var item = (MinimapItem)children[i];
item.Arrange(new Rect(item.Location - (Vector)Extent.Location, item.DesiredSize));
item.Arrange(new Rect(item.Location - (Vector)Extent.Position, item.DesiredSize));
}

return finalSize;
Expand Down
Loading

0 comments on commit e6aff83

Please sign in to comment.