MCPcopy Create free account
hub / github.com/MyGUI/mygui / updateFromColour

Method updateFromColour

Demos/Demo_Colour/ColourPanel.cpp:215–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213 }
214
215 void ColourPanel::updateFromColour(const MyGUI::Colour& _colour)
216 {
217 mCurrentColour = _colour;
218
219 std::vector<float> vec;
220 vec.push_back(_colour.red);
221 vec.push_back(_colour.green);
222 vec.push_back(_colour.blue);
223 std::sort(vec.begin(), vec.end());
224
225 MyGUI::IntPoint point(
226 static_cast<int>((1 - vec[0] / vec[2]) * mColourRect->getWidth()),
227 static_cast<int>((1 - vec[2]) * mColourRect->getHeight()));
228 mImageColourPicker->setPosition(
229 point.left - (mImageColourPicker->getWidth() / 2),
230 point.top - (mImageColourPicker->getHeight() / 2));
231
232 int iMax = (_colour.red == vec[2]) ? 0 : (_colour.green == vec[2]) ? 1 : 2;
233 int iMin = (_colour.red == vec[0]) ? 0 : (_colour.green == vec[0]) ? 1 : 2;
234 int iAvg = 3 - iMax - iMin;
235
236 if (iMin == iMax) // if gray colour - set base red
237 {
238 iMax = 0;
239 iMin = 1;
240 iAvg = 2;
241 byIndex(mBaseColour, iMin) = 0.;
242 byIndex(mBaseColour, iAvg) = 0.;
243 byIndex(mBaseColour, iMax) = 1.;
244 }
245 else
246 {
247 byIndex(mBaseColour, iMin) = 0.;
248 byIndex(mBaseColour, iAvg) = (vec[1] - vec[0]) / (vec[2] - vec[0]);
249 byIndex(mBaseColour, iMax) = 1.;
250 }
251
252
253 int i;
254 for (i = 0; i < 6; ++i)
255 {
256 if ((std::abs(byIndex(mColourRange[i], iMin) - byIndex(mBaseColour, iMin)) < 0.001f) &&
257 (std::abs(byIndex(mColourRange[i], iMax) - byIndex(mBaseColour, iMax)) < 0.001f) &&
258 (std::abs(byIndex(mColourRange[i + 1], iMin) - byIndex(mBaseColour, iMin)) < 0.001f) &&
259 (std::abs(byIndex(mColourRange[i + 1], iMax) - byIndex(mBaseColour, iMax)) < 0.001f))
260 break;
261 }
262
263 float sector_size = (float)mScrollRange->getScrollRange() / 6.0f;
264 size_t current = i;
265
266 float offset = byIndex(mBaseColour, iAvg);
267 if (byIndex(mColourRange[i + 1], iAvg) < byIndex(mColourRange[i], iAvg))
268 offset = 1 - byIndex(mBaseColour, iAvg);
269
270 size_t pos = size_t((current + offset) * sector_size);
271
272 mScrollRange->setScrollPosition(pos);

Callers

nothing calls this directly

Calls 10

getScrollRangeMethod · 0.80
sortFunction · 0.50
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45
setPositionMethod · 0.45
setScrollPositionMethod · 0.45
setColourMethod · 0.45

Tested by

no test coverage detected