demotool/window.hh

76 lines
1.7 KiB
C++
Raw Normal View History

#pragma once
#ifndef REAL_BUILD
# include "externals.hh"
#endif
2017-11-22 14:13:02 +01:00
// 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( );
2017-11-03 09:08:19 +01:00
void startFrame( const bool capture ,
ImVec2 const& mouseInitial ) const;
void warpMouse( ImVec2 const& pos ) const;
void swap( ) const;
2017-11-22 14:13:02 +01:00
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_;
2017-11-22 14:13:02 +01:00
T_AutoArray< P_ModalDialog , 8 > modals_;
};