//------------------------------------------------------------------------ bool CTextButton::getFocusPath (CGraphicsPath& outPath) { CRect r (getViewSize ()); CCoord focusWidth = getFrame ()->getFocusWidth (); r.inset (-focusWidth, -focusWidth); outPath.addRoundRect (r, roundRadius); outPath.closeSubpath (); r = getViewSize (); r.inset (frameWidth / 2., frameWidth / 2.); outPath.addRoundRect (r, roundRadius); return true; }
//---------------------------------------------------------------------------------------------------- CRect UISearchTextField::getClearMarkRect () const { CRect r (getViewSize ()); r.left = r.right - getHeight (); r.inset (2, 2); return r; }
//---------------------------------------------------------------------------------------------------- void UISearchTextField::drawClearMark (CDrawContext* context) const { if (getText ().empty ()) return; SharedPointer<CGraphicsPath> path = owned (context->createGraphicsPath ()); if (path == 0) return; CRect r = getClearMarkRect (); CColor color (fontColor); color.alpha /= 2; context->setFillColor (color); context->setDrawMode (kAntiAliasing); context->drawEllipse (r, kDrawFilled); double h,s,v; color.toHSV (h, s, v); v = 1. - v; color.fromHSV (h, s, v); context->setFrameColor (color); context->setLineWidth (2.); r.inset (r.getWidth () / (M_PI * 2.) + 1, r.getHeight () / (M_PI * 2.) + 1); path->beginSubpath (r.getTopLeft ()); path->addLine (r.getBottomRight ()); path->beginSubpath (r.getBottomLeft ()); path->addLine (r.getTopRight ()); context->setDrawMode (kAntiAliasing|kNonIntegralMode); context->drawGraphicsPath (path, CDrawContext::kPathStroked); }
//----------------------------------------------------------------------------- void EventLogDataBrowserSource::dbDrawCell (CDrawContext* context, const CRect& size, int32_t row, int32_t column, int32_t flags, CDataBrowser* browser) { CColor cellColor (kWhiteCColor); bool oddRow = row % 2 != 0; if (oddRow) { cellColor = kBlackCColor; cellColor.alpha /= 16; } String cellValue; LogEvent& logEvent = mLogEvents.at (row); if (logEvent.count > 0) { if (String (LOG_ERR) == logEventSeverity[logEvent.id]) cellColor = kRedCColor; else if (String (LOG_WARN) == logEventSeverity[logEvent.id]) cellColor = kYellowCColor; else if (String (LOG_INFO) == logEventSeverity[logEvent.id]) cellColor = kBlueCColor; if (oddRow) cellColor.alpha /= 2; else cellColor.alpha /= 3.; } context->setFillColor (cellColor); context->drawRect (size, kDrawFilled); switch (column) { case kType: { if (logEvent.count > 0) cellValue.printf (logEventSeverity[logEvent.id]); break; } case kDescription: { cellValue.assign (logEventDescriptions[row]); break; } case kCount: { cellValue.printf ("%d", logEvent.count); break; } } CRect cellSize (size); cellSize.inset (5, 0); context->setFont (kNormalFontSmall); context->setFontColor (kBlackCColor); context->drawString (cellValue.text8 (), cellSize, kLeftText); }
//----------------------------------------------------------------------------- bool CSegmentButton::getFocusPath (CGraphicsPath& outPath) { CRect r (getViewSize ()); r.inset (getFrameWidth () / 2., getFrameWidth () / 2.); outPath.addRoundRect (r, getRoundRadius ()); CCoord focusWidth = getFrame ()->getFocusWidth (); r.extend (focusWidth, focusWidth); outPath.addRoundRect (r, getRoundRadius ()); return true; }
//------------------------------------------------------------------------ CGraphicsPath* CTextButton::getPath (CDrawContext* context) { if (_path == 0) { CRect r (getViewSize ()); r.inset (frameWidth / 2., frameWidth / 2.); _path = context->createRoundRectGraphicsPath (r, roundRadius); } return _path; }
//----------------------------------------------------------------------------- void CSegmentButton::drawRect (CDrawContext* pContext, const CRect& dirtyRect) { bool isHorizontal = style == kHorizontal; SharedPointer<CGraphicsPath> path; if (gradient || gradientHighlighted || (getFrameWidth () > 0. && getFrameColor ().alpha != 0)) { CRect r (getViewSize ()); r.inset (getFrameWidth () / 2., getFrameWidth () / 2.); path = owned (pContext->createGraphicsPath ()); path->addRoundRect (r, getRoundRadius ()); } pContext->setDrawMode (kAntiAliasing); bool drawLines = getFrameWidth () > 0. && getFrameColor ().alpha != 0; if (drawLines) { pContext->setLineStyle (kLineSolid); pContext->setLineWidth (getFrameWidth ()); pContext->setFrameColor (getFrameColor ()); } if (gradient) { pContext->fillLinearGradient (path, *gradient, getViewSize ().getTopLeft (), getViewSize ().getBottomLeft ()); } uint32_t selectedIndex = getSelectedSegment (); for (uint32_t index = 0; index < segments.size (); ++index) { Segment& segment = segments[index]; if (!dirtyRect.rectOverlap (segment.rect)) continue; CRect oldClip; pContext->getClipRect (oldClip); CRect clipRect (segment.rect); clipRect.bound (oldClip); pContext->setClipRect (clipRect); bool selected = selectedIndex == index; if (selected && gradientHighlighted) pContext->fillLinearGradient (path, *gradientHighlighted, segment.rect.getTopLeft (), segment.rect.getBottomLeft ()); if (selected && segment.backgroundHighlighted) segment.backgroundHighlighted->draw (pContext, segment.rect); else if (segment.background) segment.background->draw (pContext, segment.rect); CDrawMethods::drawIconAndText (pContext, selected ? segment.iconHighlighted : segment.icon, segment.iconPosition, textAlignment, textMargin, segment.rect, segment.name, font, selected ? textColorHighlighted : textColor); pContext->setClipRect (oldClip); if (drawLines && index > 0 && index < segments.size ()) { path->beginSubpath (segment.rect.getTopLeft ()); path->addLine (isHorizontal ? segment.rect.getBottomLeft () : segment.rect.getTopRight ()); } } if (drawLines) pContext->drawGraphicsPath (path, CDrawContext::kPathStroked); setDirty (false); }
//------------------------------------------------------------------------ CMouseEventResult ScaleView::onMouseEntered (CPoint &where, const CButtonState& buttons) { if (origRect.isEmpty ()) origRect = getViewSize (); CRect r (origRect); r.inset (-40, -15); getFrame ()->getAnimator ()->removeAnimation (this, "AlphaAnimation"); getFrame ()->getAnimator ()->removeAnimation (this, "SizeAnimation"); getFrame ()->getAnimator ()->addAnimation (this, "AlphaAnimation", new Animation::AlphaValueAnimation (1.f), new Animation::RepeatTimingFunction (new Animation::LinearTimingFunction (300), -1, true)); getFrame ()->getAnimator ()->addAnimation (this, "SizeAnimation", new Animation::ViewSizeAnimation (r), new Animation::RepeatTimingFunction (new Animation::LinearTimingFunction (200), -1, true)); return CViewContainer::onMouseEntered (where, buttons); }
void draw (CDrawContext* context) { CGraphicsPath* path = context->createGraphicsPath (); if (path) { CRect r (getViewSize ()); r.inset (5, 5); path->beginSubpath (CPoint (r.left + r.getWidth () / 2, r.top)); path->addLine (CPoint (r.left, r.bottom)); path->addLine (CPoint (r.right, r.bottom)); path->closeSubpath (); setupLineStyle (context); context->drawGraphicsPath (path, CDrawContext::kPathStroked); path->forget (); } setDirty (false); }
bool DrawTestEditor::open (void *ptr) { AEffGUIEditor::open (ptr); CRect size (rect.left , rect.top, rect.right, rect.bottom); CFrame* frame = new CFrame (size, ptr, this); frame->setBackground (backgroundBitmap); size.inset (8, 8); size.top++; // the background bitmap is not correct size.left++; // the background bitmap is not correct // CView* testView = new PLinesView (size); // frame->addView (testView); setTabView (frame, size, CTabView::kPositionBottom); tooltipSupport = new CTooltipSupport; frame->setMouseObserver (tooltipSupport); // last but not least set the class variable frame to our newly created frame this->frame = frame; return true; }
void GuiCustomRowColumnView::drawBackgroundRect(CDrawContext* pContext, const CRect& _updateRect) { if (getDrawBackground()) { CRect oldClip; pContext->getClipRect(oldClip); CRect newClip(_updateRect); newClip.bound(oldClip); pContext->setClipRect(newClip); CRect tr(0, 0, getViewSize().getWidth(), getViewSize().getHeight()); getDrawBackground()->draw(pContext, tr, backgroundOffset); pContext->setClipRect(oldClip); } else if ((backgroundColor.alpha != 255 && getTransparency()) || !getTransparency()) { pContext->setDrawMode(kAliasing); pContext->setLineWidth(1); pContext->setFillColor(backgroundColor); pContext->setFrameColor(backgroundColor); pContext->setLineStyle(kLineSolid); CRect r; if (backgroundColorDrawStyle == kDrawFilled || (backgroundColorDrawStyle == kDrawFilledAndStroked && backgroundColor.alpha == 255)) { r = _updateRect; r.inset(-1, -1); } else { r = getViewSize(); r.offset(-r.left, -r.top); } pContext->drawRect(r, backgroundColorDrawStyle); } // Custom stuff pContext->setFillColor(CColor(0, 0, 0, 0)); pContext->setLineWidth(frameWidth); pContext->setFrameColor(frameColor); CRect rect = getViewSize(); rect.offset(-rect.left, -rect.top); pContext->drawRect(rect); }
//----------------------------------------------------------------------------- void CGradientView::draw (CDrawContext* context) { if (path == 0) { CRect r = getViewSize (); r.inset (frameWidth / 2., frameWidth / 2.); path = owned (context->createRoundRectGraphicsPath (r, roundRectRadius)); } if (path && gradient) { context->setDrawMode (drawAntialiased ? kAntiAliasing : kAliasing); if (gradientStyle == kLinearGradient) { CPoint colorStartPoint (0, 0); colorStartPoint.x = getViewSize ().left + getViewSize ().getWidth () / 2 + cos (radians (gradientAngle-90)) * getViewSize ().getWidth () / 2; colorStartPoint.y = getViewSize ().top + getViewSize ().getHeight () / 2 + sin (radians (gradientAngle-90)) * getViewSize ().getHeight () / 2; CPoint colorEndPoint (0, getViewSize ().getHeight ()); colorEndPoint.x = getViewSize ().left + getViewSize ().getWidth () / 2 + cos (radians (gradientAngle+90)) * getViewSize ().getWidth () / 2; colorEndPoint.y = getViewSize ().top + getViewSize ().getHeight () / 2 + sin (radians (gradientAngle+90)) * getViewSize ().getHeight () / 2; context->fillLinearGradient (path, *gradient, colorStartPoint, colorEndPoint, false); } else { CPoint center (radialCenter); center.x *= getViewSize ().getWidth (); center.y *= getViewSize ().getHeight (); center.offset (getViewSize ().left, getViewSize ().top); context->fillRadialGradient (path, *gradient, center, radialRadius * std::max (getViewSize ().getWidth (), getViewSize ().getHeight ())); } if (frameColor.alpha != 0 && frameWidth > 0.) { context->setDrawMode (drawAntialiased ? kAntiAliasing : kAliasing); context->setFrameColor (frameColor); context->setLineWidth (frameWidth); context->setLineStyle (kLineSolid); context->drawGraphicsPath (path, CDrawContext::kPathStroked); } } }
//------------------------------------------------------------------------ bool CCheckBox::getFocusPath (CGraphicsPath& outPath) { if (wantsFocus ()) { CCoord focusWidth = getFrame ()->getFocusWidth (); CRect checkBoxSize (getViewSize ()); if (getDrawBackground ()) { checkBoxSize.setWidth (getDrawBackground ()->getWidth ()); checkBoxSize.setHeight (getDrawBackground ()->getHeight () / 6); } else { checkBoxSize.setHeight (getFontCapHeight (font) + 2); checkBoxSize.setWidth (checkBoxSize.getHeight ()); checkBoxSize.offset (1, ceil ((getViewSize ().getHeight () - checkBoxSize.getHeight ()) / 2)); } outPath.addRect (checkBoxSize); checkBoxSize.inset (-focusWidth, -focusWidth); outPath.addRect (checkBoxSize); } return true; }
//---------------------------------------------------------------------------------------------------- void UIEditView::drawRect (CDrawContext *pContext, const CRect& updateRect) { // disable focus drawing bool focusDrawing = getFrame ()->focusDrawingEnabled (); if (!editing && focusDrawing) getFrame ()->setFocusDrawingEnabled (false); CViewContainer::drawRect (pContext, updateRect); if (!editing && focusDrawing) getFrame ()->setFocusDrawingEnabled (focusDrawing); CRect oldClip = pContext->getClipRect (oldClip); CRect newClip (updateRect); newClip.offset (-getViewSize ().left, -getViewSize ().top); pContext->setClipRect (updateRect); CCoord save[4]; modifyDrawContext (save, pContext); const CCoord dashLength[] = {5, 5}; const CLineStyle lineDash (CLineStyle::kLineCapButt, CLineStyle::kLineJoinMiter, 0, 2, dashLength); pContext->setLineStyle (lineDash); pContext->setLineWidth (1); pContext->setDrawMode (kAliasing); pContext->setFrameColor (kBlueCColor); pContext->drawRect (CRect (0, 0, getWidth(), getHeight()), kDrawStroked); if (editing) { if (lines) lines->draw (pContext); pContext->setDrawMode (kAntiAliasing); if (highlightView) { CRect r = UISelection::getGlobalViewCoordinates (highlightView); CPoint p; frameToLocal (p); r.offset (p.x, p.y); r.inset (2, 2); pContext->setFrameColor (viewHighlightColor); pContext->setLineStyle (kLineSolid); pContext->setLineWidth (3); pContext->drawRect (r); } if (getSelection ()->total () > 0) { pContext->setDrawMode (kAliasing); pContext->setFrameColor (viewSelectionColor); pContext->setLineStyle (kLineSolid); pContext->setLineWidth (1); FOREACH_IN_SELECTION(getSelection (), view) CRect vs = getSelection ()->getGlobalViewCoordinates (view); CPoint p; frameToLocal (p); vs.offset (p.x, p.y); pContext->drawRect (vs); FOREACH_IN_SELECTION_END } }
//------------------------------------------------------------------------ void CCheckBox::draw (CDrawContext* context) { float norm = getValueNormalized (); CRect checkBoxSize (getViewSize ()); if (getDrawBackground ()) { CPoint off; checkBoxSize.setWidth (getDrawBackground ()->getWidth ()); checkBoxSize.setHeight (getDrawBackground ()->getHeight () / 6); if (norm == 0.5) off.y = checkBoxSize.getHeight (); else if (norm > 0.5) off.y = checkBoxSize.getHeight () * 2; else off.y = 0; if (hilight) off.y += getDrawBackground ()->getHeight () / 2; getDrawBackground ()->draw (context, checkBoxSize, off); } else { checkBoxSize.setHeight (getFontCapHeight (font) + 2); checkBoxSize.setWidth (checkBoxSize.getHeight ()); checkBoxSize.offset (1, ceil ((getViewSize ().getHeight () - checkBoxSize.getHeight ()) / 2)); checkBoxSize.makeIntegral (); context->setLineWidth (1); context->setLineStyle (kLineSolid); context->setDrawMode (kAliasing); context->setFrameColor (boxFrameColor); context->setFillColor (boxFillColor); context->drawRect (checkBoxSize, kDrawFilledAndStroked); if (hilight) { CColor hilightColor = boxFrameColor; hilightColor.alpha /= 2; context->setFrameColor (hilightColor); CRect r (checkBoxSize); r.inset (1, 1); context->drawRect (r, kDrawStroked); } context->setDrawMode (kAntiAliasing); context->setFrameColor (checkMarkColor); context->setLineWidth (2); const CCoord cbInset = 2; if (style & kDrawCrossBox) { if (norm == 0.5f) { context->moveTo (CPoint (checkBoxSize.left + cbInset, checkBoxSize.top + checkBoxSize.getHeight () / 2)); context->lineTo (CPoint (checkBoxSize.right - cbInset, checkBoxSize.top + checkBoxSize.getHeight () / 2)); } else if (norm > 0.5f) { context->moveTo (CPoint (checkBoxSize.left + cbInset, checkBoxSize.top + cbInset)); context->lineTo (CPoint (checkBoxSize.right - cbInset, checkBoxSize.bottom - cbInset)); context->moveTo (CPoint (checkBoxSize.left + cbInset, checkBoxSize.bottom - cbInset)); context->lineTo (CPoint (checkBoxSize.right - cbInset, checkBoxSize.top + cbInset)); } } else { context->moveTo (CPoint (checkBoxSize.left + cbInset, checkBoxSize.top + checkBoxSize.getHeight () / 2)); if (norm == 0.5f) { context->lineTo (CPoint (checkBoxSize.right - cbInset, checkBoxSize.top + checkBoxSize.getHeight () / 2)); } else if (norm > 0.5f) { context->lineTo (CPoint (checkBoxSize.left + checkBoxSize.getWidth () / 2, checkBoxSize.bottom - cbInset)); context->lineTo (CPoint (checkBoxSize.right + 1, checkBoxSize.top - 1)); } } } if (title) { CPoint p (checkBoxSize.getBottomRight ()); p.offset (kCheckBoxTitleMargin, -1); context->setFont (font); context->setFontColor (fontColor); context->drawString (title, p, true); } setDirty (false); }
//------------------------------------------------------------------------ void CSlider::draw (CDrawContext *pContext) { CDrawContext* drawContext = pContext; // draw background if (getDrawBackground ()) { CRect rect (0, 0, widthControl, heightControl); rect.offset (getViewSize ().left, getViewSize ().top); getDrawBackground ()->draw (drawContext, rect, offset); } if (drawStyle != 0) { CRect r (getViewSize ()); pContext->setDrawMode (kAliasing); pContext->setLineStyle (kLineSolid); pContext->setLineWidth (1.); if (drawStyle & kDrawFrame || drawStyle & kDrawBack) { pContext->setFrameColor (frameColor); pContext->setFillColor (backColor); CDrawStyle d = kDrawFilled; if (drawStyle & kDrawFrame && drawStyle & kDrawBack) d = kDrawFilledAndStroked; else if (drawStyle & kDrawFrame) d = kDrawStroked; pContext->drawRect (r, d); } pContext->setDrawMode (kAliasing); if (drawStyle & kDrawValue) { if (drawStyle & kDrawFrame) r.inset (1., 1.); float drawValue = getValueNormalized (); if (drawStyle & kDrawValueFromCenter) { if (drawStyle & kDrawInverted) drawValue = 1.f - drawValue; if (getStyle () & kHorizontal) { CCoord width = r.getWidth (); r.right = r.left + r.getWidth () * drawValue; r.left += width / 2.; r.normalize (); } else { CCoord height = r.getHeight (); r.bottom = r.top + r.getHeight () * drawValue; r.top += height / 2.; r.normalize (); } } else { if (getStyle () & kHorizontal) { if (drawStyle & kDrawInverted) r.left = r.right - r.getWidth () * drawValue; else r.right = r.left + r.getWidth () * drawValue; } else { if (drawStyle & kDrawInverted) r.bottom = r.top + r.getHeight () * drawValue; else r.top = r.bottom - r.getHeight () * drawValue; } } r.normalize (); if (r.getWidth () >= 0.5 && r.getHeight () >= 0.5) { pContext->setFillColor (valueColor); pContext->drawRect (r, kDrawFilled); } } } if (pHandle) { float normValue = getValueNormalized (); if (style & kRight || style & kBottom) normValue = 1.f - normValue; // calc new coords of slider CRect rectNew; if (style & kHorizontal) { rectNew.top = offsetHandle.y; rectNew.bottom = rectNew.top + heightOfSlider; rectNew.left = offsetHandle.x + floor (normValue * rangeHandle); rectNew.left = (rectNew.left < minTmp) ? minTmp : rectNew.left; rectNew.right = rectNew.left + widthOfSlider; rectNew.right = (rectNew.right > maxTmp) ? maxTmp : rectNew.right; } else { rectNew.left = offsetHandle.x; rectNew.right = rectNew.left + widthOfSlider; rectNew.top = offsetHandle.y + floor (normValue * rangeHandle); rectNew.top = (rectNew.top < minTmp) ? minTmp : rectNew.top; rectNew.bottom = rectNew.top + heightOfSlider; rectNew.bottom = (rectNew.bottom > maxTmp) ? maxTmp : rectNew.bottom; } rectNew.offset (getViewSize ().left, getViewSize ().top); // draw slider at new position pHandle->draw (drawContext, rectNew); } setDirty (false); }
//------------------------------------------------------------------------ void CTextButton::draw (CDrawContext* context) { bool highlight = value > 0.5 ? true : false; context->setDrawMode (kAntiAliasing); context->setLineWidth (frameWidth); context->setLineStyle (CLineStyle (CLineStyle::kLineCapRound, CLineStyle::kLineJoinRound)); context->setFrameColor (highlight ? frameColorHighlighted : frameColor); CRect r (getViewSize ()); r.inset (frameWidth / 2., frameWidth / 2.); CGraphicsPath* path = getPath (context); if (path) { CColor color1 = highlight ? gradientStartColorHighlighted : gradientStartColor; CColor color2 = highlight ? gradientEndColorHighlighted : gradientEndColor; CGradient* gradient = path->createGradient (0.2, 1, color1, color2); if (gradient) { context->fillLinearGradient (path, *gradient, r.getTopLeft (), r.getBottomLeft (), false); gradient->forget (); } else { context->setFillColor (highlight ? gradientStartColorHighlighted : gradientStartColor); context->drawGraphicsPath (path, CDrawContext::kPathFilled); } context->drawGraphicsPath (path, CDrawContext::kPathStroked); } else { context->setFillColor (highlight ? gradientStartColorHighlighted : gradientStartColor); context->drawRect (getViewSize (), kDrawFilledAndStroked); } CRect titleRect = getViewSize (); titleRect.inset (frameWidth / 2., frameWidth / 2.); CBitmap* iconToDraw = highlight ? (iconHighlighted ? iconHighlighted : icon) : (icon ? icon : iconHighlighted); if (iconToDraw) { CRect iconRect (0, 0, iconToDraw->getWidth (), iconToDraw->getHeight ()); iconRect.offset (titleRect.left, titleRect.top); switch (iconPosition) { case kLeft: { iconRect.offset (textMargin, titleRect.getHeight () / 2. - iconRect.getHeight () / 2.); titleRect.left = iconRect.right; titleRect.right -= textMargin; if (getTextAlignment () == kLeftText) titleRect.left += textMargin; break; } case kRight: { iconRect.offset (titleRect.getWidth () - (textMargin + iconRect.getWidth ()), titleRect.getHeight () / 2. - iconRect.getHeight () / 2.); titleRect.right = iconRect.left; titleRect.left += textMargin; if (getTextAlignment () == kRightText) titleRect.right -= textMargin; break; } case kCenterAbove: { iconRect.offset (titleRect.getWidth () / 2. - iconRect.getWidth () / 2., 0); if (title.size () > 0) { iconRect.offset (0, titleRect.getHeight () / 2. - (iconRect.getHeight () / 2. + (textMargin + font->getSize ()) / 2.)); titleRect.top = iconRect.bottom + textMargin; titleRect.setHeight (font->getSize ()); if (getTextAlignment () == kLeftText) titleRect.left += textMargin; else if (getTextAlignment () == kRightText) titleRect.right -= textMargin; } else { iconRect.offset (0, titleRect.getHeight () / 2. - iconRect.getHeight () / 2.); } break; } case kCenterBelow: { iconRect.offset (titleRect.getWidth () / 2. - iconRect.getWidth () / 2., 0); if (title.size () > 0) { iconRect.offset (0, titleRect.getHeight () / 2. - (iconRect.getHeight () / 2.) + (textMargin + font->getSize ()) / 2.); titleRect.top = iconRect.top - (textMargin + font->getSize ()); titleRect.setHeight (font->getSize ()); if (getTextAlignment () == kLeftText) titleRect.left += textMargin; else if (getTextAlignment () == kRightText) titleRect.right -= textMargin; } else { iconRect.offset (0, titleRect.getHeight () / 2. - iconRect.getHeight () / 2.); } break; } } context->drawBitmap (iconToDraw, iconRect); } else { if (getTextAlignment () == kLeftText) titleRect.left += textMargin; else if (getTextAlignment () == kRightText) titleRect.right -= textMargin; } if (title.size () > 0) { context->setFont (font); context->setFontColor (highlight ? textColorHighlighted : textColor); context->drawString (title.c_str (), titleRect, horiTxtAlign); } setDirty (false); }
//---------------------------------------------------------------------------------------------------- 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 ()); } } }