Krotos Modules 3
Loading...
Searching...
No Matches
ModulationAssignerDropArea.cpp
Go to the documentation of this file.
2
3namespace krotos
4{
6 "SharedModeAssignPanel");
8 "SharedModeAssignPanel");
11
12 void ModulationAssignerDropArea::paint(Graphics& /*g*/) {}
13
15 {
16 Rectangle<int> bounds = getLocalBounds();
17 FlexBox flexBox;
18 // Default FlexBox settings
19 flexBox.flexDirection = FlexBox::Direction::row;
20 flexBox.flexWrap = FlexBox::Wrap::wrap;
21 flexBox.alignContent = FlexBox::AlignContent::stretch;
22 flexBox.alignItems = FlexBox::AlignItems::stretch;
23 flexBox.justifyContent = FlexBox::JustifyContent::flexStart;
24 std::vector<FlexBox> rows;
25
26 const FlexItem::Margin margin{m_margin};
27
28 // Add components to rows
29 for (auto& comp : m_dropComponents)
30 {
31 if (flexBox.items.size() >= m_maxPerRow)
32 {
33 rows.push_back(flexBox);
34 flexBox.items.clear();
35 }
36 flexBox.items.add(FlexItem(*comp).withMargin(margin).withFlex(1.0f));
37 }
38
39 for (auto& comp : m_multiDropComponents)
40 {
41 if (flexBox.items.size() >= m_maxPerRow)
42 {
43 rows.push_back(flexBox);
44 flexBox.items.clear();
45 }
46 flexBox.items.add(FlexItem(*comp).withMargin(margin).withFlex(1.0f));
47 }
48
49 // Add the last row if it's not empty
50 if (!flexBox.items.isEmpty())
51 {
52 rows.push_back(flexBox);
53 }
54
55 // Layout the rows
56 const int rowHeight = rows.size() > 0 ? bounds.getHeight() / (int)rows.size() : bounds.getHeight();
57 int y = bounds.getY();
58 // Horizontal split
59 if (m_singleRowColumn && rows.size() == 1)
60 {
61 rows[0].flexDirection = FlexBox::Direction::column;
62 }
63 for (auto& row : rows)
64 {
65 Rectangle<int> rowBounds = bounds.removeFromTop(rowHeight);
66 row.performLayout(rowBounds);
67 y += rowHeight;
68 }
69 }
70
72 {
73 m_dropComponents.add(newComp);
74 addAndMakeVisible(newComp);
75 newComp->setComponentID(ComponentIds::ModulationDropComponentID);
76 return newComp;
77 }
78
80 {
81 m_multiDropComponents.add(newComp);
82 addAndMakeVisible(newComp);
83 newComp->setComponentID(ComponentIds::ModulationMultiDropComponentID);
84 return newComp;
85 }
86
87 DropComponent* ModulationAssignerDropArea::findDropComponent(const String& kwidgetID, int modSourceID)
88 {
89 for (auto& dropComponent : m_dropComponents)
90 {
91 if (dropComponent->getConnectedKwidgetID() == kwidgetID)
92 {
93 return dropComponent;
94 }
95 }
96
97 for (auto& c : m_multiDropComponents)
98 {
99 if (c->getConnectedKwidgetID() == kwidgetID)
100 {
101 if (modSourceID <= c->getDropComponents().size())
102 {
103 return c->getDropComponents()[modSourceID];
104 }
105 }
106 }
107
108 return nullptr;
109 }
110
112 {
113 int index = -1;
114 for (auto& dropComponent : m_dropComponents)
115 {
116 if (dropComponent->getConnectedKwidgetID() == kwidgetID)
117 {
118 index = m_dropComponents.indexOf(dropComponent);
119 break;
120 }
121 }
122 if (index != -1)
123 {
124 m_dropComponents.remove(index, true);
125 }
126
127 for (auto& c : m_multiDropComponents)
128 {
129 if (c->getConnectedKwidgetID() == kwidgetID)
130 {
131 index = m_multiDropComponents.indexOf(c);
132 break;
133 }
134 }
135 if (index != -1)
136 {
137 m_multiDropComponents.remove(index, true);
138 }
139 }
140
142 {
143 m_margin = margin;
144 resized();
145 }
146
147} // namespace krotos
A component for dropping draggable juce objects onto.
Definition DropComponent.h:11
OwnedArray< MultiDropComponent > m_multiDropComponents
Definition ModulationAssignerDropArea.h:75
void removeComponent(const String &kwidgetID)
Remove a drop component using its associated kwidgetID.
Definition ModulationAssignerDropArea.cpp:111
DropComponent * findDropComponent(const String &kwidgetID, int modSourceID)
Searches all the DropComponents in this DropArea to find which one is attached to the given kwidget m...
Definition ModulationAssignerDropArea.cpp:87
const OwnedArray< DropComponent > & getDropComponents() const noexcept
Returns an array of the child drop components.
Definition ModulationAssignerDropArea.h:21
OwnedArray< DropComponent > m_dropComponents
Definition ModulationAssignerDropArea.h:74
void paint(Graphics &g) override
Definition ModulationAssignerDropArea.cpp:12
DropComponent * addDropComponent(DropComponent *newComp)
Definition ModulationAssignerDropArea.cpp:71
bool m_singleRowColumn
Definition ModulationAssignerDropArea.h:79
ModulationAssignerDropArea()
Definition ModulationAssignerDropArea.cpp:10
int m_maxPerRow
Definition ModulationAssignerDropArea.h:76
float m_margin
Definition ModulationAssignerDropArea.h:77
void resized() override
Definition ModulationAssignerDropArea.cpp:14
void setMargin(float margin)
Sets the flex box margin.
Definition ModulationAssignerDropArea.cpp:141
MultiDropComponent * addMultiDropComponent(MultiDropComponent *newComp)
Definition ModulationAssignerDropArea.cpp:79
A simple container for a holding multiple drop components used for assigning modulation to a kwidget ...
Definition MultiDropComponent.h:16
Definition AirAbsorptionFilter.cpp:2
static const String ModulationMultiDropComponentID
Definition ModulationAssignerDropArea.h:59
static const String ModulationDropComponentID
Definition ModulationAssignerDropArea.h:58