more work on gtk & code cleanup

This commit is contained in:
2025-06-16 15:30:56 +02:00
parent 6f7bb5d92c
commit a49a3b2beb
69 changed files with 374 additions and 268 deletions

View File

@@ -1,5 +1,4 @@
using Pilz.UI.WinForms;
using Pilz.UI.WinForms.Dialogs;
using Pilz.UI.WinForms.Dialogs;
namespace Pilz.UI.Dialogs;

View File

@@ -1,6 +1,5 @@
using Pilz.UI.Dialogs;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
namespace Pilz.UI.WinForms.Dialogs;
@@ -150,7 +149,7 @@ public partial class FlyoutBase : UserControl
tableLayoutPanel_ActionPanel.RowStyles.Add(new RowStyle());
tableLayoutPanel_ActionPanel.Controls.Add(button_Cancel, 2, 0);
tableLayoutPanel_ActionPanel.Controls.Add(button_Accept, 1, 0);
// FlyoutBase
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;

View File

@@ -1,5 +1,4 @@
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Drawing2D;
namespace Pilz.UI.WinForms;
@@ -61,9 +60,11 @@ public class DisplayHelp
else
{
using var brush = CreateLinearGradientBrush(r, color1, color2, gradientAngle);
var blend = new Blend(factors.Length);
blend.Factors = factors;
blend.Positions = positions;
var blend = new Blend(factors.Length)
{
Factors = factors,
Positions = positions
};
brush.Blend = blend;
g.FillRectangle(brush, r);
}

View File

@@ -1,5 +1,4 @@
using Pilz.UI.WinForms.Dialogs;
using System.Diagnostics.CodeAnalysis;
namespace Pilz.UI.WinForms.Extensions;

View File

@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Windows.Forms;
namespace Pilz.UI.WinForms;

View File

@@ -1,16 +1,11 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Pilz.UI.WinForms;
namespace Pilz.UI.WinForms;
internal class HighlightPanel : Control
{
private Dictionary<Control, eHighlightColor> _Highlights = null;
private List<HighlightRegion> _HighlightRegions = new List<HighlightRegion>();
private List<HighlightRegion> _HighlightRegions = [];
public HighlightPanel(Dictionary<Control, eHighlightColor> highlights)
{

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.ComponentModel;
// Nicht gemergte Änderung aus Projekt "Pilz.UI (net8.0-windows)"
// Vor:
// Imports System.Windows.Forms
@@ -9,7 +6,6 @@ using System.Drawing;
// Nach:
// Imports System.Drawing
// Imports System.Windows.Forms
using System.Windows.Forms;
namespace Pilz.UI.WinForms;
@@ -17,8 +13,8 @@ namespace Pilz.UI.WinForms;
public class Highlighter : Component
{
private Dictionary<Control, eHighlightColor> _Highlights = new Dictionary<Control, eHighlightColor>();
private Dictionary<Control, bool> _HighlightOnFocus = new Dictionary<Control, bool>();
private Dictionary<Control, eHighlightColor> _Highlights = [];
private Dictionary<Control, bool> _HighlightOnFocus = [];
protected override void Dispose(bool disposing)
{
@@ -143,8 +139,8 @@ public class Highlighter : Component
}
}
private Dictionary<TabControl, int> _TabControl2 = new Dictionary<TabControl, int>();
private Dictionary<Panel, int> _ParentPanel = new Dictionary<Panel, int>();
private Dictionary<TabControl, int> _TabControl2 = [];
private Dictionary<Panel, int> _ParentPanel = [];
private void AddHighlight(Dictionary<Control, eHighlightColor> highlights, Control c, eHighlightColor highlightColor)
{
@@ -386,15 +382,14 @@ public class Highlighter : Component
if (_ContainerControl is not null)
{
if (_HighlightPanel is null)
_HighlightPanel ??= new HighlightPanel(_Highlights)
{
_HighlightPanel = new HighlightPanel(_Highlights);
_HighlightPanel.FocusHighlightColor = _FocusHighlightColor;
_HighlightPanel.Margin = new Padding(0);
_HighlightPanel.Padding = new Padding(0);
_HighlightPanel.CustomHighlightColors = _CustomHighlightColors;
_HighlightPanel.Visible = false;
}
FocusHighlightColor = _FocusHighlightColor,
Margin = new Padding(0),
Padding = new Padding(0),
CustomHighlightColors = _CustomHighlightColors,
Visible = false
};
_ContainerControl.SizeChanged += ContainerControlSizeChanged;
_ContainerControl.HandleCreated += ContainerControlHandleCreated;
@@ -452,8 +447,10 @@ public class Highlighter : Component
if (_DelayTimer is null)
{
_DelayTimer = new();
_DelayTimer.Interval = 100;
_DelayTimer = new()
{
Interval = 100
};
_DelayTimer.Tick += new EventHandler(DelayTimerTick);
_DelayTimer.Start();
}

View File

@@ -1,6 +0,0 @@
namespace Pilz.UI.WinForms;
public interface ILoadContent
{
void LoadContent();
}

View File

@@ -1,6 +0,0 @@
namespace Pilz.UI.WinForms;
public interface ILoadContentAsync
{
Task LoadContentAsync();
}

View File

@@ -1,5 +1,4 @@
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Drawing2D;
namespace Pilz.UI.WinForms.PaintingControl;

View File

@@ -1,9 +1,5 @@
using Pilz.Drawing;
using Pilz.UI.WinForms.PaintingControl.EventArgs;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Pilz.UI.WinForms.PaintingControl;
@@ -35,7 +31,7 @@ public class DefaultDrawMethodes
e.Graphics.DrawString(obj.Text, new Font(obj.TextFont.FontFamily, obj.TextFont.Size * zoomFactor, obj.TextFont.Style), b, rect, f);
}
private static object _DrawPicture_newSyncObj = new object();
private static object _DrawPicture_newSyncObj = new();
public static void DrawPicture(PaintingObjectPaintEventArgs e)
{
@@ -276,9 +272,11 @@ public class DefaultDrawMethodes
public static void DrawAreaSelection(PaintEventArgs e, PaintingControl pc, PointF startMousePos, PointF lastMousePos)
{
var rectToDraw = HelpfulDrawingFunctions.GetRectangle(startMousePos, lastMousePos);
var p = new Pen(pc.AreaSelectionColor);
p.DashStyle = startMousePos.X >= lastMousePos.X ? DashStyle.DashDot : DashStyle.Solid;
p.Width = 3f;
var p = new Pen(pc.AreaSelectionColor)
{
DashStyle = startMousePos.X >= lastMousePos.X ? DashStyle.DashDot : DashStyle.Solid,
Width = 3f
};
e.Graphics.DrawRectangle(p, rectToDraw.X, rectToDraw.Y, rectToDraw.Width, rectToDraw.Height);
}

View File

@@ -1,6 +1,4 @@
using System;
namespace Pilz.UI.WinForms.PaintingControl.EventArgs;
namespace Pilz.UI.WinForms.PaintingControl;
public class PaintingObjectEventArgs(PaintingObject[] paintingObjects) : EventArgs
{

View File

@@ -1,7 +1,4 @@
using System;
using System.Drawing;
namespace Pilz.UI.WinForms.PaintingControl.EventArgs;
namespace Pilz.UI.WinForms.PaintingControl;
public class PaintingObjectPaintEventArgs(PaintingObject obj, Graphics g, PointF offset) : EventArgs
{
@@ -45,7 +42,7 @@ public class PaintingObjectPaintEventArgs(PaintingObject obj, Graphics g, PointF
/// The rectangle of the PaintingObject on Screen.
/// </summary>
/// <returns></returns>
public RectangleF Rectangle => new RectangleF(X, Y, PaintingObject.Width, PaintingObject.Height);
public RectangleF Rectangle => new(X, Y, PaintingObject.Width, PaintingObject.Height);
public PaintingObjectPaintEventArgs(PaintingObject obj, Graphics g) : this(obj, g, obj.Parent.Offset)
{

View File

@@ -1,15 +1,9 @@
using Pilz.Drawing;
using Pilz.UI.WinForms.PaintingControl.EventArgs;
using Pilz.UI.WinForms.Utilities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Windows.Forms;
namespace Pilz.UI.WinForms.PaintingControl;
@@ -48,7 +42,7 @@ public class PaintingControl : UserControl, IPaintingObjectContainer
public Color GridColor { get; set; } = Color.LightGray;
public DelegateDrawPaintingControlGridMethode DrawGridMethode { get; set; } = DefaultDrawMethodes.DrawGrid;
public DelegateDrawPaintingControlAreaSelectionMethode DrawAreaSelectionMethode { get; set; } = DefaultDrawMethodes.DrawAreaSelection;
private SizeF _ZoomFactor = new SizeF(1f, 1f);
private SizeF _ZoomFactor = new(1f, 1f);
private int _stopDrawing = -1;
private Image bufferedImg = null;
@@ -57,7 +51,7 @@ public class PaintingControl : UserControl, IPaintingObjectContainer
private bool pressedControl = false;
private bool pressedAlt = false;
private Dictionary<PaintingObject, PointF> savedPos = new Dictionary<PaintingObject, PointF>();
private Dictionary<PaintingObject, PointF> savedPos = [];
public event SelectionChangedEventHandler SelectionChanged;
@@ -413,8 +407,7 @@ public class PaintingControl : UserControl, IPaintingObjectContainer
{
if (IsResizingObjs(objs))
return;
if (movedObjs is null)
movedObjs = new List<PaintingObject>();
movedObjs ??= [];
SuspendDrawing();
@@ -663,7 +656,8 @@ public class PaintingControl : UserControl, IPaintingObjectContainer
{
obj2.X -= modLeft;
}
};
}
;
zoomLocation(obj);
@@ -674,7 +668,8 @@ public class PaintingControl : UserControl, IPaintingObjectContainer
var modW = (int)Math.Round(obj.Width % zoomedGridChunkSize.Width);
void zoomSize(PaintingObject obj2) { if (obj2.EnableResize && !obj2.HardcodedSize) { if (modH > halfHeight) obj2.Height += zoomedGridChunkSize.Height - modH; else { obj2.Height -= modH; } if (modW > halfWidth) obj2.Width += zoomedGridChunkSize.Width - modW; else { obj2.Width -= modW; } } };
void zoomSize(PaintingObject obj2) { if (obj2.EnableResize && !obj2.HardcodedSize) { if (modH > halfHeight) obj2.Height += zoomedGridChunkSize.Height - modH; else { obj2.Height -= modH; } if (modW > halfWidth) obj2.Width += zoomedGridChunkSize.Width - modW; else { obj2.Width -= modW; } } }
;
zoomSize(obj);

View File

@@ -1,8 +1,4 @@
using Pilz.UI.WinForms.PaintingControl.EventArgs;
using System.Drawing;
using System.Windows.Forms;
namespace Pilz.UI.WinForms.PaintingControl;
namespace Pilz.UI.WinForms.PaintingControl;
public delegate void DelegateDrawPaintingObjectMethode(PaintingObjectPaintEventArgs e);

View File

@@ -1,12 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace Pilz.UI.WinForms.PaintingControl;
@@ -33,9 +28,9 @@ public class PaintingObject : ICloneable, IPaintingObjectContainer
public Font TextFont { get; set; } = new Font(FontFamily.GenericSansSerif, 8.25f);
public Color TextColor { get; set; } = Color.Black;
[JsonProperty]
private PointF _Location = new PointF(50f, 50f);
private PointF _Location = new(50f, 50f);
[JsonProperty]
private SizeF _Size = new SizeF(50f, 80f);
private SizeF _Size = new(50f, 80f);
public bool EnableFill { get; set; } = true;
public bool EnableOutline { get; set; } = true;
public Color SelectionColor { get; set; } = Color.CornflowerBlue;
@@ -50,9 +45,9 @@ public class PaintingObject : ICloneable, IPaintingObjectContainer
[JsonIgnore]
public object Tag { get; set; } = null;
public string Name { get; set; } = "";
public List<PaintingObject> PinnedObjects { get; private set; } = new List<PaintingObject>();
public List<PaintingObject> PinnedObjects { get; private set; } = [];
[JsonIgnore]
public List<DelegateDrawPaintingObjectMethode> DrawMethodes { get; private set; } = new List<DelegateDrawPaintingObjectMethode>();
public List<DelegateDrawPaintingObjectMethode> DrawMethodes { get; private set; } = [];
[JsonIgnore]
public DelegateDrawPaintingObjectMethode DrawSelectionMethode { get; private set; } = DefaultDrawMethodes.DrawSelection;
public Cursor Cursor { get; set; } = Cursors.Default;
@@ -165,32 +160,32 @@ public class PaintingObject : ICloneable, IPaintingObjectContainer
{
case "DrawPicture":
{
tt = tt | PaintingObjectType.Picture;
tt |= PaintingObjectType.Picture;
break;
}
case "DrawText":
{
tt = tt | PaintingObjectType.Text;
tt |= PaintingObjectType.Text;
break;
}
case "DrawRectangle":
{
tt = tt | PaintingObjectType.Rectangle;
tt |= PaintingObjectType.Rectangle;
break;
}
case "DrawEllipse":
{
tt = tt | PaintingObjectType.Elipse;
tt |= PaintingObjectType.Elipse;
break;
}
case "DrawTriangle":
{
tt = tt | PaintingObjectType.Triangle;
tt |= PaintingObjectType.Triangle;
break;
}
case "DrawLine":
{
tt = tt | PaintingObjectType.Line;
tt |= PaintingObjectType.Line;
break;
}
}
@@ -699,7 +694,8 @@ public class PaintingObject : ICloneable, IPaintingObjectContainer
if (!blackFields.Contains(@field.Name))
@field.SetValue(dest, @field.GetValue(source));
}
};
}
;
copyFields(this, obj, blackField, metype);
copyFields(ImageProperties, obj.ImageProperties, Array.Empty<string>(), ImageProperties.GetType());

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Data;
namespace Pilz.UI.WinForms.PaintingControl;
@@ -10,7 +7,7 @@ public class PaintingObjectListLayering
public PaintingObjectList ObjectList { get; private set; }
public Dictionary<int, Func<PaintingObject, bool>> Conditions { get; private set; } = new Dictionary<int, Func<PaintingObject, bool>>();
public Dictionary<int, Func<PaintingObject, bool>> Conditions { get; private set; } = [];
/// <summary>
/// Get the order function will checkout the conditions.

View File

@@ -1,8 +1,5 @@
using Pilz.Drawing;
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace Pilz.UI.WinForms.PaintingControl;
@@ -95,7 +92,7 @@ internal class PaintingObjectResizing
private EdgeEnum mEdge = EdgeEnum.None;
private int mWidth = 4;
private int qWidth = 4 * 4;
private Rectangle rect = new Rectangle();
private Rectangle rect = new();
public bool Enabled { get; set; } = true;
public SizeF MinimumSize { get; set; } = new SizeF(15f, 15f);
@@ -239,11 +236,13 @@ internal class PaintingObjectResizing
RectangleF extRect = mObj.RectangleExtended;
var oldRect = mObj.Rectangle;
var newRect = new RectangleF();
newRect.X = extRect.X - oldRect.X;
newRect.Y = extRect.Y - oldRect.Y;
newRect.Width = (extRect.Width - oldRect.Width) / 2f;
newRect.Height = (extRect.Height - oldRect.Height) / 2f;
var newRect = new RectangleF
{
X = extRect.X - oldRect.X,
Y = extRect.Y - oldRect.Y,
Width = (extRect.Width - oldRect.Width) / 2f,
Height = (extRect.Height - oldRect.Height) / 2f
};
var setToNone = false;
var isOnTop = ReferenceEquals(mObj.Parent.GetObject(new PointF(realX, realY), true), mObj);

View File

@@ -1,5 +1,4 @@
using Pilz.UI.Symbols;
using System.Reflection;
namespace Pilz.UI.WinForms.Symbols;

View File

@@ -1,14 +1,11 @@
using System.Collections.Generic;
using System.Windows.Forms;
namespace Pilz.UI.WinForms.Utilities;
namespace Pilz.UI.WinForms.Utilities;
public static class DrawingControl
{
private const int WM_SETREDRAW = 11;
private readonly static Dictionary<nint, int> dicSuspendCount = new Dictionary<nint, int>();
private readonly static Dictionary<nint, int> dicSuspendCount = [];
public static void SuspendDrawing(this Control control)
{