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:
@@ -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
|
||||
Reference in New Issue
Block a user