demotool/ui-app.hh

102 lines
2.6 KiB
C++
Raw Normal View History

#pragma once
#include "ui-dialogs.hh"
#include "ui-mousectrl.hh"
#include "ui-actions.hh"
2017-11-24 11:34:17 +01:00
#include <ebcl/Sets.hh>
/*= WINDOW MANAGEMENT ========================================================*/
struct T_UIApp
{
T_UIApp( );
~T_UIApp( );
//----------------------------------------------------------------------
2017-11-22 14:13:02 +01:00
void pushDialog( P_ModalDialog dialog ) noexcept
{ modals_.add( std::move( dialog ) ); }
void msgbox( char const* title ,
char const* text ,
T_MessageBox::F_Handler handler = { } ,
T_MessageBox::T_Buttons buttons = T_MessageBox::BT_OK )
{ pushDialog( NewOwned< T_MessageBox >( title , text , handler , buttons ) ); }
void msgbox( T_String const& title ,
T_String const& text ,
T_MessageBox::F_Handler handler = { } ,
T_MessageBox::T_Buttons buttons = T_MessageBox::BT_OK )
{ pushDialog( NewOwned< T_MessageBox >( title , text , handler , buttons ) ); }
//----------------------------------------------------------------------
2017-11-22 14:13:02 +01:00
void addAction( T_UIAction action ) noexcept;
void actionMenu( T_String const& id ) const noexcept;
void actionButton( T_String const& id ) const noexcept;
//----------------------------------------------------------------------
ImFont* defaultFont( ) const noexcept
{ return defaultFont_; }
ImFont* smallFont( ) const noexcept
{ return smallFont_; }
//----------------------------------------------------------------------
void handleEvents( ) noexcept;
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;
private:
// Window and GL context
SDL_Window* window_;
SDL_GLContext gl_;
// Fonts
ImFont* defaultFont_;
ImFont* smallFont_;
// Do we need to quit?
bool exiting_{ false };
2017-11-24 11:34:17 +01:00
// Keyboard events / state
T_KbdMods kbMods_;
2017-11-24 11:34:17 +01:00
T_AutoArray< char , 32 > kbKeys_;
// 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_;
// Actions and keyboard shortcuts
T_ObjectTable< T_String , T_UIAction > actions_{
[]( T_UIAction const& a ) -> T_String {
return a.id;
} };
2017-11-24 11:34:17 +01:00
T_KeyValueTable< T_KeyboardShortcut , ebcl::T_Set< T_String > > shortcuts_;
2017-11-24 11:34:17 +01:00
// Event handling
void handleMouseCapture( ) noexcept;
2017-11-24 11:34:17 +01:00
void handleKeyboardShortcuts( ) noexcept;
// Modals
void handleDialogs( ) noexcept;
};