Skip to content

Commit 2519d79

Browse files
committed
#195 Bug Fixe
1 parent 76eb995 commit 2519d79

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

src/ReaLTaiizor/Controls/Picker/CyberColorPicker.Designer.cs

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

src/ReaLTaiizor/Controls/Picker/CyberColorPicker.cs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public Color SelectedColor
3939
set
4040
{
4141
tmp_selectedcolor = value;
42+
UpdateColorPickerFromColor(value);
4243
ColorChanged(value);
4344
}
4445
}
@@ -236,8 +237,9 @@ private Color PickColor(float x, float y)
236237
return Color.Empty;
237238
}
238239

239-
label1.Text = $"RGB: {Color.R}, {Color.G}, {Color.B}";
240240
label2.Text = $"HEX: #{Color.ToArgb():X}";
241+
label1.Text = $"RGB: {Color.R}, {Color.G}, {Color.B}";
242+
241243
CursorPos = new PointF(x1 + ((float)pictureBox1.Width / 2), y1 + ((float)pictureBox1.Height / 2));
242244
pictureBox2.BackColor = Color;
243245
((ValueBox)pictureBox3.Tag).Color = Color;
@@ -316,6 +318,70 @@ private Color HSVtoRGB(double H, double S, double V)
316318
return Color.FromArgb((int)R, (int)G, (int)B);
317319
}
318320

321+
private void UpdateColorPickerFromColor(Color color)
322+
{
323+
if (color.IsEmpty || color == Color.Transparent)
324+
{
325+
return;
326+
}
327+
328+
RGBtoHSV(color.R, color.G, color.B, out double h, out double s, out double v);
329+
330+
float radius = (float)pictureBox1.Width / 2;
331+
float saturationRadius = (float)(s * radius);
332+
double angleRad = h * 2 * Math.PI;
333+
334+
float x = (float)(saturationRadius * Math.Cos(angleRad)) + radius;
335+
float y = (float)(saturationRadius * Math.Sin(angleRad)) + radius;
336+
337+
((ValueBox)pictureBox3.Tag).Value = (float)v;
338+
((ValueBox)pictureBox3.Tag).Color = HSVtoRGB(h, s, 1.0);
339+
340+
CursorPos = new PointF(x, y);
341+
pictureBox1.Tag = new PointF(x, y);
342+
343+
label1.Text = $"RGB: {color.R}, {color.G}, {color.B}";
344+
label2.Text = $"HEX: #{color.ToArgb():X}";
345+
pictureBox2.BackColor = color;
346+
347+
pictureBox1.Invalidate();
348+
pictureBox2.Invalidate();
349+
pictureBox3.Invalidate();
350+
}
351+
352+
private void RGBtoHSV(int r, int g, int b, out double h, out double s, out double v)
353+
{
354+
double red = r / 255.0;
355+
double green = g / 255.0;
356+
double blue = b / 255.0;
357+
358+
double max = Math.Max(red, Math.Max(green, blue));
359+
double min = Math.Min(red, Math.Min(green, blue));
360+
double delta = max - min;
361+
362+
v = max;
363+
364+
s = max == 0 ? 0 : delta / max;
365+
366+
h = 0;
367+
if (delta != 0)
368+
{
369+
if (max == red)
370+
{
371+
h = ((green - blue) / delta) + (green < blue ? 6 : 0);
372+
}
373+
else if (max == green)
374+
{
375+
h = ((blue - red) / delta) + 2;
376+
}
377+
else
378+
{
379+
h = ((red - green) / delta) + 4;
380+
}
381+
h /= 6;
382+
}
383+
}
384+
319385
#endregion
320386
}
321387

src/ReaLTaiizor/ReaLTaiizor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Creator: Taiizor
1414
// Website: www.vegalya.com
1515
// Created: 15.May.2019
16-
// Changed: 10.Apr.2025
16+
// Changed: 11.Apr.2025
1717
// Version: 3.8.1.3
1818
//
1919
// |---------DO-NOT-REMOVE---------|

0 commit comments

Comments
 (0)