2017-10-04 11:20:27 +02:00
|
|
|
#pragma once
|
2017-11-23 14:15:17 +01:00
|
|
|
#include "ui-dialogs.hh"
|
2017-11-23 14:21:54 +01:00
|
|
|
#include "ui-mousectrl.hh"
|
2017-11-23 13:54:27 +01:00
|
|
|
#include "ui-actions.hh"
|
2017-10-04 11:20:27 +02:00
|
|
|
|
|
|
|
|
2017-11-23 12:46:48 +01:00
|
|
|
/*= WINDOW MANAGEMENT ========================================================*/
|
2017-11-23 12:24:40 +01:00
|
|
|
|
2017-11-23 22:51:50 +01:00
|
|
|
struct T_UIApp
|
2017-10-04 11:20:27 +02:00
|
|
|
{
|
2017-11-23 22:51:50 +01:00
|
|
|
T_UIApp( );
|
|
|
|
~T_UIApp( );
|
2017-10-04 11:20:27 +02:00
|
|
|
|
2017-11-23 12:46:48 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-10-04 11:20:27 +02:00
|
|
|
|
2017-11-22 14:13:02 +01:00
|
|
|
void pushDialog( P_ModalDialog dialog ) noexcept
|
|
|
|
{ modals_.add( std::move( dialog ) ); }
|
2017-11-23 12:24:40 +01:00
|
|
|
|
|
|
|
void msgbox( char const* title ,
|
|
|
|
char const* text ,
|
|
|
|
T_MessageBox::F_Handler handler = { } ,
|
|
|
|
T_MessageBox::T_Buttons buttons = T_MessageBox::BT_OK )
|
2017-11-23 12:46:48 +01:00
|
|
|
{ pushDialog( NewOwned< T_MessageBox >( title , text , handler , buttons ) ); }
|
2017-11-23 12:24:40 +01:00
|
|
|
void msgbox( T_String const& title ,
|
|
|
|
T_String const& text ,
|
|
|
|
T_MessageBox::F_Handler handler = { } ,
|
|
|
|
T_MessageBox::T_Buttons buttons = T_MessageBox::BT_OK )
|
2017-11-23 12:46:48 +01:00
|
|
|
{ pushDialog( NewOwned< T_MessageBox >( title , text , handler , buttons ) ); }
|
2017-11-23 12:24:40 +01:00
|
|
|
|
2017-11-23 12:46:48 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-11-22 14:13:02 +01:00
|
|
|
|
2017-11-23 13:54:27 +01:00
|
|
|
void addAction( T_UIAction action ) noexcept;
|
|
|
|
void actionMenu( T_String const& id ) const noexcept;
|
|
|
|
void actionButton( T_String const& id ) const noexcept;
|
|
|
|
|
2017-11-23 22:44:20 +01:00
|
|
|
template< typename... Args >
|
|
|
|
T_UIAction& newAction( Args&&... args )
|
|
|
|
{
|
|
|
|
T_UIAction a{ std::forward< Args >( args ) ... };
|
|
|
|
T_String id{ a.id };
|
|
|
|
addAction( std::move( a ) );
|
|
|
|
return *actions_.get( id );
|
|
|
|
}
|
|
|
|
|
2017-11-23 13:54:27 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2017-11-20 21:54:46 +01:00
|
|
|
ImFont* defaultFont( ) const noexcept
|
|
|
|
{ return defaultFont_; }
|
|
|
|
ImFont* smallFont( ) const noexcept
|
|
|
|
{ return smallFont_; }
|
|
|
|
|
2017-11-23 12:46:48 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2017-11-24 09:51:05 +01:00
|
|
|
void handleEvents( ) noexcept;
|
2017-11-23 12:46:48 +01:00
|
|
|
|
2017-11-24 09:51:05 +01:00
|
|
|
void setMouseDelegate( A_MouseCtrl* const delegate ) noexcept
|
|
|
|
{ mDelegate_ = delegate; }
|
|
|
|
void clearMouseDelegate( ) noexcept
|
|
|
|
{ mDelegate_ = nullptr; }
|
|
|
|
|
|
|
|
bool exiting( ) const noexcept
|
|
|
|
{ return exiting_; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void render( ) noexcept;
|
|
|
|
void swap( ) const noexcept;
|
2017-11-23 12:46:48 +01:00
|
|
|
|
2017-10-04 11:20:27 +02:00
|
|
|
private:
|
2017-11-24 09:51:05 +01:00
|
|
|
// Window and GL context
|
|
|
|
SDL_Window* window_;
|
|
|
|
SDL_GLContext gl_;
|
|
|
|
|
|
|
|
// Fonts
|
2017-11-20 21:54:46 +01:00
|
|
|
ImFont* defaultFont_;
|
|
|
|
ImFont* smallFont_;
|
2017-11-24 09:51:05 +01:00
|
|
|
|
|
|
|
// Do we need to quit?
|
|
|
|
bool exiting_{ false };
|
|
|
|
|
|
|
|
// Mouse capture
|
|
|
|
bool mCapture_{ false };
|
|
|
|
ImVec2 mInitial_{ 0 , 0 };
|
|
|
|
ImVec2 mMove_{ 0 , 0 };
|
|
|
|
A_MouseCtrl* mDelegate_;
|
|
|
|
|
|
|
|
// Stack of modal dialogs
|
2017-11-22 14:13:02 +01:00
|
|
|
T_AutoArray< P_ModalDialog , 8 > modals_;
|
2017-11-24 09:51:05 +01:00
|
|
|
|
|
|
|
// Actions and keyboard shortcuts
|
2017-11-23 13:54:27 +01:00
|
|
|
T_ObjectTable< T_String , T_UIAction > actions_{
|
|
|
|
[]( T_UIAction const& a ) -> T_String {
|
|
|
|
return a.id;
|
|
|
|
} };
|
2017-11-24 09:51:05 +01:00
|
|
|
|
|
|
|
void handleMouseCapture( ) noexcept;
|
|
|
|
void handleDialogs( ) noexcept;
|
2017-10-04 11:20:27 +02:00
|
|
|
};
|
|
|
|
|