Обновление формы просмотра

This commit is contained in:
2025-05-05 23:46:58 +04:00
parent fc5d68ca1f
commit c1b70a12eb
9 changed files with 67 additions and 549 deletions
@@ -47,6 +47,20 @@ public sealed partial class EntityTreeViewerControl : UserControl
}
private int _depthSize = 20;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Category("Entity Render")]
[Description("The size of tab.")]
public float TypeFontSize
{
get => _typeFontSize;
set
{
_typeFontSize = value;
UpdateView();
}
}
private float _typeFontSize = 9.5f;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Category("Entity Render")]
[Description("The size of plus/minus button.")]
@@ -26,6 +26,20 @@ internal class EntityTreeViewerControlRow
}
private Image? _cache;
public Image HoveredCache
{
get
{
if (_hoveredCache == null)
{
UpdateCache();
}
return _hoveredCache!;
}
set => _hoveredCache = value;
}
private Image? _hoveredCache;
public List<LadderType> Ladder
{
get => _ladder;
@@ -92,6 +106,11 @@ internal class EntityTreeViewerControlRow
get => ParentControl.ButtonSize;
set => ParentControl.ButtonSize = value;
}
public float TypeFontSize
{
get => ParentControl.TypeFontSize;
set => ParentControl.TypeFontSize = value;
}
// ValueText functions
@@ -120,7 +139,9 @@ internal class EntityTreeViewerControlRow
return result;
}
}
public Font TypeFont => new(Font.FontFamily, Font.Size * 0.6f, FontStyle.Italic);
// public Font TypeFont => new(Font.FontFamily, TypeFontSize, FontStyle.Italic);
public Font TypeFont => new(Font.FontFamily, TypeFontSize);
public string ValueText => Item.GetValueString();
public Font ValueFont =>
@@ -181,21 +202,29 @@ internal class EntityTreeViewerControlRow
public void UpdateCache()
{
Cache = new Bitmap(Width, Height);
Graphics g = Graphics.FromImage(Cache);
Cache = RenderCache(BackColor);
HoveredCache = RenderCache(HoverColor);
}
private Image RenderCache(Color backColor)
{
Image cache = new Bitmap(Width, Height);
Graphics g = Graphics.FromImage(cache);
g.FillRectangle(new SolidBrush(backColor), 0, 0, Width, Height);
RenderLadder(g);
RenderContent(g);
g.Save();
return cache;
}
public void Invalidate(Graphics? g = null)
{
g ??= Graphics.FromImage(ParentControl.ContentImage);
g.FillRectangle(new SolidBrush(Hovered ? HoverColor : BackColor), Target);
g.DrawImage(Cache, Target);
g.DrawImage(Hovered ? HoveredCache : Cache, Target);
UpdateButton();
}
@@ -329,6 +358,7 @@ internal class EntityTreeViewerControlRow
_ => ForeColor,
},
StructureFieldEnum => BlendColor(Color.Red),
StructureFieldNull => BlendColor(BackColor),
_ => ForeColor,
};
}
@@ -1,130 +0,0 @@
namespace Pf2eViewer.EntityTreeViewer;
sealed partial class EntityTreeViewerRow
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
NameLabel = new Label();
IconPictureBox = new PictureBox();
NamePanel = new Panel();
ValuePanel = new Panel();
TypeLabel = new Label();
ValueLabel = new Label();
((System.ComponentModel.ISupportInitialize) IconPictureBox).BeginInit();
NamePanel.SuspendLayout();
ValuePanel.SuspendLayout();
SuspendLayout();
//
// NameLabel
//
NameLabel.Dock = DockStyle.Fill;
NameLabel.Location = new Point(0, 0);
NameLabel.Margin = new Padding(0);
NameLabel.Name = "NameLabel";
NameLabel.Size = new Size(200, 38);
NameLabel.TabIndex = 0;
NameLabel.Text = "Name";
NameLabel.TextAlign = ContentAlignment.MiddleLeft;
//
// IconPictureBox
//
IconPictureBox.Dock = DockStyle.Left;
IconPictureBox.Location = new Point(0, 0);
IconPictureBox.Margin = new Padding(0);
IconPictureBox.Name = "IconPictureBox";
IconPictureBox.Size = new Size(20, 38);
IconPictureBox.TabIndex = 1;
IconPictureBox.TabStop = false;
IconPictureBox.Click += IconPictureBox_Click;
//
// NamePanel
//
NamePanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
NamePanel.Controls.Add(NameLabel);
NamePanel.Controls.Add(IconPictureBox);
NamePanel.Location = new Point(0, 0);
NamePanel.Name = "NamePanel";
NamePanel.Size = new Size(200, 38);
NamePanel.TabIndex = 2;
//
// ValuePanel
//
ValuePanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
ValuePanel.BackColor = SystemColors.Control;
ValuePanel.Controls.Add(ValueLabel);
ValuePanel.Controls.Add(TypeLabel);
ValuePanel.Location = new Point(200, 0);
ValuePanel.Margin = new Padding(0);
ValuePanel.Name = "ValuePanel";
ValuePanel.Size = new Size(288, 38);
ValuePanel.TabIndex = 4;
//
// TypeLabel
//
TypeLabel.Dock = DockStyle.Left;
TypeLabel.Location = new Point(0, 0);
TypeLabel.Margin = new Padding(0);
TypeLabel.Name = "TypeLabel";
TypeLabel.Size = new Size(57, 38);
TypeLabel.TabIndex = 3;
TypeLabel.Text = "TypeText";
TypeLabel.TextAlign = ContentAlignment.MiddleLeft;
//
// ValueLabel
//
ValueLabel.AutoEllipsis = true;
ValueLabel.Dock = DockStyle.Fill;
ValueLabel.Location = new Point(0, 0);
ValueLabel.Name = "ValueLabel";
ValueLabel.Size = new Size(288, 38);
ValueLabel.TabIndex = 4;
ValueLabel.Text = "ValueText";
ValueLabel.TextAlign = ContentAlignment.MiddleLeft;
//
// EntityTreeViewerRow
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(NamePanel);
Controls.Add(ValuePanel);
Name = "EntityTreeViewerRow";
Size = new Size(488, 38);
((System.ComponentModel.ISupportInitialize) IconPictureBox).EndInit();
NamePanel.ResumeLayout(false);
ValuePanel.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private Label NameLabel;
private PictureBox IconPictureBox;
private Panel NamePanel;
private Panel ValuePanel;
private Label TypeLabel;
private Label ValueLabel;
}
@@ -1,273 +0,0 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Markup;
using FontAwesome.Sharp;
namespace Pf2eViewer.EntityTreeViewer;
internal sealed partial class EntityTreeViewerRow : UserControl
{
public readonly EntityTreeViewerControl ParentControl;
public readonly StructureField Item;
public int ViewIndex = 0;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Bitmap IconCache
{
get
{
if (_iconCache == null)
{
UpdateCache();
}
return _iconCache!;
}
set => _iconCache = value;
}
private Bitmap? _iconCache;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public List<LadderType> Ladder
{
get => _ladder;
set
{
_ladder = value;
_iconCache = null;
}
}
private List<LadderType> _ladder = [];
[AllowNull]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override Font Font
{
get => ParentControl.Font;
set => ParentControl.Font = value;
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override Color ForeColor
{
get => ParentControl.ForeColor;
set => ParentControl.ForeColor = value;
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override Color BackColor
{
get => ParentControl.BackColor;
set => ParentControl.BackColor = value;
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int ItemHeight
{
get => ParentControl.ItemHeight;
set => ParentControl.ItemHeight = value;
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int DepthSize
{
get => ParentControl.ItemHeight;
set => ParentControl.ItemHeight = value;
}
// ValueText functions
public bool HasButton => Item.FieldType == StructureFieldType.Complex;
public int Depth => Item.Depth;
public int NameWidth => TextRenderer.MeasureText(NameLabel.Text, Font).Width + DepthSize;
public EntityTreeViewerRow(EntityTreeViewerControl parent, StructureField item)
{
ParentControl = parent;
Item = item;
InitializeComponent();
ApplyItem();
Refresh();
}
private void ApplyItem()
{
TypeLabel.Font = new(Font.FontFamily, Font.Size - 2, FontStyle.Italic);
NameLabel.Text = Item.Name;
TypeLabel.Text = Item.GetTypeString();
if (TypeLabel.Text != "")
{
TypeLabel.Text = $@"({TypeLabel.Text})";
}
ValueLabel.Text = Item.GetValueString();
TypeLabel.ForeColor = ValueLabel.ForeColor = GetValueColor();
if (Item.FieldType == StructureFieldType.Complex)
{
ValueLabel.Font = new(Font, FontStyle.Italic);
}
UpdateCache();
Refresh();
}
public new void Refresh()
{
base.Refresh();
Left = 0;
Top = ViewIndex * ParentControl.ItemHeight;
Width = ParentControl.ContentWidth - Left - SystemInformation.VerticalScrollBarWidth;
Height = ParentControl.ItemHeight;
// Name Panel
NamePanel.Left = 0;
NamePanel.Width = ParentControl.NameWidth - NamePanel.Left;
IconPictureBox.Width = IconCache.Width;
IconPictureBox.Image = IconCache;
NameLabel.Left = IconPictureBox.Width;
NameLabel.Width = NamePanel.Width - NameLabel.Left;
// ValueText Panel
ValuePanel.Left = NamePanel.Left + NamePanel.Width;
ValuePanel.Width = Width - ValuePanel.Left;
Size typeSize = TextRenderer.MeasureText(TypeLabel.Text, TypeLabel.Font);
TypeLabel.Width = typeSize.Width + 3;
}
private Color BlendColor(Color color, double rate = 0.5)
{
return BlendColor(ForeColor, color, rate);
}
private Color BlendColor(Color color1, Color color2, double rate)
{
return Color.FromArgb(
Mix(color1.A, color2.A),
Mix(color1.R, color2.R),
Mix(color1.G, color2.G),
Mix(color1.B, color2.B)
);
int Mix(int a, int b) => Convert.ToInt32(Math.Round(a * rate + b * (1 - rate)));
}
public Color GetValueColor()
{
return Item switch
{
StructureFieldPrimitive primitive => Type.GetTypeCode(primitive.Type) switch
{
TypeCode.Boolean => BlendColor(Color.DarkGoldenrod),
TypeCode.Int32 => BlendColor(Color.Blue),
TypeCode.Double => BlendColor(Color.Aqua),
TypeCode.String => BlendColor(Color.Green),
_ => ForeColor,
},
StructureFieldEnum => BlendColor(Color.Red),
_ => ForeColor,
};
}
// Events
private void IconPictureBox_Click(object sender, EventArgs e)
{
if (Item.GetType() != typeof(StructureFieldComplex))
{
return;
}
StructureFieldComplex complex = (StructureFieldComplex)Item;
complex.Collapsed = !complex.Collapsed;
ParentControl.UpdateView();
}
private Bitmap? GetIconImage()
{
if (Item.GetType() != typeof(StructureFieldComplex))
{
return null;
}
StructureFieldComplex complex = (StructureFieldComplex)Item;
int size = Convert.ToInt32(Math.Round(DepthSize * 0.6));
return complex.Collapsed
? IconChar.PlusSquare.ToBitmap(IconFont.Auto, size, ForeColor)
: IconChar.MinusSquare.ToBitmap(IconFont.Auto, size, ForeColor);
}
private void UpdateCache()
{
int n = Depth;
int h = ItemHeight;
int w = DepthSize;
_iconCache = new(w * (n + 1), h);
if (_ladder.Count < Depth)
{
return;
}
Graphics g = Graphics.FromImage(_iconCache);
Pen pen = new(Color.FromArgb(127, ForeColor.R, ForeColor.G, ForeColor.B), 1);
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
float cy = 0.5f * h;
for (int i = 0; i < n; i++)
{
float cx = (i + 1.5f) * w;
switch (_ladder[i])
{
case LadderType.Last:
g.DrawLine(pen, cx, 0, cx, cy);
break;
case LadderType.Through:
g.DrawLine(pen, cx, 0, cx, h);
break;
case LadderType.Empty:
default:
break;
}
if (i == n - 1)
{
g.DrawLine(pen, cx, cy, (i + 2) * w, cy);
}
}
Bitmap? icon = GetIconImage();
if (icon is not null)
{
float cx = (n + 0.5f) * w;
g.FillRectangle(
new SolidBrush(BackColor),
cx - 0.5f * icon.Width - 1,
cy - 0.5f * icon.Height - 1,
icon.Width + 2,
icon.Height + 2
);
g.DrawImage(icon, new PointF(cx - 0.5f * icon.Width, cy - 0.5f * icon.Height));
}
g.Save();
}
}
@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -174,11 +174,6 @@ internal abstract class StructureField(StructureBuilder builder, string name, in
public abstract string GetValueString();
public virtual ICollection<EntityTreeViewerRow> GetTextRows(EntityTreeViewerControl control)
{
return [new(control, this)];
}
public virtual ICollection<T> GetRows<T>(Func<StructureField, T> func)
{
StructureField[] q = [this];
@@ -351,15 +346,6 @@ internal class StructureFieldComplex : StructureField
}
}
public override ICollection<EntityTreeViewerRow> GetTextRows(EntityTreeViewerControl control)
{
List<EntityTreeViewerRow> rows = base.GetTextRows(control).ToList();
rows.AddRange(Fields.SelectMany(f => f.GetTextRows(control)).ToList());
return rows;
}
public override ICollection<T> GetRows<T>(Func<StructureField, T> func)
{
return [.. base.GetRows(func), .. Fields.SelectMany(f => f.GetRows(func)).ToList()];