From e2c6246d69ca293dae8f8bf38c012be9fcce57b5 Mon Sep 17 00:00:00 2001 From: saschawillems Date: Thu, 3 Mar 2016 16:41:57 +0100 Subject: [PATCH] Added virtual keypress handler in base example class (#56) --- base/vulkanexamplebase.cpp | 21 +++++++++++++-------- base/vulkanexamplebase.h | 3 +++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 9afec9f6..131ed456 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -736,6 +736,7 @@ void VulkanExampleBase::handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR exit(0); break; } + keyPressed((uint32_t)wParam); break; case WM_RBUTTONDOWN: case WM_LBUTTONDOWN: @@ -766,8 +767,7 @@ void VulkanExampleBase::handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR #else -// Linux : Setup window -// TODO : Not finished... +// Set up a window using XCB and request event types xcb_window_t VulkanExampleBase::setupWindow() { uint32_t value_mask, value_list[32]; @@ -776,7 +776,8 @@ xcb_window_t VulkanExampleBase::setupWindow() value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; value_list[0] = screen->black_pixel; - value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | + value_list[1] = + XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_POINTER_MOTION | @@ -879,11 +880,10 @@ void VulkanExampleBase::handleEvent(const xcb_generic_event_t *event) break; case XCB_KEY_RELEASE: { - const xcb_key_release_event_t *key = - (const xcb_key_release_event_t *)event; - - if (key->detail == 0x9) + const xcb_key_release_event_t *keyEvent = (const xcb_key_release_event_t *)event; + if (keyEvent->detail == 0x9) quit = true; + keyPressed(keyEvent->detail); } break; case XCB_DESTROY_NOTIFY: @@ -897,7 +897,12 @@ void VulkanExampleBase::handleEvent(const xcb_generic_event_t *event) void VulkanExampleBase::viewChanged() { - // For overriding on derived class + // Can be overrdiden in derived class +} + +void VulkanExampleBase::keyPressed(uint32_t keyCode) +{ + // Can be overriden in derived class } VkBool32 VulkanExampleBase::getMemoryType(uint32_t typeBits, VkFlags properties, uint32_t * typeIndex) diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index 659feb00..2707868f 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -163,6 +163,9 @@ public: // Can be overriden in derived class to e.g. update uniform buffers // Containing view dependant matrices virtual void viewChanged(); + // Called if a key is pressed + // Can be overriden derived class to do custom key handling + virtual void keyPressed(uint32_t keyCode); // Get memory type for a given memory allocation (flags and bits) VkBool32 getMemoryType(uint32_t typeBits, VkFlags properties, uint32_t *typeIndex);