本文整理汇总了C++中CColor::fromHSL方法的典型用法代码示例。如果您正苦于以下问题:C++ CColor::fromHSL方法的具体用法?C++ CColor::fromHSL怎么用?C++ CColor::fromHSL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CColor
的用法示例。
在下文中一共展示了CColor::fromHSL方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateBackground
//----------------------------------------------------------------------------------------------------
void UIColorSlider::updateBackground (CDrawContext* context)
{
double scaleFactor = context->getScaleFactor ();
SharedPointer<COffscreenContext> offscreen = owned (COffscreenContext::create (getFrame (), getWidth (), getHeight (), scaleFactor));
if (offscreen)
{
const int32_t kNumPoints = (style <= kLightness) ? 360 : 256;
CCoord width = std::floor (getWidth () + 0.5);
offscreen->beginDraw ();
offscreen->setDrawMode (kAliasing);
CCoord minWidth = 1. / scaleFactor;
CCoord widthPerColor = width / static_cast<double> (kNumPoints - 1);
CRect r;
r.setHeight (getHeight ());
r.setWidth (widthPerColor < minWidth ? minWidth : (std::floor (widthPerColor * scaleFactor + 0.5) / scaleFactor));
r.offset (-r.getWidth (), 0);
offscreen->setLineWidth (minWidth);
for (int32_t i = 0; i < kNumPoints; i++)
{
CCoord x = std::floor (widthPerColor * i * scaleFactor + 0.5) / scaleFactor;
if (x > r.right || i == kNumPoints -1)
{
CColor c = color->base ();
switch (style)
{
case kRed:
{
c.red = (uint8_t)i;
break;
}
case kGreen:
{
c.green = (uint8_t)i;
break;
}
case kBlue:
{
c.blue = (uint8_t)i;
break;
}
case kAlpha:
{
c.alpha = (uint8_t)i;
break;
}
case kHue:
{
double hue = (static_cast<double> (i) / static_cast<double> (kNumPoints)) * 360.;
c.fromHSL (hue, color->getSaturation (), color->getLightness ());
break;
}
case kSaturation:
{
double sat = (static_cast<double> (i) / static_cast<double> (kNumPoints));
c.fromHSL (color->getHue (), sat, color->getLightness ());
break;
}
case kLightness:
{
double light = (static_cast<double> (i) / static_cast<double> (kNumPoints));
c.fromHSL (color->getHue (), color->getSaturation (), light);
break;
}
}
offscreen->setFrameColor (c);
CCoord next = r.left + widthPerColor;
while (r.left < next)
{
offscreen->drawLine (r.getTopLeft (), r.getBottomLeft ());
r.offset (minWidth, 0);
}
}
}
offscreen->drawLine (r.getTopLeft (), r.getBottomLeft ());
offscreen->endDraw ();
setBackground (offscreen->getBitmap ());
}
if (getHandle () == 0)
{
offscreen = owned (COffscreenContext::create (getFrame (), 7, getHeight (), context->getScaleFactor ()));
if (offscreen)
{
offscreen->beginDraw ();
offscreen->setFrameColor (kBlackCColor);
offscreen->setLineWidth (1);
offscreen->setDrawMode (kAliasing);
CRect r (0, 0, 7, getHeight ());
offscreen->drawRect (r, kDrawStroked);
r.inset (1, 1);
offscreen->setFrameColor (kWhiteCColor);
offscreen->drawRect (r, kDrawStroked);
offscreen->endDraw ();
setHandle (offscreen->getBitmap ());
}
}
}