Skip to content

Commit 56b8660

Browse files
committed
Signals
1 parent 0bdff17 commit 56b8660

File tree

8 files changed

+19
-35
lines changed

8 files changed

+19
-35
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
url = https://github.com/Rezonality/zing
88
[submodule "zing"]
99
branch = main
10+
[submodule "libs/signals"]
11+
path = libs/signals
12+
url = https://github.com/TheWisp/signals.git

app/nodes/node_oscillator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ void Oscillator::BuildNode(Canvas& canvas)
5757
m_spWaveSlider = std::make_shared<WaveSlider>("Wave", sliderVal);
5858
m_spWaveSlider->SetRect(NRectf(0.0f, 0.0f, 0.0f, 50.0f));
5959
m_spWaveSlider->SetConstraints(glm::uvec2(LayoutConstraint::Expanding, LayoutConstraint::Preferred));
60-
m_spWaveSlider->AddValueUpdatedCB([=]() {
60+
m_connections.push_back(m_spWaveSlider->ValueUpdatedSignal.connect([=]() {
6161
UpdateWave();
62-
});
62+
}));
6363

6464
spRootLayout->AddChild(m_spWaveSlider);
6565

6666
// Keep same height, expand the width
6767
auto spCustom = std::make_shared<Widget>("Custom");
6868
spCustom->SetConstraints(glm::uvec2(LayoutConstraint::Expanding, LayoutConstraint::Preferred));
6969
spCustom->SetRect(NRectf(0.0f, 0.0f, 0.0f, 50.0f));
70-
spCustom->AddPostDrawCB([=](Canvas& canvas, const NRectf& rect) {
70+
spCustom->PostDrawSignal.connect([=](Canvas& canvas, const NRectf& rect) {
7171
m_spWaveSlider->DrawGeneratedWave(canvas, rect);
7272
});
7373
spRootLayout->AddChild(spCustom);

app/nodes/node_oscillator.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <utils/wavetable.h>
1010

11+
#include <signals/signals.hpp>
12+
1113
extern "C"
1214
{
1315
#include <soundpipe_extensions/soundpipeextension.h>
@@ -44,6 +46,9 @@ class Oscillator
4446
virtual void BuildNode(NodeGraph::Canvas& canvas);
4547

4648
protected:
49+
50+
std::vector<fteng::connection> m_connections;
51+
4752
// Inputs
4853
/*
4954
NodeGraph::Pin* m_pWave;

include/nodegraph/widgets/widget.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <zest/math/math_utils.h>
88
#include <zest/time/timer.h>
99

10+
#include <signals/signals.hpp>
11+
1012
namespace NodeGraph {
1113

1214
class Canvas;
@@ -219,8 +221,6 @@ class Layout;
219221
class Widget;
220222
using WidgetList = std::vector<std::shared_ptr<Widget>>;
221223

222-
using fnPostDraw = std::function<void(Canvas& canvas, const Zest::NRectf& hintRect)>;
223-
using fnValueUpdated = std::function<void()>;
224224
class Widget
225225
{
226226
public:
@@ -232,10 +232,6 @@ class Widget
232232
virtual Widget* GetParent() const;
233233
virtual void SetParent(Widget* pParent);
234234

235-
// Post Draw
236-
virtual void AddPostDrawCB(const fnPostDraw& fnCB);
237-
virtual void AddValueUpdatedCB(const fnValueUpdated& fnCB);
238-
239235
virtual const Zest::NRectf& GetRect() const;
240236
virtual void SetRect(const Zest::NRectf& sz);
241237
virtual const glm::uvec2& GetConstraints() const;
@@ -285,7 +281,8 @@ class Widget
285281

286282
void Visit(const std::function<void(Widget*)>& fnVisit);
287283

288-
void SendValueUpdated();
284+
fteng::signal<void()> ValueUpdatedSignal;
285+
fteng::signal<void(Canvas& canvas, const Zest::NRectf& hintRect)> PostDrawSignal;
289286

290287
protected:
291288
Zest::NRectf m_rect;
@@ -296,8 +293,6 @@ class Widget
296293
std::shared_ptr<Layout> m_spLayout;
297294
uint64_t m_flags = 0;
298295
glm::vec2 m_sizeHint = glm::vec2(0.0f);
299-
fnPostDraw m_postDrawCB;
300-
fnValueUpdated m_valueUpdatedCB;
301296
TipTimer m_tipTimer;
302297
};
303298

libs/signals

Submodule signals added at 7ff59d1

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ PRIVATE
6969
${CMAKE_BINARY_DIR}
7070
PUBLIC
7171
$<BUILD_INTERFACE:${NODEGRAPH_ROOT}/include>
72+
$<BUILD_INTERFACE:${NODEGRAPH_ROOT}/libs>
7273
$<INSTALL_INTERFACE:include>
7374
)
7475

src/widgets/widget.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ Widget::Widget(const std::string& label)
1919
{
2020
}
2121

22-
void Widget::AddPostDrawCB(const fnPostDraw& fnCB)
23-
{
24-
m_postDrawCB = fnCB;
25-
}
26-
27-
void Widget::AddValueUpdatedCB(const fnValueUpdated& fnCB)
28-
{
29-
m_valueUpdatedCB = fnCB;
30-
}
31-
3222
Widget* Widget::GetParent() const
3323
{
3424
return m_pParent;
@@ -99,10 +89,7 @@ void Widget::Draw(Canvas& canvas)
9989

10090
void Widget::PostDraw(Canvas& canvas, const NRectf& hintRect)
10191
{
102-
if (m_postDrawCB)
103-
{
104-
m_postDrawCB(canvas, hintRect);
105-
}
92+
PostDrawSignal(canvas, hintRect);
10693
}
10794

10895
Widget* Widget::MouseDown(CanvasInputState& input)
@@ -383,13 +370,5 @@ void Widget::DrawTip(Canvas& canvas, const glm::vec2& widgetTopCenter, const Wid
383370
fontSize);
384371
}
385372
}
386-
387-
void Widget::SendValueUpdated()
388-
{
389-
if (m_valueUpdatedCB)
390-
{
391-
m_valueUpdatedCB();
392-
}
393-
}
394373

395374
} // Nodegraph

src/widgets/widget_slider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void DefaultSliderCB::UpdateSlider(Slider* pSlider, SliderOp op, SliderValue& va
3232
else
3333
{
3434
myVal = val;
35-
pSlider->SendValueUpdated();
35+
pSlider->ValueUpdatedSignal();
3636
}
3737
}
3838

0 commit comments

Comments
 (0)