diff --git a/Hardware/3rdparty/bugui b/Hardware/3rdparty/bugui index 465dfda..d1cdce9 160000 --- a/Hardware/3rdparty/bugui +++ b/Hardware/3rdparty/bugui @@ -1 +1 @@ -Subproject commit 465dfda542cae212d2f06298f1d7e0136f2e66c2 +Subproject commit d1cdce9329c01e98343d798adbe76c7df0013aec diff --git a/Hardware/Controller.cpp b/Hardware/Controller.cpp index bf2eb90..a2c1a78 100644 --- a/Hardware/Controller.cpp +++ b/Hardware/Controller.cpp @@ -22,9 +22,22 @@ Controller::Controller(const score::DocumentContext& document, update(); } -void Controller::on_grid(float x, float y, bool pressed) +bool Controller::on_press(int x, int y, bool pressed) { - qDebug() << "x: " << x << " y: " << y << " pressed: " << pressed; + for (auto& w : widgets) + if (w->on_press(x, y, pressed)) + return true; + + return false; +} + +bool Controller::on_double_press(int x, int y) +{ + for (auto& w : widgets) + if (w->on_double_press(x, y)) + return true; + + return false; } void Controller::on_play(bool pressed) diff --git a/Hardware/Controller.hpp b/Hardware/Controller.hpp index 747f908..73901c7 100644 --- a/Hardware/Controller.hpp +++ b/Hardware/Controller.hpp @@ -29,7 +29,8 @@ public: void on_left(bool pressed); void on_right(bool pressed); - void on_grid(float x, float y, bool pressed); + bool on_press(int x, int y, bool pressed) override; + bool on_double_press(int x, int y) override; private: Scenario::IntervalModel* interval; diff --git a/Hardware/Widgets/IntervalWidget.cpp b/Hardware/Widgets/IntervalWidget.cpp index 5589e69..0fe6533 100644 --- a/Hardware/Widgets/IntervalWidget.cpp +++ b/Hardware/Widgets/IntervalWidget.cpp @@ -34,6 +34,34 @@ void IntervalWidget::paint(bugui::painter& painter) const painter.draw_line({x(), y()}, {x() + width(), y()}); } +bool IntervalWidget::is_inside(int px, int py) const +{ + if (px >= x() && + px <= (x() + width()) && + py == y()) + return true; + + return false; +} + +bool IntervalWidget::on_press(int x, int y, bool pressed) +{ + if (!is_inside(x, y)) return false; + + qDebug() << "is inside!"; + + return true; +} + +bool IntervalWidget::on_double_press(int x, int y) +{ + if (!is_inside(x, y)) return false; + + qDebug() << "double pressed !"; + + return true; +} + const Scenario::IntervalModel &IntervalWidget::get_model() const { return model; diff --git a/Hardware/Widgets/IntervalWidget.hpp b/Hardware/Widgets/IntervalWidget.hpp index c8ba59c..23f4c13 100644 --- a/Hardware/Widgets/IntervalWidget.hpp +++ b/Hardware/Widgets/IntervalWidget.hpp @@ -12,6 +12,8 @@ struct IntervalWidget final : bugui::base_widget Scenario::IntervalModel& interval); void paint(bugui::painter& painter) const override; + bool on_press(int x, int y, bool pressed) override; + bool on_double_press(int x, int y) override; int x() const override; int y() const override; @@ -19,6 +21,9 @@ struct IntervalWidget final : bugui::base_widget const Scenario::IntervalModel& get_model() const; +protected: + bool is_inside(int px, int py) const override; + private: Scenario::IntervalModel& model; const Process::Style& skin; diff --git a/Hardware/Widgets/ScenarioWidget.cpp b/Hardware/Widgets/ScenarioWidget.cpp index 9625b5e..17bd715 100644 --- a/Hardware/Widgets/ScenarioWidget.cpp +++ b/Hardware/Widgets/ScenarioWidget.cpp @@ -19,11 +19,31 @@ ScenarioWidget::ScenarioWidget(base_widget* parent, widgets.emplace_back(std::make_unique(this, s)); } -void ScenarioWidget::paint(bugui::painter &painter) const +void ScenarioWidget::paint(bugui::painter& painter) const { for (const auto& w : widgets) w->paint(painter); } +bool ScenarioWidget::on_press(int x, int y, bool pressed) +{ + if (!is_inside(x, y)) return false; + + for (auto& w : widgets) + if (w->on_press(x, y, pressed)) return true; + + return true; +} + +bool ScenarioWidget::on_double_press(int x, int y) +{ + if (!is_inside(x, y)) return false; + + for (auto& w : widgets) + if (w->on_double_press(x, y)) return true; + + return true; +} + int ScenarioWidget::x() const { return bugui::base_widget::parent->x(); @@ -55,7 +75,10 @@ void ScenarioWidget::on_interval_removed(const Scenario::IntervalModel& interval std::erase_if(widgets, [&interval] (auto& w) - { return static_cast(w.get())->get_model().id() == interval.id(); }); + { + auto ntrvl = static_cast(w.get()); + return ntrvl->get_model().id() == interval.id(); + }); update(); } diff --git a/Hardware/Widgets/ScenarioWidget.hpp b/Hardware/Widgets/ScenarioWidget.hpp index f3f3e09..861dbbd 100644 --- a/Hardware/Widgets/ScenarioWidget.hpp +++ b/Hardware/Widgets/ScenarioWidget.hpp @@ -18,6 +18,8 @@ public: Scenario::ProcessModel* scenario); void paint(bugui::painter& painter) const override; + bool on_press(int x, int y, bool pressed) override; + bool on_double_press(int x, int y) override; int x() const override; int y() const override;