Skip to content

Commit 9474d15

Browse files
authored
Add ellipse/concave-poly methods to DrawList (#37)
1 parent c203293 commit 9474d15

File tree

2 files changed

+159
-3
lines changed

2 files changed

+159
-3
lines changed

src/gui.zig

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ fn zguiMemFree(maybe_ptr: ?*anyopaque, _: ?*anyopaque) callconv(.C) void {
127127
defer mem_mutex.unlock();
128128

129129
if (mem_allocations != null) {
130-
const size = mem_allocations.?.fetchRemove(@intFromPtr(ptr)).?.value;
131-
const mem = @as([*]align(mem_alignment) u8, @ptrCast(@alignCast(ptr)))[0..size];
132-
mem_allocator.?.free(mem);
130+
if (mem_allocations.?.fetchRemove(@intFromPtr(ptr))) |kv| {
131+
const size = kv.value;
132+
const mem = @as([*]align(mem_alignment) u8, @ptrCast(@alignCast(ptr)))[0..size];
133+
mem_allocator.?.free(mem);
134+
}
133135
}
134136
}
135137
}
@@ -4226,6 +4228,59 @@ pub const DrawList = *opaque {
42264228
num_segments: c_int,
42274229
) void;
42284230
//----------------------------------------------------------------------------------------------
4231+
pub fn addEllipse(draw_list: DrawList, args: struct {
4232+
p: [2]f32,
4233+
r: [2]f32,
4234+
col: u32,
4235+
rot: f32 = 0,
4236+
num_segments: i32 = 0,
4237+
thickness: f32 = 1.0,
4238+
}) void {
4239+
zguiDrawList_AddEllipse(
4240+
draw_list,
4241+
&args.p,
4242+
&args.r,
4243+
args.col,
4244+
args.rot,
4245+
args.num_segments,
4246+
args.thickness,
4247+
);
4248+
}
4249+
extern fn zguiDrawList_AddEllipse(
4250+
draw_list: DrawList,
4251+
center: *const [2]f32,
4252+
radius: *const [2]f32,
4253+
col: u32,
4254+
rot: f32,
4255+
num_segments: c_int,
4256+
thickness: f32,
4257+
) void;
4258+
//----------------------------------------------------------------------------------------------
4259+
pub fn addEllipseFilled(draw_list: DrawList, args: struct {
4260+
p: [2]f32,
4261+
r: [2]f32,
4262+
col: u32,
4263+
rot: f32 = 0,
4264+
num_segments: u16 = 0,
4265+
}) void {
4266+
zguiDrawList_AddEllipseFilled(
4267+
draw_list,
4268+
&args.p,
4269+
&args.r,
4270+
args.col,
4271+
args.rot,
4272+
args.num_segments,
4273+
);
4274+
}
4275+
extern fn zguiDrawList_AddEllipseFilled(
4276+
draw_list: DrawList,
4277+
center: *const [2]f32,
4278+
radius: *const [2]f32,
4279+
col: u32,
4280+
rot: f32,
4281+
num_segments: c_int,
4282+
) void;
4283+
//----------------------------------------------------------------------------------------------
42294284
pub fn addNgon(draw_list: DrawList, args: struct {
42304285
p: [2]f32,
42314286
r: f32,
@@ -4324,6 +4379,25 @@ pub const DrawList = *opaque {
43244379
col: u32,
43254380
) void;
43264381
//----------------------------------------------------------------------------------------------
4382+
pub fn addConcavePolyFilled(
4383+
draw_list: DrawList,
4384+
points: []const [2]f32,
4385+
col: u32,
4386+
) void {
4387+
zguiDrawList_AddConcavePolyFilled(
4388+
draw_list,
4389+
points.ptr,
4390+
@intCast(points.len),
4391+
col,
4392+
);
4393+
}
4394+
extern fn zguiDrawList_AddConcavePolyFilled(
4395+
draw_list: DrawList,
4396+
points: [*]const [2]f32,
4397+
num_points: c_int,
4398+
col: u32,
4399+
) void;
4400+
//----------------------------------------------------------------------------------------------
43274401
pub fn addBezierCubic(draw_list: DrawList, args: struct {
43284402
p1: [2]f32,
43294403
p2: [2]f32,
@@ -4500,6 +4574,11 @@ pub const DrawList = *opaque {
45004574
}
45014575
extern fn zguiDrawList_PathFillConvex(draw_list: DrawList, col: c_uint) void;
45024576
//----------------------------------------------------------------------------------------------
4577+
pub fn pathFillConcave(draw_list: DrawList, col: u32) void {
4578+
return zguiDrawList_PathFillConcave(draw_list, col);
4579+
}
4580+
extern fn zguiDrawList_PathFillConcave(draw_list: DrawList, col: c_uint) void;
4581+
//----------------------------------------------------------------------------------------------
45034582
pub fn pathStroke(draw_list: DrawList, args: struct {
45044583
col: u32,
45054584
flags: DrawFlags = .{},
@@ -4550,6 +4629,34 @@ pub const DrawList = *opaque {
45504629
a_max_of_12: c_int,
45514630
) void;
45524631
//----------------------------------------------------------------------------------------------
4632+
pub fn pathEllipticalArcTo(draw_list: DrawList, args: struct {
4633+
p: [2]f32,
4634+
r: [2]f32,
4635+
rot: f32,
4636+
amin: f32,
4637+
amax: f32,
4638+
num_segments: u16 = 0,
4639+
}) void {
4640+
zguiDrawList_PathEllipticalArcTo(
4641+
draw_list,
4642+
&args.p,
4643+
&args.r,
4644+
args.rot,
4645+
args.amin,
4646+
args.amax,
4647+
args.num_segments,
4648+
);
4649+
}
4650+
extern fn zguiDrawList_PathEllipticalArcTo(
4651+
draw_list: DrawList,
4652+
center: *const [2]f32,
4653+
radius: *const [2]f32,
4654+
rot: f32,
4655+
amin: f32,
4656+
amax: f32,
4657+
num_segments: c_int,
4658+
) void;
4659+
//----------------------------------------------------------------------------------------------
45534660
pub fn pathBezierCubicCurveTo(draw_list: DrawList, args: struct {
45544661
p2: [2]f32,
45554662
p3: [2]f32,

src/zgui.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,29 @@ extern "C"
22402240
draw_list->AddCircleFilled({center[0], center[1]}, radius, col, num_segments);
22412241
}
22422242

2243+
ZGUI_API void zguiDrawList_AddEllipse(
2244+
ImDrawList *draw_list,
2245+
const float center[2],
2246+
const float radius[2],
2247+
ImU32 col,
2248+
float rot,
2249+
int num_segments,
2250+
float thickness)
2251+
{
2252+
draw_list->AddEllipse({center[0], center[1]}, {radius[0], radius[1]}, col, rot, num_segments, thickness);
2253+
}
2254+
2255+
ZGUI_API void zguiDrawList_AddEllipseFilled(
2256+
ImDrawList *draw_list,
2257+
const float center[2],
2258+
const float radius[2],
2259+
ImU32 col,
2260+
float rot,
2261+
int num_segments)
2262+
{
2263+
draw_list->AddEllipseFilled({center[0], center[1]}, {radius[0], radius[1]}, col, rot, num_segments);
2264+
}
2265+
22432266
ZGUI_API void zguiDrawList_AddNgon(
22442267
ImDrawList *draw_list,
22452268
const float center[2],
@@ -2291,6 +2314,15 @@ extern "C"
22912314
draw_list->AddConvexPolyFilled((const ImVec2 *)&points[0][0], num_points, col);
22922315
}
22932316

2317+
ZGUI_API void zguiDrawList_AddConcavePolyFilled(
2318+
ImDrawList *draw_list,
2319+
const float points[][2],
2320+
int num_points,
2321+
ImU32 col)
2322+
{
2323+
draw_list->AddConcavePolyFilled((const ImVec2 *)&points[0][0], num_points, col);
2324+
}
2325+
22942326
ZGUI_API void zguiDrawList_AddBezierCubic(
22952327
ImDrawList *draw_list,
22962328
const float p1[2],
@@ -2404,6 +2436,11 @@ extern "C"
24042436
draw_list->PathFillConvex(col);
24052437
}
24062438

2439+
ZGUI_API void zguiDrawList_PathFillConcave(ImDrawList *draw_list, ImU32 col)
2440+
{
2441+
draw_list->PathFillConcave(col);
2442+
}
2443+
24072444
ZGUI_API void zguiDrawList_PathStroke(ImDrawList *draw_list, ImU32 col, ImDrawFlags flags, float thickness)
24082445
{
24092446
draw_list->PathStroke(col, flags, thickness);
@@ -2430,6 +2467,18 @@ extern "C"
24302467
draw_list->PathArcToFast({center[0], center[1]}, radius, a_min_of_12, a_max_of_12);
24312468
}
24322469

2470+
ZGUI_API void zguiDrawList_PathEllipticalArcTo(
2471+
ImDrawList *draw_list,
2472+
const float center[2],
2473+
const float radius[2],
2474+
float rot,
2475+
int a_min,
2476+
int a_max,
2477+
int num_segments)
2478+
{
2479+
draw_list->PathEllipticalArcTo({center[0], center[1]}, {radius[0], radius[1]}, rot, a_min, a_max, num_segments);
2480+
}
2481+
24332482
ZGUI_API void zguiDrawList_PathBezierCubicCurveTo(
24342483
ImDrawList *draw_list,
24352484
const float p2[2],

0 commit comments

Comments
 (0)