void CtrlrMenuBarLookAndFeel::getIdealPopupMenuItemSize (const String &text, bool isSeparator, int standardMenuItemHeight, int &idealWidth, int &idealHeight) { if (isSeparator) { idealWidth = 50; idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10; } else { Font font (getPopupMenuFont()); if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f) font.setHeight (standardMenuItemHeight / 1.3f); idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f); idealWidth = font.getStringWidth (text) + idealHeight * 2; } }
void MyLookAndFeel::getIdealPopupMenuItemSize(const String& text, const bool isSeparator, int standardMenuItemHeight, int& idealWidth, int& idealHeight) { if (isSeparator) { idealWidth = 50; idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10; } else { Font font (getPopupMenuFont()); idealHeight = roundFloatToInt (font.getHeight() * 1.3f); idealWidth = font.getStringWidth (text) + idealHeight * 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); } } }