Wt::WRectF elevator_system_drawer::queue_corridor_rect(Direction dir, Wt::WRectF const& rc_floor) { auto const q_height = get_queue_height(SizeFormat::Pixels); return Wt::WRectF( rc_floor.left(), dir == Direction::Up ? rc_floor.top() : (rc_floor.bottom() - q_height), rc_floor.width(), q_height ); }
Wt::WRectF elevator_system_drawer::floor_rect(floor_t floor, Wt::WRectF const& rc_side) { auto const floor_height = get_floor_height(SizeFormat::Pixels); return{ rc_side.left(), rc_side.bottom() - (floor + 1) * floor_height, rc_side.width(), floor_height }; }
void elevator_system_drawer::draw_queue(size_t length, Wt::WPainter& painter, Wt::WRectF rc) { auto const person_height = get_person_height(SizeFormat::Pixels); auto const person_width = get_person_width(SizeFormat::Pixels); auto const gap_width = get_queue_gap_width(SizeFormat::Pixels); auto const margin = (rc.height() - person_height) * 0.5; rc = Wt::WRectF( rc.left(), rc.top() + margin, person_width, person_height ); double offset = person_width + gap_width; for(size_t i = 0; i < length; ++i) { draw_person(painter, rc); rc = Wt::WRectF( rc.left() + offset, rc.top(), rc.width(), rc.height() ); } }
Wt::WRectF elevator_system_drawer::queue_rect(size_t length, QueueSide side, Wt::WRectF const& rc_bounds) { auto const person_width = get_person_width(SizeFormat::Pixels); auto const queue_gap = get_queue_gap_width(SizeFormat::Pixels); switch(side) { case QueueSide::Left: return Wt::WRectF( rc_bounds.left(), rc_bounds.top(), person_width * length + queue_gap * (length - 1), rc_bounds.height() ); case QueueSide::Right: return Wt::WRectF( rc_bounds.right() - (person_width * length + queue_gap * (length - 1)), rc_bounds.top(), person_width * length + queue_gap * (length - 1), rc_bounds.height() ); } }
void elevator_system_drawer::draw_elevator(Wt::WPainter& painter, Wt::WRectF const& rc) { const auto floor_height = get_floor_height(SizeFormat::Pixels); const auto elevator_height = get_elevator_height(SizeFormat::Pixels); painter.save(); Wt::WRectF rc_elevator( rc.left(), rc.bottom() - get_current_floor() * floor_height - elevator_height, rc.width(), elevator_height ); if(m_stage == AnimationStage::Moving) { auto travelled = m_stage_step * ElevatorSpeed * m_pix_multiplier; travelled = std::min(travelled, floor_height); auto sign = m_sys.m_state.direction == Direction::Up ? 1.0 : -1.0; rc_elevator = Wt::WRectF( rc_elevator.left(), rc_elevator.top() - sign * travelled, rc_elevator.width(), rc_elevator.height() ); } double exit_door_openness = 0.0; switch(m_stage) { case AnimationStage::ExitDoorsOpening: exit_door_openness = m_stage_step * DoorSpeed * m_pix_multiplier / elevator_height; exit_door_openness = std::min(exit_door_openness, 1.0); break; case AnimationStage::ExitDoorsClosing: exit_door_openness = 1.0 - m_stage_step * DoorSpeed * m_pix_multiplier / elevator_height; exit_door_openness = std::max(exit_door_openness, 0.0); break; case AnimationStage::GettingOff: exit_door_openness = 1.0; break; } double entry_door_openness = 0.0; switch(m_stage) { case AnimationStage::EntryDoorsOpening: entry_door_openness = m_stage_step * DoorSpeed * m_pix_multiplier / elevator_height; entry_door_openness = std::min(entry_door_openness, 1.0); break; case AnimationStage::EntryDoorsClosing: entry_door_openness = 1.0 - m_stage_step * DoorSpeed * m_pix_multiplier / elevator_height; entry_door_openness = std::max(entry_door_openness, 0.0); break; case AnimationStage::GettingOn: entry_door_openness = 1.0; break; } painter.drawLine(rc_elevator.topLeft(), rc_elevator.topRight()); painter.drawLine(rc_elevator.bottomLeft(), rc_elevator.bottomRight()); painter.drawLine( rc_elevator.left(), rc_elevator.top(), rc_elevator.left(), rc_elevator.top() + (1.0 - entry_door_openness) * elevator_height ); painter.drawLine( rc_elevator.right(), rc_elevator.top(), rc_elevator.right(), rc_elevator.top() + (1.0 - exit_door_openness) * elevator_height ); if(m_sys.is_moving(m_sys.m_state.direction)) { painter.save(); painter.translate(rc_elevator.left(), rc_elevator.top()); if(m_sys.m_state.direction == elevator_system::Direction::Down) { painter.translate(0.0, rc_elevator.height() * 0.5); painter.scale(1.0, -1.0); } painter.scale(rc_elevator.width(), rc_elevator.height()); std::array< Wt::WPointF, 3 > points{ { { 0.5, 0.1 }, { 0.2, 0.4 }, { 0.8, 0.4 }, } }; painter.setPen(Wt::WPen(Wt::green)); painter.setBrush(Wt::WBrush(Wt::green)); painter.drawPolygon(&points[0], 3); painter.restore(); } Wt::WFont font = painter.font(); //font.setFamily(Wt::WFont::Default); font.setSize(20); painter.setFont(font); painter.drawText( Wt::WRectF(rc_elevator.left(), rc_elevator.center().y(), rc_elevator.width(), rc_elevator.height() * 0.5), Wt::AlignCenter | Wt::AlignMiddle, std::to_string(get_current_occupancy()) ); painter.restore(); }
void elevator_system_drawer::draw_floor(Wt::WPainter& painter, Wt::WRectF const& rc) { painter.drawLine(rc.left(), rc.bottom(), rc.right(), rc.bottom()); }