Skip to content

Commit

Permalink
NativeApp: add flags to control hot keys
Browse files Browse the repository at this point in the history
  • Loading branch information
snaulX committed Apr 11, 2023
1 parent 0f0decd commit fb0f127
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
26 changes: 26 additions & 0 deletions NativeApp/include/AppBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,29 @@

#pragma once

#include "BasicTypes.h"
#include "FlagEnum.h"

namespace Diligent
{

/// Flags to handle default hotkeys
enum HOT_KEY_FLAGS : Uint32
{
/// App doesn't react on default hotkeys
HOT_KEY_FLAG_NONE = 0,

/// App will exit by pressing Escape
HOT_KEY_FLAG_ALLOW_EXIT_ON_ESC = 1 << 0,

/// App will change fullscreen mode on Shift+Enter (only in UWP)
HOT_KEY_FLAG_ALLOW_FULL_SCREEN_SWITCH = 1 << 1,

/// Enables all default hotkeys
HOT_KEY_FLAG_ALL = ~0u
};
DEFINE_FLAG_ENUM_OPERATORS(HOT_KEY_FLAGS)

/// Base class for native applications. Platform-specific classes
/// such as Win32AppBase, LinuxAppBase are inherited from AppBase.
class AppBase
Expand Down Expand Up @@ -156,6 +176,12 @@ class AppBase
{
return false;
}

/// Returns default hotkeys handling flags
virtual HOT_KEY_FLAGS GetHotKeyFlags() const
{
return HOT_KEY_FLAG_ALL;
}
};

} // namespace Diligent
2 changes: 1 addition & 1 deletion NativeApp/src/Linux/LinuxMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ int x_main(int argc, const char* const* argv)
}
}

if (EscPressed)
if (EscPressed && (TheApp->GetHotKeyFlags() & HOT_KEY_FLAG_ALLOW_EXIT_ON_ESC))
break;

// Render the scene
Expand Down
7 changes: 5 additions & 2 deletions NativeApp/src/UWP/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,14 @@ void App::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::Ke
switch(Key)
{
case VirtualKey::Escape:
CoreApplication::Exit();
if (m_Main->GetHotKeyFlags() & HOT_KEY_FLAG_ALLOW_EXIT_ON_ESC)
{
CoreApplication::Exit();
}
break;

case VirtualKey::Enter:
if(m_bShiftPressed)
if(m_bShiftPressed && (m_Main->GetHotKeyFlags() & HOT_KEY_FLAG_ALLOW_FULL_SCREEN_SWITCH))
{
auto applicationView = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
if (applicationView->IsFullScreenMode)
Expand Down
2 changes: 1 addition & 1 deletion NativeApp/src/Win32/WinMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ LRESULT CALLBACK MessageProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lPara
return 0;

case WM_CHAR:
if (wParam == VK_ESCAPE)
if (wParam == VK_ESCAPE && (g_pTheApp->GetHotKeyFlags() & HOT_KEY_FLAG_ALLOW_EXIT_ON_ESC))
PostQuitMessage(0);
return 0;

Expand Down

0 comments on commit fb0f127

Please sign in to comment.