2023-05-14 00:31:25 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Models;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
|
|
|
|
{
|
|
|
|
|
|
public class TextDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public TextDrawingDesignerItemViewModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public TextDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.ErasableRectangle, startPoint, erasable)
|
|
|
|
|
|
{
|
|
|
|
|
|
AddTextBox();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-14 23:26:08 +08:00
|
|
|
|
public TextDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, string text, bool erasable) : base(root, DrawMode.Text, new List<Point> { startPoint }, erasable)
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = text;
|
|
|
|
|
|
InitNewDrawing();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-14 00:31:25 +08:00
|
|
|
|
public TextDrawingDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public TextDrawingDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-14 23:26:08 +08:00
|
|
|
|
protected override void Init(IDiagramViewModel root, bool initNew)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Init(root, initNew);
|
|
|
|
|
|
|
|
|
|
|
|
CustomText = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void InitNewDrawing()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsFinish)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
IsLoaded = false;
|
|
|
|
|
|
var typeface = new Typeface(new FontFamily(FontViewModel.FontFamily), FontViewModel.FontStyle, FontViewModel.FontWeight, FontViewModel.FontStretch);
|
|
|
|
|
|
var formattedText = new FormattedText(Text,
|
|
|
|
|
|
System.Globalization.CultureInfo.InvariantCulture,
|
|
|
|
|
|
FlowDirection.LeftToRight,
|
|
|
|
|
|
typeface,
|
|
|
|
|
|
FontViewModel.FontSize,
|
|
|
|
|
|
new SolidColorBrush(FontViewModel.FontColor));
|
|
|
|
|
|
|
|
|
|
|
|
Geometry = formattedText.BuildGeometry(new Point()).GetFlattenedPathGeometry();
|
2023-05-17 22:47:51 +08:00
|
|
|
|
UpdateLocation(Points[0]);
|
2023-05-14 23:26:08 +08:00
|
|
|
|
IsLoaded = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
this.SelectedDisable = Erasable;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-14 00:31:25 +08:00
|
|
|
|
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
2023-05-14 23:26:08 +08:00
|
|
|
|
{
|
2023-05-14 00:31:25 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
|
|
|
|
|
{
|
2023-05-14 23:26:08 +08:00
|
|
|
|
return base.OnMouseUp(sender, e);
|
2023-05-14 00:31:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TextDesignerItemViewModel _previewTextDesign;
|
|
|
|
|
|
public void AddTextBox()
|
|
|
|
|
|
{
|
|
|
|
|
|
_previewTextDesign = new TextAutoDesignerItemViewModel(this.Root);
|
|
|
|
|
|
_previewTextDesign.FontViewModel = CopyHelper.Mapper(this.FontViewModel);
|
|
|
|
|
|
_previewTextDesign.FontViewModel.FontColor = this.ColorViewModel.LineColor.Color;
|
|
|
|
|
|
_previewTextDesign.FontViewModel.HorizontalAlignment = HorizontalAlignment.Left;
|
|
|
|
|
|
_previewTextDesign.FontViewModel.VerticalAlignment = VerticalAlignment.Top;
|
|
|
|
|
|
_previewTextDesign.Left = Points[0].X;
|
|
|
|
|
|
_previewTextDesign.Top = Points[0].Y;
|
|
|
|
|
|
Root?.Add(_previewTextDesign, true);
|
|
|
|
|
|
_previewTextDesign.PropertyChanged += _previewTextDesign_PropertyChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void _previewTextDesign_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
|
|
|
|
{
|
2023-05-14 23:26:08 +08:00
|
|
|
|
if (e.PropertyName == nameof(IsEditing) && _previewTextDesign.IsEditing == false)
|
2023-05-14 00:31:25 +08:00
|
|
|
|
{
|
|
|
|
|
|
_previewTextDesign.PropertyChanged -= _previewTextDesign_PropertyChanged;
|
|
|
|
|
|
Root?.Remove(_previewTextDesign);
|
2023-05-14 23:26:08 +08:00
|
|
|
|
|
|
|
|
|
|
Text = _previewTextDesign?.Text;
|
2023-05-14 00:31:25 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(Text))
|
2023-05-14 23:26:08 +08:00
|
|
|
|
{
|
|
|
|
|
|
IsLoaded = false;
|
2023-05-14 00:31:25 +08:00
|
|
|
|
var typeface = new Typeface(new FontFamily(FontViewModel.FontFamily), FontViewModel.FontStyle, FontViewModel.FontWeight, FontViewModel.FontStretch);
|
2023-05-14 23:26:08 +08:00
|
|
|
|
var formattedText = new FormattedText(Text,
|
2023-05-14 00:31:25 +08:00
|
|
|
|
System.Globalization.CultureInfo.InvariantCulture,
|
|
|
|
|
|
FlowDirection.LeftToRight,
|
2023-05-14 23:26:08 +08:00
|
|
|
|
typeface,
|
|
|
|
|
|
FontViewModel.FontSize,
|
|
|
|
|
|
new SolidColorBrush(FontViewModel.FontColor));
|
2023-05-14 00:31:25 +08:00
|
|
|
|
|
|
|
|
|
|
Geometry = formattedText.BuildGeometry(new Point()).GetFlattenedPathGeometry();
|
|
|
|
|
|
IsFinish = true;
|
|
|
|
|
|
|
|
|
|
|
|
this.ItemWidth = _previewTextDesign.ItemWidth;
|
|
|
|
|
|
this.ItemHeight = _previewTextDesign.ItemHeight;
|
|
|
|
|
|
this.Left = _previewTextDesign.Left + 2 + Geometry.Bounds.Left;
|
|
|
|
|
|
this.Top = _previewTextDesign.Top + 2 + Geometry.Bounds.Top;
|
|
|
|
|
|
this.Root?.AddItemCommand.Execute(this);
|
2023-05-14 23:26:08 +08:00
|
|
|
|
IsLoaded = true;
|
|
|
|
|
|
}
|
2023-05-14 00:31:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-05-14 23:26:08 +08:00
|
|
|
|
|
2023-05-17 22:47:51 +08:00
|
|
|
|
protected override void UpdateLocation(Point point)
|
2023-05-14 23:26:08 +08:00
|
|
|
|
{
|
2023-05-14 23:26:22 +08:00
|
|
|
|
ItemWidth = Geometry.Bounds.Width + 3;
|
|
|
|
|
|
ItemHeight = Geometry.Bounds.Height + 3;
|
2023-05-17 22:47:51 +08:00
|
|
|
|
Left = point.X;
|
|
|
|
|
|
Top = point.Y;
|
2023-05-14 23:26:08 +08:00
|
|
|
|
}
|
2023-05-14 00:31:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|