#include #include "TimeSyncWidget.hpp" #include "StateWidget.hpp" #include "ScenarioWidget.hpp" #include "EventWidget.hpp" namespace Hardware { EventWidget::EventWidget(Scenario::EventModel& event, ScenarioWidget* scenario, bugui::container_widget* parent) : ScenarioComponentSpec{event, scenario, parent} { Scenario::ProcessModel* scen{scenario->get_model()}; scen->states.mutable_added.connect<&EventWidget::on_state_added>(this); scen->states.removed.connect<&EventWidget::on_state_removed>(this); for(Scenario::StateModel& s : scen->states) if (s.eventId() == model.id()) add_widget(s, scenario); set_span_recursive(); for(auto& s : children) static_cast(s.get())->set_y(); } void EventWidget::set_y() { m_y = m_absolute_y - parent->y(); } void EventWidget::set_span_recursive() { int lowest{std::numeric_limits::max()}; int heighest{0}; for(const auto& s : bugui::container_widget::children) { int sy = static_cast(s.get())->get_absolute_y(); if (sy < lowest) lowest = sy; if (sy > heighest) heighest = sy; } m_absolute_y = lowest; m_height = heighest - lowest; static_cast(bugui::base_widget::parent)->set_span(); for(const auto& s : bugui::container_widget::children) static_cast(s.get())->set_y(); } void EventWidget::paint(bugui::painter& painter) const { if (!press) return; const auto col = model.metadata().getColor().getBrush().color(); // const auto col = skin.StateSelected().color(); painter.set_color(col.red(), col.green(), col.blue(), col.alpha()); painter.draw_line(0, 0, 0, m_height); } bool EventWidget::contains(int px, int py) const { if (px == 0 && py >= 0 && py <= m_height) return true; return false; } void EventWidget::on_state_added(Scenario::StateModel& state) { if (state.eventId() != model.id()) return; add_widget(state, scenario); set_span_recursive(); update(); } void EventWidget::on_state_removed(const Scenario::StateModel& state) { if (state.eventId() != model.id()) return; remove_widget([&state] (const auto& w) { return static_cast*>(w.get())->this_model(state); }); set_span_recursive(); update(); } void EventWidget::on_press(int x, int y, bool pressed) { press = pressed; } } // namespace Hardware