WE Core
Loading...
Searching...
No Matches
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 #if TARGET_OS_IPHONE
92 _defaultString += "iOS";
93 #else
94 _defaultString += "macOS";
95 #endif
96#elif __linux__
97 _defaultString += "Linux";
98#else
99 #error "Unknown OS"
100#endif
101
102 // Arch
103 _defaultString += " ";
104#if defined(__x86_64__) || defined(_M_AMD64)
105 _defaultString += "x86_64";
106#elif defined(__aarch64__) || defined(_M_ARM64)
107 _defaultString += "arm64";
108#else
109 #error "Unknown arch"
110#endif
111
112 // Demo
113 if (isDemo) {
114 _defaultString += " (DEMO)";
115 }
116
117 _targetLabel->setText(_defaultString, juce::dontSendNotification);
118 }
119
120 void TooltipLabelUpdater::mouseEnter(const juce::MouseEvent& event) {
121 if (_targetLabel != nullptr) {
122 juce::TooltipClient* tooltipClient = dynamic_cast<juce::TooltipClient*>(event.eventComponent);
123
124 if (tooltipClient != nullptr) {
125 const juce::String displayString = tooltipClient->getTooltip().isEmpty() ? _defaultString : tooltipClient->getTooltip();
126 _targetLabel->setText(displayString, juce::dontSendNotification);
127 }
128 }
129 }
130
131 void TooltipLabelUpdater::mouseExit(const juce::MouseEvent& /*event*/) {
132 if (_targetLabel != nullptr) {
133 _targetLabel->setText(_defaultString, juce::dontSendNotification);
134 }
135 }
136
137 void TooltipLabelUpdater::refreshTooltip(juce::Component* component) {
138 if (_targetLabel != nullptr) {
139 juce::TooltipClient* tooltipClient = dynamic_cast<juce::TooltipClient*>(component);
140
141 if (tooltipClient != nullptr) {
142 const juce::String displayString = tooltipClient->getTooltip().isEmpty() ? _defaultString : tooltipClient->getTooltip();
143 _targetLabel->setText(displayString, juce::dontSendNotification);
144 }
145 }
146 }
147}
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)