2017-10-04 11:20:27 +02:00
|
|
|
#include "externals.hh"
|
|
|
|
#include "window.hh"
|
2017-11-23 14:47:25 +01:00
|
|
|
#include "ui-imgui-sdl.hh"
|
|
|
|
|
2017-11-20 21:54:46 +01:00
|
|
|
#include <imgui_internal.h>
|
2017-10-04 11:20:27 +02:00
|
|
|
|
2017-11-22 14:13:02 +01:00
|
|
|
|
|
|
|
/*= T_Window =================================================================*/
|
|
|
|
|
2017-11-21 17:32:52 +01:00
|
|
|
namespace {
|
|
|
|
#include "font-awesome.inl"
|
|
|
|
|
|
|
|
static const ImWchar IconsRanges_[] = {
|
|
|
|
ICON_MIN_FA ,
|
|
|
|
ICON_MAX_FA ,
|
|
|
|
0
|
|
|
|
};
|
2017-11-22 14:13:02 +01:00
|
|
|
} // namespace <anon>
|
2017-10-04 11:20:27 +02:00
|
|
|
|
|
|
|
T_Window::T_Window( )
|
|
|
|
{
|
|
|
|
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER );
|
|
|
|
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER , 1 );
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE , 24 );
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE , 8 );
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION , 2 );
|
|
|
|
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION , 2 );
|
|
|
|
|
|
|
|
SDL_DisplayMode current;
|
|
|
|
SDL_GetCurrentDisplayMode( 0 , ¤t );
|
|
|
|
window = SDL_CreateWindow( "DEMO",
|
|
|
|
SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED ,
|
|
|
|
1280 , 720 ,
|
|
|
|
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE );
|
|
|
|
gl = SDL_GL_CreateContext( window );
|
|
|
|
glewInit( );
|
|
|
|
if ( !GLEW_VERSION_4_5 ) {
|
|
|
|
fprintf( stderr , "OpenGL 4.5 required\n" );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui_ImplSdl_Init( window );
|
2017-11-20 21:54:46 +01:00
|
|
|
|
|
|
|
using namespace ImGui;
|
2017-11-21 17:32:52 +01:00
|
|
|
StyleColorsDark( );
|
2017-11-20 21:54:46 +01:00
|
|
|
ImGuiIO& io{ GetIO( ) };
|
2017-11-22 09:01:51 +01:00
|
|
|
io.IniFilename = nullptr;
|
2017-11-20 21:54:46 +01:00
|
|
|
{
|
|
|
|
ImFontConfig cfg;
|
|
|
|
cfg.SizePixels = 13.0f;
|
|
|
|
defaultFont_ = io.Fonts->AddFontDefault( &cfg );
|
2017-11-21 17:32:52 +01:00
|
|
|
|
|
|
|
ImFontConfig icons;
|
|
|
|
icons.MergeMode = true;
|
|
|
|
icons.PixelSnapH = true;
|
|
|
|
io.Fonts->AddFontFromMemoryCompressedBase85TTF(
|
|
|
|
FontAwesome__compressed_data_base85 , 13.f ,
|
|
|
|
&icons , IconsRanges_ );
|
2017-11-20 21:54:46 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
ImFontConfig cfg;
|
|
|
|
cfg.SizePixels = 9.0f;
|
|
|
|
smallFont_ = io.Fonts->AddFontDefault( &cfg );
|
2017-11-21 17:32:52 +01:00
|
|
|
|
|
|
|
ImFontConfig icons;
|
|
|
|
icons.MergeMode = true;
|
|
|
|
icons.PixelSnapH = true;
|
|
|
|
icons.DstFont = smallFont_;
|
|
|
|
io.Fonts->AddFontFromMemoryCompressedBase85TTF(
|
|
|
|
FontAwesome__compressed_data_base85 , 9.f ,
|
|
|
|
&icons , IconsRanges_ );
|
2017-11-20 21:54:46 +01:00
|
|
|
}
|
2017-10-04 11:20:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
T_Window::~T_Window( )
|
|
|
|
{
|
|
|
|
ImGui_ImplSdl_Shutdown( );
|
|
|
|
SDL_GL_DeleteContext( gl );
|
|
|
|
SDL_DestroyWindow( window );
|
|
|
|
SDL_Quit( );
|
|
|
|
}
|
|
|
|
|
2017-11-23 13:54:27 +01:00
|
|
|
void T_Window::addAction(
|
|
|
|
T_UIAction action ) noexcept
|
|
|
|
{
|
|
|
|
actions_.set( std::move( action ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_Window::actionMenu(
|
|
|
|
T_String const& id ) const noexcept
|
|
|
|
{
|
|
|
|
auto const* const a{ actions_.get( id ) };
|
|
|
|
if ( a ) {
|
|
|
|
a->menuItem( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_Window::actionButton(
|
|
|
|
T_String const& id ) const noexcept
|
|
|
|
{
|
|
|
|
auto const* const a{ actions_.get( id ) };
|
|
|
|
if ( a ) {
|
|
|
|
a->tbButton( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 11:20:27 +02:00
|
|
|
void T_Window::startFrame(
|
2017-11-03 09:08:19 +01:00
|
|
|
const bool capture ,
|
|
|
|
ImVec2 const& mouseInitial ) const
|
2017-10-04 11:20:27 +02:00
|
|
|
{
|
|
|
|
ImGui_ImplSdl_NewFrame( window , capture , mouseInitial );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_Window::warpMouse(
|
2017-11-03 09:08:19 +01:00
|
|
|
ImVec2 const& pos ) const
|
2017-10-04 11:20:27 +02:00
|
|
|
{
|
|
|
|
SDL_WarpMouseInWindow( window , pos.x , pos.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_Window::swap( ) const
|
|
|
|
{
|
|
|
|
SDL_GL_SwapWindow( window );
|
|
|
|
}
|
2017-11-22 14:13:02 +01:00
|
|
|
|
|
|
|
void T_Window::handleDialogs( ) noexcept
|
|
|
|
{
|
|
|
|
const auto nDialogs{ modals_.size( ) };
|
|
|
|
for ( auto i = 0u ; i < nDialogs ; i ++ ) {
|
|
|
|
const bool keep{ modals_[ i ]->draw( ) };
|
|
|
|
assert( keep || i + 1 == nDialogs );
|
|
|
|
if ( !keep ) {
|
|
|
|
modals_.removeLast( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|