# 0.3.2
Implement Path render API into drawlist Add some new drawing functions (need to make Rectangle -> RectFilled Add Menu Border ReSetup the Menu Input and Rendering API to fix flickering when moving
This commit is contained in:
@ -25,6 +25,7 @@ SOFTWARE.
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/lithium/renderer.hpp>
|
||||
#include <pd/ui7/flags.hpp>
|
||||
#include <pd/ui7/theme.hpp>
|
||||
|
||||
namespace PD {
|
||||
@ -39,6 +40,15 @@ class DrawList : public SmartCtor<DrawList> {
|
||||
DrawList(LI::Renderer::Ref r) { ren = r; }
|
||||
~DrawList() = default;
|
||||
|
||||
/**
|
||||
* Draw a Rectangle (LINED)
|
||||
* @param pos position of the rect
|
||||
* @param size Size of the rect
|
||||
* @param clr Color of the rect
|
||||
* @param thickness Thickness of the lines
|
||||
*/
|
||||
void AddRect(const vec2& pos, const vec2& size, const UI7Color& clr,
|
||||
int thickness = 1);
|
||||
/**
|
||||
* Render a Rectangle
|
||||
* @param pos Position
|
||||
@ -48,12 +58,43 @@ class DrawList : public SmartCtor<DrawList> {
|
||||
void AddRectangle(vec2 pos, vec2 szs, const UI7Color& clr);
|
||||
/**
|
||||
* Render a Triangle
|
||||
* @param pos0 Position a
|
||||
* @param pos1 Position b
|
||||
* @param pos2 Position c
|
||||
* @param a Position a
|
||||
* @param b Position b
|
||||
* @param c Position c
|
||||
* @param clr Color
|
||||
* @param thickness Thickness of the lines
|
||||
*/
|
||||
void AddTriangle(const vec2& a, const vec2& b, const vec2& c,
|
||||
const UI7Color& clr, int thickness = 1);
|
||||
/**
|
||||
* Render a Filled Triangle
|
||||
* @param a Position a
|
||||
* @param b Position b
|
||||
* @param c Position c
|
||||
* @param clr Color
|
||||
*/
|
||||
void AddTriangle(vec2 pos0, vec2 pos1, vec2 pos2, const UI7Color& clr);
|
||||
void AddTriangleFilled(const vec2& a, const vec2& b, const vec2& c,
|
||||
const UI7Color& clr);
|
||||
|
||||
/**
|
||||
* Add a Lined Circle
|
||||
* @param pos Center position
|
||||
* @param rad radius of the circle
|
||||
* @param col Color of the Circle
|
||||
* @param num_segments Number of Segments (0 = auto)
|
||||
* @param thickness thickness of the line
|
||||
*/
|
||||
void AddCircle(const vec2& pos, float rad, UI7Color col, int num_segments = 0,
|
||||
int thickness = 1);
|
||||
/**
|
||||
* Add a Circle
|
||||
* @param pos Center position
|
||||
* @param rad radius of the circle
|
||||
* @param col Color of the Circle
|
||||
* @param num_segments Number of Segments (0 = auto)
|
||||
*/
|
||||
void AddCircleFilled(const vec2& pos, float rad, UI7Color col,
|
||||
int num_segments = 0);
|
||||
/**
|
||||
* Render a Text
|
||||
* @param pos Position
|
||||
@ -82,6 +123,24 @@ class DrawList : public SmartCtor<DrawList> {
|
||||
*/
|
||||
void AddLine(const vec2& a, const vec2& b, const UI7Color& clr, 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 AddPolyLine(const std::vector<vec2>& points, const UI7Color& clr,
|
||||
UI7DrawFlags 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 AddConvexPolyFilled(const std::vector<vec2>& points,
|
||||
const UI7Color& clr);
|
||||
|
||||
/** Clear the Drawlist */
|
||||
void Clear();
|
||||
/** Process [Render] the Drawlist */
|
||||
@ -98,6 +157,61 @@ class DrawList : public SmartCtor<DrawList> {
|
||||
/** Setter fot the Layer */
|
||||
void Layer(int v) { layer = v; }
|
||||
|
||||
/** 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) {
|
||||
Path.reserve(Path.size() + num_points);
|
||||
}
|
||||
/**
|
||||
* Clear current Path
|
||||
* @note PathStroke and PathFill will automatically clear
|
||||
*/
|
||||
void PathClear() { Path.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 PathNext(const vec2& v) { Path.push_back(v); }
|
||||
/**
|
||||
* 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(const UI7Color& clr, int thickness = 1,
|
||||
UI7DrawFlags flags = 0) {
|
||||
AddPolyLine(Path, clr, flags, thickness);
|
||||
Path.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(const UI7Color& clr) {
|
||||
AddConvexPolyFilled(Path, clr);
|
||||
Path.clear();
|
||||
}
|
||||
|
||||
void PathArcToN(const vec2& c, float radius, float a_min, float a_max,
|
||||
int segments);
|
||||
/// @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 PathRect(vec2 a, vec2 b, float rounding = 0.f, UI7DrawFlags flags = 0);
|
||||
|
||||
private:
|
||||
/** Base Layer offset (Internal Used) */
|
||||
int BaseLayer() const { return base; }
|
||||
@ -114,6 +228,7 @@ class DrawList : public SmartCtor<DrawList> {
|
||||
std::stack<vec4> clip_rects; ///< Stack containing Scissor Areas
|
||||
u32 num_vertices; ///< Number of Vertices
|
||||
u32 num_indices; ///< Number of Indices
|
||||
std::vector<vec2> Path;
|
||||
// Map for Auto Static Text
|
||||
std::unordered_map<u32, LI::StaticText::Ref> static_text;
|
||||
// List of Drawcommands generated
|
||||
|
@ -31,6 +31,8 @@ using UI7Align = unsigned int;
|
||||
using UI7IOFlags = unsigned int;
|
||||
/** 32Bit Value for Layout Flags */
|
||||
using UI7LayoutFlags = unsigned int;
|
||||
/** 32Bit value for DrawFlags */
|
||||
using UI7DrawFlags = unsigned int;
|
||||
|
||||
/** Menu Flags */
|
||||
enum UI7MenuFlags_ {
|
||||
@ -56,6 +58,12 @@ enum UI7LayoutFlags_ {
|
||||
UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect
|
||||
};
|
||||
|
||||
enum UI7DrawFlags_ {
|
||||
UI7DrawFlags_None = 0,
|
||||
UI7DrawFlags_Close = 1 << 0, ///< Close a PolyLine
|
||||
UI7DrawFlags_AALines = 1 << 1, ///< Anti aliased Lines
|
||||
};
|
||||
|
||||
/** UI7 Context Flags */
|
||||
enum UI7IOFlags_ {
|
||||
UI7IOFlags_None = 0, ///< No Additional Config available
|
||||
|
@ -71,6 +71,8 @@ class IO : public SmartCtor<IO> {
|
||||
vec2 FramePadding = 5.f;
|
||||
vec2 ItemSpace = vec2(5.f, 2.f);
|
||||
vec2 MinSliderDragSize = 10.f; // Min height (Vt) and Min Width (Hz)
|
||||
bool ShowMenuBorder = true;
|
||||
bool ShowFrameBorder = false; // not implemented yet
|
||||
float OverScrollMod = 0.15f;
|
||||
u64 DoubleClickTime = 500; // Milliseconds
|
||||
std::vector<std::pair<UI7::ID, DrawList::Ref>> DrawListRegestry;
|
||||
|
@ -290,6 +290,9 @@ class Menu : public SmartCtor<Menu> {
|
||||
|
||||
// Layout API
|
||||
PD::UI7::Layout::Ref Layout;
|
||||
|
||||
UI7Color clr_close_btn = UI7Color_FrameBackground;
|
||||
UI7Color clr_collapse_tri = UI7Color_FrameBackground;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -34,6 +34,7 @@ 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
|
||||
|
@ -37,7 +37,7 @@ SOFTWARE.
|
||||
* Major Minor Patch Build
|
||||
* 0x01010000 -> 1.1.0-0
|
||||
*/
|
||||
#define UI7_VERSION 0x00030101
|
||||
#define UI7_VERSION 0x00030200
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
|
Reference in New Issue
Block a user