diff options
author | Stijn Buys <ingar@osirion.org> | 2010-12-08 20:19:21 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-12-08 20:19:21 +0000 |
commit | 82992a9b16d64104dd28d42e97cc118a75fded86 (patch) | |
tree | a7c30cedd613196c06df3fc04f6bce015c3927c1 /src/client/infowidget.cc | |
parent | 1124a81de517375a012b89bf83462c091d472cab (diff) |
Added clock.
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()); +} + } |