[inputs] handle with Controller member functions

This commit is contained in:
thibaud keller 2024-12-03 23:42:27 +00:00
parent c52e1599eb
commit 0ed36bfade
3 changed files with 116 additions and 91 deletions

@ -1 +1 @@
Subproject commit 2a725a7eb0ec3262059d7f724d2725e33b03c55f
Subproject commit 34ec6482874d49de63a353160d78af786a7258e6

View file

@ -7,91 +7,13 @@
namespace Hardware
{
Controller::Controller(const score::DocumentContext& doc)
: bugui::controller<Controller>{[&doc, this]
(bugui::commands com, bool shift)
{
switch (com)
{
case bugui::Play:
if (shift)
doc.app.actions.action<Actions::PlayGlobal>().action()->trigger();
else
doc.app.actions.action<Actions::Play>().action()->trigger();
break;
case bugui::Stop:
if (shift)
doc.app.actions.action<Actions::Reinitialize>().action()->trigger();
else
doc.app.actions.action<Actions::Stop>().action()->trigger();
break;
case bugui::Up:
if (shift)
{
v_zoom += .2;
update();
}
else
{
v_ofset += .02;
update();
}
break;
case bugui::Down:
if (shift)
{
if (v_zoom > .2)
{
v_zoom -= .2;
update();
}
}
else
{
v_ofset -= .02;
update();
}
break;
case bugui::Left:
if (shift)
{
if (h_zoom > .02)
{
h_zoom -= .02;
update();
}
}
else
{
if (h_ofset > 0)
{
h_ofset -= .02;
update();
}
}
break;
case bugui::Right:
if (shift)
{
h_zoom += .02;
update();
}
else
{
h_ofset += .02;
update();
}
break;
default:
break;
}
// qDebug() << "v_ofset: " << v_ofset;
// qDebug() << "v_zoom: " << v_zoom;
// qDebug() << "h_ofset: " << h_ofset;
// qDebug() << "h_zoom: " << h_ofset;
}
}
Controller::Controller(const score::DocumentContext& document)
: bugui::controller<Controller>{}
, doc{document}
, h_ofset{0.} // initial horizontal ofset
, v_ofset{0.} // initial verticalal ofset
, h_zoom{.125} // initial horizontal zoom
, v_zoom{1.1} // initial verticalal zoom
{}
void Controller::setup_scenario(Scenario::ProcessModel* s)
@ -114,7 +36,7 @@ void Controller::on_interval_changed(const Scenario::IntervalModel&)
update();
}
void Controller::paint(bugui::painter& painter)
void Controller::paint(bugui::painter& painter) const
{
if (!scenar) return;
@ -132,6 +54,92 @@ void Controller::paint(bugui::painter& painter)
}
}
void Controller::play(bool pressed)
{
if (m_shift)
doc.app.actions.action<Actions::PlayGlobal>().action()->trigger();
else
doc.app.actions.action<Actions::Play>().action()->trigger();
}
void Controller::stop(bool pressed)
{
if (m_shift)
doc.app.actions.action<Actions::Reinitialize>().action()->trigger();
else
doc.app.actions.action<Actions::Stop>().action()->trigger();
}
void Controller::shift(bool pressed)
{
m_shift = pressed;
}
void Controller::up(bool pressed)
{
if (m_shift)
{
v_zoom += .2;
update();
}
else
{
v_ofset += .02;
update();
}
}
void Controller::down(bool pressed)
{
if (m_shift)
{
if (v_zoom > .2)
{
v_zoom -= .2;
update();
}
}
else
{
v_ofset -= .02;
update();
}
}
void Controller::left(bool pressed)
{
if (m_shift)
{
if (h_zoom > .02)
{
h_zoom -= .02;
update();
}
}
else
{
if (h_ofset > 0)
{
h_ofset -= .02;
update();
}
}
}
void Controller::right(bool pressed)
{
if (m_shift)
{
h_zoom += .02;
update();
}
else
{
h_ofset += .02;
update();
}
}
}
#include <wobjectimpl.h>

View file

@ -2,6 +2,7 @@
#include <score_addon_hardware_export.h>
#include <score/document/DocumentContext.hpp>
#include <Scenario/Document/Interval/IntervalModel.hpp>
#include <Scenario/Process/ScenarioModel.hpp>
@ -16,15 +17,31 @@ class SCORE_ADDON_HARDWARE_EXPORT Controller
W_OBJECT(Controller)
public:
explicit Controller(const score::DocumentContext& doc);
explicit Controller(const score::DocumentContext& document);
void setup_scenario(Scenario::ProcessModel* s);
void paint(bugui::painter& painter) override;
void paint(bugui::painter& painter) const override;
void play(bool pressed);
void stop(bool pressed);
void shift(bool pressed);
void up(bool pressed);
void down(bool pressed);
void left(bool pressed);
void right(bool pressed);
private:
Scenario::ProcessModel* scenar;
void on_interval_changed(const Scenario::IntervalModel&);
Scenario::ProcessModel* scenar;
const score::DocumentContext& doc;
bool m_shift{false};
float h_ofset;
float v_ofset;
float h_zoom;
float v_zoom;
};
}