Skip to content

Commit

Permalink
Monostate pattern wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Jul 12, 2024
1 parent c2a31f6 commit c224330
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 41 deletions.
44 changes: 21 additions & 23 deletions lib/app/include/app/vtx_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@
#include <util/callback.hpp>
#include <util/chrono.hpp>
#include <util/exceptions.hpp>
#include <util/generic/base_static_singleton.hpp>
// #include <util/generic/base_static_singleton.hpp>
#include <vector>

namespace VTX::App
{
class VTXApp
{
friend class Util::Generic::UniqueInstance<VTXApp>;
// friend class Util::Generic::UniqueInstance<VTXApp>;

private:
inline static const Util::Hashing::Hash SCENE_KEY = Util::Hashing::hash( "SCENE" );

public:
VTXApp();
VTXApp( std::initializer_list<int> ) = delete;
VTXApp( const VTXApp & ) = delete;
VTXApp & operator=( const VTXApp & ) = delete;
virtual ~VTXApp();

virtual void start( const Args & );
Expand All @@ -52,32 +49,33 @@ namespace VTX::App
inline Mode::BaseMode & getCurrentMode() { return *_currentMode; }
inline const Mode::BaseMode & getCurrentMode() const { return *_currentMode; }

Util::Callback<> onStart;
Util::Callback<> onStartUI;
inline static Util::Callback<> onStart;
inline static Util::Callback<> onStartUI;

Util::Callback<float> onPreUpdate;
Util::Callback<float> onUpdate;
Util::Callback<float> onLateUpdate;
Util::Callback<float> onPostUpdate;
inline static Util::Callback<float> onPreUpdate;
inline static Util::Callback<float> onUpdate;
inline static Util::Callback<float> onLateUpdate;
inline static Util::Callback<float> onPostUpdate;

Util::Callback<float> onPreRender;
Util::Callback<float> onRender;
Util::Callback<float> onPostRender;
inline static Util::Callback<float> onPreRender;
inline static Util::Callback<float> onRender;
inline static Util::Callback<float> onPostRender;

Util::Callback<> onEndOfFrameOneShot;
inline static Util::Callback<> onEndOfFrameOneShot;

Util::Callback<> onStop;
inline static Util::Callback<> onStop;

protected:
private:
Util::Chrono _tickChrono = Util::Chrono();
std::shared_ptr<Core::System::SystemHandler> _systemHandlerPtr
inline static Util::Chrono _tickChrono;

inline static std::shared_ptr<Core::System::SystemHandler> _systemHandlerPtr
= std::make_shared<Core::System::SystemHandler>();

std::unique_ptr<Mode::BaseMode> _currentMode;
std::string _currentModeKey = "MODE_VISUALIZATION";
inline static std::unique_ptr<Mode::BaseMode> _currentMode;
inline static std::string _currentModeKey = "MODE_VISUALIZATION";

Core::Monitoring::Stats _stats;
inline static Core::Monitoring::Stats _stats;

void _handleArgs( const std::vector<std::string> & );
void _update( const float p_elapsedTime );
Expand All @@ -91,8 +89,8 @@ namespace VTX::App

namespace VTX
{
inline App::VTXApp & APP() { return Util::Generic::UniqueInstance<App::VTXApp>::get(); }
// using APP = App::VTXApp;
// inline App::VTXApp & APP() { return Util::Generic::UniqueInstance<App::VTXApp>::get(); }
using APP = App::VTXApp;
} // namespace VTX

#endif
11 changes: 2 additions & 9 deletions lib/ui/qt/include/qt/base_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,11 @@ namespace VTX::UI::QT

void center( const QWidget * const p_w = nullptr )
{
// Center.
// Get the screen geometry
QScreen * screen = QGuiApplication::primaryScreen();
QRect geometry = screen->geometry();
// Get geometry of the widget, or screen if not specified.
QRect geometry = p_w ? p_w->geometry() : QGuiApplication::primaryScreen()->geometry();

if ( p_w ) {}

// Get the main window geometry
int x = ( geometry.width() - this->width() ) / 2;
int y = ( geometry.height() - this->height() ) / 2;

// Move the main window to the center of the screen
this->move( x, y );
}
};
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/qt/src/qt/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <QIcon>
#include <QSettings>
#include <QSplashScreen>
// #include <app/action/application.hpp>
// #include <app/application/system/action_manager.hpp>
#include <app/filesystem.hpp>
#include <app/infos.hpp>
#include <util/enum.hpp>
Expand Down Expand Up @@ -71,13 +69,15 @@ namespace VTX::UI::QT
{
try
{
// Restore settings after main window is built.
_restoreSettings();
}
catch ( const std::exception & e )
{
VTX_ERROR( "Failed to restore settings: {}", e.what() );
}

// Run.
_qSplashScreen->finish( _mainWindow.get() );
_mainWindow->show();
_qApplication->exec();
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/qt/src/qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ namespace VTX::UI::QT
_defaultGeometry = saveGeometry();
_defaultState = saveState();

// Demo.
// Tool test.
/*
UI::Action action3 { "Action 3" };
addMenuAction( "Tool 1", { "Action 1" } );
addMenuAction( "Tool 1", { "Action 2" } );
Expand All @@ -80,6 +81,7 @@ namespace VTX::UI::QT
addToolBarAction( "Tool 1", { "Action 1" } );
addToolBarAction( "Tool 1", { "Action 2" } );
addToolBarAction( "Tool 1", action3 );
*/
}

void MainWindow::addMenuAction( const WidgetId & p_menu, const UI::Action & p_action )
Expand Down
12 changes: 6 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ int main( int p_argc, char * p_argv[] )

LOGGER().init( logDir, debug );

// std::unique_ptr<App::VTXApp> app;
App::VTXApp * app;
std::unique_ptr<App::VTXApp> app;
// App::VTXApp * app;
#ifdef VTX_UI_QT
if ( not args.has( "-no-gui" ) )
{
// app = std::make_unique<VTX::UI::QT::Application>();
app = &APP_QT();
app = std::make_unique<VTX::UI::QT::Application>();
// app = &APP_QT();
}
else
{
app = &APP();
// app = std::unique_ptr<App::VTXApp>( &APP() );
// app = &APP();
app = std::make_unique<App::VTXApp>();
}
#else
app = std::unique_ptr<App::VTXApp>( &APP() );
Expand Down

0 comments on commit c224330

Please sign in to comment.