Fix some Format stuff

This commit is contained in:
tobid7 2024-05-03 15:51:06 +02:00
parent 6f658af674
commit 19450ba2c9
9 changed files with 64 additions and 46 deletions

View File

@ -7,6 +7,7 @@
#include <renderd7/Hid.hpp>
#include <renderd7/Image.hpp>
#include <renderd7/Message.hpp>
#include <renderd7/Overlays.hpp>
#include <renderd7/StealConsole.hpp>
#include <renderd7/Timer.hpp>
#include <renderd7/UI7.hpp>

View File

@ -1,41 +1,40 @@
#pragma once
#include <memory>
#include <3ds.h>
#include <memory>
#include <renderd7/Error.hpp>
// Write own LinearAllocator for learning
namespace RenderD7 {
template<typename T>
class LinearAllocator : public std::allocator<T> {
public:
typedef size_t size_type;
typedef T* pointer;
typedef const T* const_pointer;
template <typename T>
class LinearAllocator : public std::allocator<T> {
public:
typedef size_t size_type;
typedef T* pointer;
typedef const T* const_pointer;
template<typename T1>
struct rebind {typedef LinearAllocator<T1> other;};
template <typename T1>
struct rebind {
typedef LinearAllocator<T1> 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<T>& a) throw(): std::allocator<T>(a) {}
~LinearAllocator() throw() {}
};
}
LinearAllocator() throw() {}
LinearAllocator(const LinearAllocator<T>& a) throw() : std::allocator<T>(a) {}
~LinearAllocator() throw() {}
};
} // namespace RenderD7

View File

@ -3,6 +3,20 @@
#include <renderd7/Ovl.hpp>
#include <string>
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;
};

View File

@ -1,6 +1,7 @@
#pragma once
#include <algorithm>
#include <functional>
#include <renderd7/DrawV2.hpp>
#include <renderd7/R7Vec.hpp>
#include <string>

View File

@ -28,6 +28,7 @@
#include <renderd7/FunctionTrace.hpp>
#include <renderd7/Hardware.hpp>
#include <renderd7/Memory.hpp>
#include <renderd7/Overlays.hpp>
#include <renderd7/Ovl.hpp>
#include <renderd7/ResultDecoder.hpp>
#include <renderd7/Screen.hpp>
@ -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;

View File

@ -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<RenderD7::Ftrace::FTRes> 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

View File

@ -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<RenderD7::Ovl_Keyboard>(text, hint));
RenderD7::AddOvl(
std::make_unique<RenderD7::Ovl_Keyboard>(text, kbd_state, hint));
} else if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Held) &&
InBox(RenderD7::Hid::GetTouchPosition(), pos, inp)) {
bg = RD7Color_FrameBgHovered;

View File

@ -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<std::string>();

View File

@ -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<Ovl_Keyboard>(kbd_test));
if (it.second)
RenderD7::AddOvl(std::make_unique<Ovl_Keyboard>(kbd_test, kbd_state));
}
}
/// Clear if handled