-
Notifications
You must be signed in to change notification settings - Fork 1
/
PatchButton.h
98 lines (80 loc) · 3.63 KB
/
PatchButton.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* MIT License
*
* Copyright (c) 2019-2023 Christof Ruch
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
#include <juce_gui_basics/juce_gui_basics.h>
#include "Thumbnail.h"
#include "LambdaValueListener.h"
class PatchButton : public juce::Component, private juce::TextButton::Listener {
public:
PatchButton(int id, bool isToggle, std::function<void(int)> clickHandler);
void setActive(bool active);
virtual void resized() override;
// virtual void paint(Graphics& g) override;
void setPatchColour(int colourId, juce::Colour newColour);
void bindColour(int colourId, juce::Value colourValue);
juce::String getButtonText() const;
void setButtonData(const juce::String &text);
void setButtonDragInfo(const juce::String &dragInfo);
void bindButtonData(juce::Value textValue);
void setSubtitle(const juce::String &text);
void bindSubtitle(juce::Value textValue);
void setFavorite(bool isFavorite);
void bindFavorite(juce::Value isFavorite);
void setHidden(bool isHidden);
void bindHidden(juce::Value isHidden);
void setThumbnailFile(const juce::String &filename, const juce::String &cacheFileName);
void setThumbnailFromCache(const Thumbnail::CacheInfo &cacheInfo);
void clearThumbnailFile();
void setToggleState(bool state);
bool getToggleState() const;
virtual void buttonClicked(juce::Button *) override;
// This is required when using the PatchButton with a scrollable list model, which reuses the buttons
void updateId(int id);
private:
std::function<void(int)> clicked_;
std::unique_ptr<juce::TextButton> button_;
Thumbnail thumbnail_;
juce::ImageComponent favoriteIcon_;
juce::ImageComponent hiddenIcon_;
juce::Label synthName_;
int id_;
bool active_;
std::unique_ptr<LambdaValueListener> titleListener_;
std::unique_ptr<LambdaValueListener> subtitleListener_;
std::unique_ptr<LambdaValueListener> colourListener_;
std::unique_ptr<LambdaValueListener> favoriteListener_;
std::unique_ptr<LambdaValueListener> hiddenListener_;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PatchButton)
};
class PatchButtonWithDropTarget : public PatchButton, public juce::DragAndDropTarget {
public:
using PatchButton::PatchButton;
typedef std::function<bool(juce::var)> TAcceptHandler;
typedef std::function<void(juce::var)> TDropHandler;
TAcceptHandler acceptsItem;
TDropHandler onItemDropped;
// DragAndDropTarget implementation
bool isInterestedInDragSource(const SourceDetails &dragSourceDetails) override;
void itemDropped(const SourceDetails &dragSourceDetails) override;
};