mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Added size observer to enable auto-centering the editor at some point
This commit is contained in:
parent
8c9144a136
commit
0b56fd9088
@ -1,44 +0,0 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Artemis.UI.Adorners
|
||||
{
|
||||
public class BoundingBoxAdorner : Adorner
|
||||
{
|
||||
private Color _boundingBoxColor;
|
||||
private Rect _boundingBoxRect;
|
||||
|
||||
public BoundingBoxAdorner(UIElement adornedElement, Color boundingBoxColor) : base(adornedElement)
|
||||
{
|
||||
_boundingBoxRect = new Rect(new Size(0, 0));
|
||||
BoundingBoxColor = boundingBoxColor;
|
||||
|
||||
IsHitTestVisible = false;
|
||||
}
|
||||
|
||||
public Color BoundingBoxColor
|
||||
{
|
||||
get => _boundingBoxColor;
|
||||
set
|
||||
{
|
||||
_boundingBoxColor = value;
|
||||
InvalidateVisual();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext drawingContext)
|
||||
{
|
||||
var renderBrush = new SolidColorBrush(BoundingBoxColor) {Opacity = 0.2};
|
||||
var renderPen = new Pen(new SolidColorBrush(BoundingBoxColor), 1.5);
|
||||
|
||||
drawingContext.DrawRectangle(renderBrush, renderPen, _boundingBoxRect);
|
||||
}
|
||||
|
||||
public void Update(Point startingPoint, Point currentPoint)
|
||||
{
|
||||
_boundingBoxRect = new Rect(startingPoint, currentPoint);
|
||||
InvalidateVisual();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -147,7 +147,6 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Adorners\BoundingBoxAdorner.cs" />
|
||||
<Compile Include="Bootstrapper.cs" />
|
||||
<Compile Include="Converters\ColorToSolidColorBrushConverter.cs" />
|
||||
<Compile Include="Converters\InverseBooleanConverter.cs" />
|
||||
@ -162,6 +161,7 @@
|
||||
<Compile Include="Ninject\Factories\IModuleViewModelFactory.cs" />
|
||||
<Compile Include="Ninject\Factories\IProfileEditorViewModelFactory.cs" />
|
||||
<Compile Include="Ninject\UIModule.cs" />
|
||||
<Compile Include="Observers\SizeObserver.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
77
src/Artemis.UI/Observers/SizeObserver.cs
Normal file
77
src/Artemis.UI/Observers/SizeObserver.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace Artemis.UI.Observers
|
||||
{
|
||||
public static class SizeObserver
|
||||
{
|
||||
public static readonly DependencyProperty ObserveProperty = DependencyProperty.RegisterAttached(
|
||||
"Observe",
|
||||
typeof(bool),
|
||||
typeof(SizeObserver),
|
||||
new FrameworkPropertyMetadata(OnObserveChanged));
|
||||
|
||||
public static readonly DependencyProperty ObservedWidthProperty = DependencyProperty.RegisterAttached(
|
||||
"ObservedWidth",
|
||||
typeof(double),
|
||||
typeof(SizeObserver));
|
||||
|
||||
public static readonly DependencyProperty ObservedHeightProperty = DependencyProperty.RegisterAttached(
|
||||
"ObservedHeight",
|
||||
typeof(double),
|
||||
typeof(SizeObserver));
|
||||
|
||||
public static bool GetObserve(FrameworkElement frameworkElement)
|
||||
{
|
||||
return (bool) frameworkElement.GetValue(ObserveProperty);
|
||||
}
|
||||
|
||||
public static void SetObserve(FrameworkElement frameworkElement, bool observe)
|
||||
{
|
||||
frameworkElement.SetValue(ObserveProperty, observe);
|
||||
}
|
||||
|
||||
public static double GetObservedWidth(FrameworkElement frameworkElement)
|
||||
{
|
||||
return (double) frameworkElement.GetValue(ObservedWidthProperty);
|
||||
}
|
||||
|
||||
public static void SetObservedWidth(FrameworkElement frameworkElement, double observedWidth)
|
||||
{
|
||||
frameworkElement.SetValue(ObservedWidthProperty, observedWidth);
|
||||
}
|
||||
|
||||
public static double GetObservedHeight(FrameworkElement frameworkElement)
|
||||
{
|
||||
return (double) frameworkElement.GetValue(ObservedHeightProperty);
|
||||
}
|
||||
|
||||
public static void SetObservedHeight(FrameworkElement frameworkElement, double observedHeight)
|
||||
{
|
||||
frameworkElement.SetValue(ObservedHeightProperty, observedHeight);
|
||||
}
|
||||
|
||||
private static void OnObserveChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var frameworkElement = (FrameworkElement) dependencyObject;
|
||||
|
||||
if ((bool) e.NewValue)
|
||||
{
|
||||
frameworkElement.SizeChanged += OnFrameworkElementSizeChanged;
|
||||
UpdateObservedSizesForFrameworkElement(frameworkElement);
|
||||
}
|
||||
else
|
||||
frameworkElement.SizeChanged -= OnFrameworkElementSizeChanged;
|
||||
}
|
||||
|
||||
private static void OnFrameworkElementSizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
UpdateObservedSizesForFrameworkElement((FrameworkElement) sender);
|
||||
}
|
||||
|
||||
private static void UpdateObservedSizesForFrameworkElement(FrameworkElement frameworkElement)
|
||||
{
|
||||
frameworkElement.SetCurrentValue(ObservedWidthProperty, frameworkElement.ActualWidth);
|
||||
frameworkElement.SetCurrentValue(ObservedHeightProperty, frameworkElement.ActualHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,7 @@
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:profileEditor="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.Visualization"
|
||||
xmlns:observers="clr-namespace:Artemis.UI.Observers"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type profileEditor:ProfileViewModel}}">
|
||||
@ -42,7 +43,10 @@
|
||||
MouseUp="{s:Action EditorGridMouseClick}"
|
||||
MouseDown="{s:Action EditorGridMouseClick}"
|
||||
MouseMove="{s:Action EditorGridMouseMove}"
|
||||
Cursor="{Binding Cursor}">
|
||||
Cursor="{Binding Cursor}"
|
||||
observers:SizeObserver.Observe="True"
|
||||
observers:SizeObserver.ObservedWidth="{Binding PanZoomViewModel.CanvasWidth, Mode=OneWayToSource}"
|
||||
observers:SizeObserver.ObservedHeight="{Binding PanZoomViewModel.CanvasHeight, Mode=OneWayToSource}">
|
||||
|
||||
<Grid.Background>
|
||||
<VisualBrush TileMode="Tile" Stretch="Uniform" Viewport="{Binding PanZoomViewModel.BackgroundViewport}" ViewportUnits="Absolute">
|
||||
|
||||
@ -20,6 +20,8 @@ namespace Artemis.UI.Screens.Shared
|
||||
|
||||
public double PanX { get; set; }
|
||||
public double PanY { get; set; }
|
||||
public double CanvasWidth { get; set; }
|
||||
public double CanvasHeight { get; set; }
|
||||
|
||||
public Rect BackgroundViewport => new Rect(PanX, PanY, 20, 20);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user