Skip to content

Commit ffd7eb8

Browse files
author
itzkxhu
committed
optimise form rounder
add star rating add svg box
1 parent 6379d61 commit ffd7eb8

File tree

7 files changed

+399
-17
lines changed

7 files changed

+399
-17
lines changed

wfcl1/Components/cuiFormRounderV2.cs

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace CuoreUI.Components
1212
public partial class cuiFormRounderV2 : Component
1313
{
1414
private Form RoundedForm;
15-
private Form FakeForm = new cuiFormRounderV2Resources.FakeForm();
15+
private readonly Form FakeForm = new FakeForm();
1616

1717
private Form privateTargetForm;
1818
public Form TargetForm
@@ -26,16 +26,36 @@ public Form TargetForm
2626
privateTargetForm = value;
2727
if (privateTargetForm != null)
2828
{
29+
//TargetForm.HandleCreated += TargetForm_HandleCreated;
2930
TargetForm.Load += TargetForm_Load;
3031
TargetForm.Resize += TargetForm_Resize;
3132
TargetForm.LocationChanged += TargetForm_LocationChanged;
3233
TargetForm.TextChanged += TargetForm_TextChanged;
34+
TargetForm.FormClosing += TargetForm_FormClosing;
3335

3436
FakeForm.Activated += FakeForm_Activated;
37+
FakeForm.FormClosing += TargetForm_FormClosing;
3538
}
3639
}
3740
}
3841

42+
private void TargetForm_HandleCreated(object sender, EventArgs e)
43+
{
44+
FakeForm.ShowInTaskbar = true;
45+
FakeForm.Opacity = 0;
46+
}
47+
48+
private void TargetForm_FormClosing(object sender, FormClosingEventArgs e)
49+
{
50+
if (e.Cancel == false)
51+
{
52+
RoundedForm.Dispose();
53+
FakeForm.Dispose();
54+
TargetForm.Dispose();
55+
Environment.Exit(0);
56+
}
57+
}
58+
3959
private void FakeForm_Activated(object sender, EventArgs e)
4060
{
4161
if (TargetForm != null && RoundedForm != null)
@@ -67,10 +87,7 @@ public int Rounding
6787
set
6888
{
6989
privateRounding = value;
70-
if (RoundedForm != null)
71-
{
72-
RoundedForm.Invalidate();
73-
}
90+
RoundedForm?.Invalidate();
7491
}
7592
}
7693

@@ -83,7 +100,7 @@ private void TargetForm_LocationChanged(object sender, EventArgs e)
83100
}
84101
}
85102

86-
private Color privateOutlineColor = Color.White;
103+
private Color privateOutlineColor = Color.FromArgb(30, 0, 0, 0);
87104
public Color OutlineColor
88105
{
89106
get
@@ -93,22 +110,38 @@ public Color OutlineColor
93110
set
94111
{
95112
privateOutlineColor = value;
113+
RoundedForm?.Invalidate();
114+
}
115+
}
116+
117+
private Color privateBackColor = Color.FromArgb(10, 10, 10);
118+
public Color BackColor
119+
{
120+
get
121+
{
122+
return privateBackColor;
123+
}
124+
set
125+
{
126+
privateBackColor = value;
127+
RoundedForm?.Invalidate();
96128
}
97129
}
98130

99131
private async void TargetForm_Load(object sender, EventArgs e)
100132
{
101-
RoundedForm = new cuiFormRounderV2Resources.RoundedForm(TargetForm.BackColor, OutlineColor);
102-
RoundedForm.Activated += FakeForm_Activated;
103-
RoundedForm.Show();
133+
TargetForm.Opacity = 0;
134+
TargetForm.ShowInTaskbar = false;
135+
TargetForm.FormBorderStyle = FormBorderStyle.None;
104136

105-
FakeForm.ShowInTaskbar = true;
106-
FakeForm.Opacity = 0;
137+
RoundedForm = new RoundedForm(BackColor, OutlineColor);
138+
139+
RoundedForm.Show();
107140
FakeForm.Show();
108141

109-
TargetForm.ShowInTaskbar = false;
110-
TargetForm.FormBorderStyle = FormBorderStyle.None;
142+
TargetForm.Opacity = 1;
111143

144+
RoundedForm.Activated += FakeForm_Activated;
112145
TargetForm_LocationChanged(this, EventArgs.Empty);
113146
TargetForm_Resize(this, EventArgs.Empty);
114147

@@ -122,13 +155,14 @@ private async void TargetForm_Load(object sender, EventArgs e)
122155
TargetForm_Resize(this, EventArgs.Empty);
123156
});
124157
tempTimer.Start();
158+
125159
await Task.Delay(1000);
126160
tempTimer.Stop();
127161
tempTimer.Dispose();
128162

129163
Timer bitmapTimer = new Timer
130164
{
131-
Interval = 32
165+
Interval = 100
132166
};
133167
Bitmap tempBitmap = new Bitmap(TargetForm.Width, TargetForm.Height);
134168
bitmapTimer.Tick += ((a1, a2) =>
@@ -141,15 +175,15 @@ private async void TargetForm_Load(object sender, EventArgs e)
141175
}
142176

143177
SharedVariables.FakeBitmap = (Bitmap)tempBitmap.Clone();
144-
FakeForm.Invoke((MethodInvoker)delegate {
178+
FakeForm.Invoke((MethodInvoker)delegate
179+
{
145180
FakeForm.Refresh();
146181
});
147182

148183
// 30 mb
149184
GC.AddMemoryPressure(30000000);
150185
});
151186
bitmapTimer.Start();
152-
153187
}
154188

155189
Size addsize(Size s1, Size s2)

wfcl1/Controls/cuiStarRating.cs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using Accord.Imaging;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Drawing.Drawing2D;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Security.Principal;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using System.Windows.Forms;
11+
12+
namespace CuoreUI.Controls
13+
{
14+
public partial class cuiStarRating : Control
15+
{
16+
public cuiStarRating()
17+
{
18+
DoubleBuffered = true;
19+
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
20+
Size = new Size(150, 28);
21+
}
22+
23+
private int privateStarCount = 5;
24+
private int privateRating = 2;
25+
private Color privateStarColor = Color.MediumSlateBlue;
26+
private int privateStarBorderSize = 1;
27+
28+
// Public properties to access private variables
29+
30+
public int StarCount
31+
{
32+
get
33+
{
34+
return privateStarCount;
35+
}
36+
set
37+
{
38+
privateStarCount = value;
39+
}
40+
}
41+
42+
public int Rating
43+
{
44+
get
45+
{
46+
return privateRating;
47+
}
48+
set
49+
{
50+
privateRating = value;
51+
}
52+
}
53+
54+
public Color StarColor
55+
{
56+
get
57+
{
58+
return privateStarColor;
59+
}
60+
set
61+
{
62+
privateStarColor = value;
63+
}
64+
}
65+
66+
public int StarBorderSize
67+
{
68+
get
69+
{
70+
return privateStarBorderSize;
71+
}
72+
set
73+
{
74+
privateStarBorderSize = value;
75+
}
76+
}
77+
protected override void OnPaint(PaintEventArgs e)
78+
{
79+
base.OnPaint(e);
80+
81+
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
82+
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
83+
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
84+
int starWidth = Height - 2;
85+
int spacing = starWidth / 5;
86+
87+
for (int i = 0; i < StarCount; i++)
88+
{
89+
int starLeft = i * (starWidth + spacing);
90+
Rectangle starRect = new Rectangle(starLeft, 0, starWidth, this.Height);
91+
starRect.Offset(starWidth / 2, 0);
92+
GraphicsPath starPath = Helper.Star(starLeft + starWidth / 2, this.Height / 2, starWidth / 2, starWidth / 3.8f, 5);
93+
94+
if ((i + 1) * 2 <= Rating)
95+
{
96+
e.Graphics.FillPath(new SolidBrush(StarColor), starPath);
97+
}
98+
else if (i * 2 + 1 == Rating)
99+
{
100+
e.Graphics.FillPath(new SolidBrush(StarColor), starPath);
101+
e.Graphics.FillRectangle(new SolidBrush(BackColor), starRect);
102+
}
103+
104+
using (Pen starBorderPen = new Pen(StarColor, StarBorderSize))
105+
{
106+
e.Graphics.DrawPath(starBorderPen, starPath);
107+
}
108+
}
109+
}
110+
}
111+
}

wfcl1/Controls/cuiSvgBox.Designer.cs

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)