Ticket #3790: patch_colorcontrol

File patch_colorcontrol, 7.4 KB (added by stpere, 16 years ago)
Line 
1Index: src/kits/interface/ColorControl.cpp
2===================================================================
3--- src/kits/interface/ColorControl.cpp (révision 30257)
4+++ src/kits/interface/ColorControl.cpp (copie de travail)
5@@ -7,6 +7,7 @@
6 * Axel Dörfler, axeld@pinc-software.de
7 * Alexandre Deckner, alex@zappotek.com
8 * Jérôme Duval
9+ * Philippe Saint-Pierre, stpere@gmail.com
10 */
11
12 /** BColorControl displays a palette of selectable colors. */
13@@ -16,6 +17,8 @@
14 #include <stdio.h>
15 #include <stdlib.h>
16
17+#include <iostream>
18+
19 #include <ControlLook.h>
20 #include <Bitmap.h>
21 #include <TextControl.h>
22@@ -263,38 +266,10 @@
23 Invalidate(_PaletteSelectorFrame(fSelectedPaletteColorIndex));
24
25 fPreviousSelectedPaletteColorIndex = fSelectedPaletteColorIndex;
26- } else {
27- float invalidateRadius = kSelectorSize/2 + kSelectorPenSize;
28- BPoint p;
29-
30- if (c1.red != c2.red) {
31- p = _SelectorPosition(_RampFrame(1), c1.red);
32- Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius,
33- p.x + invalidateRadius, p.y + invalidateRadius));
34-
35- p = _SelectorPosition(_RampFrame(1), c2.red);
36- Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius,
37- p.x + invalidateRadius, p.y + invalidateRadius));
38- }
39- if (c1.green != c2.green) {
40- p = _SelectorPosition(_RampFrame(2), c1.green);
41- Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius,
42- p.x + invalidateRadius, p.y + invalidateRadius));
43-
44- p = _SelectorPosition(_RampFrame(2), c2.green);
45- Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius,
46- p.x + invalidateRadius, p.y + invalidateRadius));
47- }
48- if (c1.blue != c2.blue) {
49- p = _SelectorPosition(_RampFrame(3), c1.blue);
50- Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius,
51- p.x + invalidateRadius, p.y + invalidateRadius));
52-
53- p = _SelectorPosition(_RampFrame(3), c2.blue);
54- Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius,
55- p.x + invalidateRadius, p.y + invalidateRadius));
56- }
57- }
58+ } else if (c1.red != c2.red
59+ || c1.green != c2.green
60+ || c1.blue != c2.blue)
61+ Invalidate();
62
63 // the textcontrols have to be updated even when the color
64 // hasn't changed since the value is clamped upstream
65@@ -493,21 +468,28 @@
66 }
67 }
68 } else {
69+ rgb_color color = ValueAsColor();
70+
71 rgb_color white = {255, 255, 255, 255};
72- rgb_color red = {255, 0, 0, 255};
73- rgb_color green = {0, 255, 0, 255};
74- rgb_color blue = {0, 0, 255, 255};
75+ rgb_color red = {255, color.green, color.blue, 255};
76+ rgb_color green = {color.red, 255, color.blue, 255};
77+ rgb_color blue = {color.red, color.green, 255, 255};
78
79+
80 rgb_color compColor = {0, 0, 0, 255};
81+ rgb_color compColor1 = {0, color.green, color.blue, 255};
82+ rgb_color compColor2 = {color.red, 0, color.blue, 255};
83+ rgb_color compColor3 = {color.red, color.green, 0, 255};
84 if (!enabled) {
85 compColor.red = compColor.green = compColor.blue = 156;
86 red.red = green.green = blue.blue = 70;
87 white.red = white.green = white.blue = 70;
88 }
89- _ColorRamp(_RampFrame(0), target, white, compColor, 0, false, update);
90- _ColorRamp(_RampFrame(1), target, red, compColor, 0, false, update);
91- _ColorRamp(_RampFrame(2), target, green, compColor, 0, false, update);
92- _ColorRamp(_RampFrame(3), target, blue, compColor, 0, false, update);
93+
94+ _ColorRamp(_RampFrame(0), target, white, compColor, 0, false);
95+ _ColorRamp(_RampFrame(1), target, red, compColor1, 0, false);
96+ _ColorRamp(_RampFrame(2), target, green, compColor2, 0, false);
97+ _ColorRamp(_RampFrame(3), target, blue, compColor3, 0, false);
98 }
99
100 target->ConstrainClippingRegion(NULL);
101@@ -527,51 +509,73 @@
102 }
103 } else {
104 rgb_color color = ValueAsColor();
105- target->SetPenSize(kSelectorPenSize);
106+
107+ target->SetPenSize(kSelectorPenSize/2);
108+
109 target->SetHighColor(255, 255, 255);
110-
111+
112 target->StrokeEllipse(_SelectorPosition(_RampFrame(1), color.red),
113- kSelectorSize / 2, kSelectorSize / 2);
114+ kSelectorSize / 2, kSelectorSize / 2);
115 target->StrokeEllipse(_SelectorPosition(_RampFrame(2), color.green),
116- kSelectorSize / 2, kSelectorSize / 2);
117+ kSelectorSize / 2, kSelectorSize / 2);
118 target->StrokeEllipse(_SelectorPosition(_RampFrame(3), color.blue),
119- kSelectorSize / 2, kSelectorSize / 2);
120+ kSelectorSize / 2, kSelectorSize / 2);
121+
122+ target->SetHighColor(0, 0, 0);
123+
124+ target->StrokeEllipse(_SelectorPosition(_RampFrame(1), color.red),
125+ kSelectorSize / 2 + kSelectorPenSize / 2,
126+ kSelectorSize / 2 + kSelectorPenSize / 2);
127+ target->StrokeEllipse(_SelectorPosition(_RampFrame(2), color.green),
128+ kSelectorSize / 2 + kSelectorPenSize / 2,
129+ kSelectorSize / 2 + kSelectorPenSize / 2);
130+ target->StrokeEllipse(_SelectorPosition(_RampFrame(3), color.blue),
131+ kSelectorSize / 2 + kSelectorPenSize / 2,
132+ kSelectorSize / 2 + kSelectorPenSize / 2);
133+
134
135- target->SetPenSize(1.0f);
136+ target->SetPenSize(1.0f);
137+ Invalidate();
138 }
139 }
140
141
142 void
143 BColorControl::_ColorRamp(BRect rect, BView* target,
144- rgb_color baseColor, rgb_color compColor, int16 flag, bool focused, BRect update)
145+ rgb_color baseColor, rgb_color compColor, int16 flag, bool focused)
146 {
147 float width = rect.Width() + 1;
148- rgb_color color;
149+ rgb_color color = compColor;
150 color.alpha = 255;
151
152- update = update & rect;
153+ target->BeginLineArray((int32)rect.Width() + 1);
154
155- if (update.IsValid() && update.Width() >= 0){
156- target->BeginLineArray((int32)update.Width() + 1);
157-
158- for (float i = (update.left - rect.left); i <= (update.right - rect.left) + 1; i++) {
159- color.red = (uint8)(i * baseColor.red / width) + compColor.red;
160- color.green = (uint8)(i * baseColor.green / width) + compColor.green;
161- color.blue = (uint8)(i * baseColor.blue / width) + compColor.blue;
162- target->AddLine(BPoint(rect.left + i, rect.top),
163- BPoint(rect.left + i, rect.bottom - 1), color);
164- }
165-
166- target->EndLineArray();
167+ float deltaR = (baseColor.red - compColor.red) / width;
168+ float deltaG = (baseColor.green - compColor.green) / width;
169+ float deltaB = (baseColor.blue - compColor.blue) / width;
170+
171+ float sumR = color.red;
172+ float sumG = color.green;
173+ float sumB = color.blue;
174+
175+ for (float i = 0; i <= width; i++) {
176+ sumR += deltaR;
177+ sumG += deltaG;
178+ sumB += deltaB;
179+ color.red = (uint8)sumR;
180+ color.green = (uint8)sumG;
181+ color.blue = (uint8)sumB;
182+ target->AddLine(BPoint(rect.left + i, rect.top),
183+ BPoint(rect.left + i, rect.bottom - 1), color);
184 }
185+ target->EndLineArray();
186 }
187
188
189 BPoint
190 BColorControl::_SelectorPosition(const BRect& rampRect, uint8 shade) const
191 {
192- float radius = kSelectorSize / 2 + kSelectorPenSize / 2;
193+ float radius = (kSelectorSize + kSelectorPenSize) / 2;
194
195 return BPoint(rampRect.left + kSelectorHSpacing + radius +
196 shade * (rampRect.Width() - 2 * (kSelectorHSpacing + radius)) / 255,
197Index: headers/os/interface/ColorControl.h
198===================================================================
199--- headers/os/interface/ColorControl.h (révision 30257)
200+++ headers/os/interface/ColorControl.h (copie de travail)
201@@ -95,7 +95,7 @@
202 void _DrawSelectors(BView* target);
203 void _ColorRamp(BRect rect, BView* target,
204 rgb_color baseColor, rgb_color compColor,
205- int16 flag, bool focused, BRect update);
206+ int16 flag, bool focused);
207 BPoint _SelectorPosition(const BRect& rampRect,
208 uint8 shade) const;
209 BRect _PaletteSelectorFrame(uint8 colorIndex) const;