diff --git a/Makefile b/Makefile index b221234..60d861f 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ COMMON = \ ui-actions.cc \ ui-colorgrading.cc \ ui-dialogs.cc \ + ui-utilities.cc \ globals.cc \ profiling.cc \ shaders.cc \ diff --git a/main.cc b/main.cc index 37a95b0..e619027 100644 --- a/main.cc +++ b/main.cc @@ -10,6 +10,7 @@ #include "rendertarget.hh" #include "sync.hh" #include "ui-sequencer.hh" +#include "ui-utilities.hh" #include "undo.hh" diff --git a/shaders.cc b/shaders.cc index d553cc3..dd73669 100644 --- a/shaders.cc +++ b/shaders.cc @@ -1,6 +1,7 @@ #include "externals.hh" #include "shaders.hh" #include "globals.hh" +#include "ui-utilities.hh" #include diff --git a/texture.cc b/texture.cc index 3c981c7..469eba0 100644 --- a/texture.cc +++ b/texture.cc @@ -1,8 +1,8 @@ #include "externals.hh" -#include "utilities.hh" #include "texture.hh" #include "globals.hh" #include "odbg.hh" +#include "ui-utilities.hh" /*==============================================================================*/ diff --git a/ui-actions.cc b/ui-actions.cc index 3444f70..751d723 100644 --- a/ui-actions.cc +++ b/ui-actions.cc @@ -1,5 +1,6 @@ #include "externals.hh" #include "ui-actions.hh" +#include "ui-utilities.hh" #include @@ -60,9 +61,7 @@ void T_UIAction::tbButton( ) const noexcept const bool e{ enabled ? enabled( ) : true }; if ( !e ) { - PushItemFlag( ImGuiItemFlags_Disabled , true ); - PushStyleVar( ImGuiStyleVar_Alpha , - GetStyle( ).Alpha * .5f ); + PushDisabled( ); } const bool rv{ Button( sb.data( ) , ImVec2{ 20 , 0 } ) }; if ( e && IsItemHovered( ) ) { @@ -79,8 +78,7 @@ void T_UIAction::tbButton( ) const noexcept EndTooltip( ); } if ( !e ) { - PopItemFlag( ); - PopStyleVar( ); + PopDisabled( ); } if ( rv ) { diff --git a/ui-colorgrading.cc b/ui-colorgrading.cc index 5f12257..b67a898 100644 --- a/ui-colorgrading.cc +++ b/ui-colorgrading.cc @@ -1,5 +1,6 @@ #include "externals.hh" #include "ui-colorgrading.hh" +#include "ui-utilities.hh" #define IMGUI_DEFINE_MATH_OPERATORS #include @@ -12,14 +13,11 @@ namespace { const bool disabled ) { if ( disabled ) { - PushItemFlag( ImGuiItemFlags_Disabled , true ); - PushStyleVar( ImGuiStyleVar_Alpha , - GetStyle( ).Alpha * 0.5f ); + PushDisabled( ); } const bool rv( Button( name ) ); if ( disabled ) { - PopItemFlag( ); - PopStyleVar( ); + PopDisabled( ); } return rv; } diff --git a/ui-dialogs.cc b/ui-dialogs.cc index c1ec979..caba1df 100644 --- a/ui-dialogs.cc +++ b/ui-dialogs.cc @@ -1,5 +1,7 @@ #include "externals.hh" #include "ui-dialogs.hh" +#include "ui-utilities.hh" + #include @@ -79,17 +81,14 @@ bool A_ModalDialog::draw( ) noexcept SameLine( 0 ); } if ( d ) { - PushItemFlag( ImGuiItemFlags_Disabled , true ); - PushStyleVar( ImGuiStyleVar_Alpha , - GetStyle( ).Alpha * .5f ); + PushDisabled( ); } if ( Button( &buttons_[ i ][ 0 ] , buttonSize ) ) { assert( clicked == -1 ); clicked = i; } if ( d ) { - PopItemFlag( ); - PopStyleVar( ); + PopDisabled( ); } } const bool close( clicked != -1 && onButton( clicked ) ); diff --git a/ui-sequencer.cc b/ui-sequencer.cc index 257c5d1..49480e4 100644 --- a/ui-sequencer.cc +++ b/ui-sequencer.cc @@ -4,6 +4,7 @@ #include "globals.hh" #include "window.hh" #include "syncedit.hh" +#include "ui-utilities.hh" #define IMGUI_DEFINE_MATH_OPERATORS #include @@ -21,37 +22,11 @@ bool FakeTab_( { using namespace ImGui; if ( disabled ) { - PushItemFlag( ImGuiItemFlags_Disabled , true ); - PushStyleVar( ImGuiStyleVar_Alpha , - GetStyle( ).Alpha * .5f ); + PushDisabled( ); } const bool rv( Button( name , ImVec2{ width , 0.f } ) ); if ( disabled ) { - PopItemFlag( ); - PopStyleVar( ); - } - return rv; -} - -void ToolbarSeparator_( ) noexcept -{ - using namespace ImGui; - SameLine( ); - VerticalSeparator( ); - SameLine( ); -} - -bool ToolbarButton_( - char const* const string , - ImVec2 const& size , - char const* const tooltip = nullptr ) noexcept -{ - using namespace ImGui; - const bool rv{ Button( string , size ) }; - if ( tooltip && IsItemHovered( ) ) { - BeginTooltip( ); - Text( tooltip ); - EndTooltip( ); + PopDisabled( ); } return rv; } @@ -130,14 +105,11 @@ uint8_t T_ChangeDurationDialog_::drawDialog( ) noexcept } if ( uPerMinute0_ == uPerMinute_ ) { - PushItemFlag( ImGuiItemFlags_Disabled , true ); - PushStyleVar( ImGuiStyleVar_Alpha , - GetStyle( ).Alpha * .5f ); + PushDisabled( ); } Checkbox( "Scale curves" , &scale_ ); if ( uPerMinute0_ == uPerMinute_ ) { - PopItemFlag( ); - PopStyleVar( ); + PopDisabled( ); } const bool eo{ units_ != units0_ || uPerMinute_ != uPerMinute0_ }; @@ -318,18 +290,18 @@ void T_SyncViewImpl_::displayToolbar( ) noexcept using namespace ImGui; auto& sync( Globals::Sync( ) ); - if ( ToolbarButton_( sync.playing( ) ? ICON_FA_STOP : ICON_FA_PLAY , BtSize , + if ( ToolbarButton( sync.playing( ) ? ICON_FA_STOP : ICON_FA_PLAY , BtSize , sync.playing( ) ? "Stop" : "Play" ) ) { sync.playing( ) = !sync.playing( ) && !sync.finished( ); } SameLine( ); - if ( ToolbarButton_( ICON_FA_BACKWARD , BtSize , "Rewind to 00:00.000" ) ) { + if ( ToolbarButton( ICON_FA_BACKWARD , BtSize , "Rewind to 00:00.000" ) ) { sync.setTime( 0 ); } - ToolbarSeparator_( ); + ToolbarSeparator( ); Text( ICON_FA_SEARCH ); bool zoomHovered{ IsItemHovered( ) }; @@ -345,22 +317,22 @@ void T_SyncViewImpl_::displayToolbar( ) noexcept SameLine( ); - if ( ToolbarButton_( followTime ? ICON_FA_LOCK : ICON_FA_UNLOCK , BtSize , + if ( ToolbarButton( followTime ? ICON_FA_LOCK : ICON_FA_UNLOCK , BtSize , followTime ? "Follows the current position.\nClick to untie." : "Not tied to the current position.\nClick to follow." ) ) { followTime = !followTime; } - ToolbarSeparator_( ); + ToolbarSeparator( ); - if ( ToolbarButton_( ICON_FA_CLOCK_O , BtSize , "Change duration and time units." ) ) { + if ( ToolbarButton( ICON_FA_CLOCK_O , BtSize , "Change duration and time units." ) ) { Globals::Window( ).pushDialog( NewOwned< T_ChangeDurationDialog_ >( sync.durationUnits( ) , sync.durationUnitSize( ) ) ); } - ToolbarSeparator_( ); + ToolbarSeparator( ); - if ( ToolbarButton_( ICON_FA_LINE_CHART , BtSize , + if ( ToolbarButton( ICON_FA_LINE_CHART , BtSize , "Select curves or sets thereof to display & edit." ) ) { const bool displaySelector{ sub == SW_CURVE_SELECTOR || sub == SW_OVERRIDE_SELECTOR }; @@ -708,9 +680,7 @@ void T_SyncViewImpl_::displayCurveSelector( ) noexcept const bool overriden{ present && *sCurves.get( n ) }; if ( overriden ) { - PushItemFlag( ImGuiItemFlags_Disabled , true ); - PushStyleVar( ImGuiStyleVar_Alpha , - GetStyle( ).Alpha * .5f ); + PushDisabled( ); } bool select{ present }; @@ -724,8 +694,7 @@ void T_SyncViewImpl_::displayCurveSelector( ) noexcept } if ( overriden ) { - PopItemFlag( ); - PopStyleVar( ); + PopDisabled( ); } } EndChild( ); @@ -763,9 +732,7 @@ void T_SyncViewImpl_::displayOverrideSelector( ) noexcept }() }; if ( hasCurves ) { - PushItemFlag( ImGuiItemFlags_Disabled , true ); - PushStyleVar( ImGuiStyleVar_Alpha , - GetStyle( ).Alpha * .5f ); + PushDisabled( ); } bool select{ present }; @@ -784,8 +751,7 @@ void T_SyncViewImpl_::displayOverrideSelector( ) noexcept } if ( hasCurves ) { - PopItemFlag( ); - PopStyleVar( ); + PopDisabled( ); } } return true; diff --git a/ui-utilities.cc b/ui-utilities.cc new file mode 100644 index 0000000..85297fe --- /dev/null +++ b/ui-utilities.cc @@ -0,0 +1,59 @@ +#include "externals.hh" +#include "ui-utilities.hh" + +#include + + +void ImGui::PushDisabled( ) noexcept +{ + PushItemFlag( ImGuiItemFlags_Disabled , true ); + PushStyleVar( ImGuiStyleVar_Alpha , GetStyle( ).Alpha * .5f ); +} + +void ImGui::PopDisabled( ) noexcept +{ + PopItemFlag( ); + PopStyleVar( ); +} + +/*------------------------------------------------------------------------------*/ + +bool ImGui::MenuItemCheckbox( + char const* name , + bool* checked ) noexcept +{ + bool rv{ MenuItem( name , "" , *checked , true ) }; + if ( rv ) { + *checked = !*checked; + } + return rv; +} + +/*------------------------------------------------------------------------------*/ + +bool ImGui::ToolbarButton( + char const* const string , + ImVec2 const& size , + char const* const tooltip , + bool enabled ) noexcept +{ + if ( !enabled ) { + PushDisabled( ); + } + const bool rv{ Button( string , size ) }; + if ( !enabled ) { + PopDisabled( ); + } else if ( tooltip && IsItemHovered( ) ) { + BeginTooltip( ); + Text( tooltip ); + EndTooltip( ); + } + return rv; +} + +void ImGui::ToolbarSeparator( ) noexcept +{ + SameLine( ); + VerticalSeparator( ); + SameLine( ); +} diff --git a/ui-utilities.hh b/ui-utilities.hh new file mode 100644 index 0000000..aed3b73 --- /dev/null +++ b/ui-utilities.hh @@ -0,0 +1,49 @@ +#pragma once +#ifndef REAL_BUILD +# include "externals.hh" +#endif + +/*= UI UTILITIES =============================================================*/ + +namespace ImGui { + + // Disable next ImGui controls + void PushDisabled( ) noexcept; + // Re-enable ImGui buttons + void PopDisabled( ) noexcept; + + /*--------------------------------------------------------------------*/ + + // Display a menu item with a checkbox + bool MenuItemCheckbox( + char const* name , + bool* checked ) noexcept; + + /*--------------------------------------------------------------------*/ + + // Display a separator for the toolbar + void ToolbarSeparator( ) noexcept; + + // Display a toolbar button + bool ToolbarButton( + char const* const string , + ImVec2 const& size , + char const* const tooltip = nullptr , + bool enabled = true ) noexcept; + +} // namespace ImGui + +/*----------------------------------------------------------------------------*/ + +#define GL_CHECK( FAIL ) \ + do { \ + auto err_( glGetError( ) ); \ + if ( err_ != GL_NO_ERROR ) FAIL; \ + } while ( 0 ) + +#define GL_ASSERT( ) \ + GL_CHECK({ \ + fprintf( stderr , "GL error %x in %s:%d\n" , \ + err_ , __FILE__ , __LINE__ ); \ + abort( ); \ + }) diff --git a/utilities.cc b/utilities.cc index b6ec7e4..70220ca 100644 --- a/utilities.cc +++ b/utilities.cc @@ -2,15 +2,6 @@ #include "utilities.hh" -void disableButton( ) -{ - ImGui::PushStyleColor( ImGuiCol_Button , ImVec4( .3 , .3 , .3 , 1 ) ); - ImGui::PushStyleColor( ImGuiCol_ButtonHovered , ImVec4( .3 , .3 , .3 , 1 ) ); - ImGui::PushStyleColor( ImGuiCol_ButtonActive , ImVec4( .3 , .3 , .3 , 1 ) ); -} - -/*----------------------------------------------------------------------------*/ - void updateAngle( float& initial , const float delta @@ -69,16 +60,3 @@ T_String GetParentPath( free( rp ); return rv; } - -/*------------------------------------------------------------------------------*/ - -bool ImGui::MenuItemCheckbox( - char const* name , - bool* checked ) -{ - bool rv{ MenuItem( name , "" , *checked , true ) }; - if ( rv ) { - *checked = !*checked; - } - return rv; -} diff --git a/utilities.hh b/utilities.hh index b5539cf..7194b19 100644 --- a/utilities.hh +++ b/utilities.hh @@ -5,31 +5,6 @@ /*= Utilities ================================================================*/ -// Disable next ImGui button(s) -void disableButton( ); -// Re-enable ImGui buttons -inline void reenableButtons( ) -{ - ImGui::PopStyleColor( 3 ); -} - -/*----------------------------------------------------------------------------*/ - -#define GL_CHECK( FAIL ) \ - do { \ - auto err_( glGetError( ) ); \ - if ( err_ != GL_NO_ERROR ) FAIL; \ - } while ( 0 ) - -#define GL_ASSERT( ) \ - GL_CHECK({ \ - fprintf( stderr , "GL error %x in %s:%d\n" , \ - err_ , __FILE__ , __LINE__ ); \ - abort( ); \ - }) - -/*----------------------------------------------------------------------------*/ - // Add some value to an angle, keeping it in [-180;180] void updateAngle( float& initial , @@ -76,13 +51,3 @@ std::string GetAbsolutePath( // Get the absolute parent path for a (possibly relative) path std::string GetParentPath( std::string const& path ); - -/*----------------------------------------------------------------------------*/ - -namespace ImGui { - - bool MenuItemCheckbox( - char const* name , - bool* checked ); - -} // namespace ImGui