Skip to content

Commit

Permalink
alea: corrected module creation method to adhere to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
gosub committed Jan 30, 2022
1 parent f51fb28 commit b4ca5dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
23 changes: 14 additions & 9 deletions src/alea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
#include "callback_button.hpp"


void CreateModule(Model* module) {
ModuleWidget *moduleWidget = module->createModuleWidget();
if (moduleWidget) {
APP->scene->rack->addModuleAtMouse(moduleWidget);
history::ModuleAdd *h = new history::ModuleAdd;
h->name = "create module";
h->setModule(moduleWidget);
APP->history->push(h);
}
void CreateModule(Model* model) {
engine::Module* module = model->createModule();
APP->engine->addModule(module);
ModuleWidget* moduleWidget = model->createModuleWidget(module);
APP->scene->rack->addModuleAtMouse(moduleWidget);
// Load template preset
moduleWidget->loadTemplate();

// history::ModuleAdd
history::ModuleAdd* h = new history::ModuleAdd;
h->name = "create module";
// This serializes the module so redoing returns to the current state.
h->setModule(moduleWidget);
APP->history->push(h);
}

template<typename Iter, typename RandomGenerator>
Expand Down
12 changes: 7 additions & 5 deletions src/callback_button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CALLBACK_BUTTON_HPP__

#include "plugin.hpp"
#include "window.hpp"
//#include "window.hpp"
#include <functional>

template<typename T>
Expand All @@ -23,10 +23,12 @@ struct CallbackButton : SvgButton {

CallbackButton() {}

virtual void onAction(const event::Action &e) override {
e.consume(this);
callback(module);
SvgButton::onAction(e);
virtual void onButton(const ButtonEvent& e) override {
SvgButton::onButton(e);
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) {
e.consume(this);
callback(module);
}
}

std::function<void (T*)> callback;
Expand Down

0 comments on commit b4ca5dc

Please sign in to comment.