//----------------------------------------------------------------------------- CGraphicsPath* CDrawContext::createRoundRectGraphicsPath (const CRect& size, CCoord radius) { CGraphicsPath* path = createGraphicsPath (); if (path) { path->addRoundRect (size, radius); } return path; }
//----------------------------------------------------------------------------- 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; }
//------------------------------------------------------------------------ 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; }
//----------------------------------------------------------------------------- void D2DDrawContext::drawArc (const CRect& _rect, const float _startAngle, const float _endAngle, const CDrawStyle drawStyle) { CGraphicsPath* path = createGraphicsPath (); if (path) { path->addArc (_rect, _startAngle, _endAngle, false); if (drawStyle == kDrawFilled || drawStyle == kDrawFilledAndStroked) drawGraphicsPath (path, kPathFilled); if (drawStyle == kDrawStroked || drawStyle == kDrawFilledAndStroked) drawGraphicsPath (path, kPathStroked); path->forget (); } }
//------------------------------------------------------------------------ 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 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); }
//------------------------------------------------------------------------ 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); }