20 layout(&l), scale(s), leader(false), leaderX(0), leaderY(0), meshFeather(-1.0f), dirty(true), originX(0), originY(0), alpha(255)
25GuiControllerView::~GuiControllerView()
30void GuiControllerView::clearLabels()
32 for(
size_t i = 0; i < labels.size(); i++)
38void GuiControllerView::rebuild()
41 width = (int)ceilf(layout->width * scale - 0.01f);
42 height = (int)ceilf(layout->height * scale - 0.01f);
44 spots.assign(layout->spots.size(), SpotCache());
45 for(
size_t i = 0; i < spots.size(); i++)
46 for(
int k = 0; k < 4; k++)
47 spots[i].built[k] =
false;
48 stickX.assign(layout->spots.size(), 0.0f);
49 stickY.assign(layout->spots.size(), 0.0f);
54 for(
size_t i = 0; i < layout->spots.size(); i++)
56 const GuiControlSpot& s = layout->spots[i];
57 GuiText * t =
nullptr;
60 t =
new GuiText(s.
label, (
int)(15.0f * std::max(scale, 0.7f)), theme.
textMuted);
63 const float cx = (s.x + s.w * 0.5f) * scale -
width * 0.5f;
64 const float cy = (s.y + s.
h * 0.5f) * scale -
height * 0.5f;
65 t->
setPosition((
int)floorf(cx + 0.5f), (
int)floorf(cy + 0.5f));
68 labelLit.push_back(
false);
90 highlighted.push_back(
id);
107 for(
size_t i = 0; i < layout->spots.size(); i++)
122 x = originX + (s->x + s->w * 0.5f) * scale;
123 y = originY + (s->y + s->
h * 0.5f) * scale;
127void GuiControllerView::emit(
const GuiMesh& m)
129 const std::vector<MeshVertex>& src = m.
vertices();
130 for(
size_t i = 0; i < src.size(); i++)
136 v.
c.
a = (uint8_t)((v.
c.
a * alpha + 127) / 255);
137 scratch.push_back(v);
151 const float feather = uiScale > 0.0f ? 1.0f / uiScale : 1.0f;
152 if(dirty || feather != meshFeather)
156 for(
size_t i = 0; i < spots.size(); i++)
157 for(
int k = 0; k < 4; k++)
159 spots[i].mesh[k] =
GuiMesh(feather);
160 spots[i].built[k] =
false;
162 meshFeather = feather;
166 originX = (float)this->
getLeft();
167 originY = (float)this->
getTop();
172 for(
int pass = 0; pass < 2; pass++)
174 for(
size_t i = 0; i < layout->spots.size(); i++)
179 const bool hl = std::find(highlighted.begin(), highlighted.end(), s.
id) != highlighted.end();
180 if((pass == 1) != hl)
182 const bool isLit = lit && lit(s.
id);
183 const int k = (isLit ? 1 : 0) + (hl ? 2 : 0);
184 if(!spots[i].built[k])
187 spots[i].built[k] =
true;
189 emit(spots[i].mesh[k]);
191 if(labels[i] && labelLit[i] != isLit)
200 for(
size_t i = 0; i < layout->spots.size(); i++)
211 if(leader && !highlighted.empty())
219 GuiRect dot = { tx - 3.5f, ty - 3.5f, 7.0f, 7.0f };
222 const std::vector<MeshVertex>& src = line.
vertices();
223 for(
size_t i = 0; i < src.size(); i++)
227 v.
c.
a = (uint8_t)((v.
c.
a * alpha + 127) / 255);
228 scratch.push_back(v);
236 for(
size_t i = 0; i < labels.size(); i++)
Umbrella header for the platform-agnostic libgui core.
void setHighlight(int id)
Highlights one control (0 = none)
void setLeader(bool on, float fromX=0.0f, float fromY=0.0f)
Draws a line from a point (design-canvas coordinates, such as a list row's edge) to the first highlig...
void draw() override
Called constantly to redraw the element.
void setLayout(const GuiControllerLayout &layout)
Changes the controller drawn.
GuiControllerView(const GuiControllerLayout &layout, float scale=1.0f)
void setStick(int id, float x, float y)
Sets an analog stick's position (-1 to 1 each)
bool getSpotCentre(int id, float &x, float &y) const
Gets the center of a control in design-canvas coordinates (false if the layout has no such control)
void setScale(float scale)
Changes the size.
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,...
int height
Element height.
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,...
void setParent(GuiElement *e)
Set the element's parent.
void setPosition(int x, int y)
Sets the element's position.
int getAlpha()
Gets the element's alpha value Considers alpha, alphaDyn, and the parent element's GetAlpha() value.
Accumulates shapes as a triangle list of MeshVertex.
void addLine(GuiPoint a, GuiPoint b, float width, const GuiFill &fill)
Adds a straight line with flat ends.
const std::vector< MeshVertex > & vertices() const
Gets the triangle list.
void addEllipse(const GuiRect &r, const GuiFill &fill, bool edgeFringe=true)
Adds a filled ellipse inscribed in a rectangle (a circle when w == h)
void setAlignment(ALIGN_H hor, ALIGN_V vert)
Sets the text alignment.
virtual void drawMesh(const MeshVertex *vertices, size_t count)=0
Draws a triangle list: three vertices per triangle, each with its own color.
Platform video backend owning the frame lifecycle (init/render/clear, screen size,...
virtual ImageRenderer * getImageRenderer()=0
virtual float getUIScale() const
Ratio of physical render-target pixels to design-canvas pixels (the width/height passed to init()).
void GuiBuildControllerSpot(GuiMesh &mesh, const GuiControlSpot &spot, CTL_STATE state, float scale)
Builds one control in one state (an analog stick's cap is separate, see GuiBuildControllerStickCap).
void GuiBuildControllerBody(GuiMesh &mesh, const GuiControllerLayout &layout, float scale)
Builds the resting drawing of a controller (silhouette, then every decorative control) in local coord...
void GuiBuildControllerStickCap(GuiMesh &mesh, const GuiControlSpot &spot, float x, float y, bool lit, float scale)
Builds an analog stick's cap, displaced by (x, y) (each -1 to 1) from the middle of its ring.
CTL_STATE
The look a control is drawn in.
@ STICK
An analog stick: an outer ring with a cap that can move.
One control on a controller drawing.
int id
Input bit this control stands for; 0 for decoration (never lit or highlighted).
const char * label
Text drawn on the control ("A", "ZL", "+"), or null.
A controller: its drawing size, silhouette and controls.
static GuiFill solid(PixelColor c)
A single flat color.
An axis-aligned rectangle (top-left origin) in design-canvas pixels.
Colors, metrics and the style recipes built from them.
static GuiTheme & current()
The theme the rest of the library reads. Starts as the default dark theme.
PixelColor textMuted
Secondary text.
A single 2D vertex with its own color, in design-canvas coordinates.
float y
Y position (design-canvas pixels).
float x
X position (design-canvas pixels).
PixelColor c
Straight (non-premultiplied) RGBA color.
8-bit-per-channel RGBA color used by the video interfaces.
uint8_t a
Alpha component.