Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/testmodelview.cc')
-rw-r--r--src/client/testmodelview.cc114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/client/testmodelview.cc b/src/client/testmodelview.cc
new file mode 100644
index 0000000..31dc98f
--- /dev/null
+++ b/src/client/testmodelview.cc
@@ -0,0 +1,114 @@
+/*
+ client/testmodelview.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
+*/
+
+#include "ui/ui.h"
+#include "ui/paint.h"
+#include "client/testmodelview.h"
+#include "model/model.h"
+
+namespace client
+{
+
+TestModelView::TestModelView(ui::Widget *parent)
+{
+ set_background(true);
+ set_border(false);
+ set_label("testmodelview");
+ testmodelview_modelview = new ui::ModelView(this);
+ testmodelview_modelview->set_radius(1.0f);
+
+ testmodelview_text = new ui::PlainText(this);
+ testmodelview_text->set_label("text");
+ testmodelview_text->set_background(false);
+ testmodelview_text->set_border(false);
+
+ testmodelview_closebutton = new ui::Button(this);
+ testmodelview_closebutton->set_text("Close");
+ testmodelview_closebutton->set_background(true);
+}
+
+TestModelView::~TestModelView()
+{
+}
+
+void TestModelView::set_modelname(const std::string & modelname)
+{
+ model::Model *model = model::Model::load(modelname);
+ testmodelview_modelview->set_modelname(modelname);
+
+ std::ostringstream str;
+ str << modelname << '\n';
+
+ if (model) {
+ size_t frags = 0;
+
+ for (model::Model::Groups::const_iterator git = model->groups().begin(); git != model->groups().end(); git++) {
+ frags += (*git)->size();
+ }
+ str << '\n';
+ str << "tris: " << model->model_tris_count << '\n';
+ str << "quads: " << model->model_quad_count << '\n';
+ str << "fragments: " << frags << '\n';
+ }
+ testmodelview_text->set_text(str.str());
+}
+
+void TestModelView::show()
+{
+ resize();
+ ui::Widget::show();
+}
+
+void TestModelView::hide() {
+ ui::Widget::hide();
+}
+
+void TestModelView::resize()
+{
+ // this view covers the entire screen
+ set_size(parent()->size());
+
+ // resize the label
+ testmodelview_text->set_size(width() - 16.0f, testmodelview_text->font()->height() * 5.0f);
+ testmodelview_text->set_location(8.0f, 8.0f);
+
+ // resize the 3d model view
+ testmodelview_modelview->set_size(width(),height());
+ testmodelview_modelview->set_location(0.0f, 0.0f);
+
+ // reposition close button
+ testmodelview_closebutton->set_size(
+ ui::UI::elementsize.width() * 1.5f,
+ ui::UI::elementsize.height()
+ );
+ testmodelview_closebutton->set_location(
+ width() - testmodelview_closebutton->width() - ui::UI::elementsize.height(),
+ height() - testmodelview_closebutton->height() - ui::UI::elementsize.height() * 0.5f
+ );
+}
+
+void TestModelView::draw_background()
+{
+ math::Color color(palette()->background());
+ color.a = 1.0f;
+ ui::Paint::set_color(color);
+ ui::Paint::draw_rectangle(global_location(), size());
+}
+
+bool TestModelView::on_emit(Widget *sender, const Event event, void *data)
+{
+ if (event == ui::Widget::EventButtonClicked) {
+ // slider value changed
+ if (sender == testmodelview_closebutton) {
+ hide();
+ }
+ return true;
+ }
+ return false;
+}
+
+} // namespace client
+