mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/macos: path
This commit is contained in:
@ -4,6 +4,7 @@ pub usingnamespace @import("graphics/bitmap_context.zig");
|
||||
pub usingnamespace @import("graphics/color_space.zig");
|
||||
pub usingnamespace @import("graphics/font.zig");
|
||||
pub usingnamespace @import("graphics/geometry.zig");
|
||||
pub usingnamespace @import("graphics/path.zig");
|
||||
|
||||
test {
|
||||
@import("std").testing.refAllDecls(@This());
|
||||
|
@ -13,6 +13,10 @@ pub const Rect = extern struct {
|
||||
origin: Point,
|
||||
size: Size,
|
||||
|
||||
pub fn init(x: f64, y: f64, width: f64, height: f64) Rect {
|
||||
return @bitCast(Rect, c.CGRectMake(x, y, width, height));
|
||||
}
|
||||
|
||||
pub fn cval(self: Rect) c.struct_CGRect {
|
||||
return @bitCast(c.struct_CGRect, self);
|
||||
}
|
||||
|
64
pkg/macos/graphics/path.zig
Normal file
64
pkg/macos/graphics/path.zig
Normal file
@ -0,0 +1,64 @@
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const foundation = @import("../foundation.zig");
|
||||
const graphics = @import("../graphics.zig");
|
||||
const c = @import("c.zig");
|
||||
|
||||
pub const Path = opaque {
|
||||
pub fn createWithRect(
|
||||
rect: graphics.Rect,
|
||||
transform: ?*const graphics.AffineTransform,
|
||||
) Allocator.Error!*Path {
|
||||
return @intToPtr(
|
||||
?*Path,
|
||||
@ptrToInt(c.CGPathCreateWithRect(
|
||||
rect.cval(),
|
||||
@ptrCast(?[*]const c.struct_CGAffineTransform, transform),
|
||||
)),
|
||||
) orelse Allocator.Error.OutOfMemory;
|
||||
}
|
||||
|
||||
pub fn release(self: *Path) void {
|
||||
foundation.CFRelease(self);
|
||||
}
|
||||
};
|
||||
|
||||
pub const MutablePath = opaque {
|
||||
pub fn create() Allocator.Error!*MutablePath {
|
||||
return @intToPtr(
|
||||
?*MutablePath,
|
||||
@ptrToInt(c.CGPathCreateMutable()),
|
||||
) orelse Allocator.Error.OutOfMemory;
|
||||
}
|
||||
|
||||
pub fn release(self: *MutablePath) void {
|
||||
foundation.CFRelease(self);
|
||||
}
|
||||
|
||||
pub fn addRect(
|
||||
self: *MutablePath,
|
||||
transform: ?*const graphics.AffineTransform,
|
||||
rect: graphics.Rect,
|
||||
) void {
|
||||
c.CGPathAddRect(
|
||||
@ptrCast(c.CGMutablePathRef, self),
|
||||
@ptrCast(?[*]const c.struct_CGAffineTransform, transform),
|
||||
rect.cval(),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
test "mutable path" {
|
||||
//const testing = std.testing;
|
||||
|
||||
const path = try MutablePath.create();
|
||||
defer path.release();
|
||||
|
||||
path.addRect(null, graphics.Rect.init(0, 0, 100, 200));
|
||||
}
|
||||
|
||||
test "path from rect" {
|
||||
const path = try Path.createWithRect(graphics.Rect.init(0, 0, 100, 200), null);
|
||||
defer path.release();
|
||||
}
|
Reference in New Issue
Block a user