Krotos Modules 3
Loading...
Searching...
No Matches
DropComponent.cpp
Go to the documentation of this file.
1#include "DropComponent.h"
2
3namespace krotos
4{
5 const Identifier DropComponent::DragSource{"DropComponent"};
6
8 DropComponent::DropComponent(const String& labelText, const String& kwidgetID)
9 : Button(labelText), m_connectedKwidgetID(kwidgetID)
10 {
11 setComponentID(labelText);
12
13 m_label.setText(labelText, dontSendNotification);
14 m_label.setJustificationType(Justification::centred);
15 m_label.setInterceptsMouseClicks(false, false);
16 m_label.setFont(m_label.getFont().withHeight(15.0f));
17 }
18
19 void DropComponent::resized() { m_label.setBounds(getLocalBounds()); }
20
22 Label& DropComponent::getLabel() { return m_label; }
23
24 void DropComponent::setText(const String& labelText)
25 {
26 m_label.setText(labelText, dontSendNotification);
27 repaint();
28 }
29
31 {
32 m_labelValue.referTo(value);
33 m_labelValue.addListener(this);
34 m_label.setText(value.getValue().toString(), NotificationType::dontSendNotification);
35 repaint();
36 }
37
38 void DropComponent::paintButton(Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
39 {
40 const Colour dragOverOver(findColour(LassoComponent<TabbedComponent>::lassoOutlineColourId));
41 auto armedColour = findColour(LassoComponent<TabbedComponent>::lassoFillColourId);
42 auto bgColour = m_armed ? armedColour : findColour(ListBox::ColourIds::backgroundColourId);
43 auto buttonBounds = getLocalBounds().toFloat();
44 const float cornerSize = m_cornerSize;
45
46 const float hoverBrightness = m_armed ? m_armedHoverBrightnessAmount : m_hoverBrightnessAmount;
47
48 bgColour = m_somethingIsBeingDraggedOver ? dragOverOver
49 : shouldDrawButtonAsDown || shouldDrawButtonAsHighlighted ? bgColour.brighter(hoverBrightness)
50 : bgColour;
51 g.setColour(bgColour);
52
54 {
55 g.fillRoundedRectangle(buttonBounds, cornerSize);
56 }
58 {
59 g.fillAll();
60 }
61 else
62 {
63 Path p;
64 p.addRoundedRectangle(
65 buttonBounds.getX(), buttonBounds.getY(), buttonBounds.getWidth(), buttonBounds.getHeight(),
66 cornerSize, cornerSize,
71
72 g.fillPath(p);
73 }
74
75 // Draw label here as it's better suited for handling the various drag / mouse hover states
76 g.setFont(m_label.getFont());
77 g.setColour(findColour(Label::ColourIds::textColourId));
78 g.setOpacity(m_somethingIsBeingDraggedOver || m_armed || shouldDrawButtonAsHighlighted ? m_hoverOpacity
80 g.drawFittedText(m_label.getText(), m_label.getBounds(), m_label.getJustificationType(), 1, 1.0f);
81 }
82
83 bool DropComponent::isInterestedInDragSource(const SourceDetails& dragSourceDetails)
84 {
86 return !dragSourceDetails.sourceComponent->getProperties()[DropComponent::DragSource].isVoid();
87 }
88
89 void DropComponent::itemDragEnter(const SourceDetails& /*dragSourceDetails*/)
90 {
92 repaint();
93 }
94
95 void DropComponent::itemDragMove(const SourceDetails& /*dragSourceDetails*/) {}
96
97 void DropComponent::itemDragExit(const SourceDetails& /*dragSourceDetails*/)
98 {
100 repaint();
101 }
102
103 void DropComponent::itemDropped(const SourceDetails& dragSourceDetails)
104 {
105 auto sourceComponent = dragSourceDetails.sourceComponent;
106 m_lastDesc = dragSourceDetails.description;
108
109 if (onDropped)
110 {
111 onDropped(dragSourceDetails.description);
112 }
113
114 repaint();
115 }
116
117 /* Returns the last drag and drop description this component receieved */
119
121 {
122 m_label.setText(value.toString(), NotificationType::dontSendNotification);
123 }
124
125 void DropComponent::setArmed(bool isArmed)
126 {
127 m_armed = isArmed;
128 repaint();
129 }
130} // namespace krotos
const float m_hoverOpacity
Definition DropComponent.h:120
void itemDragMove(const SourceDetails &) override
Definition DropComponent.cpp:95
bool m_somethingIsBeingDraggedOver
Definition DropComponent.h:109
Label m_label
Definition DropComponent.h:106
const float m_defaultOpacity
Definition DropComponent.h:120
std::function< void(var desc)> onDropped
Definition DropComponent.h:51
void itemDragExit(const SourceDetails &) override
Definition DropComponent.cpp:97
const float m_armedHoverBrightnessAmount
Definition DropComponent.h:121
void paintButton(Graphics &g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
Definition DropComponent.cpp:38
RoundedCorner m_cornerToRound
Definition DropComponent.h:115
Value m_labelValue
Definition DropComponent.h:113
@ BottomLeft
Definition DropComponent.h:70
@ BottomRight
Definition DropComponent.h:71
@ Top
Definition DropComponent.h:72
@ TopRight
Definition DropComponent.h:69
@ Bottom
Definition DropComponent.h:73
@ All
Definition DropComponent.h:74
@ TopLeft
Definition DropComponent.h:68
@ None
Definition DropComponent.h:75
void setArmed(bool isArmed)
Sets the component to draw with a visual indication that it has active modulation assigned to it.
Definition DropComponent.cpp:125
var m_lastDesc
Definition DropComponent.h:111
void resized() override
Definition DropComponent.cpp:19
bool isInterestedInDragSource(const SourceDetails &) override
Definition DropComponent.cpp:83
void setLabelValue(Value &labelValue)
Assign a Value object to the DropComponent Label text. This will assign a Listener to the given value...
Definition DropComponent.cpp:30
static const Identifier DragSource
Set this identifier in your drag source component properties so DropComponent will be interested in i...
Definition DropComponent.h:103
float m_cornerSize
Definition DropComponent.h:119
void itemDropped(const SourceDetails &dragSourceDetails) override
Definition DropComponent.cpp:103
void valueChanged(Value &value) override
Definition DropComponent.cpp:120
var getDescription()
Definition DropComponent.cpp:118
bool m_armed
Definition DropComponent.h:122
void setText(const String &labelText)
Definition DropComponent.cpp:24
void itemDragEnter(const SourceDetails &) override
Definition DropComponent.cpp:89
const float m_hoverBrightnessAmount
Definition DropComponent.h:120
DropComponent(const String &labelText, const String &kwidgetID="")
Definition DropComponent.cpp:8
Label & getLabel()
Definition DropComponent.cpp:22
Definition AirAbsorptionFilter.cpp:2