[architecture] use bugui paint function

This commit is contained in:
thibaud keller 2024-10-17 17:39:36 +01:00
parent 39f11ea247
commit deaaed30fe
3 changed files with 20 additions and 22 deletions

@ -1 +1 @@
Subproject commit 6e18b2d897e89ced5eb420aafe7c50f29026bfb6
Subproject commit ceddf2006062b5bcc83f8c3043a9bac79e485b81

View file

@ -8,7 +8,7 @@
namespace Hardware
{
Controller::Controller(const score::DocumentContext& doc)
: bugui::painter{[&doc, this]
: bugui::controller{[&doc, this]
(bugui::commands com, const bool& shift)
{
switch (com)
@ -29,12 +29,12 @@ Controller::Controller(const score::DocumentContext& doc)
if (shift)
{
v_zoom += .2;
draw_intervals();
update();
}
else
{
v_ofset += .02;
draw_intervals();
update();
}
break;
case bugui::Down:
@ -43,13 +43,13 @@ Controller::Controller(const score::DocumentContext& doc)
if (v_zoom > .2)
{
v_zoom -= .2;
draw_intervals();
update();
}
}
else
{
v_ofset -= .02;
draw_intervals();
update();
}
break;
case bugui::Left:
@ -58,7 +58,7 @@ Controller::Controller(const score::DocumentContext& doc)
if (h_zoom > .02)
{
h_zoom -= .02;
draw_intervals();
update();
}
}
else
@ -66,7 +66,7 @@ Controller::Controller(const score::DocumentContext& doc)
if (h_ofset > 0)
{
h_ofset -= .02;
draw_intervals();
update();
}
}
break;
@ -74,12 +74,12 @@ Controller::Controller(const score::DocumentContext& doc)
if (shift)
{
h_zoom += .02;
draw_intervals();
update();
}
else
{
h_ofset += .02;
draw_intervals();
update();
}
break;
default:
@ -106,32 +106,30 @@ void Controller::setup_scenario(Scenario::ProcessModel* s)
connect(scenar,
&Scenario::ProcessModel::intervalMoved,
[this] { draw_intervals(); });
[this] { update(); });
}
void Controller::on_interval_changed(const Scenario::IntervalModel &)
{
draw_intervals();
update();
}
void Controller::draw_intervals()
void Controller::paint(bugui::painter &painter)
{
if (!ctl || !scenar) return;
if (!scenar) return;
// Copied from MiniscenarioView
auto& skin = Process::Style::instance();
const auto col = skin.IntervalBase().color();
set_color(col.redF(), col.greenF(), col.blackF(), col.alphaF());
painter.set_color(col.redF(), col.greenF(), col.blackF(), col.alphaF());
for(const Scenario::IntervalModel& c : scenar->intervals)
{
auto def = c.duration.defaultDuration().sec() * h_zoom;
auto st = (c.date().sec() * h_zoom) - h_ofset;
auto y = (c.heightPercentage() * v_zoom) + v_ofset;
draw_line({st, y}, {st + def, y});
painter.draw_line({st, y}, {st + def, y});
}
update_grid();
}
}

View file

@ -5,12 +5,12 @@
#include <Scenario/Document/Interval/IntervalModel.hpp>
#include <Scenario/Process/ScenarioModel.hpp>
#include <painter.hpp>
#include <controller.hpp>
namespace Hardware
{
class SCORE_ADDON_HARDWARE_EXPORT Controller
: public bugui::painter
: public bugui::controller
, public QObject
{
W_OBJECT(Controller)
@ -19,7 +19,7 @@ public:
explicit Controller(const score::DocumentContext& doc);
void setup_scenario(Scenario::ProcessModel* s);
void draw_intervals();
void paint(bugui::painter& painter) override;
private:
Scenario::ProcessModel* scenar;