goat3d

view goatview/src/goatview.cc @ 98:b43d33f3ba69

[goatview] better LLVM/gcc detection [goatview] close_scene might have solved the occasional crashes on opening a second scene
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 21 May 2014 04:08:11 +0300
parents da100bf13f7f
children d7ab4f13f5af
line source
1 #include <stdio.h>
2 #include <limits.h>
3 #include <map>
4 #include "opengl.h"
5 #include <QtOpenGL/QtOpenGL>
6 #include <vmath/vmath.h>
7 #include "goatview.h"
8 #include "goat3d.h"
10 static void draw_grid();
11 static void draw_grid(float sz, int nlines, float alpha = 1.0f);
12 static void draw_node(goat3d_node *node);
13 static void draw_mesh(goat3d_mesh *mesh);
14 static int next_pow2(int x);
16 goat3d *scene;
17 static SceneModel *sdata;
18 static GoatViewport *glview;
20 static long anim_time;
21 static float cam_theta, cam_phi = 25, cam_dist = 8;
22 static float fov = 60.0;
23 static bool use_nodes = true;
24 static bool use_lighting = true;
25 static bool use_textures = true;
27 void post_redisplay()
28 {
29 if(glview) {
30 glview->updateGL();
31 }
32 }
35 GoatView::GoatView()
36 {
37 glview = 0;
38 scene_model = 0;
40 QGLFormat glfmt = QGLFormat::defaultFormat();
41 glfmt.setSampleBuffers(true);
42 QGLFormat::setDefaultFormat(glfmt);
44 QSettings settings;
45 resize(settings.value("main/size", QSize(1024, 768)).toSize());
46 move(settings.value("main/pos", QPoint(100, 100)).toPoint());
47 use_nodes = settings.value("use_nodes", true).toBool();
48 use_lighting = settings.value("use_lighting", true).toBool();
49 use_textures = settings.value("use_textures", true).toBool();
51 make_center(); // must be first
52 make_menu();
53 make_dock();
55 statusBar();
57 setWindowTitle("GoatView");
58 }
60 GoatView::~GoatView()
61 {
62 delete scene_model;
63 sdata = 0;
64 }
66 void GoatView::closeEvent(QCloseEvent *ev)
67 {
68 QSettings settings;
69 settings.setValue("main/size", size());
70 settings.setValue("main/pos", pos());
71 settings.setValue("use_nodes", use_nodes);
72 settings.setValue("use_lighting", use_lighting);
73 }
76 bool GoatView::load_scene(const char *fname)
77 {
78 if(scene) {
79 close_scene();
80 }
81 if(!(scene = goat3d_create()) || goat3d_load(scene, fname) == -1) {
82 QMessageBox::critical(this, "Error", "Failed to load scene file: " + QString(fname));
83 return false;
84 }
86 float bmin[3], bmax[3];
87 if(goat3d_get_bounds(scene, bmin, bmax) != -1) {
88 float bsize = (Vector3(bmax[0], bmax[1], bmax[2]) - Vector3(bmin[0], bmin[1], bmin[2])).length();
89 cam_dist = bsize / tan(DEG_TO_RAD(fov) / 2.0);
90 printf("bounds size: %f, cam_dist: %f\n", bsize, cam_dist);
91 }
93 scene_model->set_scene(scene);
94 treeview->expandAll();
95 treeview->resizeColumnToContents(0);
97 sdata = scene_model; // set the global sdata ptr
98 post_redisplay();
99 return true;
100 }
102 bool GoatView::load_anim(const char *fname)
103 {
104 if(!scene) {
105 QMessageBox::critical(this, "Error", "You must load a scene before loading any animations!");
106 return false;
107 }
109 if(goat3d_load_anim(scene, fname) == -1) {
110 QMessageBox::critical(this, "Error", QString("Failed to load animation: ") + QString(fname));
111 return false;
112 }
115 long tstart = LONG_MAX, tend = LONG_MIN;
116 int num_nodes = goat3d_get_node_count(scene);
117 for(int i=0; i<num_nodes; i++) {
118 goat3d_node *node = goat3d_get_node(scene, i);
119 if(goat3d_get_node_parent(node)) {
120 continue;
121 }
123 long t0, t1;
124 if(goat3d_get_anim_timeline(node, &t0, &t1) != -1) {
125 if(t0 < tstart) tstart = t0;
126 if(t1 > tend) tend = t1;
127 }
128 }
130 if(tstart != LONG_MAX) {
131 act_play->setDisabled(false);
132 act_rewind->setDisabled(false);
133 chk_loop->setDisabled(false);
135 slider_time->setDisabled(false);
136 slider_time->setMinimum(tstart);
137 slider_time->setMaximum(tend);
139 spin_time->setDisabled(false);
140 spin_time->setMinimum(tstart);
141 spin_time->setMaximum(tend);
142 }
144 post_redisplay();
145 return true;
146 }
148 bool GoatView::make_menu()
149 {
150 // file menu
151 QMenu *menu_file = menuBar()->addMenu("&File");
153 QAction *act_open_sce = new QAction("&Open Scene", this);
154 act_open_sce->setShortcuts(QKeySequence::Open);
155 connect(act_open_sce, &QAction::triggered, this, &GoatView::open_scene);
156 menu_file->addAction(act_open_sce);
158 QAction *act_open_anm = new QAction("Open &Animation", this);
159 connect(act_open_anm, &QAction::triggered, this, &GoatView::open_anim);
160 menu_file->addAction(act_open_anm);
162 QAction *act_close = new QAction("&Close", this);
163 connect(act_close, &QAction::triggered, this, &GoatView::close_scene);
164 menu_file->addAction(act_close);
166 menu_file->addSeparator();
168 QAction *act_quit = new QAction("&Quit", this);
169 act_quit->setShortcuts(QKeySequence::Quit);
170 connect(act_quit, &QAction::triggered, [&](){ qApp->quit(); });
171 menu_file->addAction(act_quit);
173 // view menu
174 QMenu *menu_view = menuBar()->addMenu("&View");
176 QAction *act_use_nodes = new QAction("use nodes", this);
177 act_use_nodes->setCheckable(true);
178 act_use_nodes->setChecked(use_nodes);
179 connect(act_use_nodes, &QAction::triggered, this,
180 [&](){ use_nodes = !use_nodes; post_redisplay(); });
181 menu_view->addAction(act_use_nodes);
183 QAction *act_use_lighting = new QAction("lighting", this);
184 act_use_lighting->setCheckable(true);
185 act_use_lighting->setChecked(use_lighting);
186 connect(act_use_lighting, &QAction::triggered, glview, &GoatViewport::toggle_lighting);
187 menu_view->addAction(act_use_lighting);
189 // help menu
190 QMenu *menu_help = menuBar()->addMenu("&Help");
192 QAction *act_about = new QAction("&About", this);
193 connect(act_about, &QAction::triggered, this, &GoatView::show_about);
194 menu_help->addAction(act_about);
195 return true;
196 }
198 bool GoatView::make_dock()
199 {
200 // ---- side-dock ----
201 QWidget *dock_cont = new QWidget;
202 QVBoxLayout *dock_vbox = new QVBoxLayout;
203 dock_cont->setLayout(dock_vbox);
205 QDockWidget *dock = new QDockWidget(this);
206 dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
207 dock->setWidget(dock_cont);
208 addDockWidget(Qt::LeftDockWidgetArea, dock);
210 // make the tree view widget
211 treeview = new QTreeView;
212 treeview->setAlternatingRowColors(true);
213 treeview->setSelectionMode(QAbstractItemView::SingleSelection);
214 dock_vbox->addWidget(treeview);
216 scene_model = new SceneModel;
217 connect(scene_model, &SceneModel::dataChanged, [&](){ post_redisplay(); });
218 treeview->setModel(scene_model);
220 connect(treeview->selectionModel(), &QItemSelectionModel::selectionChanged,
221 [&](){ scene_model->selchange(treeview->selectionModel()->selectedIndexes()); });
223 // misc
224 QPushButton *bn_quit = new QPushButton("quit");
225 dock_vbox->addWidget(bn_quit);
226 connect(bn_quit, &QPushButton::clicked, [&](){ qApp->quit(); });
228 // ---- bottom dock ----
229 dock_cont = new QWidget;
230 QHBoxLayout *dock_hbox = new QHBoxLayout;
231 dock_cont->setLayout(dock_hbox);
233 // animation control box
234 QGroupBox *grp_anim_ctl = new QGroupBox("Animation controls");
235 // TODO figure out how these fucking stretching policies work...
236 //grp_anim_ctl->sizePolicy().setHorizontalPolicy(QSizePolicy::Maximum);
237 grp_anim_ctl->sizePolicy().setHorizontalStretch(1);
238 dock_hbox->addWidget(grp_anim_ctl);
240 QVBoxLayout *anim_ctl_box = new QVBoxLayout;
241 grp_anim_ctl->setLayout(anim_ctl_box);
243 chk_loop = new QCheckBox("loop");
244 chk_loop->setDisabled(true);
245 chk_loop->setChecked(false);
246 anim_ctl_box->addWidget(chk_loop);
248 QToolBar *toolbar_ctl = new QToolBar;
249 anim_ctl_box->addWidget(toolbar_ctl);
251 act_rewind = new QAction(style()->standardIcon(QStyle::SP_MediaSkipBackward), "Rewind", this);
252 act_rewind->setDisabled(true);
253 connect(act_rewind, &QAction::triggered, [this](){ slider_time->setValue(slider_time->minimum()); });
254 toolbar_ctl->addAction(act_rewind);
256 act_play = new QAction(style()->standardIcon(QStyle::SP_MediaPlay), "Play", this);
257 act_play->setDisabled(true);
258 toolbar_ctl->addAction(act_play);
260 // slider and spinbox
261 QWidget *ssgroup = new QWidget;
262 ssgroup->sizePolicy().setHorizontalStretch(4);
263 dock_hbox->addWidget(ssgroup);
265 QGridLayout *ssgrid = new QGridLayout;
266 //dock_hbox->addLayout(ssgrid);
267 ssgroup->setLayout(ssgrid);
269 ssgrid->addWidget(new QLabel("msec"), 0, 0);
270 spin_time = new QSpinBox;
271 spin_time->setDisabled(true);
272 ssgrid->addWidget(spin_time, 0, 1);
274 slider_time = new QSlider(Qt::Orientation::Horizontal);
275 slider_time->setDisabled(true);
276 ssgrid->addWidget(slider_time, 1, 0, 1, 3);
278 connect(slider_time, &QSlider::valueChanged,
279 [&](){ anim_time = slider_time->value(); spin_time->setValue(anim_time); post_redisplay(); });
281 typedef void (QSpinBox::*ValueChangedIntFunc)(int);
282 connect(spin_time, (ValueChangedIntFunc)&QSpinBox::valueChanged,
283 [&](){ anim_time = spin_time->value(); slider_time->setValue(anim_time); post_redisplay(); });
285 dock = new QDockWidget(this);
286 dock->setAllowedAreas(Qt::BottomDockWidgetArea);
287 dock->setWidget(dock_cont);
288 addDockWidget(Qt::BottomDockWidgetArea, dock);
290 return true;
291 }
293 bool GoatView::make_center()
294 {
295 glview = ::glview = new GoatViewport(this);
296 setCentralWidget(glview);
297 return true;
298 }
300 void GoatView::open_scene()
301 {
302 std::string fname = QFileDialog::getOpenFileName(this, "Open scene file", "",
303 "Goat3D Scene (*.goatsce);;All Files (*)").toStdString();
304 if(fname.empty()) {
305 statusBar()->showMessage("Abort: No file selected!");
306 return;
307 }
309 statusBar()->showMessage("opening scene file");
310 if(!load_scene(fname.c_str())) {
311 statusBar()->showMessage("failed to load scene file");
312 return;
313 }
314 statusBar()->showMessage("Successfully loaded scene: " + QString(fname.c_str()));
315 }
317 void GoatView::close_scene()
318 {
319 scene_model->clear_scene();
320 treeview->reset();
321 goat3d_free(scene);
322 scene = 0;
323 }
325 void GoatView::open_anim()
326 {
327 std::string fname = QFileDialog::getOpenFileName(this, "Open animation file", "",
328 "Goat3D Animation (*.goatanm);;All Files (*)").toStdString();
329 if(fname.empty()) {
330 statusBar()->showMessage("Abort: No file selected!");
331 return;
332 }
334 statusBar()->showMessage("opening animation file");
335 if(!load_anim(fname.c_str())) {
336 statusBar()->showMessage("failed to load animation file");
337 return;
338 }
339 statusBar()->showMessage("Successfully loaded animation: " + QString(fname.c_str()));
340 }
343 // ---- OpenGL viewport ----
344 GoatViewport::GoatViewport(QWidget *main_win)
345 : QGLWidget(QGLFormat(QGL::DepthBuffer | QGL::SampleBuffers))
346 {
347 this->main_win = main_win;
348 initialized = false;
349 }
351 GoatViewport::~GoatViewport()
352 {
353 }
355 QSize GoatViewport::sizeHint() const
356 {
357 return QSize(800, 600);
358 }
360 #define CRITICAL(error, detail) \
361 do { \
362 fprintf(stderr, "%s: %s\n", error, detail); \
363 QMessageBox::critical(main_win, error, detail); \
364 abort(); \
365 } while(0)
367 void GoatViewport::initializeGL()
368 {
369 if(initialized) return;
370 initialized = true;
372 init_opengl();
374 if(!GLEW_ARB_transpose_matrix) {
375 CRITICAL("OpenGL initialization failed", "ARB_transpose_matrix extension not found!");
376 }
378 glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
380 glEnable(GL_DEPTH_TEST);
381 glEnable(GL_CULL_FACE);
382 if(use_lighting) {
383 glEnable(GL_LIGHTING);
384 }
385 glEnable(GL_LIGHT0);
387 float ldir[] = {-1, 1, 2, 0};
388 glLightfv(GL_LIGHT0, GL_POSITION, ldir);
390 glEnable(GL_MULTISAMPLE);
391 }
393 void GoatViewport::resizeGL(int xsz, int ysz)
394 {
395 glViewport(0, 0, xsz, ysz);
396 glMatrixMode(GL_PROJECTION);
397 glLoadIdentity();
398 gluPerspective(60.0, (float)xsz / (float)ysz, 0.5, 5000.0);
399 }
401 void GoatViewport::paintGL()
402 {
403 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
405 glMatrixMode(GL_MODELVIEW);
406 glLoadIdentity();
407 glTranslatef(0, 0, -cam_dist);
408 glRotatef(cam_phi, 1, 0, 0);
409 glRotatef(cam_theta, 0, 1, 0);
411 draw_grid();
413 if(!scene) return;
415 if(use_nodes) {
416 int node_count = goat3d_get_node_count(scene);
417 for(int i=0; i<node_count; i++) {
418 goat3d_node *node = goat3d_get_node(scene, i);
419 if(!goat3d_get_node_parent(node)) {
420 draw_node(node); // only draw root nodes, the rest will be drawn recursively
421 }
422 }
423 } else {
424 int mesh_count = goat3d_get_mesh_count(scene);
425 for(int i=0; i<mesh_count; i++) {
426 goat3d_mesh *mesh = goat3d_get_mesh(scene, i);
427 draw_mesh(mesh);
428 }
429 }
430 }
432 void GoatViewport::toggle_lighting()
433 {
434 use_lighting = !use_lighting;
435 if(use_lighting) {
436 glEnable(GL_LIGHTING);
437 } else {
438 glDisable(GL_LIGHTING);
439 }
440 updateGL();
441 }
443 #ifndef GLEW_ARB_transpose_matrix
444 #error "GLEW_ARB_transpose_matrix undefined?"
445 #endif
447 static void draw_grid()
448 {
449 float viewsz_orig = cam_dist * tan(DEG_TO_RAD(fov) / 2.0);
450 float sz1 = next_pow2((int)viewsz_orig);
451 float sz0 = sz1 / 2.0;
452 float t = (viewsz_orig - sz0) / (sz1 - sz0);
453 float alpha = t < 0.333333 ? 0.0 : (t > 0.666666 ? 1.0 : (t - 0.333333) / 0.333333);
455 glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BITS);
457 glEnable(GL_BLEND);
458 glDepthFunc(GL_ALWAYS);
460 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
461 draw_grid(sz0 * 2.0, 10, 1.0 - alpha);
462 draw_grid(sz1 * 2.0, 10, alpha);
464 glPopAttrib();
465 }
467 static void draw_grid(float sz, int nlines, float alpha)
468 {
469 float hsz = sz / 2.0;
470 float offs = sz / (float)nlines;
472 glPushAttrib(GL_ENABLE_BIT);
473 glDisable(GL_LIGHTING);
474 glDisable(GL_TEXTURE_2D);
476 glLineWidth(2.0);
477 glBegin(GL_LINES);
478 glColor4f(1, 0, 0, alpha);
479 glVertex3f(-hsz, 0, 0);
480 glVertex3f(hsz, 0, 0);
481 glColor4f(0, 0, 1, alpha);
482 glVertex3f(0, 0, -hsz);
483 glVertex3f(0, 0, hsz);
484 glEnd();
486 glLineWidth(1.0);
487 glBegin(GL_LINES);
488 glColor4f(0.5, 0.5, 0.5, alpha);
489 for(int i=0; i<nlines / 2; i++) {
490 float dist = (float)(i + 1) * offs;
491 for(int j=0; j<2; j++) {
492 float sign = j > 0 ? -1.0 : 1.0;
493 glVertex3f(-hsz, 0, dist * sign);
494 glVertex3f(hsz, 0, dist * sign);
495 glVertex3f(dist * sign, 0, -hsz);
496 glVertex3f(dist * sign, 0, hsz);
497 }
498 }
499 glEnd();
501 glPopAttrib();
502 }
504 static void draw_node(goat3d_node *node)
505 {
506 SceneNodeData *data = sdata ? sdata->get_node_data(node) : 0;
507 if(!data) return;
509 float xform[16];
510 goat3d_get_node_matrix(node, xform, anim_time);
512 glPushMatrix();
513 glMultTransposeMatrixf(xform);
515 if(data->visible) {
516 if(goat3d_get_node_type(node) == GOAT3D_NODE_MESH) {
517 goat3d_mesh *mesh = (goat3d_mesh*)goat3d_get_node_object(node);
519 draw_mesh(mesh);
521 if(data->selected) {
522 float bmin[3], bmax[3];
523 goat3d_get_mesh_bounds(mesh, bmin, bmax);
525 glPushAttrib(GL_ENABLE_BIT);
526 glDisable(GL_LIGHTING);
528 glColor3f(0.3, 1, 0.2);
530 glBegin(GL_LINE_LOOP);
531 glVertex3f(bmin[0], bmin[1], bmin[2]);
532 glVertex3f(bmax[0], bmin[1], bmin[2]);
533 glVertex3f(bmax[0], bmin[1], bmax[2]);
534 glVertex3f(bmin[0], bmin[1], bmax[2]);
535 glEnd();
536 glBegin(GL_LINE_LOOP);
537 glVertex3f(bmin[0], bmax[1], bmin[2]);
538 glVertex3f(bmax[0], bmax[1], bmin[2]);
539 glVertex3f(bmax[0], bmax[1], bmax[2]);
540 glVertex3f(bmin[0], bmax[1], bmax[2]);
541 glEnd();
542 glBegin(GL_LINES);
543 glVertex3f(bmin[0], bmin[1], bmin[2]);
544 glVertex3f(bmin[0], bmax[1], bmin[2]);
545 glVertex3f(bmin[0], bmin[1], bmax[2]);
546 glVertex3f(bmin[0], bmax[1], bmax[2]);
547 glVertex3f(bmax[0], bmin[1], bmin[2]);
548 glVertex3f(bmax[0], bmax[1], bmin[2]);
549 glVertex3f(bmax[0], bmin[1], bmax[2]);
550 glVertex3f(bmax[0], bmax[1], bmax[2]);
551 glEnd();
553 glPopAttrib();
554 }
555 }
556 }
558 int num_child = goat3d_get_node_child_count(node);
559 for(int i=0; i<num_child; i++) {
560 draw_node(goat3d_get_node_child(node, i));
561 }
563 glPopMatrix();
564 }
566 static void draw_mesh(goat3d_mesh *mesh)
567 {
568 static const float white[] = {1, 1, 1, 1};
569 static const float black[] = {0, 0, 0, 1};
571 const float *color;
572 goat3d_material *mtl = goat3d_get_mesh_mtl(mesh);
574 if(mtl && (color = goat3d_get_mtl_attrib(mtl, GOAT3D_MAT_ATTR_DIFFUSE))) {
575 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
576 glColor3fv(color);
577 } else {
578 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, white);
579 glColor3fv(white);
580 }
581 if(mtl && (color = goat3d_get_mtl_attrib(mtl, GOAT3D_MAT_ATTR_SPECULAR))) {
582 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
583 } else {
584 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
585 }
586 if(mtl && (color = goat3d_get_mtl_attrib(mtl, GOAT3D_MAT_ATTR_SHININESS))) {
587 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, color[0]);
588 } else {
589 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 60.0);
590 }
591 // TODO texture
594 int num_faces = goat3d_get_mesh_face_count(mesh);
595 int num_verts = goat3d_get_mesh_attrib_count(mesh, GOAT3D_MESH_ATTR_VERTEX);
597 glEnableClientState(GL_VERTEX_ARRAY);
598 glVertexPointer(3, GL_FLOAT, 0, goat3d_get_mesh_attribs(mesh, GOAT3D_MESH_ATTR_VERTEX));
600 float *data;
601 if((data = (float*)goat3d_get_mesh_attribs(mesh, GOAT3D_MESH_ATTR_NORMAL))) {
602 glEnableClientState(GL_NORMAL_ARRAY);
603 glNormalPointer(GL_FLOAT, 0, data);
604 }
605 if((data = (float*)goat3d_get_mesh_attribs(mesh, GOAT3D_MESH_ATTR_TEXCOORD))) {
606 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
607 glTexCoordPointer(2, GL_FLOAT, 0, data);
608 }
610 int *indices;
611 if((indices = goat3d_get_mesh_faces(mesh))) {
612 glDrawElements(GL_TRIANGLES, num_faces * 3, GL_UNSIGNED_INT, indices);
613 } else {
614 glDrawArrays(GL_TRIANGLES, 0, num_verts * 3);
615 }
617 glDisableClientState(GL_VERTEX_ARRAY);
618 glDisableClientState(GL_NORMAL_ARRAY);
619 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
620 }
623 static float prev_x, prev_y;
624 void GoatViewport::mousePressEvent(QMouseEvent *ev)
625 {
626 prev_x = ev->x();
627 prev_y = ev->y();
628 }
630 void GoatViewport::mouseMoveEvent(QMouseEvent *ev)
631 {
632 int dx = ev->x() - prev_x;
633 int dy = ev->y() - prev_y;
634 prev_x = ev->x();
635 prev_y = ev->y();
637 if(!dx && !dy) return;
639 if(ev->buttons() & Qt::LeftButton) {
640 cam_theta += dx * 0.5;
641 cam_phi += dy * 0.5;
643 if(cam_phi < -90) cam_phi = -90;
644 if(cam_phi > 90) cam_phi = 90;
645 }
646 if(ev->buttons() & Qt::RightButton) {
647 cam_dist += dy * 0.1;
649 if(cam_dist < 0.0) cam_dist = 0.0;
650 }
651 updateGL();
652 }
654 static const char *about_str =
655 "GoatView - Goat3D scene file viewer<br>"
656 "Copyright (C) 2014 John Tsiombikas &lt;<a href=\"mailto:nuclear@mutantstargoat.com\">nuclear@mutantstargoat.com</a>&gt;<br>"
657 "<br>"
658 "This program is free software: you can redistribute it and/or modify<br>"
659 "it under the terms of the GNU General Public License as published by<br>"
660 "the Free Software Foundation, either version 3 of the License, or<br>"
661 "(at your option) any later version.<br>"
662 "<br>"
663 "This program is distributed in the hope that it will be useful,<br>"
664 "but WITHOUT ANY WARRANTY; without even the implied warranty of<br>"
665 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>"
666 "GNU General Public License for more details.<br>"
667 "<br>"
668 "You should have received a copy of the GNU General Public License<br>"
669 "along with this program. If not, see <a href=\"http://www.gnu.org/licenses/gpl\">http://www.gnu.org/licenses/gpl</a>.";
671 void GoatView::show_about()
672 {
673 QMessageBox::information(this, "About GoatView", about_str);
674 }
677 static int next_pow2(int x)
678 {
679 x--;
680 x = (x >> 1) | x;
681 x = (x >> 2) | x;
682 x = (x >> 4) | x;
683 x = (x >> 8) | x;
684 x = (x >> 16) | x;
685 return x + 1;
686 }