From 77fcfd0f2058c1acc91c7a68598df259f6628e2f Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Tue, 13 Aug 2013 00:06:23 +0200 Subject: [PATCH] More UI tweaks --- ui/ui_screen.cpp | 8 ++++++++ ui/ui_screen.h | 6 ++++++ ui/view.cpp | 3 +++ ui/viewgroup.cpp | 11 ++++++++++- ui/viewgroup.h | 2 ++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ui/ui_screen.cpp b/ui/ui_screen.cpp index c7872831d0..9535221eca 100644 --- a/ui/ui_screen.cpp +++ b/ui/ui_screen.cpp @@ -59,6 +59,14 @@ void UIScreen::key(const KeyInput &key) { } } +void DialogScreen::key(const KeyInput &key) { + if ((key.flags & KEY_DOWN) && key.keyCode == NKCODE_ESCAPE || key.keyCode == NKCODE_BACK || key.keyCode == NKCODE_BUTTON_B) { + screenManager()->finishDialog(this, DR_CANCEL); + } else { + UIScreen::key(key); + } +} + void UIScreen::axis(const AxisInput &axis) { // Simple translation of hat to keys for Shield and other modern pads. // TODO: Use some variant of keymap? diff --git a/ui/ui_screen.h b/ui/ui_screen.h index de889883c6..430ffca612 100644 --- a/ui/ui_screen.h +++ b/ui/ui_screen.h @@ -32,6 +32,12 @@ private: int hatDown_; }; +class DialogScreen : public UIScreen { +public: + virtual void key(const KeyInput &key); +}; + + class PopupScreen : public UIScreen { public: PopupScreen(const std::string &title); diff --git a/ui/view.cpp b/ui/view.cpp index 268dde3e9b..b0e5a32cd2 100644 --- a/ui/view.cpp +++ b/ui/view.cpp @@ -207,7 +207,10 @@ void Clickable::Key(const KeyInput &key) { if (IsAcceptKeyCode(key.keyCode)) { if (down_) { Click(); + down_ = false; } + } else if (IsEscapeKeyCode(key.keyCode)) { + down_ = false; } } } diff --git a/ui/viewgroup.cpp b/ui/viewgroup.cpp index 929363723d..941abc69f3 100644 --- a/ui/viewgroup.cpp +++ b/ui/viewgroup.cpp @@ -781,6 +781,16 @@ void ChoiceStrip::SetSelection(int sel) { static_cast(views_[selected_])->Press(); } +void ChoiceStrip::Key(const KeyInput &input) { + if (input.flags & KEY_DOWN) { + if (input.keyCode == NKCODE_BUTTON_L1 && selected_ > 0) { + SetSelection(selected_ - 1); + } else if (input.keyCode == NKCODE_BUTTON_R1 && selected_ < views_.size() - 1) { + SetSelection(selected_ + 1); + } + } +} + ListView::ListView(ListAdaptor *a, LayoutParams *layoutParams) : ScrollView(ORIENT_VERTICAL, layoutParams), adaptor_(a) { linLayout_ = new LinearLayout(ORIENT_VERTICAL); @@ -858,7 +868,6 @@ static std::vector focusMoves; void KeyEvent(const KeyInput &key, ViewGroup *root) { if (key.flags & KEY_DOWN) { - ILOG("ke: %i %02x", key.deviceId, key.keyCode); // We ignore the device ID here. Anything with a DPAD is OK. if (key.keyCode >= NKCODE_DPAD_UP && key.keyCode <= NKCODE_DPAD_RIGHT) { lock_guard lock(focusLock); diff --git a/ui/viewgroup.h b/ui/viewgroup.h index 78dc2a82ec..f4feab42fb 100644 --- a/ui/viewgroup.h +++ b/ui/viewgroup.h @@ -225,6 +225,8 @@ public: void AddChoice(const std::string &title); int GetSelection() const { return selected_; } void SetSelection(int sel); + virtual void Key(const KeyInput &input); + Event OnChoice; private: