0.7.0 rewrite dev
- remove everyting - keep core -rename bit_utils to bits - add formatter for color - add float getters to color - start with new drivers api
This commit is contained in:
87
include/pd/ui7/viewport.hpp → include/pd/common.hpp
Executable file → Normal file
87
include/pd/ui7/viewport.hpp → include/pd/common.hpp
Executable file → Normal file
@@ -1,45 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/ui7/id.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class ViewPort {
|
||||
public:
|
||||
ViewPort(const ID& id, const ivec4& size) : pID(id), pSize(size) {}
|
||||
~ViewPort() {}
|
||||
|
||||
PD_SHARED(ViewPort);
|
||||
|
||||
ID GetID() const { return pID; }
|
||||
ivec4& GetSize() { return pSize; }
|
||||
|
||||
ID pID;
|
||||
ivec4 pSize;
|
||||
};
|
||||
} // namespace UI7
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <exception>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace PD {
|
||||
[[noreturn]] inline void Throw(const std::string& msg) {
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
using u8 = unsigned char;
|
||||
using u16 = unsigned short;
|
||||
using u32 = unsigned int;
|
||||
using u64 = unsigned long long;
|
||||
using ptr = uintptr_t;
|
||||
} // namespace PD
|
||||
87
include/pd/core/bit_util.hpp → include/pd/core/bits.hpp
Executable file → Normal file
87
include/pd/core/bit_util.hpp → include/pd/core/bits.hpp
Executable file → Normal file
@@ -1,46 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Binary Utillity Functions
|
||||
*/
|
||||
namespace BitUtil {
|
||||
/**
|
||||
* Check if a 32 Bit number only set a sigle bit to 1
|
||||
* @param v 32 bit unsigned int
|
||||
* @return true if its a single bit number
|
||||
*/
|
||||
PD_API bool IsSingleBit(u32 v);
|
||||
/**
|
||||
* Get the Next Power of two Number
|
||||
* @param v Current Number
|
||||
* @return Next Number thats a Pow of 2
|
||||
*/
|
||||
PD_API u32 GetPow2(u32 v);
|
||||
} // namespace BitUtil
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Bits {
|
||||
/**
|
||||
* Check if a 32 Bit number only set a sigle bit to 1
|
||||
* @param v 32 bit unsigned int
|
||||
* @return true if its a single bit number
|
||||
*/
|
||||
PD_API bool IsSingleBit(u32 v);
|
||||
/**
|
||||
* Get the Next Power of two Number
|
||||
* @param v Current Number
|
||||
* @return Next Number thats a Pow of 2
|
||||
*/
|
||||
PD_API u32 GetPow2(u32 v);
|
||||
} // namespace Bits
|
||||
} // namespace PD
|
||||
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
#include <pd/core/strings.hpp>
|
||||
|
||||
namespace PD {
|
||||
@@ -140,6 +140,11 @@ class PD_API Color {
|
||||
*/
|
||||
constexpr operator u32() const { return Get(); }
|
||||
|
||||
const float rf() const { return static_cast<float>(r) / 255.f; }
|
||||
const float gf() const { return static_cast<float>(g) / 255.f; }
|
||||
const float bf() const { return static_cast<float>(b) / 255.f; }
|
||||
const float af() const { return static_cast<float>(a) / 255.f; }
|
||||
|
||||
/** Public Access Data section */
|
||||
u8 r;
|
||||
u8 g;
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <filesystem> // Requires C++ 17 or later
|
||||
#include <format> // Requires C++ 20 or later
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <numbers>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/** Dynamic Lib loading */
|
||||
#include <pd/pd_p_api.hpp>
|
||||
|
||||
/** Memory Management */
|
||||
|
||||
#define PD_SHARED(x) \
|
||||
using Ref = std::shared_ptr<x>; \
|
||||
template <typename... Args> \
|
||||
static Ref New(Args&&... args) { \
|
||||
return std::make_shared<x>(std::forward<Args>(args)...); \
|
||||
}
|
||||
|
||||
#define PD_RAW(x) \
|
||||
using Ref = x*; \
|
||||
template <typename... Args> \
|
||||
static Ref New(Args&&... args) { \
|
||||
x* v = new x; \
|
||||
new (v) x(std::forward<Args>(args)...); \
|
||||
return v; \
|
||||
} \
|
||||
static void Delete(Ref ref) { delete ref; }
|
||||
|
||||
#define PD_UNIQUE(x) \
|
||||
using Ref = std::unique_ptr<x>; \
|
||||
template <typename... Args> \
|
||||
static Ref New(Args&&... args) { \
|
||||
return std::make_unique<x>(std::forward<Args>(args)...); \
|
||||
}
|
||||
|
||||
#define PD_BIT(x) (1 << x)
|
||||
|
||||
namespace PD {
|
||||
[[noreturn]] inline void Throw(const std::string& str) {
|
||||
#ifdef _EXCEPTIONS
|
||||
throw std::runtime_error("PD Error " + str);
|
||||
#else
|
||||
std::cout << "PD Error " << str << std::endl;
|
||||
std::abort();
|
||||
#endif
|
||||
}
|
||||
/** Types */
|
||||
using u8 = unsigned char;
|
||||
using u16 = unsigned short;
|
||||
using u32 = unsigned int;
|
||||
using u64 = unsigned long long;
|
||||
} // namespace PD
|
||||
@@ -23,9 +23,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/bit_util.hpp>
|
||||
#include <pd/core/bits.hpp>
|
||||
#include <pd/core/color.hpp>
|
||||
#include <pd/core/fnv.hpp>
|
||||
#include <pd/core/formatters.hpp>
|
||||
#include <pd/core/fquat.hpp>
|
||||
#include <pd/core/hashid.hpp>
|
||||
#include <pd/core/io.hpp>
|
||||
#include <pd/core/mat.hpp>
|
||||
@@ -35,4 +37,4 @@ SOFTWARE.
|
||||
#include <pd/core/timetrace.hpp>
|
||||
#include <pd/core/tween.hpp>
|
||||
#include <pd/core/u128.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
|
||||
98
include/pd/core/formatters.hpp
Normal file
98
include/pd/core/formatters.hpp
Normal file
@@ -0,0 +1,98 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/color.hpp>
|
||||
|
||||
template <>
|
||||
struct std::formatter<PD::Color> : std::formatter<std::string> {
|
||||
enum class ColorFmt {
|
||||
Hex,
|
||||
Rgbf,
|
||||
Rgb,
|
||||
Rgba,
|
||||
Rgbaf,
|
||||
};
|
||||
ColorFmt mode = ColorFmt::Hex;
|
||||
constexpr auto parse(std::format_parse_context& ctx) {
|
||||
auto it = ctx.begin();
|
||||
auto end = ctx.end();
|
||||
|
||||
if (it == end || *it == '}') return it;
|
||||
|
||||
if (check(it, end, 5, "rgbaf")) {
|
||||
mode = ColorFmt::Rgbaf;
|
||||
it += 5;
|
||||
} else if (check(it, end, 4, "rgba")) {
|
||||
mode = ColorFmt::Rgba;
|
||||
it += 4;
|
||||
} else if (check(it, end, 4, "rgbf")) {
|
||||
mode = ColorFmt::Rgbf;
|
||||
it += 4;
|
||||
} else if (check(it, end, 3, "rgb")) {
|
||||
mode = ColorFmt::Rgb;
|
||||
it += 3;
|
||||
} else if (check(it, end, 3, "hex")) {
|
||||
mode = ColorFmt::Hex;
|
||||
it += 3;
|
||||
} else {
|
||||
throw std::format_error("invalid format for PD::Color");
|
||||
}
|
||||
|
||||
if (it == end || *it != '}')
|
||||
throw std::format_error("invalid format for PD::Color");
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const PD::Color& value, FormatContext& ctx) const {
|
||||
switch (mode) {
|
||||
case ColorFmt::Hex:
|
||||
return std::format_to(ctx.out(), "#{:02X}{:02X}{:02X}{:02X}", value.r,
|
||||
value.g, value.b, value.a);
|
||||
case ColorFmt::Rgb:
|
||||
return std::format_to(ctx.out(), "{}, {}, {}", value.r, value.g,
|
||||
value.b);
|
||||
case ColorFmt::Rgba:
|
||||
return std::format_to(ctx.out(), "{}, {}, {}, {}", value.r, value.g,
|
||||
value.b, value.a);
|
||||
case ColorFmt::Rgbf:
|
||||
return std::format_to(ctx.out(), "{}, {}, {}", value.rf(), value.gf(),
|
||||
value.bf());
|
||||
case ColorFmt::Rgbaf:
|
||||
return std::format_to(ctx.out(), "{}, {}, {}, {}", value.rf(),
|
||||
value.gf(), value.bf(), value.af());
|
||||
default:
|
||||
return ctx.out();
|
||||
}
|
||||
}
|
||||
|
||||
constexpr bool check(std::format_parse_context::const_iterator it,
|
||||
std::format_parse_context::const_iterator end,
|
||||
size_t len, const char* what) {
|
||||
return (end - it >= static_cast<std::ptrdiff_t>(len) &&
|
||||
std::string_view(it, len) == what);
|
||||
}
|
||||
};
|
||||
@@ -25,7 +25,7 @@ SOFTWARE.
|
||||
|
||||
// This file is based on fvec4
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
#include <pd/core/vec4.hpp>
|
||||
|
||||
namespace PD {
|
||||
|
||||
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
#include <pd/core/vec3.hpp>
|
||||
|
||||
namespace PD {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename T, typename Alloc = std::allocator<T>>
|
||||
|
||||
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
@@ -92,9 +92,7 @@ PD_API const std::string PathRemoveExtension(const std::string& path);
|
||||
*/
|
||||
template <typename T>
|
||||
inline const std::string ToHex(const T& v) {
|
||||
std::stringstream s;
|
||||
s << "0x" << std::setfill('0') << std::setw(sizeof(v) * 2) << std::hex << v;
|
||||
return s.str();
|
||||
return std::format("{0:0{1}X}", v, sizeof(v) * 2);
|
||||
}
|
||||
/**
|
||||
* Generate a Hash out of a string
|
||||
@@ -107,24 +105,22 @@ PD_API u32 FastHash(const std::string& s);
|
||||
* Based on their Macros
|
||||
* @return CompilerName: Version
|
||||
*/
|
||||
inline const std::string GetCompilerVersion() {
|
||||
/// As the function looks like this Project is meant to
|
||||
/// Be ported to other systems as well
|
||||
std::stringstream res;
|
||||
inline const char* GetCompilerVersion() {
|
||||
/// As the function looks like this Project is meant to
|
||||
/// Be ported to other systems as well
|
||||
#define __mks(x) #x
|
||||
#define mkstring(x) __mks(x)
|
||||
#ifdef __clang__ // Check clang first
|
||||
res << "Clang: " << __clang_major__ << ".";
|
||||
res << __clang_minor__ << ".";
|
||||
res << __clang_patchlevel__;
|
||||
return "Clang: " mkstring(__clang_major__) "." mkstring(
|
||||
__clang_minor__) "." mkstring(__clang_patchlevel__);
|
||||
#elif __GNUC__
|
||||
res << "GCC: " << __GNUC__;
|
||||
res << "." << __GNUC_MINOR__ << ".";
|
||||
res << __GNUC_PATCHLEVEL__;
|
||||
return "GCC: " mkstring(__GNUC__) "." mkstring(__GNUC_MINOR__) "." mkstring(
|
||||
__GNUC_PATCHLEVEL__);
|
||||
#elif _MSC_VER
|
||||
res << "MSVC: " << _MSC_VER;
|
||||
return "MSVC; " mkstring(_MSC_VER);
|
||||
#else
|
||||
res << "Unknown Compiler";
|
||||
return "Unknown Compiler";
|
||||
#endif
|
||||
return res.str();
|
||||
}
|
||||
} // namespace Strings
|
||||
class U8Iterator {
|
||||
|
||||
@@ -23,10 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
class OsDriver;
|
||||
/**
|
||||
* Timer class
|
||||
*/
|
||||
@@ -36,14 +35,12 @@ class PD_API Timer {
|
||||
* Constructor
|
||||
* @param auto_start [default true] sets if timer should start after creation
|
||||
*/
|
||||
Timer(OsDriver& os, bool auto_start = true);
|
||||
Timer(bool auto_start = true);
|
||||
/**
|
||||
* Unused Deconstructor
|
||||
*/
|
||||
~Timer() {}
|
||||
|
||||
PD_SHARED(Timer);
|
||||
|
||||
/**
|
||||
* Resume Timer if Paused
|
||||
*/
|
||||
@@ -82,7 +79,5 @@ class PD_API Timer {
|
||||
u64 pNow;
|
||||
/** Is Running */
|
||||
bool pIsRunning = false;
|
||||
/** Os Driver reference */
|
||||
OsDriver& pOs;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -23,10 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
class OsDriver;
|
||||
/**
|
||||
* Class to calculate Maximum/Minimum and Average Timings
|
||||
*/
|
||||
@@ -39,8 +38,6 @@ class TimeStats {
|
||||
TimeStats(int l) : len(l), val(l, 0) {}
|
||||
~TimeStats() = default;
|
||||
|
||||
PD_SHARED(TimeStats);
|
||||
|
||||
/**
|
||||
* Add a New Value to the list
|
||||
* @param v value to add
|
||||
@@ -152,11 +149,9 @@ namespace TT {
|
||||
class Res {
|
||||
public:
|
||||
/** Constructore that Inits a protocol at size of 60 frames */
|
||||
Res() : start(0), end(0) { protocol = TimeStats::New(60); }
|
||||
Res() : start(0), end(0), protocol(60) {}
|
||||
~Res() = default;
|
||||
|
||||
PD_SHARED(Res);
|
||||
|
||||
/**
|
||||
* Setter for the ID (Name)
|
||||
* @param v ID of the Trace
|
||||
@@ -184,7 +179,7 @@ class Res {
|
||||
void SetEnd(u64 v) {
|
||||
end = v;
|
||||
diff = end - start;
|
||||
protocol->Add(GetLastDiff());
|
||||
protocol.Add(GetLastDiff());
|
||||
}
|
||||
/**
|
||||
* Getter for the End Time
|
||||
@@ -201,7 +196,7 @@ class Res {
|
||||
* Get Protcol Reference
|
||||
* @return Protocol Ref
|
||||
*/
|
||||
TimeStats::Ref GetProtocol() { return protocol; }
|
||||
TimeStats& GetProtocol() { return protocol; }
|
||||
|
||||
private:
|
||||
/** Trace ID */
|
||||
@@ -213,18 +208,18 @@ class Res {
|
||||
/** Last Diff */
|
||||
u64 diff;
|
||||
/** Protocol */
|
||||
TimeStats::Ref protocol;
|
||||
TimeStats protocol;
|
||||
};
|
||||
/**
|
||||
* Begin a Trace
|
||||
* @param id Name of the Trace
|
||||
*/
|
||||
PD_API void Beg(OsDriver& os, const std::string& id);
|
||||
PD_API void Beg(const std::string& id);
|
||||
/**
|
||||
* End a Trace
|
||||
* @param id Name of the Trace
|
||||
*/
|
||||
PD_API void End(OsDriver& os, const std::string& id);
|
||||
PD_API void End(const std::string& id);
|
||||
/**
|
||||
* Collect Start end end of the trace by tracking
|
||||
* when the Scope object goes out of scope
|
||||
@@ -246,20 +241,18 @@ class Scope {
|
||||
* Constructor requiring a Name for the Trace
|
||||
* @param id Name of the Trace
|
||||
*/
|
||||
Scope(OsDriver& os, const std::string& id) : pOs(os) {
|
||||
Scope(const std::string& id) {
|
||||
this->ID = id;
|
||||
Beg(pOs, id);
|
||||
Beg(id);
|
||||
}
|
||||
/**
|
||||
* Deconstructor getting the end time when going out of scope
|
||||
*/
|
||||
~Scope() { End(pOs, ID); }
|
||||
~Scope() { End(ID); }
|
||||
|
||||
private:
|
||||
/** Trace Name/ID */
|
||||
std::string ID;
|
||||
/** Os Driver Reference */
|
||||
OsDriver& pOs;
|
||||
};
|
||||
} // namespace TT
|
||||
} // namespace PD
|
||||
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
#include <pd/core/vec2.hpp>
|
||||
#include <pd/core/vec3.hpp>
|
||||
#include <pd/core/vec4.hpp>
|
||||
|
||||
@@ -25,7 +25,7 @@ SOFTWARE.
|
||||
|
||||
// This file is generated by lazyvec 2.0.0
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
|
||||
@@ -25,7 +25,7 @@ SOFTWARE.
|
||||
|
||||
// This file is generated by lazyvec 2.0.0
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
// Extended includes (rename if you use other filenames/paths)
|
||||
#include <pd/core/vec2.hpp>
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ SOFTWARE.
|
||||
|
||||
// This file is generated by lazyvec 2.0.0
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/common.hpp>
|
||||
// Extended includes (rename if you use other filenames/paths)
|
||||
#include <pd/core/vec2.hpp>
|
||||
#include <pd/core/vec3.hpp>
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/drivers/os.hpp>
|
||||
|
||||
namespace PD {
|
||||
class PD_API Context {
|
||||
public:
|
||||
Context()
|
||||
: pOs(OsDriver::New()), pGfx(GfxDriver::New()), pHid(HidDriver::New()) {}
|
||||
~Context() {}
|
||||
|
||||
PD_RAW(Context);
|
||||
|
||||
static Context::Ref Create();
|
||||
|
||||
template <typename Driver>
|
||||
void UseGfxDriver(PDDriverData data) {
|
||||
static_assert(std::is_base_of<GfxDriver, Driver>::value,
|
||||
"Driver must extend GfxDriver");
|
||||
pGfx.reset();
|
||||
pGfx = Driver::New(data);
|
||||
}
|
||||
|
||||
template <typename Driver>
|
||||
void UseHidDriver(PDDriverData data) {
|
||||
static_assert(std::is_base_of<HidDriver, Driver>::value,
|
||||
"Driver must extend HidDriver");
|
||||
pHid.reset();
|
||||
pHid = Driver::New(data);
|
||||
}
|
||||
|
||||
template <typename Driver>
|
||||
void UseOsDriver(PDDriverData data) {
|
||||
static_assert(std::is_base_of<OsDriver, Driver>::value,
|
||||
"Driver must extend OsDriver");
|
||||
pOs.reset();
|
||||
pOs = Driver::New(data);
|
||||
}
|
||||
|
||||
PD::Li::Texture::Ref GetSolidTex();
|
||||
|
||||
OsDriver::Ref Os() { return pOs; }
|
||||
GfxDriver::Ref Gfx() { return pGfx; }
|
||||
HidDriver::Ref Hid() { return pHid; }
|
||||
|
||||
private:
|
||||
OsDriver::Ref pOs = nullptr;
|
||||
GfxDriver::Ref pGfx = nullptr;
|
||||
HidDriver::Ref pHid = nullptr;
|
||||
|
||||
PD::Li::Texture::Ref pSolidTex = nullptr;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,29 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/drivers/context.hpp>
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/drivers/os.hpp>
|
||||
#include <pd/drivers/os.hpp>
|
||||
@@ -1,119 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/drivers/types.hpp>
|
||||
#include <pd/core/mat.hpp>
|
||||
#include <pd/drivers/interface.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
using LiBackendFlags = PD::u32;
|
||||
enum LiBackendFlags_ {
|
||||
LiBackendFlags_None = 0,
|
||||
LiBackendFlags_FlipUV_Y = PD_BIT(0), // Essential for font loading
|
||||
LiBackendFlags_FlipUV_Y = 1 << 0, // Essential for font loading
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
// The backend api nobody asked for
|
||||
class GfxDriver2 {
|
||||
public:
|
||||
GfxDriver2(const std::string& name = "NullGfx") : pName(name) {};
|
||||
~GfxDriver2() = default;
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual void Draw(const PD::Li::CmdPool& pool) {}
|
||||
virtual void TexBind(PD::Li::TexAddress addr) {}
|
||||
virtual PD::Li::TexAddress TexLoad(
|
||||
const std::vector<PD::u8>& pixels, int w, int h,
|
||||
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
|
||||
PD::Li::Texture::Filter filter = PD::Li::Texture::Filter::LINEAR) {
|
||||
return 0;
|
||||
}
|
||||
virtual void TexDelete(PD::Li::TexAddress tex) {}
|
||||
|
||||
protected:
|
||||
const std::string pName;
|
||||
LiBackendFlags pFlags = 0;
|
||||
size_t CurrentIndex = 0;
|
||||
size_t CurrentVertex = 0;
|
||||
ivec2 ViewPort;
|
||||
using TextureID = ptr;
|
||||
enum class TextureFilter {
|
||||
Linear,
|
||||
Nearest,
|
||||
};
|
||||
class GfxDriver {
|
||||
|
||||
enum class TextureFormat {
|
||||
RGBA32,
|
||||
A8,
|
||||
};
|
||||
|
||||
class PD_API GfxDriver : public DriverInterface {
|
||||
public:
|
||||
GfxDriver(const std::string& name = "NullGfx") : pName(name) {}
|
||||
GfxDriver(PDDriverData data) : pName("NullGfx") {}
|
||||
~GfxDriver() = default;
|
||||
|
||||
PD_SHARED(GfxDriver);
|
||||
|
||||
void PostInit();
|
||||
GfxDriver(std::string_view name = "Default") : DriverInterface(name) {}
|
||||
virtual ~GfxDriver() {}
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual void NewFrame() {}
|
||||
|
||||
virtual void BindTex(Li::TexAddress addr) {}
|
||||
|
||||
virtual void RenderDrawData(const Li::CmdPool& Commands) {}
|
||||
|
||||
void SetViewPort(const ivec2& vp) { ViewPort = vp; }
|
||||
void SetViewPort(int w, int h) { ViewPort = PD::ivec2(w, h); }
|
||||
|
||||
virtual Li::Texture::Ref LoadTex(
|
||||
const std::vector<u8>& pixels, int w, int h,
|
||||
Li::Texture::Type type = Li::Texture::Type::RGBA32,
|
||||
Li::Texture::Filter filter = Li::Texture::Filter::LINEAR) {
|
||||
// Texture loading not supported (when this func not get override)
|
||||
return nullptr;
|
||||
virtual void Submit() {}
|
||||
virtual void BindTexture(TextureID id) {}
|
||||
virtual void Reset() {}
|
||||
virtual TextureID LoadTexture(const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) {}
|
||||
virtual void DeleteTexture(const TextureID& tex) {}
|
||||
void Draw(const std::vector<Li::Command>& commands) {
|
||||
CountCommands += commands.size();
|
||||
// Bind shader
|
||||
Projection = Mat4::Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f);
|
||||
// Shader Set Mtx
|
||||
size_t index = 0;
|
||||
while (index < commands.size()) {
|
||||
CurrentTex = commands[index].Tex;
|
||||
if (!CurrentTex) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void DestroyTex(PD::Li::Texture::Ref tex) {}
|
||||
|
||||
Li::Texture::Ref GetSolidTex() { return pSolid; }
|
||||
|
||||
const std::string& GetName() const { return pName; }
|
||||
|
||||
const std::string pName = "NullGfx";
|
||||
LiBackendFlags Flags = 0;
|
||||
ivec2 ViewPort;
|
||||
Mat4 Projection;
|
||||
Li::Texture::Ref pSolid;
|
||||
size_t CurrentVertex = 0;
|
||||
private:
|
||||
size_t CurrentIndex = 0;
|
||||
size_t CurrentVertex = 0;
|
||||
TextureID CurrentTex = 0;
|
||||
Mat4 Projection;
|
||||
ivec2 ViewPort;
|
||||
|
||||
/** Debug Variables */
|
||||
// Counters
|
||||
size_t CountDrawcalls = 0;
|
||||
size_t CountCommands = 0;
|
||||
size_t CountVertices = 0;
|
||||
size_t CountIndices = 0;
|
||||
};
|
||||
|
||||
// Optional Index counter
|
||||
u32 IndexCounter;
|
||||
// Optional Vertex counter
|
||||
u32 VertexCounter;
|
||||
// Optional Frame Counter
|
||||
u64 FrameCounter;
|
||||
// Draw calls counter
|
||||
u32 DrawCalls;
|
||||
// Command Counter
|
||||
u32 DrawCommands;
|
||||
class PD_API Gfx {
|
||||
public:
|
||||
Gfx() = default;
|
||||
~Gfx() = default;
|
||||
|
||||
template <typename T, typename... Args>
|
||||
static void UseDriver(Args&&... args) {
|
||||
// assert(driver == nullptr && "OS Driver already set");
|
||||
driver = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
static std::unique_ptr<GfxDriver> driver;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,267 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPHidE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/drivers/types.hpp>
|
||||
|
||||
namespace PD {
|
||||
/** Did not found a better solution yet sadly */
|
||||
namespace HidKb {
|
||||
// Lets use u128 here
|
||||
using KbKey = u128;
|
||||
constexpr static KbKey Kb_No = 0;
|
||||
constexpr static KbKey Kb_Escape = KbKey::Flag(0);
|
||||
constexpr static KbKey Kb_Q = KbKey::Flag(1);
|
||||
constexpr static KbKey Kb_W = KbKey::Flag(2);
|
||||
constexpr static KbKey Kb_E = KbKey::Flag(3);
|
||||
constexpr static KbKey Kb_R = KbKey::Flag(4);
|
||||
constexpr static KbKey Kb_T = KbKey::Flag(5);
|
||||
constexpr static KbKey Kb_Z = KbKey::Flag(6);
|
||||
constexpr static KbKey Kb_U = KbKey::Flag(7);
|
||||
constexpr static KbKey Kb_I = KbKey::Flag(8);
|
||||
constexpr static KbKey Kb_O = KbKey::Flag(9);
|
||||
constexpr static KbKey Kb_P = KbKey::Flag(10);
|
||||
constexpr static KbKey Kb_A = KbKey::Flag(11);
|
||||
constexpr static KbKey Kb_S = KbKey::Flag(12);
|
||||
constexpr static KbKey Kb_D = KbKey::Flag(13);
|
||||
constexpr static KbKey Kb_F = KbKey::Flag(14);
|
||||
constexpr static KbKey Kb_G = KbKey::Flag(15);
|
||||
constexpr static KbKey Kb_H = KbKey::Flag(16);
|
||||
constexpr static KbKey Kb_J = KbKey::Flag(17);
|
||||
constexpr static KbKey Kb_K = KbKey::Flag(18);
|
||||
constexpr static KbKey Kb_L = KbKey::Flag(19);
|
||||
constexpr static KbKey Kb_Y = KbKey::Flag(20);
|
||||
constexpr static KbKey Kb_X = KbKey::Flag(21);
|
||||
constexpr static KbKey Kb_C = KbKey::Flag(22);
|
||||
constexpr static KbKey Kb_V = KbKey::Flag(23);
|
||||
constexpr static KbKey Kb_B = KbKey::Flag(24);
|
||||
constexpr static KbKey Kb_N = KbKey::Flag(25);
|
||||
constexpr static KbKey Kb_M = KbKey::Flag(26);
|
||||
constexpr static KbKey Kb_1 = KbKey::Flag(27);
|
||||
constexpr static KbKey Kb_2 = KbKey::Flag(28);
|
||||
constexpr static KbKey Kb_3 = KbKey::Flag(29);
|
||||
constexpr static KbKey Kb_4 = KbKey::Flag(30);
|
||||
constexpr static KbKey Kb_5 = KbKey::Flag(31);
|
||||
constexpr static KbKey Kb_6 = KbKey::Flag(32);
|
||||
constexpr static KbKey Kb_7 = KbKey::Flag(33);
|
||||
constexpr static KbKey Kb_8 = KbKey::Flag(34);
|
||||
constexpr static KbKey Kb_9 = KbKey::Flag(35);
|
||||
constexpr static KbKey Kb_0 = KbKey::Flag(36);
|
||||
constexpr static KbKey Kb_F1 = KbKey::Flag(37);
|
||||
constexpr static KbKey Kb_F2 = KbKey::Flag(38);
|
||||
constexpr static KbKey Kb_F3 = KbKey::Flag(39);
|
||||
constexpr static KbKey Kb_F4 = KbKey::Flag(40);
|
||||
constexpr static KbKey Kb_F5 = KbKey::Flag(41);
|
||||
constexpr static KbKey Kb_F6 = KbKey::Flag(42);
|
||||
constexpr static KbKey Kb_F7 = KbKey::Flag(43);
|
||||
constexpr static KbKey Kb_F8 = KbKey::Flag(44);
|
||||
constexpr static KbKey Kb_F9 = KbKey::Flag(45);
|
||||
constexpr static KbKey Kb_F10 = KbKey::Flag(46);
|
||||
constexpr static KbKey Kb_F11 = KbKey::Flag(47);
|
||||
constexpr static KbKey Kb_F12 = KbKey::Flag(48);
|
||||
constexpr static KbKey Kb_MouseLeft = KbKey::Flag(120);
|
||||
} // namespace HidKb
|
||||
|
||||
class PD_API HidDriver {
|
||||
public:
|
||||
enum Flags : u32 {
|
||||
Flags_None = 0,
|
||||
FLags_HasGamepad = 1 << 0,
|
||||
Flags_HasKeyboard = 1 << 1,
|
||||
Flags_HasTouch = 1 << 2,
|
||||
Flags_HasMouse = 1 << 3,
|
||||
};
|
||||
// Todo: Name to GpKey (GamepadKey)
|
||||
/** Key [Controller] */
|
||||
enum Key : u32 {
|
||||
No = 0, ///< No Key
|
||||
A = 1 << 0, ///< A
|
||||
B = 1 << 1, ///< B
|
||||
X = 1 << 2, ///< X
|
||||
Y = 1 << 3, ///< Y
|
||||
Start = 1 << 4, ///< Start
|
||||
Select = 1 << 5, ///< Select
|
||||
L = 1 << 6, ///< L
|
||||
R = 1 << 7, ///< R
|
||||
DUp = 1 << 8, ///< Dpad Up
|
||||
DDown = 1 << 9, ///< Dpad down
|
||||
DLeft = 1 << 10, ///< Dpad left
|
||||
DRight = 1 << 11, ///< Dpad right
|
||||
CPUp = 1 << 12, ///< Cpad up
|
||||
CPDown = 1 << 13, ///< cpad down
|
||||
CPLeft = 1 << 14, ///< cpad left
|
||||
CPRight = 1 << 15, ///< Cpad right
|
||||
CSUp = 1 << 16, ///< Cstick up
|
||||
CSDown = 1 << 17, ///< cstick down
|
||||
CSLeft = 1 << 18, ///< cstick left
|
||||
CSRight = 1 << 19, ///< cstick right
|
||||
ZL = 1 << 20, ///< ZL
|
||||
ZR = 1 << 21, ///< ZR
|
||||
Touch = 1 << 22, ///< Touch
|
||||
Up = DUp | CPUp, ///< DPad or CPad Up
|
||||
Down = DDown | CPDown, ///< DPad or CPad Down
|
||||
Left = DLeft | CPLeft, ///< DPad or CPad Left
|
||||
Right = DRight | CPRight, ///< DPad or CPad Right
|
||||
};
|
||||
|
||||
using KbKey = HidKb::KbKey;
|
||||
|
||||
/** Event */
|
||||
enum Event {
|
||||
Event_Null,
|
||||
Event_Down, ///< Key Pressed
|
||||
Event_Held, ///< Key Held
|
||||
Event_Up, ///< Key released
|
||||
};
|
||||
|
||||
HidDriver(const std::string& name = "NullHid") : pName(name) {}
|
||||
HidDriver(PDDriverData data) : pName("NullHid") {}
|
||||
virtual ~HidDriver() = default;
|
||||
PD_SHARED(HidDriver);
|
||||
|
||||
/**
|
||||
* Get Mouse Position
|
||||
* @return Mouse pos
|
||||
*/
|
||||
fvec2 MousePos() const {
|
||||
return pMouse[0];
|
||||
} /**
|
||||
* Get Last Mouse Position (from last frame)
|
||||
* @return Mouse pos
|
||||
*/
|
||||
fvec2 MousePosLast() const { return pMouse[1]; }
|
||||
|
||||
/**
|
||||
* Check for a Button Event
|
||||
* @param e Event Type
|
||||
* @param keys Keys to check for
|
||||
* @return if key(s) doing the requiested event
|
||||
*/
|
||||
bool IsEvent(Event e, Key keys);
|
||||
bool IsEvent(Event e, KbKey key);
|
||||
/**
|
||||
* Check for Key Press Event
|
||||
* @param keys set of keys
|
||||
* @return true if key is pressed
|
||||
*/
|
||||
bool IsDown(Key keys) const { return KeyEvents[0].at(Event_Down) & keys; }
|
||||
/**
|
||||
* Check for Key Held Event
|
||||
* @param keys set of keys
|
||||
* @return true if key is held
|
||||
*/
|
||||
bool IsHeld(Key keys) const { return KeyEvents[0].at(Event_Held) & keys; }
|
||||
/**
|
||||
* Check for Key Release Event
|
||||
* @param keys set of keys
|
||||
* @return true if key is released
|
||||
*/
|
||||
bool IsUp(Key keys) const { return KeyEvents[0].at(Event_Up) & keys; }
|
||||
|
||||
/**
|
||||
* Sett all keyevents to 0
|
||||
*/
|
||||
void Clear() {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
KeyEvents[i][Event_Down] = 0;
|
||||
KeyEvents[i][Event_Up] = 0;
|
||||
KeyEvents[i][Event_Held] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock input driver
|
||||
* @param v lock or not lock
|
||||
*/
|
||||
void Lock(bool v) {
|
||||
if (v != pLocked) {
|
||||
SwapTab();
|
||||
}
|
||||
pLocked = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Driver is locked
|
||||
* @return true if locked
|
||||
*/
|
||||
bool Locked() const { return pLocked; }
|
||||
|
||||
/**
|
||||
* Lock Input Driver
|
||||
*/
|
||||
void Lock() {
|
||||
if (!pLocked) {
|
||||
SwapTab();
|
||||
}
|
||||
pLocked = true;
|
||||
}
|
||||
/**
|
||||
* Unlock Input Driver
|
||||
*/
|
||||
void Unlock() {
|
||||
if (pLocked) {
|
||||
SwapTab();
|
||||
}
|
||||
pLocked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template Update Function for a device specific driver
|
||||
*/
|
||||
virtual void Update();
|
||||
/**
|
||||
* Get Text from Keyboard
|
||||
*/
|
||||
virtual void GetInputStr(std::string& str) {}
|
||||
|
||||
const std::string& GetName() const { return pName; }
|
||||
|
||||
/** Data Section */
|
||||
|
||||
/** Backend Identification Name */
|
||||
const std::string pName;
|
||||
|
||||
/** Flags */
|
||||
u32 Flags = 0;
|
||||
|
||||
/** Key Binds Map */
|
||||
std::unordered_map<u32, u32> pBinds;
|
||||
std::unordered_map<u128, u128> pKbBinds;
|
||||
/** Swap Tabe Function */
|
||||
void SwapTab();
|
||||
/** Using 2 Positions for Current and Last */
|
||||
fvec2 pMouse[2];
|
||||
/** Lock State */
|
||||
bool pLocked = false;
|
||||
/** Key Event Table Setup */
|
||||
std::unordered_map<Event, u32> KeyEvents[2];
|
||||
/** Keyboard Key Event Table Setup */
|
||||
std::unordered_map<Event, u128> KbKeyEvents[2];
|
||||
};
|
||||
namespace Hid {
|
||||
using Event = HidDriver::Event;
|
||||
using Key = HidDriver::Key;
|
||||
} // namespace Hid
|
||||
} // namespace PD
|
||||
16
include/pd/drivers/interface.hpp
Normal file
16
include/pd/drivers/interface.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
class DriverInterface {
|
||||
public:
|
||||
DriverInterface(const std::string_view& name) : pName(name) {}
|
||||
virtual ~DriverInterface() {}
|
||||
|
||||
const char* GetName() const { return pName.data(); }
|
||||
|
||||
private:
|
||||
std::string_view pName;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,53 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/core/timetrace.hpp>
|
||||
#include <pd/drivers/types.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
#include <pd/drivers/interface.hpp>
|
||||
|
||||
namespace PD {
|
||||
using TraceMap = std::map<std::string, TT::Res::Ref>;
|
||||
|
||||
class PD_API OsDriver {
|
||||
class PD_API OsDriver : public DriverInterface {
|
||||
public:
|
||||
OsDriver(const std::string& name = "StdPd") : pName(name) {}
|
||||
OsDriver(PDDriverData data) : pName("StdPd") {}
|
||||
virtual ~OsDriver() = default;
|
||||
PD_SHARED(OsDriver);
|
||||
OsDriver(std::string_view name = "Default") : DriverInterface(name) {}
|
||||
virtual ~OsDriver() {}
|
||||
|
||||
virtual u64 GetTime();
|
||||
virtual u64 GetNanoTime();
|
||||
TraceMap& GetTraceMap();
|
||||
TT::Res::Ref& GetTraceRef(const std::string& id);
|
||||
bool TraceExist(const std::string& id);
|
||||
const std::string& GetName() const { return pName; }
|
||||
virtual u64 GetTime() const;
|
||||
virtual u64 GetTimeNano() const;
|
||||
};
|
||||
|
||||
TraceMap pTraces;
|
||||
class PD_API Os {
|
||||
public:
|
||||
Os() = default;
|
||||
~Os() = default;
|
||||
|
||||
template <typename T, typename... Args>
|
||||
static void UseDriver(Args&&... args) {
|
||||
// assert(driver == nullptr && "OS Driver already set");
|
||||
driver = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static u64 GetTime() { return driver->GetTime(); }
|
||||
static u64 GetTimeNano() { return driver->GetTimeNano(); }
|
||||
|
||||
private:
|
||||
const std::string pName = "StdPd";
|
||||
static std::unique_ptr<OsDriver> driver;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,3 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
using PDDriverData = void*;
|
||||
24962
include/pd/external/json.hpp
vendored
24962
include/pd/external/json.hpp
vendored
File diff suppressed because it is too large
Load Diff
7988
include/pd/external/stb_image.hpp
vendored
7988
include/pd/external/stb_image.hpp
vendored
File diff suppressed because it is too large
Load Diff
5079
include/pd/external/stb_truetype.hpp
vendored
5079
include/pd/external/stb_truetype.hpp
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,88 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
class PD_API Image {
|
||||
public:
|
||||
enum Format {
|
||||
RGBA, // bpp == 4
|
||||
RGB, // bpp == 3
|
||||
RGB565, // bpp == 2 (not supported in laoding)
|
||||
BGR, // bpp == 3
|
||||
ABGR, // bpp == 4
|
||||
BGRA, // bpp == 4
|
||||
};
|
||||
Image() = default;
|
||||
Image(const std::string& path) { this->Load(path); }
|
||||
Image(const std::vector<u8>& buf) { this->Load(buf); }
|
||||
Image(const std::vector<u8>& buf, int w, int h, int bpp = 4) {
|
||||
this->Copy(buf, w, h, bpp);
|
||||
}
|
||||
~Image() = default;
|
||||
|
||||
PD_SHARED(Image)
|
||||
|
||||
void Load(const std::string& path);
|
||||
void Load(const std::vector<u8>& buf);
|
||||
void Copy(const std::vector<u8>& buf, int w, int h, int bpp = 4);
|
||||
|
||||
std::vector<PD::u8>& GetBuffer() { return pBuffer; }
|
||||
std::vector<PD::u8> GetBuffer() const { return pBuffer; }
|
||||
|
||||
int Width() const { return pWidth; }
|
||||
int Height() const { return pHeight; }
|
||||
ivec2 Size() const { return ivec2(pWidth, pHeight); }
|
||||
Format Fmt() const { return pFmt; }
|
||||
|
||||
void FlipVertical();
|
||||
void FlipHorizontal();
|
||||
|
||||
u8& operator[](int idx) { return pBuffer[idx]; }
|
||||
u8 operator[](int idx) const { return pBuffer[idx]; }
|
||||
|
||||
// Probably these make th eabove ones useless
|
||||
|
||||
operator std::vector<PD::u8>&() { return pBuffer; }
|
||||
operator std::vector<PD::u8>() const { return pBuffer; }
|
||||
|
||||
static void Convert(Image::Ref img, Image::Format dst);
|
||||
static void ReTile(Image::Ref img,
|
||||
std::function<u32(int x, int y, int w)> src,
|
||||
std::function<u32(int x, int y, int w)> dst);
|
||||
static int Fmt2Bpp(Format fmt);
|
||||
|
||||
std::vector<PD::u8> pBuffer;
|
||||
int pWidth;
|
||||
int pHeight;
|
||||
Format pFmt = Format::RGBA;
|
||||
|
||||
private:
|
||||
/** Leftover variable used for stbi_load */
|
||||
int fmt = 0;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,71 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Namepace containing functions to blur images
|
||||
*/
|
||||
namespace ImgBlur {
|
||||
/**
|
||||
* Function to create Gaussian Kernel List
|
||||
* @param radius Rasius to use
|
||||
* @param si sigma value to use
|
||||
* @return list of kernel values
|
||||
*/
|
||||
PD_API std::vector<float> GaussianKernel(int radius, float si);
|
||||
/**
|
||||
* Gaussian Blur for basic Image Buffer
|
||||
* @param buf Image Buffer (unsigned char)
|
||||
* @param w width of the image
|
||||
* @param h width of the image
|
||||
* @param radius Blur radius
|
||||
* @param si Blur sigma
|
||||
* @param idxfn Indexing function
|
||||
*/
|
||||
PD_API void GaussianBlur(
|
||||
std::vector<u8>& buf, int w, int h, float radius, float si,
|
||||
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
|
||||
return y * w + x;
|
||||
});
|
||||
/**
|
||||
* Advanced func to access memory directly
|
||||
* @param buf Referenvce to the buffer
|
||||
* @param w width of the image
|
||||
* @param h width of the image
|
||||
* @param bpp Bytes per Pixels (RGB[A], RGB565, etc)
|
||||
* @param radius Blur radius
|
||||
* @param si Blur sigma
|
||||
* @param idxfn Indexing function
|
||||
*/
|
||||
PD_API void GaussianBlur(
|
||||
void* buf, int w, int h, int bpp, float radius, float si,
|
||||
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
|
||||
return y * w + x;
|
||||
});
|
||||
} // namespace ImgBlur
|
||||
} // namespace PD
|
||||
@@ -1,58 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/image/image.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Namespace containing function to convert images
|
||||
*/
|
||||
namespace ImgConvert {
|
||||
/**
|
||||
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
|
||||
* to every pixel
|
||||
* @param out Result List
|
||||
* @param in Input Buffer List (rgb24)
|
||||
* @param w width of the image
|
||||
* @param h height of the image
|
||||
*/
|
||||
PD_API
|
||||
void RGB24toRGBA32(std::vector<PD::u8>& out, const std::vector<u8>& in,
|
||||
const int& w, const int& h);
|
||||
PD_API
|
||||
void RGB32toRGBA24(std::vector<u8>& out, const std::vector<u8>& in,
|
||||
const int& w, const int& h);
|
||||
/**
|
||||
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
|
||||
* @param buf Buffer to convert
|
||||
* @param w width
|
||||
* @param h height
|
||||
*/
|
||||
PD_API void Reverse32(std::vector<u8>& buf, const int& w, const int& h);
|
||||
PD_API void ReverseBuf(std::vector<u8>& buf, size_t bpp, int w, int h);
|
||||
} // namespace ImgConvert
|
||||
} // namespace PD
|
||||
@@ -1,103 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
#include <pd/core/pool.hpp>
|
||||
#include <pd/lithium/vertex.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
class Command {
|
||||
public:
|
||||
Command() = default;
|
||||
~Command() = default;
|
||||
Command() {}
|
||||
~Command() {}
|
||||
|
||||
PD_RAW(Command);
|
||||
|
||||
Command& AddIdx(const u16& idx) {
|
||||
IndexBuffer.push_back(VertexBuffer.size() + idx);
|
||||
return *this;
|
||||
}
|
||||
Command& AddIdxs(const u16& a, const u16& b, const u16& c) {
|
||||
IndexBuffer.push_back(VertexBuffer.size() + a);
|
||||
IndexBuffer.push_back(VertexBuffer.size() + b);
|
||||
IndexBuffer.push_back(VertexBuffer.size() + c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Command& AddVtx(const Vertex& v) {
|
||||
VertexBuffer.push_back(std::move(v));
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
VertexBuffer.clear();
|
||||
IndexBuffer.clear();
|
||||
Index = 0;
|
||||
Layer = 0;
|
||||
Tex = 0;
|
||||
ScissorOn = false;
|
||||
ScissorRect = ivec4();
|
||||
}
|
||||
|
||||
std::vector<Vertex> VertexBuffer;
|
||||
std::vector<u16> IndexBuffer;
|
||||
ivec4 ScissorRect;
|
||||
bool ScissorOn = false;
|
||||
int Layer = 0;
|
||||
int Index = 0;
|
||||
TexAddress Tex;
|
||||
};
|
||||
|
||||
class PD_API CmdPool {
|
||||
public:
|
||||
CmdPool() {}
|
||||
~CmdPool() {}
|
||||
|
||||
Command::Ref NewCmd();
|
||||
void Init(size_t initial_size);
|
||||
void Deinit();
|
||||
void Resize(size_t nulen);
|
||||
void Reset();
|
||||
Command::Ref GetCmd(size_t idx) const;
|
||||
Command::Ref GetCmd(size_t idx);
|
||||
size_t Size() const;
|
||||
size_t Cap() const;
|
||||
void Merge(CmdPool& p);
|
||||
void Copy(CmdPool& p);
|
||||
void Sort();
|
||||
|
||||
private:
|
||||
static bool pTheOrder(const Command::Ref& a, const Command::Ref& b);
|
||||
friend class DrawList;
|
||||
Command::Ref* begin() { return &pPool[0]; }
|
||||
Command::Ref* end() { return &pPool[pPoolIdx - 1]; }
|
||||
std::vector<Command::Ref> pPool;
|
||||
u32 pPoolIdx = 0;
|
||||
int Layer = 0;
|
||||
ptr Tex = 0;
|
||||
Vertex* FirstVertex = nullptr;
|
||||
u16* FirstIndex = nullptr;
|
||||
size_t VertexCount;
|
||||
size_t IndexCount;
|
||||
|
||||
PD::Pool<Vertex>* pVpool;
|
||||
PD::Pool<u16>* pIpool;
|
||||
};
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
@@ -1,224 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/font.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
|
||||
/** Path Rect Flags */
|
||||
using LiPathRectFlags = PD::u32;
|
||||
|
||||
/** Setup for everything (oder so) */
|
||||
enum LiPathRectFlags_ : PD::u32 {
|
||||
LiPathRectFlags_None = 0,
|
||||
LiPathRectFlags_KeepTopLeft = PD_BIT(0),
|
||||
LiPathRectFlags_KeepTopRight = PD_BIT(1),
|
||||
LiPathRectFlags_KeepBotRight = PD_BIT(2),
|
||||
LiPathRectFlags_KeepBotLeft = PD_BIT(3),
|
||||
LiPathRectFlags_KeepTop = PD_BIT(0) | PD_BIT(1),
|
||||
LiPathRectFlags_KeepBot = PD_BIT(2) | PD_BIT(3),
|
||||
LiPathRectFlags_KeepLeft = PD_BIT(0) | PD_BIT(3),
|
||||
LiPathRectFlags_KeepRight = PD_BIT(1) | PD_BIT(2),
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
class PD_API DrawList {
|
||||
public:
|
||||
DrawList(Context& ctx, int initial_size = 64);
|
||||
~DrawList();
|
||||
|
||||
/** Require Copy and Move Constructors */
|
||||
|
||||
DrawList(const DrawList&) = delete;
|
||||
DrawList& operator=(const DrawList&) = delete;
|
||||
|
||||
DrawList(DrawList&&) noexcept = default;
|
||||
DrawList& operator=(DrawList&&) noexcept = default;
|
||||
|
||||
PD_SHARED(DrawList);
|
||||
|
||||
/**
|
||||
* Append an input drawlist on top of this one
|
||||
* This Function will clear the Input list to make sure
|
||||
* That the moved memory blocks don't get used
|
||||
* @param list DrawList to move into current
|
||||
*/
|
||||
void Merge(DrawList::Ref list);
|
||||
/**
|
||||
* Copy another drawlist to this drawist.
|
||||
* This is important for static prerendered Drawlists
|
||||
* @param list DrawList Reference to copy from
|
||||
*/
|
||||
void Copy(DrawList::Ref list);
|
||||
/**
|
||||
* Optimize a Drawlist to a more or less perfect order
|
||||
* to reduce drawcall overhead... This function also uses
|
||||
* the Layersystem to keep specific stuff in the correct order
|
||||
*/
|
||||
void Optimize();
|
||||
|
||||
Command::Ref GetNewCmd();
|
||||
void Clear();
|
||||
void Layer(int l) { this->pPool.Layer = l; }
|
||||
int Layer() { return this->pPool.Layer; }
|
||||
void LayerUp() { this->pPool.Layer++; }
|
||||
void LayerDown() { this->pPool.Layer--; }
|
||||
|
||||
void SetFont(Font::Ref font) { pCurrentFont = font; }
|
||||
void SetFontScale(float scale) { pFontScale = scale; }
|
||||
|
||||
void DrawSolid();
|
||||
void DrawTexture(Texture::Ref tex);
|
||||
|
||||
// SECTION: Draw API //
|
||||
|
||||
void DrawRect(const fvec2& pos, const fvec2& size, u32 color,
|
||||
int thickness = 1);
|
||||
void DrawRectFilled(const fvec2& pos, const fvec2& size, u32 color);
|
||||
void DrawTriangle(const fvec2& a, const fvec2& b, const fvec2& c, u32 color,
|
||||
int thickness = 1);
|
||||
void DrawTriangleFilled(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||
u32 color);
|
||||
void DrawCircle(const fvec2& center, float rad, u32 color, int num_segments,
|
||||
int thickness = 1);
|
||||
void DrawCircleFilled(const fvec2& center, float rad, u32 color,
|
||||
int num_segments);
|
||||
void DrawText(const fvec2& p, const std::string& text, u32 color);
|
||||
/**
|
||||
* Extended Draw Text Function
|
||||
*/
|
||||
void DrawTextEx(const fvec2& p, const std::string& text, u32 color,
|
||||
LiTextFlags flags, const fvec2& box = fvec2(0.f));
|
||||
void DrawLine(const fvec2& a, const fvec2& b, u32 color, int t = 1);
|
||||
/**
|
||||
* Take list of points and display it as a line on screen
|
||||
* @param points List of Positions
|
||||
* @param clr Color of the Line
|
||||
* @param flags Additional Flags (Close for go back to starting point)
|
||||
* @param thickness Thickness of the Line
|
||||
*/
|
||||
void DrawPolyLine(const std::vector<fvec2>& points, u32 clr, u32 flags = 0,
|
||||
int thickness = 1);
|
||||
/**
|
||||
* Take a List ofpoints and display it as Filled Shape
|
||||
* @note Keep in mind to setup the list of points clockwise
|
||||
* @param points List of Points
|
||||
* @param clr Color of the shape
|
||||
*/
|
||||
void DrawConvexPolyFilled(const std::vector<fvec2>& points, u32 clr);
|
||||
|
||||
// SECTION: PATH API //
|
||||
|
||||
/**
|
||||
* Function to reserve Memory to prevent overhead on
|
||||
* pusing a lot of points with PathNext
|
||||
* @param num_points Number of Positions you want to add
|
||||
*/
|
||||
void PathReserve(size_t num_points) {
|
||||
pPath.reserve(pPath.size() + num_points);
|
||||
}
|
||||
/**
|
||||
* Clear current Path
|
||||
* @note PathStroke and PathFill will automatically clear
|
||||
*/
|
||||
void PathClear() { pPath.clear(); }
|
||||
/**
|
||||
* Add a Point to the Path
|
||||
* @note Keep in mind that this function is used for
|
||||
* setting the starting point
|
||||
* @param v Position to add
|
||||
*/
|
||||
void PathAdd(const fvec2& v) { pPath.push_back(v); }
|
||||
/**
|
||||
* Add a Point to the Path
|
||||
* @note Keep in mind that this function is used for
|
||||
* setting the starting point
|
||||
* @param x X Position to add
|
||||
* @param y Y Position to add
|
||||
*/
|
||||
void PathAdd(float x, float y) { pPath.push_back(fvec2(x, y)); }
|
||||
/**
|
||||
* Path Stroke Create Line from point to point
|
||||
* @note For Primitives like Rect or Triangle mak sure to use
|
||||
* UI7DrawFlags_Close to add a line back to the starting point
|
||||
* @param clr Color od the line
|
||||
* @param thickness Thickness of the line
|
||||
* @param flags Additional Drawflags
|
||||
*/
|
||||
void PathStroke(u32 clr, int thickness = 1, u32 flags = 0) {
|
||||
DrawPolyLine(pPath, clr, flags, thickness);
|
||||
pPath.clear();
|
||||
}
|
||||
/**
|
||||
* Fill a Path with a Color
|
||||
* @note **IMPORTANT: ** Paths need to be setup clockwise
|
||||
* to be rendered correctly
|
||||
* @param clr Fill Color
|
||||
*/
|
||||
void PathFill(u32 clr) {
|
||||
DrawConvexPolyFilled(pPath, clr);
|
||||
pPath.clear();
|
||||
}
|
||||
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
|
||||
int segments);
|
||||
void PathFastArcToN(const fvec2& c, float r, float amin, float amax, int s);
|
||||
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
|
||||
/// @param a Top Left Position
|
||||
/// @param b Bottom Right Position
|
||||
/// @param rounding rounding
|
||||
void PathRect(fvec2 a, fvec2 b, float rounding = 0.f);
|
||||
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
|
||||
/// @param a Top Left Position
|
||||
/// @param b Bottom Right Position
|
||||
/// @param rounding rounding
|
||||
/// @param flags DrawFlags (for special rounding rules)
|
||||
void PathRectEx(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0);
|
||||
|
||||
void PushClipRect(const fvec4& cr) { pClipRects.push(cr); }
|
||||
void PopClipRect() {
|
||||
if (pClipRects.empty()) {
|
||||
return;
|
||||
}
|
||||
pClipRects.pop();
|
||||
}
|
||||
const CmdPool& Data() const { return pPool; }
|
||||
/** One linear Clip rect Setup */
|
||||
void pClipCmd(Command* cmd);
|
||||
|
||||
/** Data Section */
|
||||
|
||||
std::stack<fvec4> pClipRects;
|
||||
float pFontScale = 0.7f;
|
||||
Font::Ref pCurrentFont;
|
||||
Texture::Ref CurrentTex;
|
||||
CmdPool pPool;
|
||||
std::vector<fvec2> pPath;
|
||||
u32 pNumIndices = 0;
|
||||
u32 pNumVertices = 0;
|
||||
Context* pCtx = nullptr;
|
||||
};
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
@@ -1,136 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
|
||||
using LiTextFlags = PD::u32;
|
||||
enum LiTextFlags_ {
|
||||
LiTextFlags_None = 0, ///< Do nothing
|
||||
LiTextFlags_AlignRight = 1 << 0, ///< Align Right of position
|
||||
LiTextFlags_AlignMid = 1 << 1, ///< Align in the middle of pos and box
|
||||
LiTextFlags_Shaddow = 1 << 2, ///< Draws the text twice to create shaddow
|
||||
LiTextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
|
||||
LiTextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
|
||||
LiTextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
|
||||
LiTextFlags_NoOOS = 1 << 6, ///< No Out of Screen Rendering
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
class Context;
|
||||
namespace Li {
|
||||
class DrawList;
|
||||
class PD_API Font {
|
||||
public:
|
||||
/** Codepoint Data holder */
|
||||
struct Codepoint {
|
||||
u32 pCodepoint = 0;
|
||||
fvec4 SimpleUV;
|
||||
Texture::Ref Tex;
|
||||
fvec2 Size;
|
||||
float Offset = 0.f;
|
||||
bool pInvalid = false;
|
||||
};
|
||||
|
||||
/** Constructore doesnt need Backand anymore */
|
||||
Font(Context& ctx) : pCtx(ctx) {}
|
||||
~Font() = default;
|
||||
|
||||
PD_SHARED(Font);
|
||||
|
||||
/**
|
||||
* Load a TTF File
|
||||
* @param path Path to the TTF file
|
||||
* @param px_height Pixelheight of the codepoints (limit by 64)
|
||||
*/
|
||||
void LoadTTF(const std::string& path, int px_height = 32);
|
||||
/**
|
||||
* Load a TTF File from Memory
|
||||
* @param data File data
|
||||
* @param px_height Pixelheight of the codepoints (limit by 64)
|
||||
*/
|
||||
void LoadTTF(const std::vector<u8>& data, int px_height = 32);
|
||||
/**
|
||||
* Function that loads a default integrated font...
|
||||
* This will only work if PD_LI_INCLUDE_FONTS was set
|
||||
* on lithium build cause otherwise the font data is not included
|
||||
*/
|
||||
void LoadDefaultFont(int id = 0, int pixel_height = 32);
|
||||
/**
|
||||
* Getter for Codepoint reference
|
||||
* @return codepoint dataholder reference
|
||||
*/
|
||||
Codepoint& GetCodepoint(u32 c);
|
||||
|
||||
/**
|
||||
* Get Text Bounding Box
|
||||
*/
|
||||
fvec2 GetTextBounds(const std::string& text, float scale);
|
||||
/**
|
||||
* Extended Draw Text Function that vreates a Command List
|
||||
*/
|
||||
void CmdTextEx(DrawList& dl, const fvec2& pos, u32 color, float scale,
|
||||
const std::string& text, LiTextFlags flags = 0,
|
||||
const fvec2& box = 0);
|
||||
|
||||
/**
|
||||
* Garbage collection for TextMapSystem
|
||||
*/
|
||||
void CleanupTMS();
|
||||
/**
|
||||
* Utility function to create a font atlas
|
||||
* During TTF loading (Internal and should not be called)
|
||||
*/
|
||||
void pMakeAtlas(bool final, std::vector<u8>& font_tex, int texszs,
|
||||
PD::Li::Texture::Ref tex);
|
||||
std::string pWrapText(const std::string& txt, float scale,
|
||||
const PD::fvec2& max, PD::fvec2& dim);
|
||||
std::string pShortText(const std::string& txt, float scale,
|
||||
const PD::fvec2& max, PD::fvec2& dim);
|
||||
|
||||
/** Data Section */
|
||||
int PixelHeight;
|
||||
int DefaultPixelHeight = 24;
|
||||
std::vector<Texture::Ref> Textures;
|
||||
/**
|
||||
* 32Bit Codepoint Dataholder reference map
|
||||
* **Now using unordered map**
|
||||
*/
|
||||
std::unordered_map<u32, Codepoint> CodeMap;
|
||||
/** TMS */
|
||||
struct TMELEM {
|
||||
PD::u32 ID;
|
||||
PD::fvec2 Size;
|
||||
std::string Text;
|
||||
u64 TimeStamp;
|
||||
};
|
||||
std::unordered_map<u32, TMELEM> pTMS;
|
||||
Context& pCtx;
|
||||
};
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
@@ -1,41 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef PD_LI_INCLUDE_FONTS
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
|
||||
/** Generated with pdfm */
|
||||
namespace PD {
|
||||
struct FontFileData {
|
||||
std::string Name;
|
||||
u32 StartOff;
|
||||
u32 Size;
|
||||
};
|
||||
extern FontFileData pFontData[];
|
||||
extern size_t pNumFonts;
|
||||
extern PD::u8 pFontsDataRaw[];
|
||||
} // namespace PD
|
||||
#endif
|
||||
@@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/drawlist.hpp>
|
||||
#include <pd/lithium/font.hpp>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
#include <pd/lithium/renderer.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
@@ -1,149 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
class Rect {
|
||||
public:
|
||||
Rect() : Top(0), Bot(0) {}
|
||||
~Rect() = default;
|
||||
/**
|
||||
* Constructor that initializes the rectangle using top and bottom positions.
|
||||
* @param t Top left and right corner positions.
|
||||
* @param b Bottom left and right corner positions.
|
||||
*/
|
||||
Rect(const fvec4& t, const fvec4& b) {
|
||||
Top = t;
|
||||
Bot = b;
|
||||
}
|
||||
/**
|
||||
* Constructor that initializes the rectangle using individual corner
|
||||
* positions.
|
||||
* @param tl Top left corner position.
|
||||
* @param tr Top right corner position.
|
||||
* @param bl Bottom left corner position.
|
||||
* @param br Bottom right corner position.
|
||||
*/
|
||||
Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br) {
|
||||
Top = fvec4(tl, tr);
|
||||
Bot = fvec4(bl, br);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that initializes the rectangle using a UV mapping vector.
|
||||
*
|
||||
* - The old API used vec4 for UV mapping.
|
||||
* - Spritesheets have rotated images, so this was updated to use Rect for UV.
|
||||
*
|
||||
* @param uv Vec4 UV map.
|
||||
*/
|
||||
Rect(const fvec4& uv) {
|
||||
Top = vec4(uv.x, uv.y, uv.z, uv.y);
|
||||
Bot = vec4(uv.x, uv.w, uv.z, uv.w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the top-left corner position.
|
||||
* @return Top-left position as vec2.
|
||||
*/
|
||||
fvec2 TopLeft() const { return fvec2(Top.x, Top.y); }
|
||||
/**
|
||||
* Get the top-right corner position.
|
||||
* @return Top-right position as vec2.
|
||||
*/
|
||||
fvec2 TopRight() const { return fvec2(Top.z, Top.w); }
|
||||
/**
|
||||
* Get the bottom-left corner position.
|
||||
* @return Bottom-left position as vec2.
|
||||
*/
|
||||
fvec2 BotLeft() const { return fvec2(Bot.x, Bot.y); }
|
||||
/**
|
||||
* Get the bottom-right corner position.
|
||||
* @return Bottom-right position as vec2.
|
||||
*/
|
||||
fvec2 BotRight() const { return fvec2(Bot.z, Bot.w); }
|
||||
|
||||
/**
|
||||
* Set the top-left corner position.
|
||||
* @param v New top-left position.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& TopLeft(const fvec2& v) {
|
||||
Top.x = v.x;
|
||||
Top.y = v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the top-right corner position.
|
||||
* @param v New top-right position.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& TopRight(const fvec2& v) {
|
||||
Top.z = v.x;
|
||||
Top.w = v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bottom-left corner position.
|
||||
* @param v New bottom-left position.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& BotLeft(const fvec2& v) {
|
||||
Bot.x = v.x;
|
||||
Bot.y = v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bottom-right corner position.
|
||||
* @param v New bottom-right position.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& BotRight(const fvec2& v) {
|
||||
Bot.z = v.x;
|
||||
Bot.w = v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Rect& r) const { return Top == r.Top && Bot == r.Bot; }
|
||||
|
||||
void SwapVec2XY() {
|
||||
Top.SwapXY();
|
||||
Top.SwapZW();
|
||||
Bot.SwapXY();
|
||||
Bot.SwapZW();
|
||||
}
|
||||
|
||||
/** Data Section */
|
||||
|
||||
fvec4 Top;
|
||||
fvec4 Bot;
|
||||
};
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
@@ -1,62 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/drivers/drivers.hpp>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
/**
|
||||
* Static Class Render Setup Functions
|
||||
*/
|
||||
class PD_API Renderer {
|
||||
public:
|
||||
Renderer() = default;
|
||||
~Renderer() = default;
|
||||
|
||||
// SECTION: Open Command and Object creation API
|
||||
static void RotateCorner(fvec2& pos, float s, float c);
|
||||
static Rect PrimRect(const fvec2& pos, const fvec2& size, float angle = 0.f);
|
||||
static Rect PrimLine(const fvec2& a, const fvec2& b, int thickness = 1);
|
||||
static void CmdQuad(Command* cmd, const Rect& quad, const Rect& uv,
|
||||
u32 color);
|
||||
static void CmdTriangle(Command* cmd, const fvec2 a, const fvec2 b,
|
||||
const fvec2 c, u32 clr);
|
||||
static void CmdPolyLine(const std::vector<fvec2>& points, u32 clr,
|
||||
u32 flags = 0, int thickness = 1);
|
||||
static void CmdConvexPolyFilled(Command* cmd,
|
||||
const std::vector<fvec2>& points, u32 clr,
|
||||
Texture::Ref tex);
|
||||
|
||||
// SECTION: InBounds Checks
|
||||
|
||||
static bool InBox(const fvec2& pos, const fvec2& size, const fvec4& area);
|
||||
static bool InBox(const fvec2& pos, const fvec4& area);
|
||||
static bool InBox(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||
const fvec4& area);
|
||||
};
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
@@ -1,75 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
/** Use so address type for TexAddress */
|
||||
using TexAddress = uintptr_t;
|
||||
class Texture {
|
||||
public:
|
||||
/** Texture Types */
|
||||
enum Type {
|
||||
RGBA32, ///< Rgba 32Bit
|
||||
RGB24, ///< Rgb 24 Bit
|
||||
A8, ///< A8 8Bit alpha
|
||||
};
|
||||
/** Texture Filters */
|
||||
enum Filter {
|
||||
NEAREST, ///< Nearest
|
||||
LINEAR, ///< Linear
|
||||
};
|
||||
/** Constructor */
|
||||
Texture() : Address(0), Size(0), UV(fvec4(0.f, 0.f, 1.f, 1.f)) {}
|
||||
Texture(TexAddress addr, ivec2 size,
|
||||
Li::Rect uv = fvec4(0.f, 0.f, 1.f, 1.f)) {
|
||||
Address = addr;
|
||||
Size = size;
|
||||
UV = uv;
|
||||
}
|
||||
|
||||
PD_SHARED(Texture);
|
||||
|
||||
void CopyFrom(Texture::Ref tex) {
|
||||
Address = tex->Address;
|
||||
Size = tex->Size;
|
||||
UV = tex->UV;
|
||||
}
|
||||
|
||||
/** Left in Code getter (should be remoevd) */
|
||||
ivec2 GetSize() const { return Size; }
|
||||
Li::Rect GetUV() const { return UV; }
|
||||
|
||||
operator ivec2() const { return Size; }
|
||||
operator Li::Rect() const { return UV; }
|
||||
|
||||
TexAddress Address;
|
||||
ivec2 Size;
|
||||
Li::Rect UV;
|
||||
};
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
@@ -1,52 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
class Vertex {
|
||||
public:
|
||||
Vertex() {}
|
||||
Vertex(const fvec2& p, const fvec2& u, u32 c) {
|
||||
Pos.x = p.x;
|
||||
Pos.y = p.y;
|
||||
UV = u;
|
||||
Color = c;
|
||||
}
|
||||
Vertex(const fvec2& pos, const fvec2& uv, u32 color)
|
||||
: pos(pos), uv(uv), color(color) {}
|
||||
~Vertex() {}
|
||||
|
||||
PD_RAW(Vertex);
|
||||
|
||||
// private:
|
||||
|
||||
/** Open Access Data Section */
|
||||
|
||||
fvec2 Pos;
|
||||
fvec2 UV;
|
||||
u32 Color;
|
||||
fvec2 pos;
|
||||
fvec2 uv;
|
||||
u32 color = 0x00000000;
|
||||
};
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
@@ -23,23 +23,32 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
class Snd {
|
||||
namespace Std {
|
||||
template <typename T>
|
||||
class Vector {
|
||||
public:
|
||||
Snd(const std::string& name = "NullSnd") : pName(name) {};
|
||||
~Snd() = default;
|
||||
// for c++ std stuff
|
||||
using value_type = T;
|
||||
using iterator = value_type*;
|
||||
using const_iterator = const value_type*;
|
||||
|
||||
PD_SHARED(Snd);
|
||||
Vector() {
|
||||
Size = 0;
|
||||
Cap = 0;
|
||||
Data = nullptr;
|
||||
}
|
||||
~Vector() {
|
||||
if (Data) {
|
||||
delete Data;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual bool Done(int buf_idx) {}
|
||||
virtual void Update(int buf_idx, void* data) {}
|
||||
virtual bool IsChannelPlaying(int chn) {}
|
||||
virtual bool IsChannelPaused(int chn) {}
|
||||
|
||||
const std::string pName = "NullSnd";
|
||||
T* Data = nullptr;
|
||||
size_t Size = 0;
|
||||
size_t Cap = 0;
|
||||
};
|
||||
} // namespace Std
|
||||
} // namespace PD
|
||||
@@ -1,76 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Button Object
|
||||
* @note Button Press is delayed by 1 frame
|
||||
* (but the visual reaction is done in the same frame)
|
||||
* This only means that InPressed is responding the info in
|
||||
* the next frame
|
||||
*/
|
||||
class PD_API Button : public Container {
|
||||
public:
|
||||
/**
|
||||
* Button Object constructor
|
||||
* @param label Label of the Button
|
||||
* @param pos Base Position
|
||||
* @param lr Reference to the Renderer
|
||||
*/
|
||||
Button(const std::string& label, UI7::IO::Ref io) {
|
||||
this->label = label;
|
||||
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||
}
|
||||
~Button() = default;
|
||||
PD_SHARED(Button);
|
||||
|
||||
/** Return true if butten is pressed*/
|
||||
bool IsPressed() { return pressed; }
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
*/
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text size
|
||||
UI7Color color = UI7Color_Button; ///< current button color
|
||||
std::string label; ///< Label of the Button
|
||||
bool pressed = false; ///< ispressed value
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,73 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Checkbox Object
|
||||
* @note The Updated input is available after
|
||||
* Context::Update while the visual update is done
|
||||
* during the Update
|
||||
*/
|
||||
class PD_API Checkbox : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor for Checkbox Object
|
||||
* @param label Label of the Checkbox
|
||||
* @param usr_ref Reference to the bool value to update
|
||||
* @param io IO Reference
|
||||
*/
|
||||
Checkbox(const std::string& label, bool& usr_ref, UI7::IO::Ref io)
|
||||
: usr_ref(usr_ref) {
|
||||
this->label = label;
|
||||
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||
}
|
||||
~Checkbox() = default;
|
||||
PD_SHARED(Checkbox);
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
*/
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Update Size if framepadding changed */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text Size
|
||||
fvec2 cbs = fvec2(18); ///< Checkbox size
|
||||
UI7Color color = UI7Color_FrameBackground; ///< Checkbox background Color
|
||||
std::string label; ///< Checkbox Label
|
||||
bool& usr_ref; ///< User bool reference
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,76 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
#include <pd/ui7/layout.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Color Editor (Creating a PopUP when clicking)
|
||||
*/
|
||||
class PD_API ColorEdit : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param label Label of the Button
|
||||
* @param pos Base Position
|
||||
* @param lr Reference to the Renderer
|
||||
*/
|
||||
ColorEdit(const std::string& label, u32* color, UI7::IO::Ref io) {
|
||||
// PD::Assert(color != nullptr, "Input Color Address is null!");
|
||||
this->label = label;
|
||||
this->color_ref = color;
|
||||
this->initial_color = *color;
|
||||
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||
}
|
||||
~ColorEdit() = default;
|
||||
PD_SHARED(ColorEdit);
|
||||
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
*/
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text size
|
||||
u32* color_ref = nullptr; ///< Color Reference
|
||||
u32 initial_color; ///< Initial Color
|
||||
std::string label; ///< Label of the Button
|
||||
Layout::Ref layout; ///< Layout to open
|
||||
bool is_shown = false; ///< AHow Layout Editor
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,180 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Container base class all Objects are based on
|
||||
* @note this class can be used to create custom Objects as well
|
||||
*/
|
||||
class PD_API Container {
|
||||
public:
|
||||
Container() = default;
|
||||
/**
|
||||
* Constructor with pos and Size
|
||||
* @param pos Container Position
|
||||
* @param size Container Size
|
||||
*/
|
||||
Container(const fvec2& pos, const fvec2& size) : pos(pos), size(size) {}
|
||||
/**
|
||||
* Constructor by a vec4 box
|
||||
* @param box Box containing top left and bottom right coords
|
||||
*/
|
||||
Container(const fvec4& box)
|
||||
: pos(fvec2(box.x, box.y)), size(fvec2(box.z - box.x, box.w - box.y)) {}
|
||||
~Container() = default;
|
||||
|
||||
PD_SHARED(Container);
|
||||
/**
|
||||
* Init Function Required by every Object that uses
|
||||
* Render or Input functions
|
||||
* @param io IO Reference
|
||||
* @param l DrawList Reference
|
||||
*/
|
||||
void Init(UI7::IO::Ref io, Li::DrawList::Ref l) {
|
||||
list = l;
|
||||
this->io = io;
|
||||
// this->screen = io->Ren->CurrentScreen();
|
||||
}
|
||||
|
||||
void SetClipRect(fvec4 clip) {
|
||||
pClipRect = clip;
|
||||
pCLipRectUsed = true;
|
||||
}
|
||||
|
||||
/** Setter for Position */
|
||||
void SetPos(const fvec2& pos) { this->pos = pos; }
|
||||
/** Setter for Size */
|
||||
void SetSize(const fvec2& size) { this->size = size; }
|
||||
/** Getter for Position */
|
||||
fvec2 GetPos() { return pos; }
|
||||
/** Getter for Size */
|
||||
fvec2 GetSize() { return size; }
|
||||
/**
|
||||
* Get the Containers Final Position
|
||||
* for Rendering and Input (if it has a parent Object)
|
||||
*/
|
||||
fvec2 FinalPos() {
|
||||
vec2 res = pos;
|
||||
if (parent) {
|
||||
/// Probably should use parant->FinalPos here
|
||||
res += parent->GetPos();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/** Setter for Parent Container */
|
||||
void SetParent(Container::Ref v) { parent = v; }
|
||||
/** Getter for Parent Container */
|
||||
Container::Ref GetParent() { return parent; }
|
||||
|
||||
/** Check if Rendering can be skipped */
|
||||
bool Skippable() const { return skippable; }
|
||||
/** Check if the Object got a timeout (ID OBJ Relevant) */
|
||||
bool Removable() const { return rem; }
|
||||
|
||||
/**
|
||||
* Handles Scrolling by scrolling pos as well as
|
||||
* Time for Remove for ID Objects
|
||||
* @param scrolling Scrolling Position
|
||||
* @param viewport Viewport to check if the Object is skippable
|
||||
*/
|
||||
void HandleScrolling(fvec2 scrolling, fvec4 viewport);
|
||||
/** Template function for Input Handling */
|
||||
virtual void HandleInput() {}
|
||||
/** Tamplate function for Object rendering */
|
||||
virtual void Draw() {}
|
||||
/** Template function to update internal data (if needed) */
|
||||
virtual void Update() {}
|
||||
|
||||
/** Internal function */
|
||||
void PreDraw();
|
||||
/** Internal function */
|
||||
void PostDraw();
|
||||
|
||||
/** Internal Input Handler */
|
||||
void HandleInternalInput();
|
||||
|
||||
/**
|
||||
* Function to unlock Input after Rendering is done in
|
||||
* Menu::Update
|
||||
* @note This is used if the Object got Input Handled directly after creation
|
||||
* to not check for Inputs twice
|
||||
*/
|
||||
void UnlockInput() { inp_done = false; }
|
||||
|
||||
/** Get the Objects ID (if it is an ID object)*/
|
||||
u32 GetID() const { return id; }
|
||||
/**
|
||||
* Set ID for ID Objects
|
||||
* @param id Object ID (hashed prefix+objname+prefixed_counter)
|
||||
*/
|
||||
void SetID(u32 id) { this->id = id; }
|
||||
|
||||
/** Get a reference to IO */
|
||||
UI7::IO::Ref GetIO() { return io; }
|
||||
|
||||
protected:
|
||||
/** used to skip Input/Render preocessing ot not*/
|
||||
bool skippable = false;
|
||||
/** value to check if an ID Object goes out of lifetime*/
|
||||
bool rem = false;
|
||||
/** Time of the last use (set by HandleScrolling)*/
|
||||
u64 last_use = 0;
|
||||
/** Input done or not for current frame*/
|
||||
bool inp_done = false;
|
||||
/** Reference to the Screen to draw the Object on*/
|
||||
// Screen::Ref screen;
|
||||
/** Container Position*/
|
||||
fvec2 pos;
|
||||
/** Container Size*/
|
||||
fvec2 size;
|
||||
/** Reference to the Drawlist to Draw to*/
|
||||
Li::DrawList::Ref list;
|
||||
/** IO Reference for Renderer and Theme */
|
||||
UI7::IO::Ref io;
|
||||
/** Reference to the parent container*/
|
||||
Container::Ref parent;
|
||||
/** Object ID (0 if unused)*/
|
||||
u32 id = 0;
|
||||
/** Internal Flags */
|
||||
u32 pFlags = 0;
|
||||
/** Is Selected? */
|
||||
bool pSelected = false;
|
||||
/** Was Pressed */
|
||||
bool pPressed = false;
|
||||
/** Was Pressed Twice */
|
||||
bool pPressedTwice = false;
|
||||
/** ClipRect */
|
||||
fvec4 pClipRect;
|
||||
/** Clip Rect used */
|
||||
bool pCLipRectUsed = false;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,92 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* DragData Object can take a datatype or a list
|
||||
* and modifys these by moving left or right when dragging
|
||||
*/
|
||||
template <typename T>
|
||||
class PD_API DragData : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param label Label of the Button
|
||||
* @param data Data reference (Supported types can be seen in dragdata.cpp)
|
||||
* @param num_elms Number of Array elements (for exaple with use ofvec4)
|
||||
* @param io IO Reference
|
||||
* @param min minimum number using Minimum limit
|
||||
* @param max Maximum number set by max limit by default
|
||||
* @param step To set the modifier for drag movement
|
||||
* @param precision for float and double to set precision
|
||||
*/
|
||||
DragData(const std::string& label, T* data, size_t num_elms, UI7::IO::Ref io,
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), T step = 1,
|
||||
int precision = 1) {
|
||||
// PD::Assert(data != nullptr, "Input Data Address is null!");
|
||||
this->label = label;
|
||||
this->data = data;
|
||||
this->elm_count = num_elms;
|
||||
this->min = min;
|
||||
this->max = max;
|
||||
this->step = step;
|
||||
this->precision = precision;
|
||||
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||
}
|
||||
~DragData() = default;
|
||||
|
||||
/** Als ob das funktioniert... */
|
||||
PD_SHARED(DragData<T>);
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
*/
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text size
|
||||
std::string label; ///< Label of the Button
|
||||
T* data;
|
||||
size_t elm_count = 0;
|
||||
T min;
|
||||
T max;
|
||||
T step;
|
||||
int precision = 1;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,81 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Button Object
|
||||
* @note Button Press is delayed by 1 frame
|
||||
* (but the visual reaction is done in the same frame)
|
||||
* This only means that InPressed is responding the info in
|
||||
* the next frame
|
||||
*/
|
||||
class PD_API DynObj : public Container {
|
||||
public:
|
||||
/**
|
||||
* Button Object constructor
|
||||
* @param label Label of the Button
|
||||
* @param pos Base Position
|
||||
* @param lr Reference to the Renderer
|
||||
*/
|
||||
DynObj(std::function<void(UI7::IO::Ref, Li::DrawList::Ref, Container*)>
|
||||
RenderFunc) {
|
||||
pRenFun = RenderFunc;
|
||||
}
|
||||
~DynObj() = default;
|
||||
|
||||
PD_SHARED(DynObj);
|
||||
|
||||
void AddInputHandler(std::function<void(UI7::IO::Ref, Container*)> inp) {
|
||||
pInp = inp;
|
||||
}
|
||||
|
||||
/** Return true if butten is pressed*/
|
||||
bool IsPressed() { return pressed; }
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
*/
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
UI7Color color = UI7Color_Button; ///< current button color
|
||||
bool pressed = false; ///< ispressed value
|
||||
std::function<void(UI7::IO::Ref, Li::DrawList::Ref, Container*)> pRenFun;
|
||||
std::function<void(UI7::IO::Ref, Container*)> pInp;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,69 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Image Object
|
||||
*/
|
||||
class PD_API Image : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor for the Image Object
|
||||
* @param img Image Texture Reference
|
||||
* @param size Custom Size of the Image
|
||||
*/
|
||||
Image(Li::Texture::Ref img, fvec2 size = 0.f, Li::Rect uv = fvec4(0.f)) {
|
||||
if (!img) return;
|
||||
this->img = img;
|
||||
if (size == fvec2(0.f)) {
|
||||
size = img->GetSize();
|
||||
}
|
||||
if (uv == Li::Rect(fvec4(0.f))) {
|
||||
uv = img->GetUV();
|
||||
}
|
||||
this->cuv = uv;
|
||||
this->newsize = size;
|
||||
SetSize(size);
|
||||
}
|
||||
~Image() = default;
|
||||
|
||||
PD_SHARED(Image);
|
||||
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
private:
|
||||
Li::Texture::Ref img = nullptr; ///< Texture reference to the Image
|
||||
fvec2 newsize = 0.f; ///< New Size
|
||||
Li::Rect cuv; ///< Custom UV
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,65 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Label [Text] Object
|
||||
*/
|
||||
class PD_API Label : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor for Label Object
|
||||
* @param label Label [Text] to Draw
|
||||
* @param lr Renderer Reference
|
||||
*/
|
||||
Label(const std::string& label, IO::Ref io) {
|
||||
this->label = label;
|
||||
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||
this->SetSize(tdim);
|
||||
}
|
||||
~Label() = default;
|
||||
|
||||
PD_SHARED(Label);
|
||||
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
/**
|
||||
* Override Update func to support Text modifications
|
||||
*/
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text Size
|
||||
UI7Color color = UI7Color_Text; ///< Color
|
||||
std::string label; ///< Text to Render
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,91 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Slider Object can take a datatype or a list
|
||||
* and modifys these by moving left or right when dragging
|
||||
*/
|
||||
template <typename T>
|
||||
class PD_API Slider : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param label Label of the Button
|
||||
* @param data Data reference (Supported types can be seen in Slider.cpp)
|
||||
* @param num_elms Number of Array elements (for exaple with use ofvec4)
|
||||
* @param io IO Reference
|
||||
* @param min minimum number using Minimum limit
|
||||
* @param max Maximum number set by max limit by default
|
||||
* @param step To set the modifier for drag movement
|
||||
* @param precision for float and double to set precision
|
||||
*/
|
||||
Slider(const std::string& label, T* data, UI7::IO::Ref io,
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), int precision = 1) {
|
||||
// PD::Assert(data != nullptr, "Input Data Address is null!");
|
||||
this->label = label;
|
||||
this->data = data;
|
||||
this->min = min;
|
||||
this->max = max;
|
||||
this->precision = precision;
|
||||
this->width = io->CurrentViewPort.z * 0.3f;
|
||||
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||
}
|
||||
~Slider() = default;
|
||||
|
||||
/** Als ob das funktioniert... */
|
||||
PD_SHARED(Slider<T>);
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
*/
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text size
|
||||
float width; ///< Size
|
||||
std::string label; ///< Label of the Button
|
||||
T* data;
|
||||
T min;
|
||||
T max;
|
||||
int precision = 1;
|
||||
float slw = 0.f; // silider drag width (calculated in update)
|
||||
float slp = 0.f; // silider drag pos (calculated in update)
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/container/button.hpp>
|
||||
#include <pd/ui7/container/checkbox.hpp>
|
||||
#include <pd/ui7/container/coloredit.hpp>
|
||||
#include <pd/ui7/container/dragdata.hpp>
|
||||
#include <pd/ui7/container/dynobj.hpp>
|
||||
#include <pd/ui7/container/image.hpp>
|
||||
#include <pd/ui7/container/label.hpp>
|
||||
#include <pd/ui7/container/slider.hpp>
|
||||
@@ -1,100 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
/** 32Bit Value to Stpre Menu Flags */
|
||||
using UI7MenuFlags = unsigned int;
|
||||
/** 32Bit Value to store Alignment Flags */
|
||||
using UI7Align = unsigned int;
|
||||
/** 32Bit Value to store Context (IO) flags */
|
||||
using UI7IOFlags = unsigned int;
|
||||
/** 32Bit Value for Layout Flags */
|
||||
using UI7LayoutFlags = unsigned int;
|
||||
|
||||
/** Menu Flags */
|
||||
enum UI7MenuFlags_ {
|
||||
UI7MenuFlags_None = 0, ///< No Flags (Default)
|
||||
UI7MenuFlags_NoTitlebar = 1 << 0, ///< Dont Show Titlebar
|
||||
UI7MenuFlags_CenterTitle = 1 << 1, ///< Center the Menu Title in Titlebar
|
||||
UI7MenuFlags_HzScrolling = 1 << 2, ///< Enable Horizontal Scrolling
|
||||
UI7MenuFlags_VtScrolling = 1 << 3, ///< Enable Vertical Scrolling
|
||||
UI7MenuFlags_NoBackground = 1 << 4, ///< Dont Render Menu Background
|
||||
UI7MenuFlags_NoClipRect = 1 << 5, ///< Disable clip render area of the Menu
|
||||
UI7MenuFlags_NoCollapse = 1 << 6, ///< Disable Menu Collapse
|
||||
UI7MenuFlags_NoMove = 1 << 7, ///< Disable Menu Movement
|
||||
UI7MenuFlags_NoResize = 1 << 8, ///< Disable Menu Resize
|
||||
UI7MenuFlags_NoClose = 1 << 9, ///< Disable Close Button
|
||||
UI7MenuFlags_NoScrollbar = 1 << 10, ///< Hide the Scrollbar
|
||||
// POC
|
||||
UI7MenuFlags_Maximize = 1 << 11, ///< Add a Maximize Button
|
||||
UI7MenuFlags_Minimize = 1 << 12, ///< Add a Minimize Button
|
||||
UI7MenuFlags_AlwaysAutoSize = 1 << 13, ///< Always Auto Resize Menu
|
||||
// Enable Horizontal and Vertical Scrolling
|
||||
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
|
||||
};
|
||||
|
||||
/** UI7 Layout Flags */
|
||||
enum UI7LayoutFlags_ {
|
||||
UI7LayoutFlags_None = 0, ///< No Flags used
|
||||
UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect
|
||||
};
|
||||
|
||||
/** UI7 Context Flags */
|
||||
enum UI7IOFlags_ {
|
||||
UI7IOFlags_None = 0, ///< No Additional Config available
|
||||
UI7IOFlags_HasTouch = 1 << 0, ///< Enable touch support [future]
|
||||
UI7IOFlags_HasMouseCursor = 1 << 1, ///< Enable Mouse support [future]
|
||||
};
|
||||
|
||||
/** Probably need to update this */
|
||||
enum UI7Align_ {
|
||||
UI7Align_Left = 1 << 0, ///< [Hz Op] Align Left (Default)
|
||||
UI7Align_Center = 1 << 1, ///< [Hz Op] Align Center
|
||||
UI7Align_Right = 1 << 2, ///< [Hz Op] Align Right
|
||||
UI7Align_Top = 1 << 3, ///< [Vt Op] Align Top (Default)
|
||||
UI7Align_Mid = 1 << 4, ///< [Vt Op] Align Mid
|
||||
UI7Align_Bottom = 1 << 5, ///< [Vt Op] Align Bottom
|
||||
// Default Horizontal and Vertical Alignment
|
||||
UI7Align_Default = UI7Align_Left | UI7Align_Top,
|
||||
};
|
||||
|
||||
/** Special flags for Layout::AddObjectEx */
|
||||
enum UI7LytAdd_ {
|
||||
UI7LytAdd_None = 0, ///< Also known as default or ->AddObject
|
||||
UI7LytAdd_NoCursorUpdate = 1 << 0, ///< Add without cursor alignment
|
||||
UI7LytAdd_NoScrollHandle = 1 << 1, ///< Skip HandleScrolling
|
||||
UI7LytAdd_Front = 1 << 2, ///< Add in front of the list
|
||||
};
|
||||
|
||||
/**
|
||||
* Todo: Look at this
|
||||
* Maybe proof of concept ???
|
||||
* Didnt remember that this exists
|
||||
*/
|
||||
enum UI7ContainerFlags_ {
|
||||
UI7ContainerFlags_None = 0,
|
||||
UI7ContainerFlags_EnableInternalInput = 1 << 0,
|
||||
UI7ContainerFlags_Selectable = 1 << 1,
|
||||
UI7ContainerFlags_OutlineSelected = 1 << 2,
|
||||
};
|
||||
@@ -1,74 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* ID Class (Generating an ID by String)
|
||||
*/
|
||||
class ID {
|
||||
public:
|
||||
/**
|
||||
* Constructor to Generate ID by input string
|
||||
* @param text Input String
|
||||
*/
|
||||
ID(const std::string& text) {
|
||||
pID = PD::Strings::FastHash(text);
|
||||
// pStrName = text;
|
||||
pName = text;
|
||||
}
|
||||
/**
|
||||
* Constructor used for const char* which is automatically
|
||||
* used when directly placing a string istead of using ID("")
|
||||
* @param text Input String
|
||||
*/
|
||||
constexpr ID(const char* text) {
|
||||
pID = PD::FNV1A32(text);
|
||||
pName = text;
|
||||
}
|
||||
/**
|
||||
* Use an ID as Input
|
||||
*/
|
||||
ID(u32 id) { pID = id; }
|
||||
~ID() = default;
|
||||
|
||||
/** Get The ID Initial Name */
|
||||
// constexpr const std::string_view& GetNameView() const { return pName; }
|
||||
const std::string GetName() const { return std::string(pName); }
|
||||
|
||||
/** Getter for the raw 32bit int id */
|
||||
constexpr const u32& RawID() const { return pID; }
|
||||
|
||||
/** Return the ID when casting to u32 */
|
||||
constexpr operator u32() const { return pID; }
|
||||
|
||||
u32 pID; ///< Hash of the name
|
||||
std::string pName; ///< Name
|
||||
// std::string pStrName; ///< Keep this stringview alive
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,140 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/lithium.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
#include <pd/ui7/id.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class InputHandler {
|
||||
public:
|
||||
InputHandler(PD::Context& ctx) : pCtx(ctx) {
|
||||
DragTime = Timer::New(*pCtx.Os().get(), false);
|
||||
}
|
||||
~InputHandler() = default;
|
||||
|
||||
PD_SHARED(InputHandler);
|
||||
|
||||
/**
|
||||
* Function to Check if current Object is dragged
|
||||
* or set it dragged
|
||||
* @param id ID to identify this specific Object
|
||||
* @param area Area where to start dragging
|
||||
* @return if inputs to this objects are alowed or not
|
||||
*/
|
||||
bool DragObject(const UI7::ID& id, fvec4 area) {
|
||||
if (CurrentMenu != FocusedMenu) {
|
||||
return false;
|
||||
}
|
||||
if (IsObjectDragged()) {
|
||||
// Only block if the Dragged Object has a difrent id
|
||||
if (DraggedObject != id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Get a Short define for touch pos
|
||||
fvec2 p = pCtx.Hid()->MousePos();
|
||||
// Check if Drag starts in the area position
|
||||
if ((pCtx.Hid()->IsDown(pCtx.Hid()->Key::Touch) ||
|
||||
pCtx.Hid()->IsEvent(PD::HidDriver::Event_Down, HidKb::Kb_MouseLeft)) &&
|
||||
Li::Renderer::InBox(p, area)) {
|
||||
// Set ID and iniatial Positions
|
||||
DraggedObject = id;
|
||||
DragSourcePos = p;
|
||||
DragPosition = p;
|
||||
DragLastPosition = p;
|
||||
DragDestination = area;
|
||||
// Reset and Start DragTimer
|
||||
DragTime->Reset();
|
||||
DragTime->Rseume();
|
||||
return false; // To make sure the Object is "Dragged"
|
||||
} else if ((pCtx.Hid()->IsHeld(pCtx.Hid()->Key::Touch) ||
|
||||
pCtx.Hid()->IsEvent(PD::HidDriver::Event_Held,
|
||||
HidKb::Kb_MouseLeft)) &&
|
||||
IsObjectDragged()) {
|
||||
// Update DragLast and DragPoisition
|
||||
DragLastPosition = DragPosition;
|
||||
DragPosition = p;
|
||||
} else if ((pCtx.Hid()->IsUp(pCtx.Hid()->Key::Touch) ||
|
||||
pCtx.Hid()->IsEvent(PD::HidDriver::Event_Up,
|
||||
HidKb::Kb_MouseLeft)) &&
|
||||
IsObjectDragged()) {
|
||||
// Released... Everything gets reset
|
||||
DraggedObject = 0;
|
||||
DragPosition = 0;
|
||||
DragSourcePos = 0;
|
||||
DragLastPosition = 0;
|
||||
DragDestination = fvec4(0);
|
||||
// Set Drag released to true (only one frame)
|
||||
// and Only if still in Box
|
||||
DragReleased = Li::Renderer::InBox(pCtx.Hid()->MousePosLast(), area);
|
||||
DragReleasedAW = true; // Advanced
|
||||
u64 d_rel = pCtx.Os()->GetTime();
|
||||
if (d_rel - DragLastReleased < DoubleClickTime) {
|
||||
DragDoubleRelease = true;
|
||||
DragLastReleased = 0; // Set 0 to prevent double exec
|
||||
} else {
|
||||
DragLastReleased = d_rel;
|
||||
}
|
||||
// Ensure timer is paused
|
||||
DragTime->Pause();
|
||||
DragTime->Reset();
|
||||
// Still return The Object is Dragged to ensure
|
||||
// the DragReleased var can be used
|
||||
return true;
|
||||
}
|
||||
return IsObjectDragged();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
DragTime->Update();
|
||||
DragReleased = false;
|
||||
DragReleasedAW = false;
|
||||
DragDoubleRelease = false;
|
||||
}
|
||||
|
||||
u64 DoubleClickTime = 500; // Milliseconds
|
||||
u32 FocusedMenu = 0;
|
||||
fvec4 FocusedMenuRect;
|
||||
u32 CurrentMenu = 0;
|
||||
u32 DraggedObject = 0;
|
||||
fvec2 DragSourcePos = 0;
|
||||
fvec2 DragPosition = 0;
|
||||
fvec2 DragLastPosition = 0;
|
||||
/** Fvec4 has an constructor problem currently */
|
||||
fvec4 DragDestination = fvec4(0);
|
||||
Timer::Ref DragTime;
|
||||
u64 DragLastReleased = 0;
|
||||
bool DragReleased = false; ///< Drag Releaded in Box
|
||||
bool DragReleasedAW = false; ///< Drag Released Anywhere
|
||||
bool DragDoubleRelease = false; ///< Double Click
|
||||
PD::Context& pCtx;
|
||||
/** Check if an object is Dragged already */
|
||||
bool IsObjectDragged() const { return DraggedObject != 0; }
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,118 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
#include <pd/ui7/input_api.hpp>
|
||||
#include <pd/ui7/theme.hpp>
|
||||
#include <pd/ui7/viewport.hpp>
|
||||
|
||||
namespace PD {
|
||||
class Context;
|
||||
namespace UI7 {
|
||||
class PD_API IO {
|
||||
public:
|
||||
IO(PD::Context& ctx) : pCtx(ctx) {
|
||||
Time = Timer::New(*pCtx.Os().get());
|
||||
InputHandler = InputHandler::New(pCtx);
|
||||
Theme = UI7::Theme::New();
|
||||
Back = Li::DrawList::New(pCtx);
|
||||
Front = Li::DrawList::New(pCtx);
|
||||
FDL = Li::DrawList::New(pCtx);
|
||||
DeltaStats = TimeStats::New(60);
|
||||
/** Probably not the best solution i guess */
|
||||
CurrentViewPort.z = pCtx.Gfx()->ViewPort.x;
|
||||
CurrentViewPort.w = pCtx.Gfx()->ViewPort.y;
|
||||
}
|
||||
~IO() {}
|
||||
|
||||
PD_SHARED(IO);
|
||||
|
||||
/**
|
||||
* IO Update Internal Variables
|
||||
*/
|
||||
void Update();
|
||||
|
||||
/**
|
||||
* Final Draw List for PD::Li::Gfx::RednerDrawData
|
||||
*
|
||||
* Possible thanks to the DrawList::Merge Feature
|
||||
*/
|
||||
Li::DrawList::Ref FDL = nullptr;
|
||||
ivec4 CurrentViewPort = ivec4(0, 0, 0, 0);
|
||||
std::unordered_map<u32, ViewPort::Ref> ViewPorts;
|
||||
float Framerate = 0.f;
|
||||
float Delta = 0.f;
|
||||
u64 LastTime = 0;
|
||||
TimeStats::Ref DeltaStats;
|
||||
Timer::Ref Time;
|
||||
Li::Font::Ref Font;
|
||||
float FontScale = 0.7f;
|
||||
UI7::Theme::Ref Theme;
|
||||
fvec2 MenuPadding = 5.f;
|
||||
fvec2 FramePadding = 5.f;
|
||||
float ItemRowHeight = 0.f;
|
||||
float FrameRounding = 0.f;
|
||||
fvec2 ItemSpace = vec2(5.f, 2.f);
|
||||
fvec2 MinSliderDragSize = 10.f; // Min height (Vt) and Min Width (Hz)
|
||||
bool ShowMenuBorder = true;
|
||||
bool ShowFrameBorder = false; // not implemented yet
|
||||
bool WrapLabels = false; // Beta state
|
||||
float OverScrollMod = 0.15f;
|
||||
u64 DoubleClickTime = 500; // Milliseconds
|
||||
std::list<std::pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry;
|
||||
// Short define for DrawKistRegestryLast
|
||||
std::list<std::pair<UI7::ID, Li::DrawList::Ref>> pDLRL;
|
||||
Li::DrawList::Ref Back;
|
||||
Li::DrawList::Ref Front;
|
||||
u32 NumVertices = 0; ///< Debug Vertices Num
|
||||
u32 NumIndices = 0; ///< Debug Indices Num
|
||||
std::vector<u32> MenuOrder;
|
||||
|
||||
PD::Context& pCtx; // Palladium base context
|
||||
|
||||
// DrawListApi
|
||||
void RegisterDrawList(const UI7::ID& id, Li::DrawList::Ref v) {
|
||||
DrawListRegestry.push_back(std::make_pair(id, v));
|
||||
}
|
||||
|
||||
void AddViewPort(const ID& id, const ivec4& size) {
|
||||
if (ViewPorts.count(id)) {
|
||||
return;
|
||||
}
|
||||
ViewPorts[id] = ViewPort::New(id, size);
|
||||
}
|
||||
|
||||
ViewPort::Ref GetViewPort(const ID& id) {
|
||||
if (!ViewPorts.count(id)) {
|
||||
return nullptr;
|
||||
}
|
||||
return ViewPorts[id];
|
||||
}
|
||||
|
||||
UI7::InputHandler::Ref InputHandler;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,211 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
#include <pd/ui7/container/dragdata.hpp>
|
||||
#include <pd/ui7/container/slider.hpp>
|
||||
#include <pd/ui7/flags.hpp>
|
||||
#include <pd/ui7/input_api.hpp>
|
||||
#include <pd/ui7/theme.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class Context;
|
||||
class PD_API Layout {
|
||||
public:
|
||||
Layout(const ID& id, IO::Ref io) : ID(id) {
|
||||
this->IO = io;
|
||||
DrawList = Li::DrawList::New(io->pCtx);
|
||||
DrawList->SetFont(IO->Font);
|
||||
DrawList->SetFontScale(io->FontScale);
|
||||
Scrolling[0] = false;
|
||||
Scrolling[1] = false;
|
||||
CursorInit();
|
||||
Pos = fvec2(io->CurrentViewPort.x, io->CurrentViewPort.y);
|
||||
Size = 0;
|
||||
WorkRect = fvec4(IO->MenuPadding, Size - (fvec2(2) * IO->MenuPadding));
|
||||
}
|
||||
~Layout() = default;
|
||||
|
||||
PD_SHARED(Layout);
|
||||
|
||||
/** SECTION CONTAINERS */
|
||||
/**
|
||||
* Render a Simple Label
|
||||
* @param label The text to draw
|
||||
*/
|
||||
void Label(const std::string& label);
|
||||
template <typename... Args>
|
||||
void Label(std::format_string<Args...> s, Args&&... args) {
|
||||
Label(std::format(s, std::forward<Args>(args)...));
|
||||
}
|
||||
/**
|
||||
* Render a Button
|
||||
* @param label The buttons text
|
||||
* @return if the button was pressed
|
||||
*/
|
||||
bool Button(const std::string& label);
|
||||
/**
|
||||
* Render a Checkbox
|
||||
* @param label Label of the Checkbox
|
||||
* @param v A value to update
|
||||
*/
|
||||
void Checkbox(const std::string& label, bool& v);
|
||||
/**
|
||||
* Render an Image
|
||||
* @param img Texture reference of the image
|
||||
* @param size a Custom Size if needed
|
||||
*/
|
||||
void Image(Li::Texture::Ref img, fvec2 size = 0.f, Li::Rect uv = fvec4(0));
|
||||
/**
|
||||
* Render a Drag Object witth any supported type:
|
||||
* [`int`, `float`, `double`, `u8`, `u16`, `u32`]
|
||||
* @param label Name of the Drag
|
||||
* @param data Reference to Data Object (can be multiple as well)
|
||||
* @param num_elements Defien the number of Elements in the Data addr
|
||||
* @param precission Difine the Format string len for float/double
|
||||
*/
|
||||
template <typename T>
|
||||
void DragData(const std::string& label, T* data, size_t num_elms = 1,
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), T step = 1,
|
||||
int precision = 1) {
|
||||
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
|
||||
Container::Ref r = FindObject(id);
|
||||
if (!r) {
|
||||
r = UI7::DragData<T>::New(label, data, num_elms, this->IO, min, max, step,
|
||||
precision);
|
||||
r->SetID(id);
|
||||
}
|
||||
AddObject(r);
|
||||
}
|
||||
template <typename T>
|
||||
void Slider(const std::string& label, T* data,
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), int precision = 1) {
|
||||
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
|
||||
Container::Ref r = FindObject(id);
|
||||
if (!r) {
|
||||
r = UI7::Slider<T>::New(label, data, this->IO, min, max, precision);
|
||||
r->SetID(id);
|
||||
}
|
||||
AddObject(r);
|
||||
}
|
||||
|
||||
/** SECTION OTHERSTUFF */
|
||||
|
||||
const std::string GetName() const { return ID.GetName(); }
|
||||
const UI7::ID& GetID() const { return this->ID; }
|
||||
|
||||
const fvec2& GetPosition() const { return Pos; }
|
||||
void SetPosition(const fvec2& v) { Pos = v; }
|
||||
const fvec2& GetSize() const { return Size; }
|
||||
void SetSize(const fvec2& v) { Size = v; }
|
||||
|
||||
Li::DrawList::Ref GetDrawList() { return DrawList; }
|
||||
|
||||
void CursorInit();
|
||||
void SameLine();
|
||||
void CursorMove(const fvec2& size);
|
||||
|
||||
bool ObjectWorkPos(fvec2& movpos);
|
||||
|
||||
/**
|
||||
* Extended Object Add Func to Add Object in Front or disable
|
||||
* Position by cursor as well as cursor update...
|
||||
* Should only be used in special cases as the
|
||||
* AddObject function is faster
|
||||
* Using Flags for its features cause dont want to have too much args
|
||||
*/
|
||||
void AddObjectEx(Container::Ref obj, u32 Flags);
|
||||
/**
|
||||
* Fast Function to Add Object in Layout SPace like
|
||||
* button Label images etc
|
||||
*/
|
||||
void AddObject(Container::Ref obj);
|
||||
Container::Ref FindObject(u32 id);
|
||||
void ClearIDObjects() { IDObjects.clear(); }
|
||||
|
||||
fvec2 AlignPosition(fvec2 pos, fvec2 size, fvec4 area, UI7Align alignment);
|
||||
|
||||
/** Get the Alignment for Current State */
|
||||
UI7Align GetAlignment() {
|
||||
/// if temp alignment is used then return it and
|
||||
/// reset tmpalign
|
||||
if (TempAlign) {
|
||||
auto t = TempAlign;
|
||||
TempAlign = 0;
|
||||
return t;
|
||||
}
|
||||
return Alignment;
|
||||
}
|
||||
|
||||
void SetAlign(UI7Align a) { Alignment = a; }
|
||||
void NextAlign(UI7Align a) { TempAlign = a; }
|
||||
|
||||
void Update();
|
||||
|
||||
fvec2 DbgScrollOffset() { return ScrollOffset; }
|
||||
|
||||
private:
|
||||
friend class Menu;
|
||||
friend class PD::UI7::Context;
|
||||
friend class ReMenu;
|
||||
// Base Components
|
||||
UI7::ID ID;
|
||||
UI7::IO::Ref IO;
|
||||
Li::DrawList::Ref DrawList;
|
||||
UI7LayoutFlags Flags;
|
||||
|
||||
// Positioning
|
||||
fvec2 Pos;
|
||||
fvec2 Size;
|
||||
UI7Align Alignment = UI7Align_Default;
|
||||
UI7Align TempAlign;
|
||||
|
||||
// Cursor
|
||||
fvec2 Cursor;
|
||||
fvec2 InitialCursorOffset;
|
||||
fvec2 BackupCursor;
|
||||
fvec2 SamelineCursor;
|
||||
fvec2 BeforeSameLine;
|
||||
fvec2 LastObjSize;
|
||||
fvec2 MaxPosition;
|
||||
fvec4 WorkRect;
|
||||
|
||||
// Scrolling (Only theoretical)
|
||||
// Rendering must be done by the Objective that uses the Lyt
|
||||
fvec2 ScrollOffset;
|
||||
fvec2 ScrollStart;
|
||||
bool Scrolling[2];
|
||||
|
||||
// Objects
|
||||
std::list<Container::Ref> Objects;
|
||||
std::vector<Container::Ref> IDObjects;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,146 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
#include <pd/ui7/containers.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
#include <pd/ui7/layout.hpp>
|
||||
|
||||
#include "pd/ui7/container/dragdata.hpp"
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class PD_API Menu {
|
||||
public:
|
||||
Menu(const UI7::ID& id, UI7::IO::Ref pIO);
|
||||
~Menu() {}
|
||||
|
||||
PD_SHARED(Menu);
|
||||
|
||||
/**
|
||||
* Render a Simple Label
|
||||
* @param label The text to draw
|
||||
*/
|
||||
void Label(const std::string& label);
|
||||
template <typename... Args>
|
||||
void Label(std::format_string<Args...> s, Args&&... args) {
|
||||
Label(std::format(s, std::forward<Args>(args)...));
|
||||
}
|
||||
/**
|
||||
* Render a Button
|
||||
* @param label The buttons text
|
||||
* @return if the button was pressed
|
||||
*/
|
||||
bool Button(const std::string& label);
|
||||
/**
|
||||
* Render a Checkbox
|
||||
* @param label Label of the Checkbox
|
||||
* @param v A value to update
|
||||
*/
|
||||
void Checkbox(const std::string& label, bool& v);
|
||||
/**
|
||||
* Render an Image
|
||||
* @param img Texture reference of the image
|
||||
* @param size a Custom Size if needed
|
||||
*/
|
||||
void Image(Li::Texture::Ref img, fvec2 size = 0.f, Li::Rect uv = fvec4(0));
|
||||
/**
|
||||
* Render a Drag Object witth any supported type:
|
||||
* [`int`, `float`, `double`, `u8`, `u16`, `u32`]
|
||||
* @param label Name of the Drag
|
||||
* @param data Reference to Data Object (can be multiple as well)
|
||||
* @param num_elements Defien the number of Elements in the Data addr
|
||||
* @param precission Difine the Format string len for float/double
|
||||
*/
|
||||
template <typename T>
|
||||
void DragData(const std::string& label, T* data, size_t num_elms = 1,
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), T step = 1,
|
||||
int precision = 1) {
|
||||
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
|
||||
Container::Ref r = pLayout->FindObject(id);
|
||||
if (!r) {
|
||||
r = UI7::DragData<T>::New(label, data, num_elms, pIO, min, max, step,
|
||||
precision);
|
||||
// Isnt This exactly the same line???
|
||||
// r = UI7::DragData<T>::New(label, data, num_elms, pIO, min, max, step,
|
||||
// precision);
|
||||
r->SetID(id);
|
||||
}
|
||||
pLayout->AddObject(r);
|
||||
}
|
||||
template <typename T>
|
||||
void Slider(const std::string& label, T* data,
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), int precision = 1) {
|
||||
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
|
||||
Container::Ref r = pLayout->FindObject(id);
|
||||
if (!r) {
|
||||
r = UI7::Slider<T>::New(label, data, pIO, min, max, precision);
|
||||
r->SetID(id);
|
||||
}
|
||||
pLayout->AddObject(r);
|
||||
}
|
||||
void ColorEdit(const std::string& label, u32& clr);
|
||||
void SameLine() { pLayout->SameLine(); }
|
||||
void Separator();
|
||||
void SeparatorText(const std::string& label);
|
||||
bool BeginTreeNode(const ID& id);
|
||||
void EndTreeNode();
|
||||
|
||||
void HandleFocus();
|
||||
void HandleScrolling();
|
||||
void HandleTitlebarActions();
|
||||
void DrawBaseLayout();
|
||||
|
||||
void AddObject(PD::UI7::Container::Ref obj) { pLayout->AddObject(obj); }
|
||||
void AddObjectEx(PD::UI7::Container::Ref obj, PD::u32 flags) {
|
||||
pLayout->AddObjectEx(obj, flags);
|
||||
}
|
||||
Container::Ref FindObject(u32 id) { return pLayout->FindObject(id); }
|
||||
|
||||
void Update();
|
||||
|
||||
void SetSize(PD::fvec2 size) { pLayout->SetSize(size); }
|
||||
void SetPosition(PD::fvec2 pos) { pLayout->SetPosition(pos); }
|
||||
const PD::fvec2& GetSize() const { return pLayout->GetSize(); }
|
||||
const PD::fvec2& GetPosition() const { return pLayout->GetPosition(); }
|
||||
|
||||
/** Data Section */
|
||||
|
||||
UI7MenuFlags Flags = 0;
|
||||
Layout::Ref pLayout;
|
||||
IO::Ref pIO;
|
||||
ID pID;
|
||||
bool* pIsShown = nullptr;
|
||||
bool pIsOpen = true;
|
||||
std::unordered_map<u32, bool> pTreeNodes;
|
||||
fvec2 TempScrollXY;
|
||||
|
||||
float TitleBarHeight = 0.f;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,160 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
|
||||
/**
|
||||
* Using this to support 32bit color values as well as
|
||||
* values from UI7Color_
|
||||
*/
|
||||
using UI7Color = PD::u32;
|
||||
|
||||
/** Theme Color */
|
||||
enum UI7Color_ {
|
||||
UI7Color_Background, ///< UI7 Menu Background
|
||||
UI7Color_Border, ///< Menu/Frame Border Color
|
||||
UI7Color_Button, ///< UI7 Button Idle Color
|
||||
UI7Color_ButtonDead, ///< UI7 Disabled Button Color
|
||||
UI7Color_ButtonActive, ///< UI7 Pressed Button Color
|
||||
UI7Color_ButtonHovered, ///< UI7 Hovered Button Color
|
||||
UI7Color_Text, ///< UI7 Text Color
|
||||
UI7Color_TextDead, ///< UI7 Dead Text Color
|
||||
UI7Color_Header, ///< UI7 Menu Header Color
|
||||
UI7Color_HeaderDead, ///< Inactive Header
|
||||
UI7Color_Selector, ///< UI7 Selector Color
|
||||
UI7Color_Checkmark, ///< UI7 Checkmark Color
|
||||
UI7Color_FrameBackground, ///< UI7 Frame Background
|
||||
UI7Color_FrameBackgroundHovered, ///< UI7 Hovered Frame Background
|
||||
UI7Color_Progressbar, ///< UI7 Progressbar Background
|
||||
UI7Color_ListEven, ///< UI7 List (Even Entry) Background Color
|
||||
UI7Color_ListOdd, ///< UI7 List (Odd Entry) Background Color
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class PD_API Theme {
|
||||
public:
|
||||
/**
|
||||
* Default Constructor Setting up the Default theme
|
||||
* @note if using Shared Reference you probably need to do
|
||||
* Theme::Default(*theme.get());
|
||||
*/
|
||||
Theme() { Default(*this); }
|
||||
~Theme() {}
|
||||
PD_SHARED(Theme);
|
||||
|
||||
/**
|
||||
* Simple static Loader for the Default Theme
|
||||
* @param theme Theme Reference
|
||||
*/
|
||||
static void Default(Theme& theme);
|
||||
/**
|
||||
* White Mode Theme
|
||||
* @param Theme theme reference
|
||||
*/
|
||||
static void Flashbang(Theme& theme);
|
||||
|
||||
/** Revert the last Color Change */
|
||||
Theme& Pop() {
|
||||
pTheme[pChanges[pChanges.size() - 1].first] =
|
||||
pChanges[pChanges.size() - 1].second;
|
||||
pChanges.pop_back();
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert the last color Change done for a specific color
|
||||
* @param c Color to revert change from
|
||||
*/
|
||||
Theme& Pop(UI7Color c) {
|
||||
for (size_t i = pChanges.size() - 1; i > 0; i--) {
|
||||
if (pChanges[i].first == c) {
|
||||
pTheme[c] = pChanges[i].second;
|
||||
pChanges.erase(pChanges.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change a Color
|
||||
* @param tc Color Identifier
|
||||
* @param color Color to change to
|
||||
*/
|
||||
Theme& Change(UI7Color tc, u32 color) {
|
||||
if (pTheme.find(tc) == pTheme.end()) {
|
||||
return *this;
|
||||
}
|
||||
pChanges.push_back(std::make_pair(tc, pTheme[tc]));
|
||||
pTheme[tc] = color;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Color of a Color ReferenceID
|
||||
* @param c ReferenceID
|
||||
*/
|
||||
u32 Get(UI7Color c) const {
|
||||
auto e = pTheme.find(c);
|
||||
if (e == pTheme.end()) {
|
||||
return 0x00000000;
|
||||
}
|
||||
return e->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* [UNSAFE] to use
|
||||
* Get the Color Ref of a Color ReferenceID
|
||||
* @param c ReferenceID
|
||||
*/
|
||||
u32& GetRef(UI7Color c) {
|
||||
auto e = pTheme.find(c);
|
||||
if (e == pTheme.end()) {
|
||||
static u32 noclr = 0x00000000;
|
||||
return noclr;
|
||||
}
|
||||
return e->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator wrapper for get
|
||||
* @param c Color ReferenceID
|
||||
*/
|
||||
u32 operator[](UI7Color c) const { return Get(c); }
|
||||
|
||||
/**
|
||||
* Change but just sets [can implement completly new ids]
|
||||
* @param tc Color ID (Can be self creeated ones as well)
|
||||
* @param clr Color it should be set to
|
||||
*/
|
||||
void Set(UI7Color tc, u32 clr) { pTheme[tc] = clr; }
|
||||
|
||||
std::unordered_map<u32, u32> pTheme; ///< Theme Data
|
||||
std::vector<std::pair<UI7Color, u32>> pChanges; ///< List of Changes
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -1,88 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
#include <pd/ui7/menu.hpp>
|
||||
|
||||
#include "pd/ui7/flags.hpp"
|
||||
|
||||
/**
|
||||
* Declare UI7 Version
|
||||
* Format: 00 00 00 00
|
||||
* Major Minor Patch Build
|
||||
* 0x01010000 -> 1.1.0-0
|
||||
*/
|
||||
#define UI7_VERSION 0x00060000
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Get UI7 Version String
|
||||
* @param show_build Show build num (mostly unused)
|
||||
* @return Version String (1.0.0-1 for example)
|
||||
*/
|
||||
PD_API std::string GetVersion(bool show_build = false);
|
||||
/** Base Context for UI7 */
|
||||
class PD_API Context {
|
||||
public:
|
||||
Context(PD::Context& ctx) { pIO = IO::New(ctx); }
|
||||
~Context() = default;
|
||||
|
||||
PD_SHARED(Context);
|
||||
|
||||
IO::Ref GetIO() { return pIO; }
|
||||
void AddViewPort(const ID& id, const ivec4& vp);
|
||||
void UseViewPort(const ID& id);
|
||||
void Update();
|
||||
Menu::Ref BeginMenu(const ID& id, UI7MenuFlags flags = 0,
|
||||
bool* pShow = nullptr);
|
||||
Menu::Ref CurrentMenu() { return pCurrent; }
|
||||
void EndMenu();
|
||||
void AboutMenu(bool* show = nullptr);
|
||||
void MetricsMenu(bool* show = nullptr);
|
||||
void StyleEditor(bool* show = nullptr);
|
||||
|
||||
Li::DrawList::Ref GetDrawData() { return pIO->FDL; }
|
||||
|
||||
Menu::Ref pGetOrCreateMenu(const ID& id) {
|
||||
auto menu = pMenus.find(id);
|
||||
if (menu == pMenus.end()) {
|
||||
pMenus[id] = Menu::New(id, pIO);
|
||||
menu = pMenus.find(id);
|
||||
}
|
||||
return menu->second;
|
||||
}
|
||||
|
||||
IO::Ref pIO;
|
||||
/** Current Menu */
|
||||
Menu::Ref pCurrent = nullptr;
|
||||
std::vector<u32> pCurrentMenus;
|
||||
std::vector<u32> pDFO; /** Debug Final Order */
|
||||
std::unordered_map<u32, Menu::Ref> pMenus;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
Reference in New Issue
Block a user