goat3d
view goatview/src/goatview.cc @ 74:ab66cdabf6f2
loading scene files (no vis yet)
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 06 May 2014 13:26:52 +0300 |
parents | 9862541fdcf5 |
children | 76dea247f75c |
line source
1 #include "goatview.h"
2 #include "goat3d.h"
4 goat3d *scene;
6 GoatView::GoatView()
7 {
8 make_menu();
9 make_dock();
10 make_center();
12 statusBar();
14 setWindowTitle("GoatView");
15 }
17 GoatView::~GoatView()
18 {
19 }
21 bool GoatView::make_menu()
22 {
23 QMenu *menu_file = menuBar()->addMenu("&File");
25 QAction *act_open_sce = new QAction("&Open Scene", this);
26 act_open_sce->setShortcuts(QKeySequence::Open);
27 connect(act_open_sce, &QAction::triggered, this, &GoatView::open_scene);
28 menu_file->addAction(act_open_sce);
30 QAction *act_open_anm = new QAction("Open &Animation", this);
31 connect(act_open_anm, &QAction::triggered, this, &GoatView::open_anim);
32 menu_file->addAction(act_open_anm);
34 QAction *act_quit = new QAction("&Quit", this);
35 act_quit->setShortcuts(QKeySequence::Quit);
36 connect(act_quit, &QAction::triggered, [&](){qApp->quit();});
37 menu_file->addAction(act_quit);
38 return true;
39 }
41 bool GoatView::make_dock()
42 {
43 // ---- side-dock ----
44 QWidget *dock_cont = new QWidget;
45 QVBoxLayout *dock_vbox = new QVBoxLayout;
46 dock_cont->setLayout(dock_vbox);
48 QPushButton *bn_quit = new QPushButton("quit");
49 dock_vbox->addWidget(bn_quit);
50 connect(bn_quit, &QPushButton::clicked, [&](){qApp->quit();});
52 QDockWidget *dock = new QDockWidget("Scene graph", this);
53 dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
54 dock->setWidget(dock_cont);
55 addDockWidget(Qt::LeftDockWidgetArea, dock);
57 // ---- bottom dock ----
58 dock_cont = new QWidget;
59 QHBoxLayout *dock_hbox = new QHBoxLayout;
60 dock_cont->setLayout(dock_hbox);
62 QSlider *slider_time = new QSlider(Qt::Orientation::Horizontal);
63 slider_time->setDisabled(true);
64 dock_hbox->addWidget(slider_time);
66 dock = new QDockWidget("Animation", this);
67 dock->setAllowedAreas(Qt::BottomDockWidgetArea);
68 dock->setWidget(dock_cont);
69 addDockWidget(Qt::BottomDockWidgetArea, dock);
71 return true;
72 }
74 bool GoatView::make_center()
75 {
76 GoatViewport *vport = new GoatViewport;
77 setCentralWidget(vport);
78 return true;
79 }
81 void GoatView::open_scene()
82 {
83 std::string fname = QFileDialog::getOpenFileName(this, "Open scene file", "",
84 "Goat3D Scene (*.goatsce);;All Files (*)").toStdString();
85 if(fname.empty()) {
86 statusBar()->showMessage("Abort: No file selected!");
87 return;
88 }
90 if(scene) {
91 goat3d_free(scene);
92 }
94 statusBar()->showMessage("opening scene file");
95 if(!(scene = goat3d_create()) || goat3d_load(scene, fname.c_str()) == -1) {
96 statusBar()->showMessage("failed to load scene file");
97 }
98 }
100 void GoatView::open_anim()
101 {
102 statusBar()->showMessage("opening animation...");
103 }
106 // ---- OpenGL viewport ----
107 GoatViewport::GoatViewport()
108 : QGLWidget(QGLFormat(QGL::DepthBuffer))
109 {
110 }
112 GoatViewport::~GoatViewport()
113 {
114 }
116 QSize GoatViewport::sizeHint() const
117 {
118 return QSize(800, 600);
119 }
121 void GoatViewport::initializeGL()
122 {
123 }
125 void GoatViewport::resizeGL(int xsz, int ysz)
126 {
127 glViewport(0, 0, xsz, ysz);
128 }
130 void GoatViewport::paintGL()
131 {
132 glClearColor(1, 0, 0, 1);
133 glClear(GL_COLOR_BUFFER_BIT);
134 }