2022-12-12 22:33:17 +08:00
|
|
|
|
using System.Globalization;
|
2021-07-29 13:55:18 +08:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Media;
|
2022-10-28 22:45:39 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner;
|
2023-01-25 11:11:27 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Models;
|
2022-12-12 22:33:17 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Services;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-25 15:58:05 +08:00
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Extensions.ViewModels
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
public class OutLineTextDesignerItemViewModel : TextDesignerItemViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
private IUIVisualizerService visualiserService;
|
2023-01-27 14:54:03 +08:00
|
|
|
|
public OutLineTextDesignerItemViewModel() : this(null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public OutLineTextDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
2022-12-08 20:54:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 17:53:04 +08:00
|
|
|
|
public OutLineTextDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
public OutLineTextDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
public override SelectableItemBase GetSerializableObject()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new TextDesignerItem(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-18 16:40:33 +08:00
|
|
|
|
public override void Init(IDiagramViewModel root, bool initNew)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2023-03-25 11:59:31 +08:00
|
|
|
|
base.Init(root, initNew);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2024-02-18 16:40:33 +08:00
|
|
|
|
if (visualiserService == null)
|
|
|
|
|
|
visualiserService = ApplicationServicesProvider.Instance.Provider.VisualizerService;
|
2023-03-25 11:59:31 +08:00
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-03-25 11:59:31 +08:00
|
|
|
|
protected override void InitNew()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.InitNew();
|
2021-07-23 09:42:22 +08:00
|
|
|
|
FontViewModel.FontFamily = "Arial";
|
|
|
|
|
|
FontViewModel.FontSize = 36;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AutoSize()
|
|
|
|
|
|
{
|
|
|
|
|
|
var size = MeasureString();
|
|
|
|
|
|
ItemWidth = size.Width;
|
|
|
|
|
|
ItemHeight = size.Height;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Size MeasureString()
|
|
|
|
|
|
{
|
|
|
|
|
|
var formattedText = new FormattedText(
|
|
|
|
|
|
Text,
|
|
|
|
|
|
CultureInfo.CurrentUICulture,
|
|
|
|
|
|
FlowDirection.LeftToRight,
|
|
|
|
|
|
new Typeface(new FontFamily(FontViewModel.FontFamily), FontViewModel.FontStyle, FontViewModel.FontWeight, FontViewModel.FontStretch),
|
|
|
|
|
|
FontViewModel.FontSize,
|
|
|
|
|
|
Brushes.Black);
|
|
|
|
|
|
|
|
|
|
|
|
return new Size(formattedText.Width, formattedText.Height);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void ExecuteEditCommand(object parameter)
|
|
|
|
|
|
{
|
|
|
|
|
|
EditData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-03 18:35:01 +08:00
|
|
|
|
public override bool Verify()
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(Text))
|
|
|
|
|
|
return EditData();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override bool EditData()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsReadOnly == true) return false;
|
|
|
|
|
|
|
|
|
|
|
|
OutLineTextDesignerItemData data = new OutLineTextDesignerItemData(this);
|
|
|
|
|
|
if (visualiserService.ShowDialog(data) == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = data.Text;
|
2023-04-09 12:38:57 +08:00
|
|
|
|
FontViewModel = CopyHelper.Mapper(data.FontViewModel);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
AutoSize();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|