Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 16d9cc1083633d17b93b1e8bb3421044b21bd78b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
   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_wireframebutton = new ui::IconButton(this, "bitmaps/icons/button_wireframe", "toggle r_wireframe");
	
	testmodelview_normalsbutton  = new ui::IconButton(this, "bitmaps/icons/button_normals", "toggle r_normals");
	
	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)
{
	testmodelview_modelview->set_modelname(modelname);
}

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);
	
	// 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;

	testmodelview_wireframebutton->set_geometry(l, icon_margin, icon_size, icon_size);
	testmodelview_normalsbutton->set_geometry(l + 1.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
	
	// 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());
}

void TestModelView::draw()
{
	model::Model *model = model::Model::find(testmodelview_modelview->modelname());
	
	std::ostringstream str;
	str << testmodelview_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';
	}
	testmodelview_text->set_text(str.str());
}

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