WE Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TooltipLabelUpdater.h
Go to the documentation of this file.
1/*
2 * File: TooltipLabelUpdater.h
3 *
4 * Version: 1.0.0
5 *
6 * Created: 06/06/2021
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
29namespace WECore::JUCEPlugin {
30
35 class TooltipLabelUpdater : public juce::MouseListener {
36 public:
37 inline TooltipLabelUpdater();
39
44 inline void start(juce::Label* targetLabel);
45
50 inline void start(juce::Label* targetLabel, juce::AudioProcessor::WrapperType pluginFormat, bool isDemo = false);
51
55 void stop() { _targetLabel = nullptr; }
56
57 inline virtual void mouseEnter(const juce::MouseEvent& event) override;
58 inline virtual void mouseExit(const juce::MouseEvent& event) override;
59
60 inline void refreshTooltip(juce::Component* component);
61
62 private:
63 juce::Label* _targetLabel;
64 juce::String _defaultString;
65 };
66
67 TooltipLabelUpdater::TooltipLabelUpdater() : _targetLabel(nullptr) {
68 }
69
70 void TooltipLabelUpdater::start(juce::Label* targetLabel) {
71 _targetLabel = targetLabel;
72 _defaultString = "";
73 }
74
75 void TooltipLabelUpdater::start(juce::Label* targetLabel, juce::AudioProcessor::WrapperType pluginFormat, bool isDemo) {
76 _targetLabel = targetLabel;
77
78 _defaultString = JucePlugin_Name;
79 _defaultString += " ";
80 _defaultString += JucePlugin_VersionString;
81
82 // Format
83 _defaultString += " ";
84 _defaultString += juce::AudioProcessor::getWrapperTypeDescription(pluginFormat);
85
86 // OS
87 _defaultString += " ";
88#if _WIN32
89 _defaultString += "Win";
90#elif __APPLE__
91 _defaultString += "macOS";
92#elif __linux__
93 _defaultString += "Linux";
94#else
95 #error "Unknown OS"
96#endif
97
98 // Arch
99 _defaultString += " ";
100#if defined(__x86_64__) || defined(_M_AMD64)
101 _defaultString += "x86_64";
102#elif defined(__aarch64__) || defined(_M_ARM64)
103 _defaultString += "arm64";
104#else
105 #error "Unknown arch"
106#endif
107
108 // Demo
109 if (isDemo) {
110 _defaultString += " (DEMO)";
111 }
112
113 _targetLabel->setText(_defaultString, juce::dontSendNotification);
114 }
115
116 void TooltipLabelUpdater::mouseEnter(const juce::MouseEvent& event) {
117 if (_targetLabel != nullptr) {
118 juce::TooltipClient* tooltipClient = dynamic_cast<juce::TooltipClient*>(event.eventComponent);
119
120 if (tooltipClient != nullptr) {
121 const juce::String displayString = tooltipClient->getTooltip().isEmpty() ? _defaultString : tooltipClient->getTooltip();
122 _targetLabel->setText(displayString, juce::dontSendNotification);
123 }
124 }
125 }
126
127 void TooltipLabelUpdater::mouseExit(const juce::MouseEvent& /*event*/) {
128 if (_targetLabel != nullptr) {
129 _targetLabel->setText(_defaultString, juce::dontSendNotification);
130 }
131 }
132
133 void TooltipLabelUpdater::refreshTooltip(juce::Component* component) {
134 if (_targetLabel != nullptr) {
135 juce::TooltipClient* tooltipClient = dynamic_cast<juce::TooltipClient*>(component);
136
137 if (tooltipClient != nullptr) {
138 const juce::String displayString = tooltipClient->getTooltip().isEmpty() ? _defaultString : tooltipClient->getTooltip();
139 _targetLabel->setText(displayString, juce::dontSendNotification);
140 }
141 }
142 }
143}
virtual void mouseExit(const juce::MouseEvent &event) override
void refreshTooltip(juce::Component *component)
virtual void mouseEnter(const juce::MouseEvent &event) override
void start(juce::Label *targetLabel)