Zig bindings for orca (still WIP) #140
77
src/orca.zig
77
src/orca.zig
|
@ -1550,6 +1550,62 @@ pub const clip = struct {
|
|||
pub const top = oc_clip_top;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// [GRAPHICS]: path primitives
|
||||
//------------------------------------------------------------------------------------------
|
||||
|
||||
const PathEltType = enum(c_uint) {
|
||||
Move,
|
||||
Line,
|
||||
Quadratic,
|
||||
Cubic,
|
||||
};
|
||||
|
||||
const PathElt = extern struct {
|
||||
type: PathEltType,
|
||||
p: [3]Vec2,
|
||||
};
|
||||
|
||||
const PathDescriptor = extern struct {
|
||||
start_index: u32,
|
||||
count: u32,
|
||||
start_point: Vec2,
|
||||
};
|
||||
|
||||
const Attributes = extern struct {
|
||||
width: f32,
|
||||
tolerance: f32,
|
||||
color: Color,
|
||||
joint: JointType,
|
||||
max_joint_excursion: f32,
|
||||
cap: CapType,
|
||||
|
||||
font: Font,
|
||||
font_size: f32,
|
||||
|
||||
image: Image,
|
||||
src_region: Rect,
|
||||
|
||||
transform: Mat2x3,
|
||||
clip: Rect,
|
||||
};
|
||||
|
||||
const PrimitiveCmd = enum(c_uint) {
|
||||
Fill,
|
||||
Stroke,
|
||||
Jump,
|
||||
};
|
||||
|
||||
const Primitive = extern struct {
|
||||
cmd: PrimitiveCmd,
|
||||
attributes: Attributes,
|
||||
data: extern union {
|
||||
path: PathDescriptor,
|
||||
rect: Rect,
|
||||
jump: u32,
|
||||
},
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// [GRAPHICS]: resources
|
||||
//------------------------------------------------------------------------------------------
|
||||
|
@ -1567,15 +1623,14 @@ pub const Surface = extern struct {
|
|||
extern fn oc_surface_contents_scaling(surface: Surface) Vec2;
|
||||
extern fn oc_surface_bring_to_front(surface: Surface) void;
|
||||
extern fn oc_surface_send_to_back(surface: Surface) void;
|
||||
// TODO
|
||||
// extern fn oc_surface_render_commands(
|
||||
// surface: Surface,
|
||||
// color: Color,
|
||||
// primitive_count: u32,
|
||||
// primitives: [*]Primitive,
|
||||
// elt_count: u32,
|
||||
// elements: [*]PathElt,
|
||||
// ) void;
|
||||
extern fn oc_surface_render_commands(
|
||||
surface: Surface,
|
||||
color: Color,
|
||||
primitive_count: u32,
|
||||
primitives: [*]Primitive,
|
||||
elt_count: u32,
|
||||
elements: [*]PathElt,
|
||||
) void;
|
||||
|
||||
pub const nil = oc_surface_nil;
|
||||
pub const isNil = oc_surface_is_nil;
|
||||
ilidemi marked this conversation as resolved
Outdated
|
||||
|
@ -1587,7 +1642,9 @@ pub const Surface = extern struct {
|
|||
pub const contentsScaling = oc_surface_contents_scaling;
|
||||
pub const bringToFront = oc_surface_bring_to_front;
|
||||
pub const sendToBack = oc_surface_send_to_back;
|
||||
// pub const renderCommands = oc_surface_render_commands;
|
||||
pub fn renderCommands(surface: Surface, color: Color, primitives: []Primitive, elements: []PathElt) void {
|
||||
oc_surface_render_commands(surface, color, @intCast(primitives.len), primitives.ptr, @intCast(elements.len), elements.ptr);
|
||||
}
|
||||
};
|
||||
|
||||
pub const Image = extern struct {
|
||||
|
|
Loading…
Reference in New Issue
Should non-core data structs be put into the namespace as well? Arena/Vec2 makes sense at the top level, File/IO/UI stuff seems like it can be contained
You mean like putting File/FileType/IoReq/etc into a struct named
io
, kind of like how the log stuff is namespaced intolog
? If so, I think that makes sense.What looked confusing to me was how functions are namespaced but the structs local to that module are not. Guess something like File is used for fonts and images too so it's a judgement call but something like FileDialog is pretty clear. I'm coming at this from UI angle where pretty much all of the structs are local.
Ohh I think I get it. File and Surface are legit structs here, just with a ton of methods. I thought they're more like function namespaces. Apologies for confusion.
I am still confused,
oc_file_size
andoc_file_open_with_request
are declared in the exact same way but former has File as the self argument and the latter doesn't. Does that translate into a method call and a namespaced function respectively?In Zig, calling funtions on structs is just syntax sugar for passing it as the first argument to the function. So these are equivalent:
And you can have other functions that don't pass the struct type as the first argument, you just have to call them explicitly on the struct type and not an instance, otherwise you'll get an error:
Hopefully that clears things up?
So I guess to answer your question, directly, yes. :P
And the latter one goes under File because it's a sort of a factory method. All makes sense, thank you for the explanation!