From d16e583458c905b4cf3201adba6b2b8ecfae5acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Fri, 24 Nov 2017 11:59:15 +0100 Subject: [PATCH] UI - Keyboard shortcuts / actions for various things Quit, play/stop, undo/redo --- m-tool.cc | 18 ++++++------------ ui-app.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/m-tool.cc b/m-tool.cc index e5db8ba..a586281 100644 --- a/m-tool.cc +++ b/m-tool.cc @@ -136,23 +136,17 @@ void T_Main::initDemo( ) void T_Main::makeUI( ) { using namespace ImGui; - auto& undo( Common::Undo( ) ); + auto& main{ UI::Main( ) }; bool eSequencer{ sequencer }; if ( BeginMainMenuBar( ) ) { if ( BeginMenu( "File" ) ) { - UI::Main( ).actionMenu( "Save curves" ); - UI::Main( ).actionMenu( "Reload curves" ); + main.actionMenu( "Save curves" ); + main.actionMenu( "Reload curves" ); Separator( ); - if ( MenuItem( "Undo" , "C-z" , false , undo.canUndo( ) ) ) { - undo.undo( ); - } - if ( MenuItem( "Redo" , "C-Z" , false , undo.canRedo( ) ) ) { - undo.redo( ); - } + main.actionMenu( "Undo" ); + main.actionMenu( "Redo" ); Separator( ); - if ( MenuItem( "Quit" ) ) { - done = true; - } + main.actionMenu( "Quit" ); EndMenu( ); } if ( BeginMenu( "Views" ) ) { diff --git a/ui-app.cc b/ui-app.cc index 60dbca1..ccc993c 100644 --- a/ui-app.cc +++ b/ui-app.cc @@ -1,4 +1,9 @@ #include "externals.hh" + +#include "common.hh" +#include "c-sync.hh" +#include "c-undo.hh" + #include "ui.hh" #include "ui-app.hh" #include "ui-imgui-sdl.hh" @@ -75,6 +80,42 @@ T_UIApp::T_UIApp( ) FontAwesome__compressed_data_base85 , 9.f , &icons , IconsRanges_ ); } + + //---------------------------------------------------------------------- + // Keyboard shortcuts for undo/redo/quit/etc. + + addAction( T_UIAction{ "Undo" , []() { + Common::Undo( ).undo( ); + } }.setEnabledCheck( []() { + return Common::Undo( ).canUndo( ); + } ).setIcon( ICON_FA_UNDO ) + .setShortcut( T_KeyboardShortcut{ 'z' , E_KbdMod::CTRL } ) ); + + addAction( T_UIAction{ "Redo" , []() { + Common::Undo( ).redo( ); + } }.setEnabledCheck( []() { + return Common::Undo( ).canRedo( ); + } ).setShortcut( T_KeyboardShortcut{ 'z' , { E_KbdMod::CTRL , E_KbdMod::SHIFT } } ) ); + + addAction( T_UIAction{ "Play" , []() { + Common::Sync( ).playing( ) = true; + } }.setEnabledCheck( []() { + auto const& s{ Common::Sync( ) }; + return !s.playing( ) && !s.finished( ); + } ).setIcon( ICON_FA_PLAY ) + .setShortcut( T_KeyboardShortcut{ ' ' } ) ); + + addAction( T_UIAction{ "Stop" , []() { + Common::Sync( ).playing( ) = false; + } }.setEnabledCheck( []() { + auto const& s{ Common::Sync( ) }; + return s.playing( ); + } ).setIcon( ICON_FA_STOP ) + .setShortcut( T_KeyboardShortcut{ ' ' } ) ); + + addAction( T_UIAction{ "Quit" , [this]() { + exiting_ = true; + } }.setShortcut( T_KeyboardShortcut{ 'q' , E_KbdMod::CTRL } ) ); } T_UIApp::~T_UIApp( )