summaryrefslogtreecommitdiffstats
path: root/src/CanvasModule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/CanvasModule.cpp')
-rw-r--r--src/CanvasModule.cpp170
1 files changed, 85 insertions, 85 deletions
diff --git a/src/CanvasModule.cpp b/src/CanvasModule.cpp
index 0f32f14..4b74f9e 100644
--- a/src/CanvasModule.cpp
+++ b/src/CanvasModule.cpp
@@ -49,143 +49,143 @@ CanvasModule::CanvasModule(Patchage* app,
ClientID id,
double x,
double y)
- : Module(*app->canvas(), name, x, y)
- , _app(app)
- , _menu(nullptr)
- , _name(name)
- , _type(type)
- , _id(std::move(id))
+ : Module(*app->canvas(), name, x, y)
+ , _app(app)
+ , _menu(nullptr)
+ , _name(name)
+ , _type(type)
+ , _id(std::move(id))
{
- signal_event().connect(sigc::mem_fun(this, &CanvasModule::on_event));
+ signal_event().connect(sigc::mem_fun(this, &CanvasModule::on_event));
- signal_moved().connect(sigc::mem_fun(this, &CanvasModule::store_location));
+ signal_moved().connect(sigc::mem_fun(this, &CanvasModule::store_location));
- // Set as source by default, turned off if input ports added
- set_is_source(true);
+ // Set as source by default, turned off if input ports added
+ set_is_source(true);
}
CanvasModule::~CanvasModule()
{
- _app->canvas()->remove_module(this);
- delete _menu;
- _menu = nullptr;
+ _app->canvas()->remove_module(this);
+ delete _menu;
+ _menu = nullptr;
}
void
CanvasModule::update_menu()
{
- if (!_menu) {
- return;
- }
-
- if (_type == SignalDirection::duplex) {
- bool has_in = false;
- bool has_out = false;
- for (const auto* p : *this) {
- if (p->is_input()) {
- has_in = true;
- } else {
- has_out = true;
- }
-
- if (has_in && has_out) {
- _menu->items()[0].show(); // Show "Split" menu item
- return;
- }
- }
- _menu->items()[0].hide(); // Hide "Split" menu item
- }
+ if (!_menu) {
+ return;
+ }
+
+ if (_type == SignalDirection::duplex) {
+ bool has_in = false;
+ bool has_out = false;
+ for (const auto* p : *this) {
+ if (p->is_input()) {
+ has_in = true;
+ } else {
+ has_out = true;
+ }
+
+ if (has_in && has_out) {
+ _menu->items()[0].show(); // Show "Split" menu item
+ return;
+ }
+ }
+ _menu->items()[0].hide(); // Hide "Split" menu item
+ }
}
bool
CanvasModule::show_menu(GdkEventButton* ev)
{
- _menu = new Gtk::Menu();
- Gtk::Menu::MenuList& items = _menu->items();
-
- if (_type == SignalDirection::duplex) {
- items.push_back(Gtk::Menu_Helpers::MenuElem(
- "_Split", sigc::mem_fun(this, &CanvasModule::split)));
- update_menu();
- } else {
- items.push_back(Gtk::Menu_Helpers::MenuElem(
- "_Join", sigc::mem_fun(this, &CanvasModule::join)));
- }
-
- items.push_back(Gtk::Menu_Helpers::MenuElem(
- "_Disconnect All", sigc::mem_fun(this, &CanvasModule::disconnect_all)));
-
- _menu->popup(ev->button, ev->time);
- return true;
+ _menu = new Gtk::Menu();
+ Gtk::Menu::MenuList& items = _menu->items();
+
+ if (_type == SignalDirection::duplex) {
+ items.push_back(Gtk::Menu_Helpers::MenuElem(
+ "_Split", sigc::mem_fun(this, &CanvasModule::split)));
+ update_menu();
+ } else {
+ items.push_back(Gtk::Menu_Helpers::MenuElem(
+ "_Join", sigc::mem_fun(this, &CanvasModule::join)));
+ }
+
+ items.push_back(Gtk::Menu_Helpers::MenuElem(
+ "_Disconnect All", sigc::mem_fun(this, &CanvasModule::disconnect_all)));
+
+ _menu->popup(ev->button, ev->time);
+ return true;
}
bool
CanvasModule::on_event(GdkEvent* ev)
{
- if (ev->type == GDK_BUTTON_PRESS && ev->button.button == 3) {
- return show_menu(&ev->button);
- }
- return false;
+ if (ev->type == GDK_BUTTON_PRESS && ev->button.button == 3) {
+ return show_menu(&ev->button);
+ }
+ return false;
}
void
CanvasModule::load_location()
{
- Coord loc;
-
- if (_app->conf().get_module_location(_name, _type, loc)) {
- move_to(loc.x, loc.y);
- } else {
- const double x = 20 + rand() % 640;
- const double y = 20 + rand() % 480;
-
- // Move, then store generated location so it is stable
- move_to(x, y);
- store_location(x, y);
- }
+ Coord loc;
+
+ if (_app->conf().get_module_location(_name, _type, loc)) {
+ move_to(loc.x, loc.y);
+ } else {
+ const double x = 20 + rand() % 640;
+ const double y = 20 + rand() % 480;
+
+ // Move, then store generated location so it is stable
+ move_to(x, y);
+ store_location(x, y);
+ }
}
void
CanvasModule::store_location(double x, double y)
{
- _app->conf().set_module_location(_name, _type, {x, y});
+ _app->conf().set_module_location(_name, _type, {x, y});
}
void
CanvasModule::split()
{
- assert(_type == SignalDirection::duplex);
- _app->conf().set_module_split(_name, true);
- _app->refresh();
+ assert(_type == SignalDirection::duplex);
+ _app->conf().set_module_split(_name, true);
+ _app->refresh();
}
void
CanvasModule::join()
{
- assert(_type != SignalDirection::duplex);
- _app->conf().set_module_split(_name, false);
- _app->refresh();
+ assert(_type != SignalDirection::duplex);
+ _app->conf().set_module_split(_name, false);
+ _app->refresh();
}
void
CanvasModule::disconnect_all()
{
- for (Ganv::Port* p : *this) {
- p->disconnect();
- }
+ for (Ganv::Port* p : *this) {
+ p->disconnect();
+ }
}
CanvasPort*
CanvasModule::get_port(const PortID& id)
{
- for (Ganv::Port* p : *this) {
- auto* pport = dynamic_cast<CanvasPort*>(p);
- if (pport && pport->id() == id) {
- return pport;
- }
- }
-
- return nullptr;
+ for (Ganv::Port* p : *this) {
+ auto* pport = dynamic_cast<CanvasPort*>(p);
+ if (pport && pport->id() == id) {
+ return pport;
+ }
+ }
+
+ return nullptr;
}
} // namespace patchage