X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=positionlabel.cpp;h=97a2654a7020793cdd7cab2362a9a45a2264dfb3;hb=2172ce055533d5865d58538ee00bf609e59b0f99;hp=bdbe24d394e098f66f0ebcb175c984d6f174ed11;hpb=c08c30e78fdbbde7e5823b26303b0dded3a4c1cf;p=cs356-p1-elevator.git diff --git a/positionlabel.cpp b/positionlabel.cpp index bdbe24d..97a2654 100644 --- a/positionlabel.cpp +++ b/positionlabel.cpp @@ -1,10 +1,14 @@ #include "positionlabel.hpp" PositionLabel::PositionLabel (int elevator, const std::string text) - : Gtk::Label (text) + : Gtk::Table (1, 2) + , label_(text) + , direction_img_(Gtk::Stock::YES, Gtk::ICON_SIZE_BUTTON) , elevator_(elevator) { - // Intentionally Left Empty + attach (label_, 0, 1, 0, 1); + attach (direction_img_, 1, 2, 0, 1); + show (); } int PositionLabel::getElevatorNumber () const @@ -12,4 +16,33 @@ int PositionLabel::getElevatorNumber () const return elevator_; } +void PositionLabel::update_position (float floor, Direction direction) +{ + switch (direction) + { + case UP: + direction_img_.set(Gtk::Stock::GO_UP, Gtk::ICON_SIZE_BUTTON); + break; + case DOWN: + direction_img_.set(Gtk::Stock::GO_DOWN, Gtk::ICON_SIZE_BUTTON); + break; + case IDLE: + direction_img_.set(Gtk::Stock::YES, Gtk::ICON_SIZE_BUTTON); + break; + default: + std::cout << "Bad direction in PositionLabel->update_position(" << floor + << ", " << direction << ")" << std::endl; + break; + } + + std::ostringstream str; + + // Generate the text + str << std::setiosflags (std::ios_base::showpoint | std::ios_base::fixed) + << std::setprecision(1) << floor; + + label_.set_text (str.str()); +} + + /* vim: set ts=4 sts=4 sw=4 noet tw=112: */