Update readme, add potentiometer controls
This commit is contained in:
@@ -870,6 +870,61 @@ static void emit_quad(DrawBatch *batch,
|
||||
batch->index_count += 6;
|
||||
}
|
||||
|
||||
static void emit_quad_rotated(DrawBatch *batch,
|
||||
float x0, float y0, float x1, float y1,
|
||||
float u0, float v0, float u1, float v1,
|
||||
float cr, float cg, float cb, float ca,
|
||||
float angle_rad)
|
||||
{
|
||||
if (batch->vertex_count + 4 > MAX_VERTICES || batch->index_count + 6 > MAX_INDICES)
|
||||
return;
|
||||
|
||||
U32 base = batch->vertex_count;
|
||||
UIVertex *v = &batch->vertices[base];
|
||||
|
||||
float cx = (x0 + x1) * 0.5f;
|
||||
float cy = (y0 + y1) * 0.5f;
|
||||
float cosA = cosf(angle_rad);
|
||||
float sinA = sinf(angle_rad);
|
||||
|
||||
float dx0 = x0 - cx, dy0 = y0 - cy;
|
||||
float dx1 = x1 - cx, dy1 = y1 - cy;
|
||||
|
||||
v[0].pos[0] = cx + dx0 * cosA - dy0 * sinA;
|
||||
v[0].pos[1] = cy + dx0 * sinA + dy0 * cosA;
|
||||
v[0].uv[0] = u0; v[0].uv[1] = v0;
|
||||
|
||||
v[1].pos[0] = cx + dx1 * cosA - dy0 * sinA;
|
||||
v[1].pos[1] = cy + dx1 * sinA + dy0 * cosA;
|
||||
v[1].uv[0] = u1; v[1].uv[1] = v0;
|
||||
|
||||
v[2].pos[0] = cx + dx1 * cosA - dy1 * sinA;
|
||||
v[2].pos[1] = cy + dx1 * sinA + dy1 * cosA;
|
||||
v[2].uv[0] = u1; v[2].uv[1] = v1;
|
||||
|
||||
v[3].pos[0] = cx + dx0 * cosA - dy1 * sinA;
|
||||
v[3].pos[1] = cy + dx0 * sinA + dy1 * cosA;
|
||||
v[3].uv[0] = u0; v[3].uv[1] = v1;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
v[i].col[0] = cr; v[i].col[1] = cg; v[i].col[2] = cb; v[i].col[3] = ca;
|
||||
v[i].rect_min[0] = 0; v[i].rect_min[1] = 0;
|
||||
v[i].rect_max[0] = 0; v[i].rect_max[1] = 0;
|
||||
v[i].corner_radii[0] = 0; v[i].corner_radii[1] = 0;
|
||||
v[i].corner_radii[2] = 0; v[i].corner_radii[3] = 0;
|
||||
v[i].border_thickness = 0;
|
||||
v[i].softness = 0;
|
||||
v[i].mode = 1.0f;
|
||||
}
|
||||
|
||||
U32 *idx = &batch->indices[batch->index_count];
|
||||
idx[0] = base; idx[1] = base + 1; idx[2] = base + 2;
|
||||
idx[3] = base; idx[4] = base + 2; idx[5] = base + 3;
|
||||
|
||||
batch->vertex_count += 4;
|
||||
batch->index_count += 6;
|
||||
}
|
||||
|
||||
static void emit_rect(DrawBatch *batch,
|
||||
float x0, float y0, float x1, float y1,
|
||||
float cr, float cg, float cb, float ca,
|
||||
@@ -1276,6 +1331,18 @@ void renderer_end_frame(Renderer *r, Clay_RenderCommandArray render_commands) {
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 1.0f);
|
||||
} else if (type == CUSTOM_RENDER_ROTATED_ICON) {
|
||||
bind_icon();
|
||||
CustomRotatedIconData *ri = (CustomRotatedIconData *)custom->customData;
|
||||
Clay_Color c = ri->color;
|
||||
float cr = c.r / 255.f, cg = c.g / 255.f;
|
||||
float cb = c.b / 255.f, ca = c.a / 255.f;
|
||||
UI_IconInfo *info = &g_icons[ri->icon_id];
|
||||
emit_quad_rotated(&batch,
|
||||
bb.x, bb.y, bb.x + bb.width, bb.y + bb.height,
|
||||
info->u0, info->v0, info->u1, info->v1,
|
||||
cr, cg, cb, ca,
|
||||
ri->angle_rad);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
Reference in New Issue
Block a user