aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/pkg/macos/graphics/context.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-04 19:22:04 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-05 01:23:06 +0300
commit41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch)
tree3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/pkg/macos/graphics/context.zig
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/pkg/macos/graphics/context.zig')
-rw-r--r--vendor/libghostty-vt/pkg/macos/graphics/context.zig172
1 files changed, 172 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/pkg/macos/graphics/context.zig b/vendor/libghostty-vt/pkg/macos/graphics/context.zig
new file mode 100644
index 00000000..77e4344e
--- /dev/null
+++ b/vendor/libghostty-vt/pkg/macos/graphics/context.zig
@@ -0,0 +1,172 @@
+const std = @import("std");
+const assert = std.debug.assert;
+const Allocator = std.mem.Allocator;
+const graphics = @import("../graphics.zig");
+const c = @import("c.zig").c;
+
+/// Returns a struct that has all the shared context functions for the
+/// given type.
+pub fn Context(comptime T: type) type {
+ return struct {
+ value: *T,
+
+ pub fn release(self: *T) void {
+ c.CGContextRelease(@ptrCast(self));
+ }
+
+ pub fn setLineWidth(self: *T, width: f64) void {
+ c.CGContextSetLineWidth(
+ @ptrCast(self),
+ width,
+ );
+ }
+
+ pub fn setAllowsAntialiasing(self: *T, v: bool) void {
+ c.CGContextSetAllowsAntialiasing(
+ @ptrCast(self),
+ v,
+ );
+ }
+
+ pub fn setAllowsFontSmoothing(self: *T, v: bool) void {
+ c.CGContextSetAllowsFontSmoothing(
+ @ptrCast(self),
+ v,
+ );
+ }
+
+ pub fn setAllowsFontSubpixelPositioning(self: *T, v: bool) void {
+ c.CGContextSetAllowsFontSubpixelPositioning(
+ @ptrCast(self),
+ v,
+ );
+ }
+
+ pub fn setAllowsFontSubpixelQuantization(self: *T, v: bool) void {
+ c.CGContextSetAllowsFontSubpixelQuantization(
+ @ptrCast(self),
+ v,
+ );
+ }
+
+ pub fn setShouldAntialias(self: *T, v: bool) void {
+ c.CGContextSetShouldAntialias(
+ @ptrCast(self),
+ v,
+ );
+ }
+
+ pub fn setShouldSmoothFonts(self: *T, v: bool) void {
+ c.CGContextSetShouldSmoothFonts(
+ @ptrCast(self),
+ v,
+ );
+ }
+
+ pub fn setShouldSubpixelPositionFonts(self: *T, v: bool) void {
+ c.CGContextSetShouldSubpixelPositionFonts(
+ @ptrCast(self),
+ v,
+ );
+ }
+
+ pub fn setShouldSubpixelQuantizeFonts(self: *T, v: bool) void {
+ c.CGContextSetShouldSubpixelQuantizeFonts(
+ @ptrCast(self),
+ v,
+ );
+ }
+
+ pub fn setGrayFillColor(self: *T, gray: f64, alpha: f64) void {
+ c.CGContextSetGrayFillColor(
+ @ptrCast(self),
+ gray,
+ alpha,
+ );
+ }
+
+ pub fn setGrayStrokeColor(self: *T, gray: f64, alpha: f64) void {
+ c.CGContextSetGrayStrokeColor(
+ @ptrCast(self),
+ gray,
+ alpha,
+ );
+ }
+
+ pub fn setRGBFillColor(self: *T, r: f64, g: f64, b: f64, alpha: f64) void {
+ c.CGContextSetRGBFillColor(
+ @ptrCast(self),
+ r,
+ g,
+ b,
+ alpha,
+ );
+ }
+
+ pub fn setRGBStrokeColor(self: *T, r: f64, g: f64, b: f64, alpha: f64) void {
+ c.CGContextSetRGBStrokeColor(
+ @ptrCast(self),
+ r,
+ g,
+ b,
+ alpha,
+ );
+ }
+
+ pub fn setTextDrawingMode(self: *T, mode: TextDrawingMode) void {
+ c.CGContextSetTextDrawingMode(
+ @ptrCast(self),
+ @intFromEnum(mode),
+ );
+ }
+
+ pub fn setTextMatrix(self: *T, matrix: graphics.AffineTransform) void {
+ c.CGContextSetTextMatrix(
+ @ptrCast(self),
+ @bitCast(matrix),
+ );
+ }
+
+ pub fn setTextPosition(self: *T, x: f64, y: f64) void {
+ c.CGContextSetTextPosition(
+ @ptrCast(self),
+ x,
+ y,
+ );
+ }
+
+ pub fn fillRect(self: *T, rect: graphics.Rect) void {
+ c.CGContextFillRect(
+ @ptrCast(self),
+ @bitCast(rect),
+ );
+ }
+
+ pub fn scaleCTM(self: *T, sx: c.CGFloat, sy: c.CGFloat) void {
+ c.CGContextScaleCTM(
+ @ptrCast(self),
+ sx,
+ sy,
+ );
+ }
+
+ pub fn translateCTM(self: *T, tx: c.CGFloat, ty: c.CGFloat) void {
+ c.CGContextTranslateCTM(
+ @ptrCast(self),
+ tx,
+ ty,
+ );
+ }
+ };
+}
+
+pub const TextDrawingMode = enum(c_int) {
+ fill = c.kCGTextFill,
+ stroke = c.kCGTextStroke,
+ fill_stroke = c.kCGTextFillStroke,
+ invisible = c.kCGTextInvisible,
+ fill_clip = c.kCGTextFillClip,
+ stroke_clip = c.kCGTextStrokeClip,
+ fill_stroke_clip = c.kCGTextFillStrokeClip,
+ clip = c.kCGTextClip,
+};