#pragma once #ifndef REAL_BUILD # include "externals.hh" #endif // Base class for a modal dialog that can be pushed to the window's modal // stack. class A_ModalDialog { private: const T_String id_; bool open_{ false }; T_Optional< ImVec2 > initialSize_; protected: A_ModalDialog( char const* id ) noexcept; void setInitialSize( const float width , const float height ) noexcept { initialSize_.setNew( width , height ); } // Initialisation, called right before the window is opened. // Does nothing by default. virtual void initDialog( ) noexcept; // Draw the dialog box's contents, returns true if the OK button // should be enabled. virtual bool drawDialog( ) noexcept = 0; // Handlers for both OK and Cancel. The former must be overridden, // the latter defaults to "do nothing". virtual void onOK( ) noexcept = 0; virtual void onCancel( ) noexcept; public: NO_COPY( A_ModalDialog ); NO_MOVE( A_ModalDialog ); virtual ~A_ModalDialog( ); // Draw and handle the dialog box. Returns true if it must be kept, // or false if it must be removed from the stack. bool draw( ) noexcept; }; using P_ModalDialog = T_OwnPtr< A_ModalDialog >; struct T_Window { T_Window( ); ~T_Window( ); void startFrame( const bool capture , ImVec2 const& mouseInitial ) const; void warpMouse( ImVec2 const& pos ) const; void swap( ) const; void pushDialog( P_ModalDialog dialog ) noexcept { modals_.add( std::move( dialog ) ); } void handleDialogs( ) noexcept; ImFont* defaultFont( ) const noexcept { return defaultFont_; } ImFont* smallFont( ) const noexcept { return smallFont_; } private: SDL_Window * window; SDL_GLContext gl; ImFont* defaultFont_; ImFont* smallFont_; T_AutoArray< P_ModalDialog , 8 > modals_; };