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/bitmap.cc2
-rw-r--r--src/ui/bitmap.h16
-rw-r--r--src/ui/button.cc8
-rw-r--r--src/ui/button.h22
-rw-r--r--src/ui/console.cc131
-rw-r--r--src/ui/console.h13
-rw-r--r--src/ui/container.cc2
-rw-r--r--src/ui/container.h6
-rw-r--r--src/ui/definitions.h4
-rw-r--r--src/ui/font.h24
-rw-r--r--src/ui/iconbutton.cc6
-rw-r--r--src/ui/iconbutton.h24
-rw-r--r--src/ui/inputbox.cc36
-rw-r--r--src/ui/inputbox.h16
-rw-r--r--src/ui/label.cc2
-rw-r--r--src/ui/label.h18
-rw-r--r--src/ui/menu.cc24
-rw-r--r--src/ui/menu.h14
-rwxr-xr-xsrc/ui/modelview.cc10
-rwxr-xr-xsrc/ui/modelview.h14
-rw-r--r--src/ui/paint.cc49
-rw-r--r--src/ui/paint.h5
-rw-r--r--src/ui/palette.cc30
-rw-r--r--src/ui/palette.h81
-rw-r--r--src/ui/scrollpane.cc28
-rw-r--r--src/ui/scrollpane.h14
-rw-r--r--src/ui/toolbar.cc3
-rw-r--r--src/ui/toolbar.h8
-rw-r--r--src/ui/ui.cc86
-rw-r--r--src/ui/ui.h60
-rw-r--r--src/ui/widget.cc44
-rw-r--r--src/ui/widget.h140
-rw-r--r--src/ui/window.cc2
-rw-r--r--src/ui/window.h8
34 files changed, 481 insertions, 469 deletions
diff --git a/src/ui/bitmap.cc b/src/ui/bitmap.cc
index fcf141c..4af7714 100644
--- a/src/ui/bitmap.cc
+++ b/src/ui/bitmap.cc
@@ -17,7 +17,7 @@ Bitmap::Bitmap(Widget *parent, const char *texture) : Widget(parent)
set_border(false);
set_background(true);
set_label("bitmap");
-
+
set_texture(texture);
}
diff --git a/src/ui/bitmap.h b/src/ui/bitmap.h
index 9bc1776..4838ea2 100644
--- a/src/ui/bitmap.h
+++ b/src/ui/bitmap.h
@@ -15,29 +15,29 @@ namespace ui
class Bitmap : public Widget
{
public:
- Bitmap(Widget *parent, const char *texture=0);
+ Bitmap(Widget *parent, const char *texture = 0);
~Bitmap();
-
+
inline std::string const &texture() const {
return bitmap_texture;
}
-
+
inline math::Color const &color() const {
return bitmap_color;
}
-
+
void set_texture(const std::string & texture);
void set_texture(const char *texture);
-
+
void set_color(const math::Color &color);
-
+
/// print bitmap description
virtual void print(const size_t indent) const;
-
+
protected:
/// draw the bitmap as background
virtual void draw_background();
-
+
private:
std::string bitmap_texture;
math::Color bitmap_color;
diff --git a/src/ui/button.cc b/src/ui/button.cc
index 989e9eb..85cad7e 100644
--- a/src/ui/button.cc
+++ b/src/ui/button.cc
@@ -59,7 +59,7 @@ void Button::draw_border()
paint::color(color);
} else
paint::color(palette()->border());
-
+
paint::border(global_location(), size());
}
@@ -67,17 +67,17 @@ void Button::draw()
{
if (!text().size())
return;
-
+
if (has_mouse_focus())
paint::color(palette()->highlight());
else
paint::color(palette()->foreground());
-
+
paint::label(global_location(), size(), font(), text(), alignment());
}
bool Button::on_keypress(const int key, const unsigned int modifier)
-{
+{
if (key == 512 + SDL_BUTTON_LEFT) {
core::cmd() << button_command << std::endl;
audio::play("ui/button");
diff --git a/src/ui/button.h b/src/ui/button.h
index 24097ae..a0aac72 100644
--- a/src/ui/button.h
+++ b/src/ui/button.h
@@ -16,39 +16,39 @@ namespace ui
class Button : public Label
{
public:
- Button(Widget *parent, const char *text=0, const char *command=0);
+ Button(Widget *parent, const char *text = 0, const char *command = 0);
~Button();
-
+
/// 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 button_command;
}
-
+
/// print button description
virtual void print(const size_t indent) const;
-
+
/// called when the mouse enters the widget
virtual void on_mouseover(const math::Vector2f &cursor);
-
+
/// called when the widget receives a key press
virtual bool on_keypress(const int key, const unsigned int modifier);
-
+
/// called when the widget receives a key release
virtual bool on_keyrelease(const int key, const unsigned int modifier);
-
+
protected:
/// draw the button border
virtual void draw_border();
-
+
/// draw the button
virtual void draw();
-
+
private:
std::string button_command;
};
diff --git a/src/ui/console.cc b/src/ui/console.cc
index 4fcba7d..c486c65 100644
--- a/src/ui/console.cc
+++ b/src/ui/console.cc
@@ -1,7 +1,7 @@
/*
client/console.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <iostream>
@@ -18,7 +18,8 @@
#include "ui/console.h"
#include "ui/paint.h"
-namespace ui {
+namespace ui
+{
const float DEFAULT_CONSOLE_HEIGHT = 0.7f;
const size_t DEFAULT_MAX_HISTO_LINES = 512;
@@ -29,7 +30,7 @@ ConsoleBuffer Console::con_buffer;
/* -- ConsoleBuffer ------------------------------------------------ */
ConsoleBuffer::ConsoleBuffer() : sys::ConsoleInterface()
{
- //con_print << "^BInitializing console..." << std::endl;
+ //con_print << "^BInitializing console..." << std::endl;
}
@@ -109,64 +110,64 @@ bool Console::on_keypress(const int key, const unsigned int modifier)
ui::Text::reverse_iterator upit;
- switch( key ) {
-
- case SDLK_ESCAPE:
- if (visible()) {
- hide();
+ switch (key) {
+
+ case SDLK_ESCAPE:
+ if (visible()) {
+ hide();
+ return true;
+ } else {
+ return false;
+ }
+ break;
+ /*
+ case SDLK_TAB:
+ core::CommandBuffer::complete( (*history_pos), input_pos);
+ return true;
+ break;
+ */
+ case SDLK_RETURN:
+ if (console_input->text().size()) {
+ // store input in history
+ while (history.size() >= DEFAULT_MAX_HISTO_LINES) {
+ history.pop_front();
+ }
+ core::cmd() << console_input->text() << std::endl;
+ con_print << "^B>" << console_input->text() << std::endl;
+ (*history.rbegin()).assign(console_input->text());
+ history.push_back("");
+ history_pos = history.rbegin();
+ console_input->set_text((*history_pos));
+ }
return true;
- } else {
- return false;
- }
- break;
-/*
- case SDLK_TAB:
- core::CommandBuffer::complete( (*history_pos), input_pos);
- return true;
- break;
-*/
- case SDLK_RETURN:
- if (console_input->text().size()) {
- // store input in history
- while (history.size() >= DEFAULT_MAX_HISTO_LINES) {
- history.pop_front();
+ break;
+
+ case SDLK_UP:
+ upit = history_pos;
+ ++upit;
+ if (upit != history.rend()) {
+ history_pos = upit;
+ console_input->set_text((*history_pos));
}
- core::cmd() << console_input->text() << std::endl;
- con_print << "^B>" << console_input->text() << std::endl;
- (*history.rbegin()).assign(console_input->text());
- history.push_back("");
- history_pos = history.rbegin();
- console_input->set_text((*history_pos));
- }
- return true;
- break;
-
- case SDLK_UP:
- upit = history_pos;
- ++upit;
- if (upit != history.rend()) {
- history_pos = upit;
- console_input->set_text((*history_pos));
- }
- return true;
- break;
- case SDLK_DOWN:
- if (history_pos != history.rbegin()) {
- --history_pos;
- console_input->set_text((*history_pos));
- }
- return true;
- break;
- case 512 + SDL_BUTTON_WHEELUP:
- case SDLK_PAGEUP:
- console_scrollpane->inc_scroll(scroll_offset);
- return true;
- break;
- case 512 + SDL_BUTTON_WHEELDOWN:
- case SDLK_PAGEDOWN:
- console_scrollpane->dec_scroll(scroll_offset);
- return true;
- break;
+ return true;
+ break;
+ case SDLK_DOWN:
+ if (history_pos != history.rbegin()) {
+ --history_pos;
+ console_input->set_text((*history_pos));
+ }
+ return true;
+ break;
+ case 512 + SDL_BUTTON_WHEELUP:
+ case SDLK_PAGEUP:
+ console_scrollpane->inc_scroll(scroll_offset);
+ return true;
+ break;
+ case 512 + SDL_BUTTON_WHEELDOWN:
+ case SDLK_PAGEDOWN:
+ console_scrollpane->dec_scroll(scroll_offset);
+ return true;
+ break;
}
return false;
@@ -186,8 +187,8 @@ void Console::draw()
console_scrollpane->set_location(4, 4);
console_scrollpane->set_size(s.width(), s.height() - font()->height());
-
- console_input->set_location(4, height() - font()->height() -4);
+
+ console_input->set_location(4, height() - font()->height() - 4);
console_input->set_size(s.width(), font()->height());
math::Color fancy(palette()->fancy());
@@ -196,8 +197,8 @@ void Console::draw()
std::string version(core::name() + ' ' + core::version());
s.assign(version.size() * font()->width(), font()->height());
math::Vector2f l(global_location());
- l[0] += width() - s.width() -4;
- l[1] += height() - s.height() -4;
+ l[0] += width() - s.width() - 4;
+ l[1] += height() - s.height() - 4;
paint::text(l, s, font(), version);
}
@@ -238,7 +239,7 @@ void Console::load_history()
history.clear();
char line[MAXCMDSIZE];
- while (ifs.getline(line, MAXCMDSIZE-1)) {
+ while (ifs.getline(line, MAXCMDSIZE - 1)) {
history.push_back(line);
}
diff --git a/src/ui/console.h b/src/ui/console.h
index 2cec72e..1baa42d 100644
--- a/src/ui/console.h
+++ b/src/ui/console.h
@@ -1,7 +1,7 @@
/*
ui/console.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ 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_CONSOLE_H__
@@ -12,14 +12,16 @@
#include "ui/scrollpane.h"
#include "ui/window.h"
-namespace ui {
+namespace ui
+{
/* -- class ConsoleBuffer ------------------------------------------ */
/// client console buffer
/** stores incoming console messages
*/
-class ConsoleBuffer : public sys::ConsoleInterface {
+class ConsoleBuffer : public sys::ConsoleInterface
+{
public:
ConsoleBuffer();
virtual ~ConsoleBuffer();
@@ -28,7 +30,8 @@ public:
/* -- class Console ------------------------------------------------ */
/// client system console widget
-class Console : public Window {
+class Console : public Window
+{
public:
Console(Widget *parent);
virtual ~Console();
diff --git a/src/ui/container.cc b/src/ui/container.cc
index 6705c62..04e1ec2 100644
--- a/src/ui/container.cc
+++ b/src/ui/container.cc
@@ -45,7 +45,7 @@ void Container::resize()
void Container::draw_border()
{
- if(focus()) {
+ if (focus()) {
paint::color(palette()->foreground());
} else {
paint::color(palette()->border());
diff --git a/src/ui/container.h b/src/ui/container.h
index 2045772..08ed443 100644
--- a/src/ui/container.h
+++ b/src/ui/container.h
@@ -11,10 +11,12 @@
#include "ui/window.h"
-namespace ui {
+namespace ui
+{
/// a widget containing childs of equal size
-class Container : public Window {
+class Container : public Window
+{
public:
Container(Widget *parent);
~Container();
diff --git a/src/ui/definitions.h b/src/ui/definitions.h
index e04082f..02698f4 100644
--- a/src/ui/definitions.h
+++ b/src/ui/definitions.h
@@ -18,11 +18,11 @@ enum Alignment {
AlignLeft = 0x0001,
AlignHCenter = 0x0002,
AlignRight = 0x0004,
-
+
AlignTop = 0x0010,
AlignVCenter = 0x0020,
AlignBottom = 0x0040,
-
+
AlignCenter = AlignHCenter | AlignVCenter
};
diff --git a/src/ui/font.h b/src/ui/font.h
index 4fb6310..b91120e 100644
--- a/src/ui/font.h
+++ b/src/ui/font.h
@@ -18,39 +18,39 @@ class Font
public:
Font(const char *name, const float width, const float height);
~Font();
-
+
inline const std::string & name() const {
return font_name;
}
-
+
inline const math::Vector2f & size() const {
return font_size;
}
-
+
inline float width() const {
return font_size.width();
}
-
+
inline float height() const {
return font_size.height();
}
-
+
void set_size(const float width, const float height);
-
+
void set_size(const math::Vector2f &size);
-
+
void set_width(const float width);
-
+
void set_height(const float height);
-
+
void set_name(const char *name);
-
+
void set_name(const std::string & name);
-
+
private:
std::string font_name;
-
+
math::Vector2f font_size;
};
diff --git a/src/ui/iconbutton.cc b/src/ui/iconbutton.cc
index 2c4661e..ffdafe0 100644
--- a/src/ui/iconbutton.cc
+++ b/src/ui/iconbutton.cc
@@ -77,7 +77,7 @@ void IconButton::draw()
{
if (!icon().size())
return;
-
+
if (disabled()) {
paint::color(palette()->disabled());
} else if (has_mouse_focus()) {
@@ -85,7 +85,7 @@ void IconButton::draw()
} else {
paint::color(palette()->foreground());
}
-
+
paint::bitmap(location(), size(), icon());
}
@@ -104,7 +104,7 @@ void IconButton::draw_border()
}
bool IconButton::on_keypress(const int key, const unsigned int modifier)
-{
+{
if (key == 512 + SDL_BUTTON_LEFT) {
if (enabled() && iconbutton_command.size()) {
core::cmd() << iconbutton_command << std::endl;
diff --git a/src/ui/iconbutton.h b/src/ui/iconbutton.h
index 10b073f..37d1c7b 100644
--- a/src/ui/iconbutton.h
+++ b/src/ui/iconbutton.h
@@ -15,9 +15,9 @@ namespace ui
class IconButton : public Widget
{
public:
- IconButton(Widget *parent, const char *icon=0, const char *command=0);
+ 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;
@@ -39,17 +39,17 @@ public:
}
/// enable or disable the button
- void enable(bool enabled=true);
+ void enable(bool enabled = true);
/// enable or disable the button
- void disable(bool disabled=true);
-
+ 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);
-
+
/// set the icon texture
void set_icon(const std::string & icon);
@@ -58,23 +58,23 @@ public:
/// print button description
virtual void print(const size_t indent) const;
-
+
/// called when the mouse enters the widget
virtual void on_mouseover(const math::Vector2f &cursor);
-
+
/// called when the widget receives a key press
virtual bool on_keypress(const int key, const unsigned int modifier);
-
+
/// called when the widget receives a key release
virtual bool on_keyrelease(const int key, const unsigned int modifier);
-
+
protected:
/// draw the button border
virtual void draw_border();
/// draw the button
virtual void draw();
-
+
private:
std::string iconbutton_command;
std::string iconbutton_icon;
diff --git a/src/ui/inputbox.cc b/src/ui/inputbox.cc
index 07a0a7e..6f493e2 100644
--- a/src/ui/inputbox.cc
+++ b/src/ui/inputbox.cc
@@ -18,7 +18,7 @@ InputBox::InputBox(Widget *parent) : Widget(parent)
input_text.clear();
input_pos = 0;
input_max = 512;
-
+
set_label("input");
set_background(false);
set_border(false);
@@ -72,7 +72,7 @@ void InputBox::draw()
size_t prompt_width = aux::text_length(input_prompt);
math::Vector2f v(global_location());
paint::color(palette()->text());
-
+
// draw the prompt
if (prompt_width) {
paint::text(v, size(), font(), input_prompt);
@@ -84,7 +84,7 @@ void InputBox::draw()
std::string firstpart(input_text.substr(0, input_pos));
size_t draw_width = 0;
const char *c = firstpart.c_str();
-
+
while (*c) {
if (aux::is_color_code(c)) {
c++;
@@ -93,7 +93,7 @@ void InputBox::draw()
}
c++;
}
-
+
c = firstpart.c_str();
while (*c && draw_width > text_width - prompt_width - 1) {
if (aux::is_color_code(c)) {
@@ -104,15 +104,15 @@ void InputBox::draw()
}
c++;
}
-
+
if (*c) {
paint::text(v, size(), font(), std::string(c));
}
-
+
// draw the part behind the cursor
v[0] += draw_width * font()->width();
if (input_pos < input_text.size()) {
- if (input_pos > 1 && aux::is_color_code(input_text.c_str() + input_pos -1)) {
+ if (input_pos > 1 && aux::is_color_code(input_text.c_str() + input_pos - 1)) {
paint::color_code(input_text[input_pos]);
}
// limit to width
@@ -130,7 +130,7 @@ void InputBox::draw()
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");
@@ -150,46 +150,46 @@ bool InputBox::on_keypress(const int key, const unsigned int modifier)
core::CommandBuffer::complete(input_text, input_pos);
return true;
break;
-
+
case SDLK_HOME:
input_pos = 0;
return true;
break;
-
+
case SDLK_END:
input_pos = input_text.size();
return true;
break;
-
+
case SDLK_LEFT:
if (input_pos > 0)
input_pos--;
return true;
break;
-
+
case SDLK_RIGHT:
if (input_pos < input_text.size())
input_pos++;
return true;
break;
-
+
case SDLK_DELETE:
if (input_text.size() && input_pos < input_text.size()) {
input_text.erase(input_pos, 1);
}
return true;
break;
-
+
case SDLK_BACKSPACE:
if (input_text.size() && input_pos) {
- input_text.erase(input_pos-1, 1);
+ input_text.erase(input_pos - 1, 1);
input_pos--;
}
return true;
break;
-
+
default:
- if ((key >= 32) && (key <175)) {
+ if ((key >= 32) && (key < 175)) {
if (input_text.size() < input_max) {
// TODO bell sound
if (input_pos == input_text.size())
@@ -202,7 +202,7 @@ bool InputBox::on_keypress(const int key, const unsigned int modifier)
}
break;
}
-
+
return false;
}
bool InputBox::on_keyrelease(const int key, const unsigned int modifier)
diff --git a/src/ui/inputbox.h b/src/ui/inputbox.h
index 961bbcf..d3e9d2c 100644
--- a/src/ui/inputbox.h
+++ b/src/ui/inputbox.h
@@ -18,10 +18,10 @@ class InputBox : public Widget
public:
InputBox(Widget *parent);
~InputBox();
-
+
/// set the text displayed by the label
void set_text(const std::string &text);
-
+
/// set the text displayed by the label
void set_text(const char *text);
@@ -33,25 +33,25 @@ public:
/// 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 {
return input_text;
}
-
+
/// clear the text
void clear();
-
+
protected:
/// draw the widget
virtual void draw();
-
+
/// called when the widget receives a key press
virtual bool on_keypress(const int key, const unsigned int modifier);
-
+
/// called when the widget receives a key release
virtual bool on_keyrelease(const int key, const unsigned int modifier);
-
+
private:
std::string input_text;
diff --git a/src/ui/label.cc b/src/ui/label.cc
index cf9b473..3284d0e 100644
--- a/src/ui/label.cc
+++ b/src/ui/label.cc
@@ -52,7 +52,7 @@ void Label::draw()
{
if (!label_text.size())
return;
-
+
paint::color(palette()->foreground());
paint::label(global_location(), size(), font(), text(), alignment());
}
diff --git a/src/ui/label.h b/src/ui/label.h
index beecfb4..9188dc5 100644
--- a/src/ui/label.h
+++ b/src/ui/label.h
@@ -17,35 +17,35 @@ namespace ui
class Label : public Widget
{
public:
- Label(Widget *parent, const char *text=0);
+ Label(Widget *parent, const char *text = 0);
~Label();
-
+
/// set the text displayed by the label
void set_text(const std::string &text);
-
+
/// set the text displayed by the label
void set_text(const char *text);
-
+
/// set the text alignment
void set_alignment(const unsigned int alignment);
-
+
/// return the text displayed by the label
inline const std::string &text() const {
return label_text;
}
-
+
/// text alignment
inline unsigned int alignment() const {
return label_alignment;
}
-
+
/// print label description
virtual void print(const size_t indent) const;
-
+
protected:
/// draw the label
virtual void draw();
-
+
private:
std::string label_text;
unsigned int label_alignment;
diff --git a/src/ui/menu.cc b/src/ui/menu.cc
index 716f5b4..c4dc214 100644
--- a/src/ui/menu.cc
+++ b/src/ui/menu.cc
@@ -18,7 +18,7 @@ Menu::Menu(Window *parent, const char *label) : Window(parent)
set_label(label);
set_border(false);
set_background(false);
-
+
menu_background = new Bitmap(this);
menu_container = new Container(this);
@@ -63,17 +63,17 @@ void Menu::resize()
bool Menu::on_keypress(const int key, const unsigned int modifier)
{
- switch( key ) {
-
- case SDLK_ESCAPE:
- if (visible()) {
- this->hide();
- return true;
- }
- break;
-
- default:
- break;
+ switch (key) {
+
+ case SDLK_ESCAPE:
+ if (visible()) {
+ this->hide();
+ return true;
+ }
+ break;
+
+ default:
+ break;
}
return Window::on_keypress(key, modifier);
diff --git a/src/ui/menu.h b/src/ui/menu.h
index c907d76..7fd211c 100644
--- a/src/ui/menu.h
+++ b/src/ui/menu.h
@@ -24,18 +24,18 @@ public:
/// create a new menu
Menu(Window *parent, const char * label = 0);
~Menu();
-
+
/// set the background bitmap
void set_background_texture(const char *texture);
/// set the background bitmap
void set_background_texture(const std::string &texture);
-
+
/// add a label
- Label *add_label(char const * text=0);
-
+ Label *add_label(char const * text = 0);
+
/// add a button with a command
- Button *add_button(char const *text=0, char const *command=0);
+ Button *add_button(char const *text = 0, char const *command = 0);
protected:
/// resize event
@@ -43,10 +43,10 @@ protected:
/// keypress event
virtual bool on_keypress(const int key, const unsigned int modifier);
-
+
private:
Bitmap *menu_background;
- Container *menu_container;
+ Container *menu_container;
};
}
diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc
index b913060..f247e5b 100755
--- a/src/ui/modelview.cc
+++ b/src/ui/modelview.cc
@@ -20,7 +20,7 @@ ModelView::ModelView(Widget *parent, const char *modelname) : Widget(parent)
set_border(false);
set_background(false);
set_label("modelview");
-
+
set_modelname(modelname);
modelview_zoom = 1.0f;
@@ -60,7 +60,7 @@ void ModelView::set_zoom(const float zoom)
}
bool ModelView::on_keypress(const int key, const unsigned int modifier)
-{
+{
if (key == 512 + SDL_BUTTON_WHEELUP) {
modelview_zoom -= 0.1f;
if (modelview_zoom < 1.0f)
@@ -84,7 +84,7 @@ void ModelView::draw()
paint::color(1.0f, 1.0f, 1.0f);
model::Model *model = model::Model::find(modelview_modelname);
- if (!model) {
+ if (!model) {
paint::bitmap(global_location(), size(), "bitmap/notex");
return;
}
@@ -118,7 +118,7 @@ void ModelView::draw()
gl::disable(GL_LIGHTING);
gl::disable(GL_COLOR_MATERIAL); // disable color tracking
gl::disable(GL_CULL_FACE); // disable culling
-
+
gl::depthmask(GL_TRUE); // enable depth buffer writing
gl::disable(GL_DEPTH_TEST); // disable depth buffer testing
@@ -131,7 +131,7 @@ void ModelView::draw()
void ModelView::draw_border()
{
paint::color(palette()->foreground());
- paint::border(global_location(), size());
+ paint::border(global_location(), size());
}
}
diff --git a/src/ui/modelview.h b/src/ui/modelview.h
index c9855db..54799f3 100755
--- a/src/ui/modelview.h
+++ b/src/ui/modelview.h
@@ -15,22 +15,22 @@ namespace ui
class ModelView : public Widget
{
public:
- ModelView(Widget *parent, const char *modelname=0);
+ ModelView(Widget *parent, const char *modelname = 0);
~ModelView();
-
+
inline std::string const &modelname() const {
return modelview_modelname;
}
-
+
inline math::Color const &color() const {
return modelview_color;
}
-
+
void set_modelname(const std::string & modelname);
void set_modelname(const char *modelname);
-
+
void set_color(const math::Color &color);
-
+
/// print modelview description
virtual void print(const size_t indent) const;
@@ -41,7 +41,7 @@ public:
* 1.0 is not zoomed out, 10.0 is zoomed out by a factor of 10
*/
void set_zoom(const float zoom);
-
+
protected:
/// draw the widget
virtual void draw();
diff --git a/src/ui/paint.cc b/src/ui/paint.cc
index 576484e..b3d6197 100644
--- a/src/ui/paint.cc
+++ b/src/ui/paint.cc
@@ -15,7 +15,8 @@ namespace ui
{
// contains the interface between the user interface and the render library
-namespace paint {
+namespace paint
+{
void assign_color(const char c, const math::Color &color)
{
@@ -40,7 +41,7 @@ void color_code(const char c)
void border(const math::Vector2f &location, const math::Vector2f &size)
{
using namespace gl;
-
+
begin(LineLoop);
vertex(location.x(), location.y());
vertex(location.x() + size.width(), location.y());
@@ -52,7 +53,7 @@ void border(const math::Vector2f &location, const math::Vector2f &size)
void rectangle(const math::Vector2f &location, const math::Vector2f &size)
{
using namespace gl;
-
+
begin(Quads);
vertex(location.x(), location.y());
vertex(location.x() + size.width(), location.y());
@@ -66,9 +67,9 @@ void bitmap(const math::Vector2f &location, const math::Vector2f &size, std::str
{
render::Textures::bind("bitmaps/" + texture);
gl::enable(GL_TEXTURE_2D);
-
+
gl::begin(gl::Quads);
-
+
glTexCoord2f(0.0f, 0.0f);
gl::vertex(location.x(), location.y());
@@ -82,7 +83,7 @@ void bitmap(const math::Vector2f &location, const math::Vector2f &size, std::str
gl::vertex(location.x(), location.y() + size.height());
gl::end();
-
+
gl::disable(GL_TEXTURE_2D);
}
@@ -92,25 +93,25 @@ void label(const math::Vector2f &location, const math::Vector2f &size, const Fon
unsigned int align_horizontal = (align & 0x000F);
if (!align_horizontal)
align_horizontal = AlignLeft;
-
+
unsigned int align_vertical = (align & 0x00F0);
if (!align_vertical)
align_vertical = AlignTop;
-
+
// apply text font
render::Text::setfont(font->name().c_str(), font->width(), font->height());
-
+
// enable OpenGL textures
gl::enable(GL_TEXTURE_2D);
-
+
// determine the width and height of the text
// FIXME support multiline text
float text_height = 1.0f * font->height();
float text_width = (float) aux::text_strip(text).size() * font->width();
-
+
// calculate drawing position
math::Vector2f v(location);
-
+
switch (align_horizontal) {
case AlignLeft:
v[0] += font->width();
@@ -122,36 +123,36 @@ void label(const math::Vector2f &location, const math::Vector2f &size, const Fon
v[0] += size.width() - text_width - font->width();
break;
}
-
+
switch (align_vertical) {
case AlignTop:
- v[1] += font->height()*0.5f;
+ v[1] += font->height() * 0.5f;
break;
case AlignVCenter:
v[1] += (size.height() - text_height) / 2.0f;
break;
case AlignBottom:
- v[1] += size.height() - text_height - font->height()*0.5f;
+ v[1] += size.height() - text_height - font->height() * 0.5f;
break;
}
-
+
render::Text::draw(v.x(), v.y(), text);
-
+
// disable OpenGL textures
gl::disable(GL_TEXTURE_2D);
-
+
}
// draw unaligned text
void text(const math::Vector2f &location, const math::Vector2f &size, const Font *font, const std::string &text)
{
render::Text::setfont(font->name().c_str(), font->width(), font->height());
-
+
// enable OpenGL textures
gl::enable(GL_TEXTURE_2D);
-
+
render::Text::draw(location.x(), location.y(), text);
-
+
// disable OpenGL textures
gl::disable(GL_TEXTURE_2D);
}
@@ -161,12 +162,12 @@ void text(const math::Vector2f &location, const math::Vector2f &size, const Font
{
render::Text::setfont(font->name().c_str(), font->width(), font->height());
-
+
// enable OpenGL textures
gl::enable(GL_TEXTURE_2D);
-
+
render::Text::draw(location.x(), location.y(), textstream);
-
+
// disable OpenGL textures
gl::disable(GL_TEXTURE_2D);
}
diff --git a/src/ui/paint.h b/src/ui/paint.h
index 840e18a..1d28574 100644
--- a/src/ui/paint.h
+++ b/src/ui/paint.h
@@ -13,13 +13,14 @@ namespace ui
{
/// low-level widget paint functions
-namespace paint {
+namespace paint
+{
/// assign system colors
void assign_color(const char c, const math::Color &color);
/// set paint color
-void color(float r=0.0f, float g=0.0f, float b=0.0f, float a=1.0f);
+void color(float r = 0.0f, float g = 0.0f, float b = 0.0f, float a = 1.0f);
/// set paint color
void color(math::Color const & color);
diff --git a/src/ui/palette.cc b/src/ui/palette.cc
index 2dec462..6492dc3 100644
--- a/src/ui/palette.cc
+++ b/src/ui/palette.cc
@@ -11,20 +11,20 @@ namespace ui
{
Palette::Palette() :
- palette_foreground(1.0f, 1.0f),
- palette_background(0.5f, 0.75f),
- 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),
- palette_mission(1.0f, 0.5f, 1.0f, 1.0f),
- palette_bold(1.0f, 1.0f),
- palette_fancy(0.0f, 1.0f, 0.0f, 1.0f),
- palette_warning(1.0f, 1.0f, 0.0f, 1.0f),
- palette_error(1.0f, 0.0f, 0.0f, 1.0f)
+ palette_foreground(1.0f, 1.0f),
+ palette_background(0.5f, 0.75f),
+ 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),
+ palette_mission(1.0f, 0.5f, 1.0f, 1.0f),
+ palette_bold(1.0f, 1.0f),
+ palette_fancy(0.0f, 1.0f, 0.0f, 1.0f),
+ palette_warning(1.0f, 1.0f, 0.0f, 1.0f),
+ palette_error(1.0f, 0.0f, 0.0f, 1.0f)
{
}
@@ -35,7 +35,7 @@ Palette::~Palette()
const math::Color &Palette::color(Color palettecolor) const
{
- switch(palettecolor) {
+ switch (palettecolor) {
case Foreground:
return foreground();
break;
diff --git a/src/ui/palette.h b/src/ui/palette.h
index 61a0b72..422c0e7 100644
--- a/src/ui/palette.h
+++ b/src/ui/palette.h
@@ -22,94 +22,81 @@ public:
/// default destructor
~Palette();
-
+
/// color index
- 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 };
+ 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 ------------------------------------------- */
/// set foreground color
- inline void set_foreground(const math::Color &color)
- {
+ inline void set_foreground(const math::Color &color) {
palette_foreground.assign(color);
}
-
+
/// set background color
- inline void set_background(const math::Color &color)
- {
+ inline void set_background(const math::Color &color) {
palette_background.assign(color);
}
-
+
/// set border color
- inline void set_border(const math::Color &color)
- {
+ inline void set_border(const math::Color &color) {
palette_border.assign(color);
}
-
+
/// set text color
- inline void set_text(const math::Color &color)
- {
+ inline void set_text(const math::Color &color) {
palette_text.assign(color);
}
-
+
/// set highlight color
- inline void set_highlight(const math::Color &color)
- {
+ inline void set_highlight(const math::Color &color) {
palette_highlight.assign(color);
}
-
+
/// set disabled color
- inline void set_disabled(const math::Color &color)
- {
+ inline void set_disabled(const math::Color &color) {
palette_disabled.assign(color);
}
/// set pointer color
- inline void set_pointer(const math::Color &color)
- {
+ inline void set_pointer(const math::Color &color) {
palette_pointer.assign(color);
}
-
+
/// set active pointer color
- inline void set_active(const math::Color &color)
- {
+ inline void set_active(const math::Color &color) {
palette_active.assign(color);
}
-
+
/// set debug color
- inline void set_debug(const math::Color &color)
- {
+ inline void set_debug(const math::Color &color) {
palette_debug.assign(color);
}
-
+
/// set mission color
- inline void set_mission(const math::Color &color)
- {
+ inline void set_mission(const math::Color &color) {
palette_mission.assign(color);
}
/// set bold text color
- inline void set_bold(const math::Color &color)
- {
+ inline void set_bold(const math::Color &color) {
palette_bold.assign(color);
}
-
+
/// set fancy text color
- inline void set_fancy(const math::Color &color)
- {
+ inline void set_fancy(const math::Color &color) {
palette_fancy.assign(color);
}
-
+
/// set warning text color
- inline void set_warning(const math::Color &color)
- {
+ inline void set_warning(const math::Color &color) {
palette_warning.assign(color);
}
/// set error text color
- inline void set_error(const math::Color &color)
- {
+ inline void set_error(const math::Color &color) {
palette_error.assign(color);
}
@@ -119,17 +106,17 @@ public:
inline const math::Color &foreground() const {
return palette_foreground;
}
-
+
/// background color
inline const math::Color &background() const {
return palette_background;
}
-
+
/// border color
inline const math::Color &border() const {
return palette_border;
}
-
+
/// text color
inline const math::Color &text() const {
return palette_text;
@@ -149,7 +136,7 @@ public:
inline const math::Color &pointer() const {
return palette_pointer;
}
-
+
/// active pointer color
inline const math::Color &active() const {
return palette_active;
@@ -187,7 +174,7 @@ public:
// indexed color
const math::Color &color(Palette::Color palettecolor) const;
-
+
private:
// UI colors
math::Color palette_foreground;
@@ -199,7 +186,7 @@ private:
math::Color palette_pointer;
math::Color palette_active;
math::Color palette_debug;
-
+
// HUD colors
math::Color palette_mission;
diff --git a/src/ui/scrollpane.cc b/src/ui/scrollpane.cc
index 20325d8..463956d 100644
--- a/src/ui/scrollpane.cc
+++ b/src/ui/scrollpane.cc
@@ -22,7 +22,7 @@ ScrollPane::ScrollPane(Widget *parent, ui::Text &text) : Widget(parent), scrollp
ScrollPane::~ScrollPane()
{
}
-
+
void ScrollPane::set_alignment(const unsigned int alignment)
{
scrollpane_alignment = alignment;
@@ -68,7 +68,7 @@ void ScrollPane::draw()
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;
@@ -100,8 +100,8 @@ void ScrollPane::draw()
}
// new word, wrap if necessary
- else if ((*c == '\n' ) || ( *c == ' ')) {
-
+ else if ((*c == '\n') || (*c == ' ')) {
+
if (line_length + word_length > (size_t) text_width) {
if (line.size()) {
lines.push_back(line);
@@ -111,33 +111,33 @@ void ScrollPane::draw()
line_length = 0;
}
}
-
+
line.append(word);
line_length += word_length;
word.clear();
word_length = 0;
wordpen = pen;
-
+
// new line
- if (*c == '\n' ) {
+ if (*c == '\n') {
lines.push_back(line);
line.clear();
line_length = 0;
pen = 'N';
wordpen = 'N';
- // new word
- } else if (*c == ' ' ) {
+ // new word
+ } else if (*c == ' ') {
line += ' ';
line_length++;
}
}
// new character
- else {
+ else {
word += *c;
word_length++;
-
+
if (word_length == (size_t) text_width) {
if (line.size()) {
lines.push_back(line);
@@ -158,15 +158,15 @@ void ScrollPane::draw()
c++;
}
-
+
}
- current_line++;
+ current_line++;
}
gl::color(palette()->text());
const math ::Vector2f gl(global_location());
float y = 0;
-
+
if ((alignment() & AlignTop) == AlignTop) {
int i = (int) lines.size();
for (ui::Text::iterator it = lines.begin(); it != lines.end(); it++) {
diff --git a/src/ui/scrollpane.h b/src/ui/scrollpane.h
index f0ffac1..82c74c9 100644
--- a/src/ui/scrollpane.h
+++ b/src/ui/scrollpane.h
@@ -23,12 +23,16 @@ public:
/* -- inspectors ------------------------------------------- */
/// current scroll position
- inline int scroll() const { return scrollpane_scroll; }
+ inline int scroll() const {
+ return scrollpane_scroll;
+ }
/// text alignment
- inline unsigned int alignment() const { return scrollpane_alignment; }
-
- /// set text alignment
+ inline unsigned int alignment() const {
+ return scrollpane_alignment;
+ }
+
+ /// set text alignment
void set_alignment(const unsigned int alignment);
/* -- mutators --------------------------------------------- */
@@ -45,7 +49,7 @@ public:
protected:
/// draw the scroll pane
virtual void draw();
-
+
private:
ui::Text &scrollpane_text;
int scrollpane_scroll;
diff --git a/src/ui/toolbar.cc b/src/ui/toolbar.cc
index 0d9dfe6..deeff17 100644
--- a/src/ui/toolbar.cc
+++ b/src/ui/toolbar.cc
@@ -7,7 +7,8 @@
#include "ui/toolbar.h"
#include "ui/button.h"
-namespace ui {
+namespace ui
+{
Toolbar::Toolbar(Widget *parent) : Widget(parent)
{
diff --git a/src/ui/toolbar.h b/src/ui/toolbar.h
index 4094f52..baff21b 100644
--- a/src/ui/toolbar.h
+++ b/src/ui/toolbar.h
@@ -10,13 +10,15 @@
#include "ui/widget.h"
-namespace ui {
+namespace ui
+{
/// a toolbar container widget
-class Toolbar : public Widget {
+class Toolbar : public Widget
+{
public:
/// default constructor
- Toolbar(Widget *parent=0);
+ Toolbar(Widget *parent = 0);
/// default destructor
virtual ~Toolbar();
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index f734a50..a6d54ab 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -41,7 +41,7 @@ UI *root()
void init()
{
con_print << "^BInitializing user interface..." << std::endl;
-
+
if (!global_ui) {
global_ui = new UI();
} else {
@@ -50,7 +50,7 @@ void init()
}
global_ui->load_menus();
- global_ui->load_settings();
+ global_ui->load_settings();
}
void shutdown()
@@ -71,19 +71,19 @@ UI::UI() : Window(0)
set_size(1024, 768);
set_border(false);
set_background(false);
-
+
// intialize console
ui_console = new Console(this);
// default palette
ui_palette = new Palette();
set_palette(ui_palette);
-
+
// default fonts
ui_font_small = new Font("gui", 12, 18);
ui_font_large = new Font("gui", 14, 24);
set_font(ui_font_small);
-
+
ui_mouse_focus = this;
ui_input_focus = this;
set_focus();
@@ -95,7 +95,7 @@ UI::UI() : Window(0)
UI::~UI()
{
delete ui_palette;
-
+
delete ui_font_small;
delete ui_font_large;
}
@@ -121,7 +121,7 @@ void UI::load_menus()
Button *button = 0;
Label *label = 0;
Menu *menu = 0;
-
+
while (ini.getline()) {
if (ini.got_section()) {
if (ini.got_section("menu")) {
@@ -131,10 +131,10 @@ void UI::load_menus()
} else if (menu) {
if (ini.got_section("button")) {
button = menu->add_button();
-
+
} else if (ini.got_section("label")) {
label = menu->add_label();
-
+
} else {
ini.unknown_section();
}
@@ -155,14 +155,14 @@ void UI::load_menus()
if (ini.got_key_string("text", strval)) {
aux::strip_quotes(strval);
button->set_text(strval);
-
+
} else if (ini.got_key_string("command", strval)) {
- for (size_t i =0; i <= strval.size(); i++) {
+ for (size_t i = 0; i <= strval.size(); i++) {
if (strval[i] == ',') strval[i] = ';';
}
aux::strip_quotes(strval);
button->set_command(strval);
-
+
} else if (ini.got_key_string("align", strval)) {
aux::to_label(strval);
if (strval.compare("left") == 0) {
@@ -195,7 +195,7 @@ void UI::load_menus()
ini.unkown_key();
}
}
-
+
}
}
@@ -211,7 +211,7 @@ void UI::load_menus()
menu->add_button("Connect", "connect");
menu->add_button("Quit", "quit");
}
-
+
// fallback game menu
if (!find_menu("game")) {
con_warn << "menu 'game' not found, using default" << std::endl;
@@ -236,16 +236,16 @@ void UI::load_settings()
{
ui_mouse_focus = this;
-
+
std::string filename("ui");
filesystem::IniFile ini;
ini.open(filename);
-
+
if (!ini.is_open()) {
con_error << "Could not open " << ini.name() << std::endl;
return;
}
-
+
std::string strval;
math::Color color;
@@ -253,16 +253,16 @@ void UI::load_settings()
float h = elementsize.height();
float m = elementmargin;
-
+
while (ini.getline()) {
-
+
if (ini.got_section()) {
if (ini.got_section("ui")) {
continue;
-
+
} else if (ini.got_section("colors")) {
continue;
-
+
} else if (ini.got_section("hud")) {
continue;
@@ -273,9 +273,9 @@ void UI::load_settings()
ini.unknown_section();
continue;
}
-
+
} else if (ini.got_key()) {
-
+
if (ini.in_section("ui")) {
if (ini.got_key_float("elementwidth", w)) {
elementsize.assign(w, h);
@@ -290,9 +290,9 @@ void UI::load_settings()
ini.unkown_key();
continue;
}
-
+
} else if (ini.in_section("colors")) {
-
+
if (ini.got_key_color("foreground", color)) {
ui_palette->set_foreground(color);
continue;
@@ -352,7 +352,7 @@ void UI::load_settings()
}
}
}
-
+
ini.close();
}
@@ -388,7 +388,7 @@ UI::Menus::iterator UI::find_menu(Window *menu)
if ((*it) == menu)
return it;
}
-
+
return it;
}
@@ -418,13 +418,13 @@ void UI::add_menu(Window *menu)
if (it == ui_menus.end()) {
ui_menus.push_back(menu);
}
-
+
}
void UI::show_menu(const char *label)
{
Window *menu = find_menu(label);
-
+
if (menu) {
if (ui_active_menu) {
ui_active_menu->hide();
@@ -438,7 +438,7 @@ void UI::show_menu(const char *label)
ui_active_menu = menu;
ui_active_menu->event_resize();
ui_active_menu->show();
-
+
set_pointer("pointer");
// raise console if it is visible
@@ -524,17 +524,17 @@ bool UI::input_key(const bool pressed, const int key, const unsigned int modifie
bool UI::on_keypress(const int key, const unsigned int modifier)
{
- switch( key ) {
-
- case SDLK_ESCAPE:
- if (active()) {
- hide_menu();
- audio::play("ui/menu");
- }
- return true;
- break;
- default:
- break;
+ switch (key) {
+
+ case SDLK_ESCAPE:
+ if (active()) {
+ hide_menu();
+ audio::play("ui/menu");
+ }
+ return true;
+ break;
+ default:
+ break;
}
return false;
@@ -570,7 +570,7 @@ void UI::draw_pointer()
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);
@@ -578,7 +578,7 @@ void UI::draw_pointer()
gl::push();
gl::translate(mouse_cursor.x(), mouse_cursor.y(), 0);
- float angle = core::application()->time()* 0.75f - floorf(core::application()->time() * 0.75f);
+ float angle = core::application()->time() * 0.75f - floorf(core::application()->time() * 0.75f);
angle *= 360.0f;
gl::rotate(angle, math::Vector3f(0, 0, 1.0f));
gl::translate(-mouse_cursor.x(), -mouse_cursor.y(), 0);
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 2e4bc50..c340eb8 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -21,71 +21,73 @@ class UI : public Window
public:
/// constructor
UI();
-
+
/// destructor
~UI();
-
+
/// list widgets
void list() const;
/// list visible widgets
void list_visible() const;
-
+
/// list meus
void list_menus() const;
-
+
/// load menus from menu.ini
void load_menus();
- /// load settings from ui.ini
+ /// load settings from ui.ini
void load_settings();
/// apply UI options to the render engine
void apply_render_options();
-
+
/// make a window the active window
void show_menu(const char *label);
/// hide the active window
void hide_menu();
-
+
/// show previous window
void previous_menu();
/// the console
- inline Console *console() { return ui_console; }
-
+ inline Console *console() {
+ return ui_console;
+ }
+
/// return the active menu
Window *active() {
return ui_active_menu;
}
-
+
/// return the widget with global mouse focus
inline Widget *mouse_focus() const {
return ui_mouse_focus;
}
-
+
/// return the widget with global input focus
inline Widget *input_focus() const {
return ui_input_focus;
}
-
+
/// receive global mouse movement
void input_mouse(const float x, const float y);
-
+
/// receive global key input
bool input_key(const bool pressed, const int key, const unsigned int modifier);
/// run a user interface frame
void frame();
-
+
/* -- fonts ------------------------------------------------ */
-
+
/// default small font
inline const Font *font_small() const {
return ui_font_small;
}
-
+
/// default medium font
inline const Font *font_large() const {
return ui_font_large;
@@ -94,28 +96,28 @@ public:
/* -- mouse pointer ---------------------------------------- */
/// set mouse pointer bitmap
- void set_pointer(const char *pointerbitmap=0, const Palette::Color color = Palette::Highlight,const bool animated = false);
+ void set_pointer(const char *pointerbitmap = 0, const Palette::Color color = Palette::Highlight, const bool animated = false);
static bool ui_debug;
-
+
static float elementmargin;
static math::Vector2f elementsize;
protected:
typedef std::list<Window *> Menus;
-
+
Menus::iterator find_menu(Window *menu);
Window *find_menu(const char *label);
void add_menu(Window *window);
/* -- event handlers --------------------------------------- */
-
+
/// handle keypress events
virtual bool on_keypress(const int key, const unsigned int modifier);
-
+
/// handle key release events
virtual bool on_keyrelease(const int key, const unsigned int modifier);
@@ -125,15 +127,15 @@ private:
Palette *ui_palette;
Font *ui_font_small;
Font *ui_font_large;
-
+
Window *ui_active_menu;
Widget *ui_mouse_focus;
Widget *ui_input_focus;
-
+
Console *ui_console;
Menus ui_menus;
-
+
/// TODO move to separate object to handle mouse cursor drawing
math::Vector2f mouse_cursor;
std::string mouse_pointer_bitmap;
@@ -151,10 +153,16 @@ void shutdown();
UI *root();
/// the console
-inline Console *console() { return root()->console(); }
+inline Console *console()
+{
+ return root()->console();
+}
/// debug mode
-inline bool debug() { return UI::ui_debug; }
+inline bool debug()
+{
+ return UI::ui_debug;
+}
}
diff --git a/src/ui/widget.cc b/src/ui/widget.cc
index b1157d5..2e2f291 100644
--- a/src/ui/widget.cc
+++ b/src/ui/widget.cc
@@ -22,13 +22,13 @@ Widget::Widget(Widget *parent)
widget_palette = 0;
widget_font = 0;
widget_label.assign("widget");
-
+
if (!parent) {
widget_parent = root();
} else {
widget_parent = parent;
}
-
+
if (widget_parent)
widget_parent->add_child(this);
}
@@ -55,7 +55,7 @@ size_t Widget::list(const size_t indent, const bool visible_only) const
print(indent);
size_t n = 1;
for (Children::const_iterator it = widget_children.begin(); it != widget_children.end(); it++) {
- n += (*it)->list(indent+1, visible_only);
+ n += (*it)->list(indent + 1, visible_only);
}
return n;
}
@@ -94,7 +94,7 @@ void Widget::lower()
{
if (!parent())
return;
-
+
Children::iterator it = parent()->find_child(this);
if (it != parent()->children().end()) {
parent()->children().erase(it);
@@ -106,7 +106,7 @@ void Widget::raise()
{
if (!parent())
return;
-
+
Children::iterator it = parent()->find_child(this);
if (it != parent()->children().end()) {
parent()->children().erase(it);
@@ -120,11 +120,11 @@ void Widget::set_focus()
widget_focus = true;
return;
}
-
+
for (Children::iterator it = parent()->children().begin(); it != parent()->children().end(); it++) {
(*it)->widget_focus = false;
}
-
+
widget_focus = true;
}
@@ -138,7 +138,7 @@ void Widget::hide()
widget_visible = false;
if (parent() && focus()) {
Widget::Children::reverse_iterator it = parent()->children().rbegin();
-
+
while (it != parent()->children().rend()) {
Widget *w = (*it);
if (w != this && w->visible()) {
@@ -185,7 +185,7 @@ void Widget::set_label(char const *label)
aux::to_label(widget_label);
} else {
widget_label.clear();
- }
+ }
}
void Widget::set_palette(const Palette *palette)
@@ -247,7 +247,7 @@ Widget::Children::iterator Widget::find_child(Widget *child)
if ((*it) == child)
return it;
}
-
+
return it;
}
@@ -274,7 +274,7 @@ Widget *Widget::find_input_focus()
{
if (!visible() || !widget_focus)
return 0;
-
+
for (Children::reverse_iterator rit = widget_children.rbegin(); rit != widget_children.rend(); ++rit) {
Widget *w = (*rit);
if (w->visible() && w->widget_focus) {
@@ -283,7 +283,7 @@ Widget *Widget::find_input_focus()
return f;
}
}
-
+
// no child with input focus
return this;
}
@@ -293,7 +293,7 @@ Widget *Widget::find_mouse_focus(const math::Vector2f & pos)
// this widget is not visible
if (!visible() || !size().contains(pos))
return 0;
-
+
// reverse-iterate children
for (Children::reverse_iterator rit = widget_children.rbegin(); rit != widget_children.rend(); ++rit) {
Widget *w = (*rit);
@@ -302,9 +302,9 @@ Widget *Widget::find_mouse_focus(const math::Vector2f & pos)
if (f)
return f;
}
-
+
}
-
+
// no child with mouse focus
return this;
}
@@ -324,16 +324,16 @@ bool Widget::has_input_focus() const
bool Widget::event_key(const bool pressed, const int key, const unsigned int modifier)
{
bool handled = false;
-
+
if (pressed) {
handled = on_keypress(key, modifier);
} else {
handled = on_keyrelease(key, modifier);
}
-
+
if (!handled && parent())
handled = parent()->event_key(pressed, key, modifier);
-
+
return handled;
}
@@ -341,11 +341,11 @@ bool Widget::event_mouse(const math::Vector2f &cursor)
{
math::Vector2f local_cursor = to_local_coords(cursor);
bool handled = false;
-
+
if (root()->mouse_focus() != this) {
on_mouseover(local_cursor);
}
-
+
on_mousemove(local_cursor);
return handled;
}
@@ -354,7 +354,7 @@ void Widget::event_draw()
{
if (!visible())
return;
-
+
if (widget_background)
draw_background();
if (widget_border)
@@ -362,7 +362,7 @@ void Widget::event_draw()
if (debug())
draw_debug_border();
draw();
-
+
for (Children::iterator it = widget_children.begin(); it != widget_children.end(); it++) {
if ((*it)->visible())
(*it)->event_draw();
diff --git a/src/ui/widget.h b/src/ui/widget.h
index 20e4ac4..1f87695 100644
--- a/src/ui/widget.h
+++ b/src/ui/widget.h
@@ -28,28 +28,28 @@ class Widget
public:
/// create a new widget
- Widget(Widget *parent=0);
-
+ Widget(Widget *parent = 0);
+
/// destroy a widget
virtual ~Widget();
-
+
/// parent widget this widget belongs to
inline Widget *parent() const {
return widget_parent;
}
-
+
/* -- inspectors -------------------------------------------- */
-
+
/// pixel coordinates of the top-left corner of this widget within its parent
inline const math::Vector2f &location() const {
return widget_location;
}
-
+
/// size of this widget in pixels
inline const math::Vector2f &size() const {
return widget_size;
}
-
+
/// x coordinate of the left of the widget
/**
* @see location()
@@ -66,7 +66,7 @@ public:
inline float right() const {
return widget_location.x() + widget_size.width();
}
-
+
/// y coordinate of the top of the widget
/**
* @see location()
@@ -83,7 +83,7 @@ public:
inline float bottom() const {
return widget_location.y() + widget_size.height();
}
-
+
/// width of the widget in pixels
/**
* @see size()
@@ -91,7 +91,7 @@ public:
inline float width() const {
return widget_size.width();
}
-
+
/// height of the widget in pixels
/**
* @see size()
@@ -99,61 +99,61 @@ public:
inline float height() const {
return widget_size.height();
}
-
+
/// widget label
inline const std::string &label() const {
return widget_label;
}
-
+
/// true if this widget will draw a background
inline bool background() const {
return widget_background;
}
-
+
/// true if this widget will draw a border
inline bool border() const {
return widget_border;
}
-
+
/// true if this widget is visible
inline bool visible() const {
return widget_visible;
}
-
+
/// true if this widget is not visible
inline bool hidden() const {
return !widget_visible;
}
-
+
/// the palette used to draw this widget
const Palette *palette() const;
-
+
/// the font used to draw this widget
const Font *font() const;
-
+
/// return true if the widget has input focus
bool has_input_focus() const;
-
+
/// returns true if the widget has mouse focus
bool has_mouse_focus() const;
-
+
/* -- mutators --------------------------------------------- */
-
+
/// raise the widget to the top of the widget stack
void raise();
-
+
/// lower the widget to the bottom of the widget stack
void lower();
-
+
/// show the widget
virtual void show();
-
+
/// hide the widget
virtual void hide();
-
+
/// set visibility
void set_visible(bool visible = true);
-
+
/// set input focus
void set_focus();
@@ -162,57 +162,57 @@ public:
/// set the widget geometry
void set_geometry(const math::Vector2f &location, const math::Vector2f &size);
-
+
/// set location of the top-left corner, relative to the parent
void set_location(const float x, const float y);
-
+
/// set location of the top-left corner, relative to the parent
void set_location(const math::Vector2f &location);
-
+
/// set the widgets width and height
void set_size(const float w, const float h);
-
+
/// set the widgets width and height
void set_size(const math::Vector2f &size);
-
+
/// set the widgets width
void set_width(const float w);
-
+
/// set the widgets height
void set_height(const float h);
-
+
/// set the widgets palette
void set_palette(const Palette *palette);
-
+
/// set the widgets font
void set_font(const Font *font);
-
+
/// set the widgets label
void set_label(std::string const &label);
-
+
/// set the widgets label
void set_label(const char *label);
-
+
/// enable or disable widget border
void set_border(bool border = true);
-
+
///enable or disable widget background
void set_background(bool background = true);
-
+
/* -- event distributors ----------------------------------- */
-
+
/// distribute resize event
virtual void event_resize();
-
+
/// distribute draw event
virtual void event_draw();
-
+
/// distribute keyboard events
virtual bool event_key(const bool pressed, const int key, const unsigned int modifier);
-
+
/// distribute mouse movement events
virtual bool event_mouse(const math::Vector2f &cursor);
-
+
protected:
/// type definition for child widgets
typedef std::list<Widget *> Children;
@@ -221,7 +221,7 @@ protected:
inline Children &children() {
return widget_children;
}
-
+
/// find the widget that has input focus
virtual Widget *find_input_focus();
@@ -229,18 +229,20 @@ protected:
/** @param cursor mouse cursor position relative to this widget's location
*/
Widget *find_mouse_focus(const math::Vector2f & cursor);
-
+
/// list widget content
size_t list(const size_t indent, const bool visible_only = false) const;
-
+
/// print widget description
virtual void print(const size_t indent) const;
/// true of this sibling has local focus
- inline bool focus() const { return widget_focus; }
-
+ inline bool focus() const {
+ return widget_focus;
+ }
+
/* -- coordinate mapping ----------------------------------- */
-
+
/// map local coordinates to global coordinates
inline math::Vector2f to_global_coords(const math::Vector2f &local) {
math::Vector2f v(local);
@@ -251,7 +253,7 @@ protected:
} while (parent);
return v;
}
-
+
/// map global coordinates to local coordinates
inline math::Vector2f to_local_coords(const math::Vector2f &global) {
math::Vector2f v(global);
@@ -262,7 +264,7 @@ protected:
}
return v;
}
-
+
/// map local widget location to global location
inline math::Vector2f global_location() {
math::Vector2f v(widget_location);
@@ -273,35 +275,35 @@ protected:
}
return v;
}
-
+
/* -- event handlers --------------------------------------- */
-
+
/// called when the mouse receives mouse movement
virtual void on_mousemove(const math::Vector2f &cursor);
-
+
/// called when the mouse enters the widget
virtual void on_mouseover(const math::Vector2f &cursor);
-
+
/// called when the widget receives a key press
virtual bool on_keypress(const int key, const unsigned int modifier);
-
+
/// called when the widget receives a key release
virtual bool on_keyrelease(const int key, const unsigned int modifier);
-
+
/* -- draw functions --------------------------------------- */
-
+
/// resize event
virtual void resize();
-
+
/// draw the widget
virtual void draw();
-
+
/// draw the widget background
virtual void draw_background();
-
+
/// draw the widget border
virtual void draw_border();
-
+
/// add a child widget
virtual void add_child(Widget *child);
@@ -310,7 +312,7 @@ protected:
/// remove all child widgets
virtual void remove_children();
-
+
private:
void draw_debug_border();
@@ -318,19 +320,19 @@ private:
bool widget_background;
bool widget_border;
bool widget_focus;
-
+
math::Vector2f widget_location;
math::Vector2f widget_size;
std::string widget_label;
-
+
Children widget_children;
-
+
const Palette *widget_palette;
const Font *widget_font;
Widget *widget_parent;
-
+
Children::iterator find_child(Widget *child);
-
+
};
}
diff --git a/src/ui/window.cc b/src/ui/window.cc
index 8494f34..0e545be 100644
--- a/src/ui/window.cc
+++ b/src/ui/window.cc
@@ -48,7 +48,7 @@ void Window::clear_previous()
void Window::draw_border()
{
paint::color(palette()->border());
- paint::border(global_location(), size());
+ paint::border(global_location(), size());
}
}
diff --git a/src/ui/window.h b/src/ui/window.h
index 2a077ff..6c44d54 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -17,9 +17,9 @@ class Window : public Widget
{
public:
- Window(Widget *parent=0);
+ Window(Widget *parent = 0);
~Window();
-
+
/// set the label of the previous window
void set_previous(Window *previous);
@@ -30,11 +30,11 @@ public:
/**show() sets focus on the window and all of its parents
*/
virtual void show();
-
+
inline const std::string &previous() const {
return window_previous;
}
-
+
protected:
virtual void draw_border();