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.am8
-rw-r--r--src/ui/button.cc7
-rw-r--r--src/ui/button.h4
-rw-r--r--src/ui/container.cc3
-rw-r--r--src/ui/definitions.h5
-rw-r--r--src/ui/inputbox.cc55
-rw-r--r--src/ui/inputbox.h13
-rw-r--r--src/ui/label.cc9
-rw-r--r--src/ui/label.h5
-rw-r--r--src/ui/paint.cc77
-rw-r--r--src/ui/paint.h18
-rw-r--r--src/ui/palette.cc25
-rw-r--r--src/ui/palette.h18
-rw-r--r--src/ui/scrollpane.cc172
-rw-r--r--src/ui/scrollpane.h47
-rw-r--r--src/ui/ui.cc9
-rw-r--r--src/ui/ui.h7
-rw-r--r--src/ui/widget.cc34
-rw-r--r--src/ui/widget.h4
-rw-r--r--src/ui/window.cc3
20 files changed, 408 insertions, 115 deletions
diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am
index 4bfad3d..a3084af 100644
--- a/src/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -8,8 +8,8 @@ noinst_LTLIBRARIES = libui.la
endif
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
+ menu.h paint.h palette.h scrollpane.h ui.h widget.h window.h
-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
+libui_la_SOURCES = bitmap.cc button.cc container.cc font.cc inputbox.cc \
+ label.cc menu.cc paint.cc palette.cc scrollpane.cc ui.cc widget.cc window.cc
+libui_la_LDFLAGS = -avoid-version -no-undefined \ No newline at end of file
diff --git a/src/ui/button.cc b/src/ui/button.cc
index e36d036..856c165 100644
--- a/src/ui/button.cc
+++ b/src/ui/button.cc
@@ -46,9 +46,6 @@ void Button::set_command(const std::string &command)
void Button::draw_border()
{
- if (!border())
- return;
-
if (has_mouse_focus())
paint::color(palette()->foreground());
else
@@ -57,7 +54,7 @@ void Button::draw_border()
paint::border(global_location(), size());
}
-void Button::draw_text()
+void Button::draw()
{
if (!text().size())
return;
@@ -67,7 +64,7 @@ void Button::draw_text()
else
paint::color(palette()->foreground());
- paint::text(global_location(), size(), font(), text(), alignment());
+ paint::label(global_location(), size(), font(), text(), alignment());
}
bool Button::on_keypress(const int key, const unsigned int modifier)
diff --git a/src/ui/button.h b/src/ui/button.h
index b1bb522..24097ae 100644
--- a/src/ui/button.h
+++ b/src/ui/button.h
@@ -46,8 +46,8 @@ protected:
/// draw the button border
virtual void draw_border();
- /// draw the button text
- virtual void draw_text();
+ /// draw the button
+ virtual void draw();
private:
std::string button_command;
diff --git a/src/ui/container.cc b/src/ui/container.cc
index 37fbea8..977ff4d 100644
--- a/src/ui/container.cc
+++ b/src/ui/container.cc
@@ -58,9 +58,6 @@ void Container::set_margin(const float margin)
void Container::draw_border()
{
- if (!border())
- return;
-
if(focus()) {
paint::color(palette()->foreground());
} else {
diff --git a/src/ui/definitions.h b/src/ui/definitions.h
index ea3e040..e04082f 100644
--- a/src/ui/definitions.h
+++ b/src/ui/definitions.h
@@ -7,6 +7,9 @@
#ifndef __INCLUDED_UI_DEFINITIONS_H__
#define __INCLUDED_UI_DEFINITIONS_H__
+#include <string>
+#include <deque>
+
namespace ui
{
@@ -25,6 +28,8 @@ enum Alignment {
const float pointer_size = 48.0f;
+typedef std::deque<std::string> Text;
+
}
#endif // __INCLUDED_UI_DEFINITIONS_H__
diff --git a/src/ui/inputbox.cc b/src/ui/inputbox.cc
index 30cae3b..39f8393 100644
--- a/src/ui/inputbox.cc
+++ b/src/ui/inputbox.cc
@@ -16,6 +16,7 @@ InputBox::InputBox(Widget *parent) : Widget(parent)
{
input_text.clear();
input_pos = 0;
+ input_max = 512;
set_label("input");
set_background(false);
@@ -46,15 +47,38 @@ void InputBox::set_text(const char *text)
input_pos = input_text.size();
}
+void InputBox::set_prompt(const std::string &prompt)
+{
+ input_prompt.assign(prompt);
+}
+
+void InputBox::set_prompt(const char *prompt)
+{
+ if (!prompt)
+ input_prompt.clear();
+ else
+ input_prompt.assign(prompt);
+}
+
+void InputBox::set_max(const size_t max)
+{
+ input_max = max;
+}
+
void InputBox::draw()
{
- draw_background();
- draw_border();
-
size_t text_width = (size_t) floorf(width() / font()->width());
+ size_t prompt_width = aux::text_length(input_prompt);
math::Vector2f v(global_location());
- paint::color(palette()->foreground());
+ paint::color(palette()->text());
+ // draw the prompt
+ if (prompt_width) {
+ paint::text(v, size(), font(), input_prompt);
+ v.x += prompt_width * font()->width();
+ }
+ paint::color(palette()->text());
+
// draw the part before the cursor
std::string firstpart(input_text.substr(0, input_pos));
size_t draw_width = 0;
@@ -70,7 +94,7 @@ void InputBox::draw()
}
c = firstpart.c_str();
- while (*c && draw_width > text_width - 2) {
+ while (*c && draw_width > text_width - prompt_width - 1) {
if (aux::is_color_code(c)) {
c++;
paint::color_code(*c);
@@ -81,7 +105,7 @@ void InputBox::draw()
}
if (*c) {
- paint::text(v, size(), font(), std::string(c), AlignLeft | AlignVCenter);
+ paint::text(v, size(), font(), std::string(c));
}
// draw the part behind the cursor
@@ -93,7 +117,7 @@ void InputBox::draw()
// limit to width
std::string secondpart;
c = &input_text.c_str()[input_pos];
- while (*c && (draw_width <= (text_width - 2))) {
+ while (*c && (draw_width <= (text_width - prompt_width - 1))) {
if (aux::is_color_code(c)) {
c++;
} else {
@@ -103,14 +127,14 @@ void InputBox::draw()
c++;
}
- paint::text(v, size(), font(), secondpart, AlignLeft | AlignVCenter);
+ paint::text(v, size(), font(), secondpart);
}
// draw the cursor
if (has_input_focus() && (core::application()->time() - ::floorf(core::application()->time())) < 0.5f) {
std::string cursor("^B");
cursor += (char) 11;
- paint::text(v, size(), font(), cursor, AlignLeft | AlignVCenter);
+ paint::text(v, size(), font(), cursor);
}
}
@@ -162,11 +186,14 @@ bool InputBox::on_keypress(const int key, const unsigned int modifier)
default:
if ((key >= 32) && (key <175)) {
- if (input_pos == input_text.size())
- input_text += (char)key;
- else
- input_text.insert(input_pos, 1, (char)key);
- input_pos++;
+ if (input_text.size() < input_max) {
+ // TODO bell sound
+ if (input_pos == input_text.size())
+ input_text += (char)key;
+ else
+ input_text.insert(input_pos, 1, (char)key);
+ input_pos++;
+ }
return true;
}
break;
diff --git a/src/ui/inputbox.h b/src/ui/inputbox.h
index 557ca6c..961bbcf 100644
--- a/src/ui/inputbox.h
+++ b/src/ui/inputbox.h
@@ -20,10 +20,19 @@ public:
~InputBox();
/// set the text displayed by the label
- void set_text(std::string const &text);
+ void set_text(const std::string &text);
/// set the text displayed by the label
void set_text(const char *text);
+
+ /// set the prompt
+ void set_prompt(const std::string &prompt);
+
+ /// set the prompt
+ void set_prompt(const char *prompt);
+
+ /// set the maximal input width
+ void set_max(const size_t max);
/// return the text displayed by the label
inline std::string const &text() const {
@@ -46,7 +55,9 @@ protected:
private:
std::string input_text;
+ std::string input_prompt;
size_t input_pos;
+ size_t input_max;
};
}
diff --git a/src/ui/label.cc b/src/ui/label.cc
index 80e493e..cf9b473 100644
--- a/src/ui/label.cc
+++ b/src/ui/label.cc
@@ -50,18 +50,11 @@ void Label::set_alignment(const unsigned int alignment)
void Label::draw()
{
- Widget::draw();
-
- draw_text();
-}
-
-void Label::draw_text()
-{
if (!label_text.size())
return;
paint::color(palette()->foreground());
- paint::text(global_location(), size(), font(), text(), alignment());
+ paint::label(global_location(), size(), font(), text(), alignment());
}
}
diff --git a/src/ui/label.h b/src/ui/label.h
index b7925c7..beecfb4 100644
--- a/src/ui/label.h
+++ b/src/ui/label.h
@@ -45,10 +45,7 @@ public:
protected:
/// draw the label
virtual void draw();
-
- /// draw the label text
- virtual void draw_text();
-
+
private:
std::string label_text;
unsigned int label_alignment;
diff --git a/src/ui/paint.cc b/src/ui/paint.cc
index d50e3b5..45b7eea 100644
--- a/src/ui/paint.cc
+++ b/src/ui/paint.cc
@@ -32,7 +32,7 @@ void color_code(const char c)
render::Text::setcolor(c);
}
-void border(math::Vector2f const &location, math::Vector2f const &size)
+void border(const math::Vector2f &location, const math::Vector2f &size)
{
using namespace render::gl;
@@ -44,7 +44,7 @@ void border(math::Vector2f const &location, math::Vector2f const &size)
end();
}
-void rectangle(math::Vector2f const &location, math::Vector2f const &size)
+void rectangle(const math::Vector2f &location, const math::Vector2f &size)
{
using namespace render::gl;
@@ -56,9 +56,9 @@ void rectangle(math::Vector2f const &location, math::Vector2f const &size)
end();
}
-void bitmap(math::Vector2f const &location, math::Vector2f const &size, std::string const &texture)
+// draw a bitmap
+void bitmap(const math::Vector2f &location, const math::Vector2f &size, std::string const &texture)
{
-
using namespace render::gl;
render::Textures::bind("bitmaps/" + texture);
@@ -82,41 +82,8 @@ void bitmap(math::Vector2f const &location, math::Vector2f const &size, std::str
disable(GL_TEXTURE_2D);
}
-void text_centered(math::Vector2f const &location, math::Vector2f const &size, std::string const &text, Font const *font)
-{
- using namespace render::gl;
-
- render::Text::setfont(font->name().c_str(), font->width(), font->height());
- enable(GL_TEXTURE_2D);
-
- math::Vector2f v(location);
-
- v.x += (size.x - aux::text_strip(text).size() * font->width()) /2.0f;
- v.y += (size.y - font->height()) / 2.0f;
-
- render::Text::draw(v.x, v.y, text);
-
- disable(GL_TEXTURE_2D);
-}
-
-void text(math::Vector2f const &location, Font const *font, std::stringstream & textstream)
-{
- using namespace render::gl;
- render::Text::setfont(font->name().c_str(), font->width(), font->height());
-
- // enable OpenGL textures
- enable(GL_TEXTURE_2D);
-
- render::Text::draw(location.x, location.y, textstream);
-
- // disable texturing
- disable(GL_TEXTURE_2D);
-}
-
-void text(math::Vector2f const &location, math::Vector2f const &size,
- Font const *font,
- std::string const &text,
- unsigned int align)
+// draw aligned text
+void label(const math::Vector2f &location, const math::Vector2f &size, const Font *font, const std::string &text, unsigned int align)
{
unsigned int align_horizontal = (align & 0x000F);
if (!align_horizontal)
@@ -167,11 +134,41 @@ void text(math::Vector2f const &location, math::Vector2f const &size,
render::Text::draw(v.x, v.y, text);
- // disable texturing
+ // disable OpenGL textures
disable(GL_TEXTURE_2D);
}
+// draw unaligned text
+void text(const math::Vector2f &location, const math::Vector2f &size, const Font *font, const std::string &text)
+{
+ using namespace render::gl;
+ render::Text::setfont(font->name().c_str(), font->width(), font->height());
+
+ // enable OpenGL textures
+ enable(GL_TEXTURE_2D);
+
+ render::Text::draw(location.x, location.y, text);
+
+ // disable OpenGL textures
+ disable(GL_TEXTURE_2D);
+}
+
+// draw unaligned text
+void text(const math::Vector2f &location, const math::Vector2f &size, const Font *font, std::stringstream & textstream)
+{
+ using namespace render::gl;
+ render::Text::setfont(font->name().c_str(), font->width(), font->height());
+
+ // enable OpenGL textures
+ enable(GL_TEXTURE_2D);
+
+ render::Text::draw(location.x, location.y, textstream);
+
+ // disable OpenGL textures
+ disable(GL_TEXTURE_2D);
+}
+
}
}
diff --git a/src/ui/paint.h b/src/ui/paint.h
index c90f1b5..95f1c62 100644
--- a/src/ui/paint.h
+++ b/src/ui/paint.h
@@ -25,20 +25,22 @@ void color(math::Color const & color);
void color_code(const char c);
/// draw a border
-void border(math::Vector2f const &location, math::Vector2f const &size);
+void border(const math::Vector2f &location, const math::Vector2f &size);
/// draw a rectangle
-void rectangle(math::Vector2f const &location, math::Vector2f const &size);
+void rectangle(const math::Vector2f &location, const math::Vector2f &size);
/// draw a rectangular bitmap
-void bitmap(math::Vector2f const &location, math::Vector2f const &size, std::string const &texture);
+void bitmap(const math::Vector2f &location, const math::Vector2f &size, std::string const &texture);
-/// draw one line of text from a string
-void text(math::Vector2f const &location, math::Vector2f const &size, Font const *font,
- std::string const &text, unsigned int align = AlignCenter);
+/// draw aligned text
+void label(const math::Vector2f &location, const math::Vector2f &size, const Font *font, const std::string &text, unsigned int align = AlignCenter);
-/// draw unaligned text from a stringstream
-void text(math::Vector2f const &location, Font const *font, std::stringstream & textstream);
+/// draw unaligned text
+void text(const math::Vector2f &location, const math::Vector2f &size, const Font *font, const std::string &text);
+
+/// draw unaligned text
+void text(const math::Vector2f &location, const math::Vector2f &size, const Font *font, std::stringstream & textstream);
}
diff --git a/src/ui/palette.cc b/src/ui/palette.cc
index 3a9dc78..79388d8 100644
--- a/src/ui/palette.cc
+++ b/src/ui/palette.cc
@@ -12,12 +12,15 @@ namespace ui
Palette::Palette()
{
- palette_foreground.assign(0.8f, 1.0f);
- palette_highlight.assign(1.0f, 1.0f);
- palette_background.assign(0.5f, 0.5f);
- palette_border.assign(0.0f, 0.8f, 0.0f);
- palette_pointer.assign(0.0f, 0.5f, 0.0f);
+ palette_foreground.assign(1.0f, 1.0f);
+ palette_highlight.assign(1.0f, 1.0f, 0.5f);
+ palette_text.assign(0.75f);
+ palette_background.assign(0.5f, 0.75f);
+ palette_border.assign(0.0f, 0.8f, 0.0f, 0.5f);
+ palette_pointer.assign(0.0f, 0.75f, 0.0f);
palette_active.assign(0.0f, 1.0f, 0.0f);
+
+ palette_debug.assign(1.0f, 0.0f, 1.0f, 0.75f);
}
Palette::~Palette()
@@ -45,6 +48,8 @@ const math::Color &Palette::color(Color palettecolor) const
case Active:
return active();
break;
+ case Debug:
+ return debug();
default:
return foreground();
break;
@@ -61,6 +66,11 @@ void Palette::set_highlight(math::Color const &color)
palette_highlight.assign(color);
}
+void Palette::set_text(math::Color const &color)
+{
+ palette_text.assign(color);
+}
+
void Palette::set_background(math::Color const &color)
{
palette_background.assign(color);
@@ -81,5 +91,10 @@ void Palette::set_active(math::Color const &color)
palette_active.assign(color);
}
+void Palette::set_debug(math::Color const &color)
+{
+ palette_debug.assign(color);
+}
+
}
diff --git a/src/ui/palette.h b/src/ui/palette.h
index 41eee03..1ef49c7 100644
--- a/src/ui/palette.h
+++ b/src/ui/palette.h
@@ -19,11 +19,15 @@ public:
Palette();
~Palette();
- enum Color { Foreground=0, Background=1, Highlight=2, Border=3, Pointer=4, Active=5 };
+ enum Color { Foreground=0, Background=1, Highlight=2, Border=3, Pointer=4, Active=5, Debug=6 };
+ /// set foreground color
void set_foreground(math::Color const &color);
+ /// set highlight color
void set_highlight(math::Color const &color);
+
+ void set_text(math::Color const &color);
void set_background(math::Color const &color);
@@ -32,6 +36,8 @@ public:
void set_pointer(math::Color const &color);
void set_active(math::Color const &color);
+
+ void set_debug(math::Color const &olor);
inline const math::Color &foreground() const {
return palette_foreground;
@@ -40,6 +46,10 @@ public:
inline const math::Color &highlight() const {
return palette_highlight;
}
+
+ inline const math::Color &text() const {
+ return palette_text;
+ }
inline const math::Color &background() const {
return palette_background;
@@ -57,6 +67,10 @@ public:
return palette_active;
}
+ inline const math::Color &debug() const {
+ return palette_debug;
+ }
+
const math::Color &color(Palette::Color palettecolor) const;
private:
@@ -67,6 +81,8 @@ private:
math::Color palette_pointer;
math::Color palette_active;
math::Color palette_border;
+ math::Color palette_debug;
+ math::Color palette_text;
};
}
diff --git a/src/ui/scrollpane.cc b/src/ui/scrollpane.cc
new file mode 100644
index 0000000..69bc159
--- /dev/null
+++ b/src/ui/scrollpane.cc
@@ -0,0 +1,172 @@
+/*
+ ui/scrollpane.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 "ui/scrollpane.h"
+#include "render/text.h"
+#include "render/gl.h"
+
+namespace ui
+{
+
+ScrollPane::ScrollPane(Widget *parent, ui::Text &text) : Widget(parent), scrollpane_text(text)
+{
+ set_label("scrollpane");
+}
+
+ScrollPane::~ScrollPane()
+{
+}
+
+void ScrollPane::set_scroll(int scroll)
+{
+ scrollpane_scroll = scroll;
+
+ if (scrollpane_scroll > (int) scrollpane_text.size())
+ scrollpane_scroll = (int) scrollpane_text.size();
+ else if (scrollpane_scroll < 0)
+ scrollpane_scroll = 0;
+}
+
+void ScrollPane::inc_scroll(int scroll)
+{
+ scrollpane_scroll += scroll;
+
+ if (scrollpane_scroll > (int) scrollpane_text.size())
+ scrollpane_scroll = (int) scrollpane_text.size();
+}
+
+void ScrollPane::dec_scroll(int scroll)
+{
+ scrollpane_scroll -= scroll;
+
+ if (scrollpane_scroll < 0)
+ scrollpane_scroll = 0;
+}
+
+void ScrollPane::draw()
+{
+ render::Text::setfont(font()->name().c_str(), font()->width(), font()->height());
+ render::gl::enable(GL_TEXTURE_2D);
+
+ // text size
+ int text_height = (int) floorf(height() / font()->height());
+ int text_width = (int) floorf(width() / font()->width());
+
+ // validate scroll position
+ if (scrollpane_scroll > (int) scrollpane_text.size())
+ scrollpane_scroll = (int) scrollpane_text.size();
+ else if (scrollpane_scroll < 0)
+ scrollpane_scroll = 0;
+
+ int bottom = (int) scrollpane_text.size() - scrollpane_scroll;
+ int current_line = 0;
+
+ ui::Text lines;
+
+ for (ui::Text::const_iterator it = scrollpane_text.begin(); it != scrollpane_text.end() && current_line < bottom; it++) {
+ if (current_line >= bottom - text_height) {
+ std::string linedata(*it);
+ linedata += '\n';
+
+ std::string word;
+ size_t word_length = 0;
+
+ std::string line;
+ size_t line_length = 0;
+
+ const char *c = linedata.c_str();
+ char pen = 'N';
+ char wordpen = 'N';
+
+ while (*c) {
+
+ // color code
+ if (aux::is_color_code(c)) {
+ c++;
+ pen = *c;
+ word += '^';
+ word += pen;
+ }
+
+ // new word, wrap if necessary
+ else if ((*c == '\n' ) || ( *c == ' ')) {
+
+ if (line_length + word_length > (size_t) text_width) {
+ if (line.size()) {
+ lines.push_back(line);
+ line.clear();
+ line += '^';
+ line += wordpen;
+ line_length = 0;
+ }
+ }
+
+ line.append(word);
+ line_length += word_length;
+
+ word.clear();
+ word_length = 0;
+ wordpen = pen;
+
+ // new line
+ if (*c == '\n' ) {
+ lines.push_back(line);
+ line.clear();
+ line_length = 0;
+ // new word
+ } else if (*c == ' ' ) {
+ line += ' ';
+ line_length++;
+ }
+ }
+
+ // new character
+ else {
+ word += *c;
+ word_length++;
+
+ if (word_length == (size_t) text_width) {
+ if (line.size()) {
+ lines.push_back(line);
+ line.clear();
+ line += '^';
+ line += wordpen;
+ line_length = 0;
+ }
+
+ line.append(word);
+ line_length = word_length;
+
+ word.clear();
+ word_length = 0;
+ wordpen = pen;
+ }
+ }
+
+ c++;
+ }
+
+ }
+ current_line++;
+ }
+
+ render::gl::color(palette()->text());
+ const math ::Vector2f gl(global_location());
+ float y = height() - font()->height();
+
+ for (ui::Text::reverse_iterator rit = lines.rbegin(); (y >= 0) && (rit != lines.rend()); ++rit) {
+ render::Text::draw(gl.x, gl.y + y, (*rit));
+ y -= font()->height();
+ }
+
+ render::gl::disable(GL_TEXTURE_2D);
+}
+
+}
+
+
diff --git a/src/ui/scrollpane.h b/src/ui/scrollpane.h
new file mode 100644
index 0000000..47e68ee
--- /dev/null
+++ b/src/ui/scrollpane.h
@@ -0,0 +1,47 @@
+/*
+ ui/scrollpane.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_SCROLLPANE_H__
+#define __INCLUDED_UI_SCROLLPANE_H__
+
+#include "ui/widget.h"
+#include "ui/definitions.h"
+
+namespace ui
+{
+
+/// a widget displaying centered text
+class ScrollPane : public Widget
+{
+public:
+ ScrollPane(Widget *parent, ui::Text &text);
+ ~ScrollPane();
+
+ /// set scroll
+ void set_scroll(int scroll);
+
+ /// increase scroll
+ void inc_scroll(int scroll);
+
+ /// decrease scroll
+ void dec_scroll(int scroll);
+
+ /// current scroll position
+ inline int scroll() const { return scrollpane_scroll; }
+
+protected:
+ /// draw the scroll pane
+ virtual void draw();
+
+private:
+ ui::Text &scrollpane_text;
+ int scrollpane_scroll;
+};
+
+}
+
+#endif // __INCLUDED_UI_SCROLLPANE_H__
+
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index 1ecfbb1..bacc753 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -25,6 +25,8 @@ namespace ui
/* -- static functions --------------------------------------------- */
+bool UI::ui_debug = false;
+
UI *global_ui = 0;
void func_list_ui(std::string const &args)
@@ -52,6 +54,7 @@ void help()
{
con_print << "^BUser interface functions" << std::endl;
con_print << " ui help show this help" << std::endl;
+ con_print << " ui debug toggle debug mode" << std::endl;
con_print << " ui list list widgets" << std::endl;
con_print << " ui show show user interface" << std::endl;
con_print << " ui hide hide user interface" << std::endl;
@@ -76,6 +79,8 @@ void func_ui(std::string const &args)
if (command.compare("help") == 0) {
help();
+ } else if (command.compare("debug") == 0) {
+ UI::ui_debug = !UI::ui_debug;
} else if (command.compare("list") == 0) {
global_ui->list();
} else if (command.compare("show") == 0) {
@@ -291,6 +296,8 @@ void UI::load()
} else if (ini.got_key_color("highlight", color)) {
ui_palette->set_highlight(color);
continue;
+ } else if (ini.got_key_color("text", color)) {
+ ui_palette->set_text(color);
} else if (ini.got_key_color("background", color)) {
ui_palette->set_background(color);
continue;
@@ -301,6 +308,8 @@ void UI::load()
ui_palette->set_pointer(color);
} else if (ini.got_key_color("active", color)) {
ui_palette->set_active(color);
+ } else if (ini.got_key_color("debug", color)) {
+ ui_palette->set_debug(color);
} else {
ini.unkown_key();
}
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 24f9793..97577c6 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -83,6 +83,8 @@ public:
/// set mouse pointer bitmap
void set_pointer(const char *pointerbitmap=0, const Palette::Color color = Palette::Highlight,const bool animated = false);
+ static bool ui_debug;
+
protected:
typedef std::list<Window *> Menus;
@@ -98,7 +100,7 @@ protected:
/// handle key release events
virtual bool on_keyrelease(const int key, const unsigned int modifier);
-
+
private:
void draw_pointer();
@@ -128,6 +130,9 @@ void shutdown();
/// the global root window
UI *root();
+/// debug mode
+inline bool debug() { return UI::ui_debug; }
+
}
#endif // __INCLUDED_UI_H__
diff --git a/src/ui/widget.cc b/src/ui/widget.cc
index 606c4ab..046cb01 100644
--- a/src/ui/widget.cc
+++ b/src/ui/widget.cc
@@ -200,7 +200,7 @@ void Widget::set_size(float const w, float const h)
widget_size.assign(w, h);
}
-void Widget::set_size(math::Vector2f const &size)
+void Widget::set_size(const math::Vector2f &size)
{
widget_size.assign(size);
}
@@ -329,7 +329,13 @@ void Widget::event_draw()
{
if (!visible())
return;
-
+
+ if (widget_background)
+ draw_background();
+ if (widget_border)
+ draw_border();
+ if (debug())
+ draw_debug_border();
draw();
for (Children::iterator it = widget_children.begin(); it != widget_children.end(); it++) {
@@ -371,32 +377,30 @@ bool Widget::on_keyrelease(const int key, const unsigned int modifier)
/* -- draw functions ----------------------------------------------- */
-void Widget::resize()
-{
-}
-
-void Widget::draw()
+void Widget::draw_debug_border()
{
- draw_background();
- draw_border();
+ paint::color(1.0f, 0.0f, 1.0f, 0.5f);
+ paint::border(global_location(), size());
}
void Widget::draw_background()
{
- if (!widget_background)
- return;
-
paint::color(palette()->background());
paint::rectangle(global_location(), size());
}
void Widget::draw_border()
{
- if (!widget_border)
- return;
-
paint::color(palette()->border());
paint::border(global_location(), size());
}
+void Widget::draw()
+{
+}
+
+void Widget::resize()
+{
+}
+
}
diff --git a/src/ui/widget.h b/src/ui/widget.h
index ef386c0..60670b6 100644
--- a/src/ui/widget.h
+++ b/src/ui/widget.h
@@ -149,7 +149,7 @@ public:
void set_size(float const w, float const h);
/// set the widgets width and height
- void set_size(math::Vector2f const &size);
+ void set_size(const math::Vector2f &size);
/// set the widgets width
void set_width(float const w);
@@ -282,6 +282,8 @@ protected:
virtual void remove_child(Widget *child);
private:
+ void draw_debug_border();
+
bool widget_visible;
bool widget_background;
bool widget_border;
diff --git a/src/ui/window.cc b/src/ui/window.cc
index 9ae9ec5..8494f34 100644
--- a/src/ui/window.cc
+++ b/src/ui/window.cc
@@ -47,9 +47,6 @@ void Window::clear_previous()
void Window::draw_border()
{
- if (!border())
- return;
-
paint::color(palette()->border());
paint::border(global_location(), size());
}