void drawPopupMenuItem (Graphics& g, const Rectangle<int>& area, const bool isSeparator, const bool isActive, const bool isHighlighted, const bool isTicked, const bool hasSubMenu, const String& text, const String& shortcutKeyText, const Drawable* icon, const Colour* const textColourToUse) { Rectangle<int> r(area.reduced(1)); if(isHighlighted) { g.setColour(Env::getColorTxt()); g.fillRect(r); g.setColour(Env::getColorBg()); } else { g.setColour(Env::getColorTxt()); } g.setFont(Env::getFont()); Rectangle<float> iconArea(r.removeFromRight((r.getHeight() * 5) / 4).reduced(3).toFloat()); if(isTicked) { const Path tick (getTickShape (1.0f)); g.fillPath(tick, tick.getTransformToScaleToFit (iconArea, true)); } g.drawFittedText(text, 4, 1, area.getWidth() - 4, area.getHeight() - 1, Justification::centredLeft, 1); }
void ProjucerLookAndFeel::drawToggleButton (Graphics& g, ToggleButton& button, bool isMouseOverButton, bool isButtonDown) { ignoreUnused (isMouseOverButton, isButtonDown); if (! button.isEnabled()) g.setOpacity (0.5f); bool isTextEmpty = button.getButtonText().isEmpty(); bool isPropertyComponentChild = (dynamic_cast<BooleanPropertyComponent*> (button.getParentComponent()) != nullptr); auto bounds = button.getLocalBounds(); auto sideLength = isPropertyComponentChild ? 25 : bounds.getHeight(); auto rectBounds = isTextEmpty ? bounds : bounds.removeFromLeft (jmin (sideLength, bounds.getWidth() / 3)); rectBounds = rectBounds.withSizeKeepingCentre (sideLength, sideLength).reduced (4); g.setColour (button.findColour (ToggleButton::tickDisabledColourId)); g.drawRoundedRectangle (rectBounds.toFloat(), 2.0f, 1.0f); if (button.getToggleState()) { g.setColour (button.findColour (ToggleButton::tickColourId)); const auto tick = getTickShape (0.75f); g.fillPath (tick, tick.getTransformToScaleToFit (rectBounds.reduced (2).toFloat(), false)); } if (! isTextEmpty) { bounds.removeFromLeft (5); const auto fontSize = jmin (15.0f, button.getHeight() * 0.75f); g.setFont (fontSize); g.setColour (isPropertyComponentChild ? findColour (widgetTextColourId) : button.findColour (ToggleButton::textColourId)); g.drawFittedText (button.getButtonText(), bounds, Justification::centredLeft, 2); } }
void CtrlrMenuBarLookAndFeel::drawPopupMenuItem (Graphics &g, const Rectangle<int>& area, bool isSeparator, bool isActive, bool isHighlighted, bool isTicked, bool hasSubMenu, const String& text, const String& shortcutKeyText, const Drawable* icon, const Colour* textColourToUse) { const float halfH = area.getHeight() * 0.5f; if (isSeparator) { const float separatorIndent = 5.5f; g.setColour (getColour (Ids::ctrlrMenuItemSeparatorColour)); g.fillRect (separatorIndent, halfH, area.getWidth() - (separatorIndent*2), 1.25f); } else { Colour textColour (getColour (Ids::ctrlrMenuItemTextColour)); if (isHighlighted) { drawSelectionRectangle (g, area.getWidth(), area.getHeight(), getColour (Ids::ctrlrMenuItemHighlightColour)); g.setColour (getColour (Ids::ctrlrMenuItemHighlightedTextColour)); } else { g.setColour (getColour (Ids::ctrlrMenuItemTextColour)); } if (! isActive) g.setOpacity (0.3f); Font font (getPopupMenuFont()); if (font.getHeight() > area.getHeight() / 1.3f) font.setHeight (area.getHeight() / 1.3f); g.setFont (font); const int leftBorder = (area.getHeight() * 5) / 4; const int rightBorder = 4; if (icon != nullptr) { icon->drawWithin (g, Rectangle<float> (2.0f, 1.0f, leftBorder - 4.0f, area.getHeight() - 2.0f), RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, 1.0f); } else if (isTicked) { const Path tick (getTickShape (1.0f)); const float th = font.getAscent(); const float ty = halfH - th * 0.5f; g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4), th, true)); } g.drawFittedText (text, leftBorder, 0, area.getWidth() - (leftBorder + rightBorder), area.getHeight(), Justification::centredLeft, 1); if (shortcutKeyText.isNotEmpty()) { Font f2 (font); f2.setHeight (f2.getHeight() * 0.75f); f2.setHorizontalScale (0.95f); g.setFont (f2); g.drawText (shortcutKeyText, leftBorder, 0, area.getWidth() - (leftBorder + rightBorder + 4), area.getHeight(), Justification::centredRight, true); } if (hasSubMenu) { const float arrowH = 0.6f * getPopupMenuFont().getAscent(); const float x = area.getWidth() - area.getHeight() * 0.6f; Path p; p.addTriangle (x, halfH - arrowH * 0.5f, x, halfH + arrowH * 0.5f, x + arrowH * 0.6f, halfH); g.fillPath (p); } } }
//======== drawPopupMenuItem ====================================================================== void CabbageIDELookAndFeel::drawPopupMenuItem (Graphics& g, const Rectangle<int>& area, const bool isSeparator, const bool isActive, const bool isHighlighted, const bool isTicked, const bool hasSubMenu, const String& text, const String& shortcutKeyText, const Drawable* icon, const Colour* const textColourToUse) { if (isSeparator) { Rectangle<int> r (area.reduced (5, 0)); r.removeFromTop (r.getHeight() / 2 - 1); g.setColour (Colour (0x33000000)); g.fillRect (r.removeFromTop (1)); g.setColour (Colour (0x66ffffff)); g.fillRect (r.removeFromTop (1)); } else { Colour textColour (CabbageSettings::getColourFromValueTree (colourTree, CabbageColourIds::popupMenuText, Colours::white)); if (textColourToUse != nullptr) textColour = *textColourToUse; Rectangle<int> r (area.reduced (1)); if (isHighlighted) { g.setColour (CabbageSettings::getColourFromValueTree (colourTree, CabbageColourIds::popupMenuMouseOverBackground, Colours::grey)); g.fillRect (r); g.setColour (CabbageSettings::getColourFromValueTree (colourTree, CabbageColourIds::popupMenuHighlightedText, Colours::grey)); } else { g.setColour (textColour); } if (! isActive) g.setOpacity (0.3f); Font font (getPopupMenuFont()); const float maxFontHeight = area.getHeight() / 1.4f; if (font.getHeight() > maxFontHeight) font.setHeight (maxFontHeight); g.setFont (font); Rectangle<float> iconArea (r.removeFromLeft ((r.getHeight() * 3/*5*/) / 4).reduced (3).toFloat()); if (icon != nullptr) { icon->drawWithin (g, iconArea, RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, 1.0f); } else if (isTicked) { const Path tick (getTickShape (1.0f)); g.fillPath (tick, tick.getTransformToScaleToFit (iconArea, true)); } if (hasSubMenu) { const float arrowH = 0.6f * getPopupMenuFont().getAscent(); const float x = (float) r.removeFromRight ((int) arrowH).getX(); const float halfH = (float) r.getCentreY(); Path p; p.addTriangle (x, halfH - arrowH * 0.5f, x, halfH + arrowH * 0.5f, x + arrowH * 0.6f, halfH); g.fillPath (p); } r.removeFromRight (3); g.drawFittedText (text, r, Justification::centredLeft, 1); if (shortcutKeyText.isNotEmpty()) { Font f2 (font); f2.setHeight (f2.getHeight() * 0.75f); f2.setHorizontalScale (0.95f); g.setFont (f2); g.drawText (shortcutKeyText, r, Justification::centredRight, true); } } }