Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
MainWindow.cpp
1/*
2Copyright (C) 2016-2022,2024,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#include <QFileDialog>
17#include <QMdiSubWindow>
18#include <QSurfaceFormat>
19#include <QScrollArea>
20#include <QColorSpace>
21#include <iostream>
22#include "aeongames/Renderer.hpp"
24#include "WorldEditor.h"
25#include "MainWindow.h"
26#include "SceneWindow.h"
27#include "CameraSettings.h"
28#include "NodeView.h"
29
30namespace AeonGames
31{
32 MainWindow::MainWindow ( QWidget* parent, Qt::WindowFlags flags ) : QMainWindow{parent, flags}
33 {
34 mUi.setupUi ( this );
35
36 QSurfaceFormat surface_format = QSurfaceFormat::defaultFormat();
37
38 surface_format.setColorSpace ( QColorSpace::SRgb );
39 surface_format.setRenderableType ( QSurfaceFormat::OpenGL );
40 surface_format.setSwapBehavior ( QSurfaceFormat::DoubleBuffer );
41 surface_format.setRedBufferSize ( 8 );
42 surface_format.setGreenBufferSize ( 8 );
43 surface_format.setBlueBufferSize ( 8 );
44 surface_format.setAlphaBufferSize ( 8 );
45 surface_format.setStencilBufferSize ( 8 );
46 surface_format.setDepthBufferSize ( 24 );
47 //surface_format.setSamples ( ? ); ///@< Find out what is a sensible value for multisampling
48 QSurfaceFormat::setDefaultFormat ( surface_format );
49 }
50
51 MainWindow::~MainWindow() = default;
52
53 void MainWindow::on_actionExit_triggered()
54 {
55 mUi.mdiArea->closeAllSubWindows();
56 close();
57 }
58
59 void MainWindow::on_actionNewScene_triggered()
60 {
61 SceneWindow* sceneWindow;
62 QMdiSubWindow*
63 mdiSubWindow = mUi.mdiArea->addSubWindow ( sceneWindow = new SceneWindow ( mUi.mdiArea ) );
64 mdiSubWindow->setAttribute ( Qt::WA_DeleteOnClose );
65 mdiSubWindow->setWindowTitle ( tr ( "Untitled Scene" ) );
66 mdiSubWindow->showMaximized();
67 mdiSubWindow->setMinimumSize ( QSize ( 128, 128 ) );
68 mUi.actionSave->setEnabled ( true );
69 }
70
71 void MainWindow::on_actionOpen_triggered()
72 {
73 QString filename = QFileDialog::getOpenFileName ( this,
74 tr ( "Open Scene" ),
75 tr ( "" ),
76 tr ( "Scene Files (*.scn *.txt)" ) );
77
78 if ( ! ( filename.isEmpty() || filename.isNull() ) )
79 {
80 QFileInfo fileinfo ( filename );
81 SceneWindow* sceneWindow;
82 QMdiSubWindow*
83 mdiSubWindow = mUi.mdiArea->addSubWindow ( sceneWindow = new SceneWindow ( mUi.mdiArea ) );
84 mdiSubWindow->setAttribute ( Qt::WA_DeleteOnClose );
85 mdiSubWindow->setWindowTitle ( fileinfo.absoluteFilePath() );
86 mdiSubWindow->showMaximized();
87 mdiSubWindow->setMinimumSize ( QSize ( 128, 128 ) );
88 sceneWindow->Open ( fileinfo.absoluteFilePath().toStdString() );
90 mUi.actionSave->setEnabled ( true );
91 }
92 }
93
94 void MainWindow::on_actionSave_triggered()
95 {
96 QMdiSubWindow*
97 mdiSubWindow = mUi.mdiArea->currentSubWindow ();
98 if ( !mdiSubWindow )
99 {
100 return;
101 }
102 QString filename = QFileDialog::getSaveFileName ( this,
103 tr ( "Save Scene" ),
104 tr ( "" ),
105 tr ( "Scene Files (*.scn *.txt)" ) );
106 if ( ! ( filename.isEmpty() || filename.isNull() ) )
107 {
108 SceneWindow* sceneWindow = reinterpret_cast<SceneWindow*> ( mdiSubWindow->widget() );
109 if ( sceneWindow )
110 {
111 sceneWindow->Save ( filename.toStdString() );
112 }
113 }
114 }
115
116 void MainWindow::on_actionCamera_triggered()
117 {
118 if ( mCameraSettings == nullptr )
119 {
120 mCameraSettings = new CameraSettings{this};
121 connect ( mCameraSettings, SIGNAL ( fieldOfViewChanged ( double ) ), this, SLOT ( fieldOfViewChanged ( double ) ) );
122 connect ( mCameraSettings, SIGNAL ( nearChanged ( double ) ), this, SLOT ( nearChanged ( double ) ) );
123 connect ( mCameraSettings, SIGNAL ( farChanged ( double ) ), this, SLOT ( farChanged ( double ) ) );
124 }
125 mCameraSettings->exec();
126 }
127
128 void MainWindow::on_actionNewShader_triggered()
129 {
130 QScrollArea* scrollArea{new QScrollArea{mUi.mdiArea}};
131 NodeView* nodeView{new NodeView{scrollArea}};
132 scrollArea->setWidget ( nodeView );
133 scrollArea->setWidgetResizable ( true );
134 QMdiSubWindow* mdiSubWindow{ mUi.mdiArea->addSubWindow ( scrollArea ) };
135 mdiSubWindow->setAttribute ( Qt::WA_DeleteOnClose );
136 mdiSubWindow->setWindowTitle ( tr ( "Untitled Shader" ) );
137 mdiSubWindow->showMaximized();
138 mdiSubWindow->setMinimumSize ( QSize ( 128, 128 ) );
139 mUi.actionSave->setEnabled ( true );
140 }
141
142 void MainWindow::fieldOfViewChanged ( double aFieldOfView )
143 {
144 QMdiSubWindow*
145 mdiSubWindow = mUi.mdiArea->currentSubWindow ();
146 if ( !mdiSubWindow )
147 {
148 return;
149 }
150 reinterpret_cast<SceneWindow * > ( mdiSubWindow->widget() )->SetFieldOfView ( static_cast<float> ( aFieldOfView ) );
151 }
152
153 void MainWindow::nearChanged ( double aNear )
154 {
155 QMdiSubWindow*
156 mdiSubWindow = mUi.mdiArea->currentSubWindow ();
157 if ( !mdiSubWindow )
158 {
159 return;
160 }
161 reinterpret_cast<SceneWindow * > ( mdiSubWindow->widget() )->SetNear ( static_cast<float> ( aNear ) );
162 }
163
164 void MainWindow::farChanged ( double aFar )
165 {
166 QMdiSubWindow*
167 mdiSubWindow = mUi.mdiArea->currentSubWindow ();
168 if ( !mdiSubWindow )
169 {
170 return;
171 }
172 reinterpret_cast<SceneWindow * > ( mdiSubWindow->widget() )->SetFar ( static_cast<float> ( aFar ) );
173 }
174}
Defines log severity levels and stream output for the AeonGames engine.
~MainWindow()
Destructor.
MainWindow(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags{})
Construct the main window.
<- This is here just for the literals
Definition AABB.hpp:31