Road to 0.6.0
- readd the c++ linear allocator for 3ds - start switching from PD::Vec to std::vector - Add Color::Hex as constexpr for compiletime color converts - Add FNV Hasing functions - Make UI7 ids be able to be generated at compile time - Added a Throw Function (for whatever) - Added HexCHar2Int (replaces the lookup table) - Made u128 fully constexpr
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(pd-core LANGUAGES CXX VERSION 0.5.1)
|
||||
project(pd-core LANGUAGES CXX VERSION 0.6.0)
|
||||
|
||||
set(SRC
|
||||
source/bit_util.cpp
|
||||
|
||||
@@ -25,39 +25,6 @@ SOFTWARE.
|
||||
#include <pd/core/color.hpp>
|
||||
|
||||
namespace PD {
|
||||
// The Solution of the biggest performance issue
|
||||
// A Simple Lookup table
|
||||
static const std::map<char, int> HEX_DEC = {
|
||||
{'0', 0}, {'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5},
|
||||
{'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'a', 10}, {'b', 11},
|
||||
{'c', 12}, {'d', 13}, {'e', 14}, {'f', 15}, {'A', 10}, {'B', 11},
|
||||
{'C', 12}, {'D', 13}, {'E', 14}, {'F', 15}};
|
||||
|
||||
PD_CORE_API Color& Color::Hex(const std::string& hex) {
|
||||
#ifdef PD_NO_SAFE_CODE
|
||||
/// Safetey check (not required if you programm well xd)
|
||||
if (hex.length() != 7 || hex.length() != 9 || hex.length() != 6 ||
|
||||
hex.length() != 8 || std::find_if(hex.begin(), hex.end(), [](char c) {
|
||||
return !std::isxdigit(c);
|
||||
}) != hex.end()) {
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
int offset = ((hex.length() == 7 || hex.length() == 9) ? 1 : 0);
|
||||
r = HEX_DEC.at(hex[offset]) * 16 + HEX_DEC.at(hex[offset + 1]);
|
||||
offset += 2;
|
||||
g = HEX_DEC.at(hex[offset]) * 16 + HEX_DEC.at(hex[offset + 1]);
|
||||
offset += 2;
|
||||
b = HEX_DEC.at(hex[offset]) * 16 + HEX_DEC.at(hex[offset + 1]);
|
||||
offset += 2;
|
||||
if (hex.length() == 9) {
|
||||
a = HEX_DEC.at(hex[offset]) * 16 + HEX_DEC.at(hex[offset + 1]);
|
||||
} else {
|
||||
a = 255;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
PD_CORE_API std::string Color::Hex(bool rgba) const {
|
||||
/** Need to int cast (so it is used as num and not char...) */
|
||||
std::stringstream s;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(pd-lithium LANGUAGES CXX VERSION 0.5.1)
|
||||
project(pd-lithium LANGUAGES CXX VERSION 0.6.0)
|
||||
|
||||
option(PD_LI_INCLUDE_FONTS "Include Fonts" OFF)
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ PD_LITHIUM_API void DrawList::Clear() {
|
||||
pNumIndices = 0;
|
||||
pNumVertices = 0;
|
||||
pDrawList.clear();
|
||||
pPath.Clear();
|
||||
pClipRects.Clear();
|
||||
}
|
||||
|
||||
PD_LITHIUM_API void DrawList::AddCommand(Command::Ref v) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(pd-ui7 LANGUAGES CXX VERSION 0.5.1)
|
||||
project(pd-ui7 LANGUAGES CXX VERSION 0.6.0)
|
||||
|
||||
set(SRC
|
||||
source/theme.cpp
|
||||
|
||||
@@ -27,21 +27,21 @@ SOFTWARE.
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
Menu::Menu(const ID &id, IO::Ref io) : pIO(io), pID(id) {
|
||||
Menu::Menu(const ID& id, IO::Ref io) : pIO(io), pID(id) {
|
||||
pLayout = Layout::New(id, io);
|
||||
TitleBarHeight = io->FontScale * 30.f;
|
||||
pLayout->WorkRect.y += TitleBarHeight;
|
||||
pLayout->CursorInit();
|
||||
}
|
||||
|
||||
PD_UI7_API void Menu::Label(const std::string &label) {
|
||||
PD_UI7_API void Menu::Label(const std::string& label) {
|
||||
// Layout API
|
||||
auto r = Label::New(label, pIO);
|
||||
r->SetClipRect(fvec4(pLayout->GetPosition(), pLayout->GetSize()));
|
||||
pLayout->AddObject(r);
|
||||
}
|
||||
|
||||
PD_UI7_API bool Menu::Button(const std::string &label) {
|
||||
PD_UI7_API bool Menu::Button(const std::string& label) {
|
||||
bool ret = false;
|
||||
u32 id = Strings::FastHash("btn" + label +
|
||||
std::to_string(pLayout->Objects.Size()));
|
||||
@@ -57,7 +57,7 @@ PD_UI7_API bool Menu::Button(const std::string &label) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
PD_UI7_API void Menu::Checkbox(const std::string &label, bool &v) {
|
||||
PD_UI7_API void Menu::Checkbox(const std::string& label, bool& v) {
|
||||
u32 id = Strings::FastHash("cbx" + label +
|
||||
std::to_string(pLayout->Objects.Size()));
|
||||
Container::Ref r = pLayout->FindObject(id);
|
||||
@@ -76,7 +76,7 @@ PD_UI7_API void Menu::Image(Li::Texture::Ref img, fvec2 size, Li::Rect uv) {
|
||||
PD_UI7_API void Menu::Separator() {
|
||||
// Dynamic Objects are very simple...
|
||||
Container::Ref r = DynObj::New(
|
||||
[=, this](UI7::IO::Ref io, Li::DrawList::Ref l, UI7::Container *self) {
|
||||
[=, this](UI7::IO::Ref io, Li::DrawList::Ref l, UI7::Container* self) {
|
||||
l->DrawRectFilled(self->FinalPos(), self->GetSize(),
|
||||
pIO->Theme->Get(UI7Color_TextDead));
|
||||
});
|
||||
@@ -85,10 +85,10 @@ PD_UI7_API void Menu::Separator() {
|
||||
pLayout->AddObject(r);
|
||||
}
|
||||
|
||||
PD_UI7_API void Menu::SeparatorText(const std::string &label) {
|
||||
PD_UI7_API void Menu::SeparatorText(const std::string& label) {
|
||||
// Also note to use [=] instead of [&] to not undefined access label
|
||||
Container::Ref r = DynObj::New([=, this](UI7::IO::Ref io, Li::DrawList::Ref l,
|
||||
UI7::Container *self) {
|
||||
UI7::Container* self) {
|
||||
fvec2 size = self->GetSize();
|
||||
fvec2 tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||
fvec2 pos = self->FinalPos();
|
||||
@@ -141,7 +141,7 @@ PD_UI7_API void Menu::HandleScrolling() {
|
||||
pLayout->ScrollStart = pLayout->ScrollOffset;
|
||||
}
|
||||
if (pIO->InputHandler->DragObject(
|
||||
"sbg" + pID.pName,
|
||||
"sbg" + pID.GetName(),
|
||||
fvec4(pLayout->Pos, fvec2(0.f)) + pLayout->WorkRect)) {
|
||||
if (pIO->InputHandler->DragReleasedAW) {
|
||||
} else {
|
||||
@@ -238,7 +238,7 @@ PD_UI7_API void Menu::DrawBaseLayout() {
|
||||
/** Resize Sym (Render on Top of Everything) */
|
||||
if (!(Flags & UI7MenuFlags_NoResize)) {
|
||||
Container::Ref r = DynObj::New(
|
||||
[](IO::Ref io, Li::DrawList::Ref l, UI7::Container *self) {
|
||||
[](IO::Ref io, Li::DrawList::Ref l, UI7::Container* self) {
|
||||
l->Layer = 1;
|
||||
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(0, 20));
|
||||
l->PathAdd(self->FinalPos() + self->GetSize());
|
||||
@@ -254,7 +254,7 @@ PD_UI7_API void Menu::DrawBaseLayout() {
|
||||
|
||||
/** Background */
|
||||
Container::Ref r = DynObj::New([](IO::Ref io, Li::DrawList::Ref l,
|
||||
UI7::Container *self) {
|
||||
UI7::Container* self) {
|
||||
l->Layer = 0;
|
||||
l->PathRectEx(self->FinalPos(), self->FinalPos() + self->GetSize(), 10.f,
|
||||
LiPathRectFlags_KeepTop | LiPathRectFlags_KeepBot);
|
||||
@@ -271,7 +271,7 @@ PD_UI7_API void Menu::DrawBaseLayout() {
|
||||
}
|
||||
if (!(Flags & UI7MenuFlags_NoTitlebar)) {
|
||||
Container::Ref r = DynObj::New(
|
||||
[=, this](UI7::IO::Ref io, Li::DrawList::Ref l, UI7::Container *self) {
|
||||
[=, this](UI7::IO::Ref io, Li::DrawList::Ref l, UI7::Container* self) {
|
||||
l->Layer = 20;
|
||||
/** Header Bar */
|
||||
l->DrawRectFilled(self->FinalPos(), self->GetSize(),
|
||||
@@ -295,7 +295,7 @@ PD_UI7_API void Menu::DrawBaseLayout() {
|
||||
/** Collapse Sym */
|
||||
if (!(Flags & UI7MenuFlags_NoCollapse)) {
|
||||
r = DynObj::New([=, this](UI7::IO::Ref io, Li::DrawList::Ref l,
|
||||
UI7::Container *self) {
|
||||
UI7::Container* self) {
|
||||
/** This sym actually requires layer 21 (i dont know why) */
|
||||
l->Layer = 21;
|
||||
/**
|
||||
@@ -351,7 +351,7 @@ PD_UI7_API void Menu::Update() {
|
||||
pLayout->Update();
|
||||
}
|
||||
|
||||
PD_UI7_API bool Menu::BeginTreeNode(const ID &id) {
|
||||
PD_UI7_API bool Menu::BeginTreeNode(const ID& id) {
|
||||
// As of some notes this should work:
|
||||
auto n = pTreeNodes.find(id);
|
||||
if (n == pTreeNodes.end()) {
|
||||
@@ -368,7 +368,7 @@ PD_UI7_API bool Menu::BeginTreeNode(const ID &id) {
|
||||
|
||||
// Object
|
||||
auto r =
|
||||
DynObj::New([=, this](IO::Ref io, Li::DrawList::Ref l, Container *self) {
|
||||
DynObj::New([=, this](IO::Ref io, Li::DrawList::Ref l, Container* self) {
|
||||
fvec2 ts = self->FinalPos() + fvec2(0, 7);
|
||||
fvec2 pl[2] = {fvec2(10, 5), fvec2(0, 10)};
|
||||
if (n->second) {
|
||||
@@ -383,7 +383,7 @@ PD_UI7_API bool Menu::BeginTreeNode(const ID &id) {
|
||||
id.GetName(), io->Theme->Get(UI7Color_Text));
|
||||
});
|
||||
/** Yes this new function handler was created for tree nodes */
|
||||
r->AddInputHandler([=, this](IO::Ref io, Container *self) {
|
||||
r->AddInputHandler([=, this](IO::Ref io, Container* self) {
|
||||
if (io->InputHandler->DragObject(
|
||||
ID(pID.GetName() + id.GetName()),
|
||||
fvec4(self->FinalPos(), self->GetSize()))) {
|
||||
|
||||
Reference in New Issue
Block a user