Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-06-07 18:13:15 +0000
committerStijn Buys <ingar@osirion.org>2009-06-07 18:13:15 +0000
commitf33257521bf80dcef8575c4fc3ddaf4a40ff588a (patch)
tree5e3a112e814478ba3ab624e0867761654a5ea0a4 /src/ui
parent5b94df1df2707b36401d91d80b92d0e4cdfd2277 (diff)
fixed a few widget order problems, changed map targetting behaviour
Diffstat (limited to 'src/ui')
-rwxr-xr-xsrc/ui/modelview.cc27
-rwxr-xr-xsrc/ui/modelview.h12
-rw-r--r--src/ui/ui.cc6
-rw-r--r--src/ui/ui.h3
-rw-r--r--src/ui/widget.cc7
-rw-r--r--src/ui/widget.h2
6 files changed, 53 insertions, 4 deletions
diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc
index 11dd318..e3816cd 100755
--- a/src/ui/modelview.cc
+++ b/src/ui/modelview.cc
@@ -22,6 +22,8 @@ ModelView::ModelView(Widget *parent, const char *modelname) : Widget(parent)
set_label("modelview");
set_modelname(modelname);
+
+ modelview_zoom = 1.0f;
}
ModelView::~ModelView()
@@ -51,6 +53,29 @@ void ModelView::set_color(const math::Color & color)
modelview_color.assign(color);
}
+void ModelView::set_zoom(const float zoom)
+{
+ modelview_zoom = zoom;
+ math::clamp(modelview_zoom, 1.0f, 10.0f);
+}
+
+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)
+ modelview_zoom = 1.0f;
+ return true;
+ } else if (key == 512 + SDL_BUTTON_WHEELDOWN) {
+ modelview_zoom += 0.1f;
+ if (modelview_zoom > 10.0f)
+ modelview_zoom = 10.0f;
+ return true;
+ }
+
+ return false;
+}
+
void ModelView::draw()
{
if (!modelview_modelname.size())
@@ -68,7 +93,7 @@ void ModelView::draw()
gl::clear(GL_DEPTH_BUFFER_BIT);
// gl 3d mode
- render::Camera::frustum_default(model->radius(), center.x, center.y);
+ render::Camera::frustum_default(model->radius() * modelview_zoom, center.x, center.y);
gl::disable(GL_BLEND);
gl::depthmask(GL_TRUE); // enable writing to the depth buffer
diff --git a/src/ui/modelview.h b/src/ui/modelview.h
index 1fbb4d9..c9855db 100755
--- a/src/ui/modelview.h
+++ b/src/ui/modelview.h
@@ -33,6 +33,14 @@ public:
/// print modelview description
virtual void print(const size_t indent) const;
+
+ /**
+ * @brief set the zoom out factor
+ * @param zoom the new zoom factor
+ * The zoom factor will be clamped to the range [1.0-10.0]
+ * 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
@@ -41,9 +49,13 @@ protected:
/// draw border
void draw_border();
+ /// keypress event handler
+ virtual bool on_keypress(const int key, const unsigned int modifier);
+
private:
std::string modelview_modelname;
math::Color modelview_color;
+ float modelview_zoom;
};
}
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index b7d1155..b60a65e 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -375,6 +375,12 @@ void UI::list() const
con_print << n << " user interface widgets" << std::endl;
}
+void UI::list_visible() const
+{
+ size_t n = Widget::list(0, true);
+ con_print << n << " visible user interface widgets" << std::endl;
+}
+
UI::Menus::iterator UI::find_menu(Window *menu)
{
Menus::iterator it;
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 6216ba7..2e4bc50 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -27,6 +27,9 @@ public:
/// list widgets
void list() const;
+
+ /// list visible widgets
+ void list_visible() const;
/// list meus
void list_menus() const;
diff --git a/src/ui/widget.cc b/src/ui/widget.cc
index 15fa10f..cc53c9f 100644
--- a/src/ui/widget.cc
+++ b/src/ui/widget.cc
@@ -47,12 +47,15 @@ void Widget::remove_children()
widget_children.clear();
}
-size_t Widget::list(const size_t indent) const
+size_t Widget::list(const size_t indent, const bool visible_only) const
{
+ if (visible_only && !visible())
+ return 0;
+
print(indent);
size_t n = 1;
for (Children::const_iterator it = widget_children.begin(); it != widget_children.end(); it++) {
- n += (*it)->list(indent+1);
+ n += (*it)->list(indent+1, visible_only);
}
return n;
}
diff --git a/src/ui/widget.h b/src/ui/widget.h
index d8969cc..2de7a3d 100644
--- a/src/ui/widget.h
+++ b/src/ui/widget.h
@@ -231,7 +231,7 @@ protected:
Widget *find_mouse_focus(const math::Vector2f & cursor);
/// list widget content
- size_t list(const size_t indent) const;
+ size_t list(const size_t indent, const bool visible_only = false) const;
/// print widget description
virtual void print(const size_t indent) const;