diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/infowidget.cc | 39 | ||||
-rw-r--r-- | src/client/infowidget.h | 29 | ||||
-rw-r--r-- | src/client/input.cc | 5 | ||||
-rw-r--r-- | src/client/input.h | 6 | ||||
-rw-r--r-- | src/client/video.cc | 4 | ||||
-rw-r--r-- | src/client/video.h | 1 | ||||
-rw-r--r-- | src/client/worldview.cc | 14 | ||||
-rw-r--r-- | src/client/worldview.h | 2 |
8 files changed, 94 insertions, 6 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()); +} + } diff --git a/src/client/infowidget.h b/src/client/infowidget.h index 48d1c9a..e773ef4 100644 --- a/src/client/infowidget.h +++ b/src/client/infowidget.h @@ -52,12 +52,37 @@ private: class KeyInfoWidget : public ui::Widget { public: - // default constructor + /// default constructor KeyInfoWidget(ui::Widget *parent = 0); protected: - // draw keypress events + /// draw keypress events + virtual void draw(); +}; + +/// a widget to show keypress events +class ClockInfoWidget : public ui::Widget +{ +public: + /// clock mode + enum Mode {ClockOff=0, Clock24Hours=1, Clock12Hours=2}; + + /// default constructor + ClockInfoWidget(ui::Widget *parent = 0); + + inline void set_mode(const Mode mode) { + clock_mode = mode; + } + + inline const Mode mode() const { + return clock_mode; + } + +protected: + /// draw the current time virtual void draw(); + + Mode clock_mode; }; } diff --git a/src/client/input.cc b/src/client/input.cc index 3741e15..b6199c6 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -558,9 +558,8 @@ void key_pressed(Key *key) ui::console()->toggle(); return; - } - - if (ui::root()->input_key(true, Keyboard::translate_keysym(key->sym(), keyboard_modifiers), keyboard_modifiers)) { + + } else if (ui::root()->input_key(true, Keyboard::translate_keysym(key->sym(), keyboard_modifiers), keyboard_modifiers)) { return; } else if (key->bind(modifier()).size() && core::application()->connected()) { diff --git a/src/client/input.h b/src/client/input.h index 394e521..2565189 100644 --- a/src/client/input.h +++ b/src/client/input.h @@ -13,6 +13,12 @@ namespace client { +extern core::Cvar *input_mousecontrol; +extern core::Cvar *input_keydelay; +extern core::Cvar *input_keyrepeat; +extern core::Cvar *input_mousedelay; +extern core::Cvar *input_grab; + namespace input { diff --git a/src/client/video.cc b/src/client/video.cc index 72b72da..84bbe52 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -36,6 +36,7 @@ core::Cvar *draw_ui = 0; core::Cvar *draw_stats = 0; core::Cvar *draw_devinfo = 0; core::Cvar *draw_keypress = 0; +core::Cvar *draw_clock = 0; namespace video { @@ -86,6 +87,9 @@ bool init() draw_keypress = core::Cvar::get("draw_keypress", "0", core::Cvar::Archive); draw_keypress->set_info("[bool] draw keypress key names"); + + draw_clock = core::Cvar::get("draw_clock", "0", core::Cvar::Archive); + draw_clock->set_info("[int] draw clock (0=Off, 1=24hr, 2=12hr)"); draw_ui = core::Cvar::get("draw_ui", "1", core::Cvar::Archive); draw_ui->set_info("[bool] draw the user interface"); diff --git a/src/client/video.h b/src/client/video.h index 93c3ce0..61cb9df 100644 --- a/src/client/video.h +++ b/src/client/video.h @@ -55,6 +55,7 @@ extern core::Cvar *draw_ui; extern core::Cvar *draw_stats; extern core::Cvar *draw_devinfo; extern core::Cvar *draw_keypress; +extern core::Cvar *draw_clock; } // namespace client diff --git a/src/client/worldview.cc b/src/client/worldview.cc index 35cada2..56ba77e 100644 --- a/src/client/worldview.cc +++ b/src/client/worldview.cc @@ -23,6 +23,7 @@ WorldView::WorldView(ui::Widget *parent) : ui::Widget(parent) view_devinfo = new DevInfoWidget(this); view_statsinfo = new StatsInfoWidget(this); view_keyinfo = new KeyInfoWidget(this); + view_clock = new ClockInfoWidget(this); view_playerview = new PlayerView(this); view_playerview->raise(); @@ -51,6 +52,10 @@ void WorldView::resize() // reposition stats widget view_statsinfo->set_size(font()->width()*12, font()->height()*5); view_statsinfo->set_location(width() - view_statsinfo->width() - smallmargin, smallmargin); + + // reposition clock + view_clock->set_size(font()->width()*7, font()->height()); + view_clock->set_location(width() - view_clock->width() - smallmargin, view_statsinfo->bottom() + smallmargin); // reposition keypress widget view_keyinfo->set_size(font()->width()*12, font()->height()*1); @@ -72,10 +77,17 @@ void WorldView::draw() { // worldview is only drawn when the application is connected // and the loader screen is not shown - view_devinfo->set_visible(draw_devinfo->value() ? true : false); view_statsinfo->set_visible(draw_stats->value() ? true : false); view_keyinfo->set_visible(draw_keypress->value() ? true : false); + if (draw_clock->value() <= 0) { + view_clock->set_mode(ClockInfoWidget::ClockOff); + } else if (draw_clock->value() >= 2) { + view_clock->set_mode(ClockInfoWidget::Clock12Hours); + } else { + view_clock->set_mode(ClockInfoWidget::Clock24Hours); + } + if (ui::root()->active() || !core::game()->interactive() || !core::localcontrol() || (core::localplayer()->view() && !core::localplayer()->view()->menus().size())) { view_playerview->hide(); diff --git a/src/client/worldview.h b/src/client/worldview.h index 9def8c5..3012815 100644 --- a/src/client/worldview.h +++ b/src/client/worldview.h @@ -37,8 +37,10 @@ private: DevInfoWidget *view_devinfo; StatsInfoWidget *view_statsinfo; KeyInfoWidget *view_keyinfo; + ClockInfoWidget *view_clock; Notifications *view_notify; PlayerView *view_playerview; + }; } |