From b3083a4fe57cc99c6972180a40091001cb209ad7 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 10 May 2009 15:33:16 +0000 Subject: added disabled ui palette color, added dock and launch buttons --- src/ui/iconbutton.cc | 29 ++++++++++++++++++++++------- src/ui/iconbutton.h | 38 +++++++++++++++++++++++++++----------- src/ui/palette.cc | 4 ++++ src/ui/palette.h | 16 ++++++++++++++-- src/ui/ui.cc | 4 ++++ 5 files changed, 71 insertions(+), 20 deletions(-) (limited to 'src/ui') diff --git a/src/ui/iconbutton.cc b/src/ui/iconbutton.cc index 1999072..2c4661e 100644 --- a/src/ui/iconbutton.cc +++ b/src/ui/iconbutton.cc @@ -21,9 +21,10 @@ IconButton::IconButton(Widget *parent, const char *icon, const char *command) : { set_label("iconbutton"); set_background(false); - set_border(true); + set_border(false); set_command(command); set_icon(icon); + iconbutton_enabled = true; } IconButton::~IconButton() @@ -62,22 +63,35 @@ void IconButton::set_icon(const std::string &icon) iconbutton_icon.assign(icon); } +void IconButton::enable(bool enabled) +{ + iconbutton_enabled = enabled; +} + +void IconButton::disable(bool disabled) +{ + iconbutton_enabled = !disabled; +} + void IconButton::draw() { if (!icon().size()) return; - - if (has_mouse_focus()) + + if (disabled()) { + paint::color(palette()->disabled()); + } else if (has_mouse_focus()) { paint::color(palette()->highlight()); - else + } else { paint::color(palette()->foreground()); + } paint::bitmap(location(), size(), icon()); } void IconButton::draw_border() { - if (has_mouse_focus()) { + if (enabled() && has_mouse_focus()) { math::Color color(palette()->foreground()); float t = core::application()->time(); t = t - floorf(t); @@ -92,7 +106,7 @@ void IconButton::draw_border() bool IconButton::on_keypress(const int key, const unsigned int modifier) { if (key == 512 + SDL_BUTTON_LEFT) { - if (iconbutton_command.size()) { + if (enabled() && iconbutton_command.size()) { core::cmd() << iconbutton_command << std::endl; audio::play("ui/button"); } @@ -109,7 +123,8 @@ bool IconButton::on_keyrelease(const int key, const unsigned int modifier) void IconButton::on_mouseover(const math::Vector2f &cursor) { - audio::play("ui/select"); + if (enabled()) + audio::play("ui/select"); } } diff --git a/src/ui/iconbutton.h b/src/ui/iconbutton.h index d545697..10b073f 100644 --- a/src/ui/iconbutton.h +++ b/src/ui/iconbutton.h @@ -18,29 +18,44 @@ public: IconButton(Widget *parent, const char *icon=0, const char *command=0); ~IconButton(); + /// the command this button executes + inline const std::string & command() const { + return iconbutton_command; + } + + /// the icon texture + inline const std::string & icon() const { + return iconbutton_icon; + } + + /// enabled or disabled + inline const bool enabled() const { + return iconbutton_enabled; + } + + /// enabled or disabled + inline const bool disabled() const { + return !iconbutton_enabled; + } + + /// enable or disable the button + void enable(bool enabled=true); + + /// enable or disable the button + void disable(bool disabled=true); + /// set the command this button will execute void set_command(const std::string &command); /// set the command this button will execute void set_command(const char *command); - /// the command this button executes - inline const std::string & command() const { - return iconbutton_command; - } - - /// set the icon texture void set_icon(const std::string & icon); /// set the icon texture void set_icon(const char *icon); - /// the icon texture - inline const std::string & icon() const { - return iconbutton_icon; - } - /// print button description virtual void print(const size_t indent) const; @@ -63,6 +78,7 @@ protected: private: std::string iconbutton_command; std::string iconbutton_icon; + bool iconbutton_enabled; }; } diff --git a/src/ui/palette.cc b/src/ui/palette.cc index 01fd99a..2dec462 100644 --- a/src/ui/palette.cc +++ b/src/ui/palette.cc @@ -16,6 +16,7 @@ Palette::Palette() : palette_border(0.0f, 0.8f, 0.0f, 0.5f), palette_text(0.75f, 1.0f), palette_highlight(1.0f, 1.0f, 0.5f), + palette_disabled(0.5f, 0.5f, 0.5f, 1.0f), palette_pointer(0.0f, 0.75f, 0.0f, 1.0f), palette_active(0.0f, 1.0f, 0.0f, 1.0f), palette_debug(0.50f, 0.75f), @@ -50,6 +51,9 @@ const math::Color &Palette::color(Color palettecolor) const case Highlight: return highlight(); break; + case Disabled: + return disabled(); + break; case Pointer: return pointer(); break; diff --git a/src/ui/palette.h b/src/ui/palette.h index 1aabc59..61a0b72 100644 --- a/src/ui/palette.h +++ b/src/ui/palette.h @@ -24,8 +24,8 @@ public: ~Palette(); /// color index - enum Color { Foreground=0, Background=1, Border=2, Text=3, Highlight=4, Pointer=5, Active=6, Debug=7, Mission=8, - Bold=9, Fancy=10, Warning=11, Error=12 }; + enum Color { Foreground=0, Background=1, Border=2, Text=3, Highlight=4, Disabled=5, Pointer=6, Active=7, + Debug=8, Mission=9, Bold=10, Fancy=11, Warning=12, Error=13 }; /* ---- mutators ------------------------------------------- */ @@ -59,6 +59,12 @@ public: palette_highlight.assign(color); } + /// set disabled color + inline void set_disabled(const math::Color &color) + { + palette_disabled.assign(color); + } + /// set pointer color inline void set_pointer(const math::Color &color) { @@ -134,6 +140,11 @@ public: return palette_highlight; } + /// disabled color + inline const math::Color &disabled() const { + return palette_disabled; + } + /// pointer color inline const math::Color &pointer() const { return palette_pointer; @@ -184,6 +195,7 @@ private: math::Color palette_border; math::Color palette_text; math::Color palette_highlight; + math::Color palette_disabled; math::Color palette_pointer; math::Color palette_active; math::Color palette_debug; diff --git a/src/ui/ui.cc b/src/ui/ui.cc index 55702c3..b7d1155 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -304,9 +304,13 @@ void UI::load_settings() continue; } else if (ini.got_key_color("text", color)) { ui_palette->set_text(color); + continue; } else if (ini.got_key_color("highlight", color)) { ui_palette->set_highlight(color); continue; + } else if (ini.got_key_color("disabled", color)) { + ui_palette->set_disabled(color); + continue; } else if (ini.got_key_color("pointer", color)) { ui_palette->set_pointer(color); continue; -- cgit v1.2.3