Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-04-26 15:51:50 +0000
committerStijn Buys <ingar@osirion.org>2009-04-26 15:51:50 +0000
commit8861bf21e9821f7adcbbafcb9f72e0f1b8f59344 (patch)
tree88ebec59d2302f7b63d8b6a4decd87d8e418f4be /src/ui/iconbutton.cc
parent5c1e2000231e0348ad155d304e447aad1ff309af (diff)
added ui::IconButton class
Diffstat (limited to 'src/ui/iconbutton.cc')
-rw-r--r--src/ui/iconbutton.cc115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/ui/iconbutton.cc b/src/ui/iconbutton.cc
new file mode 100644
index 0000000..1999072
--- /dev/null
+++ b/src/ui/iconbutton.cc
@@ -0,0 +1,115 @@
+/*
+ ui/iconbutton.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include <cmath>
+
+#include "audio/audio.h"
+#include "auxiliary/functions.h"
+#include "core/application.h"
+#include "core/commandbuffer.h"
+#include "sys/sys.h"
+#include "ui/paint.h"
+#include "ui/iconbutton.h"
+
+namespace ui
+{
+
+IconButton::IconButton(Widget *parent, const char *icon, const char *command) : Widget(parent)
+{
+ set_label("iconbutton");
+ set_background(false);
+ set_border(true);
+ set_command(command);
+ set_icon(icon);
+}
+
+IconButton::~IconButton()
+{
+}
+
+void IconButton::print(const size_t indent) const
+{
+ std::string marker("");
+ con_print << aux::pad_left(marker, indent*2) << label() << " \"" << icon() << "\" \"" << command() << "\"" << std::endl;
+}
+
+void IconButton::set_command(const char *command)
+{
+ if (command)
+ iconbutton_command.assign(command);
+ else
+ iconbutton_command.clear();
+}
+
+void IconButton::set_command(const std::string &command)
+{
+ iconbutton_command.assign(command);
+}
+
+void IconButton::set_icon(const char *icon)
+{
+ if (icon)
+ iconbutton_icon.assign(icon);
+ else
+ iconbutton_icon.clear();
+}
+
+void IconButton::set_icon(const std::string &icon)
+{
+ iconbutton_icon.assign(icon);
+}
+
+void IconButton::draw()
+{
+ if (!icon().size())
+ return;
+
+ if (has_mouse_focus())
+ paint::color(palette()->highlight());
+ else
+ paint::color(palette()->foreground());
+
+ paint::bitmap(location(), size(), icon());
+}
+
+void IconButton::draw_border()
+{
+ if (has_mouse_focus()) {
+ math::Color color(palette()->foreground());
+ float t = core::application()->time();
+ t = t - floorf(t);
+ if (t > 0.5)
+ t = 1 - t;
+ color.a = 0.5f + t;
+ paint::color(color);
+ paint::border(global_location(), size());
+ }
+}
+
+bool IconButton::on_keypress(const int key, const unsigned int modifier)
+{
+ if (key == 512 + SDL_BUTTON_LEFT) {
+ if (iconbutton_command.size()) {
+ core::cmd() << iconbutton_command << std::endl;
+ audio::play("ui/button");
+ }
+ return true;
+ }
+
+ return false;
+}
+
+bool IconButton::on_keyrelease(const int key, const unsigned int modifier)
+{
+ return false;
+}
+
+void IconButton::on_mouseover(const math::Vector2f &cursor)
+{
+ audio::play("ui/select");
+}
+
+}