/* client/testmodelwindow.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/testmodelwindow.h" #include "model/model.h" #include "core/gameinterface.h" namespace client { TestModelWindow::TestModelWindow(ui::Widget *parent) { set_background(true); set_border(false); set_label("testmodelwindow"); testmodelwindow_modelview = new ui::ModelView(this); testmodelwindow_modelview->set_radius(1.0f); testmodelwindow_text = new ui::PlainText(this); testmodelwindow_text->set_label("text"); testmodelwindow_text->set_background(false); testmodelwindow_text->set_border(false); testmodelwindow_wireframebutton = new ui::IconButton(this, "bitmaps/icons/button_wireframe", "toggle r_wireframe"); testmodelwindow_normalsbutton = new ui::IconButton(this, "bitmaps/icons/button_normals", "toggle r_normals"); testmodelwindow_closebutton = new ui::Button(this); testmodelwindow_closebutton->set_text("Close"); testmodelwindow_closebutton->set_background(true); } TestModelWindow::~TestModelWindow() { } void TestModelWindow::set_modelname(const std::string & modelname) { testmodelwindow_modelview->set_modelname(modelname); testmodelwindow_modelview->set_colors(core::localplayer()->color(), core::localplayer()->color_second()); } void TestModelWindow::resize() { // this is a fullscreen window set_size(parent()->size()); // resize the label testmodelwindow_text->set_size(width() - 16.0f, testmodelwindow_text->font()->height() * 5.0f); testmodelwindow_text->set_location(8.0f, 8.0f); // resize the 3d model view testmodelwindow_modelview->set_size(width(),height()); testmodelwindow_modelview->set_location(0.0f, 0.0f); // resize icon buttons const float icon_margin = 4.0f; const float icon_size = 48.0f; const float icon_count = 2; const float l = (width() - ((icon_count + 1) * icon_margin) - (icon_count * icon_size)) * 0.5f; testmodelwindow_wireframebutton->set_geometry(l, icon_margin, icon_size, icon_size); testmodelwindow_normalsbutton->set_geometry(l + 1.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); // reposition close button testmodelwindow_closebutton->set_size( ui::UI::elementsize.width() * 1.5f, ui::UI::elementsize.height() ); testmodelwindow_closebutton->set_location( width() - testmodelwindow_closebutton->width() - ui::UI::elementsize.height(), height() - testmodelwindow_closebutton->height() - ui::UI::elementsize.height() * 0.5f ); } void TestModelWindow::draw_background() { math::Color color(palette()->background()); color.a = 1.0f; ui::Paint::set_color(color); ui::Paint::draw_rectangle(global_location(), size()); } void TestModelWindow::draw() { model::Model *model = model::Model::find(testmodelwindow_modelview->modelname()); std::ostringstream str; str << testmodelwindow_modelview->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'; } testmodelwindow_text->set_text(str.str()); } bool TestModelWindow::on_emit(Widget *sender, const Event event, void *data) { if (event == ui::Widget::EventButtonClicked) { // slider value changed if (sender == testmodelwindow_closebutton) { hide(); } return true; } return false; } } // namespace client