Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/FEntwumS.Common/Builders/GenericGraphElementBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public T Build()
{
X = this._x,
Y = this._y,
Width = this._width,
Height = this._height,
ElementWidth = this._width,
ElementHeight = this._height,
srcLocation = this._srclocation,
ZIndex = _zIndex,
ClipToBounds = false
Expand Down
26 changes: 13 additions & 13 deletions src/FEntwumS.Common/Builders/GraphNodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,18 @@ public GraphNodeBuilder<T> WithExpandCollapseInteractionControl(
(expandCollapseButton.Content as PathIcon)?.Data = AppIcons.MINUS;
}

directAncestorNode.PropertyChanged += (o, eventArgs) =>
{
if (eventArgs.Property == PositionableSubControl.ScaleProperty &&
expandCollapseButton.Content is PathIcon buttonContent)
{
double newScale = (double)eventArgs.NewValue!;
double oldScale = (double)eventArgs.OldValue!;
double scaleDifference = newScale / oldScale;

expandCollapseButton.GetVisualParent<StackPanel>()?.RenderTransform = new ScaleTransform(newScale, newScale);
}
};
// directAncestorNode.PropertyChanged += (o, eventArgs) =>
// {
// if (eventArgs.Property == PositionableSubControl.ScaleProperty &&
// expandCollapseButton.Content is PathIcon buttonContent)
// {
// double newScale = (double)eventArgs.NewValue!;
// double oldScale = (double)eventArgs.OldValue!;
// double scaleDifference = newScale / oldScale;
//
// expandCollapseButton.GetVisualParent<StackPanel>()?.RenderTransform = new ScaleTransform(newScale, newScale);
// }
// };
}
};

Expand Down Expand Up @@ -514,7 +514,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
}

sendingPanningNetlist.ZoomBounds = new Rect(new Point(absoluteX, absoluteY),
new Size(clickedNode.Width, clickedNode.Height));
new Size(clickedNode.ElementWidth, clickedNode.ElementHeight));
}
else
{
Expand Down
24 changes: 4 additions & 20 deletions src/FEntwumS.Common/Controls/GenericGraphElementControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,21 @@ public string srcLocation
AvaloniaProperty.Register<GenericGraphElementControl, string>(nameof(srcLocation),
defaultBindingMode: BindingMode.TwoWay,
defaultValue: "");

public double cullingOriginX = 0.0d;
public double cullingOriginY = 0.0d;

#endregion

#region Event Handling

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Property == ParentProperty)
{
var newParent = e.NewValue;

if (newParent is PanningControl { Child: GenericGraphElementControl childControl })
childControl.PropertyChanged += (sender, args) =>
{
if (args.Property == ScaleProperty && args.NewValue is double newScale)
{
childControl.NetlistTheme.RegenerateBrushesAndPens(newScale);
}
};
}

base.OnPropertyChanged(e);
}

#endregion

#region Rendering

protected override Size MeasureCore(Size availableSize)
{
return Double.IsNaN(Width) || Double.IsNaN(Height) ? new Size(100, 100) : new Size(Width, Height);
return Double.IsNaN(ElementWidth) || Double.IsNaN(ElementHeight) ? new Size(100, 100) : new Size(ElementWidth, ElementHeight);
}

protected override void ArrangeCore(Rect finalRect)
Expand Down
25 changes: 23 additions & 2 deletions src/FEntwumS.Common/Controls/GraphEdgeControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,30 @@ public override void Render(DrawingContext context)
context.DrawGeometry(null, linePen, _contentGeometry);
}

protected override void RegenerateDrawnElements()
protected override void UpdateScale(double newScale)
{
_contentGeometry.Transform = new ScaleTransform(Scale, Scale);
double scaleDifference = newScale / Scale;

base.UpdateScale(newScale);

cullingOriginX *= scaleDifference;
cullingOriginY *= scaleDifference;
ElementWidth *= scaleDifference;
ElementHeight *= scaleDifference;
}

protected override void RegenerateDrawnElements(double newScale)
{
if (!this.IsVisible)
{
return;
}

_contentGeometry.Transform = new ScaleTransform(newScale, newScale);
Rect newBounds = _contentGeometry.Bounds;

ElementWidth = newBounds.Width;
ElementHeight = newBounds.Height;
}

#endregion
Expand Down
82 changes: 60 additions & 22 deletions src/FEntwumS.Common/Controls/GraphEntityNodeControl.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
using Avalonia;
using Avalonia.Data;
using Avalonia.Interactivity;
using FEntwumS.Common.Services;
using OneWare.Essentials.Services;

namespace FEntwumS.Common.Controls;

public class GraphEntityNodeControl : GraphNodeControl
{
#region Properties

private Rect _currentViewPort= new Rect(0, 0, 3840, 2160);

public Rect CurrentViewPort
{

get => _currentViewPort;
set
{
_currentViewPort = value;
CheckChildVisibility();

if (_hasEntityChildren)
{
foreach (GraphEntityNodeControl childEntity in _childEntities)
{
childEntity.CurrentViewPort = new Rect(_currentViewPort.X - childEntity.X, _currentViewPort.Y - childEntity.Y, _currentViewPort.Width, _currentViewPort.Height);
}
}
OnViewPortChanged();
}
}

Expand All @@ -34,37 +29,80 @@ public Rect CurrentViewPort

private List<GraphEntityNodeControl> _childEntities = new List<GraphEntityNodeControl>();
private bool _hasEntityChildren = true;

private List<GenericGraphElementControl> _childElements = new List<GenericGraphElementControl>();
private bool _hasChildElements = true;
#endregion

#region Event handling

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
protected override void OnLoaded(RoutedEventArgs e)
{
_childEntities.Clear();
_childEntities.AddRange(this.VisualChildren.OfType<GraphEntityNodeControl>());

_hasEntityChildren = _childEntities.Count > 0;

base.OnAttachedToVisualTree(e);
_childElements.Clear();
_childElements.AddRange(this.VisualChildren.OfType<GenericGraphElementControl>());

_hasChildElements = _childElements.Count > 0;

base.OnLoaded(e);
}

protected void CheckChildVisibility()
protected virtual void OnViewPortChanged()
{
if (!_hasEntityChildren)
if (!this.IsVisible)
{
return;
}

foreach (GraphEntityNodeControl childEntity in _childEntities)
CheckChildVisibility();

if (_hasEntityChildren)
{
Rect childArea = new Rect(childEntity.X, childEntity.Y,
childEntity.Width, childEntity.Height);
foreach (GraphEntityNodeControl childEntity in _childEntities)
{
childEntity.CurrentViewPort = new Rect(CurrentViewPort.X - childEntity.X, CurrentViewPort.Y - childEntity.Y, CurrentViewPort.Width, CurrentViewPort.Height);
}
}
}

protected virtual void CheckChildVisibility()
{
#if DEBUG
if (ServiceManager.GetService<ISettingsService>().GetSettingValue<bool>("NetlistViewer_FreezeGUIState"))
{
return;
}
#endif

if (!_hasChildElements)
{
return;
}

foreach (GenericGraphElementControl childElement in _childElements)
{
Rect childArea = new Rect(childElement.cullingOriginX, childElement.cullingOriginY,
childElement.ElementWidth, childElement.ElementHeight);

bool isVisible = CurrentViewPort.Contains(childArea)
|| childArea.Intersects(CurrentViewPort)
|| childArea.Contains(CurrentViewPort);

childEntity.IsVisible = isVisible;
|| childArea.Intersects(CurrentViewPort)
|| childArea.Contains(CurrentViewPort);
if (!childElement.IsVisible && isVisible)
{
childElement.IsVisible = true;

childElement.Scale = this.Scale;

childElement.InvalidateMeasure();
}
else
{
childElement.IsVisible = isVisible;
}
}
}

Expand Down
31 changes: 22 additions & 9 deletions src/FEntwumS.Common/Controls/GraphJunctionControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public JunctionShape _junctionShape

protected override void OnInitialized()
{
double rh = Width / 2.0d,
rv = Height / 2.0d;
double rh = ElementWidth / 2.0d,
rv = ElementHeight / 2.0d;

double ow = Width * 1.4d,
oh = Height * 1.4d;
double ow = ElementWidth * 1.4d,
oh = ElementHeight * 1.4d;

double orh = ow / 2.0d,
orv = oh / 2.0d;
Expand All @@ -56,8 +56,8 @@ protected override void OnInitialized()
oby = orv;
_contentGeometry = _junctionShape switch
{
JunctionShape.Circle => new EllipseGeometry(new Rect(ilx, ity, Width, Height)),
JunctionShape.Square => new RectangleGeometry(new Rect(ilx, ity, Width, Height)),
JunctionShape.Circle => new EllipseGeometry(new Rect(ilx, ity, ElementWidth, ElementHeight)),
JunctionShape.Square => new RectangleGeometry(new Rect(ilx, ity, ElementWidth, ElementHeight)),
JunctionShape.Diamond => new PolylineGeometry([
new Point(0.0d, oty),
new Point(orx, 0.0d),
Expand All @@ -83,15 +83,28 @@ protected override void OnInitialized()

public override void Render(DrawingContext context)
{
if (_contentGeometry.Bounds.Height >= 2.0d)
if (ElementHeight >= 2.0d)
{
context.DrawGeometry(NetlistTheme.EdgeBrush, null, _contentGeometry);
}
}

protected override void RegenerateDrawnElements()
protected override void UpdateScale(double newScale)
{
_contentGeometry.Transform = new ScaleTransform(Scale, Scale);
base.UpdateScale(newScale);

cullingOriginX = X;
cullingOriginY = Y;
}

protected override void RegenerateDrawnElements(double newScale)
{
if (!this.IsVisible)
{
return;
}

_contentGeometry.Transform = new ScaleTransform(newScale, newScale);
}

#endregion
Expand Down
23 changes: 21 additions & 2 deletions src/FEntwumS.Common/Controls/GraphLabelControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Avalonia;
using Avalonia.Data;
using Avalonia.Media;
using Avalonia.VisualTree;

namespace FEntwumS.Common.Controls;

Expand Down Expand Up @@ -53,19 +54,37 @@ public double Fontsize

public override void Render(DrawingContext context)
{
if (!this.GetVisualParent().IsVisible || !this.IsVisible)
{
return;
}

if (Scale >= 0.2d)
{
context.DrawText(_formattedContent, new Point(0, 0));
}
}

protected override void RegenerateDrawnElements()
protected override void UpdateScale(double newScale)
{
base.UpdateScale(newScale);

cullingOriginX = X;
cullingOriginY = Y;
}

protected override void RegenerateDrawnElements(double newScale)
{
if (!this.GetVisualParent().IsVisible || !this.IsVisible)
{
return;
}

_formattedContent = new FormattedText(Content ?? "",
CultureInfo.InvariantCulture,
FlowDirection.LeftToRight,
NetlistTheme.Typeface,
Fontsize * Scale,
Fontsize * newScale,
NetlistTheme.TextBrush);
}

Expand Down
Loading