| 230 | } |
| 231 | |
| 232 | void ColourPanel::updateFromColour(const MyGUI::Colour& _colour) |
| 233 | { |
| 234 | mCurrentColour = _colour; |
| 235 | if (!mAlphaSupport) |
| 236 | mCurrentColour.alpha = 1; |
| 237 | |
| 238 | std::vector<float> vec; |
| 239 | vec.push_back(mCurrentColour.red); |
| 240 | vec.push_back(mCurrentColour.green); |
| 241 | vec.push_back(mCurrentColour.blue); |
| 242 | std::sort(vec.begin(), vec.end()); |
| 243 | |
| 244 | MyGUI::IntPoint point( |
| 245 | static_cast<int>((1 - vec[0] / vec[2]) * mColourRect->getWidth()), |
| 246 | static_cast<int>((1 - vec[2]) * mColourRect->getHeight())); |
| 247 | mImageColourPicker->setPosition( |
| 248 | point.left - (mImageColourPicker->getWidth() / 2), |
| 249 | point.top - (mImageColourPicker->getHeight() / 2)); |
| 250 | |
| 251 | int iMax = (mCurrentColour.red == vec[2]) ? 0 : (mCurrentColour.green == vec[2]) ? 1 : 2; |
| 252 | int iMin = (mCurrentColour.red == vec[0]) ? 0 : (mCurrentColour.green == vec[0]) ? 1 : 2; |
| 253 | int iAvg = 3 - iMax - iMin; |
| 254 | |
| 255 | if (iMin == iMax) // if gray colour - set base red |
| 256 | { |
| 257 | iMax = 0; |
| 258 | iMin = 1; |
| 259 | iAvg = 2; |
| 260 | byIndex(mBaseColour, iMin) = 0.; |
| 261 | byIndex(mBaseColour, iAvg) = 0.; |
| 262 | byIndex(mBaseColour, iMax) = 1.; |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | byIndex(mBaseColour, iMin) = 0.; |
| 267 | byIndex(mBaseColour, iAvg) = (vec[1] - vec[0]) / (vec[2] - vec[0]); |
| 268 | byIndex(mBaseColour, iMax) = 1.; |
| 269 | } |
| 270 | |
| 271 | int i = 0; |
| 272 | for (i = 0; i < 6; ++i) |
| 273 | { |
| 274 | if ((std::fabs(byIndex(mColourRange[i], iMin) - byIndex(mBaseColour, iMin)) < 0.001f) && |
| 275 | (std::fabs(byIndex(mColourRange[i], iMax) - byIndex(mBaseColour, iMax)) < 0.001f) && |
| 276 | (std::fabs(byIndex(mColourRange[i + 1], iMin) - byIndex(mBaseColour, iMin)) < 0.001f) && |
| 277 | (std::fabs(byIndex(mColourRange[i + 1], iMax) - byIndex(mBaseColour, iMax)) < 0.001f)) |
| 278 | break; |
| 279 | } |
| 280 | |
| 281 | float sector_size = static_cast<float>(mScrollRange->getScrollRange()) / 6.0f; |
| 282 | size_t current = i; |
| 283 | |
| 284 | float offset = byIndex(mBaseColour, iAvg); |
| 285 | if (byIndex(mColourRange[i + 1], iAvg) < byIndex(mColourRange[i], iAvg)) |
| 286 | offset = 1 - byIndex(mBaseColour, iAvg); |
| 287 | |
| 288 | size_t pos = size_t((current + offset) * sector_size); |
| 289 |
nothing calls this directly
no test coverage detected