Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/Makefile.am4
-rw-r--r--src/ui/button.cc14
-rw-r--r--src/ui/container.cc17
-rw-r--r--src/ui/container.h2
-rw-r--r--src/ui/definitions.h2
-rw-r--r--src/ui/inputbox.cc (renamed from src/ui/input.cc)20
-rw-r--r--src/ui/inputbox.h (renamed from src/ui/input.h)14
-rw-r--r--src/ui/menu.h2
-rw-r--r--src/ui/palette.cc27
-rw-r--r--src/ui/palette.h16
-rw-r--r--src/ui/ui.cc68
-rw-r--r--src/ui/ui.h16
-rw-r--r--src/ui/widget.cc4
-rw-r--r--src/ui/widget.h2
-rw-r--r--src/ui/window.cc8
-rw-r--r--src/ui/window.h3
16 files changed, 164 insertions, 55 deletions
diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am
index a68c307..4bfad3d 100644
--- a/src/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -7,9 +7,9 @@ else
noinst_LTLIBRARIES = libui.la
endif
-noinst_HEADERS = bitmap.h button.h container.h definitions.h font.h input.h label.h \
+noinst_HEADERS = bitmap.h button.h container.h definitions.h font.h inputbox.h label.h \
menu.h paint.h palette.h ui.h widget.h window.h
-libui_la_SOURCES = bitmap.cc button.cc container.cc font.cc input.cc label.cc \
+libui_la_SOURCES = bitmap.cc button.cc container.cc font.cc inputbox.cc label.cc \
menu.cc paint.cc palette.cc ui.cc widget.cc window.cc
libui_la_LDFLAGS = -avoid-version -no-undefined
diff --git a/src/ui/button.cc b/src/ui/button.cc
index 08fd0e9..e36d036 100644
--- a/src/ui/button.cc
+++ b/src/ui/button.cc
@@ -71,18 +71,18 @@ void Button::draw_text()
}
bool Button::on_keypress(const int key, const unsigned int modifier)
-{
- return false;
-}
-
-bool Button::on_keyrelease(const int key, const unsigned int modifier)
-{
+{
if (key == 512 + SDL_BUTTON_LEFT) {
core::cmd() << button_command << std::endl;
audio::play("ui/button");
return true;
}
-
+
+ return false;
+}
+
+bool Button::on_keyrelease(const int key, const unsigned int modifier)
+{
return false;
}
diff --git a/src/ui/container.cc b/src/ui/container.cc
index 5a12e8e..37fbea8 100644
--- a/src/ui/container.cc
+++ b/src/ui/container.cc
@@ -6,6 +6,7 @@
#include "ui/container.h"
+#include "ui/paint.h"
namespace ui
{
@@ -31,9 +32,8 @@ void Container::resize()
{
float w = container_childsize.width() * 1.5f;
float h = children().size() * (container_childsize.height() + margin()) + container_childsize.height();
-
set_size(w, h);
-
+
const float x = container_childsize.width() * 0.25f;
float y = container_childsize.height() * 0.5f;
@@ -56,4 +56,17 @@ void Container::set_margin(const float margin)
container_margin = margin;
}
+void Container::draw_border()
+{
+ if (!border())
+ return;
+
+ if(focus()) {
+ paint::color(palette()->foreground());
+ } else {
+ paint::color(palette()->border());
+ }
+ paint::border(global_location(), size());
+}
+
}
diff --git a/src/ui/container.h b/src/ui/container.h
index ae97bdf..5556759 100644
--- a/src/ui/container.h
+++ b/src/ui/container.h
@@ -27,6 +27,8 @@ public:
inline float margin() const { return container_margin; }
protected:
+ virtual void draw_border();
+
virtual void resize();
private:
diff --git a/src/ui/definitions.h b/src/ui/definitions.h
index b9b4e3c..ea3e040 100644
--- a/src/ui/definitions.h
+++ b/src/ui/definitions.h
@@ -23,6 +23,8 @@ enum Alignment {
AlignCenter = AlignHCenter | AlignVCenter
};
+const float pointer_size = 48.0f;
+
}
#endif // __INCLUDED_UI_DEFINITIONS_H__
diff --git a/src/ui/input.cc b/src/ui/inputbox.cc
index 8113354..30cae3b 100644
--- a/src/ui/input.cc
+++ b/src/ui/inputbox.cc
@@ -1,10 +1,10 @@
/*
- ui/input.cc
+ ui/inputbox.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
-#include "ui/input.h"
+#include "ui/inputbox.h"
#include "ui/paint.h"
#include "auxiliary/functions.h"
#include "core/core.h"
@@ -12,7 +12,7 @@
namespace ui
{
-Input::Input(Widget *parent) : Widget(parent)
+InputBox::InputBox(Widget *parent) : Widget(parent)
{
input_text.clear();
input_pos = 0;
@@ -22,22 +22,22 @@ Input::Input(Widget *parent) : Widget(parent)
set_border(false);
}
-Input::~Input()
+InputBox::~InputBox()
{
}
-void Input::clear()
+void InputBox::clear()
{
input_text.clear();
input_pos = 0;
}
-void Input::set_text(std::string const &text)
+void InputBox::set_text(std::string const &text)
{
input_text.assign(text);
input_pos = input_text.size();
}
-void Input::set_text(const char *text)
+void InputBox::set_text(const char *text)
{
if (text)
input_text.assign(text);
@@ -46,7 +46,7 @@ void Input::set_text(const char *text)
input_pos = input_text.size();
}
-void Input::draw()
+void InputBox::draw()
{
draw_background();
draw_border();
@@ -114,7 +114,7 @@ void Input::draw()
}
}
-bool Input::on_keypress(const int key, const unsigned int modifier)
+bool InputBox::on_keypress(const int key, const unsigned int modifier)
{
switch (key) {
case SDLK_TAB:
@@ -174,7 +174,7 @@ bool Input::on_keypress(const int key, const unsigned int modifier)
return false;
}
-bool Input::on_keyrelease(const int key, const unsigned int modifier)
+bool InputBox::on_keyrelease(const int key, const unsigned int modifier)
{
return false;
}
diff --git a/src/ui/input.h b/src/ui/inputbox.h
index 214f63e..557ca6c 100644
--- a/src/ui/input.h
+++ b/src/ui/inputbox.h
@@ -1,11 +1,11 @@
/*
- ui/input.h
+ ui/inputbox.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
-#ifndef __INCLUDED_UI_INPUT_H__
-#define __INCLUDED_UI_INPUT_H__
+#ifndef __INCLUDED_UI_INPUTBOX_H__
+#define __INCLUDED_UI_INPUTBOX_H__
#include "ui/widget.h"
@@ -13,11 +13,11 @@ namespace ui
{
/// text input widget
-class Input : public Widget
+class InputBox : public Widget
{
public:
- Input(Widget *parent);
- ~Input();
+ InputBox(Widget *parent);
+ ~InputBox();
/// set the text displayed by the label
void set_text(std::string const &text);
@@ -51,5 +51,5 @@ private:
}
-#endif // __INCLUDED_UI_INPUT_H__
+#endif // __INCLUDED_UI_INPUTBOX_H__
diff --git a/src/ui/menu.h b/src/ui/menu.h
index a909e20..e3a853a 100644
--- a/src/ui/menu.h
+++ b/src/ui/menu.h
@@ -36,7 +36,7 @@ public:
/// add a button with a command
Button *add_button(char const *text=0, char const *command=0);
-
+
protected:
/// resize event
virtual void resize();
diff --git a/src/ui/palette.cc b/src/ui/palette.cc
index 20d1e93..3a9dc78 100644
--- a/src/ui/palette.cc
+++ b/src/ui/palette.cc
@@ -24,6 +24,33 @@ Palette::~Palette()
{
}
+const math::Color &Palette::color(Color palettecolor) const
+{
+ switch(palettecolor) {
+ case Foreground:
+ return foreground();
+ break;
+ case Background:
+ return background();
+ break;
+ case Highlight:
+ return highlight();
+ break;
+ case Border:
+ return border();
+ break;
+ case Pointer:
+ return pointer();
+ break;
+ case Active:
+ return active();
+ break;
+ default:
+ return foreground();
+ break;
+ }
+}
+
void Palette::set_foreground(math::Color const &color)
{
palette_foreground.assign(color);
diff --git a/src/ui/palette.h b/src/ui/palette.h
index 9d27f95..41eee03 100644
--- a/src/ui/palette.h
+++ b/src/ui/palette.h
@@ -19,6 +19,8 @@ public:
Palette();
~Palette();
+ enum Color { Foreground=0, Background=1, Highlight=2, Border=3, Pointer=4, Active=5 };
+
void set_foreground(math::Color const &color);
void set_highlight(math::Color const &color);
@@ -31,29 +33,31 @@ public:
void set_active(math::Color const &color);
- inline math::Color const &foreground() const {
+ inline const math::Color &foreground() const {
return palette_foreground;
}
- inline math::Color const &highlight() const {
+ inline const math::Color &highlight() const {
return palette_highlight;
}
- inline math::Color const &background() const {
+ inline const math::Color &background() const {
return palette_background;
}
- inline math::Color const &border() const {
+ inline const math::Color &border() const {
return palette_border;
}
- inline math::Color const &pointer() const {
+ inline const math::Color &pointer() const {
return palette_pointer;
}
- inline math::Color const &active() const {
+ inline const math::Color &active() const {
return palette_active;
}
+
+ const math::Color &color(Palette::Color palettecolor) const;
private:
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index baedd38..1ecfbb1 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -7,13 +7,16 @@
#include <string>
#include <sstream>
+#include "audio/audio.h"
#include "auxiliary/functions.h"
#include "core/core.h"
#include "filesystem/filesystem.h"
+#include "render/gl.h"
#include "sys/sys.h"
#include "ui/button.h"
#include "ui/label.h"
#include "ui/menu.h"
+#include "ui/paint.h"
#include "ui/ui.h"
#include "ui/widget.h"
@@ -204,6 +207,9 @@ UI::UI() : Window(0)
ui_mouse_focus = this;
ui_input_focus = this;
set_focus();
+
+ mouse_pointer_color = Palette::Pointer;
+ mouse_pointer_bitmap.assign("pointer");
}
UI::~UI()
@@ -386,7 +392,9 @@ void UI::show_menu(const char *label)
ui_active_menu = menu;
ui_active_menu->event_resize();
- ui_active_menu->show();
+ ui_active_menu->show();
+
+ set_pointer("pointer");
} else {
con_warn << "Unknown window '" << label << "'" << std::endl;
}
@@ -418,6 +426,9 @@ void UI::frame()
}
event_draw();
+
+ if (visible())
+ draw_pointer();
}
/* -- global event handlers ---------------------------------------- */
@@ -453,21 +464,18 @@ bool UI::input_key(const bool pressed, const int key, const unsigned int modifie
return handled;
}
-/* -- event handlers ----------------------------------------------- */
-/*
- These functions handle events for this widget only. They are
- the fallback input handlers
-*/
bool UI::on_keypress(const int key, const unsigned int modifier)
{
switch( key ) {
case SDLK_ESCAPE:
if (active()) {
- previous_menu();
+ hide_menu();
+ audio::play("ui/menu");
} else {
if (core::application()->connected()) {
show_menu("game");
+ audio::play("ui/menu");
}
}
return true;
@@ -484,5 +492,51 @@ bool UI::on_keyrelease(const int key, const unsigned int modifier)
return false;
}
+void UI::set_pointer(const char *pointerbitmap, const Palette::Color color, const bool animated)
+{
+ if (!pointerbitmap) {
+ mouse_pointer_bitmap.clear();
+ } else {
+ mouse_pointer_bitmap.assign(pointerbitmap);
+ }
+ mouse_pointer_animated = animated;
+ mouse_pointer_color = color;
+}
+
+void UI::draw_pointer()
+{
+ if (!mouse_pointer_bitmap.size())
+ return;
+
+ math::Color c(palette()->color(mouse_pointer_color));
+ if (mouse_pointer_animated) {
+ c.a = 1;
+ } else {
+ c.a = 0.5f;
+ }
+ paint::color(c);
+ math::Vector2f pos(mouse_cursor.x - pointer_size * 0.5f, mouse_cursor.y - pointer_size * 0.5f);
+ math::Vector2f s(pointer_size, pointer_size);
+
+ std::string texture("pointers/");
+ texture.append(mouse_pointer_bitmap);
+
+ if (mouse_pointer_animated) {
+ render::gl::push();
+ render::gl::translate(mouse_cursor.x, mouse_cursor.y, 0);
+
+ float angle = core::application()->time()* 0.75f - floorf(core::application()->time() * 0.75f);
+ angle *= 360.0f;
+ render::gl::rotate(angle, math::Vector3f(0, 0, 1.0f));
+ render::gl::translate(-mouse_cursor.x, -mouse_cursor.y, 0);
+ }
+
+ paint::bitmap(pos, s, texture);
+
+ if (mouse_pointer_animated) {
+ render::gl::pop();
+ }
+}
+
}
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 8fa32c2..24f9793 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -62,7 +62,7 @@ public:
/// receive global key input
bool input_key(const bool pressed, const int key, const unsigned int modifier);
-
+
/// run a user interface frame
void frame();
@@ -77,7 +77,12 @@ public:
inline const Font *font_large() const {
return ui_font_large;
}
-
+
+ /* -- mouse pointer ---------------------------------------- */
+
+ /// set mouse pointer bitmap
+ void set_pointer(const char *pointerbitmap=0, const Palette::Color color = Palette::Highlight,const bool animated = false);
+
protected:
typedef std::list<Window *> Menus;
@@ -95,6 +100,8 @@ protected:
virtual bool on_keyrelease(const int key, const unsigned int modifier);
private:
+ void draw_pointer();
+
Palette *ui_palette;
Font *ui_font_small;
Font *ui_font_large;
@@ -106,7 +113,10 @@ private:
Menus ui_menus;
/// TODO move to separate object to handle mouse cursor drawing
- math::Vector2f mouse_cursor;
+ math::Vector2f mouse_cursor;
+ std::string mouse_pointer_bitmap;
+ Palette::Color mouse_pointer_color;
+ bool mouse_pointer_animated;
};
/// initialize the user interface
diff --git a/src/ui/widget.cc b/src/ui/widget.cc
index 24dfe5c..606c4ab 100644
--- a/src/ui/widget.cc
+++ b/src/ui/widget.cc
@@ -209,6 +209,7 @@ void Widget::set_width(float const w)
{
widget_size.x = w;
}
+
void Widget::set_height(float const h)
{
widget_size.y = h;
@@ -339,10 +340,11 @@ void Widget::event_draw()
void Widget::event_resize()
{
+ resize();
+
for (Children::iterator it = widget_children.begin(); it != widget_children.end(); it++) {
(*it)->event_resize();
}
- resize();
}
/* -- event handlers ----------------------------------------------- */
diff --git a/src/ui/widget.h b/src/ui/widget.h
index 41ad795..ef386c0 100644
--- a/src/ui/widget.h
+++ b/src/ui/widget.h
@@ -200,7 +200,7 @@ protected:
/// find the widget that has input focus
virtual Widget *find_input_focus();
-
+
/// find widget that has mosue focus
/** @param cursor mouse cursor position relative to this widget's location
*/
diff --git a/src/ui/window.cc b/src/ui/window.cc
index 3015a10..9ae9ec5 100644
--- a/src/ui/window.cc
+++ b/src/ui/window.cc
@@ -50,12 +50,8 @@ void Window::draw_border()
if (!border())
return;
- if(focus()) {
- paint::color(palette()->foreground());
- } else {
- paint::color(palette()->border());
- }
- paint::border(global_location(), size());
+ paint::color(palette()->border());
+ paint::border(global_location(), size());
}
}
diff --git a/src/ui/window.h b/src/ui/window.h
index 412d1f1..2a077ff 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -20,8 +20,6 @@ public:
Window(Widget *parent=0);
~Window();
- virtual void draw_border();
-
/// set the label of the previous window
void set_previous(Window *previous);
@@ -38,6 +36,7 @@ public:
}
protected:
+ virtual void draw_border();
std::string window_previous;
};