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