UI - Refactoring progress

(see previous log message)
This commit is contained in:
Emmanuel BENOîT 2017-11-23 14:43:15 +01:00
parent 743af1d0d7
commit 6ac2511ce7
12 changed files with 139 additions and 124 deletions

View file

@ -27,6 +27,7 @@ COMMON = \
ui-actions.cc \ ui-actions.cc \
ui-colorgrading.cc \ ui-colorgrading.cc \
ui-dialogs.cc \ ui-dialogs.cc \
ui-utilities.cc \
globals.cc \ globals.cc \
profiling.cc \ profiling.cc \
shaders.cc \ shaders.cc \

View file

@ -10,6 +10,7 @@
#include "rendertarget.hh" #include "rendertarget.hh"
#include "sync.hh" #include "sync.hh"
#include "ui-sequencer.hh" #include "ui-sequencer.hh"
#include "ui-utilities.hh"
#include "undo.hh" #include "undo.hh"

View file

@ -1,6 +1,7 @@
#include "externals.hh" #include "externals.hh"
#include "shaders.hh" #include "shaders.hh"
#include "globals.hh" #include "globals.hh"
#include "ui-utilities.hh"
#include <ebcl/Sets.hh> #include <ebcl/Sets.hh>

View file

@ -1,8 +1,8 @@
#include "externals.hh" #include "externals.hh"
#include "utilities.hh"
#include "texture.hh" #include "texture.hh"
#include "globals.hh" #include "globals.hh"
#include "odbg.hh" #include "odbg.hh"
#include "ui-utilities.hh"
/*==============================================================================*/ /*==============================================================================*/

View file

@ -1,5 +1,6 @@
#include "externals.hh" #include "externals.hh"
#include "ui-actions.hh" #include "ui-actions.hh"
#include "ui-utilities.hh"
#include <imgui_internal.h> #include <imgui_internal.h>
@ -60,9 +61,7 @@ void T_UIAction::tbButton( ) const noexcept
const bool e{ enabled ? enabled( ) : true }; const bool e{ enabled ? enabled( ) : true };
if ( !e ) { if ( !e ) {
PushItemFlag( ImGuiItemFlags_Disabled , true ); PushDisabled( );
PushStyleVar( ImGuiStyleVar_Alpha ,
GetStyle( ).Alpha * .5f );
} }
const bool rv{ Button( sb.data( ) , ImVec2{ 20 , 0 } ) }; const bool rv{ Button( sb.data( ) , ImVec2{ 20 , 0 } ) };
if ( e && IsItemHovered( ) ) { if ( e && IsItemHovered( ) ) {
@ -79,8 +78,7 @@ void T_UIAction::tbButton( ) const noexcept
EndTooltip( ); EndTooltip( );
} }
if ( !e ) { if ( !e ) {
PopItemFlag( ); PopDisabled( );
PopStyleVar( );
} }
if ( rv ) { if ( rv ) {

View file

@ -1,5 +1,6 @@
#include "externals.hh" #include "externals.hh"
#include "ui-colorgrading.hh" #include "ui-colorgrading.hh"
#include "ui-utilities.hh"
#define IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui_internal.h> #include <imgui_internal.h>
@ -12,14 +13,11 @@ namespace {
const bool disabled ) const bool disabled )
{ {
if ( disabled ) { if ( disabled ) {
PushItemFlag( ImGuiItemFlags_Disabled , true ); PushDisabled( );
PushStyleVar( ImGuiStyleVar_Alpha ,
GetStyle( ).Alpha * 0.5f );
} }
const bool rv( Button( name ) ); const bool rv( Button( name ) );
if ( disabled ) { if ( disabled ) {
PopItemFlag( ); PopDisabled( );
PopStyleVar( );
} }
return rv; return rv;
} }

View file

@ -1,5 +1,7 @@
#include "externals.hh" #include "externals.hh"
#include "ui-dialogs.hh" #include "ui-dialogs.hh"
#include "ui-utilities.hh"
#include <imgui_internal.h> #include <imgui_internal.h>
@ -79,17 +81,14 @@ bool A_ModalDialog::draw( ) noexcept
SameLine( 0 ); SameLine( 0 );
} }
if ( d ) { if ( d ) {
PushItemFlag( ImGuiItemFlags_Disabled , true ); PushDisabled( );
PushStyleVar( ImGuiStyleVar_Alpha ,
GetStyle( ).Alpha * .5f );
} }
if ( Button( &buttons_[ i ][ 0 ] , buttonSize ) ) { if ( Button( &buttons_[ i ][ 0 ] , buttonSize ) ) {
assert( clicked == -1 ); assert( clicked == -1 );
clicked = i; clicked = i;
} }
if ( d ) { if ( d ) {
PopItemFlag( ); PopDisabled( );
PopStyleVar( );
} }
} }
const bool close( clicked != -1 && onButton( clicked ) ); const bool close( clicked != -1 && onButton( clicked ) );

View file

@ -4,6 +4,7 @@
#include "globals.hh" #include "globals.hh"
#include "window.hh" #include "window.hh"
#include "syncedit.hh" #include "syncedit.hh"
#include "ui-utilities.hh"
#define IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui_internal.h> #include <imgui_internal.h>
@ -21,37 +22,11 @@ bool FakeTab_(
{ {
using namespace ImGui; using namespace ImGui;
if ( disabled ) { if ( disabled ) {
PushItemFlag( ImGuiItemFlags_Disabled , true ); PushDisabled( );
PushStyleVar( ImGuiStyleVar_Alpha ,
GetStyle( ).Alpha * .5f );
} }
const bool rv( Button( name , ImVec2{ width , 0.f } ) ); const bool rv( Button( name , ImVec2{ width , 0.f } ) );
if ( disabled ) { if ( disabled ) {
PopItemFlag( ); PopDisabled( );
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( );
} }
return rv; return rv;
} }
@ -130,14 +105,11 @@ uint8_t T_ChangeDurationDialog_::drawDialog( ) noexcept
} }
if ( uPerMinute0_ == uPerMinute_ ) { if ( uPerMinute0_ == uPerMinute_ ) {
PushItemFlag( ImGuiItemFlags_Disabled , true ); PushDisabled( );
PushStyleVar( ImGuiStyleVar_Alpha ,
GetStyle( ).Alpha * .5f );
} }
Checkbox( "Scale curves" , &scale_ ); Checkbox( "Scale curves" , &scale_ );
if ( uPerMinute0_ == uPerMinute_ ) { if ( uPerMinute0_ == uPerMinute_ ) {
PopItemFlag( ); PopDisabled( );
PopStyleVar( );
} }
const bool eo{ units_ != units0_ || uPerMinute_ != uPerMinute0_ }; const bool eo{ units_ != units0_ || uPerMinute_ != uPerMinute0_ };
@ -318,18 +290,18 @@ void T_SyncViewImpl_::displayToolbar( ) noexcept
using namespace ImGui; using namespace ImGui;
auto& sync( Globals::Sync( ) ); 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( ) ? "Stop" : "Play" ) ) {
sync.playing( ) = !sync.playing( ) && !sync.finished( ); sync.playing( ) = !sync.playing( ) && !sync.finished( );
} }
SameLine( ); 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 ); sync.setTime( 0 );
} }
ToolbarSeparator_( ); ToolbarSeparator( );
Text( ICON_FA_SEARCH ); Text( ICON_FA_SEARCH );
bool zoomHovered{ IsItemHovered( ) }; bool zoomHovered{ IsItemHovered( ) };
@ -345,22 +317,22 @@ void T_SyncViewImpl_::displayToolbar( ) noexcept
SameLine( ); 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." followTime ? "Follows the current position.\nClick to untie."
: "Not tied to the current position.\nClick to follow." ) ) { : "Not tied to the current position.\nClick to follow." ) ) {
followTime = !followTime; 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_ >( Globals::Window( ).pushDialog( NewOwned< T_ChangeDurationDialog_ >(
sync.durationUnits( ) , sync.durationUnitSize( ) ) ); 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." ) ) { "Select curves or sets thereof to display & edit." ) ) {
const bool displaySelector{ sub == SW_CURVE_SELECTOR const bool displaySelector{ sub == SW_CURVE_SELECTOR
|| sub == SW_OVERRIDE_SELECTOR }; || sub == SW_OVERRIDE_SELECTOR };
@ -708,9 +680,7 @@ void T_SyncViewImpl_::displayCurveSelector( ) noexcept
const bool overriden{ present && *sCurves.get( n ) }; const bool overriden{ present && *sCurves.get( n ) };
if ( overriden ) { if ( overriden ) {
PushItemFlag( ImGuiItemFlags_Disabled , true ); PushDisabled( );
PushStyleVar( ImGuiStyleVar_Alpha ,
GetStyle( ).Alpha * .5f );
} }
bool select{ present }; bool select{ present };
@ -724,8 +694,7 @@ void T_SyncViewImpl_::displayCurveSelector( ) noexcept
} }
if ( overriden ) { if ( overriden ) {
PopItemFlag( ); PopDisabled( );
PopStyleVar( );
} }
} }
EndChild( ); EndChild( );
@ -763,9 +732,7 @@ void T_SyncViewImpl_::displayOverrideSelector( ) noexcept
}() }; }() };
if ( hasCurves ) { if ( hasCurves ) {
PushItemFlag( ImGuiItemFlags_Disabled , true ); PushDisabled( );
PushStyleVar( ImGuiStyleVar_Alpha ,
GetStyle( ).Alpha * .5f );
} }
bool select{ present }; bool select{ present };
@ -784,8 +751,7 @@ void T_SyncViewImpl_::displayOverrideSelector( ) noexcept
} }
if ( hasCurves ) { if ( hasCurves ) {
PopItemFlag( ); PopDisabled( );
PopStyleVar( );
} }
} }
return true; return true;

59
ui-utilities.cc Normal file
View file

@ -0,0 +1,59 @@
#include "externals.hh"
#include "ui-utilities.hh"
#include <imgui_internal.h>
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( );
}

49
ui-utilities.hh Normal file
View file

@ -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( ); \
})

View file

@ -2,15 +2,6 @@
#include "utilities.hh" #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( void updateAngle(
float& initial , float& initial ,
const float delta const float delta
@ -69,16 +60,3 @@ T_String GetParentPath(
free( rp ); free( rp );
return rv; return rv;
} }
/*------------------------------------------------------------------------------*/
bool ImGui::MenuItemCheckbox(
char const* name ,
bool* checked )
{
bool rv{ MenuItem( name , "" , *checked , true ) };
if ( rv ) {
*checked = !*checked;
}
return rv;
}

View file

@ -5,31 +5,6 @@
/*= Utilities ================================================================*/ /*= 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] // Add some value to an angle, keeping it in [-180;180]
void updateAngle( void updateAngle(
float& initial , float& initial ,
@ -76,13 +51,3 @@ std::string GetAbsolutePath(
// Get the absolute parent path for a (possibly relative) path // Get the absolute parent path for a (possibly relative) path
std::string GetParentPath( std::string GetParentPath(
std::string const& path ); std::string const& path );
/*----------------------------------------------------------------------------*/
namespace ImGui {
bool MenuItemCheckbox(
char const* name ,
bool* checked );
} // namespace ImGui