MCPcopy Create free account
hub / github.com/TranslucentTB/TranslucentTB / UpdateColors

Method UpdateColors

Xaml/Controls/ColorPickerSlider.cpp:49–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47 }
48
49 void ColorPickerSlider::UpdateColors()
50 {
51 auto hsvColor = HsvColor();
52
53 // Calculate and set the background
54 UpdateBackground(hsvColor);
55
56 // Calculate and set the foreground ensuring contrast with the background
57 Windows::UI::Color rgbColor = Util::Color::FromHSV(hsvColor);
58 Windows::UI::Color selectedRgbColor;
59 const double sliderPercent = Value() / (Maximum() - Minimum());
60
61 const auto colorChannel = ColorChannel();
62 const auto alphaMaxForced = IsAlphaMaxForced();
63 if (ColorRepresentation() == txmp::ColorRepresentation::Hsva)
64 {
65 if (alphaMaxForced && colorChannel != txmp::ColorChannel::Alpha)
66 {
67 hsvColor.A = 1.0;
68 }
69
70 const auto saturationMaxForced = IsSaturationValueMaxForced();
71 switch (colorChannel)
72 {
73 case txmp::ColorChannel::Channel1:
74 hsvColor.H = std::clamp(sliderPercent * 360.0, 0.0, 360.0);
75 if (saturationMaxForced)
76 {
77 hsvColor.S = hsvColor.V = 1.0;
78 }
79 break;
80
81 case txmp::ColorChannel::Channel2:
82 hsvColor.S = std::clamp(sliderPercent * 1.0, 0.0, 1.0);
83 if (saturationMaxForced)
84 {
85 hsvColor.V = 1.0;
86 }
87 break;
88
89 case txmp::ColorChannel::Channel3:
90 hsvColor.V = std::clamp(sliderPercent * 1.0, 0.0, 1.0);
91 if (saturationMaxForced)
92 {
93 hsvColor.S = 1.0;
94 }
95 break;
96 }
97
98 selectedRgbColor = Util::Color::FromHSV(hsvColor);
99 }
100 else
101 {
102 if (alphaMaxForced && colorChannel != txmp::ColorChannel::Alpha)
103 {
104 rgbColor.A = 255;
105 }
106

Calls 3

HsvColorClass · 0.85
ColorClass · 0.85
IsDarkColorMethod · 0.80

Tested by

no test coverage detected