diff --git a/include/rd7.hpp b/include/rd7.hpp index edc5898..1d072fc 100644 --- a/include/rd7.hpp +++ b/include/rd7.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/include/renderd7/Allocator.hpp b/include/renderd7/Allocator.hpp index f32e6d4..b6bf5e9 100644 --- a/include/renderd7/Allocator.hpp +++ b/include/renderd7/Allocator.hpp @@ -1,41 +1,40 @@ #pragma once -#include #include <3ds.h> +#include #include // Write own LinearAllocator for learning namespace RenderD7 { - template - class LinearAllocator : public std::allocator { - public: - typedef size_t size_type; - typedef T* pointer; - typedef const T* const_pointer; +template +class LinearAllocator : public std::allocator { + public: + typedef size_t size_type; + typedef T* pointer; + typedef const T* const_pointer; - template - struct rebind {typedef LinearAllocator other;}; + template + struct rebind { + typedef LinearAllocator other; + }; - pointer allocate(size_type n, const void* hint=nullptr) { - if(n > this->max_size()) { - RenderD7::Error("Linear Allocator: \nBad Alloc -> size is larger than free space!"); - return nullptr; - } - return (pointer)linearAlloc(n*sizeof(T)); - } + pointer allocate(size_type n, const void* hint = nullptr) { + if (n > this->max_size()) { + RenderD7::Error( + "Linear Allocator: \nBad Alloc -> size is larger than free space!"); + return nullptr; + } + return (pointer)linearAlloc(n * sizeof(T)); + } - void deallocate(pointer p, size_type) { - linearFree((void*)p); - } + void deallocate(pointer p, size_type) { linearFree((void*)p); } - size_type max_size() { - return linearSpaceFree(); - } + size_type max_size() { return linearSpaceFree(); } - LinearAllocator() throw() {} - LinearAllocator(const LinearAllocator& a) throw(): std::allocator(a) {} - ~LinearAllocator() throw() {} - }; -} \ No newline at end of file + LinearAllocator() throw() {} + LinearAllocator(const LinearAllocator& a) throw() : std::allocator(a) {} + ~LinearAllocator() throw() {} +}; +} // namespace RenderD7 \ No newline at end of file diff --git a/include/renderd7/Overlays.hpp b/include/renderd7/Overlays.hpp index e9601ba..eef74db 100644 --- a/include/renderd7/Overlays.hpp +++ b/include/renderd7/Overlays.hpp @@ -3,6 +3,20 @@ #include #include +typedef int RD7Keyboard; + +enum RD7Keyboard_ { + RD7Keyboard_Default, + RD7Keyboard_Numpad, + RD7Keyboard_Password, +}; + +enum RD7KeyboardState { + RD7KeyboardState_None = 0, + RD7KeyboardState_Cancel = 1, + RD7KeyboardState_Confirm = 2, +}; + namespace RenderD7 { class Ovl_Ftrace : public RenderD7::Ovl { public: @@ -44,20 +58,12 @@ class Ovl_Metrik : public RenderD7::Ovl { float* i_txt_size; }; -typedef int RD7Keyboard; - -enum RD7Keyboard_ { - RD7Keyboard_Default, - RD7Keyboard_Numpad, - RD7Keyboard_Password, -}; - class Ovl_Keyboard : public RenderD7::Ovl { public: /// @brief Constructor /// Keyboard Type not Supported for now - Ovl_Keyboard(std::string& ref, const std::string& hint = "", - RD7Keyboard type = 0); + Ovl_Keyboard(std::string& ref, RD7KeyboardState& state, + const std::string& hint = "", RD7Keyboard type = 0); /// @brief Deconstructor ~Ovl_Keyboard(); /// @brief Override for Draw @@ -70,6 +76,7 @@ class Ovl_Keyboard : public RenderD7::Ovl { // Pointer to useres String std::string* typed_text = nullptr; std::string str_bak; + RD7KeyboardState* state; int mode = 0; int ft3 = 0; }; diff --git a/include/renderd7/UI7.hpp b/include/renderd7/UI7.hpp index 4c59a3c..956e702 100644 --- a/include/renderd7/UI7.hpp +++ b/include/renderd7/UI7.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include diff --git a/include/renderd7/renderd7.hpp b/include/renderd7/renderd7.hpp index 3ddc0ef..49a2ea1 100644 --- a/include/renderd7/renderd7.hpp +++ b/include/renderd7/renderd7.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -112,6 +113,7 @@ class RSettings : public RenderD7::Scene { /// @param mtscreenstate Screen the Overlay is Set to std::string mtscreenstate = "Top"; std::string kbd_test; + RD7KeyboardState kbd_state; bool statemtold = false; bool stateftold = false; float tmp_txt; diff --git a/source/Overlays.cpp b/source/Overlays.cpp index d3c7525..fa5efcf 100644 --- a/source/Overlays.cpp +++ b/source/Overlays.cpp @@ -247,8 +247,9 @@ void Ovl_Ftrace::Draw(void) const { float tmp_txt = RenderD7::TextGetSize(); RenderD7::TextDefaultSize(); RenderD7::OnScreen(Top); - RenderD7::Draw2::RFS(R7Vec2(0, 0), R7Vec2(400, 20), - RenderD7::StyleColor(RD7Color_Background)); + RenderD7::Color::RGBA bg(RD7Color_Background); + bg.changeA(150); + RenderD7::Draw2::RFS(R7Vec2(0, 0), R7Vec2(400, 20), bg.toRGBA()); std::vector dt; for (auto const& it : RenderD7::Ftrace::rd7_traces) @@ -344,12 +345,14 @@ void Ovl_Metrik::Logic() { if (!i_is_enabled[0]) this->Kill(); } -Ovl_Keyboard::Ovl_Keyboard(std::string& ref, const std::string& hint, - RD7Keyboard type) { +Ovl_Keyboard::Ovl_Keyboard(std::string& ref, RD7KeyboardState& state, + const std::string& hint, RD7Keyboard type) { // Blocks All Input outside of Keyboard // Doesnt work for Hidkeys down etc RenderD7::Hid::Lock(); typed_text = &ref; + this->state = &state; + *this->state = RD7KeyboardState_None; str_bak = ref; ft3 = 0; } @@ -439,8 +442,10 @@ void Ovl_Keyboard::Logic() { // Enter } else if (it.first == 0x05) { *typed_text = str_bak; + *state = RD7KeyboardState_Cancel; this->Kill(); } else if (it.first == 0x06) { + *state = RD7KeyboardState_Confirm; this->Kill(); } else if (it.first == 0x07) { // this->typed_text += '\t'; // Tab diff --git a/source/UI7.cpp b/source/UI7.cpp index 815bc59..2311b8c 100644 --- a/source/UI7.cpp +++ b/source/UI7.cpp @@ -421,6 +421,7 @@ void InputText(const std::string &label, std::string &text, R7Vec2 inp = cbs + R7Vec2(txtdim.x + 5, 0); RD7Color bg = RD7Color_FrameBg; auto id = UI7CtxNewID(label); + RD7KeyboardState kbd_state; // tmp (goes out of scope) R7Vec2 pos = GetCursorPos(); @@ -429,7 +430,8 @@ void InputText(const std::string &label, std::string &text, if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Up) && InBox(RenderD7::Hid::GetLastTouchPosition(), pos, inp)) { bg = RD7Color_FrameBgHovered; - RenderD7::AddOvl(std::make_unique(text, hint)); + RenderD7::AddOvl( + std::make_unique(text, kbd_state, hint)); } else if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Held) && InBox(RenderD7::Hid::GetTouchPosition(), pos, inp)) { bg = RD7Color_FrameBgHovered; diff --git a/source/lang.cpp b/source/lang.cpp index 01e1a84..882dc4e 100644 --- a/source/lang.cpp +++ b/source/lang.cpp @@ -65,7 +65,7 @@ std::string RenderD7::Lang::GetSys() { } } std::string RenderD7::Lang::Get(const std::string &key) { - if(!appJson.contains("keys")) return "ERR-01"; + if (!appJson.contains("keys")) return "ERR-01"; nlohmann::json js = appJson["keys"]; if (!js.contains(key)) return key; return js.at(key).get(); diff --git a/source/renderd7.cpp b/source/renderd7.cpp index 2788008..c132643 100644 --- a/source/renderd7.cpp +++ b/source/renderd7.cpp @@ -599,10 +599,10 @@ void RenderD7::RSettings::Draw(void) const { // List Bg for (int i = 0; i < 12; i++) { if ((i % 2 == 0)) - RenderD7::Draw2::RFS(R7Vec2(0, 40 + (i) * 15), R7Vec2(400, 15), + RenderD7::Draw2::RFS(R7Vec2(0, 40 + (i)*15), R7Vec2(400, 15), RenderD7::StyleColor(RD7Color_List0)); else - RenderD7::Draw2::RFS(R7Vec2(0, 40 + (i) * 15), R7Vec2(400, 15), + RenderD7::Draw2::RFS(R7Vec2(0, 40 + (i)*15), R7Vec2(400, 15), RenderD7::StyleColor(RD7Color_List1)); } @@ -731,7 +731,8 @@ void RenderD7::RSettings::Logic() { return; } } else if (it.first == 0x00000003) { - if (it.second) RenderD7::AddOvl(std::make_unique(kbd_test)); + if (it.second) + RenderD7::AddOvl(std::make_unique(kbd_test, kbd_state)); } } /// Clear if handled