#include "StateWidget.hpp" namespace Hardware { StateWidget::StateWidget(Scenario::StateModel& state, container_widget* parent) : bugui::container_widget{parent} , model{state} , skin{Process::Style::instance()} { } int StateWidget::x() const { return parent->x(); } int StateWidget::y() const { return model.heightPercentage() * parent->height(); } void StateWidget::paint(bugui::painter& painter) const { // Copied from MiniscenarioView const auto col = skin.IntervalBase().color(); painter.set_color(col.red(), col.green(), col.blue(), col.alpha()); painter.draw_line({x(), y()}, {x() + width(), y()}); } bool StateWidget::contains(int px, int py) const { if (px >= x() && px <= (x() + width()) && py == y()) return true; return false; } bool StateWidget::on_press(int x, int y, bool pressed) { if (!contains(x, y)) return false; qDebug() << "is inside!"; return true; } bool StateWidget::on_double_press(int x, int y) { if (!contains(x, y)) return false; qDebug() << "double pressed !"; return true; } bool StateWidget::on_drag(int from_x, int from_y, int to_x, int to_y) { if (!contains(from_x, from_y)) return false; if (from_y != to_y) model.setHeightPercentage(to_y / static_cast(parent->height())); return true; } const Scenario::StateModel& StateWidget::get_model() const { return model; } }