UI - Renamed structures for keyboard modifiers

This commit is contained in:
Emmanuel BENOîT 2017-11-24 11:48:08 +01:00
parent fa242b08a4
commit bcf8843436
11 changed files with 34 additions and 34 deletions

View file

@ -12,13 +12,13 @@ void T_KeyboardShortcut::toString(
const size_t size ) const noexcept const size_t size ) const noexcept
{ {
const char ch[ 2 ] = { const char ch[ 2 ] = {
char( ( modifiers & E_KeyboardModifier::SHIFT ) char( ( modifiers & E_KbdMod::SHIFT )
? toupper( character ) : tolower( character ) ) , ? toupper( character ) : tolower( character ) ) ,
0 0
}; };
snprintf( buffer , size , "%s%s%s" , snprintf( buffer , size , "%s%s%s" ,
( modifiers & E_KeyboardModifier::CTRL ) ? "C-" : "" , ( modifiers & E_KbdMod::CTRL ) ? "C-" : "" ,
( modifiers & E_KeyboardModifier::ALT ) ? "A-" : "" , ( modifiers & E_KbdMod::ALT ) ? "A-" : "" ,
[&]( ) { [&]( ) {
switch ( character ) { switch ( character ) {
case ' ': return "<space>"; case ' ': return "<space>";

View file

@ -7,11 +7,11 @@
struct T_KeyboardShortcut struct T_KeyboardShortcut
{ {
char character; char character;
T_KeyboardModifiers modifiers; T_KbdMods modifiers;
explicit constexpr T_KeyboardShortcut( explicit constexpr T_KeyboardShortcut(
char character , char character ,
T_KeyboardModifiers modifiers = { } ) noexcept T_KbdMods modifiers = { } ) noexcept
: character{ character } , modifiers{ modifiers } : character{ character } , modifiers{ modifiers }
{} {}

View file

@ -155,15 +155,15 @@ void T_UIApp::handleEvents( ) noexcept
auto& io( ImGui::GetIO( ) ); auto& io( ImGui::GetIO( ) );
io.MouseDrawCursor = true; io.MouseDrawCursor = true;
kbMods_ = ( ([&io]() { kbMods_ = ( ([&io]() {
T_KeyboardModifiers kb; T_KbdMods kb;
if ( io.KeyCtrl ) { if ( io.KeyCtrl ) {
kb |= E_KeyboardModifier::CTRL; kb |= E_KbdMod::CTRL;
} }
if ( io.KeyShift ) { if ( io.KeyShift ) {
kb |= E_KeyboardModifier::SHIFT; kb |= E_KbdMod::SHIFT;
} }
if ( io.KeyAlt ) { if ( io.KeyAlt ) {
kb |= E_KeyboardModifier::ALT; kb |= E_KbdMod::ALT;
} }
return kb; return kb;
})() ); })() );

View file

@ -72,7 +72,7 @@ struct T_UIApp
bool exiting_{ false }; bool exiting_{ false };
// Keyboard events / state // Keyboard events / state
T_KeyboardModifiers kbMods_; T_KbdMods kbMods_;
T_AutoArray< char , 32 > kbKeys_; T_AutoArray< char , 32 > kbKeys_;
// Mouse capture // Mouse capture

View file

@ -13,10 +13,10 @@ using T_MouseButtons = T_Flags< E_MouseButton >;
/*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/
enum class E_KeyboardModifier enum class E_KbdMod
{ {
CTRL , CTRL ,
SHIFT , SHIFT ,
ALT , ALT ,
}; };
using T_KeyboardModifiers = T_Flags< E_KeyboardModifier >; using T_KbdMods = T_Flags< E_KbdMod >;

View file

@ -11,13 +11,13 @@ class A_MouseCtrl
virtual void handleDragAndDrop( virtual void handleDragAndDrop(
ImVec2 const& move , ImVec2 const& move ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons T_MouseButtons buttons
) noexcept = 0; ) noexcept = 0;
virtual void handleWheel( virtual void handleWheel(
float wheel , float wheel ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons T_MouseButtons buttons
) noexcept = 0; ) noexcept = 0;
}; };

View file

@ -274,12 +274,12 @@ struct T_MouseCam_ : public virtual A_MouseCtrl
void handleDragAndDrop( void handleDragAndDrop(
ImVec2 const& move , ImVec2 const& move ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons ) noexcept override; T_MouseButtons buttons ) noexcept override;
void handleWheel( void handleWheel(
float wheel , float wheel ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons ) noexcept override; T_MouseButtons buttons ) noexcept override;
}; };
@ -287,7 +287,7 @@ struct T_MouseCam_ : public virtual A_MouseCtrl
void T_MouseCam_::handleDragAndDrop( void T_MouseCam_::handleDragAndDrop(
ImVec2 const& move , ImVec2 const& move ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons ) noexcept T_MouseButtons buttons ) noexcept
{ {
auto& sync( Common::Sync( ) ); auto& sync( Common::Sync( ) );
@ -313,7 +313,7 @@ void T_MouseCam_::handleDragAndDrop(
void T_MouseCam_::handleWheel( void T_MouseCam_::handleWheel(
const float wheel , const float wheel ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons ) noexcept T_MouseButtons buttons ) noexcept
{ {
auto& sync( Common::Sync( ) ); auto& sync( Common::Sync( ) );
@ -327,7 +327,7 @@ void T_MouseCam_::handleWheel(
auto& sinp( sync.inputs( ) ); auto& sinp( sync.inputs( ) );
auto& cam{ camera.camera }; auto& cam{ camera.camera };
auto const& ovip{ ov.inputPositions( ) }; auto const& ovip{ ov.inputPositions( ) };
if ( modifiers & E_KeyboardModifier::SHIFT ) { if ( modifiers & E_KbdMod::SHIFT ) {
auto const& fc( ov.fovConfig( ) ); auto const& fc( ov.fovConfig( ) );
if ( fc.mode == T_CamOverride::FM_FOV ) { if ( fc.mode == T_CamOverride::FM_FOV ) {
sinp[ ovip[ fc.inputIndex ] ] = cam.fieldOfView( ); sinp[ ovip[ fc.inputIndex ] ] = cam.fieldOfView( );

View file

@ -30,7 +30,7 @@ T_UISync::T_UISync( )
} }.setEnabledCheck( []() { } }.setEnabledCheck( []() {
return Common::Sync( ).curvesModified( ); return Common::Sync( ).curvesModified( );
} ).setIcon( ICON_FA_FLOPPY_O ) } ).setIcon( ICON_FA_FLOPPY_O )
.setShortcut( T_KeyboardShortcut{ 's' , E_KeyboardModifier::CTRL } ) ); .setShortcut( T_KeyboardShortcut{ 's' , E_KbdMod::CTRL } ) );
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
UI::Main( ).addAction( T_UIAction{ "Reload curves" , []() { UI::Main( ).addAction( T_UIAction{ "Reload curves" , []() {
UI::Main( ).msgbox( UI::Main( ).msgbox(
@ -46,7 +46,7 @@ T_UISync::T_UISync( )
return Common::Sync( ).curvesModified( ); return Common::Sync( ).curvesModified( );
} ).setIcon( ICON_FA_DOWNLOAD ) } ).setIcon( ICON_FA_DOWNLOAD )
.setShortcut( T_KeyboardShortcut{ 'r' , .setShortcut( T_KeyboardShortcut{ 'r' ,
{ E_KeyboardModifier::CTRL , E_KeyboardModifier::SHIFT } } ) ); { E_KbdMod::CTRL , E_KbdMod::SHIFT } } ) );
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
const auto addui{ [this]( char const* type , F_Override ov ) { const auto addui{ [this]( char const* type , F_Override ov ) {
const bool ok{ sovuis_.add( T_String{ type } , std::move( ov ) ) }; const bool ok{ sovuis_.add( T_String{ type } , std::move( ov ) ) };
@ -208,7 +208,7 @@ void T_UISync::clearMouseDelegate( ) noexcept
void T_UISync::handleDragAndDrop( void T_UISync::handleDragAndDrop(
ImVec2 const& move , ImVec2 const& move ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons ) noexcept T_MouseButtons buttons ) noexcept
{ {
if ( mouseDelegate_ ) { if ( mouseDelegate_ ) {
@ -218,7 +218,7 @@ void T_UISync::handleDragAndDrop(
void T_UISync::handleWheel( void T_UISync::handleWheel(
const float wheel , const float wheel ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons ) noexcept T_MouseButtons buttons ) noexcept
{ {
if ( mouseDelegate_ ) { if ( mouseDelegate_ ) {

View file

@ -37,11 +37,11 @@ class T_UISync : public A_MouseCtrl
void handleDragAndDrop( void handleDragAndDrop(
ImVec2 const& move , ImVec2 const& move ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons ) noexcept override; T_MouseButtons buttons ) noexcept override;
void handleWheel( void handleWheel(
float wheel , float wheel ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons ) noexcept override; T_MouseButtons buttons ) noexcept override;
private: private:

View file

@ -65,17 +65,17 @@ void ImGui::ToolbarSeparator( ) noexcept
void T_CameraMouseControl::handleDragAndDrop( void T_CameraMouseControl::handleDragAndDrop(
ImVec2 const& move , ImVec2 const& move ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons ) noexcept T_MouseButtons buttons ) noexcept
{ {
if ( move.x == 0 || move.y == 0 ) { if ( move.x == 0 || move.y == 0 ) {
return; return;
} }
const float fdx( move.x * .1f * ( ( modifiers & E_KeyboardModifier::CTRL ) ? 1.f : .1f ) ); const float fdx( move.x * .1f * ( ( modifiers & E_KbdMod::CTRL ) ? 1.f : .1f ) );
const float fdy( move.y * .1f * ( ( modifiers & E_KeyboardModifier::CTRL ) ? 1.f : .1f ) ); const float fdy( move.y * .1f * ( ( modifiers & E_KbdMod::CTRL ) ? 1.f : .1f ) );
if ( ( buttons & E_MouseButton::LEFT ) && ( modifiers & E_KeyboardModifier::SHIFT ) ) { if ( ( buttons & E_MouseButton::LEFT ) && ( modifiers & E_KbdMod::SHIFT ) ) {
// Left mouse button, shift - move camera // Left mouse button, shift - move camera
const auto side( normalize( cross( camera.upVector( ) , camera.direction( ) ) ) ); const auto side( normalize( cross( camera.upVector( ) , camera.direction( ) ) ) );
camera.lookAt( ) += .1f * ( side * fdx + camera.upVector( ) * fdy ); camera.lookAt( ) += .1f * ( side * fdx + camera.upVector( ) * fdy );
@ -92,11 +92,11 @@ void T_CameraMouseControl::handleDragAndDrop(
void T_CameraMouseControl::handleWheel( void T_CameraMouseControl::handleWheel(
const float wheel , const float wheel ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons /* buttons */ ) noexcept T_MouseButtons /* buttons */ ) noexcept
{ {
const float delta( wheel * ( ( modifiers & E_KeyboardModifier::CTRL ) ? 1.f : .1f) ); const float delta( wheel * ( ( modifiers & E_KbdMod::CTRL ) ? 1.f : .1f) );
if ( modifiers & E_KeyboardModifier::SHIFT ) { if ( modifiers & E_KbdMod::SHIFT ) {
camera.fieldOfView( ) = ImClamp( camera.fieldOfView( ) + delta , 1.f , 179.f ); camera.fieldOfView( ) = ImClamp( camera.fieldOfView( ) + delta , 1.f , 179.f );
camera.cvtFov2Np( ); camera.cvtFov2Np( );
} else { } else {

View file

@ -60,11 +60,11 @@ struct T_CameraMouseControl : public A_MouseCtrl
void handleDragAndDrop( void handleDragAndDrop(
ImVec2 const& move , ImVec2 const& move ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons ) noexcept override; T_MouseButtons buttons ) noexcept override;
void handleWheel( void handleWheel(
float wheel , float wheel ,
T_KeyboardModifiers modifiers , T_KbdMods modifiers ,
T_MouseButtons buttons ) noexcept override; T_MouseButtons buttons ) noexcept override;
}; };