goat3d

diff goatview/src/goatview.cc @ 88:7941e89798e5

selections
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 15 May 2014 06:52:01 +0300
parents 91e3aa1a60c3
children 8b156bc5205b
line diff
     1.1 --- a/goatview/src/goatview.cc	Wed May 14 18:28:38 2014 +0300
     1.2 +++ b/goatview/src/goatview.cc	Thu May 15 06:52:01 2014 +0300
     1.3 @@ -11,6 +11,7 @@
     1.4  
     1.5  goat3d *scene;
     1.6  static SceneModel *sdata;
     1.7 +static GoatViewport *glview;
     1.8  
     1.9  static long anim_time;
    1.10  static float cam_theta, cam_phi, cam_dist = 8;
    1.11 @@ -18,6 +19,11 @@
    1.12  static bool use_nodes = true;
    1.13  static bool use_lighting = true;
    1.14  
    1.15 +void post_redisplay()
    1.16 +{
    1.17 +	glview->updateGL();
    1.18 +}
    1.19 +
    1.20  
    1.21  GoatView::GoatView()
    1.22  {
    1.23 @@ -105,7 +111,7 @@
    1.24  	act_use_nodes->setCheckable(true);
    1.25  	act_use_nodes->setChecked(use_nodes);
    1.26  	connect(act_use_nodes, &QAction::triggered, this,
    1.27 -			[&](){ use_nodes = !use_nodes; glview->updateGL(); });
    1.28 +			[&](){ use_nodes = !use_nodes; post_redisplay(); });
    1.29  	menu_view->addAction(act_use_nodes);
    1.30  
    1.31  	QAction *act_use_lighting = new QAction("lighting", this);
    1.32 @@ -137,19 +143,17 @@
    1.33  
    1.34  	// make the tree view widget
    1.35  	treeview = new QTreeView;
    1.36 -	/*
    1.37 -	scntree->setColumnCount(1);
    1.38 -	QStringList hdrstr;
    1.39 -	hdrstr << "Node";// << "Type";
    1.40 -	scntree->setHeaderItem(new QTreeWidgetItem((QTreeWidget*)0, hdrstr));
    1.41 -	*/
    1.42  	treeview->setAlternatingRowColors(true);
    1.43 +	treeview->setSelectionMode(QAbstractItemView::SingleSelection);
    1.44  	dock_vbox->addWidget(treeview);
    1.45  
    1.46  	scene_model = new SceneModel;
    1.47 -	connect(scene_model, &SceneModel::dataChanged, [&](){ glview->updateGL(); });
    1.48 +	connect(scene_model, &SceneModel::dataChanged, [&](){ post_redisplay(); });
    1.49  	treeview->setModel(scene_model);
    1.50  
    1.51 +	connect(treeview->selectionModel(), &QItemSelectionModel::selectionChanged,
    1.52 +			[&](){ scene_model->selchange(treeview->selectionModel()->selectedIndexes()); });
    1.53 +
    1.54  	// misc
    1.55  	QPushButton *bn_quit = new QPushButton("quit");
    1.56  	dock_vbox->addWidget(bn_quit);
    1.57 @@ -174,7 +178,7 @@
    1.58  
    1.59  bool GoatView::make_center()
    1.60  {
    1.61 -	glview = new GoatViewport(this);
    1.62 +	glview = ::glview = new GoatViewport(this);
    1.63  	setCentralWidget(glview);
    1.64  	return true;
    1.65  }
    1.66 @@ -316,6 +320,43 @@
    1.67  			goat3d_mesh *mesh = (goat3d_mesh*)goat3d_get_node_object(node);
    1.68  
    1.69  			draw_mesh(mesh);
    1.70 +
    1.71 +			if(data->selected) {
    1.72 +				float bmin[3], bmax[3];
    1.73 +				goat3d_get_mesh_bounds(mesh, bmin, bmax);
    1.74 +
    1.75 +				glPushAttrib(GL_ENABLE_BIT);
    1.76 +				glDisable(GL_LIGHTING);
    1.77 +
    1.78 +				glColor3f(0.3, 1, 0.2);
    1.79 +
    1.80 +				glBegin(GL_LINE_LOOP);
    1.81 +				glVertex3f(bmin[0], bmin[1], bmin[2]);
    1.82 +				glVertex3f(bmax[0], bmin[1], bmin[2]);
    1.83 +				glVertex3f(bmax[0], bmin[1], bmax[2]);
    1.84 +				glVertex3f(bmin[0], bmin[1], bmax[2]);
    1.85 +				glEnd();
    1.86 +
    1.87 +				glBegin(GL_LINE_LOOP);
    1.88 +				glVertex3f(bmin[0], bmax[1], bmin[2]);
    1.89 +				glVertex3f(bmax[0], bmax[1], bmin[2]);
    1.90 +				glVertex3f(bmax[0], bmax[1], bmax[2]);
    1.91 +				glVertex3f(bmin[0], bmax[1], bmax[2]);
    1.92 +				glEnd();
    1.93 +
    1.94 +				glBegin(GL_LINES);
    1.95 +				glVertex3f(bmin[0], bmin[1], bmin[2]);
    1.96 +				glVertex3f(bmin[0], bmax[1], bmin[2]);
    1.97 +				glVertex3f(bmin[0], bmin[1], bmax[2]);
    1.98 +				glVertex3f(bmin[0], bmax[1], bmax[2]);
    1.99 +				glVertex3f(bmax[0], bmin[1], bmin[2]);
   1.100 +				glVertex3f(bmax[0], bmax[1], bmin[2]);
   1.101 +				glVertex3f(bmax[0], bmin[1], bmax[2]);
   1.102 +				glVertex3f(bmax[0], bmax[1], bmax[2]);
   1.103 +				glEnd();
   1.104 +
   1.105 +				glPopAttrib();
   1.106 +			}
   1.107  		}
   1.108  	}
   1.109