Changes:
Prepare for New Theme API Add Func and Scoped Trace Add A Scrollbar to menus Smooth out scrolling
This commit is contained in:
@ -20,7 +20,9 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define UNPACK_RGBA(col) (uint8_t)(col >> 24), (col >> 16), (col >> 8), (col)
|
||||
#define UNPACK_BGRA(col) (uint8_t)(col >> 8), (col >> 16), (col >> 24), (col)
|
||||
@ -58,23 +60,59 @@ enum RD7Color_ {
|
||||
RD7Color_TextDisabled, /// Text Disabled Color
|
||||
RD7Color_Text2, ///< And This want for Texts on Dark Backgrounds
|
||||
RD7Color_Background, ///< Your Bg Color
|
||||
RD7Color_Header, ///< Header Color (if the header is dark text2 is used)
|
||||
RD7Color_Selector,
|
||||
RD7Color_SelectorFade,
|
||||
RD7Color_List0,
|
||||
RD7Color_List1,
|
||||
RD7Color_MessageBackground,
|
||||
RD7Color_Button,
|
||||
RD7Color_ButtonHovered,
|
||||
RD7Color_ButtonDisabled,
|
||||
RD7Color_ButtonActive,
|
||||
RD7Color_Checkmark,
|
||||
RD7Color_FrameBg,
|
||||
RD7Color_FrameBgHovered,
|
||||
RD7Color_Progressbar,
|
||||
RD7Color_Header, ///< Header Color (if the header is dark text2 is used)
|
||||
RD7Color_Selector, ///< Selector Color
|
||||
RD7Color_SelectorFade, ///< Selector FadingTo Color
|
||||
RD7Color_List0, ///< List Color1
|
||||
RD7Color_List1, ///< List Color2
|
||||
RD7Color_MessageBackground, ///< Message Background
|
||||
RD7Color_Button, ///< Button Color
|
||||
RD7Color_ButtonHovered, ///< Button Color if Hovered
|
||||
RD7Color_ButtonDisabled, ///< Button Color if disabled
|
||||
RD7Color_ButtonActive, ///< Button Colkor if Clicked
|
||||
RD7Color_Checkmark, ///< Checkbox Checkmark Color
|
||||
RD7Color_FrameBg, ///< Frame Background Color
|
||||
RD7Color_FrameBgHovered, ///< Frame Background Color if hovered
|
||||
RD7Color_Progressbar, ///< Progressbar Color
|
||||
/// NON COLOR ///
|
||||
RD7Color_Len, ///< Used to define the lengh of this list
|
||||
};
|
||||
|
||||
namespace RenderD7 {
|
||||
class Theme {
|
||||
public:
|
||||
Theme() = default;
|
||||
~Theme() = default;
|
||||
|
||||
void Load(const std::string &path);
|
||||
void Default();
|
||||
|
||||
unsigned int Get(RD7Color clr);
|
||||
void Set(RD7Color clr, unsigned int v);
|
||||
void Swap(RD7Color a, RD7Color b);
|
||||
bool Undo();
|
||||
void UndoAll();
|
||||
|
||||
// For Smart Pointer
|
||||
using Ref = std::shared_ptr<Theme>;
|
||||
static Ref New() { return std::make_shared<Theme>(); }
|
||||
|
||||
private:
|
||||
struct change {
|
||||
change(RD7Color a, unsigned int f, unsigned int t)
|
||||
: clr(a), from(f), to(t) {}
|
||||
change(RD7Color a, RD7Color b, unsigned int f, unsigned int t)
|
||||
: clr(a), clr2(b), from(f), to(t) {}
|
||||
RD7Color clr;
|
||||
RD7Color clr2 = 0; // Used if Swap
|
||||
unsigned int from;
|
||||
unsigned int to;
|
||||
};
|
||||
// Use a vector for faster access
|
||||
std::vector<unsigned int> clr_tab;
|
||||
std::vector<change> changes;
|
||||
};
|
||||
|
||||
unsigned int StyleColor(RD7Color color);
|
||||
void RedirectColor(RD7Color to, RD7Color from);
|
||||
void TextColorByBg(RD7Color background);
|
||||
@ -88,6 +126,8 @@ void UndoAllColorEdits();
|
||||
void ThemeLoad(const std::string &path);
|
||||
void ThemeSave(const std::string &path);
|
||||
void ThemeDefault();
|
||||
Theme::Ref ThemeActive();
|
||||
void ThemeSet(Theme::Ref theme);
|
||||
namespace Color {
|
||||
/// @brief RGBA Class
|
||||
class RGBA {
|
||||
|
@ -18,8 +18,10 @@
|
||||
|
||||
#pragma once
|
||||
// Base includes
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
// 3ds does not support std::chrono
|
||||
#include <3ds.h>
|
||||
|
||||
@ -39,6 +41,7 @@ struct FTRes {
|
||||
uint64_t time_start; ///< when started
|
||||
uint64_t time_end; ///< when stopped
|
||||
float time_of; ///< stop - start (how long)
|
||||
float time_ofm; ///< max time off
|
||||
bool is_ovl; ///< is displayed in overlay?
|
||||
};
|
||||
|
||||
@ -48,21 +51,44 @@ extern std::map<std::string, RenderD7::Ftrace::FTRes> rd7_traces;
|
||||
/// @brief Set a Start TracePoint
|
||||
/// @param group Set a Group Name
|
||||
/// @param func_name Set a Function Name
|
||||
inline void Beg(std::string group, std::string func_name) {
|
||||
inline void Beg(const std::string& group, const std::string& func_name) {
|
||||
std::string trace_id = scomb(group, func_name);
|
||||
rd7_traces[trace_id].group = group;
|
||||
rd7_traces[trace_id].func_name = func_name;
|
||||
rd7_traces[trace_id].time_start = svcGetSystemTick();
|
||||
auto& trace = rd7_traces[trace_id];
|
||||
trace.group = group;
|
||||
trace.func_name = func_name;
|
||||
trace.time_start = svcGetSystemTick();
|
||||
}
|
||||
/// @brief Set an End TracePoint
|
||||
/// @param group Set a Group Name
|
||||
/// @param func_name Set a Function Name
|
||||
inline void End(std::string group, std::string func_name) {
|
||||
inline void End(const std::string& group, const std::string& func_name) {
|
||||
std::string trace_id = scomb(group, func_name);
|
||||
rd7_traces[trace_id].time_end = svcGetSystemTick();
|
||||
rd7_traces[trace_id].time_of = static_cast<float>(
|
||||
((float)rd7_traces[trace_id].time_end / (float)TICKS_PER_MSEC) -
|
||||
((float)rd7_traces[trace_id].time_start / (float)TICKS_PER_MSEC));
|
||||
auto& trace = rd7_traces[trace_id];
|
||||
trace.time_end = svcGetSystemTick();
|
||||
if (trace.time_of > trace.time_ofm) trace.time_ofm = trace.time_of;
|
||||
trace.time_of =
|
||||
static_cast<float>(trace.time_end - trace.time_start) / TICKS_PER_MSEC;
|
||||
}
|
||||
/// @brief Trace a function execution
|
||||
/// @param group Set a Group Name
|
||||
/// @param name Set a Function Name
|
||||
inline void Func(const std::string& group, const std::string& name,
|
||||
std::function<void()> fun) {
|
||||
if (!fun) return;
|
||||
Beg(group, name);
|
||||
fun();
|
||||
End(group, name);
|
||||
}
|
||||
|
||||
/// @brief This Starts an Ftrace and
|
||||
/// end ist when going out of scope
|
||||
struct ScopedTrace {
|
||||
ScopedTrace(std::string g, std::string n) : group(g), name(n) {
|
||||
Ftrace::Beg(g, n);
|
||||
}
|
||||
~ScopedTrace() { Ftrace::End(group, name); }
|
||||
std::string group;
|
||||
std::string name;
|
||||
};
|
||||
} // namespace Ftrace
|
||||
} // namespace RenderD7
|
||||
|
16
include/renderd7/ThemeEditor.hpp
Normal file
16
include/renderd7/ThemeEditor.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <renderd7/renderd7.hpp>
|
||||
|
||||
namespace RenderD7 {
|
||||
class ThemeEditor : public RenderD7::Scene {
|
||||
public:
|
||||
ThemeEditor() = default;
|
||||
~ThemeEditor() = default;
|
||||
|
||||
void Draw() const override;
|
||||
void Logic() override;
|
||||
|
||||
private:
|
||||
};
|
||||
} // namespace RenderD7
|
Reference in New Issue
Block a user