Add SMART_CTOR
Begin with Render2 (Draw2 replacement)
Add UI7 DrawLists
This commit is contained in:
tobid7 2024-06-08 16:30:01 +02:00
parent f399f032e7
commit 07ed5af300
8 changed files with 398 additions and 233 deletions

View File

@ -21,6 +21,7 @@
#include <cstring>
#include <memory>
#include <renderd7/smart_ctor.hpp>
#include <string>
#include <vector>
@ -28,9 +29,7 @@
#define UNPACK_BGRA(col) (uint8_t)(col >> 8), (col >> 16), (col >> 24), (col)
inline uint32_t RGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) {
#define ISIMPLEPAK(x, y) (((x)&0xff) << y)
return (ISIMPLEPAK(r, 0) | ISIMPLEPAK(g, 8) | ISIMPLEPAK(b, 16) |
ISIMPLEPAK(a, 24));
return (r | g << 8 | b << 16 | a << 24);
}
typedef int RD7Color;
@ -98,8 +97,7 @@ class Theme {
std::vector<unsigned int> &GetTableRef() { return clr_tab; }
// For Smart Pointer
using Ref = std::shared_ptr<Theme>;
static Ref New() { return std::make_shared<Theme>(); }
RD7_SMART_CTOR(Theme);
// Loader method
void CopyOther(Theme::Ref theme);
@ -188,7 +186,7 @@ class RGBA {
/// @brief Get as Uint32
/// @return color
uint32_t toRGBA() const { return RGBA8(m_r, m_g, m_b, m_a); }
unsigned int toRGBA() const { return RGBA8(m_r, m_g, m_b, m_a); }
// Just calculate the "lightness" f.e. to use Text or Text2
float luminance() const {
@ -202,7 +200,7 @@ class RGBA {
return (luminance() >= 0.5);
}
uint8_t m_r, m_g, m_b, m_a;
uint8_t m_r = 0, m_g = 0, m_b = 0, m_a = 0;
};
std::string RGBA2Hex(unsigned int c32);
/// @brief Convert RGB to Hex

View File

@ -0,0 +1,44 @@
/**
* This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <map>
#include <renderd7/Color.hpp>
#include <renderd7/Font.hpp>
#include <renderd7/R7Vec.hpp>
#include <renderd7/smart_ctor.hpp>
namespace RenderD7 {
class R2Base {
public:
R2Base();
~R2Base() = default;
void SetFont();
Font::Ref GetFont();
void DefaultFont();
private:
const float default_text_size = 0.5f;
float text_size = 0.5;
Font::Ref font[2];
R7Vec2 max_wh;
std::map<std::string, float> ts;
std::map<std::string, int> mln;
};
} // namespace RenderD7

View File

@ -20,6 +20,7 @@
#include <renderd7/DrawV2.hpp>
#include <renderd7/R7Vec.hpp>
#include <renderd7/smart_ctor.hpp>
// UI7: The new RenderD7 UI Standart based on
// Draw2 (based on Citro2D)
@ -35,6 +36,32 @@ enum UI7MenuFlags_ {
UI7MenuFlags_Scrolling = MAKEFLAG(2),
};
class DrawCmd;
class UI7DrawList {
public:
UI7DrawList() = default;
~UI7DrawList() = default;
void AddRectangle(R7Vec2 pos, R7Vec2 szs, RD7Color clr);
void AddRectangle(R7Vec2 pos, R7Vec2 szs, unsigned int clr);
void AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, RD7Color clr);
void AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, unsigned int clr);
void AddText(R7Vec2 pos, const std::string &text, RD7Color clr,
RD7TextFlags flags = 0, R7Vec2 box = R7Vec2());
void AddText(R7Vec2 pos, const std::string &text, unsigned int clr,
RD7TextFlags flags = 0, R7Vec2 box = R7Vec2());
void AddCall(std::shared_ptr<DrawCmd> cmd);
void Process(bool auto_clear = true);
void Clear();
RD7_SMART_CTOR(UI7DrawList)
private:
void AddDebugCall(std::shared_ptr<DrawCmd> cmd);
std::vector<std::shared_ptr<DrawCmd>> list;
};
namespace UI7 {
// Key functions
void Init();
@ -73,4 +100,7 @@ void SetCursorPos(R7Vec2 cp);
void RestoreCursor();
void SameLine();
float GetScrollingOffset();
// DrawLists
UI7DrawList::Ref GetForegroundList();
UI7DrawList::Ref GetBackgroundList();
} // namespace UI7

View File

@ -23,6 +23,7 @@
#include <fstream>
#include <memory>
#include <renderd7/Error.hpp>
#include <renderd7/smart_ctor.hpp>
namespace RenderD7 {
class Font {
@ -30,11 +31,8 @@ class Font {
Font() = default;
Font(const std::string& path) { Load(path); };
~Font() { Unload(); }
using Ref = std::shared_ptr<Font>;
template <typename... args>
inline static Ref New(args&&... a) {
return std::make_shared<Font>(std::forward<args>(a)...);
}
RD7_SMART_CTOR(Font)
void Load(const std::string& path) {
std::ifstream ft(path, std::ios::in | std::ios::binary);
bool io = ft.is_open();

View File

@ -0,0 +1,28 @@
/**
* This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory>
#define RD7_SMART_CTOR(type) \
using Ref = std::shared_ptr<type>; \
template <typename... args> \
static Ref New(args&&... cargs) { \
return std::make_shared<type>(std::forward<args>(cargs)...); \
}

7
source/Render2.cpp Normal file
View File

@ -0,0 +1,7 @@
#include <renderd7/Render2.hpp>
namespace RenderD7 {
R2Base::R2Base() {
for (int i = 0; i < 2; i++) this->font[i] = Font::New();
}
} // namespace RenderD7

View File

@ -94,81 +94,29 @@ enum DrawCmdType_ {
DrawCmdType_Debug,
};
struct DrawCmd;
void UI7CtxPushDebugCmd(std::shared_ptr<DrawCmd> ref);
struct DrawCmd {
DrawCmd(R7Vec4 r, RD7Color c) : rect(r), clr(c), type(DrawCmdType_Rect) {}
DrawCmd(R7Vec4 r, unsigned int c)
: rect(r), ovr_clr(c), type(DrawCmdType_Rect) {
clr = -1;
}
DrawCmd(R7Vec4 r, R7Vec2 a, RD7Color c)
: rect(r), add_coords(a), clr(c), type(DrawCmdType_Triangle) {}
DrawCmd(R7Vec4 r, R7Vec2 a, unsigned int c)
: rect(r), add_coords(a), ovr_clr(c), type(DrawCmdType_Triangle) {
clr = -1;
}
DrawCmd(R7Vec2 p, const std::string &t, RD7Color c, RD7TextFlags f = 0)
: rect(p, R7Vec2()),
text(t),
clr(c),
text_flags(f),
type(DrawCmdType_Text) {}
DrawCmd(R7Vec2 p, const std::string &t, unsigned int c, RD7TextFlags f = 0)
: rect(p, R7Vec2()),
text(t),
ovr_clr(c),
text_flags(f),
type(DrawCmdType_Text) {
clr = -1;
}
class DrawCmd {
public:
// Empty Command
DrawCmd() {}
// For Debug API
DrawCmd(DrawCmd &thiz) {
auto cmd = DrawCmd::New();
cmd->add_coords = thiz.add_coords;
cmd->clr = thiz.clr;
cmd->ovr_clr = thiz.ovr_clr;
cmd->rect = thiz.rect;
cmd->stype = thiz.type;
cmd->text = thiz.text;
cmd->text_box = thiz.text_box;
cmd->text_flags = thiz.text_flags;
cmd->type = DrawCmdType_Debug;
cmd->screen = rd7i_current_screen;
UI7CtxPushDebugCmd(cmd);
}
R7Vec4 rect; // Position / Size
R7Vec2 add_coords; // Additional Coords
RD7Color clr; // Color
std::string text; // Text
DrawCmdType type; // DrawCmd Type
DrawCmdType stype; // Second Type
unsigned int ovr_clr; // Override Color (if not clr)
RD7TextFlags text_flags; // Flags for Text Rendering
R7Vec2 text_box; // Maximum text Box
bool screen;
// Process the Command
void Process() {
DrawCmd(*this);
if (type == DrawCmdType_Skip) {
return;
}
auto color = (clr == -1 ? ovr_clr : RenderD7::ThemeActive()->Get(clr));
RenderD7::OnScreen(screen ? Top : Bottom);
if (type == DrawCmdType_Rect) {
RenderD7::Draw2::RFS(R7Vec2(rect.x, rect.y), R7Vec2(rect.z, rect.w),
color);
RenderD7::Draw2::RFS(R7Vec2(rect.x, rect.y), R7Vec2(rect.z, rect.w), clr);
} else if (type == DrawCmdType_Triangle) {
RenderD7::Draw2::TriangleSolid(R7Vec2(rect.x, rect.y),
R7Vec2(rect.z, rect.w), add_coords, color);
R7Vec2(rect.z, rect.w), add_coords, clr);
} else if (type == DrawCmdType_Text) {
if (text_box.x || text_box.y) {
RenderD7::TextMaxBox(text_box);
}
RenderD7::Draw2::TextClr(R7Vec2(rect.x, rect.y), text, color, text_flags);
RenderD7::Draw2::TextClr(R7Vec2(rect.x, rect.y), text, clr, text_flags);
if (text_box.x || text_box.y) {
RenderD7::TextDefaultBox();
}
@ -188,6 +136,10 @@ struct DrawCmd {
R7Vec2(rect.x + rect.z, rect.y),
R7Vec2(rect.x, rect.y + rect.w),
0xff0000ff);
} else if (stype == DrawCmdType_Triangle) {
RenderD7::Draw2::TriangleLined(R7Vec2(rect.x, rect.y),
R7Vec2(rect.z, rect.w), add_coords,
0xff00ff00);
} else if (stype == DrawCmdType_Text) {
auto szs = RenderD7::GetTextDimensions(text);
if (text_flags & RD7TextFlags_AlignRight) {
@ -202,14 +154,132 @@ struct DrawCmd {
0xff00ffff);
}
}
// For Smart Pointer
using Ref = std::shared_ptr<DrawCmd>;
template <typename... args>
static Ref New(args &&...cargs) {
return std::make_shared<DrawCmd>(std::forward<args>(cargs)...);
}
RD7_SMART_CTOR(DrawCmd)
R7Vec4 rect = R7Vec4(); // Position / Size
R7Vec2 add_coords = R7Vec2(); // Additional Coords
unsigned int clr = 0; // Color
std::string text = ""; // Text
DrawCmdType type = DrawCmdType_Skip; // DrawCmd Type
DrawCmdType stype = DrawCmdType_Skip; // Second Type
RD7TextFlags text_flags = 0; // Flags for Text Rendering
R7Vec2 text_box = R7Vec2(); // Maximum text Box
bool screen = false; // Defines Top or Bottom
};
void UI7DrawList::AddRectangle(R7Vec2 pos, R7Vec2 szs, RD7Color clr) {
auto cmd = DrawCmd::New();
cmd->screen = rd7i_current_screen;
cmd->rect.x = pos.x;
cmd->rect.y = pos.y;
cmd->rect.z = szs.x;
cmd->rect.w = szs.y;
cmd->clr = RenderD7::ThemeActive()->Get(clr);
cmd->type = DrawCmdType_Rect;
AddDebugCall(cmd);
AddCall(cmd);
}
void UI7DrawList::AddRectangle(R7Vec2 pos, R7Vec2 szs, unsigned int clr) {
auto cmd = DrawCmd::New();
cmd->screen = rd7i_current_screen;
cmd->rect.x = pos.x;
cmd->rect.y = pos.y;
cmd->rect.z = szs.x;
cmd->rect.w = szs.y;
cmd->clr = clr;
cmd->type = DrawCmdType_Rect;
AddDebugCall(cmd);
AddCall(cmd);
}
void UI7DrawList::AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2,
RD7Color clr) {
auto cmd = DrawCmd::New();
cmd->screen = rd7i_current_screen;
cmd->rect.x = pos0.x;
cmd->rect.y = pos0.y;
cmd->rect.z = pos1.x;
cmd->rect.w = pos1.y;
cmd->add_coords = pos2;
cmd->clr = RenderD7::ThemeActive()->Get(clr);
cmd->type = DrawCmdType_Triangle;
AddDebugCall(cmd);
AddCall(cmd);
}
void UI7DrawList::AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2,
unsigned int clr) {
auto cmd = DrawCmd::New();
cmd->screen = rd7i_current_screen;
cmd->rect.x = pos0.x;
cmd->rect.y = pos0.y;
cmd->rect.z = pos1.x;
cmd->rect.w = pos1.y;
cmd->add_coords = pos2;
cmd->clr = clr;
cmd->type = DrawCmdType_Triangle;
AddDebugCall(cmd);
AddCall(cmd);
}
void UI7DrawList::AddText(R7Vec2 pos, const std::string &text, RD7Color clr,
RD7TextFlags flags, R7Vec2 box) {
auto cmd = DrawCmd::New();
cmd->screen = rd7i_current_screen;
cmd->rect.x = pos.x;
cmd->rect.y = pos.y;
cmd->text = text;
cmd->clr = RenderD7::ThemeActive()->Get(clr);
cmd->text_flags = flags;
cmd->text_box = box;
cmd->type = DrawCmdType_Text;
AddDebugCall(cmd);
AddCall(cmd);
}
void UI7DrawList::AddText(R7Vec2 pos, const std::string &text, unsigned int clr,
RD7TextFlags flags, R7Vec2 box) {
auto cmd = DrawCmd::New();
cmd->screen = rd7i_current_screen;
cmd->rect.x = pos.x;
cmd->rect.y = pos.y;
cmd->text = text;
cmd->text_flags = flags;
cmd->text_box = box;
cmd->clr = clr;
cmd->type = DrawCmdType_Text;
AddDebugCall(cmd);
AddCall(cmd);
}
void UI7DrawList::AddCall(std::shared_ptr<DrawCmd> cmd) {
this->list.push_back(cmd);
}
void UI7DrawList::Process(bool auto_clear) {
for (auto it : this->list) {
it->Process();
}
if (auto_clear) this->Clear();
}
void UI7DrawList::Clear() { this->list.clear(); }
void UI7DrawList::AddDebugCall(std::shared_ptr<DrawCmd> cmd) {
auto dcmd = DrawCmd::New();
dcmd->add_coords = cmd->add_coords;
dcmd->clr = cmd->clr;
dcmd->rect = cmd->rect;
dcmd->stype = cmd->type;
dcmd->text = cmd->text;
dcmd->text_box = cmd->text_box;
dcmd->text_flags = cmd->text_flags;
dcmd->type = DrawCmdType_Debug;
dcmd->screen = rd7i_current_screen;
UI7CtxPushDebugCmd(dcmd);
}
struct UI7Menu {
UI7Menu() {}
UI7ID menuid; // menu ID
@ -227,16 +297,15 @@ struct UI7Menu {
std::string submenu;
// DrawLists
std::vector<DrawCmd::Ref> background;
std::vector<DrawCmd::Ref> main;
std::vector<DrawCmd::Ref> front;
UI7DrawList::Ref background;
UI7DrawList::Ref main;
UI7DrawList::Ref front;
R7Vec2 ms; // Max Size
R7Vec2 msr; // Max Size Real (Slider)
R7Vec2 mdp; // Mouse/Touch Initial pos
// For Smart Pointer
using Ref = std::shared_ptr<UI7Menu>;
static Ref New() { return std::make_shared<UI7Menu>(); }
RD7_SMART_CTOR(UI7Menu)
};
struct UI7_Ctx {
@ -255,14 +324,19 @@ struct UI7_Ctx {
bool in_menu;
bool debugging;
std::map<std::string, UI7Menu::Ref> menus;
std::vector<DrawCmd::Ref> debug_calls;
std::vector<UI7Menu::Ref> active_menus;
UI7DrawList::Ref debug_calls;
UI7DrawList::Ref bdl;
UI7DrawList::Ref fdl;
UI7Menu::Ref cm;
RD7_SMART_CTOR(UI7_Ctx)
};
UI7_Ctx *ui7_ctx;
UI7_Ctx::Ref ui7_ctx;
void UI7CtxPushDebugCmd(DrawCmd::Ref ref) {
ui7_ctx->debug_calls.push_back(ref);
if (ui7_ctx->debugging) ui7_ctx->debug_calls->AddCall(ref);
}
bool UI7CtxValidate() {
@ -285,6 +359,9 @@ bool UI7CtxBeginMenu(const std::string &lb) {
ui7_ctx->cm->menuid = id;
ui7_ctx->cm->cursor = R7Vec2(0, 0);
ui7_ctx->cm->has_touch = !rd7i_current_screen;
if (!ui7_ctx->cm->background) ui7_ctx->cm->background = UI7DrawList::New();
if (!ui7_ctx->cm->main) ui7_ctx->cm->main = UI7DrawList::New();
if (!ui7_ctx->cm->front) ui7_ctx->cm->front = UI7DrawList::New();
ui7_ctx->in_menu = true;
return true;
}
@ -311,20 +388,13 @@ void UI7CtxEndMenu() {
(szs) * (static_cast<float>(ui7_ctx->cm->scrolling_offset) /
static_cast<float>(ui7_ctx->cm->msr.y)))));
int slider_w = 4;
ui7_ctx->cm->front.push_back(
DrawCmd::New(R7Vec4(R7Vec2(sw - 12, tsp), R7Vec2(slider_w * 2, szs)),
RD7Color_List0));
ui7_ctx->cm->front.push_back(DrawCmd::New(
R7Vec4(R7Vec2(sw - 10, slider_pos + 2), R7Vec2(slider_w, slider_rh)),
RD7Color_Selector));
ui7_ctx->cm->front->AddRectangle(R7Vec2(sw - 12, tsp),
R7Vec2(slider_w * 2, szs), RD7Color_List0);
ui7_ctx->cm->front->AddRectangle(R7Vec2(sw - 10, slider_pos + 2),
R7Vec2(slider_w, slider_h),
RD7Color_Selector);
}
// Proccess DrawLists
for (auto &it : ui7_ctx->cm->background) it->Process();
for (auto &it : ui7_ctx->cm->main) it->Process();
for (auto &it : ui7_ctx->cm->front) it->Process();
ui7_ctx->cm->background.clear();
ui7_ctx->cm->main.clear();
ui7_ctx->cm->front.clear();
ui7_ctx->active_menus.push_back(ui7_ctx->cm);
ui7_ctx->cm = nullptr;
ui7_ctx->in_menu = false;
}
@ -351,27 +421,35 @@ bool InBox(R7Vec2 inpos, R7Vec2 boxpos, R7Vec2 boxsize) {
void Init() {
// If Context is valid it makes no sense to reinit lol
if (UI7CtxValidate()) return;
ui7_ctx = new UI7_Ctx;
ui7_ctx = UI7_Ctx::New();
ui7_ctx->delta = 0.0f;
ui7_ctx->time = 0.0f;
ui7_ctx->_last = __get_time();
ui7_ctx->bdl = UI7DrawList::New();
ui7_ctx->fdl = UI7DrawList::New();
ui7_ctx->debug_calls = UI7DrawList::New();
ui7_ctx->is_activated = true;
}
void Deinit() {
// Dont deinit something not initialized
// Please dont count how often init... was
// written wrong by me :(
if (!UI7CtxValidate()) return;
ui7_ctx->is_activated = false;
ui7_ctx->menus.clear();
delete ui7_ctx;
ui7_ctx->debug_calls->Clear();
ui7_ctx->active_menus.clear();
}
void Update() {
// Dont do anithing without ctx;
if (!UI7CtxValidate()) return;
ui7_ctx->debug_calls.clear();
ui7_ctx->bdl->Process();
for (auto &it : ui7_ctx->active_menus) {
it->background->Process();
it->main->Process();
it->front->Process();
}
ui7_ctx->fdl->Process();
ui7_ctx->active_menus.clear();
float current = __get_time();
ui7_ctx->delta = (current - ui7_ctx->_last) / 1000.f;
ui7_ctx->_last = current;
@ -421,12 +499,11 @@ bool Button(const std::string &label, R7Vec2 size) {
btn = RD7Color_ButtonHovered;
}
}
ui7_ctx->cm->main.push_back(DrawCmd::New(R7Vec4(pos, size), btn));
ui7_ctx->cm->main->AddRectangle(pos, size, btn);
pos = R7Vec2(pos.x + size.x * 0.5f - textdim.x * 0.5,
pos.y + size.y * 0.5f - textdim.y * 0.5);
ui7_ctx->cm->main.push_back(
DrawCmd::New(pos, label, RenderD7::ThemeActive()->AutoText(btn)));
ui7_ctx->cm->main->AddText(pos, label,
RenderD7::ThemeActive()->AutoText(btn));
return ret;
}
@ -461,14 +538,14 @@ void Checkbox(const std::string &label, bool &c) {
}
}
ui7_ctx->cm->main.push_back(DrawCmd::New(R7Vec4(pos, cbs), bg));
ui7_ctx->cm->main->AddRectangle(pos, cbs, bg);
if (c == true) {
ui7_ctx->cm->main.push_back(DrawCmd::New(
R7Vec4(pos + R7Vec2(2, 2), cbs - R7Vec2(4, 4)), RD7Color_Checkmark));
ui7_ctx->cm->main->AddRectangle(pos + R7Vec2(2, 2), cbs - R7Vec2(4, 4),
RD7Color_Checkmark);
}
ui7_ctx->cm->main.push_back(
DrawCmd::New(pos + R7Vec2(cbs.x + 5, 1), label,
RenderD7::ThemeActive()->AutoText(RD7Color_Background)));
ui7_ctx->cm->main->AddText(
pos + R7Vec2(cbs.x + 5, 1), label,
RenderD7::ThemeActive()->AutoText(RD7Color_Background));
}
void Label(const std::string &label, RD7TextFlags flags) {
@ -491,11 +568,11 @@ void Label(const std::string &label, RD7TextFlags flags) {
auto &list =
(upos.y + textdim.y < tbh) ? ui7_ctx->cm->front : ui7_ctx->cm->main;
list.push_back(DrawCmd::New(
list->AddText(
pos, label,
RenderD7::ThemeActive()->AutoText(
(upos.y + textdim.y < tbh ? RD7Color_Header : RD7Color_Background)),
flags));
flags);
}
void Progressbar(float value) {
@ -514,15 +591,13 @@ void Progressbar(float value) {
return;
}
ui7_ctx->cm->main.push_back(
DrawCmd::New(R7Vec4(pos, size), RD7Color_FrameBg));
ui7_ctx->cm->main.push_back(
DrawCmd::New(R7Vec4(pos + R7Vec2(2, 2), size - R7Vec2(4, 4)),
RD7Color_FrameBgHovered));
ui7_ctx->cm->main->AddRectangle(pos, size, RD7Color_FrameBg);
ui7_ctx->cm->main->AddRectangle(pos + R7Vec2(2, 2), size - R7Vec2(4, 4),
RD7Color_FrameBgHovered);
if (!(value != value) && !(value < 0.0) && !(value > 1.0)) {
ui7_ctx->cm->main.push_back(DrawCmd::New(
R7Vec4(pos + R7Vec2(2, 2), R7Vec2((size.x - 4) * value, size.y - 4)),
RD7Color_Progressbar));
ui7_ctx->cm->main->AddRectangle(pos + R7Vec2(2, 2),
R7Vec2((size.x - 4) * value, size.y - 4),
RD7Color_Progressbar);
}
}
@ -556,9 +631,9 @@ void BrowserList(const std::vector<std::string> &entrys, int &selection,
int selindex = (selection < max_entrys ? selection : (max_entrys - 1));
for (int i = 0; i < max_entrys; i++) {
ui7_ctx->cm->main.push_back(
DrawCmd::New(R7Vec4(pos + R7Vec2(0, 15 * i), R7Vec2(size.x, 15)),
(i % 2 == 0 ? RD7Color_List0 : RD7Color_List1)));
ui7_ctx->cm->main->AddRectangle(
pos + R7Vec2(0, 15 * i), R7Vec2(size.x, 15),
(i % 2 == 0 ? RD7Color_List0 : RD7Color_List1));
}
for (size_t i = 0;
i < ((entrys.size() < (size_t)max_entrys) ? entrys.size()
@ -567,21 +642,19 @@ void BrowserList(const std::vector<std::string> &entrys, int &selection,
int list_index =
(selection < max_entrys ? i : (i + selection - (max_entrys - 1)));
if (i == (size_t)selindex) {
ui7_ctx->cm->main.push_back(DrawCmd::New(
R7Vec4(pos + R7Vec2(0, 15 * i), R7Vec2(size.x, 15)),
ui7_ctx->cm->main->AddRectangle(
pos + R7Vec2(0, 15 * i), R7Vec2(size.x, 15),
(unsigned int)RenderD7::Color::RGBA(RD7Color_Selector)
.fade_to(RD7Color_SelectorFade, std::sin(RenderD7::GetTime()))
.toRGBA()));
.toRGBA());
}
auto cmd =
DrawCmd::New(pos + R7Vec2(5, 15 * i), entrys[list_index],
RenderD7::ThemeActive()->AutoText(
selindex == (int)i
? RD7Color_Selector
: (i % 2 == 0 ? RD7Color_List0 : RD7Color_List1)),
txtflags | RD7TextFlags_Short);
cmd->text_box = R7Vec2(size.x, 15);
ui7_ctx->cm->main.push_back(cmd);
ui7_ctx->cm->main->AddText(
pos + R7Vec2(5, 15 * i), entrys[list_index],
RenderD7::ThemeActive()->AutoText(
selindex == (int)i
? RD7Color_Selector
: (i % 2 == 0 ? RD7Color_List0 : RD7Color_List1)),
txtflags | RD7TextFlags_Short, R7Vec2(size.x, 15));
}
RenderD7::CustomTextSize(tmp_txt);
}
@ -620,13 +693,12 @@ void InputText(const std::string &label, std::string &text,
}
}
ui7_ctx->cm->main.push_back(DrawCmd::New(R7Vec4(pos, cbs), bg));
ui7_ctx->cm->main.push_back(
DrawCmd::New(pos + R7Vec2(5, 1), (text != "" ? text : hint),
RenderD7::ThemeActive()->AutoText(bg)));
ui7_ctx->cm->main.push_back(
DrawCmd::New(pos + R7Vec2(cbs.x + 5, 1), id.Title(),
RenderD7::ThemeActive()->AutoText(RD7Color_Background)));
ui7_ctx->cm->main->AddRectangle(pos, cbs, bg);
ui7_ctx->cm->main->AddText(pos + R7Vec2(5, 1), (text != "" ? text : hint),
RenderD7::ThemeActive()->AutoText(bg));
ui7_ctx->cm->main->AddText(
pos + R7Vec2(cbs.x + 5, 1), id.Title(),
RenderD7::ThemeActive()->AutoText(RD7Color_Background));
}
bool BeginMenu(const std::string &title, R7Vec2 size, UI7MenuFlags flags) {
@ -726,15 +798,14 @@ bool BeginMenu(const std::string &title, R7Vec2 size, UI7MenuFlags flags) {
ui7_ctx->cm->scrolling_offset = 0.f;
ui7_ctx->cm->scrolling_mod = 0.f;
}
ui7_ctx->cm->background.push_back(
DrawCmd::New(R7Vec4(R7Vec2(), size), RD7Color_Background));
ui7_ctx->cm->background->AddRectangle(R7Vec2(), size, RD7Color_Background);
if (titlebar) {
ui7_ctx->cm->front.push_back(
DrawCmd::New(R7Vec4(R7Vec2(), R7Vec2(size.x, tbh)), RD7Color_Header));
ui7_ctx->cm->front.push_back(DrawCmd::New(
ui7_ctx->cm->front->AddRectangle(R7Vec2(), R7Vec2(size.x, tbh),
RD7Color_Header);
ui7_ctx->cm->front->AddText(
R7Vec2(5, 2), id.Title(),
RenderD7::ThemeActive()->AutoText(RD7Color_Header), txtflags));
RenderD7::ThemeActive()->AutoText(RD7Color_Header), txtflags);
}
SetCursorPos(R7Vec2(5, ui7_ctx->cm->tbh + 5));
@ -900,100 +971,81 @@ void ColorSelector(const std::string &label, unsigned int &color) {
}
if (!isunlock && !inkbd) RenderD7::Hid::Lock();
// Draw Frame
ui7_ctx->cm->front.push_back(
DrawCmd::New(R7Vec4(npos.x, npos.y, 107, 97), RD7Color_FrameBg));
ui7_ctx->cm->front->AddRectangle(npos, R7Vec2(107, 97), RD7Color_FrameBg);
// Draw Color Button
ui7_ctx->cm->front.push_back(
DrawCmd::New(R7Vec4(npos + R7Vec2(2, 2), cbs), outline));
ui7_ctx->cm->front.push_back(
DrawCmd::New(R7Vec4(npos + R7Vec2(4, 4), cbs - R7Vec2(4, 4)), color));
// Setup TextCommand with Short flag
auto cmd =
DrawCmd::New(npos + R7Vec2(cbs.x + 7, 1), label,
RenderD7::ThemeActive()->AutoText(RD7Color_FrameBg));
cmd->text_box = R7Vec2(93 - cbs.x - 5, 0);
cmd->text_flags |= RD7TextFlags_Short;
ui7_ctx->cm->front.push_back(cmd);
ui7_ctx->cm->front->AddRectangle(npos + R7Vec2(2, 2), cbs, outline);
ui7_ctx->cm->front->AddRectangle(npos + R7Vec2(4, 4), cbs - R7Vec2(4, 4),
color);
// Draw Color Name Shorted if needed
ui7_ctx->cm->front->AddText(
npos + R7Vec2(cbs.x + 7, 1), label,
RenderD7::ThemeActive()->AutoText(RD7Color_FrameBg),
RD7TextFlags_Short);
// Add luminance text
ui7_ctx->cm->front.push_back(DrawCmd::New(
ui7_ctx->cm->front->AddText(
npos + R7Vec2(2, cbs.y + 4), "lum: " + std::to_string(clr.luminance()),
RenderD7::ThemeActive()->AutoText(RD7Color_FrameBg)));
RenderD7::ThemeActive()->AutoText(RD7Color_FrameBg));
// Add Hex value
ui7_ctx->cm->front.push_back(
DrawCmd::New(npos + R7Vec2(2, cbs.y * 2 + 4),
"hex: " + RenderD7::Color::RGBA2Hex(color),
RenderD7::ThemeActive()->AutoText(RD7Color_FrameBg)));
ui7_ctx->cm->front->AddText(
npos + R7Vec2(2, cbs.y * 2 + 4),
"hex: " + RenderD7::Color::RGBA2Hex(color),
RenderD7::ThemeActive()->AutoText(RD7Color_FrameBg));
// Red
{
ui7_ctx->cm->front.push_back(DrawCmd::New(
R7Vec4(npos + R7Vec2(2, cbs.y * 3 + 4), R7Vec2(50, cbs.y)),
RD7Color_FrameBgHovered));
ui7_ctx->cm->front.push_back(
DrawCmd::New(R7Vec4(npos + R7Vec2(2, cbs.y * 3 + 4),
R7Vec2(50 * ((float)clr.m_r / 255.f), cbs.y)),
0xff0000ff));
auto ncmd = DrawCmd::New(npos + R7Vec2(2, cbs.y * 3 + 4),
"R: " + std::to_string(clr.m_r), RD7Color_Text);
ncmd->text_flags |= RD7TextFlags_AlignMid;
ncmd->text_box = R7Vec2(50, 0);
ui7_ctx->cm->front.push_back(ncmd);
ui7_ctx->cm->front->AddRectangle(npos + R7Vec2(2, cbs.y * 3 + 4),
R7Vec2(50, cbs.y),
RD7Color_FrameBgHovered);
ui7_ctx->cm->front->AddRectangle(
npos + R7Vec2(2, cbs.y * 3 + 4),
R7Vec2(50 * ((float)clr.m_r / 255.f), cbs.y), 0xff0000ff);
ui7_ctx->cm->front->AddText(
npos + R7Vec2(2, cbs.y * 3 + 4), "R: " + std::to_string(clr.m_r),
RD7Color_Text, RD7TextFlags_AlignMid, R7Vec2(50, 0));
}
// Green
{
ui7_ctx->cm->front.push_back(DrawCmd::New(
R7Vec4(npos + R7Vec2(54, cbs.y * 3 + 4), R7Vec2(50, cbs.y)),
RD7Color_FrameBgHovered));
ui7_ctx->cm->front.push_back(
DrawCmd::New(R7Vec4(npos + R7Vec2(54, cbs.y * 3 + 4),
R7Vec2(50 * ((float)clr.m_g / 255.f), cbs.y)),
0xff00ff00));
auto ncmd = DrawCmd::New(npos + R7Vec2(54, cbs.y * 3 + 4),
"G: " + std::to_string(clr.m_g), RD7Color_Text);
ncmd->text_flags |= RD7TextFlags_AlignMid;
ncmd->text_box = R7Vec2(50, 0);
ui7_ctx->cm->front.push_back(ncmd);
ui7_ctx->cm->front->AddRectangle(npos + R7Vec2(54, cbs.y * 3 + 4),
R7Vec2(50, cbs.y),
RD7Color_FrameBgHovered);
ui7_ctx->cm->front->AddRectangle(
npos + R7Vec2(54, cbs.y * 3 + 4),
R7Vec2(50 * ((float)clr.m_g / 255.f), cbs.y), 0xff00ff00);
ui7_ctx->cm->front->AddText(
npos + R7Vec2(54, cbs.y * 3 + 4), "G: " + std::to_string(clr.m_g),
RD7Color_Text, RD7TextFlags_AlignMid, R7Vec2(50, 0));
}
// Blue
{
ui7_ctx->cm->front.push_back(DrawCmd::New(
R7Vec4(npos + R7Vec2(2, cbs.y * 4 + 4), R7Vec2(50, cbs.y)),
RD7Color_FrameBgHovered));
ui7_ctx->cm->front.push_back(
DrawCmd::New(R7Vec4(npos + R7Vec2(2, cbs.y * 4 + 4),
R7Vec2(50 * ((float)clr.m_b / 255.f), cbs.y)),
0xffff0000));
auto ncmd = DrawCmd::New(npos + R7Vec2(2, cbs.y * 4 + 4),
"B: " + std::to_string(clr.m_b), RD7Color_Text);
ncmd->text_flags |= RD7TextFlags_AlignMid;
ncmd->text_box = R7Vec2(50, 0);
ui7_ctx->cm->front.push_back(ncmd);
ui7_ctx->cm->front->AddRectangle(npos + R7Vec2(2, cbs.y * 4 + 4),
R7Vec2(50, cbs.y),
RD7Color_FrameBgHovered);
ui7_ctx->cm->front->AddRectangle(
npos + R7Vec2(2, cbs.y * 4 + 4),
R7Vec2(50 * ((float)clr.m_b / 255.f), cbs.y), 0xffff0000);
ui7_ctx->cm->front->AddText(
npos + R7Vec2(2, cbs.y * 4 + 4), "B: " + std::to_string(clr.m_b),
RD7Color_Text, RD7TextFlags_AlignMid, R7Vec2(50, 0));
}
// Alpha
{
ui7_ctx->cm->front.push_back(DrawCmd::New(
R7Vec4(npos + R7Vec2(54, cbs.y * 4 + 4), R7Vec2(50, cbs.y)),
RD7Color_FrameBgHovered));
ui7_ctx->cm->front.push_back(
DrawCmd::New(R7Vec4(npos + R7Vec2(54, cbs.y * 4 + 4),
R7Vec2(50 * ((float)clr.m_a / 255.f), cbs.y)),
0xffffffff));
auto ncmd = DrawCmd::New(npos + R7Vec2(54, cbs.y * 4 + 4),
"A: " + std::to_string(clr.m_a), RD7Color_Text);
ncmd->text_flags |= RD7TextFlags_AlignMid;
ncmd->text_box = R7Vec2(50, 0);
ui7_ctx->cm->front.push_back(ncmd);
ui7_ctx->cm->front->AddRectangle(npos + R7Vec2(54, cbs.y * 4 + 4),
R7Vec2(50, cbs.y),
RD7Color_FrameBgHovered);
ui7_ctx->cm->front->AddRectangle(
npos + R7Vec2(54, cbs.y * 4 + 4),
R7Vec2(50 * ((float)clr.m_a / 255.f), cbs.y), 0xffffffff);
ui7_ctx->cm->front->AddText(
npos + R7Vec2(54, cbs.y * 4 + 4), "A: " + std::to_string(clr.m_a),
RD7Color_Text, RD7TextFlags_AlignMid, R7Vec2(50, 0));
}
}
ui7_ctx->cm->main.push_back(DrawCmd::New(R7Vec4(pos, cbs), outline));
ui7_ctx->cm->main.push_back(
DrawCmd::New(R7Vec4(pos + R7Vec2(2, 2), cbs - R7Vec2(4, 4)), color));
ui7_ctx->cm->main.push_back(
DrawCmd::New(pos + R7Vec2(cbs.x + 5, 1), label,
RenderD7::ThemeActive()->AutoText(RD7Color_Background)));
ui7_ctx->cm->main->AddRectangle(pos, cbs, outline);
ui7_ctx->cm->main->AddRectangle(pos + R7Vec2(2, 2), cbs - R7Vec2(4, 4),
color);
ui7_ctx->cm->main->AddText(
pos + R7Vec2(cbs.x + 5, 1), label,
RenderD7::ThemeActive()->AutoText(RD7Color_Background));
}
bool BeginTree(const std::string &text) {
@ -1033,10 +1085,9 @@ void SameLine() {
void Debug() {
if (!UI7CtxValidate()) return;
if (ui7_ctx->debugging) {
for (auto &it : ui7_ctx->debug_calls) {
it->Process();
}
ui7_ctx->debug_calls->Process(false);
}
ui7_ctx->debug_calls->Clear();
}
float GetScrollingOffset() {
@ -1054,4 +1105,13 @@ bool &IsDebugging() {
return ui7_ctx->debugging;
}
UI7DrawList::Ref GetForegroundList() {
if (!UI7CtxValidate()) return nullptr;
return ui7_ctx->fdl;
}
UI7DrawList::Ref GetBackgroundList() {
if (!UI7CtxValidate()) return nullptr;
return ui7_ctx->bdl;
}
} // namespace UI7

View File

@ -300,7 +300,6 @@ bool RenderD7::MainLoop() {
d7_hRepeat = hidKeysDownRepeat();
hidTouchRead(&d7_touch);
Hid::Update();
UI7::Update();
rd7i_hid_touch_pos = R7Vec2(d7_touch.px, d7_touch.py);
RenderD7::ClearTextBufs();
@ -500,9 +499,10 @@ void RenderD7::FrameEnd() {
RenderD7::Scene::doDraw();
RenderD7::Scene::doLogic();
}
UI7::Update();
UI7::Debug();
RenderD7::ProcessMessages();
OvlHandler();
UI7::Debug();
Npifade();
C3D_FrameEnd(0);
}