-
-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathObject.h
More file actions
187 lines (136 loc) · 5.2 KB
/
Object.h
File metadata and controls
187 lines (136 loc) · 5.2 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
// Copyright (c) 2021-2025 Timothy Schoen
// For information on usage and redistribution, and for a DISCLAIMER OF ALL
// WARRANTIES, see the file, "LICENSE.txt," in this distribution.
*/
#pragma once
#include "Utility/ModifierKeyListener.h"
#include <juce_gui_basics/juce_gui_basics.h>
#include <juce_animation/juce_animation.h>
#include "Utility/SettingsFile.h"
#include "Utility/RateReducer.h"
#include "Utility/NVGUtils.h"
#include "Pd/WeakReference.h"
#include "Iolet.h"
#include <nanovg.h>
#ifdef NANOVG_GL_IMPLEMENTATION
# include <juce_opengl/juce_opengl.h>
using namespace juce::gl;
# undef NANOVG_GL_IMPLEMENTATION
# include <nanovg_gl_utils.h>
# define NANOVG_GL_IMPLEMENTATION 1
#endif
struct ObjectDragState;
class ObjectBase;
class Iolet;
class Canvas;
class Connection;
class Object final : public Component
, public Value::Listener
, public ChangeListener
, public KeyListener
, public NVGComponent
, public SettingsFileListener
, private TextEditor::Listener {
public:
explicit Object(Canvas* parent, String const& name = "", Point<int> position = { 100, 100 });
Object(pd::WeakReference object, Canvas* parent);
~Object() override;
void settingsChanged(String const& name, var const& value) override;
void valueChanged(Value& v) override;
void changeListenerCallback(ChangeBroadcaster* source) override;
void moved() override;
void resized() override;
void updateIoletGeometry();
bool keyPressed(KeyPress const& key, Component* component) override;
void updateIolets();
void setType(String const& newType, pd::WeakReference existingObject = nullptr);
void updateBounds();
void applyBounds();
void showEditor();
void hideEditor();
bool isInitialEditorShown() const;
String getType(bool withOriginPrefix = true) const;
Rectangle<int> getSelectableBounds() const;
Rectangle<int> getObjectBounds() const;
void setObjectBounds(Rectangle<int> bounds);
ComponentBoundsConstrainer* getConstrainer() const;
void openHelpPatch() const;
t_gobj* getPointer() const;
SmallArray<Connection*> getConnections() const;
void mouseEnter(MouseEvent const& e) override;
void mouseExit(MouseEvent const& e) override;
void render(NVGcontext* nvg) override;
void renderIolets(NVGcontext* nvg);
void renderLabel(NVGcontext* nvg);
void mouseMove(MouseEvent const& e) override;
void mouseDown(MouseEvent const& e) override;
void mouseUp(MouseEvent const& e) override;
void mouseDrag(MouseEvent const& e) override;
void lookAndFeelChanged() override;
void textEditorReturnKeyPressed(TextEditor& ed) override;
void textEditorTextChanged(TextEditor& ed) override;
bool hitTest(int x, int y) override;
void triggerOverlayActiveState();
SmallArray<Rectangle<float>> getCorners() const;
uint16_t numInputs = 0;
uint16_t numOutputs = 0;
Value locked;
Value commandLocked;
Value presentationMode;
Value hvccMode;
Value patchDownwardsOnly;
Canvas* cnv;
PluginEditor* editor;
std::unique_ptr<ObjectBase> gui;
PooledPtrArray<Iolet, 8, 4> iolets;
ResizableBorderComponent::Zone resizeZone;
static constexpr int margin = 6;
static constexpr int doubleMargin = margin * 2;
static constexpr int height = 32;
static constexpr int minimumSize = 9;
Rectangle<int> originalBounds;
bool isSelected() const;
void hideHandles(bool const shouldHide)
{
showHandles = !shouldHide;
repaint();
}
// Controls the way object activity propagates upwards inside GOPs.
enum ObjectActivityPolicy {
Self, // Trigger object's own activity only.
Parent, // Trigger activity of object itself, and direct parent GOP only.
Recursive // Trigger activity of object itself, and all parent GOPs recursively.
};
ObjectActivityPolicy objectActivityPolicy : 2 = ObjectActivityPolicy::Self;
private:
void initialise();
void updateTooltips();
void openNewObjectEditor();
void setSelected(bool shouldBeSelected);
bool selectedFlag : 1 = false;
bool showHandles : 1 = true;
bool selectionStateChanged : 1 = false;
bool drawIoletExpanded : 1 = false;
bool validResizeZone : 1 = false;
bool wasLockedOnMouseDown : 1 = false;
bool isHvccCompatible : 1 = true;
bool isGemObject : 1 = false;
bool isObjectMouseActive : 1 = false;
ObjectDragState& ds;
RateReducer rateReducer = RateReducer(30);
float activeStateAlpha = 0.0f;
VBlankAnimatorUpdater updater { this };
Animator activityStateFade = ValueAnimatorBuilder { }
.withDurationMs(450)
.withEasing(Easings::createEaseInOut())
.withValueChangedCallback([this](float v) {
activeStateAlpha = 1.0f - v;
repaint();
})
.build();
std::unique_ptr<TextEditor> newObjectEditor;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Object)
JUCE_DECLARE_WEAK_REFERENCEABLE(Object)
friend class Iolet;
};