WE Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PopupMenuV2.h
Go to the documentation of this file.
1/*
2 * File: PopupMenuV2.h
3 *
4 * Version: 1.0.0
5 *
6 * Created: 19/03/2019
7 *
8 * This file is part of WECore.
9 *
10 * WECore is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * WECore is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with WECore. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25#pragma once
26
27#include "../JuceLibraryCode/JuceHeader.h"
28
30
39 template <typename BASE>
40 class PopupMenuV2 : public BASE {
41
42 public:
43 PopupMenuV2() : _popupMenuFontName("Courier New") {}
44 virtual ~PopupMenuV2() = default;
45
47 inline virtual void drawPopupMenuItem(juce::Graphics& g,
48 const juce::Rectangle<int>& area,
49 bool isSeparator,
50 bool isActive,
51 bool isHighlighted,
52 bool isTicked,
53 bool hasSubMenu,
54 const juce::String& text,
55 const juce::String& shortcutKeyText,
56 const juce::Drawable* icon,
57 const juce::Colour* textColour) override;
58
59 inline virtual juce::Font getPopupMenuFont() override;
62 void setPopupMenuFontName(const char* fontName) { _popupMenuFontName = fontName; }
63
64 private:
65 const char* _popupMenuFontName;
66 };
67
68 template <typename BASE>
70 const juce::Rectangle<int>& area,
71 bool /*isSeparator*/,
72 bool /*isActive*/,
73 bool isHighlighted,
74 bool isTicked,
75 bool /*hasSubMenu*/,
76 const juce::String& text,
77 const juce::String& /*shortcutKeyText*/,
78 const juce::Drawable* /*icon*/,
79 const juce::Colour* /*textColour*/) {
80
81 juce::Rectangle<int> r = area.reduced(1);
82
83 if (isHighlighted) {
84 g.setColour(BASE::findColour(juce::PopupMenu::highlightedBackgroundColourId));
85 g.fillRect(r);
86
87 g.setColour(BASE::findColour(juce::PopupMenu::highlightedTextColourId));
88 } else if (isTicked) {
89 g.setColour(BASE::findColour(juce::PopupMenu::highlightedBackgroundColourId).withAlpha(0.2f));
90 g.fillRect(r);
91
92 g.setColour(BASE::findColour(juce::PopupMenu::textColourId));
93 } else {
94 g.setColour(BASE::findColour(juce::PopupMenu::textColourId));
95 }
96
97 juce::Font font(getPopupMenuFont());
98
99 const float maxFontHeight {area.getHeight() / 1.3f};
100
101 if (font.getHeight() > maxFontHeight) {
102 font.setHeight(maxFontHeight);
103 }
104
105 g.setFont(font);
106
107 r.removeFromLeft(3);
108 g.drawFittedText(text, r, juce::Justification::centredLeft, 1);
109 }
110
111 template <typename BASE>
113 juce::Font comboFont;
114 comboFont.setTypefaceName(_popupMenuFontName);
115 return comboFont;
116 }
117}
void setPopupMenuFontName(const char *fontName)
Definition PopupMenuV2.h:62
virtual void drawPopupMenuItem(juce::Graphics &g, const juce::Rectangle< int > &area, bool isSeparator, bool isActive, bool isHighlighted, bool isTicked, bool hasSubMenu, const juce::String &text, const juce::String &shortcutKeyText, const juce::Drawable *icon, const juce::Colour *textColour) override
Definition PopupMenuV2.h:69
virtual juce::Font getPopupMenuFont() override