diff options
Diffstat (limited to 'src/client/infowidget.cc')
-rw-r--r-- | src/client/infowidget.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/client/infowidget.cc b/src/client/infowidget.cc index 062baf4..393734c 100644 --- a/src/client/infowidget.cc +++ b/src/client/infowidget.cc @@ -184,5 +184,44 @@ void KeyInfoWidget::draw() } } +/* -- ClockInfoWidget ---------------------------------------------- */ + +ClockInfoWidget::ClockInfoWidget(ui::Widget *parent) : ui::Widget(parent) +{ + set_label("clock"); + set_border(false); + set_background(false); + + clock_mode = ClockOff; +} + +void ClockInfoWidget::draw() +{ + if (mode() == ClockOff) + return; + + std::ostringstream clockstr; + const unsigned long current_time = sys::time(); + unsigned long hours = current_time / 3600; + unsigned long minutes = (current_time % 3600) / 60; + //unsigned long seconds = current_time % 60; + + clockstr << std::setfill('0') << std::setw(2); + if (mode() == Clock12Hours) { + if (hours > 12) { + clockstr << hours-12 << ":" << std::setfill('0') << std::setw(2) << minutes << "pm"; + } else { + if (hours == 0) + hours +=12; + clockstr << hours << ":" << std::setfill('0') << std::setw(2) << minutes << "am"; + } + } else { + clockstr << " " << hours << ":" << std::setfill('0') << std::setw(2) << minutes; + } + + ui::Paint::set_color(palette()->foreground()); + ui::Paint::draw_text(global_location(), font(), clockstr.str()); +} + } |