yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::gui::KeyboardShortcuts Class Reference

Manages keyboard shortcuts and provides an overlay UI. More...

#include <keyboard_shortcuts.h>

Public Member Functions

void RegisterShortcut (const Shortcut &shortcut)
 
void RegisterShortcut (const std::string &id, const std::string &description, ImGuiKey key, bool ctrl, bool shift, bool alt, const std::string &category, ShortcutContext context, std::function< void()> action)
 
void UnregisterShortcut (const std::string &id)
 
void SetShortcutEnabled (const std::string &id, bool enabled)
 
void ProcessInput ()
 
void DrawOverlay ()
 
void ToggleOverlay ()
 
void ShowOverlay ()
 
void HideOverlay ()
 
bool IsOverlayVisible () const
 
void SetCurrentContext (ShortcutContext context)
 
ShortcutContext GetCurrentContext () const
 
std::vector< const Shortcut * > GetShortcutsInCategory (const std::string &category) const
 
std::vector< const Shortcut * > GetContextShortcuts () const
 
std::vector< std::string > GetCategories () const
 
void RegisterDefaultShortcuts (std::function< void()> open_callback, std::function< void()> save_callback, std::function< void()> save_as_callback, std::function< void()> close_callback, std::function< void()> undo_callback, std::function< void()> redo_callback, std::function< void()> copy_callback, std::function< void()> paste_callback, std::function< void()> cut_callback, std::function< void()> find_callback)
 

Static Public Member Functions

static KeyboardShortcutsGet ()
 
static bool IsTextInputActive ()
 

Private Member Functions

 KeyboardShortcuts ()=default
 
 ~KeyboardShortcuts ()=default
 
 KeyboardShortcuts (const KeyboardShortcuts &)=delete
 
KeyboardShortcutsoperator= (const KeyboardShortcuts &)=delete
 
void DrawOverlayContent ()
 
void DrawShortcutRow (const Shortcut &shortcut)
 
void DrawCategorySection (const std::string &category, const std::vector< const Shortcut * > &shortcuts)
 
bool IsShortcutActiveInContext (const Shortcut &shortcut) const
 

Private Attributes

std::map< std::string, Shortcutshortcuts_
 
std::vector< std::string > category_order_
 
bool show_overlay_ = false
 
char search_filter_ [256] = {}
 
std::string expanded_category_
 
ShortcutContext current_context_ = ShortcutContext::kGlobal
 
bool toggle_key_was_pressed_ = false
 

Detailed Description

Manages keyboard shortcuts and provides an overlay UI.

This class provides a centralized system for registering, displaying, and processing keyboard shortcuts. It includes an overlay UI that can be toggled with the '?' key to show all available shortcuts.

Usage:

KeyboardShortcuts::Get().RegisterShortcut({ .id = "file.save", .description = "Save Project", .key = ImGuiKey_S, .requires_ctrl = true, .category = "File", .context = ShortcutContext::kGlobal, .action = []() { SaveProject(); } });

KeyboardShortcuts::Get().ProcessInput(); KeyboardShortcuts::Get().DrawOverlay();

Definition at line 85 of file keyboard_shortcuts.h.

Constructor & Destructor Documentation

◆ KeyboardShortcuts() [1/2]

yaze::gui::KeyboardShortcuts::KeyboardShortcuts ( )
privatedefault

◆ ~KeyboardShortcuts()

yaze::gui::KeyboardShortcuts::~KeyboardShortcuts ( )
privatedefault

◆ KeyboardShortcuts() [2/2]

yaze::gui::KeyboardShortcuts::KeyboardShortcuts ( const KeyboardShortcuts & )
privatedelete

Member Function Documentation

◆ Get()

KeyboardShortcuts & yaze::gui::KeyboardShortcuts::Get ( )
static

Definition at line 144 of file keyboard_shortcuts.cc.

◆ RegisterShortcut() [1/2]

void yaze::gui::KeyboardShortcuts::RegisterShortcut ( const Shortcut & shortcut)

Definition at line 149 of file keyboard_shortcuts.cc.

References yaze::gui::Shortcut::id, and shortcuts_.

Referenced by RegisterDefaultShortcuts(), and RegisterShortcut().

◆ RegisterShortcut() [2/2]

void yaze::gui::KeyboardShortcuts::RegisterShortcut ( const std::string & id,
const std::string & description,
ImGuiKey key,
bool ctrl,
bool shift,
bool alt,
const std::string & category,
ShortcutContext context,
std::function< void()> action )

◆ UnregisterShortcut()

void yaze::gui::KeyboardShortcuts::UnregisterShortcut ( const std::string & id)

Definition at line 173 of file keyboard_shortcuts.cc.

References shortcuts_.

◆ SetShortcutEnabled()

void yaze::gui::KeyboardShortcuts::SetShortcutEnabled ( const std::string & id,
bool enabled )

Definition at line 177 of file keyboard_shortcuts.cc.

References shortcuts_.

◆ ProcessInput()

void yaze::gui::KeyboardShortcuts::ProcessInput ( )

Definition at line 191 of file keyboard_shortcuts.cc.

References HideOverlay(), IsShortcutActiveInContext(), IsTextInputActive(), shortcuts_, show_overlay_, toggle_key_was_pressed_, and ToggleOverlay().

Here is the call graph for this function:

◆ DrawOverlay()

void yaze::gui::KeyboardShortcuts::DrawOverlay ( )

Definition at line 249 of file keyboard_shortcuts.cc.

References DrawOverlayContent(), yaze::gui::ThemeManager::Get(), yaze::gui::ThemeManager::GetCurrentTheme(), HideOverlay(), and show_overlay_.

Here is the call graph for this function:

◆ ToggleOverlay()

void yaze::gui::KeyboardShortcuts::ToggleOverlay ( )

Definition at line 241 of file keyboard_shortcuts.cc.

References search_filter_, and show_overlay_.

Referenced by ProcessInput().

◆ ShowOverlay()

void yaze::gui::KeyboardShortcuts::ShowOverlay ( )
inline

Definition at line 118 of file keyboard_shortcuts.h.

References show_overlay_.

◆ HideOverlay()

void yaze::gui::KeyboardShortcuts::HideOverlay ( )
inline

Definition at line 119 of file keyboard_shortcuts.h.

References show_overlay_.

Referenced by DrawOverlay(), DrawOverlayContent(), and ProcessInput().

◆ IsOverlayVisible()

bool yaze::gui::KeyboardShortcuts::IsOverlayVisible ( ) const
inline

Definition at line 120 of file keyboard_shortcuts.h.

References show_overlay_.

◆ SetCurrentContext()

void yaze::gui::KeyboardShortcuts::SetCurrentContext ( ShortcutContext context)
inline

Definition at line 123 of file keyboard_shortcuts.h.

References current_context_.

◆ GetCurrentContext()

ShortcutContext yaze::gui::KeyboardShortcuts::GetCurrentContext ( ) const
inline

Definition at line 124 of file keyboard_shortcuts.h.

References current_context_.

◆ GetShortcutsInCategory()

std::vector< const Shortcut * > yaze::gui::KeyboardShortcuts::GetShortcutsInCategory ( const std::string & category) const

Definition at line 507 of file keyboard_shortcuts.cc.

References shortcuts_.

◆ GetContextShortcuts()

std::vector< const Shortcut * > yaze::gui::KeyboardShortcuts::GetContextShortcuts ( ) const

Definition at line 518 of file keyboard_shortcuts.cc.

References IsShortcutActiveInContext(), and shortcuts_.

Here is the call graph for this function:

◆ GetCategories()

std::vector< std::string > yaze::gui::KeyboardShortcuts::GetCategories ( ) const

Definition at line 528 of file keyboard_shortcuts.cc.

References shortcuts_.

◆ RegisterDefaultShortcuts()

void yaze::gui::KeyboardShortcuts::RegisterDefaultShortcuts ( std::function< void()> open_callback,
std::function< void()> save_callback,
std::function< void()> save_as_callback,
std::function< void()> close_callback,
std::function< void()> undo_callback,
std::function< void()> redo_callback,
std::function< void()> copy_callback,
std::function< void()> paste_callback,
std::function< void()> cut_callback,
std::function< void()> find_callback )

Definition at line 545 of file keyboard_shortcuts.cc.

References yaze::gui::kDungeon, yaze::gui::kEmulator, yaze::gui::kGlobal, yaze::gui::kOverworld, and RegisterShortcut().

Here is the call graph for this function:

◆ IsTextInputActive()

bool yaze::gui::KeyboardShortcuts::IsTextInputActive ( )
static

Definition at line 185 of file keyboard_shortcuts.cc.

Referenced by ProcessInput().

◆ operator=()

KeyboardShortcuts & yaze::gui::KeyboardShortcuts::operator= ( const KeyboardShortcuts & )
privatedelete

◆ DrawOverlayContent()

◆ DrawShortcutRow()

◆ DrawCategorySection()

void yaze::gui::KeyboardShortcuts::DrawCategorySection ( const std::string & category,
const std::vector< const Shortcut * > & shortcuts )
private

Definition at line 420 of file keyboard_shortcuts.cc.

References yaze::gui::ConvertColorToImVec4(), DrawShortcutRow(), yaze::gui::ThemeManager::Get(), and yaze::gui::ThemeManager::GetCurrentTheme().

Referenced by DrawOverlayContent().

Here is the call graph for this function:

◆ IsShortcutActiveInContext()

bool yaze::gui::KeyboardShortcuts::IsShortcutActiveInContext ( const Shortcut & shortcut) const
private

Member Data Documentation

◆ shortcuts_

std::map<std::string, Shortcut> yaze::gui::KeyboardShortcuts::shortcuts_
private

◆ category_order_

std::vector<std::string> yaze::gui::KeyboardShortcuts::category_order_
private
Initial value:
= {
"File", "Edit", "View", "Navigation", "Tools", "Editor", "Other"
}

Definition at line 174 of file keyboard_shortcuts.h.

Referenced by DrawOverlayContent().

◆ show_overlay_

bool yaze::gui::KeyboardShortcuts::show_overlay_ = false
private

◆ search_filter_

char yaze::gui::KeyboardShortcuts::search_filter_[256] = {}
private

Definition at line 180 of file keyboard_shortcuts.h.

Referenced by DrawOverlayContent(), and ToggleOverlay().

◆ expanded_category_

std::string yaze::gui::KeyboardShortcuts::expanded_category_
private

Definition at line 181 of file keyboard_shortcuts.h.

◆ current_context_

ShortcutContext yaze::gui::KeyboardShortcuts::current_context_ = ShortcutContext::kGlobal
private

◆ toggle_key_was_pressed_

bool yaze::gui::KeyboardShortcuts::toggle_key_was_pressed_ = false
private

Definition at line 185 of file keyboard_shortcuts.h.

Referenced by ProcessInput().


The documentation for this class was generated from the following files: