From 75e31d915c6c80888860fb5631636f99c5f6a52c Mon Sep 17 00:00:00 2001 From: Aloshi Date: Fri, 16 May 2014 19:14:22 -0500 Subject: [PATCH] Escape now closes the "configure a device" dialog. Does not work on the first run. --- src/guis/GuiDetectDevice.cpp | 13 +++++++++++-- src/guis/GuiDetectDevice.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/guis/GuiDetectDevice.cpp b/src/guis/GuiDetectDevice.cpp index 70ed69401..51578705f 100644 --- a/src/guis/GuiDetectDevice.cpp +++ b/src/guis/GuiDetectDevice.cpp @@ -14,7 +14,7 @@ using namespace Eigen; -GuiDetectDevice::GuiDetectDevice(Window* window, bool firstRun) : GuiComponent(window), +GuiDetectDevice::GuiDetectDevice(Window* window, bool firstRun) : GuiComponent(window), mFirstRun(firstRun), mBackground(window, ":/frame.png"), mGrid(window, Vector2i(1, 5)) { mHoldingConfig = NULL; @@ -49,7 +49,9 @@ GuiDetectDevice::GuiDetectDevice(Window* window, bool firstRun) : GuiComponent(w // message mMsg1 = std::make_shared(mWindow, "HOLD A BUTTON ON YOUR DEVICE TO CONFIGURE IT.", Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER); mGrid.setEntry(mMsg1, Vector2i(0, 2), false, true); - mMsg2 = std::make_shared(mWindow, "PRESS F4 TO QUIT AT ANY TIME.", Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER); + + const char* msg2str = firstRun ? "PRESS F4 TO QUIT AT ANY TIME." : "PRESS ESC TO CANCEL."; + mMsg2 = std::make_shared(mWindow, msg2str, Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER); mGrid.setEntry(mMsg2, Vector2i(0, 3), false, true); // currently held device @@ -75,6 +77,13 @@ void GuiDetectDevice::onSizeChanged() bool GuiDetectDevice::input(InputConfig* config, Input input) { + if(!mFirstRun && input.device == DEVICE_KEYBOARD && input.type == TYPE_KEY && input.value && input.id == SDLK_ESCAPE) + { + // cancel configuring + delete this; + return true; + } + if(input.type == TYPE_BUTTON || input.type == TYPE_KEY) { if(input.value && mHoldingConfig == NULL) diff --git a/src/guis/GuiDetectDevice.h b/src/guis/GuiDetectDevice.h index 71d133692..ebc43b7b5 100644 --- a/src/guis/GuiDetectDevice.h +++ b/src/guis/GuiDetectDevice.h @@ -16,6 +16,7 @@ public: void onSizeChanged() override; private: + bool mFirstRun; InputConfig* mHoldingConfig; int mHoldTime;