From 67ccd0a05577bb33126f1afe88b1053fd43ab931 Mon Sep 17 00:00:00 2001 From: zetaPRIME Date: Wed, 1 Mar 2017 07:06:41 -0500 Subject: [PATCH] bunch of form and UI fixes, modal dialogs! --- libstarlight/source/starlight/Application.cpp | 11 ++- .../source/starlight/InputManager.cpp | 8 +- libstarlight/source/starlight/InputManager.h | 61 ++++++------ .../source/starlight/dialog/MessageBox.cpp | 92 ++++++++++++++++++ .../source/starlight/dialog/MessageBox.h | 31 ++++++ libstarlight/source/starlight/gfx/FontBMF.cpp | 3 + libstarlight/source/starlight/ui/Button.cpp | 4 +- libstarlight/source/starlight/ui/Button.h | 3 +- libstarlight/source/starlight/ui/Form.cpp | 4 +- libstarlight/source/starlight/ui/Form.h | 2 +- .../source/starlight/ui/ScrollField.cpp | 7 +- .../source/starlight/ui/TouchScreenCanvas.cpp | 4 +- libstarlight/todo.txt | 4 +- testbed/source/Core.cpp | 30 +++++- themes/default/decorations/panel.bg.json | 4 + themes/default/decorations/panel.bg.png | Bin 0 -> 509 bytes 16 files changed, 214 insertions(+), 54 deletions(-) create mode 100644 libstarlight/source/starlight/dialog/MessageBox.cpp create mode 100644 libstarlight/source/starlight/dialog/MessageBox.h create mode 100644 themes/default/decorations/panel.bg.json create mode 100644 themes/default/decorations/panel.bg.png diff --git a/libstarlight/source/starlight/Application.cpp b/libstarlight/source/starlight/Application.cpp index c979da1..fe2989f 100644 --- a/libstarlight/source/starlight/Application.cpp +++ b/libstarlight/source/starlight/Application.cpp @@ -81,6 +81,8 @@ void Application::_init() { void Application::_end() { End(); + forms.clear(); // not sure why, but not doing this results in a data abort if any forms are active + RenderCore::Close(); ConfigManager::End(); } @@ -115,8 +117,13 @@ void Application::_mainLoop() { // update step InputManager::Update(); Update(); - for (auto it : forms) { // update loop for forms - it->Update(it == forms.back()); + { // update loop for forms, guarded from snap-outs + auto it = forms.begin(); + while (it != forms.end()) { + auto next = std::next(it); + (*it)->Update(*it == forms.back()); + it = next; + } } touchScreen->Update(); topScreen->Update(); diff --git a/libstarlight/source/starlight/InputManager.cpp b/libstarlight/source/starlight/InputManager.cpp index 1a60aa3..5351134 100644 --- a/libstarlight/source/starlight/InputManager.cpp +++ b/libstarlight/source/starlight/InputManager.cpp @@ -58,11 +58,11 @@ void InputManager::Update() { touchLast = touchNow; hidTouchRead(&tp); - if (Held(KEY_TOUCH)) touchNow = Vector2(tp.px, tp.py); + if (Held(Keys::TOUCH)) touchNow = Vector2(tp.px, tp.py); - if (Pressed(KEY_TOUCH)) touchStart = touchLast = touchNow; + if (Pressed(Keys::TOUCH)) touchStart = touchLast = touchNow; - if (!Held(KEY_TOUCH) && !Released(KEY_TOUCH)) touchTime = 0; + if (!Held(Keys::TOUCH) && !Released(Keys::TOUCH)) touchTime = 0; else touchTime++; } @@ -119,4 +119,4 @@ void DragHandle::Release() { rptr = nullptr; wptr = std::shared_ptr(nullptr); e->OnDragRelease(); -} \ No newline at end of file +} diff --git a/libstarlight/source/starlight/InputManager.h b/libstarlight/source/starlight/InputManager.h index b2bf241..fedac27 100644 --- a/libstarlight/source/starlight/InputManager.h +++ b/libstarlight/source/starlight/InputManager.h @@ -10,38 +10,38 @@ // borrow this from ctrulib #ifndef BIT #define BIT(n) (1U<<(n)) -enum { - KEY_A = BIT(0), ///< A - KEY_B = BIT(1), ///< B - KEY_SELECT = BIT(2), ///< Select - KEY_START = BIT(3), ///< Start - KEY_DRIGHT = BIT(4), ///< D-Pad Right - KEY_DLEFT = BIT(5), ///< D-Pad Left - KEY_DUP = BIT(6), ///< D-Pad Up - KEY_DDOWN = BIT(7), ///< D-Pad Down - KEY_R = BIT(8), ///< R - KEY_L = BIT(9), ///< L - KEY_X = BIT(10), ///< X - KEY_Y = BIT(11), ///< Y - KEY_ZL = BIT(14), ///< ZL (New 3DS only) - KEY_ZR = BIT(15), ///< ZR (New 3DS only) - KEY_TOUCH = BIT(20), ///< Touch (Not actually provided by HID) - KEY_CSTICK_RIGHT = BIT(24), ///< C-Stick Right (New 3DS only) - KEY_CSTICK_LEFT = BIT(25), ///< C-Stick Left (New 3DS only) - KEY_CSTICK_UP = BIT(26), ///< C-Stick Up (New 3DS only) - KEY_CSTICK_DOWN = BIT(27), ///< C-Stick Down (New 3DS only) - KEY_CPAD_RIGHT = BIT(28), ///< Circle Pad Right - KEY_CPAD_LEFT = BIT(29), ///< Circle Pad Left - KEY_CPAD_UP = BIT(30), ///< Circle Pad Up - KEY_CPAD_DOWN = BIT(31), ///< Circle Pad Down +#endif +enum class Keys : unsigned int { + A = BIT(0), ///< A + B = BIT(1), ///< B + SELECT = BIT(2), ///< Select + START = BIT(3), ///< Start + DRIGHT = BIT(4), ///< D-Pad Right + DLEFT = BIT(5), ///< D-Pad Left + DUP = BIT(6), ///< D-Pad Up + DDOWN = BIT(7), ///< D-Pad Down + R = BIT(8), ///< R + L = BIT(9), ///< L + X = BIT(10), ///< X + Y = BIT(11), ///< Y + ZL = BIT(14), ///< ZL (New 3DS only) + ZR = BIT(15), ///< ZR (New 3DS only) + TOUCH = BIT(20), ///< Touch (Not actually provided by HID) + CSTICK_RIGHT = BIT(24), ///< C-Stick Right (New 3DS only) + CSTICK_LEFT = BIT(25), ///< C-Stick Left (New 3DS only) + CSTICK_UP = BIT(26), ///< C-Stick Up (New 3DS only) + CSTICK_DOWN = BIT(27), ///< C-Stick Down (New 3DS only) + CPAD_RIGHT = BIT(28), ///< Circle Pad Right + CPAD_LEFT = BIT(29), ///< Circle Pad Left + CPAD_UP = BIT(30), ///< Circle Pad Up + CPAD_DOWN = BIT(31), ///< Circle Pad Down // Generic catch-all directions - KEY_UP = KEY_DUP | KEY_CPAD_UP, ///< D-Pad Up or Circle Pad Up - KEY_DOWN = KEY_DDOWN | KEY_CPAD_DOWN, ///< D-Pad Down or Circle Pad Down - KEY_LEFT = KEY_DLEFT | KEY_CPAD_LEFT, ///< D-Pad Left or Circle Pad Left - KEY_RIGHT = KEY_DRIGHT | KEY_CPAD_RIGHT, ///< D-Pad Right or Circle Pad Right + UP = DUP | CPAD_UP, ///< D-Pad Up or Circle Pad Up + DOWN = DDOWN | CPAD_DOWN, ///< D-Pad Down or Circle Pad Down + LEFT = DLEFT | CPAD_LEFT, ///< D-Pad Left or Circle Pad Left + RIGHT = DRIGHT | CPAD_RIGHT, ///< D-Pad Right or Circle Pad Right }; -#endif namespace starlight { class InputManager; @@ -87,8 +87,11 @@ namespace starlight { static Vector2 CStick(); static bool Held(unsigned int mask); + static inline bool Held(Keys mask) { return Held(static_cast(mask)); } static bool Pressed(unsigned int mask); + static inline bool Pressed(Keys mask) { return Pressed(static_cast(mask)); } static bool Released(unsigned int mask); + static inline bool Released(Keys mask) { return Released(static_cast(mask)); } static Vector2 TouchPos(); static Vector2 TouchDelta(); diff --git a/libstarlight/source/starlight/dialog/MessageBox.cpp b/libstarlight/source/starlight/dialog/MessageBox.cpp new file mode 100644 index 0000000..e45288f --- /dev/null +++ b/libstarlight/source/starlight/dialog/MessageBox.cpp @@ -0,0 +1,92 @@ +#include "MessageBox.h" + +#include "starlight/InputManager.h" + +#include "starlight/ui/Image.h" +#include "starlight/ui/Button.h" +#include "starlight/ui/Label.h" +#include "starlight/ui/ScrollField.h" + +using starlight::InputManager; + +using starlight::ui::Image; +using starlight::ui::Button; +using starlight::ui::Label; +using starlight::ui::ScrollField; + +using starlight::ui::Form; + +using starlight::dialog::MessageBox; + +MessageBox::MessageBox(Mode m, const std::string& msg, std::function onSelect) : Form(true) { + priority = 10; + eOnSelect = onSelect; + + VRect boxArea = VRect(160, 120, 0, 0).Expand(Vector2(300, 200)*.5); + + auto bg = std::make_shared(boxArea, "decorations/panel.bg"); + touchScreen->Add(bg); + auto scroll = std::make_shared(boxArea.Expand(-8, -8).TopEdge(200-16-8-32)); + touchScreen->Add(scroll); + auto label = std::make_shared