forked from bahstrike/DyeAtlas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HSVSlidersPopup.cs
90 lines (72 loc) · 2.81 KB
/
HSVSlidersPopup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DyeAtlas
{
public partial class HSVSlidersPopup : Form
{
public readonly DyeAtlas dyeAtlas;
public HSVSlidersPopup(DyeAtlas _dyeAtlas)
{
dyeAtlas = _dyeAtlas;
InitializeComponent();
}
DateTime? ValuesUpdatedTime = null;
void UpdateValues()
{
// cheating with static values lol
Palette.HueImportance = (double)hueTrack.Value / (double)(hueTrack.Maximum - hueTrack.Minimum);
Palette.SaturationImportance = (double)satTrack.Value / (double)(satTrack.Maximum - satTrack.Minimum);
Palette.ValueImportance = (double)valTrack.Value / (double)(valTrack.Maximum - valTrack.Minimum);
// update UI
hueLabel.Text = $"Hue Importance: {Palette.HueImportance.ToString("0.0")}";
satLabel.Text = $"Saturation Importance: {Palette.SaturationImportance.ToString("0.0")}";
valLabel.Text = $"Brightness Importance: {Palette.ValueImportance.ToString("0.0")}";
ValuesUpdatedTime = DateTime.Now;
}
public bool updating = false;
private void HSVSlidersPopup_Load(object sender, EventArgs e)
{
updating = true;
hueTrack.Value = (int)Math.Round((Palette.HueImportance) * (double)(hueTrack.Maximum - hueTrack.Minimum));
satTrack.Value = (int)Math.Round((Palette.SaturationImportance) * (double)(satTrack.Maximum - satTrack.Minimum));
valTrack.Value = (int)Math.Round((Palette.ValueImportance) * (double)(valTrack.Maximum - valTrack.Minimum));
updating = false;
// just update labels
UpdateValues();
}
private void HSVSlidersPopup_FormClosing(object sender, FormClosingEventArgs e)
{
dyeAtlas.hsvcompare.Checked = false;// we dont wanna use HSV anymore
}
private void Track_ValueChanged(object sender, EventArgs e)
{
if (updating)
return;
UpdateValues();
}
private void resetButton_Click(object sender, EventArgs e)
{
updating = true;
hueTrack.Value = 0;
satTrack.Value = 0;
valTrack.Value = 0;
updating = false;
UpdateValues();
}
private void timer1_Tick(object sender, EventArgs e)
{
if(ValuesUpdatedTime.HasValue && DateTime.Now.Subtract(ValuesUpdatedTime.Value).TotalMilliseconds > 350)
{
dyeAtlas.Reprocess();
ValuesUpdatedTime = null;
}
}
}
}