[UI/HID] ui::VirtualKey enum

This commit is contained in:
Triang3l
2021-07-01 23:32:26 +03:00
parent ddee85f0be
commit 1cf12ec70b
18 changed files with 675 additions and 324 deletions

View File

@@ -81,20 +81,23 @@ inline T byte_swap(T value) {
template <typename T, std::endian E>
struct endian_store {
endian_store() = default;
endian_store(const T& src) {
endian_store(const T& src) { set(src); }
endian_store(const endian_store& other) { set(other); }
operator T() const { return get(); }
void set(const T& src) {
if constexpr (std::endian::native == E) {
value = src;
} else {
value = xe::byte_swap(src);
}
}
endian_store(const endian_store& other) { value = other.value; }
operator T() const {
void set(const endian_store& other) { value = other.value; }
T get() const {
if constexpr (std::endian::native == E) {
return value;
} else {
return xe::byte_swap(value);
}
return xe::byte_swap(value);
}
endian_store<T, E>& operator+=(int a) {

View File

@@ -30,6 +30,7 @@
#include "xenia/base/assert.h"
#include "xenia/base/cvar.h"
#include "xenia/base/profiling.h"
#include "xenia/ui/virtual_key.h"
#include "xenia/ui/window.h"
#if XE_OPTION_PROFILING
@@ -112,31 +113,35 @@ void Profiler::ThreadEnter(const char* name) {
void Profiler::ThreadExit() { MicroProfileOnThreadExit(); }
bool Profiler::OnKeyDown(int key_code) {
bool Profiler::OnKeyDown(ui::VirtualKey virtual_key) {
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
switch (key_code) {
case VK_OEM_3: // `
switch (virtual_key) {
case ui::VirtualKey::kOem3: // `
MicroProfileTogglePause();
return true;
#if XE_OPTION_PROFILING_UI
case VK_TAB:
case ui::VirtualKey::kTab:
MicroProfileToggleDisplayMode();
return true;
case 0x31: // 1
case ui::VirtualKey::k1:
MicroProfileModKey(1);
return true;
#endif // XE_OPTION_PROFILING_UI
default:
break;
}
return false;
}
bool Profiler::OnKeyUp(int key_code) {
switch (key_code) {
bool Profiler::OnKeyUp(ui::VirtualKey virtual_key) {
switch (virtual_key) {
#if XE_OPTION_PROFILING_UI
case 0x31: // 1
case ui::VirtualKey::k1:
MicroProfileModKey(0);
return true;
#endif // XE_OPTION_PROFILING_UI
default:
break;
}
return false;
}
@@ -219,14 +224,14 @@ void Profiler::set_window(ui::Window* window) {
// Watch for toggle/mode keys and such.
window_->on_key_down.AddListener([](ui::KeyEvent* e) {
if (Profiler::is_visible()) {
Profiler::OnKeyDown(e->key_code());
Profiler::OnKeyDown(e->virtual_key());
e->set_handled(true);
window_->Invalidate();
}
});
window_->on_key_up.AddListener([](ui::KeyEvent* e) {
if (Profiler::is_visible()) {
Profiler::OnKeyUp(e->key_code());
Profiler::OnKeyUp(e->virtual_key());
e->set_handled(true);
window_->Invalidate();
}
@@ -257,8 +262,8 @@ void Profiler::Shutdown() {}
uint32_t Profiler::GetColor(const char* str) { return 0; }
void Profiler::ThreadEnter(const char* name) {}
void Profiler::ThreadExit() {}
bool Profiler::OnKeyDown(int key_code) { return false; }
bool Profiler::OnKeyUp(int key_code) { return false; }
bool Profiler::OnKeyDown(ui::VirtualKey virtual_key) { return false; }
bool Profiler::OnKeyUp(ui::VirtualKey virtual_key) { return false; }
void Profiler::OnMouseDown(bool left_button, bool right_button) {}
void Profiler::OnMouseUp() {}
void Profiler::OnMouseMove(int x, int y) {}

View File

@@ -13,6 +13,7 @@
#include <memory>
#include "xenia/base/string.h"
#include "xenia/ui/virtual_key.h"
#if XE_PLATFORM_WIN32
#define XE_OPTION_PROFILING 1
@@ -171,8 +172,8 @@ class Profiler {
// Deactivates the calling thread for profiling.
static void ThreadExit();
static bool OnKeyDown(int key_code);
static bool OnKeyUp(int key_code);
static bool OnKeyDown(ui::VirtualKey virtual_key);
static bool OnKeyUp(ui::VirtualKey virtual_key);
static void OnMouseDown(bool left_button, bool right_button);
static void OnMouseUp();
static void OnMouseMove(int x, int y);