Skip to content

Commit

Permalink
upgraded to 8
Browse files Browse the repository at this point in the history
  • Loading branch information
SDClowen committed Dec 27, 2024
1 parent a34f463 commit 7153922
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Examples/SDUI.Demo/SDUI.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
2 changes: 1 addition & 1 deletion Examples/SDUI.Examples.Mac/SDUI.Examples.Mac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
2 changes: 1 addition & 1 deletion Examples/SDUI.Test/SDUI.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>disable</ImplicitUsings>
Expand Down
137 changes: 137 additions & 0 deletions SDUI/Controls/FlowLayoutPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using SDUI.Helpers;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace SDUI.Controls;

public class FlowLayoutPanel : System.Windows.Forms.FlowLayoutPanel
{
private int _radius = 10;
public int Radius
{
get => _radius;
set
{
_radius = value;

Invalidate();
}
}

private Padding _border;
public Padding Border
{
get => _border;
set
{
if (_border == value)
return;

_border = value;
Invalidate();
}
}

private Color _borderColor = Color.Transparent;
public Color BorderColor
{
get => _borderColor;
set
{
if (_borderColor == value)
return;

_borderColor = value;
Invalidate();
}
}

private float _shadowDepth = 4;
public float ShadowDepth
{
get => _shadowDepth;
set
{
if (_shadowDepth == value)
return;

_shadowDepth = value;
Invalidate();
}
}

public FlowLayoutPanel()
{
SetStyle(ControlStyles.SupportsTransparentBackColor |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint, true);

BackColor = Color.Transparent;
DoubleBuffered = true;
}

protected override void OnParentBackColorChanged(EventArgs e)
{
base.OnParentBackColorChanged(e);
Invalidate();
}

protected override void OnPaint(PaintEventArgs e)
{
var graphics = e.Graphics;
graphics.SmoothingMode = SmoothingMode.AntiAlias;

GroupBoxRenderer.DrawParentBackground(graphics, ClientRectangle, this);
if (ColorScheme.DrawDebugBorders)
{
using var redPen = new Pen(Color.Red, 1);
redPen.Alignment = PenAlignment.Inset;
e.Graphics.DrawRectangle(redPen, new Rectangle(0, 0, Width - 1, Height - 1));
}

var rect = ClientRectangle.ToRectangleF();

var color = BackColor == Color.Transparent ? ColorScheme.BackColor2 : BackColor;
var borderColor = _borderColor == Color.Transparent ? ColorScheme.BorderColor : _borderColor;

var inflate = _shadowDepth / 4f;
//rect.Inflate(-inflate, -inflate);

if (_radius > 0)
{
using var path = rect.Radius(_radius);
/*var shadow = DropShadow.Create(path, Color.Black.Alpha(20), _shadowDepth);
var shadowBounds = DropShadow.GetBounds(shadowRect, _shadowDepth);
//shadowBounds.Offset(0, 0);
e.Graphics.DrawImageUnscaled(shadow, shadowBounds.Location);
*/

using (var brush = new SolidBrush(color))
e.Graphics.FillPath(brush, path);

//e.Graphics.DrawShadow(rect, _shadowDepth, _radius);
ShadowUtils.DrawShadow(graphics, ColorScheme.ShadowColor, rect.ToRectangle(), (int)(_shadowDepth + 1) + 40, DockStyle.Right);
using var pen = new Pen(borderColor, _border.All);
e.Graphics.DrawPath(pen, path);

return;
}

using (var brush = new SolidBrush(color))
e.Graphics.FillRectangle(brush, rect);

e.Graphics.DrawShadow(rect, _shadowDepth, _radius == 0 ? 1 : _radius);

ControlPaint.DrawBorder(e.Graphics, ClientRectangle,
borderColor, _border.Left, ButtonBorderStyle.Solid,
borderColor, _border.Top, ButtonBorderStyle.Solid,
borderColor, _border.Right, ButtonBorderStyle.Solid,
borderColor, _border.Bottom, ButtonBorderStyle.Solid);
}
}
44 changes: 6 additions & 38 deletions SDUI/Controls/UIWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ protected override void OnPaint(PaintEventArgs e)
if (_inMaxBox)
graphics.FillRectangle(Color.FromArgb((int)(maxBoxHoverAnimationManager.GetProgress() * hoverColor.A), hoverColor.RemoveAlpha()), _maximizeBoxRect);

graphics.DrawRectangle(foreColor,
graphics.DrawRectangle(foreColor,
_maximizeBoxRect.Left + _maximizeBoxRect.Width / 2 - (12 * DPI / 2),
_maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 - (11 * DPI / 2),
12 * DPI, 11 * DPI);
Expand Down Expand Up @@ -1243,7 +1243,7 @@ protected override void OnPaint(PaintEventArgs e)
var y = activePageRect.Bottom - 2;
var x = previousActivePageRect.X + (int)((activePageRect.X - previousActivePageRect.X) * animationProgress);
var width = previousActivePageRect.Width + (int)((activePageRect.Width - previousActivePageRect.Width) * animationProgress);

if (_tabDesingMode == TabDesingMode.Rectangle)
{
graphics.DrawRectangle(hoverColor, activePageRect.X, 0, width, _titleHeightDPI);
Expand All @@ -1269,44 +1269,12 @@ protected override void OnPaint(PaintEventArgs e)
hoverColor = ForeColor.Alpha(60);

using var hoverBrush = hoverColor.Brush();
var tabRect = new RectangleF(x, 5, width, _titleHeightDPI);
var tabRect = new RectangleF(x, 5, width, _titleHeightDPI - 7);

var radius = 9 * DPI;
graphics.FillPath(hoverBrush, tabRect.Radius(radius, radius, 0, 0));
var radius = 12;
graphics.FillPath(hoverBrush, tabRect.ChromePath(radius));
//tabRect.Inflate(0, -4 * DPI);
//graphics.DrawShadow(tabRect, 5, (int)radius, hoverColor.Determine().Alpha(155));

for (int i = 0; i < 2; i++)
{
// GraphicsPath oluşturuyoruz
GraphicsPath path = new();
path.StartFigure();

path.AddBezier(0, 25, 20, 32, 32, 0, 32, 0); // İlk eğriyi çiz

path.AddLine(32, 0, 32, 32);
path.AddLine(32, 32, 0, 32);
path.CloseFigure();


RectangleF bounds = path.GetBounds();
float offsetX = tabRect.X / 2 - bounds.X / 2;
float offsetY = tabRect.Y / 2 - bounds.Y / 2;

if (i == 0)
graphics.TranslateTransform(tabRect.X - bounds.Width, tabRect.Y + bounds.Height - 15);
else
{
Matrix transform = new();
transform.Scale(-1, 1);

path.Transform(transform);
graphics.TranslateTransform(tabRect.Width + tabRect.X + bounds.Width, tabRect.Y + bounds.Height - 15);
}

graphics.FillPath(hoverBrush, path);
graphics.ResetTransform();
}
//graphics.DrawShadow(tabRect, 5, radius, hoverColor.Determine().Alpha(155));
}

//Draw tab headers
Expand Down
38 changes: 21 additions & 17 deletions SDUI/Controls/UIWindowBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ private bool _aeroEnabled

public UIWindowBase()
{
//BackColor = Color.FromArgb(0, 0, 0, 0);
SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.OptimizedDoubleBuffer, true);
BackColor = Color.FromArgb(0, 0, 0, 0);
ResizeRedraw = true;
}

Expand Down Expand Up @@ -93,8 +94,8 @@ protected override CreateParams CreateParams
cp.ClassStyle |= CS_DBLCLKS;

var style = (uint)cp.Style;
if(DesignMode)

if (DesignMode)
style &= ~(uint)SetWindowLongFlags.WS_CAPTION;

style &= ~(uint)SetWindowLongFlags.WS_SYSMENU;
Expand Down Expand Up @@ -149,7 +150,7 @@ protected override void WndProc(ref Message m)
if (WindowState != FormWindowState.Maximized)
{
int gripDist = 10;

var pt = PointToClient(Cursor.Position);

Size clientSize = ClientSize;
Expand Down Expand Up @@ -325,10 +326,10 @@ protected override void OnHandleCreated(EventArgs e)
DwmSetWindowAttribute(Handle, DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_POLICY, ref v, 4);
var margins = new MARGINS()
{
Bottom = 1,
Left = 1,
Right = 1,
Top = 1
Bottom = dwmMargin,
Left = dwmMargin,
Right = dwmMargin,
Top = dwmMargin
};

DwmExtendFrameIntoClientArea(this.Handle, ref margins);
Expand All @@ -347,15 +348,18 @@ protected override void OnBackColorChanged(EventArgs e)

if (!WindowsHelper.IsModern)
return;

WindowsHelper.UseImmersiveDarkMode(Handle, ColorScheme.BackColor.IsDark());
/*
var flag = DWMSBT_TRANSIENTWINDOW;
DwmSetWindowAttribute(
Handle,
DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE,
ref flag,
Marshal.SizeOf<int>());
*/

if (ColorScheme.BackColor.IsDark())
{
var flag = DWMSBT_TABBEDWINDOW;
DwmSetWindowAttribute(
Handle,
DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE,
ref flag,
Marshal.SizeOf<int>());
}

}
}
33 changes: 33 additions & 0 deletions SDUI/Extensions/DrawingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,39 @@ public static bool InRegion(this PointF point, PointF[] points)
}
}

public static GraphicsPath ChromePath(this RectangleF bounds, float radius)
{
var diameter = radius * 2;
var x = bounds.Location.X;
var y = bounds.Location.Y;
var path = new GraphicsPath();

if (radius == 0)
{
path.AddRectangle(bounds);
return path;
}

// Top left arc
path.AddArc(x, y, diameter, diameter, 180, 90);

// Top right arc
x = bounds.Right - diameter;
path.AddArc(x, y, diameter, diameter, 270, 90);

y = bounds.Bottom - diameter;

// bottom right
path.AddArc(x + diameter, y, diameter, diameter, 180, -90); // Sağ alt dışa doğru eğri

// Bottom left arc
x = bounds.Left - diameter;
path.AddArc(x, y, diameter, diameter, 90, -90);

path.CloseFigure();
return path;
}

public static GraphicsPath Path(this Point[] points)
{
var path = new GraphicsPath();
Expand Down
5 changes: 1 addition & 4 deletions SDUI/SDUI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>disable</ImplicitUsings>
Expand All @@ -13,9 +13,6 @@
</ItemGroup>

<ItemGroup>
<Compile Update="Controls\NTextBox.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Update="Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand Down

0 comments on commit 7153922

Please sign in to comment.