11static const int kBlendSteps = 4;
15 blend(1.0f), blendStep(kBlendSteps), started(false), dirty(true), meshWidth(-1), meshHeight(-1), meshFeather(-1.0f),
58 transition = seconds < 0.0f ? 0.0f : seconds;
67 case STATE::CLICKED:
return SHAPE_STATE::PRESSED;
68 case STATE::DISABLED:
return SHAPE_STATE::DISABLED;
69 default:
return SHAPE_STATE::NORMAL;
84 const GuiPaint& want = style.forState(shapeStateFor(
state));
87 from = to = shown = want;
89 blendStep = kBlendSteps;
97 blend = transition > 0.0f ? 0.0f : 1.0f;
102 blendStep = kBlendSteps;
112 blendStep = kBlendSteps;
119 const float eased = blend * blend * (3.0f - 2.0f * blend);
120 const int step = (int)(eased * (
float)kBlendSteps + 0.5f);
121 if(step != blendStep)
124 shown = GuiPaint::mix(from, to, (
float)step / (
float)kBlendSteps);
132 const float feather = scale > 0.0f ? 1.0f / scale : 1.0f;
133 if(dirty || !mesh || meshWidth !=
width || meshHeight !=
height || meshFeather != feather)
148 meshFeather = feather;
155 const float hw =
width * 0.5f;
156 const float hh =
height * 0.5f;
Umbrella header for the platform-agnostic libgui core.
bool isVisible()
Checks whether or not the element is visible.
int getTop()
Gets the current topmost coordinate of the element Considers vertical alignment, y offset,...
float getScaleX()
Gets the element's current x scale Considers scale, scaleDyn, and the parent element's GetScale() val...
int height
Element height.
float getScaleY()
Gets the element's current y scale Considers scale, scaleDyn, and the parent element's GetScale() val...
void updateEffects()
Updates the element's effects (dynamic values) Called by Draw(), used for animation purposes.
int getLeft()
Gets the current leftmost coordinate of the element Considers horizontal alignment,...
STATE state
Element state (DEFAULT, SELECTED, CLICKED, DISABLED)
int getAlpha()
Gets the element's alpha value Considers alpha, alphaDyn, and the parent element's GetAlpha() value.
static void draw(GuiSharedMesh *mesh, float x, float y, float scaleX, float scaleY, uint8_t alpha, std::vector< MeshVertex > &scratch)
Draws a mesh with its (0,0) at (x, y), stretched by scaleX/scaleY about that point.
static GuiSharedMesh * acquire(const GuiMeshKey &key)
Finds or builds the mesh for a key and takes a reference to it. Pair with release().
static void release(GuiSharedMesh *mesh)
Gives back a reference from acquire().
void setCorners(const GuiCorners &c)
Sets the corner radii of a rectangle.
void setShape(SHAPE s)
Sets the shape kind (rectangle or ellipse)
void setStyle(const GuiShapeStyle &s)
Sets the look for every state; applies immediately.
void setPaint(const GuiPaint &p)
Sets one look for every state.
void setTransition(float seconds)
Sets how long a change of state takes to blend, in seconds (0 = instant)
GuiShape(int w=0, int h=0)
Constructor.
void draw() override
Constantly called to draw the shape.
void setCapsule()
Rounds a rectangle's ends fully (radius half the shorter side)
Platform video backend owning the frame lifecycle (init/render/clear, screen size,...
virtual float getUIScale() const
Ratio of physical render-target pixels to design-canvas pixels (the width/height passed to init()).
virtual float getDeltaTime() const =0
STATE
Interaction state of a GuiElement (default, selected, clicked, held, disabled).
SHAPE_STATE
The states a styled shape distinguishes.
SHAPE
Basic shape kinds a paint can be applied to.
@ FOCUSED
Highlighted: under the cursor, or selected with the D-pad.
@ RECTANGLE
Rectangle, with optional rounded corners (see GuiCorners)
Per-corner radii, in the order top-left, top-right, bottom-right, bottom-left.
Everything that decides what a shape's triangles are.
float tolerance
Curve tolerance, see GuiMesh.
int width
Width in design-canvas pixels.
GuiCorners corners
Corner radii of a rectangle.
GuiPaint paint
Fill, outline and shadow.
SHAPE kind
Rectangle or ellipse.
float feather
Anti-aliasing fringe width, see GuiMesh.
int height
Height in design-canvas pixels.
A set of paints, one per state. States left unset fall back to the normal paint. GuiShapeStyle(rest)....