From 82992a9b16d64104dd28d42e97cc118a75fded86 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 8 Dec 2010 20:19:21 +0000 Subject: Added clock. --- src/client/infowidget.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/client/infowidget.cc') 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()); +} + } -- cgit v1.2.3