mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Update Zig (#164)
* update zig * pkg/fontconfig: clean up @as * pkg/freetype,harfbuzz: clean up @as * pkg/imgui: clean up @as * pkg/macos: clean up @as * pkg/pixman,utf8proc: clean up @as * clean up @as * lots more @as cleanup * undo flatpak changes * clean up @as
This commit is contained in:

committed by
GitHub

parent
0c632e7345
commit
314f9287b1
6
flake.lock
generated
6
flake.lock
generated
@ -126,11 +126,11 @@
|
|||||||
"nixpkgs": "nixpkgs_2"
|
"nixpkgs": "nixpkgs_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1687694884,
|
"lastModified": 1688126918,
|
||||||
"narHash": "sha256-TLXEykE/LSMwGETveZ9lI8fvd7nuJgq0+6tQwvCvP1k=",
|
"narHash": "sha256-A4j6rWShGZf2wf7RwTd1sWhN9qLAINDYsExqZD6N09k=",
|
||||||
"owner": "mitchellh",
|
"owner": "mitchellh",
|
||||||
"repo": "zig-overlay",
|
"repo": "zig-overlay",
|
||||||
"rev": "1c1c9f9ecc76ec222826770e10e6fef4c54d1e82",
|
"rev": "601ed4533722f87b9e97580d30ddd687e58c6b16",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -4,7 +4,7 @@ const c = @import("c.zig");
|
|||||||
|
|
||||||
pub const CharSet = opaque {
|
pub const CharSet = opaque {
|
||||||
pub fn create() *CharSet {
|
pub fn create() *CharSet {
|
||||||
return @ptrCast(*CharSet, c.FcCharSetCreate());
|
return @ptrCast(c.FcCharSetCreate());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(self: *CharSet) void {
|
pub fn destroy(self: *CharSet) void {
|
||||||
@ -20,17 +20,11 @@ pub const CharSet = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cval(self: *CharSet) *c.struct__FcCharSet {
|
pub inline fn cval(self: *CharSet) *c.struct__FcCharSet {
|
||||||
return @ptrCast(
|
return @ptrCast(self);
|
||||||
*c.struct__FcCharSet,
|
|
||||||
self,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cvalConst(self: *const CharSet) *const c.struct__FcCharSet {
|
pub inline fn cvalConst(self: *const CharSet) *const c.struct__FcCharSet {
|
||||||
return @ptrCast(
|
return @ptrCast(self);
|
||||||
*const c.struct__FcCharSet,
|
|
||||||
self,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,11 +10,11 @@ const MatchKind = @import("main.zig").MatchKind;
|
|||||||
|
|
||||||
pub const Config = opaque {
|
pub const Config = opaque {
|
||||||
pub fn destroy(self: *Config) void {
|
pub fn destroy(self: *Config) void {
|
||||||
c.FcConfigDestroy(@ptrCast(*c.struct__FcConfig, self));
|
c.FcConfigDestroy(@ptrCast(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fontList(self: *Config, pat: *Pattern, os: *ObjectSet) *FontSet {
|
pub fn fontList(self: *Config, pat: *Pattern, os: *ObjectSet) *FontSet {
|
||||||
return @ptrCast(*FontSet, c.FcFontList(self.cval(), pat.cval(), os.cval()));
|
return @ptrCast(c.FcFontList(self.cval(), pat.cval(), os.cval()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fontSort(
|
pub fn fontSort(
|
||||||
@ -24,21 +24,21 @@ pub const Config = opaque {
|
|||||||
charset: ?[*]*CharSet,
|
charset: ?[*]*CharSet,
|
||||||
) FontSortResult {
|
) FontSortResult {
|
||||||
var result: FontSortResult = undefined;
|
var result: FontSortResult = undefined;
|
||||||
result.fs = @ptrCast(*FontSet, c.FcFontSort(
|
result.fs = @ptrCast(c.FcFontSort(
|
||||||
self.cval(),
|
self.cval(),
|
||||||
pat.cval(),
|
pat.cval(),
|
||||||
if (trim) c.FcTrue else c.FcFalse,
|
if (trim) c.FcTrue else c.FcFalse,
|
||||||
@ptrCast([*c]?*c.struct__FcCharSet, charset),
|
@ptrCast(charset),
|
||||||
@ptrCast([*c]c_uint, &result.result),
|
@ptrCast(&result.result),
|
||||||
));
|
));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fontRenderPrepare(self: *Config, pat: *Pattern, font: *Pattern) Error!*Pattern {
|
pub fn fontRenderPrepare(self: *Config, pat: *Pattern, font: *Pattern) Error!*Pattern {
|
||||||
return @ptrCast(
|
return @as(
|
||||||
?*Pattern,
|
?*Pattern,
|
||||||
c.FcFontRenderPrepare(self.cval(), pat.cval(), font.cval()),
|
@ptrCast(c.FcFontRenderPrepare(self.cval(), pat.cval(), font.cval())),
|
||||||
) orelse Error.FontconfigFailed;
|
) orelse Error.FontconfigFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ pub const Config = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cval(self: *Config) *c.struct__FcConfig {
|
pub inline fn cval(self: *Config) *c.struct__FcConfig {
|
||||||
return @ptrCast(*c.struct__FcConfig, self);
|
return @ptrCast(self);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ const Pattern = @import("pattern.zig").Pattern;
|
|||||||
|
|
||||||
pub const FontSet = opaque {
|
pub const FontSet = opaque {
|
||||||
pub fn create() *FontSet {
|
pub fn create() *FontSet {
|
||||||
return @ptrCast(*FontSet, c.FcFontSetCreate());
|
return @ptrCast(c.FcFontSetCreate());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(self: *FontSet) void {
|
pub fn destroy(self: *FontSet) void {
|
||||||
@ -16,8 +16,8 @@ pub const FontSet = opaque {
|
|||||||
const empty: [0]*Pattern = undefined;
|
const empty: [0]*Pattern = undefined;
|
||||||
const s = self.cval();
|
const s = self.cval();
|
||||||
if (s.fonts == null) return ∅
|
if (s.fonts == null) return ∅
|
||||||
const ptr = @ptrCast([*]*Pattern, @alignCast(@alignOf(*Pattern), s.fonts));
|
const ptr: [*]*Pattern = @ptrCast(@alignCast(s.fonts));
|
||||||
const len = @intCast(usize, s.nfont);
|
const len: usize = @intCast(s.nfont);
|
||||||
return ptr[0..len];
|
return ptr[0..len];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,10 +30,7 @@ pub const FontSet = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cval(self: *FontSet) *c.struct__FcFontSet {
|
pub inline fn cval(self: *FontSet) *c.struct__FcFontSet {
|
||||||
return @ptrCast(
|
return @ptrCast(@alignCast(self));
|
||||||
*c.struct__FcFontSet,
|
|
||||||
@alignCast(@alignOf(c.struct__FcFontSet), self),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,15 +11,15 @@ pub fn fini() void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn initLoadConfig() *Config {
|
pub fn initLoadConfig() *Config {
|
||||||
return @ptrCast(*Config, c.FcInitLoadConfig());
|
return @ptrCast(c.FcInitLoadConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initLoadConfigAndFonts() *Config {
|
pub fn initLoadConfigAndFonts() *Config {
|
||||||
return @ptrCast(*Config, c.FcInitLoadConfigAndFonts());
|
return @ptrCast(c.FcInitLoadConfigAndFonts());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn version() u32 {
|
pub fn version() u32 {
|
||||||
return @intCast(u32, c.FcGetVersion());
|
return @intCast(c.FcGetVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
test "version" {
|
test "version" {
|
||||||
|
@ -4,7 +4,7 @@ const c = @import("c.zig");
|
|||||||
|
|
||||||
pub const LangSet = opaque {
|
pub const LangSet = opaque {
|
||||||
pub fn create() *LangSet {
|
pub fn create() *LangSet {
|
||||||
return @ptrCast(*LangSet, c.FcLangSetCreate());
|
return @ptrCast(c.FcLangSetCreate());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(self: *LangSet) void {
|
pub fn destroy(self: *LangSet) void {
|
||||||
@ -16,17 +16,11 @@ pub const LangSet = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cval(self: *LangSet) *c.struct__FcLangSet {
|
pub inline fn cval(self: *LangSet) *c.struct__FcLangSet {
|
||||||
return @ptrCast(
|
return @ptrCast(self);
|
||||||
*c.struct__FcLangSet,
|
|
||||||
self,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cvalConst(self: *const LangSet) *const c.struct__FcLangSet {
|
pub inline fn cvalConst(self: *const LangSet) *const c.struct__FcLangSet {
|
||||||
return @ptrCast(
|
return @ptrCast(self);
|
||||||
*const c.struct__FcLangSet,
|
|
||||||
self,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ const Property = @import("main.zig").Property;
|
|||||||
|
|
||||||
pub const ObjectSet = opaque {
|
pub const ObjectSet = opaque {
|
||||||
pub fn create() *ObjectSet {
|
pub fn create() *ObjectSet {
|
||||||
return @ptrCast(*ObjectSet, c.FcObjectSetCreate());
|
return @ptrCast(c.FcObjectSetCreate());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(self: *ObjectSet) void {
|
pub fn destroy(self: *ObjectSet) void {
|
||||||
@ -16,10 +16,7 @@ pub const ObjectSet = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cval(self: *ObjectSet) *c.struct__FcObjectSet {
|
pub inline fn cval(self: *ObjectSet) *c.struct__FcObjectSet {
|
||||||
return @ptrCast(
|
return @ptrCast(@alignCast(self));
|
||||||
*c.struct__FcObjectSet,
|
|
||||||
@alignCast(@alignOf(c.struct__FcObjectSet), self),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,11 +11,11 @@ const Weight = @import("main.zig").Weight;
|
|||||||
|
|
||||||
pub const Pattern = opaque {
|
pub const Pattern = opaque {
|
||||||
pub fn create() *Pattern {
|
pub fn create() *Pattern {
|
||||||
return @ptrCast(*Pattern, c.FcPatternCreate());
|
return @ptrCast(c.FcPatternCreate());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(str: [:0]const u8) *Pattern {
|
pub fn parse(str: [:0]const u8) *Pattern {
|
||||||
return @ptrCast(*Pattern, c.FcNameParse(str.ptr));
|
return @ptrCast(c.FcNameParse(str.ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(self: *Pattern) void {
|
pub fn destroy(self: *Pattern) void {
|
||||||
@ -37,12 +37,12 @@ pub const Pattern = opaque {
|
|||||||
|
|
||||||
pub fn get(self: *Pattern, prop: Property, id: u32) Error!Value {
|
pub fn get(self: *Pattern, prop: Property, id: u32) Error!Value {
|
||||||
var val: c.struct__FcValue = undefined;
|
var val: c.struct__FcValue = undefined;
|
||||||
try @enumFromInt(Result, c.FcPatternGet(
|
try @as(Result, @enumFromInt(c.FcPatternGet(
|
||||||
self.cval(),
|
self.cval(),
|
||||||
prop.cval().ptr,
|
prop.cval().ptr,
|
||||||
@intCast(c_int, id),
|
@intCast(id),
|
||||||
&val,
|
&val,
|
||||||
)).toError();
|
))).toError();
|
||||||
|
|
||||||
return Value.init(&val);
|
return Value.init(&val);
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ pub const Pattern = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn filter(self: *Pattern, os: *const ObjectSet) *Pattern {
|
pub fn filter(self: *Pattern, os: *const ObjectSet) *Pattern {
|
||||||
return @ptrCast(*Pattern, c.FcPatternFilter(self.cval(), os.cval()));
|
return @ptrCast(c.FcPatternFilter(self.cval(), os.cval()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn objectIterator(self: *Pattern) ObjectIterator {
|
pub fn objectIterator(self: *Pattern) ObjectIterator {
|
||||||
@ -64,7 +64,7 @@ pub const Pattern = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cval(self: *Pattern) *c.struct__FcPattern {
|
pub inline fn cval(self: *Pattern) *c.struct__FcPattern {
|
||||||
return @ptrCast(*c.struct__FcPattern, self);
|
return @ptrCast(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ObjectIterator = struct {
|
pub const ObjectIterator = struct {
|
||||||
@ -93,10 +93,7 @@ pub const Pattern = opaque {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.FcPatternIterNext(
|
return c.FcPatternIterNext(self.pat, @ptrCast(&self.iter)) == c.FcTrue;
|
||||||
self.pat,
|
|
||||||
@ptrCast([*c]c.struct__FcPatternIter, &self.iter),
|
|
||||||
) == c.FcTrue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn object(self: *ObjectIterator) []const u8 {
|
pub fn object(self: *ObjectIterator) []const u8 {
|
||||||
@ -107,7 +104,7 @@ pub const Pattern = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn valueLen(self: *ObjectIterator) usize {
|
pub fn valueLen(self: *ObjectIterator) usize {
|
||||||
return @intCast(usize, c.FcPatternIterValueCount(self.pat, &self.iter.?));
|
return @intCast(c.FcPatternIterValueCount(self.pat, &self.iter.?));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn valueIterator(self: *ObjectIterator) ValueIterator {
|
pub fn valueIterator(self: *ObjectIterator) ValueIterator {
|
||||||
@ -139,8 +136,8 @@ pub const Pattern = opaque {
|
|||||||
self.id += 1;
|
self.id += 1;
|
||||||
|
|
||||||
return Entry{
|
return Entry{
|
||||||
.result = @enumFromInt(Result, result),
|
.result = @enumFromInt(result),
|
||||||
.binding = @enumFromInt(ValueBinding, binding),
|
.binding = @enumFromInt(binding),
|
||||||
.value = Value.init(&value),
|
.value = Value.init(&value),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,6 @@ pub const Range = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cval(self: *Range) *c.struct__FcRange {
|
pub inline fn cval(self: *Range) *c.struct__FcRange {
|
||||||
return @ptrCast(
|
return @ptrCast(self);
|
||||||
*c.struct__FcRange,
|
|
||||||
self,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -34,18 +34,18 @@ pub const Value = union(Type) {
|
|||||||
range: *const Range,
|
range: *const Range,
|
||||||
|
|
||||||
pub fn init(cvalue: *c.struct__FcValue) Value {
|
pub fn init(cvalue: *c.struct__FcValue) Value {
|
||||||
return switch (@enumFromInt(Type, cvalue.type)) {
|
return switch (@as(Type, @enumFromInt(cvalue.type))) {
|
||||||
.unknown => .{ .unknown = {} },
|
.unknown => .{ .unknown = {} },
|
||||||
.void => .{ .void = {} },
|
.void => .{ .void = {} },
|
||||||
.string => .{ .string = std.mem.sliceTo(cvalue.u.s, 0) },
|
.string => .{ .string = std.mem.sliceTo(cvalue.u.s, 0) },
|
||||||
.integer => .{ .integer = @intCast(i32, cvalue.u.i) },
|
.integer => .{ .integer = @intCast(cvalue.u.i) },
|
||||||
.double => .{ .double = cvalue.u.d },
|
.double => .{ .double = cvalue.u.d },
|
||||||
.bool => .{ .bool = cvalue.u.b == c.FcTrue },
|
.bool => .{ .bool = cvalue.u.b == c.FcTrue },
|
||||||
.matrix => .{ .matrix = @ptrCast(*const Matrix, cvalue.u.m) },
|
.matrix => .{ .matrix = @ptrCast(cvalue.u.m) },
|
||||||
.char_set => .{ .char_set = @ptrCast(*const CharSet, cvalue.u.c) },
|
.char_set => .{ .char_set = @ptrCast(cvalue.u.c) },
|
||||||
.ft_face => .{ .ft_face = @ptrCast(*anyopaque, cvalue.u.f) },
|
.ft_face => .{ .ft_face = @ptrCast(cvalue.u.f) },
|
||||||
.lang_set => .{ .lang_set = @ptrCast(*const LangSet, cvalue.u.l) },
|
.lang_set => .{ .lang_set = @ptrCast(cvalue.u.l) },
|
||||||
.range => .{ .range = @ptrCast(*const Range, cvalue.u.r) },
|
.range => .{ .range = @ptrCast(cvalue.u.r) },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,15 +55,15 @@ pub const Value = union(Type) {
|
|||||||
.u = switch (self) {
|
.u = switch (self) {
|
||||||
.unknown => undefined,
|
.unknown => undefined,
|
||||||
.void => undefined,
|
.void => undefined,
|
||||||
.integer => |v| .{ .i = @intCast(c_int, v) },
|
.integer => |v| .{ .i = @intCast(v) },
|
||||||
.double => |v| .{ .d = v },
|
.double => |v| .{ .d = v },
|
||||||
.string => |v| .{ .s = v.ptr },
|
.string => |v| .{ .s = v.ptr },
|
||||||
.bool => |v| .{ .b = if (v) c.FcTrue else c.FcFalse },
|
.bool => |v| .{ .b = if (v) c.FcTrue else c.FcFalse },
|
||||||
.matrix => |v| .{ .m = @ptrCast(*const c.struct__FcMatrix, v) },
|
.matrix => |v| .{ .m = @ptrCast(v) },
|
||||||
.char_set => |v| .{ .c = @ptrCast(*const c.struct__FcCharSet, v) },
|
.char_set => |v| .{ .c = @ptrCast(v) },
|
||||||
.ft_face => |v| .{ .f = v },
|
.ft_face => |v| .{ .f = v },
|
||||||
.lang_set => |v| .{ .l = @ptrCast(*const c.struct__FcLangSet, v) },
|
.lang_set => |v| .{ .l = @ptrCast(v) },
|
||||||
.range => |v| .{ .r = @ptrCast(*const c.struct__FcRange, v) },
|
.range => |v| .{ .r = @ptrCast(v) },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ pub fn initMemoryFace(self: Library, data: []const u8, index: i32) Error!Face {
|
|||||||
try intToError(c.FT_New_Memory_Face(
|
try intToError(c.FT_New_Memory_Face(
|
||||||
self.handle,
|
self.handle,
|
||||||
data.ptr,
|
data.ptr,
|
||||||
@intCast(c_long, data.len),
|
@intCast(data.len),
|
||||||
index,
|
index,
|
||||||
&face.handle,
|
&face.handle,
|
||||||
));
|
));
|
||||||
|
@ -4,5 +4,5 @@ const c = @import("c.zig");
|
|||||||
/// Compute (a*b)/0x10000 with maximum accuracy. Its main use is to multiply
|
/// Compute (a*b)/0x10000 with maximum accuracy. Its main use is to multiply
|
||||||
/// a given value by a 16.16 fixed-point factor.
|
/// a given value by a 16.16 fixed-point factor.
|
||||||
pub fn mulFix(a: i32, b: i32) i32 {
|
pub fn mulFix(a: i32, b: i32) i32 {
|
||||||
return @intCast(i32, c.FT_MulFix(a, b));
|
return @intCast(c.FT_MulFix(a, b));
|
||||||
}
|
}
|
||||||
|
@ -72,14 +72,13 @@ pub const Face = struct {
|
|||||||
return intToError(c.FT_Load_Glyph(
|
return intToError(c.FT_Load_Glyph(
|
||||||
self.handle,
|
self.handle,
|
||||||
glyph_index,
|
glyph_index,
|
||||||
@bitCast(i32, load_flags),
|
@bitCast(load_flags),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a pointer to a given SFNT table stored within a face.
|
/// Return a pointer to a given SFNT table stored within a face.
|
||||||
pub fn getSfntTable(self: Face, comptime tag: SfntTag) ?*tag.DataType() {
|
pub fn getSfntTable(self: Face, comptime tag: SfntTag) ?*tag.DataType() {
|
||||||
const T = tag.DataType();
|
return @ptrCast(@alignCast(c.FT_Get_Sfnt_Table(
|
||||||
return @ptrCast(?*T, @alignCast(@alignOf(T), c.FT_Get_Sfnt_Table(
|
|
||||||
self.handle,
|
self.handle,
|
||||||
@intFromEnum(tag),
|
@intFromEnum(tag),
|
||||||
)));
|
)));
|
||||||
@ -163,7 +162,7 @@ pub const LoadFlags = packed struct {
|
|||||||
test "bitcast" {
|
test "bitcast" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const cval: i32 = c.FT_LOAD_RENDER | c.FT_LOAD_PEDANTIC | c.FT_LOAD_COLOR;
|
const cval: i32 = c.FT_LOAD_RENDER | c.FT_LOAD_PEDANTIC | c.FT_LOAD_COLOR;
|
||||||
const flags = @bitCast(LoadFlags, cval);
|
const flags = @as(LoadFlags, @bitCast(cval));
|
||||||
try testing.expect(!flags.no_hinting);
|
try testing.expect(!flags.no_hinting);
|
||||||
try testing.expect(flags.render);
|
try testing.expect(flags.render);
|
||||||
try testing.expect(flags.pedantic);
|
try testing.expect(flags.pedantic);
|
||||||
|
@ -54,7 +54,7 @@ pub const Blob = struct {
|
|||||||
pub fn create(data: []const u8, mode: MemoryMode) Error!Blob {
|
pub fn create(data: []const u8, mode: MemoryMode) Error!Blob {
|
||||||
const handle = c.hb_blob_create_or_fail(
|
const handle = c.hb_blob_create_or_fail(
|
||||||
data.ptr,
|
data.ptr,
|
||||||
@intCast(c_uint, data.len),
|
@intCast(data.len),
|
||||||
@intFromEnum(mode),
|
@intFromEnum(mode),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@ -83,14 +83,14 @@ pub const Blob = struct {
|
|||||||
const Callback = struct {
|
const Callback = struct {
|
||||||
pub fn callback(data: ?*anyopaque) callconv(.C) void {
|
pub fn callback(data: ?*anyopaque) callconv(.C) void {
|
||||||
@call(.{ .modifier = .always_inline }, destroycb, .{
|
@call(.{ .modifier = .always_inline }, destroycb, .{
|
||||||
@ptrCast(?*T, @alignCast(@alignOf(T), data)),
|
@as(?*T, @ptrCast(@alignCast(data))),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return c.hb_blob_set_user_data(
|
return c.hb_blob_set_user_data(
|
||||||
self.handle,
|
self.handle,
|
||||||
@ptrCast([*c]c.hb_user_data_key_t, key),
|
@ptrCast(key),
|
||||||
ptr,
|
ptr,
|
||||||
if (destroycb != null) Callback.callback else null,
|
if (destroycb != null) Callback.callback else null,
|
||||||
if (replace) 1 else 0,
|
if (replace) 1 else 0,
|
||||||
@ -104,13 +104,9 @@ pub const Blob = struct {
|
|||||||
comptime T: type,
|
comptime T: type,
|
||||||
key: ?*anyopaque,
|
key: ?*anyopaque,
|
||||||
) ?*T {
|
) ?*T {
|
||||||
const opt = c.hb_blob_get_user_data(
|
const opt = c.hb_blob_get_user_data(self.handle, @ptrCast(key));
|
||||||
self.handle,
|
|
||||||
@ptrCast([*c]c.hb_user_data_key_t, key),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (opt) |ptr|
|
if (opt) |ptr|
|
||||||
return @ptrCast(?*T, @alignCast(@alignOf(T), ptr))
|
return @ptrCast(@alignCast(ptr))
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ pub const Buffer = struct {
|
|||||||
/// Fetches the type of buffer contents. Buffers are either empty, contain
|
/// Fetches the type of buffer contents. Buffers are either empty, contain
|
||||||
/// characters (before shaping), or contain glyphs (the result of shaping).
|
/// characters (before shaping), or contain glyphs (the result of shaping).
|
||||||
pub fn getContentType(self: Buffer) ContentType {
|
pub fn getContentType(self: Buffer) ContentType {
|
||||||
return @enumFromInt(ContentType, c.hb_buffer_get_content_type(self.handle));
|
return @enumFromInt(c.hb_buffer_get_content_type(self.handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Appends a character with the Unicode value of codepoint to buffer,
|
/// Appends a character with the Unicode value of codepoint to buffer,
|
||||||
@ -76,9 +76,9 @@ pub const Buffer = struct {
|
|||||||
c.hb_buffer_add_codepoints(
|
c.hb_buffer_add_codepoints(
|
||||||
self.handle,
|
self.handle,
|
||||||
text.ptr,
|
text.ptr,
|
||||||
@intCast(c_int, text.len),
|
@intCast(text.len),
|
||||||
0,
|
0,
|
||||||
@intCast(c_int, text.len),
|
@intCast(text.len),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,9 +90,9 @@ pub const Buffer = struct {
|
|||||||
c.hb_buffer_add_utf32(
|
c.hb_buffer_add_utf32(
|
||||||
self.handle,
|
self.handle,
|
||||||
text.ptr,
|
text.ptr,
|
||||||
@intCast(c_int, text.len),
|
@intCast(text.len),
|
||||||
0,
|
0,
|
||||||
@intCast(c_int, text.len),
|
@intCast(text.len),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,9 +104,9 @@ pub const Buffer = struct {
|
|||||||
c.hb_buffer_add_utf16(
|
c.hb_buffer_add_utf16(
|
||||||
self.handle,
|
self.handle,
|
||||||
text.ptr,
|
text.ptr,
|
||||||
@intCast(c_int, text.len),
|
@intCast(text.len),
|
||||||
0,
|
0,
|
||||||
@intCast(c_int, text.len),
|
@intCast(text.len),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,9 +118,9 @@ pub const Buffer = struct {
|
|||||||
c.hb_buffer_add_utf8(
|
c.hb_buffer_add_utf8(
|
||||||
self.handle,
|
self.handle,
|
||||||
text.ptr,
|
text.ptr,
|
||||||
@intCast(c_int, text.len),
|
@intCast(text.len),
|
||||||
0,
|
0,
|
||||||
@intCast(c_int, text.len),
|
@intCast(text.len),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,9 +130,9 @@ pub const Buffer = struct {
|
|||||||
c.hb_buffer_add_latin1(
|
c.hb_buffer_add_latin1(
|
||||||
self.handle,
|
self.handle,
|
||||||
text.ptr,
|
text.ptr,
|
||||||
@intCast(c_int, text.len),
|
@intCast(text.len),
|
||||||
0,
|
0,
|
||||||
@intCast(c_int, text.len),
|
@intCast(text.len),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ pub const Buffer = struct {
|
|||||||
|
|
||||||
/// See hb_buffer_set_direction()
|
/// See hb_buffer_set_direction()
|
||||||
pub fn getDirection(self: Buffer) Direction {
|
pub fn getDirection(self: Buffer) Direction {
|
||||||
return @enumFromInt(Direction, c.hb_buffer_get_direction(self.handle));
|
return @enumFromInt(c.hb_buffer_get_direction(self.handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the script of buffer to script.
|
/// Sets the script of buffer to script.
|
||||||
@ -167,7 +167,7 @@ pub const Buffer = struct {
|
|||||||
|
|
||||||
/// See hb_buffer_set_script()
|
/// See hb_buffer_set_script()
|
||||||
pub fn getScript(self: Buffer) Script {
|
pub fn getScript(self: Buffer) Script {
|
||||||
return @enumFromInt(Script, c.hb_buffer_get_script(self.handle));
|
return @enumFromInt(c.hb_buffer_get_script(self.handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the language of buffer to language .
|
/// Sets the language of buffer to language .
|
||||||
@ -192,10 +192,7 @@ pub const Buffer = struct {
|
|||||||
/// long as buffer contents are not modified.
|
/// long as buffer contents are not modified.
|
||||||
pub fn getGlyphInfos(self: Buffer) []GlyphInfo {
|
pub fn getGlyphInfos(self: Buffer) []GlyphInfo {
|
||||||
var length: u32 = 0;
|
var length: u32 = 0;
|
||||||
const ptr = @ptrCast(
|
const ptr: [*c]GlyphInfo = @ptrCast(c.hb_buffer_get_glyph_infos(self.handle, &length));
|
||||||
[*c]GlyphInfo,
|
|
||||||
c.hb_buffer_get_glyph_infos(self.handle, &length),
|
|
||||||
);
|
|
||||||
return ptr[0..length];
|
return ptr[0..length];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +207,7 @@ pub const Buffer = struct {
|
|||||||
var length: u32 = 0;
|
var length: u32 = 0;
|
||||||
|
|
||||||
if (c.hb_buffer_get_glyph_positions(self.handle, &length)) |positions| {
|
if (c.hb_buffer_get_glyph_positions(self.handle, &length)) |positions| {
|
||||||
const ptr = @ptrCast([*]GlyphPosition, positions);
|
const ptr: [*]GlyphPosition = @ptrCast(positions);
|
||||||
return ptr[0..length];
|
return ptr[0..length];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,18 +194,15 @@ pub const Language = struct {
|
|||||||
/// hb_language_t.
|
/// hb_language_t.
|
||||||
pub fn fromString(str: []const u8) Language {
|
pub fn fromString(str: []const u8) Language {
|
||||||
return .{
|
return .{
|
||||||
.handle = c.hb_language_from_string(
|
.handle = c.hb_language_from_string(str.ptr, @intCast(str.len)),
|
||||||
str.ptr,
|
|
||||||
@intCast(c_int, str.len),
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts an hb_language_t to a string.
|
/// Converts an hb_language_t to a string.
|
||||||
pub fn toString(self: Language) [:0]const u8 {
|
pub fn toString(self: Language) [:0]const u8 {
|
||||||
return std.mem.span(@ptrCast(
|
return std.mem.span(@as(
|
||||||
[*:0]const u8,
|
[*:0]const u8,
|
||||||
c.hb_language_to_string(self.handle),
|
@ptrCast(c.hb_language_to_string(self.handle)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,16 +228,16 @@ pub const Feature = extern struct {
|
|||||||
var f: c.hb_feature_t = undefined;
|
var f: c.hb_feature_t = undefined;
|
||||||
return if (c.hb_feature_from_string(
|
return if (c.hb_feature_from_string(
|
||||||
str.ptr,
|
str.ptr,
|
||||||
@intCast(c_int, str.len),
|
@intCast(str.len),
|
||||||
&f,
|
&f,
|
||||||
) > 0)
|
) > 0)
|
||||||
@bitCast(Feature, f)
|
@bitCast(f)
|
||||||
else
|
else
|
||||||
null;
|
null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toString(self: *Feature, buf: []u8) void {
|
pub fn toString(self: *Feature, buf: []u8) void {
|
||||||
c.hb_feature_to_string(self, buf.ptr, @intCast(c_uint, buf.len));
|
c.hb_feature_to_string(self, buf.ptr, @intCast(buf.len));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ test {
|
|||||||
try testing.expect(ftc.FT_New_Memory_Face(
|
try testing.expect(ftc.FT_New_Memory_Face(
|
||||||
ft_lib,
|
ft_lib,
|
||||||
testFont,
|
testFont,
|
||||||
@intCast(c_long, testFont.len),
|
@intCast(testFont.len),
|
||||||
0,
|
0,
|
||||||
&ft_face,
|
&ft_face,
|
||||||
) == ftok);
|
) == ftok);
|
||||||
|
@ -12,9 +12,7 @@ const Feature = @import("common.zig").Feature;
|
|||||||
pub fn shape(font: Font, buf: Buffer, features: ?[]const Feature) void {
|
pub fn shape(font: Font, buf: Buffer, features: ?[]const Feature) void {
|
||||||
const hb_feats: [*c]const c.hb_feature_t = feats: {
|
const hb_feats: [*c]const c.hb_feature_t = feats: {
|
||||||
if (features) |fs| {
|
if (features) |fs| {
|
||||||
if (fs.len > 0) {
|
if (fs.len > 0) break :feats @ptrCast(fs.ptr);
|
||||||
break :feats @ptrCast([*]const c.hb_feature_t, fs.ptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break :feats null;
|
break :feats null;
|
||||||
@ -24,6 +22,6 @@ pub fn shape(font: Font, buf: Buffer, features: ?[]const Feature) void {
|
|||||||
font.handle,
|
font.handle,
|
||||||
buf.handle,
|
buf.handle,
|
||||||
hb_feats,
|
hb_feats,
|
||||||
if (features) |f| @intCast(c_uint, f.len) else 0,
|
if (features) |f| @intCast(f.len) else 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,9 @@ const Allocator = std.mem.Allocator;
|
|||||||
|
|
||||||
pub const Context = opaque {
|
pub const Context = opaque {
|
||||||
pub fn create() Allocator.Error!*Context {
|
pub fn create() Allocator.Error!*Context {
|
||||||
return @ptrCast(
|
return @as(
|
||||||
?*Context,
|
?*Context,
|
||||||
c.igCreateContext(null),
|
@ptrCast(c.igCreateContext(null)),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,10 +19,7 @@ pub const Context = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cval(self: *Context) *c.ImGuiContext {
|
pub inline fn cval(self: *Context) *c.ImGuiContext {
|
||||||
return @ptrCast(
|
return @ptrCast(@alignCast(self));
|
||||||
*c.ImGuiContext,
|
|
||||||
@alignCast(@alignOf(c.ImGuiContext), self),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,14 +27,14 @@ pub const tableHeadersRow = c.igTableHeadersRow;
|
|||||||
pub const tableNextColumn = c.igTableNextColumn;
|
pub const tableNextColumn = c.igTableNextColumn;
|
||||||
|
|
||||||
pub fn showDemoWindow(open: ?*bool) void {
|
pub fn showDemoWindow(open: ?*bool) void {
|
||||||
c.igShowDemoWindow(@ptrCast([*c]bool, if (open) |v| v else null));
|
c.igShowDemoWindow(@ptrCast(if (open) |v| v else null));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn begin(name: [:0]const u8, open: ?*bool, flags: WindowFlags) bool {
|
pub fn begin(name: [:0]const u8, open: ?*bool, flags: WindowFlags) bool {
|
||||||
return c.igBegin(
|
return c.igBegin(
|
||||||
name.ptr,
|
name.ptr,
|
||||||
@ptrCast([*c]bool, if (open) |v| v else null),
|
@ptrCast(if (open) |v| v else null),
|
||||||
@bitCast(c_int, flags),
|
@bitCast(flags),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,14 +45,14 @@ pub fn collapsingHeader(
|
|||||||
) bool {
|
) bool {
|
||||||
return c.igCollapsingHeader_BoolPtr(
|
return c.igCollapsingHeader_BoolPtr(
|
||||||
label.ptr,
|
label.ptr,
|
||||||
@ptrCast([*c]bool, if (visible) |v| v else null),
|
@ptrCast(if (visible) |v| v else null),
|
||||||
@bitCast(c_int, flags),
|
@bitCast(flags),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isItemHovered(flags: HoveredFlags) bool {
|
pub fn isItemHovered(flags: HoveredFlags) bool {
|
||||||
return c.igIsItemHovered(
|
return c.igIsItemHovered(
|
||||||
@bitCast(c_int, flags),
|
@bitCast(flags),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ pub fn treeNode(
|
|||||||
) bool {
|
) bool {
|
||||||
return c.igTreeNodeEx_Str(
|
return c.igTreeNodeEx_Str(
|
||||||
label.ptr,
|
label.ptr,
|
||||||
@bitCast(c_int, flags),
|
@bitCast(flags),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ pub fn beginTable(
|
|||||||
return c.igBeginTable(
|
return c.igBeginTable(
|
||||||
id.ptr,
|
id.ptr,
|
||||||
cols,
|
cols,
|
||||||
@bitCast(c_int, flags),
|
@bitCast(flags),
|
||||||
.{ .x = 0, .y = 0 },
|
.{ .x = 0, .y = 0 },
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
@ -91,7 +91,7 @@ pub fn tableSetupColumn(
|
|||||||
) void {
|
) void {
|
||||||
c.igTableSetupColumn(
|
c.igTableSetupColumn(
|
||||||
label.ptr,
|
label.ptr,
|
||||||
@bitCast(c_int, flags),
|
@bitCast(flags),
|
||||||
init_size,
|
init_size,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
@ -108,7 +108,7 @@ pub fn inputTextMultiline(
|
|||||||
buf.ptr,
|
buf.ptr,
|
||||||
buf.len,
|
buf.len,
|
||||||
size,
|
size,
|
||||||
@bitCast(c_int, flags),
|
@bitCast(flags),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
@ -5,16 +5,13 @@ const Allocator = std.mem.Allocator;
|
|||||||
|
|
||||||
pub const DrawData = opaque {
|
pub const DrawData = opaque {
|
||||||
pub fn get() Allocator.Error!*DrawData {
|
pub fn get() Allocator.Error!*DrawData {
|
||||||
return @ptrCast(
|
return @as(
|
||||||
?*DrawData,
|
?*DrawData,
|
||||||
c.igGetDrawData(),
|
@ptrCast(c.igGetDrawData()),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cval(self: *DrawData) *c.ImGuiDrawData {
|
pub inline fn cval(self: *DrawData) *c.ImGuiDrawData {
|
||||||
return @ptrCast(
|
return @ptrCast(@alignCast(self));
|
||||||
*c.ImGuiDrawData,
|
|
||||||
@alignCast(@alignOf(c.ImGuiDrawData), self),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -17,8 +17,8 @@ pub const FontAtlas = opaque {
|
|||||||
|
|
||||||
_ = c.ImFontAtlas_AddFontFromMemoryTTF(
|
_ = c.ImFontAtlas_AddFontFromMemoryTTF(
|
||||||
self.cval(),
|
self.cval(),
|
||||||
@ptrFromInt(?*anyopaque, @intFromPtr(data.ptr)),
|
@ptrFromInt(@intFromPtr(data.ptr)),
|
||||||
@intCast(c_int, data.len),
|
@intCast(data.len),
|
||||||
size_px,
|
size_px,
|
||||||
cfg,
|
cfg,
|
||||||
null,
|
null,
|
||||||
@ -26,9 +26,6 @@ pub const FontAtlas = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cval(self: *FontAtlas) *c.ImFontAtlas {
|
pub inline fn cval(self: *FontAtlas) *c.ImFontAtlas {
|
||||||
return @ptrCast(
|
return @ptrCast(@alignCast(self));
|
||||||
*c.ImFontAtlas,
|
|
||||||
@alignCast(@alignOf(c.ImFontAtlas), self),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -5,17 +5,14 @@ const Allocator = std.mem.Allocator;
|
|||||||
|
|
||||||
pub const IO = opaque {
|
pub const IO = opaque {
|
||||||
pub fn get() Allocator.Error!*IO {
|
pub fn get() Allocator.Error!*IO {
|
||||||
return @ptrCast(
|
return @as(
|
||||||
?*IO,
|
?*IO,
|
||||||
c.igGetIO(),
|
@ptrCast(c.igGetIO()),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cval(self: *IO) *c.ImGuiIO {
|
pub inline fn cval(self: *IO) *c.ImGuiIO {
|
||||||
return @ptrCast(
|
return @ptrCast(@alignCast(self));
|
||||||
*c.ImGuiIO,
|
|
||||||
@alignCast(@alignOf(c.ImGuiIO), self),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,9 +4,9 @@ const Allocator = std.mem.Allocator;
|
|||||||
|
|
||||||
pub const Style = opaque {
|
pub const Style = opaque {
|
||||||
pub fn get() Allocator.Error!*Style {
|
pub fn get() Allocator.Error!*Style {
|
||||||
return @ptrCast(
|
return @as(
|
||||||
?*Style,
|
?*Style,
|
||||||
c.igGetStyle(),
|
@ptrCast(c.igGetStyle()),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,9 +27,6 @@ pub const Style = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn cval(self: *Style) *c.ImGuiStyle {
|
pub inline fn cval(self: *Style) *c.ImGuiStyle {
|
||||||
return @ptrCast(
|
return @ptrCast(@alignCast(self));
|
||||||
*c.ImGuiStyle,
|
|
||||||
@alignCast(@alignOf(c.ImGuiStyle), self),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -6,8 +6,8 @@ pub const Array = opaque {
|
|||||||
pub fn create(comptime T: type, values: []*const T) Allocator.Error!*Array {
|
pub fn create(comptime T: type, values: []*const T) Allocator.Error!*Array {
|
||||||
return CFArrayCreate(
|
return CFArrayCreate(
|
||||||
null,
|
null,
|
||||||
@ptrCast([*]*const anyopaque, values.ptr),
|
@ptrCast(values.ptr),
|
||||||
@intCast(usize, values.len),
|
@intCast(values.len),
|
||||||
null,
|
null,
|
||||||
) orelse error.OutOfMemory;
|
) orelse error.OutOfMemory;
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ pub const Array = opaque {
|
|||||||
/// constness so that further API calls work correctly. The Foundation
|
/// constness so that further API calls work correctly. The Foundation
|
||||||
/// API doesn't properly mark things const/non-const.
|
/// API doesn't properly mark things const/non-const.
|
||||||
pub fn getValueAtIndex(self: *Array, comptime T: type, idx: usize) *T {
|
pub fn getValueAtIndex(self: *Array, comptime T: type, idx: usize) *T {
|
||||||
return @ptrCast(*T, CFArrayGetValueAtIndex(self, idx));
|
return @ptrCast(CFArrayGetValueAtIndex(self, idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern "c" fn CFArrayCreate(
|
pub extern "c" fn CFArrayCreate(
|
||||||
|
@ -11,30 +11,24 @@ pub const AttributedString = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getLength(self: *AttributedString) usize {
|
pub fn getLength(self: *AttributedString) usize {
|
||||||
return @intCast(
|
return @intCast(c.CFAttributedStringGetLength(@ptrCast(self)));
|
||||||
usize,
|
|
||||||
c.CFAttributedStringGetLength(@ptrCast(c.CFAttributedStringRef, self)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getString(self: *AttributedString) *foundation.String {
|
pub fn getString(self: *AttributedString) *foundation.String {
|
||||||
return @ptrFromInt(
|
return @ptrFromInt(@intFromPtr(
|
||||||
*foundation.String,
|
c.CFAttributedStringGetString(@ptrCast(self)),
|
||||||
@intFromPtr(
|
));
|
||||||
c.CFAttributedStringGetString(@ptrCast(c.CFAttributedStringRef, self)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const MutableAttributedString = opaque {
|
pub const MutableAttributedString = opaque {
|
||||||
pub fn create(cap: usize) Allocator.Error!*MutableAttributedString {
|
pub fn create(cap: usize) Allocator.Error!*MutableAttributedString {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*MutableAttributedString,
|
?*MutableAttributedString,
|
||||||
@intFromPtr(c.CFAttributedStringCreateMutable(
|
@ptrFromInt(@intFromPtr(c.CFAttributedStringCreateMutable(
|
||||||
null,
|
null,
|
||||||
@intCast(c.CFIndex, cap),
|
@intCast(cap),
|
||||||
)),
|
))),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,9 +42,9 @@ pub const MutableAttributedString = opaque {
|
|||||||
replacement: *foundation.String,
|
replacement: *foundation.String,
|
||||||
) void {
|
) void {
|
||||||
c.CFAttributedStringReplaceString(
|
c.CFAttributedStringReplaceString(
|
||||||
@ptrCast(c.CFMutableAttributedStringRef, self),
|
@ptrCast(self),
|
||||||
range.cval(),
|
range.cval(),
|
||||||
@ptrCast(c.CFStringRef, replacement),
|
@ptrCast(replacement),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,9 +63,9 @@ pub const MutableAttributedString = opaque {
|
|||||||
key;
|
key;
|
||||||
|
|
||||||
c.CFAttributedStringSetAttribute(
|
c.CFAttributedStringSetAttribute(
|
||||||
@ptrCast(c.CFMutableAttributedStringRef, self),
|
@ptrCast(self),
|
||||||
range.cval(),
|
range.cval(),
|
||||||
@ptrCast(c.CFStringRef, key_arg),
|
@ptrCast(key_arg),
|
||||||
value,
|
value,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,10 @@ pub const Range = extern struct {
|
|||||||
length: c.CFIndex,
|
length: c.CFIndex,
|
||||||
|
|
||||||
pub fn init(loc: usize, len: usize) Range {
|
pub fn init(loc: usize, len: usize) Range {
|
||||||
return @bitCast(Range, c.CFRangeMake(@intCast(c_long, loc), @intCast(c_long, len)));
|
return @bitCast(c.CFRangeMake(@intCast(loc), @intCast(len)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cval(self: Range) c.CFRange {
|
pub fn cval(self: Range) c.CFRange {
|
||||||
return @bitCast(c.CFRange, self);
|
return @bitCast(self);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -8,19 +8,19 @@ pub const CharacterSet = opaque {
|
|||||||
pub fn createWithCharactersInString(
|
pub fn createWithCharactersInString(
|
||||||
str: *foundation.String,
|
str: *foundation.String,
|
||||||
) Allocator.Error!*CharacterSet {
|
) Allocator.Error!*CharacterSet {
|
||||||
return @ptrFromInt(?*CharacterSet, @intFromPtr(c.CFCharacterSetCreateWithCharactersInString(
|
return @as(?*CharacterSet, @ptrFromInt(@intFromPtr(c.CFCharacterSetCreateWithCharactersInString(
|
||||||
null,
|
null,
|
||||||
@ptrCast(c.CFStringRef, str),
|
@ptrCast(str),
|
||||||
))) orelse Allocator.Error.OutOfMemory;
|
)))) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createWithCharactersInRange(
|
pub fn createWithCharactersInRange(
|
||||||
range: foundation.Range,
|
range: foundation.Range,
|
||||||
) Allocator.Error!*CharacterSet {
|
) Allocator.Error!*CharacterSet {
|
||||||
return @ptrFromInt(?*CharacterSet, @intFromPtr(c.CFCharacterSetCreateWithCharactersInRange(
|
return @as(?*CharacterSet, @ptrFromInt(@intFromPtr(c.CFCharacterSetCreateWithCharactersInRange(
|
||||||
null,
|
null,
|
||||||
range.cval(),
|
range.cval(),
|
||||||
))) orelse Allocator.Error.OutOfMemory;
|
)))) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn release(self: *CharacterSet) void {
|
pub fn release(self: *CharacterSet) void {
|
||||||
|
@ -5,14 +5,14 @@ const c = @import("c.zig");
|
|||||||
|
|
||||||
pub const Data = opaque {
|
pub const Data = opaque {
|
||||||
pub fn createWithBytesNoCopy(data: []const u8) Allocator.Error!*Data {
|
pub fn createWithBytesNoCopy(data: []const u8) Allocator.Error!*Data {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*Data,
|
?*Data,
|
||||||
@intFromPtr(c.CFDataCreateWithBytesNoCopy(
|
@ptrFromInt(@intFromPtr(c.CFDataCreateWithBytesNoCopy(
|
||||||
null,
|
null,
|
||||||
data.ptr,
|
data.ptr,
|
||||||
@intCast(c_long, data.len),
|
@intCast(data.len),
|
||||||
c.kCFAllocatorNull,
|
c.kCFAllocatorNull,
|
||||||
)),
|
))),
|
||||||
) orelse error.OutOfMemory;
|
) orelse error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,14 +15,14 @@ pub const Dictionary = opaque {
|
|||||||
assert(keys.?.len == values.?.len);
|
assert(keys.?.len == values.?.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return @ptrFromInt(?*Dictionary, @intFromPtr(c.CFDictionaryCreate(
|
return @as(?*Dictionary, @ptrFromInt(@intFromPtr(c.CFDictionaryCreate(
|
||||||
null,
|
null,
|
||||||
@ptrCast([*c]?*const anyopaque, if (keys) |slice| slice.ptr else null),
|
@ptrCast(if (keys) |slice| slice.ptr else null),
|
||||||
@ptrCast([*c]?*const anyopaque, if (values) |slice| slice.ptr else null),
|
@ptrCast(if (values) |slice| slice.ptr else null),
|
||||||
@intCast(c.CFIndex, if (keys) |slice| slice.len else 0),
|
@intCast(if (keys) |slice| slice.len else 0),
|
||||||
&c.kCFTypeDictionaryKeyCallBacks,
|
&c.kCFTypeDictionaryKeyCallBacks,
|
||||||
&c.kCFTypeDictionaryValueCallBacks,
|
&c.kCFTypeDictionaryValueCallBacks,
|
||||||
))) orelse Allocator.Error.OutOfMemory;
|
)))) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn release(self: *Dictionary) void {
|
pub fn release(self: *Dictionary) void {
|
||||||
@ -30,12 +30,12 @@ pub const Dictionary = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getCount(self: *Dictionary) usize {
|
pub fn getCount(self: *Dictionary) usize {
|
||||||
return @intCast(usize, c.CFDictionaryGetCount(@ptrCast(c.CFDictionaryRef, self)));
|
return @intCast(c.CFDictionaryGetCount(@ptrCast(self)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getValue(self: *Dictionary, comptime V: type, key: ?*const anyopaque) ?*V {
|
pub fn getValue(self: *Dictionary, comptime V: type, key: ?*const anyopaque) ?*V {
|
||||||
return @ptrFromInt(?*V, @intFromPtr(c.CFDictionaryGetValue(
|
return @ptrFromInt(@intFromPtr(c.CFDictionaryGetValue(
|
||||||
@ptrCast(c.CFDictionaryRef, self),
|
@ptrCast(self),
|
||||||
key,
|
key,
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
@ -43,20 +43,20 @@ pub const Dictionary = opaque {
|
|||||||
|
|
||||||
pub const MutableDictionary = opaque {
|
pub const MutableDictionary = opaque {
|
||||||
pub fn create(cap: usize) Allocator.Error!*MutableDictionary {
|
pub fn create(cap: usize) Allocator.Error!*MutableDictionary {
|
||||||
return @ptrFromInt(?*MutableDictionary, @intFromPtr(c.CFDictionaryCreateMutable(
|
return @as(?*MutableDictionary, @ptrFromInt(@intFromPtr(c.CFDictionaryCreateMutable(
|
||||||
null,
|
null,
|
||||||
@intCast(c.CFIndex, cap),
|
@intCast(cap),
|
||||||
&c.kCFTypeDictionaryKeyCallBacks,
|
&c.kCFTypeDictionaryKeyCallBacks,
|
||||||
&c.kCFTypeDictionaryValueCallBacks,
|
&c.kCFTypeDictionaryValueCallBacks,
|
||||||
))) orelse Allocator.Error.OutOfMemory;
|
)))) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createMutableCopy(cap: usize, src: *Dictionary) Allocator.Error!*MutableDictionary {
|
pub fn createMutableCopy(cap: usize, src: *Dictionary) Allocator.Error!*MutableDictionary {
|
||||||
return @ptrFromInt(?*MutableDictionary, @intFromPtr(c.CFDictionaryCreateMutableCopy(
|
return @as(?*MutableDictionary, @ptrFromInt(@intFromPtr(c.CFDictionaryCreateMutableCopy(
|
||||||
null,
|
null,
|
||||||
@intCast(c.CFIndex, cap),
|
@intCast(cap),
|
||||||
@ptrCast(c.CFDictionaryRef, src),
|
@ptrCast(src),
|
||||||
))) orelse Allocator.Error.OutOfMemory;
|
)))) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn release(self: *MutableDictionary) void {
|
pub fn release(self: *MutableDictionary) void {
|
||||||
@ -65,7 +65,7 @@ pub const MutableDictionary = opaque {
|
|||||||
|
|
||||||
pub fn setValue(self: *MutableDictionary, key: ?*const anyopaque, value: ?*const anyopaque) void {
|
pub fn setValue(self: *MutableDictionary, key: ?*const anyopaque, value: ?*const anyopaque) void {
|
||||||
c.CFDictionarySetValue(
|
c.CFDictionarySetValue(
|
||||||
@ptrCast(c.CFMutableDictionaryRef, self),
|
@ptrCast(self),
|
||||||
key,
|
key,
|
||||||
value,
|
value,
|
||||||
);
|
);
|
||||||
@ -100,7 +100,7 @@ test "mutable dictionary" {
|
|||||||
dict.setValue(c.kCFURLIsPurgeableKey, str);
|
dict.setValue(c.kCFURLIsPurgeableKey, str);
|
||||||
|
|
||||||
{
|
{
|
||||||
const imm = @ptrCast(*Dictionary, dict);
|
const imm = @as(*Dictionary, @ptrCast(dict));
|
||||||
try testing.expectEqual(@as(usize, 1), imm.getCount());
|
try testing.expectEqual(@as(usize, 1), imm.getCount());
|
||||||
try testing.expect(imm.getValue(foundation.String, c.kCFURLIsPurgeableKey) != null);
|
try testing.expect(imm.getValue(foundation.String, c.kCFURLIsPurgeableKey) != null);
|
||||||
try testing.expect(imm.getValue(foundation.String, c.kCFURLIsVolumeKey) == null);
|
try testing.expect(imm.getValue(foundation.String, c.kCFURLIsVolumeKey) == null);
|
||||||
|
@ -8,16 +8,16 @@ pub const Number = opaque {
|
|||||||
comptime type_: NumberType,
|
comptime type_: NumberType,
|
||||||
value: *const type_.ValueType(),
|
value: *const type_.ValueType(),
|
||||||
) Allocator.Error!*Number {
|
) Allocator.Error!*Number {
|
||||||
return @ptrFromInt(?*Number, @intFromPtr(c.CFNumberCreate(
|
return @as(?*Number, @ptrFromInt(@intFromPtr(c.CFNumberCreate(
|
||||||
null,
|
null,
|
||||||
@intFromEnum(type_),
|
@intFromEnum(type_),
|
||||||
value,
|
value,
|
||||||
))) orelse Allocator.Error.OutOfMemory;
|
)))) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getValue(self: *Number, comptime t: NumberType, ptr: *t.ValueType()) bool {
|
pub fn getValue(self: *Number, comptime t: NumberType, ptr: *t.ValueType()) bool {
|
||||||
return c.CFNumberGetValue(
|
return c.CFNumberGetValue(
|
||||||
@ptrCast(c.CFNumberRef, self),
|
@ptrCast(self),
|
||||||
@intFromEnum(t),
|
@intFromEnum(t),
|
||||||
ptr,
|
ptr,
|
||||||
) == 1;
|
) == 1;
|
||||||
|
@ -10,13 +10,13 @@ pub const String = opaque {
|
|||||||
encoding: StringEncoding,
|
encoding: StringEncoding,
|
||||||
external: bool,
|
external: bool,
|
||||||
) Allocator.Error!*String {
|
) Allocator.Error!*String {
|
||||||
return @ptrFromInt(?*String, @intFromPtr(c.CFStringCreateWithBytes(
|
return @as(?*String, @ptrFromInt(@intFromPtr(c.CFStringCreateWithBytes(
|
||||||
null,
|
null,
|
||||||
bs.ptr,
|
bs.ptr,
|
||||||
@intCast(c_long, bs.len),
|
@intCast(bs.len),
|
||||||
@intFromEnum(encoding),
|
@intFromEnum(encoding),
|
||||||
@intFromBool(external),
|
@intFromBool(external),
|
||||||
))) orelse Allocator.Error.OutOfMemory;
|
)))) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn release(self: *String) void {
|
pub fn release(self: *String) void {
|
||||||
@ -24,13 +24,13 @@ pub const String = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getLength(self: *String) usize {
|
pub fn getLength(self: *String) usize {
|
||||||
return @intCast(usize, c.CFStringGetLength(@ptrCast(c.CFStringRef, self)));
|
return @intCast(c.CFStringGetLength(@ptrCast(self)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hasPrefix(self: *String, prefix: *String) bool {
|
pub fn hasPrefix(self: *String, prefix: *String) bool {
|
||||||
return c.CFStringHasPrefix(
|
return c.CFStringHasPrefix(
|
||||||
@ptrCast(c.CFStringRef, self),
|
@ptrCast(self),
|
||||||
@ptrCast(c.CFStringRef, prefix),
|
@ptrCast(prefix),
|
||||||
) == 1;
|
) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,21 +39,18 @@ pub const String = opaque {
|
|||||||
other: *String,
|
other: *String,
|
||||||
options: StringComparison,
|
options: StringComparison,
|
||||||
) foundation.ComparisonResult {
|
) foundation.ComparisonResult {
|
||||||
return @enumFromInt(
|
return @enumFromInt(c.CFStringCompare(
|
||||||
foundation.ComparisonResult,
|
@ptrCast(self),
|
||||||
c.CFStringCompare(
|
@ptrCast(other),
|
||||||
@ptrCast(c.CFStringRef, self),
|
@intCast(@as(c_int, @bitCast(options))),
|
||||||
@ptrCast(c.CFStringRef, other),
|
));
|
||||||
@intCast(c_ulong, @bitCast(c_int, options)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cstring(self: *String, buf: []u8, encoding: StringEncoding) ?[]const u8 {
|
pub fn cstring(self: *String, buf: []u8, encoding: StringEncoding) ?[]const u8 {
|
||||||
if (c.CFStringGetCString(
|
if (c.CFStringGetCString(
|
||||||
@ptrCast(c.CFStringRef, self),
|
@ptrCast(self),
|
||||||
buf.ptr,
|
buf.ptr,
|
||||||
@intCast(c_long, buf.len),
|
@intCast(buf.len),
|
||||||
@intFromEnum(encoding),
|
@intFromEnum(encoding),
|
||||||
) == 0) return null;
|
) == 0) return null;
|
||||||
return std.mem.sliceTo(buf, 0);
|
return std.mem.sliceTo(buf, 0);
|
||||||
@ -61,7 +58,7 @@ pub const String = opaque {
|
|||||||
|
|
||||||
pub fn cstringPtr(self: *String, encoding: StringEncoding) ?[:0]const u8 {
|
pub fn cstringPtr(self: *String, encoding: StringEncoding) ?[:0]const u8 {
|
||||||
const ptr = c.CFStringGetCStringPtr(
|
const ptr = c.CFStringGetCStringPtr(
|
||||||
@ptrCast(c.CFStringRef, self),
|
@ptrCast(self),
|
||||||
@intFromEnum(encoding),
|
@intFromEnum(encoding),
|
||||||
);
|
);
|
||||||
if (ptr == null) return null;
|
if (ptr == null) return null;
|
||||||
|
@ -17,14 +17,14 @@ pub const URL = opaque {
|
|||||||
style: URLPathStyle,
|
style: URLPathStyle,
|
||||||
dir: bool,
|
dir: bool,
|
||||||
) Allocator.Error!*URL {
|
) Allocator.Error!*URL {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*URL,
|
?*URL,
|
||||||
@intFromPtr(c.CFURLCreateWithFileSystemPath(
|
@ptrFromInt(@intFromPtr(c.CFURLCreateWithFileSystemPath(
|
||||||
null,
|
null,
|
||||||
@ptrCast(c.CFStringRef, path),
|
@ptrCast(path),
|
||||||
@intFromEnum(style),
|
@intFromEnum(style),
|
||||||
if (dir) 1 else 0,
|
if (dir) 1 else 0,
|
||||||
)),
|
))),
|
||||||
) orelse error.OutOfMemory;
|
) orelse error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +11,10 @@ pub const AffineTransform = extern struct {
|
|||||||
ty: c.CGFloat,
|
ty: c.CGFloat,
|
||||||
|
|
||||||
pub fn identity() AffineTransform {
|
pub fn identity() AffineTransform {
|
||||||
return @bitCast(AffineTransform, c.CGAffineTransformIdentity);
|
return @bitCast(c.CGAffineTransformIdentity);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cval(self: AffineTransform) c.struct_CGAffineTransform {
|
pub fn cval(self: AffineTransform) c.struct_CGAffineTransform {
|
||||||
return @bitCast(c.struct_CGAffineTransform, self);
|
return @bitCast(self);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -17,17 +17,17 @@ pub const BitmapContext = opaque {
|
|||||||
space: *graphics.ColorSpace,
|
space: *graphics.ColorSpace,
|
||||||
opts: c_uint,
|
opts: c_uint,
|
||||||
) Allocator.Error!*BitmapContext {
|
) Allocator.Error!*BitmapContext {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*BitmapContext,
|
?*BitmapContext,
|
||||||
@intFromPtr(c.CGBitmapContextCreate(
|
@ptrFromInt(@intFromPtr(c.CGBitmapContextCreate(
|
||||||
@ptrCast(?*anyopaque, if (data) |d| d.ptr else null),
|
@ptrCast(if (data) |d| d.ptr else null),
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
bits_per_component,
|
bits_per_component,
|
||||||
bytes_per_row,
|
bytes_per_row,
|
||||||
@ptrCast(c.CGColorSpaceRef, space),
|
@ptrCast(space),
|
||||||
opts,
|
opts,
|
||||||
)),
|
))),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -5,21 +5,21 @@ const c = @import("c.zig");
|
|||||||
|
|
||||||
pub const ColorSpace = opaque {
|
pub const ColorSpace = opaque {
|
||||||
pub fn createDeviceGray() Allocator.Error!*ColorSpace {
|
pub fn createDeviceGray() Allocator.Error!*ColorSpace {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*ColorSpace,
|
?*ColorSpace,
|
||||||
@intFromPtr(c.CGColorSpaceCreateDeviceGray()),
|
@ptrFromInt(@intFromPtr(c.CGColorSpaceCreateDeviceGray())),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createDeviceRGB() Allocator.Error!*ColorSpace {
|
pub fn createDeviceRGB() Allocator.Error!*ColorSpace {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*ColorSpace,
|
?*ColorSpace,
|
||||||
@intFromPtr(c.CGColorSpaceCreateDeviceRGB()),
|
@ptrFromInt(@intFromPtr(c.CGColorSpaceCreateDeviceRGB())),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn release(self: *ColorSpace) void {
|
pub fn release(self: *ColorSpace) void {
|
||||||
c.CGColorSpaceRelease(@ptrCast(c.CGColorSpaceRef, self));
|
c.CGColorSpaceRelease(@ptrCast(self));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,40 +9,40 @@ const c = @import("c.zig");
|
|||||||
pub fn Context(comptime T: type) type {
|
pub fn Context(comptime T: type) type {
|
||||||
return struct {
|
return struct {
|
||||||
pub fn release(self: *T) void {
|
pub fn release(self: *T) void {
|
||||||
c.CGContextRelease(@ptrCast(c.CGContextRef, self));
|
c.CGContextRelease(@ptrCast(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setLineWidth(self: *T, width: f64) void {
|
pub fn setLineWidth(self: *T, width: f64) void {
|
||||||
c.CGContextSetLineWidth(
|
c.CGContextSetLineWidth(
|
||||||
@ptrCast(c.CGContextRef, self),
|
@ptrCast(self),
|
||||||
width,
|
width,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setAllowsAntialiasing(self: *T, v: bool) void {
|
pub fn setAllowsAntialiasing(self: *T, v: bool) void {
|
||||||
c.CGContextSetAllowsAntialiasing(
|
c.CGContextSetAllowsAntialiasing(
|
||||||
@ptrCast(c.CGContextRef, self),
|
@ptrCast(self),
|
||||||
v,
|
v,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setShouldAntialias(self: *T, v: bool) void {
|
pub fn setShouldAntialias(self: *T, v: bool) void {
|
||||||
c.CGContextSetShouldAntialias(
|
c.CGContextSetShouldAntialias(
|
||||||
@ptrCast(c.CGContextRef, self),
|
@ptrCast(self),
|
||||||
v,
|
v,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setShouldSmoothFonts(self: *T, v: bool) void {
|
pub fn setShouldSmoothFonts(self: *T, v: bool) void {
|
||||||
c.CGContextSetShouldSmoothFonts(
|
c.CGContextSetShouldSmoothFonts(
|
||||||
@ptrCast(c.CGContextRef, self),
|
@ptrCast(self),
|
||||||
v,
|
v,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setGrayFillColor(self: *T, gray: f64, alpha: f64) void {
|
pub fn setGrayFillColor(self: *T, gray: f64, alpha: f64) void {
|
||||||
c.CGContextSetGrayFillColor(
|
c.CGContextSetGrayFillColor(
|
||||||
@ptrCast(c.CGContextRef, self),
|
@ptrCast(self),
|
||||||
gray,
|
gray,
|
||||||
alpha,
|
alpha,
|
||||||
);
|
);
|
||||||
@ -50,7 +50,7 @@ pub fn Context(comptime T: type) type {
|
|||||||
|
|
||||||
pub fn setGrayStrokeColor(self: *T, gray: f64, alpha: f64) void {
|
pub fn setGrayStrokeColor(self: *T, gray: f64, alpha: f64) void {
|
||||||
c.CGContextSetGrayStrokeColor(
|
c.CGContextSetGrayStrokeColor(
|
||||||
@ptrCast(c.CGContextRef, self),
|
@ptrCast(self),
|
||||||
gray,
|
gray,
|
||||||
alpha,
|
alpha,
|
||||||
);
|
);
|
||||||
@ -58,7 +58,7 @@ pub fn Context(comptime T: type) type {
|
|||||||
|
|
||||||
pub fn setRGBFillColor(self: *T, r: f64, g: f64, b: f64, alpha: f64) void {
|
pub fn setRGBFillColor(self: *T, r: f64, g: f64, b: f64, alpha: f64) void {
|
||||||
c.CGContextSetRGBFillColor(
|
c.CGContextSetRGBFillColor(
|
||||||
@ptrCast(c.CGContextRef, self),
|
@ptrCast(self),
|
||||||
r,
|
r,
|
||||||
g,
|
g,
|
||||||
b,
|
b,
|
||||||
@ -68,21 +68,21 @@ pub fn Context(comptime T: type) type {
|
|||||||
|
|
||||||
pub fn setTextDrawingMode(self: *T, mode: TextDrawingMode) void {
|
pub fn setTextDrawingMode(self: *T, mode: TextDrawingMode) void {
|
||||||
c.CGContextSetTextDrawingMode(
|
c.CGContextSetTextDrawingMode(
|
||||||
@ptrCast(c.CGContextRef, self),
|
@ptrCast(self),
|
||||||
@intFromEnum(mode),
|
@intFromEnum(mode),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setTextMatrix(self: *T, matrix: graphics.AffineTransform) void {
|
pub fn setTextMatrix(self: *T, matrix: graphics.AffineTransform) void {
|
||||||
c.CGContextSetTextMatrix(
|
c.CGContextSetTextMatrix(
|
||||||
@ptrCast(c.CGContextRef, self),
|
@ptrCast(self),
|
||||||
matrix.cval(),
|
matrix.cval(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setTextPosition(self: *T, x: f64, y: f64) void {
|
pub fn setTextPosition(self: *T, x: f64, y: f64) void {
|
||||||
c.CGContextSetTextPosition(
|
c.CGContextSetTextPosition(
|
||||||
@ptrCast(c.CGContextRef, self),
|
@ptrCast(self),
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
);
|
);
|
||||||
@ -90,8 +90,8 @@ pub fn Context(comptime T: type) type {
|
|||||||
|
|
||||||
pub fn fillRect(self: *T, rect: graphics.Rect) void {
|
pub fn fillRect(self: *T, rect: graphics.Rect) void {
|
||||||
c.CGContextFillRect(
|
c.CGContextFillRect(
|
||||||
@ptrCast(c.CGContextRef, self),
|
@ptrCast(self),
|
||||||
@bitCast(c.CGRect, rect),
|
@bitCast(rect),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,7 @@ pub const Point = extern struct {
|
|||||||
y: c.CGFloat,
|
y: c.CGFloat,
|
||||||
|
|
||||||
pub fn cval(self: Point) c.struct_CGPoint {
|
pub fn cval(self: Point) c.struct_CGPoint {
|
||||||
return @bitCast(c.struct_CGPoint, self);
|
return @bitCast(self);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -14,11 +14,11 @@ pub const Rect = extern struct {
|
|||||||
size: Size,
|
size: Size,
|
||||||
|
|
||||||
pub fn init(x: f64, y: f64, width: f64, height: f64) Rect {
|
pub fn init(x: f64, y: f64, width: f64, height: f64) Rect {
|
||||||
return @bitCast(Rect, c.CGRectMake(x, y, width, height));
|
return @bitCast(c.CGRectMake(x, y, width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cval(self: Rect) c.struct_CGRect {
|
pub fn cval(self: Rect) c.struct_CGRect {
|
||||||
return @bitCast(c.struct_CGRect, self);
|
return @bitCast(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isNull(self: Rect) bool {
|
pub fn isNull(self: Rect) bool {
|
||||||
@ -31,6 +31,6 @@ pub const Size = extern struct {
|
|||||||
height: c.CGFloat,
|
height: c.CGFloat,
|
||||||
|
|
||||||
pub fn cval(self: Size) c.struct_CGSize {
|
pub fn cval(self: Size) c.struct_CGSize {
|
||||||
return @bitCast(c.struct_CGSize, self);
|
return @bitCast(self);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -10,12 +10,12 @@ pub const Path = opaque {
|
|||||||
rect: graphics.Rect,
|
rect: graphics.Rect,
|
||||||
transform: ?*const graphics.AffineTransform,
|
transform: ?*const graphics.AffineTransform,
|
||||||
) Allocator.Error!*Path {
|
) Allocator.Error!*Path {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*Path,
|
?*Path,
|
||||||
@intFromPtr(c.CGPathCreateWithRect(
|
@ptrFromInt(@intFromPtr(c.CGPathCreateWithRect(
|
||||||
rect.cval(),
|
rect.cval(),
|
||||||
@ptrCast(?[*]const c.struct_CGAffineTransform, transform),
|
@ptrCast(transform),
|
||||||
)),
|
))),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,9 +26,9 @@ pub const Path = opaque {
|
|||||||
|
|
||||||
pub const MutablePath = opaque {
|
pub const MutablePath = opaque {
|
||||||
pub fn create() Allocator.Error!*MutablePath {
|
pub fn create() Allocator.Error!*MutablePath {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*MutablePath,
|
?*MutablePath,
|
||||||
@intFromPtr(c.CGPathCreateMutable()),
|
@ptrFromInt(@intFromPtr(c.CGPathCreateMutable())),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,8 +42,8 @@ pub const MutablePath = opaque {
|
|||||||
rect: graphics.Rect,
|
rect: graphics.Rect,
|
||||||
) void {
|
) void {
|
||||||
c.CGPathAddRect(
|
c.CGPathAddRect(
|
||||||
@ptrCast(c.CGMutablePathRef, self),
|
@ptrCast(self),
|
||||||
@ptrCast(?[*]const c.struct_CGAffineTransform, transform),
|
@ptrCast(transform),
|
||||||
rect.cval(),
|
rect.cval(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,10 @@ pub const Log = opaque {
|
|||||||
subsystem: [:0]const u8,
|
subsystem: [:0]const u8,
|
||||||
category: [:0]const u8,
|
category: [:0]const u8,
|
||||||
) *Log {
|
) *Log {
|
||||||
return @ptrFromInt(?*Log, @intFromPtr(c.os_log_create(
|
return @as(?*Log, @ptrFromInt(@intFromPtr(c.os_log_create(
|
||||||
subsystem.ptr,
|
subsystem.ptr,
|
||||||
category.ptr,
|
category.ptr,
|
||||||
))).?;
|
)))).?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn release(self: *Log) void {
|
pub fn release(self: *Log) void {
|
||||||
@ -20,7 +20,7 @@ pub const Log = opaque {
|
|||||||
|
|
||||||
pub fn typeEnabled(self: *Log, typ: LogType) bool {
|
pub fn typeEnabled(self: *Log, typ: LogType) bool {
|
||||||
return c.os_log_type_enabled(
|
return c.os_log_type_enabled(
|
||||||
@ptrCast(c.os_log_t, self),
|
@ptrCast(self),
|
||||||
@intFromEnum(typ),
|
@intFromEnum(typ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -8,25 +8,25 @@ const c = @import("c.zig");
|
|||||||
|
|
||||||
pub const Font = opaque {
|
pub const Font = opaque {
|
||||||
pub fn createWithFontDescriptor(desc: *text.FontDescriptor, size: f32) Allocator.Error!*Font {
|
pub fn createWithFontDescriptor(desc: *text.FontDescriptor, size: f32) Allocator.Error!*Font {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*Font,
|
?*Font,
|
||||||
@intFromPtr(c.CTFontCreateWithFontDescriptor(
|
@ptrFromInt(@intFromPtr(c.CTFontCreateWithFontDescriptor(
|
||||||
@ptrCast(c.CTFontDescriptorRef, desc),
|
@ptrCast(desc),
|
||||||
size,
|
size,
|
||||||
null,
|
null,
|
||||||
)),
|
))),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copyWithAttributes(self: *Font, size: f32, attrs: ?*text.FontDescriptor) Allocator.Error!*Font {
|
pub fn copyWithAttributes(self: *Font, size: f32, attrs: ?*text.FontDescriptor) Allocator.Error!*Font {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*Font,
|
?*Font,
|
||||||
@intFromPtr(c.CTFontCreateCopyWithAttributes(
|
@ptrFromInt(@intFromPtr(c.CTFontCreateCopyWithAttributes(
|
||||||
@ptrCast(c.CTFontRef, self),
|
@ptrCast(self),
|
||||||
size,
|
size,
|
||||||
null,
|
null,
|
||||||
@ptrCast(c.CTFontDescriptorRef, attrs),
|
@ptrCast(attrs),
|
||||||
)),
|
))),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,10 +37,10 @@ pub const Font = opaque {
|
|||||||
pub fn getGlyphsForCharacters(self: *Font, chars: []const u16, glyphs: []graphics.Glyph) bool {
|
pub fn getGlyphsForCharacters(self: *Font, chars: []const u16, glyphs: []graphics.Glyph) bool {
|
||||||
assert(chars.len == glyphs.len);
|
assert(chars.len == glyphs.len);
|
||||||
return c.CTFontGetGlyphsForCharacters(
|
return c.CTFontGetGlyphsForCharacters(
|
||||||
@ptrCast(c.CTFontRef, self),
|
@ptrCast(self),
|
||||||
chars.ptr,
|
chars.ptr,
|
||||||
glyphs.ptr,
|
glyphs.ptr,
|
||||||
@intCast(c_long, chars.len),
|
@intCast(chars.len),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,11 +52,11 @@ pub const Font = opaque {
|
|||||||
) void {
|
) void {
|
||||||
assert(positions.len == glyphs.len);
|
assert(positions.len == glyphs.len);
|
||||||
c.CTFontDrawGlyphs(
|
c.CTFontDrawGlyphs(
|
||||||
@ptrCast(c.CTFontRef, self),
|
@ptrCast(self),
|
||||||
glyphs.ptr,
|
glyphs.ptr,
|
||||||
@ptrCast([*]const c.struct_CGPoint, positions.ptr),
|
@ptrCast(positions.ptr),
|
||||||
glyphs.len,
|
glyphs.len,
|
||||||
@ptrCast(c.CGContextRef, context),
|
@ptrCast(context),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,12 +67,12 @@ pub const Font = opaque {
|
|||||||
rects: ?[]graphics.Rect,
|
rects: ?[]graphics.Rect,
|
||||||
) graphics.Rect {
|
) graphics.Rect {
|
||||||
if (rects) |s| assert(glyphs.len == s.len);
|
if (rects) |s| assert(glyphs.len == s.len);
|
||||||
return @bitCast(graphics.Rect, c.CTFontGetBoundingRectsForGlyphs(
|
return @bitCast(c.CTFontGetBoundingRectsForGlyphs(
|
||||||
@ptrCast(c.CTFontRef, self),
|
@ptrCast(self),
|
||||||
@intFromEnum(orientation),
|
@intFromEnum(orientation),
|
||||||
glyphs.ptr,
|
glyphs.ptr,
|
||||||
@ptrCast(?[*]c.struct_CGRect, if (rects) |s| s.ptr else null),
|
@ptrCast(if (rects) |s| s.ptr else null),
|
||||||
@intCast(c_long, glyphs.len),
|
@intCast(glyphs.len),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,56 +84,51 @@ pub const Font = opaque {
|
|||||||
) f64 {
|
) f64 {
|
||||||
if (advances) |s| assert(glyphs.len == s.len);
|
if (advances) |s| assert(glyphs.len == s.len);
|
||||||
return c.CTFontGetAdvancesForGlyphs(
|
return c.CTFontGetAdvancesForGlyphs(
|
||||||
@ptrCast(c.CTFontRef, self),
|
@ptrCast(self),
|
||||||
@intFromEnum(orientation),
|
@intFromEnum(orientation),
|
||||||
glyphs.ptr,
|
glyphs.ptr,
|
||||||
@ptrCast(?[*]c.struct_CGSize, if (advances) |s| s.ptr else null),
|
@ptrCast(if (advances) |s| s.ptr else null),
|
||||||
@intCast(c_long, glyphs.len),
|
@intCast(glyphs.len),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copyAttribute(self: *Font, comptime attr: text.FontAttribute) attr.Value() {
|
pub fn copyAttribute(self: *Font, comptime attr: text.FontAttribute) attr.Value() {
|
||||||
return @ptrFromInt(attr.Value(), @intFromPtr(c.CTFontCopyAttribute(
|
return @ptrFromInt(@intFromPtr(c.CTFontCopyAttribute(
|
||||||
@ptrCast(c.CTFontRef, self),
|
@ptrCast(self),
|
||||||
@ptrCast(c.CFStringRef, attr.key()),
|
@ptrCast(attr.key()),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copyDisplayName(self: *Font) *foundation.String {
|
pub fn copyDisplayName(self: *Font) *foundation.String {
|
||||||
return @ptrFromInt(
|
return @ptrFromInt(@intFromPtr(c.CTFontCopyDisplayName(@ptrCast(self))));
|
||||||
*foundation.String,
|
|
||||||
@intFromPtr(c.CTFontCopyDisplayName(@ptrCast(c.CTFontRef, self))),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getSymbolicTraits(self: *Font) text.FontSymbolicTraits {
|
pub fn getSymbolicTraits(self: *Font) text.FontSymbolicTraits {
|
||||||
return @bitCast(text.FontSymbolicTraits, c.CTFontGetSymbolicTraits(
|
return @bitCast(c.CTFontGetSymbolicTraits(@ptrCast(self)));
|
||||||
@ptrCast(c.CTFontRef, self),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getAscent(self: *Font) f64 {
|
pub fn getAscent(self: *Font) f64 {
|
||||||
return c.CTFontGetAscent(@ptrCast(c.CTFontRef, self));
|
return c.CTFontGetAscent(@ptrCast(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDescent(self: *Font) f64 {
|
pub fn getDescent(self: *Font) f64 {
|
||||||
return c.CTFontGetDescent(@ptrCast(c.CTFontRef, self));
|
return c.CTFontGetDescent(@ptrCast(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getLeading(self: *Font) f64 {
|
pub fn getLeading(self: *Font) f64 {
|
||||||
return c.CTFontGetLeading(@ptrCast(c.CTFontRef, self));
|
return c.CTFontGetLeading(@ptrCast(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getBoundingBox(self: *Font) graphics.Rect {
|
pub fn getBoundingBox(self: *Font) graphics.Rect {
|
||||||
return @bitCast(graphics.Rect, c.CTFontGetBoundingBox(@ptrCast(c.CTFontRef, self)));
|
return @bitCast(c.CTFontGetBoundingBox(@ptrCast(self)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getUnderlinePosition(self: *Font) f64 {
|
pub fn getUnderlinePosition(self: *Font) f64 {
|
||||||
return c.CTFontGetUnderlinePosition(@ptrCast(c.CTFontRef, self));
|
return c.CTFontGetUnderlinePosition(@ptrCast(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getUnderlineThickness(self: *Font) f64 {
|
pub fn getUnderlineThickness(self: *Font) f64 {
|
||||||
return c.CTFontGetUnderlineThickness(@ptrCast(c.CTFontRef, self));
|
return c.CTFontGetUnderlineThickness(@ptrCast(self));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,19 +6,19 @@ const c = @import("c.zig");
|
|||||||
|
|
||||||
pub const FontCollection = opaque {
|
pub const FontCollection = opaque {
|
||||||
pub fn createFromAvailableFonts() Allocator.Error!*FontCollection {
|
pub fn createFromAvailableFonts() Allocator.Error!*FontCollection {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*FontCollection,
|
?*FontCollection,
|
||||||
@intFromPtr(c.CTFontCollectionCreateFromAvailableFonts(null)),
|
@ptrFromInt(@intFromPtr(c.CTFontCollectionCreateFromAvailableFonts(null))),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createWithFontDescriptors(descs: *foundation.Array) Allocator.Error!*FontCollection {
|
pub fn createWithFontDescriptors(descs: *foundation.Array) Allocator.Error!*FontCollection {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*FontCollection,
|
?*FontCollection,
|
||||||
@intFromPtr(c.CTFontCollectionCreateWithFontDescriptors(
|
@ptrFromInt(@intFromPtr(c.CTFontCollectionCreateWithFontDescriptors(
|
||||||
@ptrCast(c.CFArrayRef, descs),
|
@ptrCast(descs),
|
||||||
null,
|
null,
|
||||||
)),
|
))),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,12 +27,8 @@ pub const FontCollection = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn createMatchingFontDescriptors(self: *FontCollection) *foundation.Array {
|
pub fn createMatchingFontDescriptors(self: *FontCollection) *foundation.Array {
|
||||||
const result = c.CTFontCollectionCreateMatchingFontDescriptors(
|
const result = c.CTFontCollectionCreateMatchingFontDescriptors(@ptrCast(self));
|
||||||
@ptrCast(c.CTFontCollectionRef, self),
|
if (result) |ptr| return @ptrFromInt(@intFromPtr(ptr));
|
||||||
);
|
|
||||||
if (result) |ptr| {
|
|
||||||
return @ptrFromInt(*foundation.Array, @intFromPtr(ptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we have no results, we create an empty array. This is not
|
// If we have no results, we create an empty array. This is not
|
||||||
// exactly matching the Mac API. We can fix this later if we want
|
// exactly matching the Mac API. We can fix this later if we want
|
||||||
|
@ -5,16 +5,16 @@ const c = @import("c.zig");
|
|||||||
|
|
||||||
pub const FontDescriptor = opaque {
|
pub const FontDescriptor = opaque {
|
||||||
pub fn createWithNameAndSize(name: *foundation.String, size: f64) Allocator.Error!*FontDescriptor {
|
pub fn createWithNameAndSize(name: *foundation.String, size: f64) Allocator.Error!*FontDescriptor {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*FontDescriptor,
|
?*FontDescriptor,
|
||||||
@intFromPtr(c.CTFontDescriptorCreateWithNameAndSize(@ptrCast(c.CFStringRef, name), size)),
|
@ptrFromInt(@intFromPtr(c.CTFontDescriptorCreateWithNameAndSize(@ptrCast(name), size))),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createWithAttributes(dict: *foundation.Dictionary) Allocator.Error!*FontDescriptor {
|
pub fn createWithAttributes(dict: *foundation.Dictionary) Allocator.Error!*FontDescriptor {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*FontDescriptor,
|
?*FontDescriptor,
|
||||||
@intFromPtr(c.CTFontDescriptorCreateWithAttributes(@ptrCast(c.CFDictionaryRef, dict))),
|
@ptrFromInt(@intFromPtr(c.CTFontDescriptorCreateWithAttributes(@ptrCast(dict)))),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,12 +22,12 @@ pub const FontDescriptor = opaque {
|
|||||||
original: *FontDescriptor,
|
original: *FontDescriptor,
|
||||||
dict: *foundation.Dictionary,
|
dict: *foundation.Dictionary,
|
||||||
) Allocator.Error!*FontDescriptor {
|
) Allocator.Error!*FontDescriptor {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*FontDescriptor,
|
?*FontDescriptor,
|
||||||
@intFromPtr(c.CTFontDescriptorCreateCopyWithAttributes(
|
@ptrFromInt(@intFromPtr(c.CTFontDescriptorCreateCopyWithAttributes(
|
||||||
@ptrCast(c.CTFontDescriptorRef, original),
|
@ptrCast(original),
|
||||||
@ptrCast(c.CFDictionaryRef, dict),
|
@ptrCast(dict),
|
||||||
)),
|
))),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,15 +36,15 @@ pub const FontDescriptor = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn copyAttribute(self: *FontDescriptor, comptime attr: FontAttribute) attr.Value() {
|
pub fn copyAttribute(self: *FontDescriptor, comptime attr: FontAttribute) attr.Value() {
|
||||||
return @ptrFromInt(attr.Value(), @intFromPtr(c.CTFontDescriptorCopyAttribute(
|
return @ptrFromInt(@intFromPtr(c.CTFontDescriptorCopyAttribute(
|
||||||
@ptrCast(c.CTFontDescriptorRef, self),
|
@ptrCast(self),
|
||||||
@ptrCast(c.CFStringRef, attr.key()),
|
@ptrCast(attr.key()),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copyAttributes(self: *FontDescriptor) *foundation.Dictionary {
|
pub fn copyAttributes(self: *FontDescriptor) *foundation.Dictionary {
|
||||||
return @ptrFromInt(*foundation.Dictionary, @intFromPtr(c.CTFontDescriptorCopyAttributes(
|
return @ptrFromInt(@intFromPtr(c.CTFontDescriptorCopyAttributes(
|
||||||
@ptrCast(c.CTFontDescriptorRef, self),
|
@ptrCast(self),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -76,7 +76,7 @@ pub const FontAttribute = enum {
|
|||||||
downloaded,
|
downloaded,
|
||||||
|
|
||||||
pub fn key(self: FontAttribute) *foundation.String {
|
pub fn key(self: FontAttribute) *foundation.String {
|
||||||
return @ptrFromInt(*foundation.String, @intFromPtr(switch (self) {
|
return @as(*foundation.String, @ptrFromInt(@intFromPtr(switch (self) {
|
||||||
.url => c.kCTFontURLAttribute,
|
.url => c.kCTFontURLAttribute,
|
||||||
.name => c.kCTFontNameAttribute,
|
.name => c.kCTFontNameAttribute,
|
||||||
.display_name => c.kCTFontDisplayNameAttribute,
|
.display_name => c.kCTFontDisplayNameAttribute,
|
||||||
@ -101,7 +101,7 @@ pub const FontAttribute = enum {
|
|||||||
.enabled => c.kCTFontEnabledAttribute,
|
.enabled => c.kCTFontEnabledAttribute,
|
||||||
.downloadable => c.kCTFontDownloadableAttribute,
|
.downloadable => c.kCTFontDownloadableAttribute,
|
||||||
.downloaded => c.kCTFontDownloadedAttribute,
|
.downloaded => c.kCTFontDownloadedAttribute,
|
||||||
}));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Value(comptime self: FontAttribute) type {
|
pub fn Value(comptime self: FontAttribute) type {
|
||||||
@ -141,12 +141,12 @@ pub const FontTraitKey = enum {
|
|||||||
slant,
|
slant,
|
||||||
|
|
||||||
pub fn key(self: FontTraitKey) *foundation.String {
|
pub fn key(self: FontTraitKey) *foundation.String {
|
||||||
return @ptrFromInt(*foundation.String, @intFromPtr(switch (self) {
|
return @as(*foundation.String, @ptrFromInt(@intFromPtr(switch (self) {
|
||||||
.symbolic => c.kCTFontSymbolicTrait,
|
.symbolic => c.kCTFontSymbolicTrait,
|
||||||
.weight => c.kCTFontWeightTrait,
|
.weight => c.kCTFontWeightTrait,
|
||||||
.width => c.kCTFontWidthTrait,
|
.width => c.kCTFontWidthTrait,
|
||||||
.slant => c.kCTFontSlantTrait,
|
.slant => c.kCTFontSlantTrait,
|
||||||
}));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Value(self: FontTraitKey) type {
|
pub fn Value(self: FontTraitKey) type {
|
||||||
@ -176,11 +176,11 @@ pub const FontSymbolicTraits = packed struct {
|
|||||||
pub fn init(num: *foundation.Number) FontSymbolicTraits {
|
pub fn init(num: *foundation.Number) FontSymbolicTraits {
|
||||||
var raw: i32 = undefined;
|
var raw: i32 = undefined;
|
||||||
_ = num.getValue(.sint32, &raw);
|
_ = num.getValue(.sint32, &raw);
|
||||||
return @bitCast(FontSymbolicTraits, raw);
|
return @as(FontSymbolicTraits, @bitCast(raw));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cval(self: FontSymbolicTraits) c.CTFontSymbolicTraits {
|
pub fn cval(self: FontSymbolicTraits) c.CTFontSymbolicTraits {
|
||||||
return @bitCast(c.CTFontSymbolicTraits, self);
|
return @as(c.CTFontSymbolicTraits, @bitCast(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
@ -197,7 +197,7 @@ pub const FontSymbolicTraits = packed struct {
|
|||||||
.expanded = true,
|
.expanded = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
try std.testing.expectEqual(actual, @bitCast(c.CTFontSymbolicTraits, expected));
|
try std.testing.expectEqual(actual, @as(c.CTFontSymbolicTraits, @bitCast(expected)));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "number" {
|
test "number" {
|
||||||
|
@ -4,19 +4,13 @@ const foundation = @import("../foundation.zig");
|
|||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
|
||||||
pub fn createFontDescriptorsFromURL(url: *foundation.URL) ?*foundation.Array {
|
pub fn createFontDescriptorsFromURL(url: *foundation.URL) ?*foundation.Array {
|
||||||
return @ptrFromInt(
|
return @ptrFromInt(@intFromPtr(c.CTFontManagerCreateFontDescriptorsFromURL(
|
||||||
?*foundation.Array,
|
@ptrCast(url),
|
||||||
@intFromPtr(c.CTFontManagerCreateFontDescriptorsFromURL(
|
)));
|
||||||
@ptrCast(c.CFURLRef, url),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createFontDescriptorsFromData(data: *foundation.Data) ?*foundation.Array {
|
pub fn createFontDescriptorsFromData(data: *foundation.Data) ?*foundation.Array {
|
||||||
return @ptrFromInt(
|
return @ptrFromInt(@intFromPtr(c.CTFontManagerCreateFontDescriptorsFromData(
|
||||||
?*foundation.Array,
|
@ptrCast(data),
|
||||||
@intFromPtr(c.CTFontManagerCreateFontDescriptorsFromData(
|
)));
|
||||||
@ptrCast(c.CFDataRef, data),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -17,17 +17,14 @@ pub const Frame = opaque {
|
|||||||
points: []graphics.Point,
|
points: []graphics.Point,
|
||||||
) void {
|
) void {
|
||||||
c.CTFrameGetLineOrigins(
|
c.CTFrameGetLineOrigins(
|
||||||
@ptrCast(c.CTFrameRef, self),
|
@ptrCast(self),
|
||||||
@bitCast(c.CFRange, range),
|
@bitCast(range),
|
||||||
@ptrCast(*c.CGPoint, points.ptr),
|
@ptrCast(points.ptr),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getLines(self: *Frame) *foundation.Array {
|
pub fn getLines(self: *Frame) *foundation.Array {
|
||||||
return @ptrFromInt(
|
return @ptrFromInt(@intFromPtr(c.CTFrameGetLines(@ptrCast(self))));
|
||||||
*foundation.Array,
|
|
||||||
@intFromPtr(c.CTFrameGetLines(@ptrCast(c.CTFrameRef, self))),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,11 +8,11 @@ const c = @import("c.zig");
|
|||||||
|
|
||||||
pub const Framesetter = opaque {
|
pub const Framesetter = opaque {
|
||||||
pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Framesetter {
|
pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Framesetter {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*Framesetter,
|
?*Framesetter,
|
||||||
@intFromPtr(c.CTFramesetterCreateWithAttributedString(
|
@ptrFromInt(@intFromPtr(c.CTFramesetterCreateWithAttributedString(
|
||||||
@ptrCast(c.CFAttributedStringRef, str),
|
@ptrCast(str),
|
||||||
)),
|
))),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,14 +26,14 @@ pub const Framesetter = opaque {
|
|||||||
path: *graphics.Path,
|
path: *graphics.Path,
|
||||||
attrs: ?*foundation.Dictionary,
|
attrs: ?*foundation.Dictionary,
|
||||||
) !*text.Frame {
|
) !*text.Frame {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*text.Frame,
|
?*text.Frame,
|
||||||
@intFromPtr(c.CTFramesetterCreateFrame(
|
@ptrFromInt(@intFromPtr(c.CTFramesetterCreateFrame(
|
||||||
@ptrCast(c.CTFramesetterRef, self),
|
@ptrCast(self),
|
||||||
@bitCast(c.CFRange, range),
|
@bitCast(range),
|
||||||
@ptrCast(c.CGPathRef, path),
|
@ptrCast(path),
|
||||||
@ptrCast(c.CFDictionaryRef, attrs),
|
@ptrCast(attrs),
|
||||||
)),
|
))),
|
||||||
) orelse error.FrameCreateFailed;
|
) orelse error.FrameCreateFailed;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -47,7 +47,7 @@ test {
|
|||||||
str.replaceString(foundation.Range.init(0, 0), rep);
|
str.replaceString(foundation.Range.init(0, 0), rep);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fs = try Framesetter.createWithAttributedString(@ptrCast(*foundation.AttributedString, str));
|
const fs = try Framesetter.createWithAttributedString(@ptrCast(str));
|
||||||
defer fs.release();
|
defer fs.release();
|
||||||
|
|
||||||
const path = try graphics.Path.createWithRect(graphics.Rect.init(0, 0, 100, 200), null);
|
const path = try graphics.Path.createWithRect(graphics.Rect.init(0, 0, 100, 200), null);
|
||||||
|
@ -8,11 +8,11 @@ const c = @import("c.zig");
|
|||||||
|
|
||||||
pub const Line = opaque {
|
pub const Line = opaque {
|
||||||
pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Line {
|
pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Line {
|
||||||
return @ptrFromInt(
|
return @as(
|
||||||
?*Line,
|
?*Line,
|
||||||
@intFromPtr(c.CTLineCreateWithAttributedString(
|
@ptrFromInt(@intFromPtr(c.CTLineCreateWithAttributedString(
|
||||||
@ptrCast(c.CFAttributedStringRef, str),
|
@ptrCast(str),
|
||||||
)),
|
))),
|
||||||
) orelse Allocator.Error.OutOfMemory;
|
) orelse Allocator.Error.OutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,8 +21,8 @@ pub const Line = opaque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getGlyphCount(self: *Line) usize {
|
pub fn getGlyphCount(self: *Line) usize {
|
||||||
return @intCast(usize, c.CTLineGetGlyphCount(
|
return @intCast(c.CTLineGetGlyphCount(
|
||||||
@ptrCast(c.CTLineRef, self),
|
@ptrCast(self),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,9 +39,9 @@ pub const Line = opaque {
|
|||||||
// C ABI issue happening.
|
// C ABI issue happening.
|
||||||
var result: graphics.Rect = undefined;
|
var result: graphics.Rect = undefined;
|
||||||
zig_cabi_CTLineGetBoundsWithOptions(
|
zig_cabi_CTLineGetBoundsWithOptions(
|
||||||
@ptrCast(c.CTLineRef, self),
|
@ptrCast(self),
|
||||||
opts.cval(),
|
opts.cval(),
|
||||||
@ptrCast(*c.CGRect, &result),
|
@ptrCast(&result),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -61,7 +61,7 @@ pub const Line = opaque {
|
|||||||
leading: ?*f64,
|
leading: ?*f64,
|
||||||
) f64 {
|
) f64 {
|
||||||
return c.CTLineGetTypographicBounds(
|
return c.CTLineGetTypographicBounds(
|
||||||
@ptrCast(c.CTLineRef, self),
|
@ptrCast(self),
|
||||||
ascent,
|
ascent,
|
||||||
descent,
|
descent,
|
||||||
leading,
|
leading,
|
||||||
@ -79,7 +79,7 @@ pub const LineBoundsOptions = packed struct {
|
|||||||
_padding: u58 = 0,
|
_padding: u58 = 0,
|
||||||
|
|
||||||
pub fn cval(self: LineBoundsOptions) c.CTLineBoundsOptions {
|
pub fn cval(self: LineBoundsOptions) c.CTLineBoundsOptions {
|
||||||
return @bitCast(c.CTLineBoundsOptions, self);
|
return @bitCast(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
@ -97,7 +97,7 @@ pub const LineBoundsOptions = packed struct {
|
|||||||
.use_optical_bounds = true,
|
.use_optical_bounds = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
try std.testing.expectEqual(actual, @bitCast(c.CTLineBoundsOptions, expected));
|
try std.testing.expectEqual(actual, @as(c.CTLineBoundsOptions, @bitCast(expected)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ test "line" {
|
|||||||
font,
|
font,
|
||||||
);
|
);
|
||||||
|
|
||||||
const line = try Line.createWithAttributedString(@ptrCast(*foundation.AttributedString, str));
|
const line = try Line.createWithAttributedString(@as(*foundation.AttributedString, @ptrCast(str)));
|
||||||
defer line.release();
|
defer line.release();
|
||||||
|
|
||||||
try testing.expectEqual(@as(usize, 5), line.getGlyphCount());
|
try testing.expectEqual(@as(usize, 5), line.getGlyphCount());
|
||||||
|
@ -5,7 +5,7 @@ pub const StringAttribute = enum {
|
|||||||
font,
|
font,
|
||||||
|
|
||||||
pub fn key(self: StringAttribute) *foundation.String {
|
pub fn key(self: StringAttribute) *foundation.String {
|
||||||
return @ptrFromInt(*foundation.String, @intFromPtr(switch (self) {
|
return @ptrFromInt(@intFromPtr(switch (self) {
|
||||||
.font => c.kCTFontAttributeName,
|
.font => c.kCTFontAttributeName,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ pub const FormatCode = enum(c_uint) {
|
|||||||
/// Calculates a valid stride for the bpp and width. Based on Cairo.
|
/// Calculates a valid stride for the bpp and width. Based on Cairo.
|
||||||
pub fn strideForWidth(self: FormatCode, width: u32) c_int {
|
pub fn strideForWidth(self: FormatCode, width: u32) c_int {
|
||||||
const alignment = @sizeOf(u32);
|
const alignment = @sizeOf(u32);
|
||||||
const val = @intCast(c_int, (self.bpp() * width + 7) / 8);
|
const val = @as(c_int, @intCast((self.bpp() * width + 7) / 8));
|
||||||
return val + (alignment - 1) & -alignment;
|
return val + (alignment - 1) & -alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ pub const FormatCode = enum(c_uint) {
|
|||||||
const val = @intFromEnum(self);
|
const val = @intFromEnum(self);
|
||||||
const v1 = val >> ofs;
|
const v1 = val >> ofs;
|
||||||
const v2 = @as(c_uint, 1) << num;
|
const v2 = @as(c_uint, 1) << num;
|
||||||
const v3 = @intCast(u5, (val >> 22) & 3);
|
const v3 = @as(u5, @intCast((val >> 22) & 3));
|
||||||
return ((v1 & (v2 - 1)) << v3);
|
return ((v1 & (v2 - 1)) << v3);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -10,25 +10,25 @@ pub const Image = opaque {
|
|||||||
bits: [*]u32,
|
bits: [*]u32,
|
||||||
stride: c_int,
|
stride: c_int,
|
||||||
) pixman.Error!*Image {
|
) pixman.Error!*Image {
|
||||||
return @ptrCast(?*Image, c.pixman_image_create_bits_no_clear(
|
return @as(?*Image, @ptrCast(c.pixman_image_create_bits_no_clear(
|
||||||
@intFromEnum(format),
|
@intFromEnum(format),
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
bits,
|
bits,
|
||||||
stride,
|
stride,
|
||||||
)) orelse return pixman.Error.PixmanFailure;
|
))) orelse return pixman.Error.PixmanFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createSolidFill(
|
pub fn createSolidFill(
|
||||||
color: pixman.Color,
|
color: pixman.Color,
|
||||||
) pixman.Error!*Image {
|
) pixman.Error!*Image {
|
||||||
return @ptrCast(?*Image, c.pixman_image_create_solid_fill(
|
return @as(?*Image, @ptrCast(c.pixman_image_create_solid_fill(
|
||||||
@ptrCast(*const c.pixman_color_t, &color),
|
@ptrCast(&color),
|
||||||
)) orelse return pixman.Error.PixmanFailure;
|
))) orelse return pixman.Error.PixmanFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unref(self: *Image) bool {
|
pub fn unref(self: *Image) bool {
|
||||||
return c.pixman_image_unref(@ptrCast(*c.pixman_image_t, self)) == 1;
|
return c.pixman_image_unref(@ptrCast(self)) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A variant of getDataUnsafe that sets the length of the slice to
|
/// A variant of getDataUnsafe that sets the length of the slice to
|
||||||
@ -39,24 +39,24 @@ pub const Image = opaque {
|
|||||||
const height = self.getHeight();
|
const height = self.getHeight();
|
||||||
const stride = self.getStride();
|
const stride = self.getStride();
|
||||||
const ptr = self.getDataUnsafe();
|
const ptr = self.getDataUnsafe();
|
||||||
const len = @intCast(usize, height * stride);
|
const len = @as(usize, @intCast(height * stride));
|
||||||
return ptr[0..len];
|
return ptr[0..len];
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDataUnsafe(self: *Image) [*]u32 {
|
pub fn getDataUnsafe(self: *Image) [*]u32 {
|
||||||
return c.pixman_image_get_data(@ptrCast(*c.pixman_image_t, self));
|
return c.pixman_image_get_data(@ptrCast(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getHeight(self: *Image) c_int {
|
pub fn getHeight(self: *Image) c_int {
|
||||||
return c.pixman_image_get_height(@ptrCast(*c.pixman_image_t, self));
|
return c.pixman_image_get_height(@ptrCast(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getWidth(self: *Image) c_int {
|
pub fn getWidth(self: *Image) c_int {
|
||||||
return c.pixman_image_get_width(@ptrCast(*c.pixman_image_t, self));
|
return c.pixman_image_get_width(@ptrCast(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getStride(self: *Image) c_int {
|
pub fn getStride(self: *Image) c_int {
|
||||||
return c.pixman_image_get_stride(@ptrCast(*c.pixman_image_t, self));
|
return c.pixman_image_get_stride(@ptrCast(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fillBoxes(
|
pub fn fillBoxes(
|
||||||
@ -67,10 +67,10 @@ pub const Image = opaque {
|
|||||||
) pixman.Error!void {
|
) pixman.Error!void {
|
||||||
if (c.pixman_image_fill_boxes(
|
if (c.pixman_image_fill_boxes(
|
||||||
@intFromEnum(op),
|
@intFromEnum(op),
|
||||||
@ptrCast(*c.pixman_image_t, self),
|
@ptrCast(self),
|
||||||
@ptrCast(*const c.pixman_color_t, &color),
|
@ptrCast(&color),
|
||||||
@intCast(c_int, boxes.len),
|
@intCast(boxes.len),
|
||||||
@ptrCast([*c]const c.pixman_box32_t, boxes.ptr),
|
@ptrCast(boxes.ptr),
|
||||||
) == 0) return pixman.Error.PixmanFailure;
|
) == 0) return pixman.Error.PixmanFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,10 +82,10 @@ pub const Image = opaque {
|
|||||||
) pixman.Error!void {
|
) pixman.Error!void {
|
||||||
if (c.pixman_image_fill_rectangles(
|
if (c.pixman_image_fill_rectangles(
|
||||||
@intFromEnum(op),
|
@intFromEnum(op),
|
||||||
@ptrCast(*c.pixman_image_t, self),
|
@ptrCast(self),
|
||||||
@ptrCast(*const c.pixman_color_t, &color),
|
@ptrCast(&color),
|
||||||
@intCast(c_int, rects.len),
|
@intCast(rects.len),
|
||||||
@ptrCast([*c]const c.pixman_rectangle16_t, rects.ptr),
|
@ptrCast(rects.ptr),
|
||||||
) == 0) return pixman.Error.PixmanFailure;
|
) == 0) return pixman.Error.PixmanFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,8 +96,8 @@ pub const Image = opaque {
|
|||||||
y_off: c_int,
|
y_off: c_int,
|
||||||
) void {
|
) void {
|
||||||
c.pixman_rasterize_trapezoid(
|
c.pixman_rasterize_trapezoid(
|
||||||
@ptrCast(*c.pixman_image_t, self),
|
@ptrCast(self),
|
||||||
@ptrCast(*const c.pixman_trapezoid_t, &trap),
|
@ptrCast(&trap),
|
||||||
x_off,
|
x_off,
|
||||||
y_off,
|
y_off,
|
||||||
);
|
);
|
||||||
@ -119,9 +119,9 @@ pub const Image = opaque {
|
|||||||
) void {
|
) void {
|
||||||
c.pixman_image_composite(
|
c.pixman_image_composite(
|
||||||
@intFromEnum(op),
|
@intFromEnum(op),
|
||||||
@ptrCast(*c.pixman_image_t, src),
|
@ptrCast(src),
|
||||||
@ptrCast(?*c.pixman_image_t, mask),
|
@ptrCast(mask),
|
||||||
@ptrCast(*c.pixman_image_t, self),
|
@ptrCast(self),
|
||||||
src_x,
|
src_x,
|
||||||
src_y,
|
src_y,
|
||||||
mask_x,
|
mask_x,
|
||||||
@ -146,15 +146,15 @@ pub const Image = opaque {
|
|||||||
) void {
|
) void {
|
||||||
c.pixman_composite_triangles(
|
c.pixman_composite_triangles(
|
||||||
@intFromEnum(op),
|
@intFromEnum(op),
|
||||||
@ptrCast(*c.pixman_image_t, src),
|
@ptrCast(src),
|
||||||
@ptrCast(*c.pixman_image_t, self),
|
@ptrCast(self),
|
||||||
@intFromEnum(mask_format),
|
@intFromEnum(mask_format),
|
||||||
x_src,
|
x_src,
|
||||||
y_src,
|
y_src,
|
||||||
x_dst,
|
x_dst,
|
||||||
y_dst,
|
y_dst,
|
||||||
@intCast(c_int, tris.len),
|
@intCast(tris.len),
|
||||||
@ptrCast([*c]const c.pixman_triangle_t, tris.ptr),
|
@ptrCast(tris.ptr),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -168,7 +168,7 @@ test "create and destroy" {
|
|||||||
const format: pixman.FormatCode = .g1;
|
const format: pixman.FormatCode = .g1;
|
||||||
const stride = format.strideForWidth(width);
|
const stride = format.strideForWidth(width);
|
||||||
|
|
||||||
const len = height * @intCast(usize, stride);
|
const len = height * @as(usize, @intCast(stride));
|
||||||
var data = try alloc.alloc(u32, len);
|
var data = try alloc.alloc(u32, len);
|
||||||
defer alloc.free(data);
|
defer alloc.free(data);
|
||||||
@memset(data, 0);
|
@memset(data, 0);
|
||||||
@ -190,7 +190,7 @@ test "fill boxes a1" {
|
|||||||
const stride = format.strideForWidth(width);
|
const stride = format.strideForWidth(width);
|
||||||
|
|
||||||
// Image
|
// Image
|
||||||
const len = height * @intCast(usize, stride);
|
const len = height * @as(usize, @intCast(stride));
|
||||||
var data = try alloc.alloc(u32, len);
|
var data = try alloc.alloc(u32, len);
|
||||||
defer alloc.free(data);
|
defer alloc.free(data);
|
||||||
@memset(data, 0);
|
@memset(data, 0);
|
||||||
|
@ -73,8 +73,8 @@ pub const Fixed = enum(i32) {
|
|||||||
|
|
||||||
pub fn init(v: anytype) Fixed {
|
pub fn init(v: anytype) Fixed {
|
||||||
return switch (@TypeOf(v)) {
|
return switch (@TypeOf(v)) {
|
||||||
comptime_int, i32, u32 => @enumFromInt(Fixed, v << 16),
|
comptime_int, i32, u32 => @enumFromInt(v << 16),
|
||||||
f64 => @enumFromInt(Fixed, @intFromFloat(i32, v * 65536)),
|
f64 => @enumFromInt(@as(i32, @intFromFloat(v * 65536))),
|
||||||
else => {
|
else => {
|
||||||
@compileLog(@TypeOf(v));
|
@compileLog(@TypeOf(v));
|
||||||
@compileError("unsupported type");
|
@compileError("unsupported type");
|
||||||
|
@ -106,7 +106,7 @@ const Impl = struct {
|
|||||||
log2_ptr_align: u8,
|
log2_ptr_align: u8,
|
||||||
ret_addr: usize,
|
ret_addr: usize,
|
||||||
) ?[*]u8 {
|
) ?[*]u8 {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
|
const self = @as(*Self, @ptrCast(@alignCast(ctx)));
|
||||||
const result = self.parent.rawAlloc(len, log2_ptr_align, ret_addr);
|
const result = self.parent.rawAlloc(len, log2_ptr_align, ret_addr);
|
||||||
if (result) |data| {
|
if (result) |data| {
|
||||||
if (len != 0) {
|
if (len != 0) {
|
||||||
@ -128,7 +128,7 @@ const Impl = struct {
|
|||||||
new_len: usize,
|
new_len: usize,
|
||||||
ret_addr: usize,
|
ret_addr: usize,
|
||||||
) bool {
|
) bool {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
|
const self = @as(*Self, @ptrCast(@alignCast(ctx)));
|
||||||
if (self.parent.rawResize(buf, log2_buf_align, new_len, ret_addr)) {
|
if (self.parent.rawResize(buf, log2_buf_align, new_len, ret_addr)) {
|
||||||
if (name) |n| {
|
if (name) |n| {
|
||||||
freeNamed(buf.ptr, n);
|
freeNamed(buf.ptr, n);
|
||||||
@ -152,7 +152,7 @@ const Impl = struct {
|
|||||||
log2_buf_align: u8,
|
log2_buf_align: u8,
|
||||||
ret_addr: usize,
|
ret_addr: usize,
|
||||||
) void {
|
) void {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
|
const self = @as(*Self, @ptrCast(@alignCast(ctx)));
|
||||||
self.parent.rawFree(buf, log2_buf_align, ret_addr);
|
self.parent.rawFree(buf, log2_buf_align, ret_addr);
|
||||||
|
|
||||||
if (buf.len != 0) {
|
if (buf.len != 0) {
|
||||||
|
@ -4,15 +4,15 @@ pub const c = @import("c.zig");
|
|||||||
/// except that a width of 0 is returned for non-printable codepoints
|
/// except that a width of 0 is returned for non-printable codepoints
|
||||||
/// instead of -1 as in `wcwidth`.
|
/// instead of -1 as in `wcwidth`.
|
||||||
pub fn charwidth(codepoint: u21) u8 {
|
pub fn charwidth(codepoint: u21) u8 {
|
||||||
return @intCast(u8, c.utf8proc_charwidth(@intCast(i32, codepoint)));
|
return @intCast(c.utf8proc_charwidth(@intCast(codepoint)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a pair of consecutive codepoints, return whether a grapheme break is
|
/// Given a pair of consecutive codepoints, return whether a grapheme break is
|
||||||
/// permitted between them (as defined by the extended grapheme clusters in UAX#29).
|
/// permitted between them (as defined by the extended grapheme clusters in UAX#29).
|
||||||
pub fn graphemeBreakStateful(cp1: u21, cp2: u21, state: *i32) bool {
|
pub fn graphemeBreakStateful(cp1: u21, cp2: u21, state: *i32) bool {
|
||||||
return c.utf8proc_grapheme_break_stateful(
|
return c.utf8proc_grapheme_break_stateful(
|
||||||
@intCast(i32, cp1),
|
@intCast(cp1),
|
||||||
@intCast(i32, cp2),
|
@intCast(cp2),
|
||||||
state,
|
state,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ pub fn start(self: *Command, alloc: Allocator) !void {
|
|||||||
const pid = try std.os.fork();
|
const pid = try std.os.fork();
|
||||||
if (pid != 0) {
|
if (pid != 0) {
|
||||||
// Parent, return immediately.
|
// Parent, return immediately.
|
||||||
self.pid = @intCast(i32, pid);
|
self.pid = @intCast(pid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,10 +201,7 @@ pub fn setData(self: *Command, pointer: ?*anyopaque) void {
|
|||||||
|
|
||||||
/// Returns command->data.
|
/// Returns command->data.
|
||||||
pub fn getData(self: Command, comptime DT: type) ?*DT {
|
pub fn getData(self: Command, comptime DT: type) ?*DT {
|
||||||
return if (self.data) |ptr|
|
return if (self.data) |ptr| @ptrCast(@alignCast(ptr)) else null;
|
||||||
@ptrCast(?*DT, @alignCast(@alignOf(DT), ptr))
|
|
||||||
else
|
|
||||||
null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Search for "cmd" in the PATH and return the absolute path. This will
|
/// Search for "cmd" in the PATH and return the absolute path. This will
|
||||||
|
@ -97,8 +97,8 @@ pub fn update(self: *const DevMode) !void {
|
|||||||
if (imgui.treeNode("Atlas: Greyscale", .{ .default_open = true })) {
|
if (imgui.treeNode("Atlas: Greyscale", .{ .default_open = true })) {
|
||||||
defer imgui.treePop();
|
defer imgui.treePop();
|
||||||
const atlas = &surface.font_group.atlas_greyscale;
|
const atlas = &surface.font_group.atlas_greyscale;
|
||||||
const tex = switch (Renderer) {
|
const tex: usize = switch (Renderer) {
|
||||||
renderer.OpenGL => @intCast(usize, surface.renderer.texture.id),
|
renderer.OpenGL => @intCast(surface.renderer.texture.id),
|
||||||
renderer.Metal => @intFromPtr(surface.renderer.texture_greyscale.value),
|
renderer.Metal => @intFromPtr(surface.renderer.texture_greyscale.value),
|
||||||
else => @compileError("renderer unsupported, add it!"),
|
else => @compileError("renderer unsupported, add it!"),
|
||||||
};
|
};
|
||||||
@ -108,8 +108,8 @@ pub fn update(self: *const DevMode) !void {
|
|||||||
if (imgui.treeNode("Atlas: Color (Emoji)", .{ .default_open = true })) {
|
if (imgui.treeNode("Atlas: Color (Emoji)", .{ .default_open = true })) {
|
||||||
defer imgui.treePop();
|
defer imgui.treePop();
|
||||||
const atlas = &surface.font_group.atlas_color;
|
const atlas = &surface.font_group.atlas_color;
|
||||||
const tex = switch (Renderer) {
|
const tex: usize = switch (Renderer) {
|
||||||
renderer.OpenGL => @intCast(usize, surface.renderer.texture_color.id),
|
renderer.OpenGL => @intCast(surface.renderer.texture_color.id),
|
||||||
renderer.Metal => @intFromPtr(surface.renderer.texture_color.value),
|
renderer.Metal => @intFromPtr(surface.renderer.texture_color.value),
|
||||||
else => @compileError("renderer unsupported, add it!"),
|
else => @compileError("renderer unsupported, add it!"),
|
||||||
};
|
};
|
||||||
@ -166,10 +166,10 @@ fn atlasInfo(self: *const DevMode, atlas: *font.Atlas, tex: ?usize) !void {
|
|||||||
|
|
||||||
if (tex) |id| {
|
if (tex) |id| {
|
||||||
imgui.c.igImage(
|
imgui.c.igImage(
|
||||||
@ptrFromInt(*anyopaque, id),
|
@ptrFromInt(id),
|
||||||
.{
|
.{
|
||||||
.x = @floatFromInt(f32, atlas.size),
|
.x = @floatFromInt(atlas.size),
|
||||||
.y = @floatFromInt(f32, atlas.size),
|
.y = @floatFromInt(atlas.size),
|
||||||
},
|
},
|
||||||
.{ .x = 0, .y = 0 },
|
.{ .x = 0, .y = 0 },
|
||||||
.{ .x = 1, .y = 1 },
|
.{ .x = 1, .y = 1 },
|
||||||
|
@ -55,7 +55,7 @@ pub fn open(size: winsize) !Pty {
|
|||||||
&slave_fd,
|
&slave_fd,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@ptrCast([*c]c.struct_winsize, &sizeCopy),
|
@ptrCast(&sizeCopy),
|
||||||
) < 0)
|
) < 0)
|
||||||
return error.OpenptyFailed;
|
return error.OpenptyFailed;
|
||||||
errdefer {
|
errdefer {
|
||||||
|
@ -200,8 +200,8 @@ pub fn init(
|
|||||||
// The font size we desire along with the DPI determined for the surface
|
// The font size we desire along with the DPI determined for the surface
|
||||||
const font_size: font.face.DesiredSize = .{
|
const font_size: font.face.DesiredSize = .{
|
||||||
.points = config.@"font-size",
|
.points = config.@"font-size",
|
||||||
.xdpi = @intFromFloat(u16, x_dpi),
|
.xdpi = @intFromFloat(x_dpi),
|
||||||
.ydpi = @intFromFloat(u16, y_dpi),
|
.ydpi = @intFromFloat(y_dpi),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Find all the fonts for this surface
|
// Find all the fonts for this surface
|
||||||
@ -324,8 +324,8 @@ pub fn init(
|
|||||||
const cell_size = try renderer.CellSize.init(alloc, font_group);
|
const cell_size = try renderer.CellSize.init(alloc, font_group);
|
||||||
|
|
||||||
// Convert our padding from points to pixels
|
// Convert our padding from points to pixels
|
||||||
const padding_x = (@floatFromInt(f32, config.@"window-padding-x") * x_dpi) / 72;
|
const padding_x = (@as(f32, @floatFromInt(config.@"window-padding-x")) * x_dpi) / 72;
|
||||||
const padding_y = (@floatFromInt(f32, config.@"window-padding-y") * y_dpi) / 72;
|
const padding_y = (@as(f32, @floatFromInt(config.@"window-padding-y")) * y_dpi) / 72;
|
||||||
const padding: renderer.Padding = .{
|
const padding: renderer.Padding = .{
|
||||||
.top = padding_y,
|
.top = padding_y,
|
||||||
.bottom = padding_y,
|
.bottom = padding_y,
|
||||||
@ -429,8 +429,8 @@ pub fn init(
|
|||||||
// Set a minimum size that is cols=10 h=4. This matches Mac's Terminal.app
|
// Set a minimum size that is cols=10 h=4. This matches Mac's Terminal.app
|
||||||
// but is otherwise somewhat arbitrary.
|
// but is otherwise somewhat arbitrary.
|
||||||
try rt_surface.setSizeLimits(.{
|
try rt_surface.setSizeLimits(.{
|
||||||
.width = @intFromFloat(u32, cell_size.width * 10),
|
.width = @intFromFloat(cell_size.width * 10),
|
||||||
.height = @intFromFloat(u32, cell_size.height * 4),
|
.height = @intFromFloat(cell_size.height * 4),
|
||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
// Call our size callback which handles all our retina setup
|
// Call our size callback which handles all our retina setup
|
||||||
@ -447,10 +447,10 @@ pub fn init(
|
|||||||
dev_io.cval().IniFilename = "ghostty_dev_mode.ini";
|
dev_io.cval().IniFilename = "ghostty_dev_mode.ini";
|
||||||
|
|
||||||
// Add our built-in fonts so it looks slightly better
|
// Add our built-in fonts so it looks slightly better
|
||||||
const dev_atlas = @ptrCast(*imgui.FontAtlas, dev_io.cval().Fonts);
|
const dev_atlas: *imgui.FontAtlas = @ptrCast(dev_io.cval().Fonts);
|
||||||
dev_atlas.addFontFromMemoryTTF(
|
dev_atlas.addFontFromMemoryTTF(
|
||||||
face_ttf,
|
face_ttf,
|
||||||
@floatFromInt(f32, font_size.pixels()),
|
@floatFromInt(font_size.pixels()),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Default dark style
|
// Default dark style
|
||||||
@ -561,7 +561,7 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
|
|||||||
.set_title => |*v| {
|
.set_title => |*v| {
|
||||||
// The ptrCast just gets sliceTo to return the proper type.
|
// The ptrCast just gets sliceTo to return the proper type.
|
||||||
// We know that our title should end in 0.
|
// We know that our title should end in 0.
|
||||||
const slice = std.mem.sliceTo(@ptrCast([*:0]const u8, v), 0);
|
const slice = std.mem.sliceTo(@as([*:0]const u8, @ptrCast(v)), 0);
|
||||||
log.debug("changing title \"{s}\"", .{slice});
|
log.debug("changing title \"{s}\"", .{slice});
|
||||||
try self.rt_surface.setTitle(slice);
|
try self.rt_surface.setTitle(slice);
|
||||||
},
|
},
|
||||||
@ -662,7 +662,7 @@ pub fn imePoint(self: *const Surface) apprt.IMEPos {
|
|||||||
|
|
||||||
const x: f64 = x: {
|
const x: f64 = x: {
|
||||||
// Simple x * cell width gives the top-left corner
|
// Simple x * cell width gives the top-left corner
|
||||||
var x: f64 = @floatCast(f64, @floatFromInt(f32, cursor.x) * self.cell_size.width);
|
var x: f64 = @floatCast(@as(f32, @floatFromInt(cursor.x)) * self.cell_size.width);
|
||||||
|
|
||||||
// We want the midpoint
|
// We want the midpoint
|
||||||
x += self.cell_size.width / 2;
|
x += self.cell_size.width / 2;
|
||||||
@ -675,7 +675,7 @@ pub fn imePoint(self: *const Surface) apprt.IMEPos {
|
|||||||
|
|
||||||
const y: f64 = y: {
|
const y: f64 = y: {
|
||||||
// Simple x * cell width gives the top-left corner
|
// Simple x * cell width gives the top-left corner
|
||||||
var y: f64 = @floatCast(f64, @floatFromInt(f32, cursor.y) * self.cell_size.height);
|
var y: f64 = @floatCast(@as(f32, @floatFromInt(cursor.y)) * self.cell_size.height);
|
||||||
|
|
||||||
// We want the bottom
|
// We want the bottom
|
||||||
y += self.cell_size.height;
|
y += self.cell_size.height;
|
||||||
@ -1157,8 +1157,8 @@ pub fn keyCallback(
|
|||||||
|
|
||||||
// Handle non-printables
|
// Handle non-printables
|
||||||
const char: u8 = char: {
|
const char: u8 = char: {
|
||||||
const mods_int = @bitCast(u8, mods);
|
const mods_int: u8 = @bitCast(mods);
|
||||||
const ctrl_only = @bitCast(u8, input.Mods{ .ctrl = true });
|
const ctrl_only: u8 = @bitCast(input.Mods{ .ctrl = true });
|
||||||
|
|
||||||
// If we're only pressing control, check if this is a character
|
// If we're only pressing control, check if this is a character
|
||||||
// we convert to a non-printable.
|
// we convert to a non-printable.
|
||||||
@ -1200,18 +1200,18 @@ pub fn keyCallback(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we don't care what modifiers we press we do this.
|
// Otherwise, we don't care what modifiers we press we do this.
|
||||||
break :char @as(u8, switch (key) {
|
break :char switch (key) {
|
||||||
.backspace => 0x7F,
|
.backspace => 0x7F,
|
||||||
.enter => '\r',
|
.enter => '\r',
|
||||||
.tab => '\t',
|
.tab => '\t',
|
||||||
.escape => 0x1B,
|
.escape => 0x1B,
|
||||||
else => 0,
|
else => 0,
|
||||||
});
|
};
|
||||||
};
|
};
|
||||||
if (char > 0) {
|
if (char > 0) {
|
||||||
// Ask our IO thread to write the data
|
// Ask our IO thread to write the data
|
||||||
var data: termio.Message.WriteReq.Small.Array = undefined;
|
var data: termio.Message.WriteReq.Small.Array = undefined;
|
||||||
data[0] = @intCast(u8, char);
|
data[0] = @intCast(char);
|
||||||
_ = self.io_thread.mailbox.push(.{
|
_ = self.io_thread.mailbox.push(.{
|
||||||
.write_small = .{
|
.write_small = .{
|
||||||
.data = data,
|
.data = data,
|
||||||
@ -1306,7 +1306,7 @@ pub fn scrollCallback(
|
|||||||
if (!scroll_mods.precision) {
|
if (!scroll_mods.precision) {
|
||||||
const y_sign: isize = if (yoff > 0) -1 else 1;
|
const y_sign: isize = if (yoff > 0) -1 else 1;
|
||||||
const y_delta_unsigned: usize = @max(@divFloor(self.grid_size.rows, 15), 1);
|
const y_delta_unsigned: usize = @max(@divFloor(self.grid_size.rows, 15), 1);
|
||||||
const y_delta: isize = y_sign * @intCast(isize, y_delta_unsigned);
|
const y_delta: isize = y_sign * @as(isize, @intCast(y_delta_unsigned));
|
||||||
break :y .{ .sign = y_sign, .delta_unsigned = y_delta_unsigned, .delta = y_delta };
|
break :y .{ .sign = y_sign, .delta_unsigned = y_delta_unsigned, .delta = y_delta };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1337,8 +1337,8 @@ pub fn scrollCallback(
|
|||||||
self.mouse.pending_scroll_y = poff - (amount * cell_size);
|
self.mouse.pending_scroll_y = poff - (amount * cell_size);
|
||||||
|
|
||||||
break :y .{
|
break :y .{
|
||||||
.delta_unsigned = @intFromFloat(usize, @fabs(amount)),
|
.delta_unsigned = @intFromFloat(@fabs(amount)),
|
||||||
.delta = @intFromFloat(isize, amount),
|
.delta = @intFromFloat(amount),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1347,7 +1347,7 @@ pub fn scrollCallback(
|
|||||||
if (!scroll_mods.precision) {
|
if (!scroll_mods.precision) {
|
||||||
const x_sign: isize = if (xoff < 0) -1 else 1;
|
const x_sign: isize = if (xoff < 0) -1 else 1;
|
||||||
const x_delta_unsigned: usize = 1;
|
const x_delta_unsigned: usize = 1;
|
||||||
const x_delta: isize = x_sign * @intCast(isize, x_delta_unsigned);
|
const x_delta: isize = x_sign * @as(isize, @intCast(x_delta_unsigned));
|
||||||
break :x .{ .sign = x_sign, .delta_unsigned = x_delta_unsigned, .delta = x_delta };
|
break :x .{ .sign = x_sign, .delta_unsigned = x_delta_unsigned, .delta = x_delta };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1362,8 +1362,8 @@ pub fn scrollCallback(
|
|||||||
self.mouse.pending_scroll_x = poff - (amount * cell_size);
|
self.mouse.pending_scroll_x = poff - (amount * cell_size);
|
||||||
|
|
||||||
break :x .{
|
break :x .{
|
||||||
.delta_unsigned = @intFromFloat(usize, @fabs(amount)),
|
.delta_unsigned = @intFromFloat(@fabs(amount)),
|
||||||
.delta = @intFromFloat(isize, amount),
|
.delta = @intFromFloat(amount),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1524,8 +1524,8 @@ fn mouseReport(
|
|||||||
data[1] = '[';
|
data[1] = '[';
|
||||||
data[2] = 'M';
|
data[2] = 'M';
|
||||||
data[3] = 32 + button_code;
|
data[3] = 32 + button_code;
|
||||||
data[4] = 32 + @intCast(u8, viewport_point.x) + 1;
|
data[4] = 32 + @as(u8, @intCast(viewport_point.x)) + 1;
|
||||||
data[5] = 32 + @intCast(u8, viewport_point.y) + 1;
|
data[5] = 32 + @as(u8, @intCast(viewport_point.y)) + 1;
|
||||||
|
|
||||||
// Ask our IO thread to write the data
|
// Ask our IO thread to write the data
|
||||||
_ = self.io_thread.mailbox.push(.{
|
_ = self.io_thread.mailbox.push(.{
|
||||||
@ -1549,14 +1549,14 @@ fn mouseReport(
|
|||||||
|
|
||||||
// UTF-8 encode the x/y
|
// UTF-8 encode the x/y
|
||||||
var i: usize = 4;
|
var i: usize = 4;
|
||||||
i += try std.unicode.utf8Encode(@intCast(u21, 32 + viewport_point.x + 1), data[i..]);
|
i += try std.unicode.utf8Encode(@intCast(32 + viewport_point.x + 1), data[i..]);
|
||||||
i += try std.unicode.utf8Encode(@intCast(u21, 32 + viewport_point.y + 1), data[i..]);
|
i += try std.unicode.utf8Encode(@intCast(32 + viewport_point.y + 1), data[i..]);
|
||||||
|
|
||||||
// Ask our IO thread to write the data
|
// Ask our IO thread to write the data
|
||||||
_ = self.io_thread.mailbox.push(.{
|
_ = self.io_thread.mailbox.push(.{
|
||||||
.write_small = .{
|
.write_small = .{
|
||||||
.data = data,
|
.data = data,
|
||||||
.len = @intCast(u8, i),
|
.len = @intCast(i),
|
||||||
},
|
},
|
||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
},
|
},
|
||||||
@ -1579,7 +1579,7 @@ fn mouseReport(
|
|||||||
_ = self.io_thread.mailbox.push(.{
|
_ = self.io_thread.mailbox.push(.{
|
||||||
.write_small = .{
|
.write_small = .{
|
||||||
.data = data,
|
.data = data,
|
||||||
.len = @intCast(u8, resp.len),
|
.len = @intCast(resp.len),
|
||||||
},
|
},
|
||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
},
|
},
|
||||||
@ -1598,7 +1598,7 @@ fn mouseReport(
|
|||||||
_ = self.io_thread.mailbox.push(.{
|
_ = self.io_thread.mailbox.push(.{
|
||||||
.write_small = .{
|
.write_small = .{
|
||||||
.data = data,
|
.data = data,
|
||||||
.len = @intCast(u8, resp.len),
|
.len = @intCast(resp.len),
|
||||||
},
|
},
|
||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
},
|
},
|
||||||
@ -1621,7 +1621,7 @@ fn mouseReport(
|
|||||||
_ = self.io_thread.mailbox.push(.{
|
_ = self.io_thread.mailbox.push(.{
|
||||||
.write_small = .{
|
.write_small = .{
|
||||||
.data = data,
|
.data = data,
|
||||||
.len = @intCast(u8, resp.len),
|
.len = @intCast(resp.len),
|
||||||
},
|
},
|
||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
},
|
},
|
||||||
@ -1652,8 +1652,8 @@ pub fn mouseButtonCallback(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Always record our latest mouse state
|
// Always record our latest mouse state
|
||||||
self.mouse.click_state[@intCast(usize, @intFromEnum(button))] = action;
|
self.mouse.click_state[@intCast(@intFromEnum(button))] = action;
|
||||||
self.mouse.mods = @bitCast(input.Mods, mods);
|
self.mouse.mods = @bitCast(mods);
|
||||||
|
|
||||||
// Shift-click continues the previous mouse state if we have a selection.
|
// Shift-click continues the previous mouse state if we have a selection.
|
||||||
// cursorPosCallback will also do a mouse report so we don't need to do any
|
// cursorPosCallback will also do a mouse report so we don't need to do any
|
||||||
@ -1815,7 +1815,7 @@ pub fn cursorPosCallback(
|
|||||||
// since the spec (afaict) does not say...
|
// since the spec (afaict) does not say...
|
||||||
const button: ?input.MouseButton = button: for (self.mouse.click_state, 0..) |state, i| {
|
const button: ?input.MouseButton = button: for (self.mouse.click_state, 0..) |state, i| {
|
||||||
if (state == .press)
|
if (state == .press)
|
||||||
break :button @enumFromInt(input.MouseButton, i);
|
break :button @enumFromInt(i);
|
||||||
} else null;
|
} else null;
|
||||||
|
|
||||||
try self.mouseReport(button, .motion, self.mouse.mods, pos);
|
try self.mouseReport(button, .motion, self.mouse.mods, pos);
|
||||||
@ -1835,7 +1835,7 @@ pub fn cursorPosCallback(
|
|||||||
// up. The amount we scroll up is dependent on how negative we are.
|
// up. The amount we scroll up is dependent on how negative we are.
|
||||||
// Note: one day, we can change this from distance to time based if we want.
|
// Note: one day, we can change this from distance to time based if we want.
|
||||||
//log.warn("CURSOR POS: {} {}", .{ pos, self.screen_size });
|
//log.warn("CURSOR POS: {} {}", .{ pos, self.screen_size });
|
||||||
const max_y = @floatFromInt(f32, self.screen_size.height);
|
const max_y: f32 = @floatFromInt(self.screen_size.height);
|
||||||
if (pos.y < 0 or pos.y > max_y) {
|
if (pos.y < 0 or pos.y > max_y) {
|
||||||
const delta: isize = if (pos.y < 0) -1 else 1;
|
const delta: isize = if (pos.y < 0) -1 else 1;
|
||||||
try self.io.terminal.scrollViewport(.{ .delta = delta });
|
try self.io.terminal.scrollViewport(.{ .delta = delta });
|
||||||
@ -1947,7 +1947,7 @@ fn dragLeftClickSingle(
|
|||||||
const cell_xboundary = self.cell_size.width * 0.6;
|
const cell_xboundary = self.cell_size.width * 0.6;
|
||||||
|
|
||||||
// first xpos of the clicked cell
|
// first xpos of the clicked cell
|
||||||
const cell_xstart = @floatFromInt(f32, self.mouse.left_click_point.x) * self.cell_size.width;
|
const cell_xstart = @as(f32, @floatFromInt(self.mouse.left_click_point.x)) * self.cell_size.width;
|
||||||
const cell_start_xpos = self.mouse.left_click_xpos - cell_xstart;
|
const cell_start_xpos = self.mouse.left_click_xpos - cell_xstart;
|
||||||
|
|
||||||
// If this is the same cell, then we only start the selection if weve
|
// If this is the same cell, then we only start the selection if weve
|
||||||
@ -2022,8 +2022,8 @@ fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Viewport {
|
|||||||
return .{
|
return .{
|
||||||
.x = if (xpos < 0) 0 else x: {
|
.x = if (xpos < 0) 0 else x: {
|
||||||
// Our cell is the mouse divided by cell width
|
// Our cell is the mouse divided by cell width
|
||||||
const cell_width = @floatCast(f64, self.cell_size.width);
|
const cell_width: f64 = @floatCast(self.cell_size.width);
|
||||||
const x = @intFromFloat(usize, xpos / cell_width);
|
const x: usize = @intFromFloat(xpos / cell_width);
|
||||||
|
|
||||||
// Can be off the screen if the user drags it out, so max
|
// Can be off the screen if the user drags it out, so max
|
||||||
// it out on our available columns
|
// it out on our available columns
|
||||||
@ -2031,8 +2031,8 @@ fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Viewport {
|
|||||||
},
|
},
|
||||||
|
|
||||||
.y = if (ypos < 0) 0 else y: {
|
.y = if (ypos < 0) 0 else y: {
|
||||||
const cell_height = @floatCast(f64, self.cell_size.height);
|
const cell_height: f64 = @floatCast(self.cell_size.height);
|
||||||
const y = @intFromFloat(usize, ypos / cell_height);
|
const y: usize = @intFromFloat(ypos / cell_height);
|
||||||
break :y @min(y, self.grid_size.rows - 1);
|
break :y @min(y, self.grid_size.rows - 1);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -149,8 +149,8 @@ pub const Surface = struct {
|
|||||||
.core_surface = undefined,
|
.core_surface = undefined,
|
||||||
.nsview = objc.Object.fromId(opts.nsview),
|
.nsview = objc.Object.fromId(opts.nsview),
|
||||||
.content_scale = .{
|
.content_scale = .{
|
||||||
.x = @floatCast(f32, opts.scale_factor),
|
.x = @floatCast(opts.scale_factor),
|
||||||
.y = @floatCast(f32, opts.scale_factor),
|
.y = @floatCast(opts.scale_factor),
|
||||||
},
|
},
|
||||||
.size = .{ .width = 800, .height = 600 },
|
.size = .{ .width = 800, .height = 600 },
|
||||||
.cursor_pos = .{ .x = 0, .y = 0 },
|
.cursor_pos = .{ .x = 0, .y = 0 },
|
||||||
@ -263,8 +263,8 @@ pub const Surface = struct {
|
|||||||
|
|
||||||
pub fn updateContentScale(self: *Surface, x: f64, y: f64) void {
|
pub fn updateContentScale(self: *Surface, x: f64, y: f64) void {
|
||||||
self.content_scale = .{
|
self.content_scale = .{
|
||||||
.x = @floatCast(f32, x),
|
.x = @floatCast(x),
|
||||||
.y = @floatCast(f32, y),
|
.y = @floatCast(y),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,8 +314,8 @@ pub const Surface = struct {
|
|||||||
pub fn cursorPosCallback(self: *Surface, x: f64, y: f64) void {
|
pub fn cursorPosCallback(self: *Surface, x: f64, y: f64) void {
|
||||||
// Convert our unscaled x/y to scaled.
|
// Convert our unscaled x/y to scaled.
|
||||||
self.cursor_pos = self.cursorPosToPixels(.{
|
self.cursor_pos = self.cursorPosToPixels(.{
|
||||||
.x = @floatCast(f32, x),
|
.x = @floatCast(x),
|
||||||
.y = @floatCast(f32, y),
|
.y = @floatCast(y),
|
||||||
}) catch |err| {
|
}) catch |err| {
|
||||||
log.err(
|
log.err(
|
||||||
"error converting cursor pos to scaled pixels in cursor pos callback err={}",
|
"error converting cursor pos to scaled pixels in cursor pos callback err={}",
|
||||||
@ -479,7 +479,7 @@ pub const CAPI = struct {
|
|||||||
action,
|
action,
|
||||||
key,
|
key,
|
||||||
unmapped_key,
|
unmapped_key,
|
||||||
@bitCast(input.Mods, @truncate(u8, @bitCast(c_uint, mods))),
|
@bitCast(@as(u8, @truncate(@as(c_uint, @bitCast(mods))))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -498,7 +498,7 @@ pub const CAPI = struct {
|
|||||||
surface.mouseButtonCallback(
|
surface.mouseButtonCallback(
|
||||||
action,
|
action,
|
||||||
button,
|
button,
|
||||||
@bitCast(input.Mods, @truncate(u8, @bitCast(c_uint, mods))),
|
@bitCast(@as(u8, @truncate(@as(c_uint, @bitCast(mods))))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,7 +516,7 @@ pub const CAPI = struct {
|
|||||||
surface.scrollCallback(
|
surface.scrollCallback(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
@bitCast(input.ScrollMods, @truncate(u8, @bitCast(c_uint, scroll_mods))),
|
@bitCast(@as(u8, @truncate(@as(c_uint, @bitCast(scroll_mods))))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,8 +291,8 @@ pub const Surface = struct {
|
|||||||
};
|
};
|
||||||
const physical_size = monitor.getPhysicalSize();
|
const physical_size = monitor.getPhysicalSize();
|
||||||
const video_mode = monitor.getVideoMode() orelse return glfw.mustGetErrorCode();
|
const video_mode = monitor.getVideoMode() orelse return glfw.mustGetErrorCode();
|
||||||
const physical_x_dpi = @floatFromInt(f32, video_mode.getWidth()) / (@floatFromInt(f32, physical_size.width_mm) / 25.4);
|
const physical_x_dpi = @as(f32, @floatFromInt(video_mode.getWidth())) / (@as(f32, @floatFromInt(physical_size.width_mm)) / 25.4);
|
||||||
const physical_y_dpi = @floatFromInt(f32, video_mode.getHeight()) / (@floatFromInt(f32, physical_size.height_mm) / 25.4);
|
const physical_y_dpi = @as(f32, @floatFromInt(video_mode.getHeight())) / (@as(f32, @floatFromInt(physical_size.height_mm)) / 25.4);
|
||||||
log.debug("physical dpi x={} y={}", .{
|
log.debug("physical dpi x={} y={}", .{
|
||||||
physical_x_dpi,
|
physical_x_dpi,
|
||||||
physical_y_dpi,
|
physical_y_dpi,
|
||||||
@ -463,8 +463,8 @@ pub const Surface = struct {
|
|||||||
const unscaled_pos = self.window.getCursorPos();
|
const unscaled_pos = self.window.getCursorPos();
|
||||||
const pos = try self.cursorPosToPixels(unscaled_pos);
|
const pos = try self.cursorPosToPixels(unscaled_pos);
|
||||||
return apprt.CursorPos{
|
return apprt.CursorPos{
|
||||||
.x = @floatCast(f32, pos.xpos),
|
.x = @floatCast(pos.xpos),
|
||||||
.y = @floatCast(f32, pos.ypos),
|
.y = @floatCast(pos.ypos),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,8 +512,8 @@ pub const Surface = struct {
|
|||||||
if (fb_size.width == size.width and fb_size.height == size.height)
|
if (fb_size.width == size.width and fb_size.height == size.height)
|
||||||
return pos;
|
return pos;
|
||||||
|
|
||||||
const x_scale = @floatFromInt(f64, fb_size.width) / @floatFromInt(f64, size.width);
|
const x_scale = @as(f64, @floatFromInt(fb_size.width)) / @as(f64, @floatFromInt(size.width));
|
||||||
const y_scale = @floatFromInt(f64, fb_size.height) / @floatFromInt(f64, size.height);
|
const y_scale = @as(f64, @floatFromInt(fb_size.height)) / @as(f64, @floatFromInt(size.height));
|
||||||
return .{
|
return .{
|
||||||
.xpos = pos.xpos * x_scale,
|
.xpos = pos.xpos * x_scale,
|
||||||
.ypos = pos.ypos * y_scale,
|
.ypos = pos.ypos * y_scale,
|
||||||
@ -564,7 +564,7 @@ pub const Surface = struct {
|
|||||||
defer tracy.end();
|
defer tracy.end();
|
||||||
|
|
||||||
// Convert our glfw types into our input types
|
// Convert our glfw types into our input types
|
||||||
const mods = @bitCast(input.Mods, glfw_mods);
|
const mods: input.Mods = @bitCast(glfw_mods);
|
||||||
const action: input.Action = switch (glfw_action) {
|
const action: input.Action = switch (glfw_action) {
|
||||||
.release => .release,
|
.release => .release,
|
||||||
.press => .press,
|
.press => .press,
|
||||||
@ -764,8 +764,8 @@ pub const Surface = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
core_win.cursorPosCallback(.{
|
core_win.cursorPosCallback(.{
|
||||||
.x = @floatCast(f32, pos.xpos),
|
.x = @floatCast(pos.xpos),
|
||||||
.y = @floatCast(f32, pos.ypos),
|
.y = @floatCast(pos.ypos),
|
||||||
}) catch |err| {
|
}) catch |err| {
|
||||||
log.err("error in cursor pos callback err={}", .{err});
|
log.err("error in cursor pos callback err={}", .{err});
|
||||||
return;
|
return;
|
||||||
@ -784,7 +784,7 @@ pub const Surface = struct {
|
|||||||
const core_win = window.getUserPointer(CoreSurface) orelse return;
|
const core_win = window.getUserPointer(CoreSurface) orelse return;
|
||||||
|
|
||||||
// Convert glfw button to input button
|
// Convert glfw button to input button
|
||||||
const mods = @bitCast(input.Mods, glfw_mods);
|
const mods: input.Mods = @bitCast(glfw_mods);
|
||||||
const button: input.MouseButton = switch (glfw_button) {
|
const button: input.MouseButton = switch (glfw_button) {
|
||||||
.left => .left,
|
.left => .left,
|
||||||
.right => .right,
|
.right => .right,
|
||||||
|
@ -63,7 +63,7 @@ pub const App = struct {
|
|||||||
errdefer config.deinit();
|
errdefer config.deinit();
|
||||||
|
|
||||||
// Create our GTK Application which encapsulates our process.
|
// Create our GTK Application which encapsulates our process.
|
||||||
const app = @ptrCast(?*c.GtkApplication, c.gtk_application_new(
|
const app = @as(?*c.GtkApplication, @ptrCast(c.gtk_application_new(
|
||||||
null,
|
null,
|
||||||
|
|
||||||
// GTK >= 2.74
|
// GTK >= 2.74
|
||||||
@ -71,7 +71,7 @@ pub const App = struct {
|
|||||||
c.G_APPLICATION_DEFAULT_FLAGS
|
c.G_APPLICATION_DEFAULT_FLAGS
|
||||||
else
|
else
|
||||||
c.G_APPLICATION_FLAGS_NONE,
|
c.G_APPLICATION_FLAGS_NONE,
|
||||||
)) orelse return error.GtkInitFailed;
|
))) orelse return error.GtkInitFailed;
|
||||||
errdefer c.g_object_unref(app);
|
errdefer c.g_object_unref(app);
|
||||||
_ = c.g_signal_connect_data(
|
_ = c.g_signal_connect_data(
|
||||||
app,
|
app,
|
||||||
@ -89,12 +89,12 @@ pub const App = struct {
|
|||||||
if (c.g_main_context_acquire(ctx) == 0) return error.GtkContextAcquireFailed;
|
if (c.g_main_context_acquire(ctx) == 0) return error.GtkContextAcquireFailed;
|
||||||
errdefer c.g_main_context_release(ctx);
|
errdefer c.g_main_context_release(ctx);
|
||||||
|
|
||||||
const gapp = @ptrCast(*c.GApplication, app);
|
const gapp = @as(*c.GApplication, @ptrCast(app));
|
||||||
var err_: ?*c.GError = null;
|
var err_: ?*c.GError = null;
|
||||||
if (c.g_application_register(
|
if (c.g_application_register(
|
||||||
gapp,
|
gapp,
|
||||||
null,
|
null,
|
||||||
@ptrCast([*c][*c]c.GError, &err_),
|
@ptrCast(&err_),
|
||||||
) == 0) {
|
) == 0) {
|
||||||
if (err_) |err| {
|
if (err_) |err| {
|
||||||
log.warn("error registering application: {s}", .{err.message});
|
log.warn("error registering application: {s}", .{err.message});
|
||||||
@ -213,20 +213,20 @@ pub const App = struct {
|
|||||||
"Quit Ghostty?",
|
"Quit Ghostty?",
|
||||||
);
|
);
|
||||||
c.gtk_message_dialog_format_secondary_text(
|
c.gtk_message_dialog_format_secondary_text(
|
||||||
@ptrCast(*c.GtkMessageDialog, alert),
|
@ptrCast(alert),
|
||||||
"All active terminal sessions will be terminated.",
|
"All active terminal sessions will be terminated.",
|
||||||
);
|
);
|
||||||
|
|
||||||
// We want the "yes" to appear destructive.
|
// We want the "yes" to appear destructive.
|
||||||
const yes_widget = c.gtk_dialog_get_widget_for_response(
|
const yes_widget = c.gtk_dialog_get_widget_for_response(
|
||||||
@ptrCast(*c.GtkDialog, alert),
|
@ptrCast(alert),
|
||||||
c.GTK_RESPONSE_YES,
|
c.GTK_RESPONSE_YES,
|
||||||
);
|
);
|
||||||
c.gtk_widget_add_css_class(yes_widget, "destructive-action");
|
c.gtk_widget_add_css_class(yes_widget, "destructive-action");
|
||||||
|
|
||||||
// We want the "no" to be the default action
|
// We want the "no" to be the default action
|
||||||
c.gtk_dialog_set_default_response(
|
c.gtk_dialog_set_default_response(
|
||||||
@ptrCast(*c.GtkDialog, alert),
|
@ptrCast(alert),
|
||||||
c.GTK_RESPONSE_NO,
|
c.GTK_RESPONSE_NO,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ pub const App = struct {
|
|||||||
_ = ud;
|
_ = ud;
|
||||||
|
|
||||||
// Close the alert window
|
// Close the alert window
|
||||||
c.gtk_window_destroy(@ptrCast(*c.GtkWindow, alert));
|
c.gtk_window_destroy(@ptrCast(alert));
|
||||||
|
|
||||||
// If we didn't confirm then we're done
|
// If we didn't confirm then we're done
|
||||||
if (response != c.GTK_RESPONSE_YES) return;
|
if (response != c.GTK_RESPONSE_YES) return;
|
||||||
@ -254,8 +254,8 @@ pub const App = struct {
|
|||||||
c.g_list_foreach(list, struct {
|
c.g_list_foreach(list, struct {
|
||||||
fn callback(data: c.gpointer, _: c.gpointer) callconv(.C) void {
|
fn callback(data: c.gpointer, _: c.gpointer) callconv(.C) void {
|
||||||
const ptr = data orelse return;
|
const ptr = data orelse return;
|
||||||
const widget = @ptrCast(*c.GtkWidget, @alignCast(@alignOf(c.GtkWidget), ptr));
|
const widget: *c.GtkWidget = @ptrCast(@alignCast(ptr));
|
||||||
const window = @ptrCast(*c.GtkWindow, widget);
|
const window: *c.GtkWindow = @ptrCast(widget);
|
||||||
c.gtk_window_destroy(window);
|
c.gtk_window_destroy(window);
|
||||||
}
|
}
|
||||||
}.callback, null);
|
}.callback, null);
|
||||||
@ -296,7 +296,7 @@ const Window = struct {
|
|||||||
|
|
||||||
// Create the window
|
// Create the window
|
||||||
const window = c.gtk_application_window_new(app.app);
|
const window = c.gtk_application_window_new(app.app);
|
||||||
const gtk_window = @ptrCast(*c.GtkWindow, window);
|
const gtk_window: *c.GtkWindow = @ptrCast(window);
|
||||||
errdefer c.gtk_window_destroy(gtk_window);
|
errdefer c.gtk_window_destroy(gtk_window);
|
||||||
self.window = gtk_window;
|
self.window = gtk_window;
|
||||||
c.gtk_window_set_title(gtk_window, "Ghostty");
|
c.gtk_window_set_title(gtk_window, "Ghostty");
|
||||||
@ -307,7 +307,7 @@ const Window = struct {
|
|||||||
|
|
||||||
// Create a notebook to hold our tabs.
|
// Create a notebook to hold our tabs.
|
||||||
const notebook_widget = c.gtk_notebook_new();
|
const notebook_widget = c.gtk_notebook_new();
|
||||||
const notebook = @ptrCast(*c.GtkNotebook, notebook_widget);
|
const notebook: *c.GtkNotebook = @ptrCast(notebook_widget);
|
||||||
self.notebook = notebook;
|
self.notebook = notebook;
|
||||||
c.gtk_notebook_set_tab_pos(notebook, c.GTK_POS_TOP);
|
c.gtk_notebook_set_tab_pos(notebook, c.GTK_POS_TOP);
|
||||||
c.gtk_notebook_set_scrollable(notebook, 1);
|
c.gtk_notebook_set_scrollable(notebook, 1);
|
||||||
@ -339,12 +339,12 @@ const Window = struct {
|
|||||||
|
|
||||||
// Build our tab label
|
// Build our tab label
|
||||||
const label_box_widget = c.gtk_box_new(c.GTK_ORIENTATION_HORIZONTAL, 0);
|
const label_box_widget = c.gtk_box_new(c.GTK_ORIENTATION_HORIZONTAL, 0);
|
||||||
const label_box = @ptrCast(*c.GtkBox, label_box_widget);
|
const label_box = @as(*c.GtkBox, @ptrCast(label_box_widget));
|
||||||
const label_text = c.gtk_label_new("Ghostty");
|
const label_text = c.gtk_label_new("Ghostty");
|
||||||
c.gtk_box_append(label_box, label_text);
|
c.gtk_box_append(label_box, label_text);
|
||||||
|
|
||||||
const label_close_widget = c.gtk_button_new_from_icon_name("window-close");
|
const label_close_widget = c.gtk_button_new_from_icon_name("window-close");
|
||||||
const label_close = @ptrCast(*c.GtkButton, label_close_widget);
|
const label_close = @as(*c.GtkButton, @ptrCast(label_close_widget));
|
||||||
c.gtk_button_set_has_frame(label_close, 0);
|
c.gtk_button_set_has_frame(label_close, 0);
|
||||||
c.gtk_box_append(label_box, label_close_widget);
|
c.gtk_box_append(label_box, label_close_widget);
|
||||||
_ = c.g_signal_connect_data(label_close, "clicked", c.G_CALLBACK(>kTabCloseClick), self, null, G_CONNECT_DEFAULT);
|
_ = c.g_signal_connect_data(label_close, "clicked", c.G_CALLBACK(>kTabCloseClick), self, null, G_CONNECT_DEFAULT);
|
||||||
@ -356,8 +356,8 @@ const Window = struct {
|
|||||||
const gl_area = c.gtk_gl_area_new();
|
const gl_area = c.gtk_gl_area_new();
|
||||||
try surface.init(self.app, .{
|
try surface.init(self.app, .{
|
||||||
.window = self,
|
.window = self,
|
||||||
.gl_area = @ptrCast(*c.GtkGLArea, gl_area),
|
.gl_area = @ptrCast(gl_area),
|
||||||
.title_label = @ptrCast(*c.GtkLabel, label_text),
|
.title_label = @ptrCast(label_text),
|
||||||
});
|
});
|
||||||
errdefer surface.deinit();
|
errdefer surface.deinit();
|
||||||
const page_idx = c.gtk_notebook_append_page(self.notebook, gl_area, label_box_widget);
|
const page_idx = c.gtk_notebook_append_page(self.notebook, gl_area, label_box_widget);
|
||||||
@ -377,16 +377,16 @@ const Window = struct {
|
|||||||
// Set the userdata of the close button so it points to this page.
|
// Set the userdata of the close button so it points to this page.
|
||||||
const page = c.gtk_notebook_get_page(self.notebook, gl_area) orelse
|
const page = c.gtk_notebook_get_page(self.notebook, gl_area) orelse
|
||||||
return error.GtkNotebookPageNotFound;
|
return error.GtkNotebookPageNotFound;
|
||||||
c.g_object_set_data(@ptrCast(*c.GObject, label_close), TAB_CLOSE_SURFACE, surface);
|
c.g_object_set_data(@ptrCast(label_close), TAB_CLOSE_SURFACE, surface);
|
||||||
c.g_object_set_data(@ptrCast(*c.GObject, label_close), TAB_CLOSE_PAGE, page);
|
c.g_object_set_data(@ptrCast(label_close), TAB_CLOSE_PAGE, page);
|
||||||
c.g_object_set_data(@ptrCast(*c.GObject, gl_area), TAB_CLOSE_PAGE, page);
|
c.g_object_set_data(@ptrCast(gl_area), TAB_CLOSE_PAGE, page);
|
||||||
|
|
||||||
// Switch to the new tab
|
// Switch to the new tab
|
||||||
c.gtk_notebook_set_current_page(self.notebook, page_idx);
|
c.gtk_notebook_set_current_page(self.notebook, page_idx);
|
||||||
|
|
||||||
// We need to grab focus after it is added to the window. When
|
// We need to grab focus after it is added to the window. When
|
||||||
// creating a window we want to always focus on the widget.
|
// creating a window we want to always focus on the widget.
|
||||||
const widget = @ptrCast(*c.GtkWidget, gl_area);
|
const widget = @as(*c.GtkWidget, @ptrCast(gl_area));
|
||||||
_ = c.gtk_widget_grab_focus(widget);
|
_ = c.gtk_widget_grab_focus(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,12 +415,12 @@ const Window = struct {
|
|||||||
/// Close the surface. This surface must be definitely part of this window.
|
/// Close the surface. This surface must be definitely part of this window.
|
||||||
fn closeSurface(self: *Window, surface: *Surface) void {
|
fn closeSurface(self: *Window, surface: *Surface) void {
|
||||||
assert(surface.window == self);
|
assert(surface.window == self);
|
||||||
self.closeTab(getNotebookPage(@ptrCast(*c.GObject, surface.gl_area)) orelse return);
|
self.closeTab(getNotebookPage(@ptrCast(surface.gl_area)) orelse return);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Go to the previous tab for a surface.
|
/// Go to the previous tab for a surface.
|
||||||
fn gotoPreviousTab(self: *Window, surface: *Surface) void {
|
fn gotoPreviousTab(self: *Window, surface: *Surface) void {
|
||||||
const page = getNotebookPage(@ptrCast(*c.GObject, surface.gl_area)) orelse return;
|
const page = getNotebookPage(@ptrCast(surface.gl_area)) orelse return;
|
||||||
const page_idx = getNotebookPageIndex(page);
|
const page_idx = getNotebookPageIndex(page);
|
||||||
|
|
||||||
// The next index is the previous or we wrap around.
|
// The next index is the previous or we wrap around.
|
||||||
@ -438,7 +438,7 @@ const Window = struct {
|
|||||||
|
|
||||||
/// Go to the next tab for a surface.
|
/// Go to the next tab for a surface.
|
||||||
fn gotoNextTab(self: *Window, surface: *Surface) void {
|
fn gotoNextTab(self: *Window, surface: *Surface) void {
|
||||||
const page = getNotebookPage(@ptrCast(*c.GObject, surface.gl_area)) orelse return;
|
const page = getNotebookPage(@ptrCast(surface.gl_area)) orelse return;
|
||||||
const page_idx = getNotebookPageIndex(page);
|
const page_idx = getNotebookPageIndex(page);
|
||||||
const max = c.gtk_notebook_get_n_pages(self.notebook) -| 1;
|
const max = c.gtk_notebook_get_n_pages(self.notebook) -| 1;
|
||||||
const next_idx = if (page_idx < max) page_idx + 1 else 0;
|
const next_idx = if (page_idx < max) page_idx + 1 else 0;
|
||||||
@ -476,9 +476,8 @@ const Window = struct {
|
|||||||
|
|
||||||
fn gtkTabCloseClick(btn: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void {
|
fn gtkTabCloseClick(btn: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void {
|
||||||
_ = ud;
|
_ = ud;
|
||||||
const surface = @ptrCast(*Surface, @alignCast(
|
const surface: *Surface = @ptrCast(@alignCast(
|
||||||
@alignOf(Surface),
|
c.g_object_get_data(@ptrCast(btn), TAB_CLOSE_SURFACE) orelse return,
|
||||||
c.g_object_get_data(@ptrCast(*c.GObject, btn), TAB_CLOSE_SURFACE) orelse return,
|
|
||||||
));
|
));
|
||||||
|
|
||||||
surface.core_surface.close();
|
surface.core_surface.close();
|
||||||
@ -498,20 +497,20 @@ const Window = struct {
|
|||||||
"Close this window?",
|
"Close this window?",
|
||||||
);
|
);
|
||||||
c.gtk_message_dialog_format_secondary_text(
|
c.gtk_message_dialog_format_secondary_text(
|
||||||
@ptrCast(*c.GtkMessageDialog, alert),
|
@ptrCast(alert),
|
||||||
"All terminal sessions in this window will be terminated.",
|
"All terminal sessions in this window will be terminated.",
|
||||||
);
|
);
|
||||||
|
|
||||||
// We want the "yes" to appear destructive.
|
// We want the "yes" to appear destructive.
|
||||||
const yes_widget = c.gtk_dialog_get_widget_for_response(
|
const yes_widget = c.gtk_dialog_get_widget_for_response(
|
||||||
@ptrCast(*c.GtkDialog, alert),
|
@ptrCast(alert),
|
||||||
c.GTK_RESPONSE_YES,
|
c.GTK_RESPONSE_YES,
|
||||||
);
|
);
|
||||||
c.gtk_widget_add_css_class(yes_widget, "destructive-action");
|
c.gtk_widget_add_css_class(yes_widget, "destructive-action");
|
||||||
|
|
||||||
// We want the "no" to be the default action
|
// We want the "no" to be the default action
|
||||||
c.gtk_dialog_set_default_response(
|
c.gtk_dialog_set_default_response(
|
||||||
@ptrCast(*c.GtkDialog, alert),
|
@ptrCast(alert),
|
||||||
c.GTK_RESPONSE_NO,
|
c.GTK_RESPONSE_NO,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -526,7 +525,7 @@ const Window = struct {
|
|||||||
response: c.gint,
|
response: c.gint,
|
||||||
ud: ?*anyopaque,
|
ud: ?*anyopaque,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
c.gtk_window_destroy(@ptrCast(*c.GtkWindow, alert));
|
c.gtk_window_destroy(@ptrCast(alert));
|
||||||
if (response == c.GTK_RESPONSE_YES) {
|
if (response == c.GTK_RESPONSE_YES) {
|
||||||
const self = userdataSelf(ud.?);
|
const self = userdataSelf(ud.?);
|
||||||
c.gtk_window_destroy(self.window);
|
c.gtk_window_destroy(self.window);
|
||||||
@ -547,8 +546,7 @@ const Window = struct {
|
|||||||
/// Get the GtkNotebookPage for the given object. You must be sure the
|
/// Get the GtkNotebookPage for the given object. You must be sure the
|
||||||
/// object has the notebook page property set.
|
/// object has the notebook page property set.
|
||||||
fn getNotebookPage(obj: *c.GObject) ?*c.GtkNotebookPage {
|
fn getNotebookPage(obj: *c.GObject) ?*c.GtkNotebookPage {
|
||||||
return @ptrCast(*c.GtkNotebookPage, @alignCast(
|
return @ptrCast(@alignCast(
|
||||||
@alignOf(c.GtkNotebookPage),
|
|
||||||
c.g_object_get_data(obj, TAB_CLOSE_PAGE) orelse return null,
|
c.g_object_get_data(obj, TAB_CLOSE_PAGE) orelse return null,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -558,7 +556,7 @@ const Window = struct {
|
|||||||
defer c.g_value_unset(&value);
|
defer c.g_value_unset(&value);
|
||||||
_ = c.g_value_init(&value, c.G_TYPE_INT);
|
_ = c.g_value_init(&value, c.G_TYPE_INT);
|
||||||
c.g_object_get_property(
|
c.g_object_get_property(
|
||||||
@ptrCast(*c.GObject, @alignCast(@alignOf(c.GObject), page)),
|
@ptrCast(@alignCast(page)),
|
||||||
"position",
|
"position",
|
||||||
&value,
|
&value,
|
||||||
);
|
);
|
||||||
@ -567,7 +565,7 @@ const Window = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn userdataSelf(ud: *anyopaque) *Window {
|
fn userdataSelf(ud: *anyopaque) *Window {
|
||||||
return @ptrCast(*Window, @alignCast(@alignOf(Window), ud));
|
return @ptrCast(@alignCast(ud));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -619,7 +617,7 @@ pub const Surface = struct {
|
|||||||
clipboard: c.GValue,
|
clipboard: c.GValue,
|
||||||
|
|
||||||
pub fn init(self: *Surface, app: *App, opts: Options) !void {
|
pub fn init(self: *Surface, app: *App, opts: Options) !void {
|
||||||
const widget = @ptrCast(*c.GtkWidget, opts.gl_area);
|
const widget = @as(*c.GtkWidget, @ptrCast(opts.gl_area));
|
||||||
c.gtk_gl_area_set_required_version(opts.gl_area, 3, 3);
|
c.gtk_gl_area_set_required_version(opts.gl_area, 3, 3);
|
||||||
c.gtk_gl_area_set_has_stencil_buffer(opts.gl_area, 0);
|
c.gtk_gl_area_set_has_stencil_buffer(opts.gl_area, 0);
|
||||||
c.gtk_gl_area_set_has_depth_buffer(opts.gl_area, 0);
|
c.gtk_gl_area_set_has_depth_buffer(opts.gl_area, 0);
|
||||||
@ -642,7 +640,7 @@ pub const Surface = struct {
|
|||||||
const im_context = c.gtk_im_multicontext_new();
|
const im_context = c.gtk_im_multicontext_new();
|
||||||
errdefer c.g_object_unref(im_context);
|
errdefer c.g_object_unref(im_context);
|
||||||
c.gtk_event_controller_key_set_im_context(
|
c.gtk_event_controller_key_set_im_context(
|
||||||
@ptrCast(*c.GtkEventControllerKey, ec_key),
|
@ptrCast(ec_key),
|
||||||
im_context,
|
im_context,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -656,14 +654,8 @@ pub const Surface = struct {
|
|||||||
// Clicks
|
// Clicks
|
||||||
const gesture_click = c.gtk_gesture_click_new();
|
const gesture_click = c.gtk_gesture_click_new();
|
||||||
errdefer c.g_object_unref(gesture_click);
|
errdefer c.g_object_unref(gesture_click);
|
||||||
c.gtk_gesture_single_set_button(@ptrCast(
|
c.gtk_gesture_single_set_button(@ptrCast(gesture_click), 0);
|
||||||
*c.GtkGestureSingle,
|
c.gtk_widget_add_controller(widget, @ptrCast(gesture_click));
|
||||||
gesture_click,
|
|
||||||
), 0);
|
|
||||||
c.gtk_widget_add_controller(widget, @ptrCast(
|
|
||||||
*c.GtkEventController,
|
|
||||||
gesture_click,
|
|
||||||
));
|
|
||||||
|
|
||||||
// Mouse movement
|
// Mouse movement
|
||||||
const ec_motion = c.gtk_event_controller_motion_new();
|
const ec_motion = c.gtk_event_controller_motion_new();
|
||||||
@ -778,7 +770,7 @@ pub const Surface = struct {
|
|||||||
"Close this terminal?",
|
"Close this terminal?",
|
||||||
);
|
);
|
||||||
c.gtk_message_dialog_format_secondary_text(
|
c.gtk_message_dialog_format_secondary_text(
|
||||||
@ptrCast(*c.GtkMessageDialog, alert),
|
@ptrCast(alert),
|
||||||
"There is still a running process in the terminal. " ++
|
"There is still a running process in the terminal. " ++
|
||||||
"Closing the terminal will kill this process. " ++
|
"Closing the terminal will kill this process. " ++
|
||||||
"Are you sure you want to close the terminal?" ++
|
"Are you sure you want to close the terminal?" ++
|
||||||
@ -787,14 +779,14 @@ pub const Surface = struct {
|
|||||||
|
|
||||||
// We want the "yes" to appear destructive.
|
// We want the "yes" to appear destructive.
|
||||||
const yes_widget = c.gtk_dialog_get_widget_for_response(
|
const yes_widget = c.gtk_dialog_get_widget_for_response(
|
||||||
@ptrCast(*c.GtkDialog, alert),
|
@ptrCast(alert),
|
||||||
c.GTK_RESPONSE_YES,
|
c.GTK_RESPONSE_YES,
|
||||||
);
|
);
|
||||||
c.gtk_widget_add_css_class(yes_widget, "destructive-action");
|
c.gtk_widget_add_css_class(yes_widget, "destructive-action");
|
||||||
|
|
||||||
// We want the "no" to be the default action
|
// We want the "no" to be the default action
|
||||||
c.gtk_dialog_set_default_response(
|
c.gtk_dialog_set_default_response(
|
||||||
@ptrCast(*c.GtkDialog, alert),
|
@ptrCast(alert),
|
||||||
c.GTK_RESPONSE_NO,
|
c.GTK_RESPONSE_NO,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -861,10 +853,7 @@ pub const Surface = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getClipboardString(self: *Surface) ![:0]const u8 {
|
pub fn getClipboardString(self: *Surface) ![:0]const u8 {
|
||||||
const clipboard = c.gtk_widget_get_clipboard(@ptrCast(
|
const clipboard = c.gtk_widget_get_clipboard(@ptrCast(self.gl_area));
|
||||||
*c.GtkWidget,
|
|
||||||
self.gl_area,
|
|
||||||
));
|
|
||||||
|
|
||||||
const content = c.gdk_clipboard_get_content(clipboard) orelse {
|
const content = c.gdk_clipboard_get_content(clipboard) orelse {
|
||||||
// On my machine, this NEVER works, so we fallback to glfw's
|
// On my machine, this NEVER works, so we fallback to glfw's
|
||||||
@ -884,10 +873,7 @@ pub const Surface = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn setClipboardString(self: *const Surface, val: [:0]const u8) !void {
|
pub fn setClipboardString(self: *const Surface, val: [:0]const u8) !void {
|
||||||
const clipboard = c.gtk_widget_get_clipboard(@ptrCast(
|
const clipboard = c.gtk_widget_get_clipboard(@ptrCast(self.gl_area));
|
||||||
*c.GtkWidget,
|
|
||||||
self.gl_area,
|
|
||||||
));
|
|
||||||
|
|
||||||
c.gdk_clipboard_set_text(clipboard, val.ptr);
|
c.gdk_clipboard_set_text(clipboard, val.ptr);
|
||||||
}
|
}
|
||||||
@ -937,12 +923,12 @@ pub const Surface = struct {
|
|||||||
// Some debug output to help understand what GTK is telling us.
|
// Some debug output to help understand what GTK is telling us.
|
||||||
{
|
{
|
||||||
const scale_factor = scale: {
|
const scale_factor = scale: {
|
||||||
const widget = @ptrCast(*c.GtkWidget, area);
|
const widget = @as(*c.GtkWidget, @ptrCast(area));
|
||||||
break :scale c.gtk_widget_get_scale_factor(widget);
|
break :scale c.gtk_widget_get_scale_factor(widget);
|
||||||
};
|
};
|
||||||
|
|
||||||
const window_scale_factor = scale: {
|
const window_scale_factor = scale: {
|
||||||
const window = @ptrCast(*c.GtkNative, self.window.window);
|
const window = @as(*c.GtkNative, @ptrCast(self.window.window));
|
||||||
const gdk_surface = c.gtk_native_get_surface(window);
|
const gdk_surface = c.gtk_native_get_surface(window);
|
||||||
break :scale c.gdk_surface_get_scale_factor(gdk_surface);
|
break :scale c.gdk_surface_get_scale_factor(gdk_surface);
|
||||||
};
|
};
|
||||||
@ -956,8 +942,8 @@ pub const Surface = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.size = .{
|
self.size = .{
|
||||||
.width = @intCast(u32, width),
|
.width = @intCast(width),
|
||||||
.height = @intCast(u32, height),
|
.height = @intCast(height),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Call the primary callback.
|
// Call the primary callback.
|
||||||
@ -988,13 +974,10 @@ pub const Surface = struct {
|
|||||||
ud: ?*anyopaque,
|
ud: ?*anyopaque,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const self = userdataSelf(ud.?);
|
const self = userdataSelf(ud.?);
|
||||||
const button = translateMouseButton(c.gtk_gesture_single_get_current_button(@ptrCast(
|
const button = translateMouseButton(c.gtk_gesture_single_get_current_button(@ptrCast(gesture)));
|
||||||
*c.GtkGestureSingle,
|
|
||||||
gesture,
|
|
||||||
)));
|
|
||||||
|
|
||||||
// If we don't have focus, grab it.
|
// If we don't have focus, grab it.
|
||||||
const gl_widget = @ptrCast(*c.GtkWidget, self.gl_area);
|
const gl_widget = @as(*c.GtkWidget, @ptrCast(self.gl_area));
|
||||||
if (c.gtk_widget_has_focus(gl_widget) == 0) {
|
if (c.gtk_widget_has_focus(gl_widget) == 0) {
|
||||||
_ = c.gtk_widget_grab_focus(gl_widget);
|
_ = c.gtk_widget_grab_focus(gl_widget);
|
||||||
}
|
}
|
||||||
@ -1012,11 +995,7 @@ pub const Surface = struct {
|
|||||||
_: c.gdouble,
|
_: c.gdouble,
|
||||||
ud: ?*anyopaque,
|
ud: ?*anyopaque,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const button = translateMouseButton(c.gtk_gesture_single_get_current_button(@ptrCast(
|
const button = translateMouseButton(c.gtk_gesture_single_get_current_button(@ptrCast(gesture)));
|
||||||
*c.GtkGestureSingle,
|
|
||||||
gesture,
|
|
||||||
)));
|
|
||||||
|
|
||||||
const self = userdataSelf(ud.?);
|
const self = userdataSelf(ud.?);
|
||||||
self.core_surface.mouseButtonCallback(.release, button, .{}) catch |err| {
|
self.core_surface.mouseButtonCallback(.release, button, .{}) catch |err| {
|
||||||
log.err("error in key callback err={}", .{err});
|
log.err("error in key callback err={}", .{err});
|
||||||
@ -1032,8 +1011,8 @@ pub const Surface = struct {
|
|||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const self = userdataSelf(ud.?);
|
const self = userdataSelf(ud.?);
|
||||||
self.cursor_pos = .{
|
self.cursor_pos = .{
|
||||||
.x = @max(@as(f32, 0), @floatCast(f32, x)),
|
.x = @max(@as(f32, 0), @as(f32, @floatCast(x))),
|
||||||
.y = @floatCast(f32, y),
|
.y = @floatCast(y),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.core_surface.cursorPosCallback(self.cursor_pos) catch |err| {
|
self.core_surface.cursorPosCallback(self.cursor_pos) catch |err| {
|
||||||
@ -1067,7 +1046,7 @@ pub const Surface = struct {
|
|||||||
ud: ?*anyopaque,
|
ud: ?*anyopaque,
|
||||||
) callconv(.C) c.gboolean {
|
) callconv(.C) c.gboolean {
|
||||||
const self = userdataSelf(ud.?);
|
const self = userdataSelf(ud.?);
|
||||||
const display = c.gtk_widget_get_display(@ptrCast(*c.GtkWidget, self.gl_area)).?;
|
const display = c.gtk_widget_get_display(@ptrCast(self.gl_area)).?;
|
||||||
|
|
||||||
// We want to use only the key that corresponds to the hardware key.
|
// We want to use only the key that corresponds to the hardware key.
|
||||||
// I suspect this logic is actually wrong for customized keyboards,
|
// I suspect this logic is actually wrong for customized keyboards,
|
||||||
@ -1087,7 +1066,7 @@ pub const Surface = struct {
|
|||||||
// that assumption is true.
|
// that assumption is true.
|
||||||
const keyval = keyval: {
|
const keyval = keyval: {
|
||||||
if (found > 0) {
|
if (found > 0) {
|
||||||
for (keys[0..@intCast(usize, keys_len)], 0..) |key, i| {
|
for (keys[0..@intCast(keys_len)], 0..) |key, i| {
|
||||||
if (key.group == 0 and key.level == 0)
|
if (key.group == 0 and key.level == 0)
|
||||||
break :keyval keyvals[i];
|
break :keyval keyvals[i];
|
||||||
}
|
}
|
||||||
@ -1183,7 +1162,7 @@ pub const Surface = struct {
|
|||||||
response: c.gint,
|
response: c.gint,
|
||||||
ud: ?*anyopaque,
|
ud: ?*anyopaque,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
c.gtk_window_destroy(@ptrCast(*c.GtkWindow, alert));
|
c.gtk_window_destroy(@ptrCast(alert));
|
||||||
if (response == c.GTK_RESPONSE_YES) {
|
if (response == c.GTK_RESPONSE_YES) {
|
||||||
const self = userdataSelf(ud.?);
|
const self = userdataSelf(ud.?);
|
||||||
self.window.closeSurface(self);
|
self.window.closeSurface(self);
|
||||||
@ -1191,7 +1170,7 @@ pub const Surface = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn userdataSelf(ud: *anyopaque) *Surface {
|
fn userdataSelf(ud: *anyopaque) *Surface {
|
||||||
return @ptrCast(*Surface, @alignCast(@alignOf(Surface), ud));
|
return @ptrCast(@alignCast(ud));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ pub fn BlockingQueue(
|
|||||||
pub const Size = u32;
|
pub const Size = u32;
|
||||||
|
|
||||||
// The bounds of this queue. We recast this to Size so we can do math.
|
// The bounds of this queue. We recast this to Size so we can do math.
|
||||||
const bounds = @intCast(Size, capacity);
|
const bounds: Size = @intCast(capacity);
|
||||||
|
|
||||||
/// Specifies the timeout for an operation.
|
/// Specifies the timeout for an operation.
|
||||||
pub const Timeout = union(enum) {
|
pub const Timeout = union(enum) {
|
||||||
|
@ -431,7 +431,7 @@ pub const Config = struct {
|
|||||||
|
|
||||||
try result.keybind.set.put(
|
try result.keybind.set.put(
|
||||||
alloc,
|
alloc,
|
||||||
.{ .key = @enumFromInt(inputpkg.Key, i), .mods = mods },
|
.{ .key = @enumFromInt(i), .mods = mods },
|
||||||
.{ .goto_tab = (i - start) + 1 },
|
.{ .goto_tab = (i - start) + 1 },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ pub const Wasm = struct {
|
|||||||
const atlas = init(
|
const atlas = init(
|
||||||
alloc,
|
alloc,
|
||||||
size,
|
size,
|
||||||
@enumFromInt(Format, format),
|
@enumFromInt(format),
|
||||||
) catch return null;
|
) catch return null;
|
||||||
const result = alloc.create(Atlas) catch return null;
|
const result = alloc.create(Atlas) catch return null;
|
||||||
result.* = atlas;
|
result.* = atlas;
|
||||||
@ -449,7 +449,7 @@ pub const Wasm = struct {
|
|||||||
// Draw it
|
// Draw it
|
||||||
try ctx.call(void, "putImageData", .{ image_data, 0, 0 });
|
try ctx.call(void, "putImageData", .{ image_data, 0, 0 });
|
||||||
|
|
||||||
const id = @bitCast(js.Ref, @intFromEnum(canvas.value)).id;
|
const id = @as(js.Ref, @bitCast(@intFromEnum(canvas.value))).id;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -561,7 +561,7 @@ test "writing RGB data" {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 33 because of the 1px border and so on
|
// 33 because of the 1px border and so on
|
||||||
const depth = @intCast(usize, atlas.format.depth());
|
const depth = @as(usize, @intCast(atlas.format.depth()));
|
||||||
try testing.expectEqual(@as(u8, 1), atlas.data[33 * depth]);
|
try testing.expectEqual(@as(u8, 1), atlas.data[33 * depth]);
|
||||||
try testing.expectEqual(@as(u8, 2), atlas.data[33 * depth + 1]);
|
try testing.expectEqual(@as(u8, 2), atlas.data[33 * depth + 1]);
|
||||||
try testing.expectEqual(@as(u8, 3), atlas.data[33 * depth + 2]);
|
try testing.expectEqual(@as(u8, 3), atlas.data[33 * depth + 2]);
|
||||||
@ -591,7 +591,7 @@ test "grow RGB" {
|
|||||||
|
|
||||||
// Our top left skips the first row (size * depth) and the first
|
// Our top left skips the first row (size * depth) and the first
|
||||||
// column (depth) for the 1px border.
|
// column (depth) for the 1px border.
|
||||||
const depth = @intCast(usize, atlas.format.depth());
|
const depth = @as(usize, @intCast(atlas.format.depth()));
|
||||||
var tl = (atlas.size * depth) + depth;
|
var tl = (atlas.size * depth) + depth;
|
||||||
try testing.expectEqual(@as(u8, 10), atlas.data[tl]);
|
try testing.expectEqual(@as(u8, 10), atlas.data[tl]);
|
||||||
try testing.expectEqual(@as(u8, 11), atlas.data[tl + 1]);
|
try testing.expectEqual(@as(u8, 11), atlas.data[tl + 1]);
|
||||||
|
@ -353,7 +353,7 @@ pub const Wasm = struct {
|
|||||||
.wc = .{
|
.wc = .{
|
||||||
.alloc = alloc,
|
.alloc = alloc,
|
||||||
.font_str = font_str,
|
.font_str = font_str,
|
||||||
.presentation = @enumFromInt(font.Presentation, presentation),
|
.presentation = @enumFromInt(presentation),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
errdefer face.deinit();
|
errdefer face.deinit();
|
||||||
|
@ -143,7 +143,7 @@ pub const FontIndex = packed struct(u8) {
|
|||||||
|
|
||||||
/// Convert to int
|
/// Convert to int
|
||||||
pub fn int(self: FontIndex) u8 {
|
pub fn int(self: FontIndex) u8 {
|
||||||
return @bitCast(u8, self);
|
return @bitCast(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this is a "special" index which doesn't map to
|
/// Returns true if this is a "special" index which doesn't map to
|
||||||
@ -151,7 +151,7 @@ pub const FontIndex = packed struct(u8) {
|
|||||||
/// this font.
|
/// this font.
|
||||||
pub fn special(self: FontIndex) ?Special {
|
pub fn special(self: FontIndex) ?Special {
|
||||||
if (self.idx < Special.start) return null;
|
if (self.idx < Special.start) return null;
|
||||||
return @enumFromInt(Special, self.idx);
|
return @enumFromInt(self.idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
@ -223,7 +223,7 @@ fn indexForCodepointExact(self: Group, cp: u32, style: Style, p: ?Presentation)
|
|||||||
if (deferred.hasCodepoint(cp, p)) {
|
if (deferred.hasCodepoint(cp, p)) {
|
||||||
return FontIndex{
|
return FontIndex{
|
||||||
.style = style,
|
.style = style,
|
||||||
.idx = @intCast(FontIndex.IndexInt, i),
|
.idx = @intCast(i),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,7 +247,7 @@ pub fn presentationFromIndex(self: Group, index: FontIndex) !font.Presentation {
|
|||||||
/// fonts (i.e. box glyphs) do not have a face.
|
/// fonts (i.e. box glyphs) do not have a face.
|
||||||
pub fn faceFromIndex(self: Group, index: FontIndex) !*Face {
|
pub fn faceFromIndex(self: Group, index: FontIndex) !*Face {
|
||||||
if (index.special() != null) return error.SpecialHasNoFace;
|
if (index.special() != null) return error.SpecialHasNoFace;
|
||||||
const deferred = &self.faces.get(index.style).items[@intCast(usize, index.idx)];
|
const deferred = &self.faces.get(index.style).items[@intCast(index.idx)];
|
||||||
try deferred.load(self.lib, self.size);
|
try deferred.load(self.lib, self.size);
|
||||||
return &deferred.face.?;
|
return &deferred.face.?;
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ pub fn renderGlyph(
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
const face = &self.faces.get(index.style).items[@intCast(usize, index.idx)];
|
const face = &self.faces.get(index.style).items[@intCast(index.idx)];
|
||||||
try face.load(self.lib, self.size);
|
try face.load(self.lib, self.size);
|
||||||
return try face.face.?.renderGlyph(alloc, atlas, glyph_index, max_height);
|
return try face.face.?.renderGlyph(alloc, atlas, glyph_index, max_height);
|
||||||
}
|
}
|
||||||
@ -327,15 +327,15 @@ pub const Wasm = struct {
|
|||||||
|
|
||||||
// Set details for our sprite font
|
// Set details for our sprite font
|
||||||
self.sprite = font.sprite.Face{
|
self.sprite = font.sprite.Face{
|
||||||
.width = @intFromFloat(u32, metrics.cell_width),
|
.width = @intFromFloat(metrics.cell_width),
|
||||||
.height = @intFromFloat(u32, metrics.cell_height),
|
.height = @intFromFloat(metrics.cell_height),
|
||||||
.thickness = 2,
|
.thickness = 2,
|
||||||
.underline_position = @intFromFloat(u32, metrics.underline_position),
|
.underline_position = @intFromFloat(metrics.underline_position),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn group_add_face(self: *Group, style: u16, face: *font.DeferredFace) void {
|
export fn group_add_face(self: *Group, style: u16, face: *font.DeferredFace) void {
|
||||||
return self.addFace(alloc, @enumFromInt(Style, style), face.*) catch |err| {
|
return self.addFace(alloc, @enumFromInt(style), face.*) catch |err| {
|
||||||
log.warn("error adding face to group err={}", .{err});
|
log.warn("error adding face to group err={}", .{err});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@ -350,13 +350,13 @@ pub const Wasm = struct {
|
|||||||
|
|
||||||
/// Presentation is negative for doesn't matter.
|
/// Presentation is negative for doesn't matter.
|
||||||
export fn group_index_for_codepoint(self: *Group, cp: u32, style: u16, p: i16) i16 {
|
export fn group_index_for_codepoint(self: *Group, cp: u32, style: u16, p: i16) i16 {
|
||||||
const presentation = if (p < 0) null else @enumFromInt(Presentation, p);
|
const presentation: ?Presentation = if (p < 0) null else @enumFromInt(p);
|
||||||
const idx = self.indexForCodepoint(
|
const idx = self.indexForCodepoint(
|
||||||
cp,
|
cp,
|
||||||
@enumFromInt(Style, style),
|
@enumFromInt(style),
|
||||||
presentation,
|
presentation,
|
||||||
) orelse return -1;
|
) orelse return -1;
|
||||||
return @intCast(i16, @bitCast(u8, idx));
|
return @intCast(@as(u8, @bitCast(idx)));
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn group_render_glyph(
|
export fn group_render_glyph(
|
||||||
@ -379,7 +379,7 @@ pub const Wasm = struct {
|
|||||||
cp: u32,
|
cp: u32,
|
||||||
max_height_: u16,
|
max_height_: u16,
|
||||||
) !*Glyph {
|
) !*Glyph {
|
||||||
const idx = @bitCast(FontIndex, @intCast(u8, idx_));
|
const idx = @as(FontIndex, @bitCast(@as(u8, @intCast(idx_))));
|
||||||
const max_height = if (max_height_ <= 0) null else max_height_;
|
const max_height = if (max_height_ <= 0) null else max_height_;
|
||||||
const glyph = try self.renderGlyph(alloc, atlas, idx, cp, max_height);
|
const glyph = try self.renderGlyph(alloc, atlas, idx, cp, max_height);
|
||||||
|
|
||||||
|
@ -266,14 +266,14 @@ pub const Wasm = struct {
|
|||||||
|
|
||||||
/// Presentation is negative for doesn't matter.
|
/// Presentation is negative for doesn't matter.
|
||||||
export fn group_cache_index_for_codepoint(self: *GroupCache, cp: u32, style: u16, p: i16) i16 {
|
export fn group_cache_index_for_codepoint(self: *GroupCache, cp: u32, style: u16, p: i16) i16 {
|
||||||
const presentation = if (p < 0) null else @enumFromInt(Presentation, p);
|
const presentation: ?Presentation = if (p < 0) null else @enumFromInt(p);
|
||||||
if (self.indexForCodepoint(
|
if (self.indexForCodepoint(
|
||||||
alloc,
|
alloc,
|
||||||
cp,
|
cp,
|
||||||
@enumFromInt(Style, style),
|
@enumFromInt(style),
|
||||||
presentation,
|
presentation,
|
||||||
)) |idx| {
|
)) |idx| {
|
||||||
return @intCast(i16, @bitCast(u8, idx orelse return -1));
|
return @intCast(@as(u8, @bitCast(idx orelse return -1)));
|
||||||
} else |err| {
|
} else |err| {
|
||||||
log.warn("error getting index for codepoint from group cache size err={}", .{err});
|
log.warn("error getting index for codepoint from group cache size err={}", .{err});
|
||||||
return -1;
|
return -1;
|
||||||
@ -298,7 +298,7 @@ pub const Wasm = struct {
|
|||||||
cp: u32,
|
cp: u32,
|
||||||
max_height_: u16,
|
max_height_: u16,
|
||||||
) !*Glyph {
|
) !*Glyph {
|
||||||
const idx = @bitCast(Group.FontIndex, @intCast(u8, idx_));
|
const idx = @as(Group.FontIndex, @bitCast(@as(u8, @intCast(idx_))));
|
||||||
const max_height = if (max_height_ <= 0) null else max_height_;
|
const max_height = if (max_height_ <= 0) null else max_height_;
|
||||||
const glyph = try self.renderGlyph(alloc, idx, cp, max_height);
|
const glyph = try self.renderGlyph(alloc, idx, cp, max_height);
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ pub const Descriptor = struct {
|
|||||||
|
|
||||||
// Set our size attribute if set
|
// Set our size attribute if set
|
||||||
if (self.size > 0) {
|
if (self.size > 0) {
|
||||||
const size32 = @intCast(i32, self.size);
|
const size32 = @as(i32, @intCast(self.size));
|
||||||
const size = try macos.foundation.Number.create(
|
const size = try macos.foundation.Number.create(
|
||||||
.sint32,
|
.sint32,
|
||||||
&size32,
|
&size32,
|
||||||
@ -132,7 +132,7 @@ pub const Descriptor = struct {
|
|||||||
// of the symbolic traits value, and set that in our attributes.
|
// of the symbolic traits value, and set that in our attributes.
|
||||||
const traits_num = try macos.foundation.Number.create(
|
const traits_num = try macos.foundation.Number.create(
|
||||||
.sint32,
|
.sint32,
|
||||||
@ptrCast(*const i32, &traits_cval),
|
@as(*const i32, @ptrCast(&traits_cval)),
|
||||||
);
|
);
|
||||||
defer traits_num.release();
|
defer traits_num.release();
|
||||||
|
|
||||||
@ -149,10 +149,7 @@ pub const Descriptor = struct {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return try macos.text.FontDescriptor.createWithAttributes(@ptrCast(
|
return try macos.text.FontDescriptor.createWithAttributes(@ptrCast(attrs));
|
||||||
*macos.foundation.Dictionary,
|
|
||||||
attrs,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -291,9 +288,7 @@ pub const CoreText = struct {
|
|||||||
// the descriptor removes the charset restriction. This is tested.
|
// the descriptor removes the charset restriction. This is tested.
|
||||||
const attrs = original.copyAttributes();
|
const attrs = original.copyAttributes();
|
||||||
defer attrs.release();
|
defer attrs.release();
|
||||||
break :desc try macos.text.FontDescriptor.createWithAttributes(
|
break :desc try macos.text.FontDescriptor.createWithAttributes(@ptrCast(attrs));
|
||||||
@ptrCast(*macos.foundation.Dictionary, attrs),
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
defer desc.release();
|
defer desc.release();
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ pub const Face = struct {
|
|||||||
/// adjusted to the final size for final load.
|
/// adjusted to the final size for final load.
|
||||||
pub fn initFontCopy(base: *macos.text.Font, size: font.face.DesiredSize) !Face {
|
pub fn initFontCopy(base: *macos.text.Font, size: font.face.DesiredSize) !Face {
|
||||||
// Create a copy
|
// Create a copy
|
||||||
const ct_font = try base.copyWithAttributes(@floatFromInt(f32, size.points), null);
|
const ct_font = try base.copyWithAttributes(@floatFromInt(size.points), null);
|
||||||
errdefer ct_font.release();
|
errdefer ct_font.release();
|
||||||
|
|
||||||
var hb_font = try harfbuzz.coretext.createFont(ct_font);
|
var hb_font = try harfbuzz.coretext.createFont(ct_font);
|
||||||
@ -90,7 +90,7 @@ pub const Face = struct {
|
|||||||
// to decode down into exactly one glyph ID.
|
// to decode down into exactly one glyph ID.
|
||||||
if (pair) assert(glyphs[1] == 0);
|
if (pair) assert(glyphs[1] == 0);
|
||||||
|
|
||||||
return @intCast(u32, glyphs[0]);
|
return @intCast(glyphs[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render a glyph using the glyph index. The rendered glyph is stored in the
|
/// Render a glyph using the glyph index. The rendered glyph is stored in the
|
||||||
@ -109,14 +109,14 @@ pub const Face = struct {
|
|||||||
|
|
||||||
_ = max_height;
|
_ = max_height;
|
||||||
|
|
||||||
var glyphs = [_]macos.graphics.Glyph{@intCast(macos.graphics.Glyph, glyph_index)};
|
var glyphs = [_]macos.graphics.Glyph{@intCast(glyph_index)};
|
||||||
|
|
||||||
// Get the bounding rect for this glyph to determine the width/height
|
// Get the bounding rect for this glyph to determine the width/height
|
||||||
// of the bitmap. We use the rounded up width/height of the bounding rect.
|
// of the bitmap. We use the rounded up width/height of the bounding rect.
|
||||||
var bounding: [1]macos.graphics.Rect = undefined;
|
var bounding: [1]macos.graphics.Rect = undefined;
|
||||||
_ = self.font.getBoundingRectForGlyphs(.horizontal, &glyphs, &bounding);
|
_ = self.font.getBoundingRectForGlyphs(.horizontal, &glyphs, &bounding);
|
||||||
const glyph_width = @intFromFloat(u32, @ceil(bounding[0].size.width));
|
const glyph_width = @as(u32, @intFromFloat(@ceil(bounding[0].size.width)));
|
||||||
const glyph_height = @intFromFloat(u32, @ceil(bounding[0].size.height));
|
const glyph_height = @as(u32, @intFromFloat(@ceil(bounding[0].size.height)));
|
||||||
|
|
||||||
// Width and height. Note the padding doubling is because we want
|
// Width and height. Note the padding doubling is because we want
|
||||||
// the padding on both sides (top/bottom, left/right).
|
// the padding on both sides (top/bottom, left/right).
|
||||||
@ -195,17 +195,17 @@ pub const Face = struct {
|
|||||||
// by default below the line. We have to add height (glyph height)
|
// by default below the line. We have to add height (glyph height)
|
||||||
// so that we shift the glyph UP to be on the line, then we add our
|
// so that we shift the glyph UP to be on the line, then we add our
|
||||||
// baseline offset to move the glyph further UP to match the baseline.
|
// baseline offset to move the glyph further UP to match the baseline.
|
||||||
break :offset_y @intCast(i32, height) + @intFromFloat(i32, @ceil(baseline_with_offset));
|
break :offset_y @as(i32, @intCast(height)) + @as(i32, @intFromFloat(@ceil(baseline_with_offset)));
|
||||||
};
|
};
|
||||||
|
|
||||||
return font.Glyph{
|
return font.Glyph{
|
||||||
.width = glyph_width,
|
.width = glyph_width,
|
||||||
.height = glyph_height,
|
.height = glyph_height,
|
||||||
.offset_x = @intFromFloat(i32, @ceil(bounding[0].origin.x)),
|
.offset_x = @intFromFloat(@ceil(bounding[0].origin.x)),
|
||||||
.offset_y = offset_y,
|
.offset_y = offset_y,
|
||||||
.atlas_x = region.x + padding,
|
.atlas_x = region.x + padding,
|
||||||
.atlas_y = region.y + padding,
|
.atlas_y = region.y + padding,
|
||||||
.advance_x = @floatCast(f32, advances[0].width),
|
.advance_x = @floatCast(advances[0].width),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ pub const Face = struct {
|
|||||||
max = @max(advances[i].width, max);
|
max = @max(advances[i].width, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
break :cell_width @floatCast(f32, max);
|
break :cell_width @floatCast(max);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calculate the cell height by using CoreText's layout engine
|
// Calculate the cell height by using CoreText's layout engine
|
||||||
@ -269,9 +269,7 @@ pub const Face = struct {
|
|||||||
|
|
||||||
// Create our framesetter with our string. This is used to
|
// Create our framesetter with our string. This is used to
|
||||||
// emit "frames" for the layout.
|
// emit "frames" for the layout.
|
||||||
const fs = try macos.text.Framesetter.createWithAttributedString(
|
const fs = try macos.text.Framesetter.createWithAttributedString(@ptrCast(string));
|
||||||
@ptrCast(*macos.foundation.AttributedString, string),
|
|
||||||
);
|
|
||||||
defer fs.release();
|
defer fs.release();
|
||||||
|
|
||||||
// Create a rectangle to fit all of this and create a frame of it.
|
// Create a rectangle to fit all of this and create a frame of it.
|
||||||
@ -280,7 +278,7 @@ pub const Face = struct {
|
|||||||
defer path.release();
|
defer path.release();
|
||||||
const frame = try fs.createFrame(
|
const frame = try fs.createFrame(
|
||||||
macos.foundation.Range.init(0, 0),
|
macos.foundation.Range.init(0, 0),
|
||||||
@ptrCast(*macos.graphics.Path, path),
|
@ptrCast(path),
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
defer frame.release();
|
defer frame.release();
|
||||||
@ -305,8 +303,8 @@ pub const Face = struct {
|
|||||||
//std.log.warn("ascent={} descent={} leading={}", .{ ascent, descent, leading });
|
//std.log.warn("ascent={} descent={} leading={}", .{ ascent, descent, leading });
|
||||||
|
|
||||||
break :metrics .{
|
break :metrics .{
|
||||||
.height = @floatCast(f32, points[0].y - points[1].y),
|
.height = @floatCast(points[0].y - points[1].y),
|
||||||
.ascent = @floatCast(f32, ascent),
|
.ascent = @floatCast(ascent),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -314,8 +312,8 @@ pub const Face = struct {
|
|||||||
const cell_height = layout_metrics.height;
|
const cell_height = layout_metrics.height;
|
||||||
const cell_baseline = layout_metrics.ascent;
|
const cell_baseline = layout_metrics.ascent;
|
||||||
const underline_position = @ceil(layout_metrics.ascent -
|
const underline_position = @ceil(layout_metrics.ascent -
|
||||||
@floatCast(f32, ct_font.getUnderlinePosition()));
|
@as(f32, @floatCast(ct_font.getUnderlinePosition())));
|
||||||
const underline_thickness = @ceil(@floatCast(f32, ct_font.getUnderlineThickness()));
|
const underline_thickness = @ceil(@as(f32, @floatCast(ct_font.getUnderlineThickness())));
|
||||||
const strikethrough_position = cell_baseline * 0.6;
|
const strikethrough_position = cell_baseline * 0.6;
|
||||||
const strikethrough_thickness = underline_thickness;
|
const strikethrough_thickness = underline_thickness;
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ pub const Face = struct {
|
|||||||
// to what the user requested. Otherwise, we can choose an arbitrary
|
// to what the user requested. Otherwise, we can choose an arbitrary
|
||||||
// pixel size.
|
// pixel size.
|
||||||
if (face.isScalable()) {
|
if (face.isScalable()) {
|
||||||
const size_26dot6 = @intCast(i32, size.points << 6); // mult by 64
|
const size_26dot6 = @as(i32, @intCast(size.points << 6)); // mult by 64
|
||||||
try face.setCharSize(0, size_26dot6, size.xdpi, size.ydpi);
|
try face.setCharSize(0, size_26dot6, size.xdpi, size.ydpi);
|
||||||
} else try selectSizeNearest(face, size.pixels());
|
} else try selectSizeNearest(face, size.pixels());
|
||||||
}
|
}
|
||||||
@ -94,8 +94,8 @@ pub const Face = struct {
|
|||||||
var best_i: i32 = 0;
|
var best_i: i32 = 0;
|
||||||
var best_diff: i32 = 0;
|
var best_diff: i32 = 0;
|
||||||
while (i < face.handle.*.num_fixed_sizes) : (i += 1) {
|
while (i < face.handle.*.num_fixed_sizes) : (i += 1) {
|
||||||
const width = face.handle.*.available_sizes[@intCast(usize, i)].width;
|
const width = face.handle.*.available_sizes[@intCast(i)].width;
|
||||||
const diff = @intCast(i32, size) - @intCast(i32, width);
|
const diff = @as(i32, @intCast(size)) - @as(i32, @intCast(width));
|
||||||
if (i == 0 or diff < best_diff) {
|
if (i == 0 or diff < best_diff) {
|
||||||
best_diff = diff;
|
best_diff = diff;
|
||||||
best_i = i;
|
best_i = i;
|
||||||
@ -175,7 +175,7 @@ pub const Face = struct {
|
|||||||
break :blk try func(alloc, bitmap_ft);
|
break :blk try func(alloc, bitmap_ft);
|
||||||
} else null;
|
} else null;
|
||||||
defer if (bitmap_converted) |bm| {
|
defer if (bitmap_converted) |bm| {
|
||||||
const len = @intCast(usize, bm.pitch) * @intCast(usize, bm.rows);
|
const len = @as(usize, @intCast(bm.pitch)) * @as(usize, @intCast(bm.rows));
|
||||||
alloc.free(bm.buffer[0..len]);
|
alloc.free(bm.buffer[0..len]);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -195,23 +195,23 @@ pub const Face = struct {
|
|||||||
var result = bm;
|
var result = bm;
|
||||||
result.rows = max;
|
result.rows = max;
|
||||||
result.width = (result.rows * bm.width) / bm.rows;
|
result.width = (result.rows * bm.width) / bm.rows;
|
||||||
result.pitch = @intCast(c_int, result.width) * atlas.format.depth();
|
result.pitch = @as(c_int, @intCast(result.width)) * atlas.format.depth();
|
||||||
|
|
||||||
const buf = try alloc.alloc(
|
const buf = try alloc.alloc(
|
||||||
u8,
|
u8,
|
||||||
@intCast(usize, result.pitch) * @intCast(usize, result.rows),
|
@as(usize, @intCast(result.pitch)) * @as(usize, @intCast(result.rows)),
|
||||||
);
|
);
|
||||||
result.buffer = buf.ptr;
|
result.buffer = buf.ptr;
|
||||||
errdefer alloc.free(buf);
|
errdefer alloc.free(buf);
|
||||||
|
|
||||||
if (resize.stbir_resize_uint8(
|
if (resize.stbir_resize_uint8(
|
||||||
bm.buffer,
|
bm.buffer,
|
||||||
@intCast(c_int, bm.width),
|
@intCast(bm.width),
|
||||||
@intCast(c_int, bm.rows),
|
@intCast(bm.rows),
|
||||||
bm.pitch,
|
bm.pitch,
|
||||||
result.buffer,
|
result.buffer,
|
||||||
@intCast(c_int, result.width),
|
@intCast(result.width),
|
||||||
@intCast(c_int, result.rows),
|
@intCast(result.rows),
|
||||||
result.pitch,
|
result.pitch,
|
||||||
atlas.format.depth(),
|
atlas.format.depth(),
|
||||||
) == 0) {
|
) == 0) {
|
||||||
@ -223,7 +223,7 @@ pub const Face = struct {
|
|||||||
break :resized result;
|
break :resized result;
|
||||||
};
|
};
|
||||||
defer if (bitmap_resized) |bm| {
|
defer if (bitmap_resized) |bm| {
|
||||||
const len = @intCast(usize, bm.pitch) * @intCast(usize, bm.rows);
|
const len = @as(usize, @intCast(bm.pitch)) * @as(usize, @intCast(bm.rows));
|
||||||
alloc.free(bm.buffer[0..len]);
|
alloc.free(bm.buffer[0..len]);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -242,14 +242,14 @@ pub const Face = struct {
|
|||||||
const glyph_metrics = if (bitmap_resized) |bm| metrics: {
|
const glyph_metrics = if (bitmap_resized) |bm| metrics: {
|
||||||
// Our ratio for the resize
|
// Our ratio for the resize
|
||||||
const ratio = ratio: {
|
const ratio = ratio: {
|
||||||
const new = @floatFromInt(f64, bm.rows);
|
const new: f64 = @floatFromInt(bm.rows);
|
||||||
const old = @floatFromInt(f64, bitmap_original.rows);
|
const old: f64 = @floatFromInt(bitmap_original.rows);
|
||||||
break :ratio new / old;
|
break :ratio new / old;
|
||||||
};
|
};
|
||||||
|
|
||||||
var copy = glyph.*;
|
var copy = glyph.*;
|
||||||
copy.bitmap_top = @intFromFloat(c_int, @round(@floatFromInt(f64, copy.bitmap_top) * ratio));
|
copy.bitmap_top = @as(c_int, @intFromFloat(@round(@as(f64, @floatFromInt(copy.bitmap_top)) * ratio)));
|
||||||
copy.bitmap_left = @intFromFloat(c_int, @round(@floatFromInt(f64, copy.bitmap_left) * ratio));
|
copy.bitmap_left = @as(c_int, @intFromFloat(@round(@as(f64, @floatFromInt(copy.bitmap_left)) * ratio)));
|
||||||
break :metrics copy;
|
break :metrics copy;
|
||||||
} else glyph.*;
|
} else glyph.*;
|
||||||
|
|
||||||
@ -296,7 +296,7 @@ pub const Face = struct {
|
|||||||
while (i < bitmap.rows) : (i += 1) {
|
while (i < bitmap.rows) : (i += 1) {
|
||||||
fastmem.copy(u8, dst_ptr, src_ptr[0 .. bitmap.width * depth]);
|
fastmem.copy(u8, dst_ptr, src_ptr[0 .. bitmap.width * depth]);
|
||||||
dst_ptr = dst_ptr[tgt_w * depth ..];
|
dst_ptr = dst_ptr[tgt_w * depth ..];
|
||||||
src_ptr += @intCast(usize, bitmap.pitch);
|
src_ptr += @as(usize, @intCast(bitmap.pitch));
|
||||||
}
|
}
|
||||||
break :buffer temp;
|
break :buffer temp;
|
||||||
} else bitmap.buffer[0..(tgt_w * tgt_h * depth)];
|
} else bitmap.buffer[0..(tgt_w * tgt_h * depth)];
|
||||||
@ -308,7 +308,7 @@ pub const Face = struct {
|
|||||||
atlas.set(region, buffer);
|
atlas.set(region, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
const offset_y = offset_y: {
|
const offset_y: c_int = offset_y: {
|
||||||
// For non-scalable colorized fonts, we assume they are pictographic
|
// For non-scalable colorized fonts, we assume they are pictographic
|
||||||
// and just center the glyph. So far this has only applied to emoji
|
// and just center the glyph. So far this has only applied to emoji
|
||||||
// fonts. Emoji fonts don't always report a correct ascender/descender
|
// fonts. Emoji fonts don't always report a correct ascender/descender
|
||||||
@ -318,14 +318,14 @@ pub const Face = struct {
|
|||||||
// NOTE(mitchellh): I don't know if this is right, this doesn't
|
// NOTE(mitchellh): I don't know if this is right, this doesn't
|
||||||
// _feel_ right, but it makes all my limited test cases work.
|
// _feel_ right, but it makes all my limited test cases work.
|
||||||
if (self.face.hasColor() and !self.face.isScalable()) {
|
if (self.face.hasColor() and !self.face.isScalable()) {
|
||||||
break :offset_y @intCast(c_int, tgt_h);
|
break :offset_y @intCast(tgt_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Y offset is the offset of the top of our bitmap PLUS our
|
// The Y offset is the offset of the top of our bitmap PLUS our
|
||||||
// baseline calculation. The baseline calculation is so that everything
|
// baseline calculation. The baseline calculation is so that everything
|
||||||
// is properly centered when we render it out into a monospace grid.
|
// is properly centered when we render it out into a monospace grid.
|
||||||
// Note: we add here because our X/Y is actually reversed, adding goes UP.
|
// Note: we add here because our X/Y is actually reversed, adding goes UP.
|
||||||
break :offset_y glyph_metrics.bitmap_top + @intFromFloat(c_int, self.metrics.cell_baseline);
|
break :offset_y glyph_metrics.bitmap_top + @as(c_int, @intFromFloat(self.metrics.cell_baseline));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Store glyph metadata
|
// Store glyph metadata
|
||||||
@ -343,15 +343,15 @@ pub const Face = struct {
|
|||||||
/// Convert 16.6 pixel format to pixels based on the scale factor of the
|
/// Convert 16.6 pixel format to pixels based on the scale factor of the
|
||||||
/// current font size.
|
/// current font size.
|
||||||
fn unitsToPxY(self: Face, units: i32) i32 {
|
fn unitsToPxY(self: Face, units: i32) i32 {
|
||||||
return @intCast(i32, freetype.mulFix(
|
return @intCast(freetype.mulFix(
|
||||||
units,
|
units,
|
||||||
@intCast(i32, self.face.handle.*.size.*.metrics.y_scale),
|
@intCast(self.face.handle.*.size.*.metrics.y_scale),
|
||||||
) >> 6);
|
) >> 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert 26.6 pixel format to f32
|
/// Convert 26.6 pixel format to f32
|
||||||
fn f26dot6ToFloat(v: freetype.c.FT_F26Dot6) f32 {
|
fn f26dot6ToFloat(v: freetype.c.FT_F26Dot6) f32 {
|
||||||
return @floatFromInt(f32, v >> 6);
|
return @floatFromInt(v >> 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate the metrics associated with a face. This is not public because
|
/// Calculate the metrics associated with a face. This is not public because
|
||||||
@ -398,8 +398,8 @@ pub const Face = struct {
|
|||||||
if (face.getCharIndex('_')) |glyph_index| {
|
if (face.getCharIndex('_')) |glyph_index| {
|
||||||
if (face.loadGlyph(glyph_index, .{ .render = true })) {
|
if (face.loadGlyph(glyph_index, .{ .render = true })) {
|
||||||
var res: f32 = f26dot6ToFloat(size_metrics.ascender);
|
var res: f32 = f26dot6ToFloat(size_metrics.ascender);
|
||||||
res -= @floatFromInt(f32, face.handle.*.glyph.*.bitmap_top);
|
res -= @floatFromInt(face.handle.*.glyph.*.bitmap_top);
|
||||||
res += @floatFromInt(f32, face.handle.*.glyph.*.bitmap.rows);
|
res += @floatFromInt(face.handle.*.glyph.*.bitmap.rows);
|
||||||
break :underscore res;
|
break :underscore res;
|
||||||
} else |_| {
|
} else |_| {
|
||||||
// Ignore the error since we just fall back below
|
// Ignore the error since we just fall back below
|
||||||
@ -422,19 +422,19 @@ pub const Face = struct {
|
|||||||
|
|
||||||
// The underline position. This is a value from the top where the
|
// The underline position. This is a value from the top where the
|
||||||
// underline should go.
|
// underline should go.
|
||||||
const underline_position = underline_pos: {
|
const underline_position: f32 = underline_pos: {
|
||||||
// The ascender is already scaled for scalable fonts, but the
|
// The ascender is already scaled for scalable fonts, but the
|
||||||
// underline position is not.
|
// underline position is not.
|
||||||
const ascender_px = @intCast(i32, size_metrics.ascender) >> 6;
|
const ascender_px = @as(i32, @intCast(size_metrics.ascender)) >> 6;
|
||||||
const declared_px = freetype.mulFix(
|
const declared_px = freetype.mulFix(
|
||||||
face.handle.*.underline_position,
|
face.handle.*.underline_position,
|
||||||
@intCast(i32, face.handle.*.size.*.metrics.y_scale),
|
@intCast(face.handle.*.size.*.metrics.y_scale),
|
||||||
) >> 6;
|
) >> 6;
|
||||||
|
|
||||||
// We use the declared underline position if its available
|
// We use the declared underline position if its available
|
||||||
const declared = ascender_px - declared_px;
|
const declared = ascender_px - declared_px;
|
||||||
if (declared > 0)
|
if (declared > 0)
|
||||||
break :underline_pos @floatFromInt(f32, declared);
|
break :underline_pos @floatFromInt(declared);
|
||||||
|
|
||||||
// If we have no declared underline position, we go slightly under the
|
// If we have no declared underline position, we go slightly under the
|
||||||
// cell height (mainly: non-scalable fonts, i.e. emoji)
|
// cell height (mainly: non-scalable fonts, i.e. emoji)
|
||||||
@ -453,13 +453,13 @@ pub const Face = struct {
|
|||||||
} = if (face.getSfntTable(.os2)) |os2| .{
|
} = if (face.getSfntTable(.os2)) |os2| .{
|
||||||
.pos = pos: {
|
.pos = pos: {
|
||||||
// Ascender is scaled, strikeout pos is not
|
// Ascender is scaled, strikeout pos is not
|
||||||
const ascender_px = @intCast(i32, size_metrics.ascender) >> 6;
|
const ascender_px = @as(i32, @intCast(size_metrics.ascender)) >> 6;
|
||||||
const declared_px = freetype.mulFix(
|
const declared_px = freetype.mulFix(
|
||||||
os2.yStrikeoutPosition,
|
os2.yStrikeoutPosition,
|
||||||
@intCast(i32, face.handle.*.size.*.metrics.y_scale),
|
@as(i32, @intCast(face.handle.*.size.*.metrics.y_scale)),
|
||||||
) >> 6;
|
) >> 6;
|
||||||
|
|
||||||
break :pos @floatFromInt(f32, ascender_px - declared_px);
|
break :pos @floatFromInt(ascender_px - declared_px);
|
||||||
},
|
},
|
||||||
.thickness = @max(@as(f32, 1), fontUnitsToPxY(face, os2.yStrikeoutSize)),
|
.thickness = @max(@as(f32, 1), fontUnitsToPxY(face, os2.yStrikeoutSize)),
|
||||||
} else .{
|
} else .{
|
||||||
@ -490,8 +490,8 @@ pub const Face = struct {
|
|||||||
|
|
||||||
/// Convert freetype "font units" to pixels using the Y scale.
|
/// Convert freetype "font units" to pixels using the Y scale.
|
||||||
fn fontUnitsToPxY(face: freetype.Face, x: i32) f32 {
|
fn fontUnitsToPxY(face: freetype.Face, x: i32) f32 {
|
||||||
const mul = freetype.mulFix(x, @intCast(i32, face.handle.*.size.*.metrics.y_scale));
|
const mul = freetype.mulFix(x, @as(i32, @intCast(face.handle.*.size.*.metrics.y_scale)));
|
||||||
const div = @floatFromInt(f32, mul) / 64;
|
const div = @as(f32, @floatFromInt(mul)) / 64;
|
||||||
return @ceil(div);
|
return @ceil(div);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -55,20 +55,20 @@ pub fn monoToGreyscale(alloc: Allocator, bm: Bitmap) Allocator.Error!Bitmap {
|
|||||||
while (j > 0) : (j -= 1) {
|
while (j > 0) : (j -= 1) {
|
||||||
var bit: u4 = 8;
|
var bit: u4 = 8;
|
||||||
while (bit > 0) : (bit -= 1) {
|
while (bit > 0) : (bit -= 1) {
|
||||||
const mask = @as(u8, 1) << @intCast(u3, bit - 1);
|
const mask = @as(u8, 1) << @as(u3, @intCast(bit - 1));
|
||||||
const bitval: u8 = if (bm.buffer[source_i + (j - 1)] & mask > 0) 0xFF else 0;
|
const bitval: u8 = if (bm.buffer[source_i + (j - 1)] & mask > 0) 0xFF else 0;
|
||||||
buf[target_i] = bitval;
|
buf[target_i] = bitval;
|
||||||
target_i += 1;
|
target_i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
source_i += @intCast(usize, bm.pitch);
|
source_i += @intCast(bm.pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
var copy = bm;
|
var copy = bm;
|
||||||
copy.buffer = buf.ptr;
|
copy.buffer = buf.ptr;
|
||||||
copy.pixel_mode = freetype.c.FT_PIXEL_MODE_GRAY;
|
copy.pixel_mode = freetype.c.FT_PIXEL_MODE_GRAY;
|
||||||
copy.pitch = @intCast(c_int, bm.width);
|
copy.pitch = @as(c_int, @intCast(bm.width));
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ test "mono to greyscale" {
|
|||||||
.rows = 1,
|
.rows = 1,
|
||||||
.width = 8,
|
.width = 8,
|
||||||
.pitch = 1,
|
.pitch = 1,
|
||||||
.buffer = @ptrCast([*c]u8, &mono_data),
|
.buffer = @ptrCast(&mono_data),
|
||||||
.num_grays = 0,
|
.num_grays = 0,
|
||||||
.pixel_mode = freetype.c.FT_PIXEL_MODE_MONO,
|
.pixel_mode = freetype.c.FT_PIXEL_MODE_MONO,
|
||||||
.palette_mode = 0,
|
.palette_mode = 0,
|
||||||
|
@ -352,7 +352,7 @@ pub const Face = struct {
|
|||||||
// If we are a normal glyph then we are a single codepoint and
|
// If we are a normal glyph then we are a single codepoint and
|
||||||
// we just UTF8 encode it as-is.
|
// we just UTF8 encode it as-is.
|
||||||
if (glyph_index < grapheme_start) {
|
if (glyph_index < grapheme_start) {
|
||||||
const utf8_len = try std.unicode.utf8Encode(@intCast(u21, glyph_index), &utf8);
|
const utf8_len = try std.unicode.utf8Encode(@intCast(glyph_index), &utf8);
|
||||||
break :glyph_str js.string(utf8[0..utf8_len]);
|
break :glyph_str js.string(utf8[0..utf8_len]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,14 +370,14 @@ pub const Face = struct {
|
|||||||
// Get the width and height of the render
|
// Get the width and height of the render
|
||||||
const metrics = try measure_ctx.call(js.Object, "measureText", .{glyph_str});
|
const metrics = try measure_ctx.call(js.Object, "measureText", .{glyph_str});
|
||||||
errdefer metrics.deinit();
|
errdefer metrics.deinit();
|
||||||
const width: u32 = @intFromFloat(u32, @ceil(width: {
|
const width: u32 = @as(u32, @intFromFloat(@ceil(width: {
|
||||||
// We prefer the bounding box since it is tighter but certain
|
// We prefer the bounding box since it is tighter but certain
|
||||||
// text such as emoji do not have a bounding box set so we use
|
// text such as emoji do not have a bounding box set so we use
|
||||||
// the full run width instead.
|
// the full run width instead.
|
||||||
const bounding_right = try metrics.get(f32, "actualBoundingBoxRight");
|
const bounding_right = try metrics.get(f32, "actualBoundingBoxRight");
|
||||||
if (bounding_right > 0) break :width bounding_right;
|
if (bounding_right > 0) break :width bounding_right;
|
||||||
break :width try metrics.get(f32, "width");
|
break :width try metrics.get(f32, "width");
|
||||||
})) + 1;
|
}))) + 1;
|
||||||
|
|
||||||
const left = try metrics.get(f32, "actualBoundingBoxLeft");
|
const left = try metrics.get(f32, "actualBoundingBoxLeft");
|
||||||
const asc = try metrics.get(f32, "actualBoundingBoxAscent");
|
const asc = try metrics.get(f32, "actualBoundingBoxAscent");
|
||||||
@ -389,7 +389,7 @@ pub const Face = struct {
|
|||||||
const broken_bbox = asc + desc < 0.001;
|
const broken_bbox = asc + desc < 0.001;
|
||||||
|
|
||||||
// Height is our ascender + descender for this char
|
// Height is our ascender + descender for this char
|
||||||
const height = if (!broken_bbox) @intFromFloat(u32, @ceil(asc + desc)) + 1 else width;
|
const height = if (!broken_bbox) @as(u32, @intFromFloat(@ceil(asc + desc))) + 1 else width;
|
||||||
|
|
||||||
// Note: width and height both get "+ 1" added to them above. This
|
// Note: width and height both get "+ 1" added to them above. This
|
||||||
// is important so that there is a 1px border around the glyph to avoid
|
// is important so that there is a 1px border around the glyph to avoid
|
||||||
@ -424,8 +424,8 @@ pub const Face = struct {
|
|||||||
// Draw background
|
// Draw background
|
||||||
try ctx.set("fillStyle", js.string("transparent"));
|
try ctx.set("fillStyle", js.string("transparent"));
|
||||||
try ctx.call(void, "fillRect", .{
|
try ctx.call(void, "fillRect", .{
|
||||||
@as(u32, 0),
|
0,
|
||||||
@as(u32, 0),
|
0,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
});
|
});
|
||||||
@ -435,7 +435,7 @@ pub const Face = struct {
|
|||||||
try ctx.call(void, "fillText", .{
|
try ctx.call(void, "fillText", .{
|
||||||
glyph_str,
|
glyph_str,
|
||||||
left + 1,
|
left + 1,
|
||||||
if (!broken_bbox) asc + 1 else @floatFromInt(f32, height),
|
if (!broken_bbox) asc + 1 else @as(f32, @floatFromInt(height)),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Read the image data and get it into a []u8 on our side
|
// Read the image data and get it into a []u8 on our side
|
||||||
@ -449,7 +449,7 @@ pub const Face = struct {
|
|||||||
|
|
||||||
// Allocate our local memory to copy the data to.
|
// Allocate our local memory to copy the data to.
|
||||||
const len = try src_array.get(u32, "length");
|
const len = try src_array.get(u32, "length");
|
||||||
var bitmap = try alloc.alloc(u8, @intCast(usize, len));
|
var bitmap = try alloc.alloc(u8, @intCast(len));
|
||||||
errdefer alloc.free(bitmap);
|
errdefer alloc.free(bitmap);
|
||||||
|
|
||||||
// Create our target Uint8Array that we can use to copy from src.
|
// Create our target Uint8Array that we can use to copy from src.
|
||||||
@ -501,7 +501,7 @@ pub const Wasm = struct {
|
|||||||
alloc,
|
alloc,
|
||||||
ptr[0..len],
|
ptr[0..len],
|
||||||
.{ .points = pts },
|
.{ .points = pts },
|
||||||
@enumFromInt(font.Presentation, presentation),
|
@enumFromInt(presentation),
|
||||||
);
|
);
|
||||||
errdefer face.deinit();
|
errdefer face.deinit();
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ pub const Shaper = struct {
|
|||||||
|
|
||||||
for (info, 0..) |v, i| {
|
for (info, 0..) |v, i| {
|
||||||
self.cell_buf[i] = .{
|
self.cell_buf[i] = .{
|
||||||
.x = @intCast(u16, v.cluster),
|
.x = @intCast(v.cluster),
|
||||||
.glyph_index = v.codepoint,
|
.glyph_index = v.codepoint,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ pub const RunIterator = struct {
|
|||||||
if (font_idx.int() != current_font.int()) break;
|
if (font_idx.int() != current_font.int()) break;
|
||||||
|
|
||||||
// Continue with our run
|
// Continue with our run
|
||||||
try self.hooks.addCodepoint(cell.char, @intCast(u32, cluster));
|
try self.hooks.addCodepoint(cell.char, @intCast(cluster));
|
||||||
|
|
||||||
// If this cell is part of a grapheme cluster, add all the grapheme
|
// If this cell is part of a grapheme cluster, add all the grapheme
|
||||||
// data points.
|
// data points.
|
||||||
@ -126,7 +126,7 @@ pub const RunIterator = struct {
|
|||||||
var it = self.row.codepointIterator(j);
|
var it = self.row.codepointIterator(j);
|
||||||
while (it.next()) |cp| {
|
while (it.next()) |cp| {
|
||||||
if (cp == 0xFE0E or cp == 0xFE0F) continue;
|
if (cp == 0xFE0E or cp == 0xFE0F) continue;
|
||||||
try self.hooks.addCodepoint(cp, @intCast(u32, cluster));
|
try self.hooks.addCodepoint(cp, @intCast(cluster));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,8 +138,8 @@ pub const RunIterator = struct {
|
|||||||
defer self.i = j;
|
defer self.i = j;
|
||||||
|
|
||||||
return TextRun{
|
return TextRun{
|
||||||
.offset = @intCast(u16, self.i),
|
.offset = @intCast(self.i),
|
||||||
.cells = @intCast(u16, j - self.i),
|
.cells = @intCast(j - self.i),
|
||||||
.group = self.group,
|
.group = self.group,
|
||||||
.font_index = current_font,
|
.font_index = current_font,
|
||||||
};
|
};
|
||||||
|
@ -92,7 +92,7 @@ pub const Shaper = struct {
|
|||||||
// we can't have any more information to do anything else.
|
// we can't have any more information to do anything else.
|
||||||
1 => {
|
1 => {
|
||||||
self.cell_buf[0] = .{
|
self.cell_buf[0] = .{
|
||||||
.x = @intCast(u16, clusters[0]),
|
.x = @intCast(clusters[0]),
|
||||||
.glyph_index = codepoints[0],
|
.glyph_index = codepoints[0],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ pub const Shaper = struct {
|
|||||||
// This means we can render things like skin tone emoji but
|
// This means we can render things like skin tone emoji but
|
||||||
// we can't render things like single glyph "=>".
|
// we can't render things like single glyph "=>".
|
||||||
var break_state: i32 = 0;
|
var break_state: i32 = 0;
|
||||||
var cp1 = @intCast(u21, codepoints[0]);
|
var cp1: u21 = @intCast(codepoints[0]);
|
||||||
|
|
||||||
var start: usize = 0;
|
var start: usize = 0;
|
||||||
var i: usize = 1;
|
var i: usize = 1;
|
||||||
@ -121,7 +121,7 @@ pub const Shaper = struct {
|
|||||||
// break. This isn't strictly true but its how terminals
|
// break. This isn't strictly true but its how terminals
|
||||||
// work today.
|
// work today.
|
||||||
const grapheme_break = i == codepoints.len or blk: {
|
const grapheme_break = i == codepoints.len or blk: {
|
||||||
const cp2 = @intCast(u21, codepoints[i]);
|
const cp2: u21 = @intCast(codepoints[i]);
|
||||||
defer cp1 = cp2;
|
defer cp1 = cp2;
|
||||||
|
|
||||||
break :blk utf8proc.graphemeBreakStateful(
|
break :blk utf8proc.graphemeBreakStateful(
|
||||||
@ -144,7 +144,7 @@ pub const Shaper = struct {
|
|||||||
// If we have only a single codepoint then just render it
|
// If we have only a single codepoint then just render it
|
||||||
// as-is.
|
// as-is.
|
||||||
1 => self.cell_buf[cur] = .{
|
1 => self.cell_buf[cur] = .{
|
||||||
.x = @intCast(u16, clusters[start]),
|
.x = @intCast(clusters[start]),
|
||||||
.glyph_index = codepoints[start],
|
.glyph_index = codepoints[start],
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ pub const Shaper = struct {
|
|||||||
var acc: usize = 0;
|
var acc: usize = 0;
|
||||||
for (cluster_points) |cp| {
|
for (cluster_points) |cp| {
|
||||||
acc += try std.unicode.utf8CodepointSequenceLength(
|
acc += try std.unicode.utf8CodepointSequenceLength(
|
||||||
@intCast(u21, cp),
|
@intCast(cp),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ pub const Shaper = struct {
|
|||||||
var buf_i: usize = 0;
|
var buf_i: usize = 0;
|
||||||
for (cluster_points) |cp| {
|
for (cluster_points) |cp| {
|
||||||
buf_i += try std.unicode.utf8Encode(
|
buf_i += try std.unicode.utf8Encode(
|
||||||
@intCast(u21, cp),
|
@intCast(cp),
|
||||||
buf[buf_i..],
|
buf[buf_i..],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ pub const Shaper = struct {
|
|||||||
const index = try face.graphemeGlyphIndex(cluster);
|
const index = try face.graphemeGlyphIndex(cluster);
|
||||||
|
|
||||||
self.cell_buf[cur] = .{
|
self.cell_buf[cur] = .{
|
||||||
.x = @intCast(u16, clusters[start]),
|
.x = @intCast(clusters[start]),
|
||||||
.glyph_index = index,
|
.glyph_index = index,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -66,7 +66,7 @@ pub fn renderGlyph(
|
|||||||
// Our coordinates start at the BOTTOM for our renderers so we have to
|
// Our coordinates start at the BOTTOM for our renderers so we have to
|
||||||
// specify an offset of the full height because we rendered a full size
|
// specify an offset of the full height because we rendered a full size
|
||||||
// cell.
|
// cell.
|
||||||
const offset_y = @intCast(i32, self.height);
|
const offset_y = @as(i32, @intCast(self.height));
|
||||||
|
|
||||||
return font.Glyph{
|
return font.Glyph{
|
||||||
.width = self.width,
|
.width = self.width,
|
||||||
@ -75,7 +75,7 @@ pub fn renderGlyph(
|
|||||||
.offset_y = offset_y,
|
.offset_y = offset_y,
|
||||||
.atlas_x = region.x,
|
.atlas_x = region.x,
|
||||||
.atlas_y = region.y,
|
.atlas_y = region.y,
|
||||||
.advance_x = @floatFromInt(f32, self.width),
|
.advance_x = @floatFromInt(self.width),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1065,27 +1065,27 @@ fn draw_light_diagonal_upper_right_to_lower_left(self: Box, canvas: *font.sprite
|
|||||||
const thick_px = Thickness.light.height(self.thickness);
|
const thick_px = Thickness.light.height(self.thickness);
|
||||||
canvas.trapezoid(.{
|
canvas.trapezoid(.{
|
||||||
.top = 0,
|
.top = 0,
|
||||||
.bottom = @intCast(i32, self.height),
|
.bottom = @as(i32, @intCast(self.height)),
|
||||||
.left = .{
|
.left = .{
|
||||||
.p1 = .{
|
.p1 = .{
|
||||||
.x = @intFromFloat(i32, @floatFromInt(f64, self.width) - @floatFromInt(f64, thick_px) / 2),
|
.x = @as(i32, @intFromFloat(@as(f64, @floatFromInt(self.width)) - @as(f64, @floatFromInt(thick_px)) / 2)),
|
||||||
.y = 0,
|
.y = 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
.p2 = .{
|
.p2 = .{
|
||||||
.x = @intFromFloat(i32, 0 - @floatFromInt(f64, thick_px) / 2),
|
.x = @as(i32, @intFromFloat(0 - @as(f64, @floatFromInt(thick_px)) / 2)),
|
||||||
.y = @intCast(i32, self.height),
|
.y = @as(i32, @intCast(self.height)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.right = .{
|
.right = .{
|
||||||
.p1 = .{
|
.p1 = .{
|
||||||
.x = @intFromFloat(i32, @floatFromInt(f64, self.width) + @floatFromInt(f64, thick_px) / 2),
|
.x = @as(i32, @intFromFloat(@as(f64, @floatFromInt(self.width)) + @as(f64, @floatFromInt(thick_px)) / 2)),
|
||||||
.y = 0,
|
.y = 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
.p2 = .{
|
.p2 = .{
|
||||||
.x = @intFromFloat(i32, 0 + @floatFromInt(f64, thick_px) / 2),
|
.x = @as(i32, @intFromFloat(0 + @as(f64, @floatFromInt(thick_px)) / 2)),
|
||||||
.y = @intCast(i32, self.height),
|
.y = @as(i32, @intCast(self.height)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -1095,27 +1095,27 @@ fn draw_light_diagonal_upper_left_to_lower_right(self: Box, canvas: *font.sprite
|
|||||||
const thick_px = Thickness.light.height(self.thickness);
|
const thick_px = Thickness.light.height(self.thickness);
|
||||||
canvas.trapezoid(.{
|
canvas.trapezoid(.{
|
||||||
.top = 0,
|
.top = 0,
|
||||||
.bottom = @intCast(i32, self.height),
|
.bottom = @as(i32, @intCast(self.height)),
|
||||||
.left = .{
|
.left = .{
|
||||||
.p1 = .{
|
.p1 = .{
|
||||||
.x = @intFromFloat(i32, 0 - @floatFromInt(f64, thick_px) / 2),
|
.x = @as(i32, @intFromFloat(0 - @as(f64, @floatFromInt(thick_px)) / 2)),
|
||||||
.y = 0,
|
.y = 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
.p2 = .{
|
.p2 = .{
|
||||||
.x = @intFromFloat(i32, @floatFromInt(f64, self.width) - @floatFromInt(f64, thick_px) / 2),
|
.x = @as(i32, @intFromFloat(@as(f64, @floatFromInt(self.width)) - @as(f64, @floatFromInt(thick_px)) / 2)),
|
||||||
.y = @intCast(i32, self.height),
|
.y = @as(i32, @intCast(self.height)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.right = .{
|
.right = .{
|
||||||
.p1 = .{
|
.p1 = .{
|
||||||
.x = @intFromFloat(i32, 0 + @floatFromInt(f64, thick_px) / 2),
|
.x = @as(i32, @intFromFloat(0 + @as(f64, @floatFromInt(thick_px)) / 2)),
|
||||||
.y = 0,
|
.y = 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
.p2 = .{
|
.p2 = .{
|
||||||
.x = @intFromFloat(i32, @floatFromInt(f64, self.width) + @floatFromInt(f64, thick_px) / 2),
|
.x = @as(i32, @intFromFloat(@as(f64, @floatFromInt(self.width)) + @as(f64, @floatFromInt(thick_px)) / 2)),
|
||||||
.y = @intCast(i32, self.height),
|
.y = @as(i32, @intCast(self.height)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -1194,7 +1194,7 @@ fn draw_lower_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
self.height - @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.height) / 8)),
|
self.height - @as(u32, @intFromFloat(@round(3 * @as(f64, @floatFromInt(self.height)) / 8))),
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
@ -1204,7 +1204,7 @@ fn draw_lower_half_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
self.height - @intFromFloat(u32, @round(@floatFromInt(f64, self.height) / 2)),
|
self.height - @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.height)) / 2))),
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
@ -1214,7 +1214,7 @@ fn draw_lower_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
self.height - @intFromFloat(u32, @round(5 * @floatFromInt(f64, self.height) / 8)),
|
self.height - @as(u32, @intFromFloat(@round(5 * @as(f64, @floatFromInt(self.height)) / 8))),
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
@ -1224,7 +1224,7 @@ fn draw_lower_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void
|
|||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
self.height - @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.height) / 4)),
|
self.height - @as(u32, @intFromFloat(@round(3 * @as(f64, @floatFromInt(self.height)) / 4))),
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
@ -1234,7 +1234,7 @@ fn draw_lower_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
self.height - @intFromFloat(u32, @round(7 * @floatFromInt(f64, self.height) / 8)),
|
self.height - @as(u32, @intFromFloat(@round(7 * @as(f64, @floatFromInt(self.height)) / 8))),
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
@ -1246,7 +1246,7 @@ fn draw_upper_one_quarter_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
@intFromFloat(u32, @round(@floatFromInt(f64, self.height) / 4)),
|
@as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.height)) / 4))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1256,7 +1256,7 @@ fn draw_upper_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
@intFromFloat(u32, @round(3 * @floatFromInt(f64, self.height) / 8)),
|
@as(u32, @intFromFloat(@round(3 * @as(f64, @floatFromInt(self.height)) / 8))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1266,7 +1266,7 @@ fn draw_upper_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
@intFromFloat(u32, @round(5 * @floatFromInt(f64, self.height) / 8)),
|
@as(u32, @intFromFloat(@round(5 * @as(f64, @floatFromInt(self.height)) / 8))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1276,7 +1276,7 @@ fn draw_upper_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
@intFromFloat(u32, @round(3 * @floatFromInt(f64, self.height) / 4)),
|
@as(u32, @intFromFloat(@round(3 * @as(f64, @floatFromInt(self.height)) / 4))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1286,7 +1286,7 @@ fn draw_upper_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
@intFromFloat(u32, @round(7 * @floatFromInt(f64, self.height) / 8)),
|
@as(u32, @intFromFloat(@round(7 * @as(f64, @floatFromInt(self.height)) / 8))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1299,7 +1299,7 @@ fn draw_left_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@intFromFloat(u32, @round(7 * @floatFromInt(f64, self.width) / 8)),
|
@as(u32, @intFromFloat(@round(7 * @as(f64, @floatFromInt(self.width)) / 8))),
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1309,7 +1309,7 @@ fn draw_left_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@intFromFloat(u32, @round(3 * @floatFromInt(f64, self.width) / 4)),
|
@as(u32, @intFromFloat(@round(3 * @as(f64, @floatFromInt(self.width)) / 4))),
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1319,7 +1319,7 @@ fn draw_left_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@intFromFloat(u32, @round(5 * @floatFromInt(f64, self.width) / 8)),
|
@as(u32, @intFromFloat(@round(5 * @as(f64, @floatFromInt(self.width)) / 8))),
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1329,7 +1329,7 @@ fn draw_left_half_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 2)),
|
@as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 2))),
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1339,7 +1339,7 @@ fn draw_left_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@intFromFloat(u32, @round(3 * @floatFromInt(f64, self.width) / 8)),
|
@as(u32, @intFromFloat(@round(3 * @as(f64, @floatFromInt(self.width)) / 8))),
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1349,14 +1349,14 @@ fn draw_left_one_quarter_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 4)),
|
@as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 4))),
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_vertical_one_eighth_block_n(self: Box, canvas: *font.sprite.Canvas, n: u32) void {
|
fn draw_vertical_one_eighth_block_n(self: Box, canvas: *font.sprite.Canvas, n: u32) void {
|
||||||
const x = @intFromFloat(u32, @round(@floatFromInt(f64, n) * @floatFromInt(f64, self.width) / 8));
|
const x = @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(n)) * @as(f64, @floatFromInt(self.width)) / 8)));
|
||||||
const w = @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 8));
|
const w = @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 8)));
|
||||||
self.rect(canvas, x, 0, x + w, self.height);
|
self.rect(canvas, x, 0, x + w, self.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1367,7 +1367,7 @@ fn draw_left_one_eighth_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
fn draw_right_half_block(self: Box, canvas: *font.sprite.Canvas) void {
|
fn draw_right_half_block(self: Box, canvas: *font.sprite.Canvas) void {
|
||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
@intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 2)),
|
@as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 2))),
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
@ -1378,9 +1378,9 @@ fn draw_pixman_shade(self: Box, canvas: *font.sprite.Canvas, v: u16) void {
|
|||||||
canvas.rect((font.sprite.Box{
|
canvas.rect((font.sprite.Box{
|
||||||
.x1 = 0,
|
.x1 = 0,
|
||||||
.y1 = 0,
|
.y1 = 0,
|
||||||
.x2 = @intCast(i32, self.width),
|
.x2 = @as(i32, @intCast(self.width)),
|
||||||
.y2 = @intCast(i32, self.height),
|
.y2 = @as(i32, @intCast(self.height)),
|
||||||
}).rect(), @enumFromInt(font.sprite.Color, v));
|
}).rect(), @as(font.sprite.Color, @enumFromInt(v)));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_light_shade(self: Box, canvas: *font.sprite.Canvas) void {
|
fn draw_light_shade(self: Box, canvas: *font.sprite.Canvas) void {
|
||||||
@ -1396,8 +1396,8 @@ fn draw_dark_shade(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw_horizontal_one_eighth_block_n(self: Box, canvas: *font.sprite.Canvas, n: u32) void {
|
fn draw_horizontal_one_eighth_block_n(self: Box, canvas: *font.sprite.Canvas, n: u32) void {
|
||||||
const y = @intFromFloat(u32, @round(@floatFromInt(f64, n) * @floatFromInt(f64, self.height) / 8));
|
const y = @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(n)) * @as(f64, @floatFromInt(self.height)) / 8)));
|
||||||
const h = @intFromFloat(u32, @round(@floatFromInt(f64, self.height) / 8));
|
const h = @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.height)) / 8)));
|
||||||
self.rect(canvas, 0, y, self.width, y + h);
|
self.rect(canvas, 0, y, self.width, y + h);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1408,7 +1408,7 @@ fn draw_upper_one_eighth_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
fn draw_right_one_eighth_block(self: Box, canvas: *font.sprite.Canvas) void {
|
fn draw_right_one_eighth_block(self: Box, canvas: *font.sprite.Canvas) void {
|
||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
self.width - @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 8)),
|
self.width - @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 8))),
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
@ -1450,7 +1450,7 @@ fn draw_horizontal_one_eighth_1358_block(self: Box, canvas: *font.sprite.Canvas)
|
|||||||
fn draw_right_one_quarter_block(self: Box, canvas: *font.sprite.Canvas) void {
|
fn draw_right_one_quarter_block(self: Box, canvas: *font.sprite.Canvas) void {
|
||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
self.width - @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 4)),
|
self.width - @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 4))),
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
@ -1460,7 +1460,7 @@ fn draw_right_one_quarter_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
fn draw_right_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void {
|
fn draw_right_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void {
|
||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
self.width - @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.width) / 4)),
|
self.width - @as(u32, @intFromFloat(@round(3 * @as(f64, @floatFromInt(self.width)) / 4))),
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
@ -1470,7 +1470,7 @@ fn draw_right_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void
|
|||||||
fn draw_right_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
fn draw_right_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
self.width - @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.width) / 8)),
|
self.width - @as(u32, @intFromFloat(@round(3 * @as(f64, @floatFromInt(self.width)) / 8))),
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
@ -1480,7 +1480,7 @@ fn draw_right_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
fn draw_right_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
fn draw_right_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
self.width - @intFromFloat(u32, @round(5 * @floatFromInt(f64, self.width) / 8)),
|
self.width - @as(u32, @intFromFloat(@round(5 * @as(f64, @floatFromInt(self.width)) / 8))),
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
@ -1490,7 +1490,7 @@ fn draw_right_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
fn draw_right_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
fn draw_right_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
|
||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
self.width - @intFromFloat(u32, @round(7 * @floatFromInt(f64, self.width) / 8)),
|
self.width - @as(u32, @intFromFloat(@round(7 * @as(f64, @floatFromInt(self.width)) / 8))),
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
@ -1502,18 +1502,18 @@ fn quad_upper_left(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@intFromFloat(u32, @ceil(@floatFromInt(f64, self.width) / 2)),
|
@as(u32, @intFromFloat(@ceil(@as(f64, @floatFromInt(self.width)) / 2))),
|
||||||
@intFromFloat(u32, @ceil(@floatFromInt(f64, self.height) / 2)),
|
@as(u32, @intFromFloat(@ceil(@as(f64, @floatFromInt(self.height)) / 2))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn quad_upper_right(self: Box, canvas: *font.sprite.Canvas) void {
|
fn quad_upper_right(self: Box, canvas: *font.sprite.Canvas) void {
|
||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
@intFromFloat(u32, @floor(@floatFromInt(f64, self.width) / 2)),
|
@as(u32, @intFromFloat(@floor(@as(f64, @floatFromInt(self.width)) / 2))),
|
||||||
0,
|
0,
|
||||||
self.width,
|
self.width,
|
||||||
@intFromFloat(u32, @ceil(@floatFromInt(f64, self.height) / 2)),
|
@as(u32, @intFromFloat(@ceil(@as(f64, @floatFromInt(self.height)) / 2))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1521,8 +1521,8 @@ fn quad_lower_left(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
0,
|
0,
|
||||||
@intFromFloat(u32, @floor(@floatFromInt(f64, self.height) / 2)),
|
@as(u32, @intFromFloat(@floor(@as(f64, @floatFromInt(self.height)) / 2))),
|
||||||
@intFromFloat(u32, @ceil(@floatFromInt(f64, self.width) / 2)),
|
@as(u32, @intFromFloat(@ceil(@as(f64, @floatFromInt(self.width)) / 2))),
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1530,8 +1530,8 @@ fn quad_lower_left(self: Box, canvas: *font.sprite.Canvas) void {
|
|||||||
fn quad_lower_right(self: Box, canvas: *font.sprite.Canvas) void {
|
fn quad_lower_right(self: Box, canvas: *font.sprite.Canvas) void {
|
||||||
self.rect(
|
self.rect(
|
||||||
canvas,
|
canvas,
|
||||||
@intFromFloat(u32, @floor(@floatFromInt(f64, self.width) / 2)),
|
@as(u32, @intFromFloat(@floor(@as(f64, @floatFromInt(self.width)) / 2))),
|
||||||
@intFromFloat(u32, @floor(@floatFromInt(f64, self.height) / 2)),
|
@as(u32, @intFromFloat(@floor(@as(f64, @floatFromInt(self.height)) / 2))),
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
);
|
);
|
||||||
@ -1755,8 +1755,8 @@ fn draw_sextant(self: Box, canvas: *font.sprite.Canvas, cp: u32) void {
|
|||||||
|
|
||||||
fn xHalfs(self: Box) [2]u32 {
|
fn xHalfs(self: Box) [2]u32 {
|
||||||
return .{
|
return .{
|
||||||
@intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 2)),
|
@as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 2))),
|
||||||
@intFromFloat(u32, @floatFromInt(f64, self.width) / 2),
|
@as(u32, @intFromFloat(@as(f64, @floatFromInt(self.width)) / 2)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2116,9 +2116,9 @@ fn draw_wedge_triangle(self: Box, canvas: *font.sprite.Canvas, cp: u32) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canvas.triangle(.{
|
canvas.triangle(.{
|
||||||
.p1 = .{ .x = @intCast(i32, p1_x), .y = @intCast(i32, p1_y) },
|
.p1 = .{ .x = @as(i32, @intCast(p1_x)), .y = @as(i32, @intCast(p1_y)) },
|
||||||
.p2 = .{ .x = @intCast(i32, p2_x), .y = @intCast(i32, p2_y) },
|
.p2 = .{ .x = @as(i32, @intCast(p2_x)), .y = @as(i32, @intCast(p2_y)) },
|
||||||
.p3 = .{ .x = @intCast(i32, p3_x), .y = @intCast(i32, p3_y) },
|
.p3 = .{ .x = @as(i32, @intCast(p3_x)), .y = @as(i32, @intCast(p3_y)) },
|
||||||
}, .on);
|
}, .on);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2147,16 +2147,16 @@ fn draw_wedge_triangle_and_box(self: Box, canvas: *font.sprite.Canvas, cp: u32)
|
|||||||
const box: font.sprite.Box = switch (cp) {
|
const box: font.sprite.Box = switch (cp) {
|
||||||
0x1fb46, 0x1fb51 => .{
|
0x1fb46, 0x1fb51 => .{
|
||||||
.x1 = 0,
|
.x1 = 0,
|
||||||
.y1 = @intCast(i32, y_thirds[1]),
|
.y1 = @as(i32, @intCast(y_thirds[1])),
|
||||||
.x2 = @intCast(i32, self.width),
|
.x2 = @as(i32, @intCast(self.width)),
|
||||||
.y2 = @intCast(i32, self.height),
|
.y2 = @as(i32, @intCast(self.height)),
|
||||||
},
|
},
|
||||||
|
|
||||||
0x1fb5c, 0x1fb67 => .{
|
0x1fb5c, 0x1fb67 => .{
|
||||||
.x1 = 0,
|
.x1 = 0,
|
||||||
.y1 = 0,
|
.y1 = 0,
|
||||||
.x2 = @intCast(i32, self.width),
|
.x2 = @as(i32, @intCast(self.width)),
|
||||||
.y2 = @intCast(i32, y_thirds[0]),
|
.y2 = @as(i32, @intCast(y_thirds[0])),
|
||||||
},
|
},
|
||||||
|
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
@ -2191,7 +2191,7 @@ fn draw_light_arc(
|
|||||||
// thickness/2.) whose centers are on its edge. This means to get the
|
// thickness/2.) whose centers are on its edge. This means to get the
|
||||||
// radius of the quartercircle, we add the exact half thickness to the
|
// radius of the quartercircle, we add the exact half thickness to the
|
||||||
// radius of the inner circle.
|
// radius of the inner circle.
|
||||||
var c_r: f64 = @floatFromInt(f64, circle_inner_edge) + @floatFromInt(f64, thick_pixels) / 2;
|
var c_r: f64 = @as(f64, @floatFromInt(circle_inner_edge)) + @as(f64, @floatFromInt(thick_pixels)) / 2;
|
||||||
|
|
||||||
// We need to draw short lines from the end of the quartercircle to the
|
// We need to draw short lines from the end of the quartercircle to the
|
||||||
// box-edges, store one endpoint (the other is the edge of the
|
// box-edges, store one endpoint (the other is the edge of the
|
||||||
@ -2305,16 +2305,16 @@ fn draw_light_arc(
|
|||||||
// As the quartercircle ends (vertically) in the middle of a pixel, an
|
// As the quartercircle ends (vertically) in the middle of a pixel, an
|
||||||
// uneven number helps hit that exactly.
|
// uneven number helps hit that exactly.
|
||||||
{
|
{
|
||||||
var i: f64 = @floatFromInt(f64, y_min) * 16;
|
var i: f64 = @as(f64, @floatFromInt(y_min)) * 16;
|
||||||
while (i <= @floatFromInt(f64, y_max) * 16) : (i += 1) {
|
while (i <= @as(f64, @floatFromInt(y_max)) * 16) : (i += 1) {
|
||||||
const y = i / 16;
|
const y = i / 16;
|
||||||
const x = x: {
|
const x = x: {
|
||||||
// circle_hemisphere * sqrt(c_r2 - (y - c_y) * (y - c_y)) + c_x;
|
// circle_hemisphere * sqrt(c_r2 - (y - c_y) * (y - c_y)) + c_x;
|
||||||
const hemi = @floatFromInt(f64, circle_hemisphere);
|
const hemi = @as(f64, @floatFromInt(circle_hemisphere));
|
||||||
const y_part = y - @floatFromInt(f64, c_y);
|
const y_part = y - @as(f64, @floatFromInt(c_y));
|
||||||
const y_squared = y_part * y_part;
|
const y_squared = y_part * y_part;
|
||||||
const sqrt = @sqrt(c_r2 - y_squared);
|
const sqrt = @sqrt(c_r2 - y_squared);
|
||||||
const f_c_x = @floatFromInt(f64, c_x);
|
const f_c_x = @as(f64, @floatFromInt(c_x));
|
||||||
|
|
||||||
// We need to detect overflows and just skip this i
|
// We need to detect overflows and just skip this i
|
||||||
const a = hemi * sqrt;
|
const a = hemi * sqrt;
|
||||||
@ -2326,15 +2326,15 @@ fn draw_light_arc(
|
|||||||
break :x b;
|
break :x b;
|
||||||
};
|
};
|
||||||
|
|
||||||
const row = @intFromFloat(i32, @round(y));
|
const row = @as(i32, @intFromFloat(@round(y)));
|
||||||
const col = @intFromFloat(i32, @round(x));
|
const col = @as(i32, @intFromFloat(@round(x)));
|
||||||
if (col < 0) continue;
|
if (col < 0) continue;
|
||||||
|
|
||||||
// rectangle big enough to fit entire circle with radius thick/2.
|
// rectangle big enough to fit entire circle with radius thick/2.
|
||||||
const row1 = row - @intCast(i32, thick / 2 + 1);
|
const row1 = row - @as(i32, @intCast(thick / 2 + 1));
|
||||||
const row2 = row + @intCast(i32, thick / 2 + 1);
|
const row2 = row + @as(i32, @intCast(thick / 2 + 1));
|
||||||
const col1 = col - @intCast(i32, thick / 2 + 1);
|
const col1 = col - @as(i32, @intCast(thick / 2 + 1));
|
||||||
const col2 = col + @intCast(i32, thick / 2 + 1);
|
const col2 = col + @as(i32, @intCast(thick / 2 + 1));
|
||||||
|
|
||||||
const row_start = @min(row1, row2);
|
const row_start = @min(row1, row2);
|
||||||
const row_end = @max(row1, row2);
|
const row_end = @max(row1, row2);
|
||||||
@ -2348,14 +2348,14 @@ fn draw_light_arc(
|
|||||||
// this is accomplished by rejecting pixels where the distance from
|
// this is accomplished by rejecting pixels where the distance from
|
||||||
// their center to x,y is greater than thick/2.
|
// their center to x,y is greater than thick/2.
|
||||||
var r: i32 = @max(row_start, 0);
|
var r: i32 = @max(row_start, 0);
|
||||||
const r_end = @max(@min(row_end, @intCast(i32, height)), 0);
|
const r_end = @max(@min(row_end, @as(i32, @intCast(height))), 0);
|
||||||
while (r < r_end) : (r += 1) {
|
while (r < r_end) : (r += 1) {
|
||||||
const r_midpoint = @floatFromInt(f64, r) + 0.5;
|
const r_midpoint = @as(f64, @floatFromInt(r)) + 0.5;
|
||||||
|
|
||||||
var c: i32 = @max(col_start, 0);
|
var c: i32 = @max(col_start, 0);
|
||||||
const c_end = @max(@min(col_end, @intCast(i32, width)), 0);
|
const c_end = @max(@min(col_end, @as(i32, @intCast(width))), 0);
|
||||||
while (c < c_end) : (c += 1) {
|
while (c < c_end) : (c += 1) {
|
||||||
const c_midpoint = @floatFromInt(f64, c) + 0.5;
|
const c_midpoint = @as(f64, @floatFromInt(c)) + 0.5;
|
||||||
|
|
||||||
// vector from point on quartercircle to midpoint of the current pixel.
|
// vector from point on quartercircle to midpoint of the current pixel.
|
||||||
const center_midpoint_x = c_midpoint - x;
|
const center_midpoint_x = c_midpoint - x;
|
||||||
@ -2364,10 +2364,10 @@ fn draw_light_arc(
|
|||||||
// distance from current point to circle-center.
|
// distance from current point to circle-center.
|
||||||
const dist = @sqrt(center_midpoint_x * center_midpoint_x + center_midpoint_y * center_midpoint_y);
|
const dist = @sqrt(center_midpoint_x * center_midpoint_x + center_midpoint_y * center_midpoint_y);
|
||||||
// skip if midpoint of pixel is outside the circle.
|
// skip if midpoint of pixel is outside the circle.
|
||||||
if (dist > @floatFromInt(f64, thick) / 2) continue;
|
if (dist > @as(f64, @floatFromInt(thick)) / 2) continue;
|
||||||
|
|
||||||
// Set our pixel
|
// Set our pixel
|
||||||
const idx = @intCast(usize, r * @intCast(i32, width) + c);
|
const idx = @as(usize, @intCast(r * @as(i32, @intCast(width)) + c));
|
||||||
ss_data[idx] = 0xFF;
|
ss_data[idx] = 0xFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2390,15 +2390,15 @@ fn draw_light_arc(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const average = @intCast(u8, @min(total / (supersample * supersample), 0xff));
|
const average = @as(u8, @intCast(@min(total / (supersample * supersample), 0xff)));
|
||||||
canvas.rect(
|
canvas.rect(
|
||||||
.{
|
.{
|
||||||
.x = @intCast(i32, c),
|
.x = @as(i32, @intCast(c)),
|
||||||
.y = @intCast(i32, r),
|
.y = @as(i32, @intCast(r)),
|
||||||
.width = 1,
|
.width = 1,
|
||||||
.height = 1,
|
.height = 1,
|
||||||
},
|
},
|
||||||
@enumFromInt(font.sprite.Color, average),
|
@as(font.sprite.Color, @enumFromInt(average)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2649,10 +2649,10 @@ fn vline(
|
|||||||
thickness_px: u32,
|
thickness_px: u32,
|
||||||
) void {
|
) void {
|
||||||
canvas.rect((font.sprite.Box{
|
canvas.rect((font.sprite.Box{
|
||||||
.x1 = @intCast(i32, @min(@max(x, 0), self.width)),
|
.x1 = @as(i32, @intCast(@min(@max(x, 0), self.width))),
|
||||||
.x2 = @intCast(i32, @min(@max(x + thickness_px, 0), self.width)),
|
.x2 = @as(i32, @intCast(@min(@max(x + thickness_px, 0), self.width))),
|
||||||
.y1 = @intCast(i32, @min(@max(y1, 0), self.height)),
|
.y1 = @as(i32, @intCast(@min(@max(y1, 0), self.height))),
|
||||||
.y2 = @intCast(i32, @min(@max(y2, 0), self.height)),
|
.y2 = @as(i32, @intCast(@min(@max(y2, 0), self.height))),
|
||||||
}).rect(), .on);
|
}).rect(), .on);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2665,10 +2665,10 @@ fn hline(
|
|||||||
thickness_px: u32,
|
thickness_px: u32,
|
||||||
) void {
|
) void {
|
||||||
canvas.rect((font.sprite.Box{
|
canvas.rect((font.sprite.Box{
|
||||||
.x1 = @intCast(i32, @min(@max(x1, 0), self.width)),
|
.x1 = @as(i32, @intCast(@min(@max(x1, 0), self.width))),
|
||||||
.x2 = @intCast(i32, @min(@max(x2, 0), self.width)),
|
.x2 = @as(i32, @intCast(@min(@max(x2, 0), self.width))),
|
||||||
.y1 = @intCast(i32, @min(@max(y, 0), self.height)),
|
.y1 = @as(i32, @intCast(@min(@max(y, 0), self.height))),
|
||||||
.y2 = @intCast(i32, @min(@max(y + thickness_px, 0), self.height)),
|
.y2 = @as(i32, @intCast(@min(@max(y + thickness_px, 0), self.height))),
|
||||||
}).rect(), .on);
|
}).rect(), .on);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2681,10 +2681,10 @@ fn rect(
|
|||||||
y2: u32,
|
y2: u32,
|
||||||
) void {
|
) void {
|
||||||
canvas.rect((font.sprite.Box{
|
canvas.rect((font.sprite.Box{
|
||||||
.x1 = @intCast(i32, @min(@max(x1, 0), self.width)),
|
.x1 = @as(i32, @intCast(@min(@max(x1, 0), self.width))),
|
||||||
.y1 = @intCast(i32, @min(@max(y1, 0), self.height)),
|
.y1 = @as(i32, @intCast(@min(@max(y1, 0), self.height))),
|
||||||
.x2 = @intCast(i32, @min(@max(x2, 0), self.width)),
|
.x2 = @as(i32, @intCast(@min(@max(x2, 0), self.width))),
|
||||||
.y2 = @intCast(i32, @min(@max(y2, 0), self.height)),
|
.y2 = @as(i32, @intCast(@min(@max(y2, 0), self.height))),
|
||||||
}).rect(), .on);
|
}).rect(), .on);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ pub fn renderGlyph(
|
|||||||
.underline => try underline.renderGlyph(
|
.underline => try underline.renderGlyph(
|
||||||
alloc,
|
alloc,
|
||||||
atlas,
|
atlas,
|
||||||
@enumFromInt(Sprite, cp),
|
@enumFromInt(cp),
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
self.underline_position,
|
self.underline_position,
|
||||||
@ -88,7 +88,7 @@ const Kind = enum {
|
|||||||
|
|
||||||
pub fn init(cp: u32) ?Kind {
|
pub fn init(cp: u32) ?Kind {
|
||||||
return switch (cp) {
|
return switch (cp) {
|
||||||
Sprite.start...Sprite.end => switch (@enumFromInt(Sprite, cp)) {
|
Sprite.start...Sprite.end => switch (@as(Sprite, @enumFromInt(cp))) {
|
||||||
.underline,
|
.underline,
|
||||||
.underline_double,
|
.underline_double,
|
||||||
.underline_dotted,
|
.underline_dotted,
|
||||||
|
@ -31,8 +31,8 @@ pub const Box = struct {
|
|||||||
return .{
|
return .{
|
||||||
.x = tl_x,
|
.x = tl_x,
|
||||||
.y = tl_y,
|
.y = tl_y,
|
||||||
.width = @intCast(u32, br_x - tl_x),
|
.width = @intCast(br_x - tl_x),
|
||||||
.height = @intCast(u32, br_y - tl_y),
|
.height = @intCast(br_y - tl_y),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -68,16 +68,16 @@ pub const Color = enum(u8) {
|
|||||||
fn pixmanColor(self: Color) pixman.Color {
|
fn pixmanColor(self: Color) pixman.Color {
|
||||||
// pixman uses u16 for color while our color value is u8 so we
|
// pixman uses u16 for color while our color value is u8 so we
|
||||||
// scale it up proportionally.
|
// scale it up proportionally.
|
||||||
const max = @floatFromInt(f32, std.math.maxInt(u8));
|
const max = @as(f32, @floatFromInt(std.math.maxInt(u8)));
|
||||||
const max_u16 = @floatFromInt(f32, std.math.maxInt(u16));
|
const max_u16 = @as(f32, @floatFromInt(std.math.maxInt(u16)));
|
||||||
const unscaled = @floatFromInt(f32, @intFromEnum(self));
|
const unscaled = @as(f32, @floatFromInt(@intFromEnum(self)));
|
||||||
const scaled = @intFromFloat(u16, (unscaled * max_u16) / max);
|
const scaled = @as(u16, @intFromFloat((unscaled * max_u16) / max));
|
||||||
return .{ .red = 0, .green = 0, .blue = 0, .alpha = scaled };
|
return .{ .red = 0, .green = 0, .blue = 0, .alpha = scaled };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cssColor(self: Color, buf: []u8) ![]u8 {
|
fn cssColor(self: Color, buf: []u8) ![]u8 {
|
||||||
return try std.fmt.bufPrint(buf, "rgba(0, 0, 0, {:.2})", .{
|
return try std.fmt.bufPrint(buf, "rgba(0, 0, 0, {:.2})", .{
|
||||||
@floatFromInt(f32, @intFromEnum(self)) / 255,
|
@as(f32, @floatFromInt(@intFromEnum(self))) / 255,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -144,8 +144,8 @@ const WebCanvasImpl = struct {
|
|||||||
const ctx = self.context(color) catch return;
|
const ctx = self.context(color) catch return;
|
||||||
defer ctx.deinit();
|
defer ctx.deinit();
|
||||||
ctx.call(void, "fillRect", .{
|
ctx.call(void, "fillRect", .{
|
||||||
@intCast(u32, v.x),
|
@as(u32, @intCast(v.x)),
|
||||||
@intCast(u32, v.y),
|
@as(u32, @intCast(v.y)),
|
||||||
v.width,
|
v.width,
|
||||||
v.height,
|
v.height,
|
||||||
}) catch return;
|
}) catch return;
|
||||||
@ -235,7 +235,7 @@ const WebCanvasImpl = struct {
|
|||||||
|
|
||||||
// Allocate our local memory to copy the data to.
|
// Allocate our local memory to copy the data to.
|
||||||
const len = try src_array.get(u32, "length");
|
const len = try src_array.get(u32, "length");
|
||||||
var bitmap = try alloc.alloc(u8, @intCast(usize, len));
|
var bitmap = try alloc.alloc(u8, @intCast(len));
|
||||||
errdefer alloc.free(bitmap);
|
errdefer alloc.free(bitmap);
|
||||||
|
|
||||||
// Create our target Uint8Array that we can use to copy from src.
|
// Create our target Uint8Array that we can use to copy from src.
|
||||||
@ -304,7 +304,7 @@ const PixmanImpl = struct {
|
|||||||
// for boxes are always 8bpp
|
// for boxes are always 8bpp
|
||||||
const format: pixman.FormatCode = .a8;
|
const format: pixman.FormatCode = .a8;
|
||||||
const stride = format.strideForWidth(width);
|
const stride = format.strideForWidth(width);
|
||||||
const len = @intCast(usize, stride * @intCast(c_int, height));
|
const len = @as(usize, @intCast(stride * @as(c_int, @intCast(height))));
|
||||||
|
|
||||||
// Allocate our buffer. pixman uses []u32 so we divide our length
|
// Allocate our buffer. pixman uses []u32 so we divide our length
|
||||||
// by 4 since u32 / u8 = 4.
|
// by 4 since u32 / u8 = 4.
|
||||||
@ -315,8 +315,8 @@ const PixmanImpl = struct {
|
|||||||
// Create the image we'll draw to
|
// Create the image we'll draw to
|
||||||
const img = try pixman.Image.createBitsNoClear(
|
const img = try pixman.Image.createBitsNoClear(
|
||||||
format,
|
format,
|
||||||
@intCast(c_int, width),
|
@intCast(width),
|
||||||
@intCast(c_int, height),
|
@intCast(height),
|
||||||
data.ptr,
|
data.ptr,
|
||||||
stride,
|
stride,
|
||||||
);
|
);
|
||||||
@ -338,18 +338,15 @@ const PixmanImpl = struct {
|
|||||||
pub fn writeAtlas(self: *Canvas, alloc: Allocator, atlas: *font.Atlas) !font.Atlas.Region {
|
pub fn writeAtlas(self: *Canvas, alloc: Allocator, atlas: *font.Atlas) !font.Atlas.Region {
|
||||||
assert(atlas.format == .greyscale);
|
assert(atlas.format == .greyscale);
|
||||||
|
|
||||||
const width = @intCast(u32, self.image.getWidth());
|
const width = @as(u32, @intCast(self.image.getWidth()));
|
||||||
const height = @intCast(u32, self.image.getHeight());
|
const height = @as(u32, @intCast(self.image.getHeight()));
|
||||||
const region = try atlas.reserve(alloc, width, height);
|
const region = try atlas.reserve(alloc, width, height);
|
||||||
if (region.width > 0 and region.height > 0) {
|
if (region.width > 0 and region.height > 0) {
|
||||||
const depth = atlas.format.depth();
|
const depth = atlas.format.depth();
|
||||||
|
|
||||||
// Convert our []u32 to []u8 since we use 8bpp formats
|
// Convert our []u32 to []u8 since we use 8bpp formats
|
||||||
const stride = self.image.getStride();
|
const stride = self.image.getStride();
|
||||||
const data = @alignCast(
|
const data = @as([*]u8, @ptrCast(self.data.ptr))[0 .. self.data.len * 4];
|
||||||
@alignOf(u8),
|
|
||||||
@ptrCast([*]u8, self.data.ptr)[0 .. self.data.len * 4],
|
|
||||||
);
|
|
||||||
|
|
||||||
// We can avoid a buffer copy if our atlas width and bitmap
|
// We can avoid a buffer copy if our atlas width and bitmap
|
||||||
// width match and the bitmap pitch is just the width (meaning
|
// width match and the bitmap pitch is just the width (meaning
|
||||||
@ -365,7 +362,7 @@ const PixmanImpl = struct {
|
|||||||
while (i < height) : (i += 1) {
|
while (i < height) : (i += 1) {
|
||||||
std.mem.copy(u8, dst_ptr, src_ptr[0 .. width * depth]);
|
std.mem.copy(u8, dst_ptr, src_ptr[0 .. width * depth]);
|
||||||
dst_ptr = dst_ptr[width * depth ..];
|
dst_ptr = dst_ptr[width * depth ..];
|
||||||
src_ptr += @intCast(usize, stride);
|
src_ptr += @as(usize, @intCast(stride));
|
||||||
}
|
}
|
||||||
break :buffer temp;
|
break :buffer temp;
|
||||||
} else data[0..(width * height * depth)];
|
} else data[0..(width * height * depth)];
|
||||||
@ -385,10 +382,10 @@ const PixmanImpl = struct {
|
|||||||
pub fn rect(self: *Canvas, v: Rect, color: Color) void {
|
pub fn rect(self: *Canvas, v: Rect, color: Color) void {
|
||||||
const boxes = &[_]pixman.Box32{
|
const boxes = &[_]pixman.Box32{
|
||||||
.{
|
.{
|
||||||
.x1 = @intCast(i32, v.x),
|
.x1 = @intCast(v.x),
|
||||||
.y1 = @intCast(i32, v.y),
|
.y1 = @intCast(v.y),
|
||||||
.x2 = @intCast(i32, v.x + @intCast(i32, v.width)),
|
.x2 = @intCast(v.x + @as(i32, @intCast(v.width))),
|
||||||
.y2 = @intCast(i32, v.y + @intCast(i32, v.height)),
|
.y2 = @intCast(v.y + @as(i32, @intCast(v.height))),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -448,10 +445,10 @@ const PixmanImpl = struct {
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@intCast(i16, dest.x),
|
@intCast(dest.x),
|
||||||
@intCast(i16, dest.y),
|
@intCast(dest.y),
|
||||||
@intCast(u16, dest.width),
|
@intCast(dest.width),
|
||||||
@intCast(u16, dest.height),
|
@intCast(dest.height),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -43,7 +43,7 @@ pub fn renderGlyph(
|
|||||||
// Our coordinates start at the BOTTOM for our renderers so we have to
|
// Our coordinates start at the BOTTOM for our renderers so we have to
|
||||||
// specify an offset of the full height because we rendered a full size
|
// specify an offset of the full height because we rendered a full size
|
||||||
// cell.
|
// cell.
|
||||||
const offset_y = @intCast(i32, height);
|
const offset_y = @as(i32, @intCast(height));
|
||||||
|
|
||||||
return font.Glyph{
|
return font.Glyph{
|
||||||
.width = width,
|
.width = width,
|
||||||
@ -52,7 +52,7 @@ pub fn renderGlyph(
|
|||||||
.offset_y = offset_y,
|
.offset_y = offset_y,
|
||||||
.atlas_x = region.x,
|
.atlas_x = region.x,
|
||||||
.atlas_y = region.y,
|
.atlas_y = region.y,
|
||||||
.advance_x = @floatFromInt(f32, width),
|
.advance_x = @floatFromInt(width),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ const Draw = struct {
|
|||||||
// Ensure we never overflow out of bounds on the canvas
|
// Ensure we never overflow out of bounds on the canvas
|
||||||
const y_max = self.height -| 1;
|
const y_max = self.height -| 1;
|
||||||
const bottom = @min(self.pos + self.thickness, y_max);
|
const bottom = @min(self.pos + self.thickness, y_max);
|
||||||
const y = @intCast(i32, bottom - self.thickness);
|
const y = @as(i32, @intCast(bottom - self.thickness));
|
||||||
|
|
||||||
canvas.rect(.{
|
canvas.rect(.{
|
||||||
.x = 0,
|
.x = 0,
|
||||||
@ -104,14 +104,14 @@ const Draw = struct {
|
|||||||
|
|
||||||
canvas.rect(.{
|
canvas.rect(.{
|
||||||
.x = 0,
|
.x = 0,
|
||||||
.y = @intCast(i32, top),
|
.y = @intCast(top),
|
||||||
.width = self.width,
|
.width = self.width,
|
||||||
.height = self.thickness,
|
.height = self.thickness,
|
||||||
}, .on);
|
}, .on);
|
||||||
|
|
||||||
canvas.rect(.{
|
canvas.rect(.{
|
||||||
.x = 0,
|
.x = 0,
|
||||||
.y = @intCast(i32, bottom),
|
.y = @intCast(bottom),
|
||||||
.width = self.width,
|
.width = self.width,
|
||||||
.height = self.thickness,
|
.height = self.thickness,
|
||||||
}, .on);
|
}, .on);
|
||||||
@ -130,8 +130,8 @@ const Draw = struct {
|
|||||||
const x = @min(i * dot_width, self.width - 1);
|
const x = @min(i * dot_width, self.width - 1);
|
||||||
const width = @min(self.width - 1 - x, dot_width);
|
const width = @min(self.width - 1 - x, dot_width);
|
||||||
canvas.rect(.{
|
canvas.rect(.{
|
||||||
.x = @intCast(i32, i * dot_width),
|
.x = @intCast(i * dot_width),
|
||||||
.y = @intCast(i32, y),
|
.y = @intCast(y),
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = self.thickness,
|
.height = self.thickness,
|
||||||
}, .on);
|
}, .on);
|
||||||
@ -151,8 +151,8 @@ const Draw = struct {
|
|||||||
const x = @min(i * dash_width, self.width - 1);
|
const x = @min(i * dash_width, self.width - 1);
|
||||||
const width = @min(self.width - 1 - x, dash_width);
|
const width = @min(self.width - 1 - x, dash_width);
|
||||||
canvas.rect(.{
|
canvas.rect(.{
|
||||||
.x = @intCast(i32, x),
|
.x = @intCast(x),
|
||||||
.y = @intCast(i32, y),
|
.y = @intCast(y),
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = self.thickness,
|
.height = self.thickness,
|
||||||
}, .on);
|
}, .on);
|
||||||
@ -178,24 +178,24 @@ const Draw = struct {
|
|||||||
// The full heightof the wave can be from the bottom to the
|
// The full heightof the wave can be from the bottom to the
|
||||||
// underline position. We also calculate our starting y which is
|
// underline position. We also calculate our starting y which is
|
||||||
// slightly below our descender since our wave will move about that.
|
// slightly below our descender since our wave will move about that.
|
||||||
const wave_height = @floatFromInt(f64, y_max - pos);
|
const wave_height = @as(f64, @floatFromInt(y_max - pos));
|
||||||
const half_height = wave_height / 4;
|
const half_height = wave_height / 4;
|
||||||
const y = pos + @intFromFloat(u32, half_height);
|
const y = pos + @as(u32, @intFromFloat(half_height));
|
||||||
|
|
||||||
const x_factor = (2 * std.math.pi) / @floatFromInt(f64, self.width);
|
const x_factor = (2 * std.math.pi) / @as(f64, @floatFromInt(self.width));
|
||||||
var x: u32 = 0;
|
var x: u32 = 0;
|
||||||
while (x < self.width) : (x += 1) {
|
while (x < self.width) : (x += 1) {
|
||||||
const vertical = @intFromFloat(
|
const vertical = @as(
|
||||||
u32,
|
u32,
|
||||||
(-1 * half_height) * @sin(@floatFromInt(f64, x) * x_factor) + half_height,
|
@intFromFloat((-1 * half_height) * @sin(@as(f64, @floatFromInt(x)) * x_factor) + half_height),
|
||||||
);
|
);
|
||||||
|
|
||||||
var row: u32 = 0;
|
var row: u32 = 0;
|
||||||
while (row < self.thickness) : (row += 1) {
|
while (row < self.thickness) : (row += 1) {
|
||||||
const y1 = @min(row + y + vertical, y_max);
|
const y1 = @min(row + y + vertical, y_max);
|
||||||
canvas.rect(.{
|
canvas.rect(.{
|
||||||
.x = @intCast(i32, x),
|
.x = @intCast(x),
|
||||||
.y = @intCast(i32, y1),
|
.y = @intCast(y1),
|
||||||
.width = 1,
|
.width = 1,
|
||||||
.height = 1,
|
.height = 1,
|
||||||
}, .on);
|
}, .on);
|
||||||
|
@ -17,9 +17,9 @@ pub const Mods = packed struct(u8) {
|
|||||||
// For our own understanding
|
// For our own understanding
|
||||||
test {
|
test {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
try testing.expectEqual(@bitCast(u8, Mods{}), @as(u8, 0b0));
|
try testing.expectEqual(@as(u8, @bitCast(Mods{})), @as(u8, 0b0));
|
||||||
try testing.expectEqual(
|
try testing.expectEqual(
|
||||||
@bitCast(u8, Mods{ .shift = true }),
|
@as(u8, @bitCast(Mods{ .shift = true })),
|
||||||
@as(u8, 0b0000_0001),
|
@as(u8, 0b0000_0001),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -79,9 +79,9 @@ pub const ScrollMods = packed struct(u8) {
|
|||||||
// For our own understanding
|
// For our own understanding
|
||||||
test {
|
test {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
try testing.expectEqual(@bitCast(u8, ScrollMods{}), @as(u8, 0b0));
|
try testing.expectEqual(@as(u8, @bitCast(ScrollMods{})), @as(u8, 0b0));
|
||||||
try testing.expectEqual(
|
try testing.expectEqual(
|
||||||
@bitCast(u8, ScrollMods{ .precision = true }),
|
@as(u8, @bitCast(ScrollMods{ .precision = true })),
|
||||||
@as(u8, 0b0000_0001),
|
@as(u8, 0b0000_0001),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ pub const FlatpakHostCommand = struct {
|
|||||||
"(uub)",
|
"(uub)",
|
||||||
pid,
|
pid,
|
||||||
sig,
|
sig,
|
||||||
@intCast(c_int, @intFromBool(pg)),
|
@as(c_int, @intCast(@intFromBool(pg))),
|
||||||
),
|
),
|
||||||
c.G_VARIANT_TYPE("()"),
|
c.G_VARIANT_TYPE("()"),
|
||||||
c.G_DBUS_CALL_FLAGS_NONE,
|
c.G_DBUS_CALL_FLAGS_NONE,
|
||||||
@ -273,7 +273,7 @@ pub const FlatpakHostCommand = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const args = c.g_ptr_array_free(args_ptr, 0);
|
const args = c.g_ptr_array_free(args_ptr, 0);
|
||||||
defer c.g_free(@ptrCast(?*anyopaque, args));
|
defer c.g_free(@as(?*anyopaque, @ptrCast(args)));
|
||||||
|
|
||||||
// Get the cwd in case we don't have ours set. A small optimization
|
// Get the cwd in case we don't have ours set. A small optimization
|
||||||
// would be to do this only if we need it but this isn't a
|
// would be to do this only if we need it but this isn't a
|
||||||
@ -362,7 +362,7 @@ pub const FlatpakHostCommand = struct {
|
|||||||
params: ?*c.GVariant,
|
params: ?*c.GVariant,
|
||||||
ud: ?*anyopaque,
|
ud: ?*anyopaque,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const self = @ptrCast(*FlatpakHostCommand, @alignCast(@alignOf(FlatpakHostCommand), ud));
|
const self = @as(*FlatpakHostCommand, @ptrCast(@alignCast(ud)));
|
||||||
const state = state: {
|
const state = state: {
|
||||||
self.state_mutex.lock();
|
self.state_mutex.lock();
|
||||||
defer self.state_mutex.unlock();
|
defer self.state_mutex.unlock();
|
||||||
|
@ -16,7 +16,7 @@ pub fn clickInterval() ?u32 {
|
|||||||
|
|
||||||
// Get the interval and convert to ms
|
// Get the interval and convert to ms
|
||||||
const interval = NSEvent.msgSend(f64, objc.sel("doubleClickInterval"), .{});
|
const interval = NSEvent.msgSend(f64, objc.sel("doubleClickInterval"), .{});
|
||||||
const ms = @intFromFloat(u32, @ceil(interval * 1000));
|
const ms = @as(u32, @intFromFloat(@ceil(interval * 1000)));
|
||||||
return ms;
|
return ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ pub fn toHostOwned(ptr: anytype) ![*]u8 {
|
|||||||
const info = @typeInfo(@TypeOf(ptr)).Pointer;
|
const info = @typeInfo(@TypeOf(ptr)).Pointer;
|
||||||
const T = info.child;
|
const T = info.child;
|
||||||
const size = @sizeOf(T);
|
const size = @sizeOf(T);
|
||||||
const casted = @ptrFromInt([*]u8, @intFromPtr(ptr));
|
const casted = @as([*]u8, @ptrFromInt(@intFromPtr(ptr)));
|
||||||
|
|
||||||
// Store the information about it
|
// Store the information about it
|
||||||
try allocs.putNoClobber(alloc, casted, size);
|
try allocs.putNoClobber(alloc, casted, size);
|
||||||
@ -81,14 +81,14 @@ pub fn toHostOwned(ptr: anytype) ![*]u8 {
|
|||||||
|
|
||||||
/// Returns true if the value is host owned.
|
/// Returns true if the value is host owned.
|
||||||
pub fn isHostOwned(ptr: anytype) bool {
|
pub fn isHostOwned(ptr: anytype) bool {
|
||||||
const casted = @ptrFromInt([*]u8, @intFromPtr(ptr));
|
const casted = @as([*]u8, @ptrFromInt(@intFromPtr(ptr)));
|
||||||
return allocs.contains(casted);
|
return allocs.contains(casted);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a pointer back to a module-owned value. The caller is expected
|
/// Convert a pointer back to a module-owned value. The caller is expected
|
||||||
/// to cast or have the valid pointer for alloc calls.
|
/// to cast or have the valid pointer for alloc calls.
|
||||||
pub fn toModuleOwned(ptr: anytype) void {
|
pub fn toModuleOwned(ptr: anytype) void {
|
||||||
const casted = @ptrFromInt([*]u8, @intFromPtr(ptr));
|
const casted = @as([*]u8, @ptrFromInt(@intFromPtr(ptr)));
|
||||||
_ = allocs.remove(casted);
|
_ = allocs.remove(casted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ pub const Target = enum {
|
|||||||
|
|
||||||
/// Our specific target platform.
|
/// Our specific target platform.
|
||||||
pub const target: ?Target = if (!builtin.target.isWasm()) null else target: {
|
pub const target: ?Target = if (!builtin.target.isWasm()) null else target: {
|
||||||
const result = @enumFromInt(Target, @intFromEnum(options.wasm_target));
|
const result = @as(Target, @enumFromInt(@intFromEnum(options.wasm_target)));
|
||||||
// This maybe isn't necessary but I don't know if enums without a specific
|
// This maybe isn't necessary but I don't know if enums without a specific
|
||||||
// tag type and value are guaranteed to be the same between build.zig
|
// tag type and value are guaranteed to be the same between build.zig
|
||||||
// compilation and our own source compilation so I have this just in case.
|
// compilation and our own source compilation so I have this just in case.
|
||||||
|
@ -213,10 +213,10 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
|
|||||||
|
|
||||||
// Set the sprite font up
|
// Set the sprite font up
|
||||||
options.font_group.group.sprite = font.sprite.Face{
|
options.font_group.group.sprite = font.sprite.Face{
|
||||||
.width = @intFromFloat(u32, metrics.cell_width),
|
.width = @intFromFloat(metrics.cell_width),
|
||||||
.height = @intFromFloat(u32, metrics.cell_height),
|
.height = @intFromFloat(metrics.cell_height),
|
||||||
.thickness = 2,
|
.thickness = 2,
|
||||||
.underline_position = @intFromFloat(u32, metrics.underline_position),
|
.underline_position = @intFromFloat(metrics.underline_position),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the font shaper. We initially create a shaper that can support
|
// Create the font shaper. We initially create a shaper that can support
|
||||||
@ -238,8 +238,8 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
|
|||||||
objc.Object,
|
objc.Object,
|
||||||
objc.sel("newBufferWithBytes:length:options:"),
|
objc.sel("newBufferWithBytes:length:options:"),
|
||||||
.{
|
.{
|
||||||
@ptrCast(*const anyopaque, &data),
|
@as(*const anyopaque, @ptrCast(&data)),
|
||||||
@intCast(c_ulong, data.len * @sizeOf(u16)),
|
@as(c_ulong, @intCast(data.len * @sizeOf(u16))),
|
||||||
MTLResourceStorageModeShared,
|
MTLResourceStorageModeShared,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -254,7 +254,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
|
|||||||
objc.Object,
|
objc.Object,
|
||||||
objc.sel("newBufferWithLength:options:"),
|
objc.sel("newBufferWithLength:options:"),
|
||||||
.{
|
.{
|
||||||
@intCast(c_ulong, prealloc * @sizeOf(GPUCell)),
|
@as(c_ulong, @intCast(prealloc * @sizeOf(GPUCell))),
|
||||||
MTLResourceStorageModeShared,
|
MTLResourceStorageModeShared,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -269,7 +269,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
|
|||||||
objc.Object,
|
objc.Object,
|
||||||
objc.sel("newBufferWithLength:options:"),
|
objc.sel("newBufferWithLength:options:"),
|
||||||
.{
|
.{
|
||||||
@intCast(c_ulong, prealloc * @sizeOf(GPUCell)),
|
@as(c_ulong, @intCast(prealloc * @sizeOf(GPUCell))),
|
||||||
MTLResourceStorageModeShared,
|
MTLResourceStorageModeShared,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -362,7 +362,7 @@ pub fn finalizeSurfaceInit(self: *const Metal, surface: *apprt.Surface) !void {
|
|||||||
|
|
||||||
apprt.embedded => .{
|
apprt.embedded => .{
|
||||||
.view = surface.nsview,
|
.view = surface.nsview,
|
||||||
.scaleFactor = @floatCast(f64, surface.content_scale.x),
|
.scaleFactor = @floatCast(surface.content_scale.x),
|
||||||
},
|
},
|
||||||
|
|
||||||
else => @compileError("unsupported apprt for metal"),
|
else => @compileError("unsupported apprt for metal"),
|
||||||
@ -383,10 +383,7 @@ pub fn finalizeSurfaceInit(self: *const Metal, surface: *apprt.Surface) !void {
|
|||||||
pub fn initDevMode(self: *const Metal, surface: *apprt.Surface) !void {
|
pub fn initDevMode(self: *const Metal, surface: *apprt.Surface) !void {
|
||||||
if (DevMode.enabled) {
|
if (DevMode.enabled) {
|
||||||
// Initialize for our window
|
// Initialize for our window
|
||||||
assert(imgui.ImplGlfw.initForOther(
|
assert(imgui.ImplGlfw.initForOther(@ptrCast(surface.window.handle), true));
|
||||||
@ptrCast(*imgui.ImplGlfw.GLFWWindow, surface.window.handle),
|
|
||||||
true,
|
|
||||||
));
|
|
||||||
assert(imgui.ImplMetal.init(self.device.value));
|
assert(imgui.ImplMetal.init(self.device.value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -480,10 +477,10 @@ pub fn setFontSize(self: *Metal, size: font.face.DesiredSize) !void {
|
|||||||
|
|
||||||
// Set the sprite font up
|
// Set the sprite font up
|
||||||
self.font_group.group.sprite = font.sprite.Face{
|
self.font_group.group.sprite = font.sprite.Face{
|
||||||
.width = @intFromFloat(u32, self.cell_size.width),
|
.width = @intFromFloat(self.cell_size.width),
|
||||||
.height = @intFromFloat(u32, self.cell_size.height),
|
.height = @intFromFloat(self.cell_size.height),
|
||||||
.thickness = 2,
|
.thickness = 2,
|
||||||
.underline_position = @intFromFloat(u32, metrics.underline_position),
|
.underline_position = @intFromFloat(metrics.underline_position),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Notify the window that the cell size changed.
|
// Notify the window that the cell size changed.
|
||||||
@ -622,9 +619,9 @@ pub fn render(
|
|||||||
attachment.setProperty("storeAction", @intFromEnum(MTLStoreAction.store));
|
attachment.setProperty("storeAction", @intFromEnum(MTLStoreAction.store));
|
||||||
attachment.setProperty("texture", texture);
|
attachment.setProperty("texture", texture);
|
||||||
attachment.setProperty("clearColor", MTLClearColor{
|
attachment.setProperty("clearColor", MTLClearColor{
|
||||||
.red = @floatFromInt(f32, critical.bg.r) / 255,
|
.red = @as(f32, @floatFromInt(critical.bg.r)) / 255,
|
||||||
.green = @floatFromInt(f32, critical.bg.g) / 255,
|
.green = @as(f32, @floatFromInt(critical.bg.g)) / 255,
|
||||||
.blue = @floatFromInt(f32, critical.bg.b) / 255,
|
.blue = @as(f32, @floatFromInt(critical.bg.b)) / 255,
|
||||||
.alpha = 1.0,
|
.alpha = 1.0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -651,7 +648,7 @@ pub fn render(
|
|||||||
void,
|
void,
|
||||||
objc.sel("setVertexBytes:length:atIndex:"),
|
objc.sel("setVertexBytes:length:atIndex:"),
|
||||||
.{
|
.{
|
||||||
@ptrCast(*const anyopaque, &self.uniforms),
|
@as(*const anyopaque, @ptrCast(&self.uniforms)),
|
||||||
@as(c_ulong, @sizeOf(@TypeOf(self.uniforms))),
|
@as(c_ulong, @sizeOf(@TypeOf(self.uniforms))),
|
||||||
@as(c_ulong, 1),
|
@as(c_ulong, 1),
|
||||||
},
|
},
|
||||||
@ -771,8 +768,8 @@ pub fn setScreenSize(self: *Metal, dim: renderer.ScreenSize) !void {
|
|||||||
|
|
||||||
// Set the size of the drawable surface to the bounds
|
// Set the size of the drawable surface to the bounds
|
||||||
self.swapchain.setProperty("drawableSize", macos.graphics.Size{
|
self.swapchain.setProperty("drawableSize", macos.graphics.Size{
|
||||||
.width = @floatFromInt(f64, dim.width),
|
.width = @floatFromInt(dim.width),
|
||||||
.height = @floatFromInt(f64, dim.height),
|
.height = @floatFromInt(dim.height),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Setup our uniforms
|
// Setup our uniforms
|
||||||
@ -780,8 +777,8 @@ pub fn setScreenSize(self: *Metal, dim: renderer.ScreenSize) !void {
|
|||||||
self.uniforms = .{
|
self.uniforms = .{
|
||||||
.projection_matrix = math.ortho2d(
|
.projection_matrix = math.ortho2d(
|
||||||
-1 * padding.left,
|
-1 * padding.left,
|
||||||
@floatFromInt(f32, padded_dim.width) + padding.right,
|
@as(f32, @floatFromInt(padded_dim.width)) + padding.right,
|
||||||
@floatFromInt(f32, padded_dim.height) + padding.bottom,
|
@as(f32, @floatFromInt(padded_dim.height)) + padding.bottom,
|
||||||
-1 * padding.top,
|
-1 * padding.top,
|
||||||
),
|
),
|
||||||
.cell_size = .{ self.cell_size.width, self.cell_size.height },
|
.cell_size = .{ self.cell_size.width, self.cell_size.height },
|
||||||
@ -836,7 +833,7 @@ fn rebuildCells(
|
|||||||
y == screen.cursor.y)
|
y == screen.cursor.y)
|
||||||
{
|
{
|
||||||
for (self.cells.items[start_i..]) |cell| {
|
for (self.cells.items[start_i..]) |cell| {
|
||||||
if (cell.grid_pos[0] == @floatFromInt(f32, screen.cursor.x) and
|
if (cell.grid_pos[0] == @as(f32, @floatFromInt(screen.cursor.x)) and
|
||||||
cell.mode == .fg)
|
cell.mode == .fg)
|
||||||
{
|
{
|
||||||
cursor_cell = cell;
|
cursor_cell = cell;
|
||||||
@ -986,7 +983,7 @@ pub fn updateCell(
|
|||||||
if (colors.bg) |rgb| {
|
if (colors.bg) |rgb| {
|
||||||
self.cells_bg.appendAssumeCapacity(.{
|
self.cells_bg.appendAssumeCapacity(.{
|
||||||
.mode = .bg,
|
.mode = .bg,
|
||||||
.grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) },
|
.grid_pos = .{ @as(f32, @floatFromInt(x)), @as(f32, @floatFromInt(y)) },
|
||||||
.cell_width = cell.widthLegacy(),
|
.cell_width = cell.widthLegacy(),
|
||||||
.color = .{ rgb.r, rgb.g, rgb.b, alpha },
|
.color = .{ rgb.r, rgb.g, rgb.b, alpha },
|
||||||
});
|
});
|
||||||
@ -999,7 +996,7 @@ pub fn updateCell(
|
|||||||
self.alloc,
|
self.alloc,
|
||||||
shaper_run.font_index,
|
shaper_run.font_index,
|
||||||
shaper_cell.glyph_index,
|
shaper_cell.glyph_index,
|
||||||
@intFromFloat(u16, @ceil(self.cell_size.height)),
|
@intFromFloat(@ceil(self.cell_size.height)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// If we're rendering a color font, we use the color atlas
|
// If we're rendering a color font, we use the color atlas
|
||||||
@ -1011,7 +1008,7 @@ pub fn updateCell(
|
|||||||
|
|
||||||
self.cells.appendAssumeCapacity(.{
|
self.cells.appendAssumeCapacity(.{
|
||||||
.mode = mode,
|
.mode = mode,
|
||||||
.grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) },
|
.grid_pos = .{ @as(f32, @floatFromInt(x)), @as(f32, @floatFromInt(y)) },
|
||||||
.cell_width = cell.widthLegacy(),
|
.cell_width = cell.widthLegacy(),
|
||||||
.color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha },
|
.color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha },
|
||||||
.glyph_pos = .{ glyph.atlas_x, glyph.atlas_y },
|
.glyph_pos = .{ glyph.atlas_x, glyph.atlas_y },
|
||||||
@ -1041,7 +1038,7 @@ pub fn updateCell(
|
|||||||
|
|
||||||
self.cells.appendAssumeCapacity(.{
|
self.cells.appendAssumeCapacity(.{
|
||||||
.mode = .fg,
|
.mode = .fg,
|
||||||
.grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) },
|
.grid_pos = .{ @as(f32, @floatFromInt(x)), @as(f32, @floatFromInt(y)) },
|
||||||
.cell_width = cell.widthLegacy(),
|
.cell_width = cell.widthLegacy(),
|
||||||
.color = .{ color.r, color.g, color.b, alpha },
|
.color = .{ color.r, color.g, color.b, alpha },
|
||||||
.glyph_pos = .{ glyph.atlas_x, glyph.atlas_y },
|
.glyph_pos = .{ glyph.atlas_x, glyph.atlas_y },
|
||||||
@ -1053,7 +1050,7 @@ pub fn updateCell(
|
|||||||
if (cell.attrs.strikethrough) {
|
if (cell.attrs.strikethrough) {
|
||||||
self.cells.appendAssumeCapacity(.{
|
self.cells.appendAssumeCapacity(.{
|
||||||
.mode = .strikethrough,
|
.mode = .strikethrough,
|
||||||
.grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) },
|
.grid_pos = .{ @as(f32, @floatFromInt(x)), @as(f32, @floatFromInt(y)) },
|
||||||
.cell_width = cell.widthLegacy(),
|
.cell_width = cell.widthLegacy(),
|
||||||
.color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha },
|
.color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha },
|
||||||
});
|
});
|
||||||
@ -1095,8 +1092,8 @@ fn addCursor(self: *Metal, screen: *terminal.Screen) void {
|
|||||||
self.cells.appendAssumeCapacity(.{
|
self.cells.appendAssumeCapacity(.{
|
||||||
.mode = .fg,
|
.mode = .fg,
|
||||||
.grid_pos = .{
|
.grid_pos = .{
|
||||||
@floatFromInt(f32, screen.cursor.x),
|
@as(f32, @floatFromInt(screen.cursor.x)),
|
||||||
@floatFromInt(f32, screen.cursor.y),
|
@as(f32, @floatFromInt(screen.cursor.y)),
|
||||||
},
|
},
|
||||||
.cell_width = if (cell.attrs.wide) 2 else 1,
|
.cell_width = if (cell.attrs.wide) 2 else 1,
|
||||||
.color = .{ color.r, color.g, color.b, 0xFF },
|
.color = .{ color.r, color.g, color.b, 0xFF },
|
||||||
@ -1128,7 +1125,7 @@ fn syncCells(
|
|||||||
objc.Object,
|
objc.Object,
|
||||||
objc.sel("newBufferWithLength:options:"),
|
objc.sel("newBufferWithLength:options:"),
|
||||||
.{
|
.{
|
||||||
@intCast(c_ulong, size * @sizeOf(GPUCell)),
|
@as(c_ulong, @intCast(size * @sizeOf(GPUCell))),
|
||||||
MTLResourceStorageModeShared,
|
MTLResourceStorageModeShared,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -1145,7 +1142,7 @@ fn syncCells(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const src = src: {
|
const src = src: {
|
||||||
const ptr = @ptrCast([*]const u8, cells.items.ptr);
|
const ptr = @as([*]const u8, @ptrCast(cells.items.ptr));
|
||||||
break :src ptr[0..req_bytes];
|
break :src ptr[0..req_bytes];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1172,12 +1169,12 @@ fn syncAtlasTexture(device: objc.Object, atlas: *const font.Atlas, texture: *obj
|
|||||||
MTLRegion{
|
MTLRegion{
|
||||||
.origin = .{ .x = 0, .y = 0, .z = 0 },
|
.origin = .{ .x = 0, .y = 0, .z = 0 },
|
||||||
.size = .{
|
.size = .{
|
||||||
.width = @intCast(c_ulong, atlas.size),
|
.width = @intCast(atlas.size),
|
||||||
.height = @intCast(c_ulong, atlas.size),
|
.height = @intCast(atlas.size),
|
||||||
.depth = 1,
|
.depth = 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@as(c_ulong, 0),
|
0,
|
||||||
atlas.data.ptr,
|
atlas.data.ptr,
|
||||||
@as(c_ulong, atlas.format.depth() * atlas.size),
|
@as(c_ulong, atlas.format.depth() * atlas.size),
|
||||||
);
|
);
|
||||||
@ -1440,8 +1437,8 @@ fn initAtlasTexture(device: objc.Object, atlas: *const font.Atlas) !objc.Object
|
|||||||
|
|
||||||
// Set our properties
|
// Set our properties
|
||||||
desc.setProperty("pixelFormat", @intFromEnum(pixel_format));
|
desc.setProperty("pixelFormat", @intFromEnum(pixel_format));
|
||||||
desc.setProperty("width", @intCast(c_ulong, atlas.size));
|
desc.setProperty("width", @as(c_ulong, @intCast(atlas.size)));
|
||||||
desc.setProperty("height", @intCast(c_ulong, atlas.size));
|
desc.setProperty("height", @as(c_ulong, @intCast(atlas.size)));
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
const id = device.msgSend(
|
const id = device.msgSend(
|
||||||
@ -1462,9 +1459,9 @@ fn deinitMTLResource(obj: objc.Object) void {
|
|||||||
fn checkError(err_: ?*anyopaque) !void {
|
fn checkError(err_: ?*anyopaque) !void {
|
||||||
if (err_) |err| {
|
if (err_) |err| {
|
||||||
const nserr = objc.Object.fromId(err);
|
const nserr = objc.Object.fromId(err);
|
||||||
const str = @ptrCast(
|
const str = @as(
|
||||||
*macos.foundation.String,
|
*macos.foundation.String,
|
||||||
nserr.getProperty(?*anyopaque, "localizedDescription").?,
|
@ptrCast(nserr.getProperty(?*anyopaque, "localizedDescription").?),
|
||||||
);
|
);
|
||||||
|
|
||||||
log.err("metal error={s}", .{str.cstringPtr(.ascii).?});
|
log.err("metal error={s}", .{str.cstringPtr(.ascii).?});
|
||||||
|
@ -136,8 +136,8 @@ const SetScreenSize = struct {
|
|||||||
try gl.viewport(
|
try gl.viewport(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@intCast(i32, self.size.width),
|
@intCast(self.size.width),
|
||||||
@intCast(i32, self.size.height),
|
@intCast(self.size.height),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update the projection uniform within our shader
|
// Update the projection uniform within our shader
|
||||||
@ -147,8 +147,8 @@ const SetScreenSize = struct {
|
|||||||
// 2D orthographic projection with the full w/h
|
// 2D orthographic projection with the full w/h
|
||||||
math.ortho2d(
|
math.ortho2d(
|
||||||
-1 * padding.left,
|
-1 * padding.left,
|
||||||
@floatFromInt(f32, padded_size.width) + padding.right,
|
@as(f32, @floatFromInt(padded_size.width)) + padding.right,
|
||||||
@floatFromInt(f32, padded_size.height) + padding.bottom,
|
@as(f32, @floatFromInt(padded_size.height)) + padding.bottom,
|
||||||
-1 * padding.top,
|
-1 * padding.top,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -218,10 +218,7 @@ const GPUCellMode = enum(u8) {
|
|||||||
|
|
||||||
/// Apply a mask to the mode.
|
/// Apply a mask to the mode.
|
||||||
pub fn mask(self: GPUCellMode, m: GPUCellMode) GPUCellMode {
|
pub fn mask(self: GPUCellMode, m: GPUCellMode) GPUCellMode {
|
||||||
return @enumFromInt(
|
return @enumFromInt(@intFromEnum(self) | @intFromEnum(m));
|
||||||
GPUCellMode,
|
|
||||||
@intFromEnum(self) | @intFromEnum(m),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -357,8 +354,8 @@ pub fn init(alloc: Allocator, options: renderer.Options) !OpenGL {
|
|||||||
try texbind.image2D(
|
try texbind.image2D(
|
||||||
0,
|
0,
|
||||||
.Red,
|
.Red,
|
||||||
@intCast(c_int, options.font_group.atlas_greyscale.size),
|
@intCast(options.font_group.atlas_greyscale.size),
|
||||||
@intCast(c_int, options.font_group.atlas_greyscale.size),
|
@intCast(options.font_group.atlas_greyscale.size),
|
||||||
0,
|
0,
|
||||||
.Red,
|
.Red,
|
||||||
.UnsignedByte,
|
.UnsignedByte,
|
||||||
@ -378,8 +375,8 @@ pub fn init(alloc: Allocator, options: renderer.Options) !OpenGL {
|
|||||||
try texbind.image2D(
|
try texbind.image2D(
|
||||||
0,
|
0,
|
||||||
.RGBA,
|
.RGBA,
|
||||||
@intCast(c_int, options.font_group.atlas_color.size),
|
@intCast(options.font_group.atlas_color.size),
|
||||||
@intCast(c_int, options.font_group.atlas_color.size),
|
@intCast(options.font_group.atlas_color.size),
|
||||||
0,
|
0,
|
||||||
.BGRA,
|
.BGRA,
|
||||||
.UnsignedByte,
|
.UnsignedByte,
|
||||||
@ -476,8 +473,8 @@ pub fn surfaceInit(surface: *apprt.Surface) !void {
|
|||||||
const version = try gl.glad.load(null);
|
const version = try gl.glad.load(null);
|
||||||
errdefer gl.glad.unload();
|
errdefer gl.glad.unload();
|
||||||
log.info("loaded OpenGL {}.{}", .{
|
log.info("loaded OpenGL {}.{}", .{
|
||||||
gl.glad.versionMajor(@intCast(c_uint, version)),
|
gl.glad.versionMajor(@intCast(version)),
|
||||||
gl.glad.versionMinor(@intCast(c_uint, version)),
|
gl.glad.versionMinor(@intCast(version)),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -515,7 +512,7 @@ pub fn initDevMode(self: *const OpenGL, surface: *apprt.Surface) !void {
|
|||||||
if (DevMode.enabled) {
|
if (DevMode.enabled) {
|
||||||
// Initialize for our window
|
// Initialize for our window
|
||||||
assert(imgui.ImplGlfw.initForOpenGL(
|
assert(imgui.ImplGlfw.initForOpenGL(
|
||||||
@ptrCast(*imgui.ImplGlfw.GLFWWindow, surface.window.handle),
|
@ptrCast(surface.window.handle),
|
||||||
true,
|
true,
|
||||||
));
|
));
|
||||||
assert(imgui.ImplOpenGL3.init("#version 330 core"));
|
assert(imgui.ImplOpenGL3.init("#version 330 core"));
|
||||||
@ -561,8 +558,8 @@ pub fn threadEnter(self: *const OpenGL, surface: *apprt.Surface) !void {
|
|||||||
const version = try gl.glad.load(&glfw.getProcAddress);
|
const version = try gl.glad.load(&glfw.getProcAddress);
|
||||||
errdefer gl.glad.unload();
|
errdefer gl.glad.unload();
|
||||||
log.info("loaded OpenGL {}.{}", .{
|
log.info("loaded OpenGL {}.{}", .{
|
||||||
gl.glad.versionMajor(@intCast(c_uint, version)),
|
gl.glad.versionMajor(@intCast(version)),
|
||||||
gl.glad.versionMinor(@intCast(c_uint, version)),
|
gl.glad.versionMinor(@intCast(version)),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -661,10 +658,10 @@ fn resetFontMetrics(
|
|||||||
|
|
||||||
// Set details for our sprite font
|
// Set details for our sprite font
|
||||||
font_group.group.sprite = font.sprite.Face{
|
font_group.group.sprite = font.sprite.Face{
|
||||||
.width = @intFromFloat(u32, metrics.cell_width),
|
.width = @intFromFloat(metrics.cell_width),
|
||||||
.height = @intFromFloat(u32, metrics.cell_height),
|
.height = @intFromFloat(metrics.cell_height),
|
||||||
.thickness = 2,
|
.thickness = 2,
|
||||||
.underline_position = @intFromFloat(u32, metrics.underline_position),
|
.underline_position = @intFromFloat(metrics.underline_position),
|
||||||
};
|
};
|
||||||
|
|
||||||
return metrics;
|
return metrics;
|
||||||
@ -895,7 +892,7 @@ pub fn rebuildCells(
|
|||||||
var i: usize = self.cells.items.len;
|
var i: usize = self.cells.items.len;
|
||||||
for (gop.value_ptr.items) |cell| {
|
for (gop.value_ptr.items) |cell| {
|
||||||
self.cells.appendAssumeCapacity(cell);
|
self.cells.appendAssumeCapacity(cell);
|
||||||
self.cells.items[i].grid_row = @intCast(u16, y);
|
self.cells.items[i].grid_row = @intCast(y);
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1002,8 +999,8 @@ fn addCursor(self: *OpenGL, screen: *terminal.Screen) void {
|
|||||||
|
|
||||||
self.cells.appendAssumeCapacity(.{
|
self.cells.appendAssumeCapacity(.{
|
||||||
.mode = .fg,
|
.mode = .fg,
|
||||||
.grid_col = @intCast(u16, screen.cursor.x),
|
.grid_col = @intCast(screen.cursor.x),
|
||||||
.grid_row = @intCast(u16, screen.cursor.y),
|
.grid_row = @intCast(screen.cursor.y),
|
||||||
.grid_width = if (cell.attrs.wide) 2 else 1,
|
.grid_width = if (cell.attrs.wide) 2 else 1,
|
||||||
.fg_r = color.r,
|
.fg_r = color.r,
|
||||||
.fg_g = color.g,
|
.fg_g = color.g,
|
||||||
@ -1120,8 +1117,8 @@ pub fn updateCell(
|
|||||||
|
|
||||||
self.cells_bg.appendAssumeCapacity(.{
|
self.cells_bg.appendAssumeCapacity(.{
|
||||||
.mode = mode,
|
.mode = mode,
|
||||||
.grid_col = @intCast(u16, x),
|
.grid_col = @intCast(x),
|
||||||
.grid_row = @intCast(u16, y),
|
.grid_row = @intCast(y),
|
||||||
.grid_width = cell.widthLegacy(),
|
.grid_width = cell.widthLegacy(),
|
||||||
.glyph_x = 0,
|
.glyph_x = 0,
|
||||||
.glyph_y = 0,
|
.glyph_y = 0,
|
||||||
@ -1147,7 +1144,7 @@ pub fn updateCell(
|
|||||||
self.alloc,
|
self.alloc,
|
||||||
shaper_run.font_index,
|
shaper_run.font_index,
|
||||||
shaper_cell.glyph_index,
|
shaper_cell.glyph_index,
|
||||||
@intFromFloat(u16, @ceil(self.cell_size.height)),
|
@intFromFloat(@ceil(self.cell_size.height)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// If we're rendering a color font, we use the color atlas
|
// If we're rendering a color font, we use the color atlas
|
||||||
@ -1159,8 +1156,8 @@ pub fn updateCell(
|
|||||||
|
|
||||||
self.cells.appendAssumeCapacity(.{
|
self.cells.appendAssumeCapacity(.{
|
||||||
.mode = mode,
|
.mode = mode,
|
||||||
.grid_col = @intCast(u16, x),
|
.grid_col = @intCast(x),
|
||||||
.grid_row = @intCast(u16, y),
|
.grid_row = @intCast(y),
|
||||||
.grid_width = cell.widthLegacy(),
|
.grid_width = cell.widthLegacy(),
|
||||||
.glyph_x = glyph.atlas_x,
|
.glyph_x = glyph.atlas_x,
|
||||||
.glyph_y = glyph.atlas_y,
|
.glyph_y = glyph.atlas_y,
|
||||||
@ -1200,8 +1197,8 @@ pub fn updateCell(
|
|||||||
|
|
||||||
self.cells.appendAssumeCapacity(.{
|
self.cells.appendAssumeCapacity(.{
|
||||||
.mode = .fg,
|
.mode = .fg,
|
||||||
.grid_col = @intCast(u16, x),
|
.grid_col = @intCast(x),
|
||||||
.grid_row = @intCast(u16, y),
|
.grid_row = @intCast(y),
|
||||||
.grid_width = cell.widthLegacy(),
|
.grid_width = cell.widthLegacy(),
|
||||||
.glyph_x = underline_glyph.atlas_x,
|
.glyph_x = underline_glyph.atlas_x,
|
||||||
.glyph_y = underline_glyph.atlas_y,
|
.glyph_y = underline_glyph.atlas_y,
|
||||||
@ -1223,8 +1220,8 @@ pub fn updateCell(
|
|||||||
if (cell.attrs.strikethrough) {
|
if (cell.attrs.strikethrough) {
|
||||||
self.cells.appendAssumeCapacity(.{
|
self.cells.appendAssumeCapacity(.{
|
||||||
.mode = .strikethrough,
|
.mode = .strikethrough,
|
||||||
.grid_col = @intCast(u16, x),
|
.grid_col = @intCast(x),
|
||||||
.grid_row = @intCast(u16, y),
|
.grid_row = @intCast(y),
|
||||||
.grid_width = cell.widthLegacy(),
|
.grid_width = cell.widthLegacy(),
|
||||||
.glyph_x = 0,
|
.glyph_x = 0,
|
||||||
.glyph_y = 0,
|
.glyph_y = 0,
|
||||||
@ -1312,8 +1309,8 @@ fn flushAtlas(self: *OpenGL) !void {
|
|||||||
try texbind.image2D(
|
try texbind.image2D(
|
||||||
0,
|
0,
|
||||||
.Red,
|
.Red,
|
||||||
@intCast(c_int, atlas.size),
|
@intCast(atlas.size),
|
||||||
@intCast(c_int, atlas.size),
|
@intCast(atlas.size),
|
||||||
0,
|
0,
|
||||||
.Red,
|
.Red,
|
||||||
.UnsignedByte,
|
.UnsignedByte,
|
||||||
@ -1324,8 +1321,8 @@ fn flushAtlas(self: *OpenGL) !void {
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@intCast(c_int, atlas.size),
|
@intCast(atlas.size),
|
||||||
@intCast(c_int, atlas.size),
|
@intCast(atlas.size),
|
||||||
.Red,
|
.Red,
|
||||||
.UnsignedByte,
|
.UnsignedByte,
|
||||||
atlas.data.ptr,
|
atlas.data.ptr,
|
||||||
@ -1346,8 +1343,8 @@ fn flushAtlas(self: *OpenGL) !void {
|
|||||||
try texbind.image2D(
|
try texbind.image2D(
|
||||||
0,
|
0,
|
||||||
.RGBA,
|
.RGBA,
|
||||||
@intCast(c_int, atlas.size),
|
@intCast(atlas.size),
|
||||||
@intCast(c_int, atlas.size),
|
@intCast(atlas.size),
|
||||||
0,
|
0,
|
||||||
.BGRA,
|
.BGRA,
|
||||||
.UnsignedByte,
|
.UnsignedByte,
|
||||||
@ -1358,8 +1355,8 @@ fn flushAtlas(self: *OpenGL) !void {
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@intCast(c_int, atlas.size),
|
@intCast(atlas.size),
|
||||||
@intCast(c_int, atlas.size),
|
@intCast(atlas.size),
|
||||||
.BGRA,
|
.BGRA,
|
||||||
.UnsignedByte,
|
.UnsignedByte,
|
||||||
atlas.data.ptr,
|
atlas.data.ptr,
|
||||||
@ -1388,9 +1385,9 @@ pub fn draw(self: *OpenGL) !void {
|
|||||||
|
|
||||||
// Clear the surface
|
// Clear the surface
|
||||||
gl.clearColor(
|
gl.clearColor(
|
||||||
@floatFromInt(f32, self.draw_background.r) / 255,
|
@as(f32, @floatFromInt(self.draw_background.r)) / 255,
|
||||||
@floatFromInt(f32, self.draw_background.g) / 255,
|
@as(f32, @floatFromInt(self.draw_background.g)) / 255,
|
||||||
@floatFromInt(f32, self.draw_background.b) / 255,
|
@as(f32, @floatFromInt(self.draw_background.b)) / 255,
|
||||||
1.0,
|
1.0,
|
||||||
);
|
);
|
||||||
gl.clear(gl.c.GL_COLOR_BUFFER_BIT);
|
gl.clear(gl.c.GL_COLOR_BUFFER_BIT);
|
||||||
|
@ -54,7 +54,7 @@ pub const Binding = struct {
|
|||||||
data: anytype,
|
data: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
const info = dataInfo(data);
|
const info = dataInfo(data);
|
||||||
glad.context.BufferSubData.?(@intFromEnum(b.target), @intCast(c_long, offset), info.size, info.ptr);
|
glad.context.BufferSubData.?(@intFromEnum(b.target), @intCast(offset), info.size, info.ptr);
|
||||||
try errors.getError();
|
try errors.getError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ pub const Binding = struct {
|
|||||||
size: usize,
|
size: usize,
|
||||||
usage: Usage,
|
usage: Usage,
|
||||||
) !void {
|
) !void {
|
||||||
glad.context.BufferData.?(@intFromEnum(b.target), @intCast(c_long, size), null, @intFromEnum(usage));
|
glad.context.BufferData.?(@intFromEnum(b.target), @intCast(size), null, @intFromEnum(usage));
|
||||||
try errors.getError();
|
try errors.getError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ pub const Binding = struct {
|
|||||||
.ptr = data,
|
.ptr = data,
|
||||||
},
|
},
|
||||||
.Slice => .{
|
.Slice => .{
|
||||||
.size = @intCast(isize, @sizeOf(ptr.child) * data.len),
|
.size = @intCast(@sizeOf(ptr.child) * data.len),
|
||||||
.ptr = data.ptr,
|
.ptr = data.ptr,
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
@ -169,7 +169,7 @@ pub const Binding = struct {
|
|||||||
) !void {
|
) !void {
|
||||||
const normalized_c: c.GLboolean = if (normalized) c.GL_TRUE else c.GL_FALSE;
|
const normalized_c: c.GLboolean = if (normalized) c.GL_TRUE else c.GL_FALSE;
|
||||||
const offsetPtr = if (offset > 0)
|
const offsetPtr = if (offset > 0)
|
||||||
@ptrFromInt(*const anyopaque, offset)
|
@as(*const anyopaque, @ptrFromInt(offset))
|
||||||
else
|
else
|
||||||
null;
|
null;
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ pub const Binding = struct {
|
|||||||
offset: usize,
|
offset: usize,
|
||||||
) !void {
|
) !void {
|
||||||
const offsetPtr = if (offset > 0)
|
const offsetPtr = if (offset > 0)
|
||||||
@ptrFromInt(*const anyopaque, offset)
|
@as(*const anyopaque, @ptrFromInt(offset))
|
||||||
else
|
else
|
||||||
null;
|
null;
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ pub inline fn setUniform(
|
|||||||
) !void {
|
) !void {
|
||||||
const loc = glad.context.GetUniformLocation.?(
|
const loc = glad.context.GetUniformLocation.?(
|
||||||
p.id,
|
p.id,
|
||||||
@ptrCast([*c]const u8, n.ptr),
|
@ptrCast(n.ptr),
|
||||||
);
|
);
|
||||||
if (loc < 0) {
|
if (loc < 0) {
|
||||||
return error.UniformNameInvalid;
|
return error.UniformNameInvalid;
|
||||||
@ -99,7 +99,7 @@ pub inline fn setUniform(
|
|||||||
loc,
|
loc,
|
||||||
1,
|
1,
|
||||||
c.GL_FALSE,
|
c.GL_FALSE,
|
||||||
@ptrCast([*c]const f32, &value),
|
@ptrCast(&value),
|
||||||
),
|
),
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ pub inline fn create(typ: c.GLenum) errors.Error!Shader {
|
|||||||
|
|
||||||
/// Set the source and compile a shader.
|
/// Set the source and compile a shader.
|
||||||
pub inline fn setSourceAndCompile(s: Shader, source: [:0]const u8) !void {
|
pub inline fn setSourceAndCompile(s: Shader, source: [:0]const u8) !void {
|
||||||
glad.context.ShaderSource.?(s.id, 1, &@ptrCast([*c]const u8, source), null);
|
glad.context.ShaderSource.?(s.id, 1, &@as([*c]const u8, @ptrCast(source)), null);
|
||||||
glad.context.CompileShader.?(s.id);
|
glad.context.CompileShader.?(s.id);
|
||||||
|
|
||||||
// Check if compilation succeeded
|
// Check if compilation succeeded
|
||||||
|
@ -16,7 +16,7 @@ pub fn drawArrays(mode: c.GLenum, first: c.GLint, count: c.GLsizei) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn drawElements(mode: c.GLenum, count: c.GLsizei, typ: c.GLenum, offset: usize) !void {
|
pub fn drawElements(mode: c.GLenum, count: c.GLsizei, typ: c.GLenum, offset: usize) !void {
|
||||||
const offsetPtr = if (offset == 0) null else @ptrFromInt(*const anyopaque, offset);
|
const offsetPtr = if (offset == 0) null else @as(*const anyopaque, @ptrFromInt(offset));
|
||||||
glad.context.DrawElements.?(mode, count, typ, offsetPtr);
|
glad.context.DrawElements.?(mode, count, typ, offsetPtr);
|
||||||
try errors.getError();
|
try errors.getError();
|
||||||
}
|
}
|
||||||
@ -27,7 +27,7 @@ pub fn drawElementsInstanced(
|
|||||||
typ: c.GLenum,
|
typ: c.GLenum,
|
||||||
primcount: usize,
|
primcount: usize,
|
||||||
) !void {
|
) !void {
|
||||||
glad.context.DrawElementsInstanced.?(mode, count, typ, null, @intCast(c.GLsizei, primcount));
|
glad.context.DrawElementsInstanced.?(mode, count, typ, null, @intCast(primcount));
|
||||||
try errors.getError();
|
try errors.getError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ pub fn len() !u32 {
|
|||||||
var n: c.GLint = undefined;
|
var n: c.GLint = undefined;
|
||||||
glad.context.GetIntegerv.?(c.GL_NUM_EXTENSIONS, &n);
|
glad.context.GetIntegerv.?(c.GL_NUM_EXTENSIONS, &n);
|
||||||
try errors.getError();
|
try errors.getError();
|
||||||
return @intCast(u32, n);
|
return @intCast(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator for the extensions.
|
/// Returns an iterator for the extensions.
|
||||||
|
@ -18,10 +18,7 @@ pub fn load(getProcAddress: anytype) !c_int {
|
|||||||
|
|
||||||
const res = switch (@TypeOf(getProcAddress)) {
|
const res = switch (@TypeOf(getProcAddress)) {
|
||||||
// glfw
|
// glfw
|
||||||
GlfwFn => c.gladLoadGLContext(&context, @ptrCast(
|
GlfwFn => c.gladLoadGLContext(&context, @ptrCast(getProcAddress)),
|
||||||
*const fn ([*c]const u8) callconv(.C) ?GlProc,
|
|
||||||
getProcAddress,
|
|
||||||
)),
|
|
||||||
|
|
||||||
// null proc address means that we are just loading the globally
|
// null proc address means that we are just loading the globally
|
||||||
// pointed gl functions
|
// pointed gl functions
|
||||||
|
@ -48,8 +48,8 @@ pub const ScreenSize = struct {
|
|||||||
/// Subtract padding from the screen size.
|
/// Subtract padding from the screen size.
|
||||||
pub fn subPadding(self: ScreenSize, padding: Padding) ScreenSize {
|
pub fn subPadding(self: ScreenSize, padding: Padding) ScreenSize {
|
||||||
return .{
|
return .{
|
||||||
.width = self.width -| @intFromFloat(u32, padding.left + padding.right),
|
.width = self.width -| @as(u32, @intFromFloat(padding.left + padding.right)),
|
||||||
.height = self.height -| @intFromFloat(u32, padding.top + padding.bottom),
|
.height = self.height -| @as(u32, @intFromFloat(padding.top + padding.bottom)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -71,8 +71,8 @@ pub const GridSize = struct {
|
|||||||
/// Update the columns/rows for the grid based on the given screen and
|
/// Update the columns/rows for the grid based on the given screen and
|
||||||
/// cell size.
|
/// cell size.
|
||||||
pub fn update(self: *GridSize, screen: ScreenSize, cell: CellSize) void {
|
pub fn update(self: *GridSize, screen: ScreenSize, cell: CellSize) void {
|
||||||
self.columns = @max(1, @intFromFloat(Unit, @floatFromInt(f32, screen.width) / cell.width));
|
self.columns = @max(1, @as(Unit, @intFromFloat(@as(f32, @floatFromInt(screen.width)) / cell.width)));
|
||||||
self.rows = @max(1, @intFromFloat(Unit, @floatFromInt(f32, screen.height) / cell.height));
|
self.rows = @max(1, @as(Unit, @intFromFloat(@as(f32, @floatFromInt(screen.height)) / cell.height)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -87,12 +87,12 @@ pub const Padding = struct {
|
|||||||
/// for the given grid and cell sizes.
|
/// for the given grid and cell sizes.
|
||||||
pub fn balanced(screen: ScreenSize, grid: GridSize, cell: CellSize) Padding {
|
pub fn balanced(screen: ScreenSize, grid: GridSize, cell: CellSize) Padding {
|
||||||
// The size of our full grid
|
// The size of our full grid
|
||||||
const grid_width = @floatFromInt(f32, grid.columns) * cell.width;
|
const grid_width = @as(f32, @floatFromInt(grid.columns)) * cell.width;
|
||||||
const grid_height = @floatFromInt(f32, grid.rows) * cell.height;
|
const grid_height = @as(f32, @floatFromInt(grid.rows)) * cell.height;
|
||||||
|
|
||||||
// The empty space to the right of a line and bottom of the last row
|
// The empty space to the right of a line and bottom of the last row
|
||||||
const space_right = @floatFromInt(f32, screen.width) - grid_width;
|
const space_right = @as(f32, @floatFromInt(screen.width)) - grid_width;
|
||||||
const space_bot = @floatFromInt(f32, screen.height) - grid_height;
|
const space_bot = @as(f32, @floatFromInt(screen.height)) - grid_height;
|
||||||
|
|
||||||
// The left/right padding is just an equal split.
|
// The left/right padding is just an equal split.
|
||||||
const padding_right = @floor(space_right / 2);
|
const padding_right = @floor(space_right / 2);
|
||||||
|
@ -348,8 +348,8 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action {
|
|||||||
|
|
||||||
// If this is our first time seeing a parameter, we track
|
// If this is our first time seeing a parameter, we track
|
||||||
// the separator used so that we can't mix separators later.
|
// the separator used so that we can't mix separators later.
|
||||||
if (self.params_idx == 0) self.params_sep = @enumFromInt(ParamSepState, c);
|
if (self.params_idx == 0) self.params_sep = @enumFromInt(c);
|
||||||
if (@enumFromInt(ParamSepState, c) != self.params_sep) self.params_sep = .mixed;
|
if (@as(ParamSepState, @enumFromInt(c)) != self.params_sep) self.params_sep = .mixed;
|
||||||
|
|
||||||
// Set param final value
|
// Set param final value
|
||||||
self.params[self.params_idx] = self.param_acc;
|
self.params[self.params_idx] = self.param_acc;
|
||||||
|
@ -228,7 +228,7 @@ pub const Cell = struct {
|
|||||||
} });
|
} });
|
||||||
|
|
||||||
// We're empty if we have no char AND we have no styling
|
// We're empty if we have no char AND we have no styling
|
||||||
return self.char == 0 and @bitCast(AttrInt, self.attrs) == 0;
|
return self.char == 0 and @as(AttrInt, @bitCast(self.attrs)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The width of the cell.
|
/// The width of the cell.
|
||||||
@ -967,7 +967,7 @@ pub fn getRow(self: *Screen, index: RowIndex) Row {
|
|||||||
if (row.storage[0].header.id == 0) {
|
if (row.storage[0].header.id == 0) {
|
||||||
const Id = @TypeOf(self.next_row_id);
|
const Id = @TypeOf(self.next_row_id);
|
||||||
const id = self.next_row_id;
|
const id = self.next_row_id;
|
||||||
self.next_row_id +%= @intCast(Id, self.cols);
|
self.next_row_id +%= @as(Id, @intCast(self.cols));
|
||||||
|
|
||||||
// Store the header
|
// Store the header
|
||||||
row.storage[0].header.id = id;
|
row.storage[0].header.id = id;
|
||||||
@ -1463,7 +1463,7 @@ fn scrollDelta(self: *Screen, delta: isize, grow: bool) !void {
|
|||||||
// If we're scrolling up, then we just subtract and we're done.
|
// If we're scrolling up, then we just subtract and we're done.
|
||||||
// We just clamp at 0 which blocks us from scrolling off the top.
|
// We just clamp at 0 which blocks us from scrolling off the top.
|
||||||
if (delta < 0) {
|
if (delta < 0) {
|
||||||
self.viewport -|= @intCast(usize, -delta);
|
self.viewport -|= @as(usize, @intCast(-delta));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1472,7 +1472,7 @@ fn scrollDelta(self: *Screen, delta: isize, grow: bool) !void {
|
|||||||
if (!grow) {
|
if (!grow) {
|
||||||
self.viewport = @min(
|
self.viewport = @min(
|
||||||
self.history,
|
self.history,
|
||||||
self.viewport + @intCast(usize, delta),
|
self.viewport + @as(usize, @intCast(delta)),
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1480,7 +1480,7 @@ fn scrollDelta(self: *Screen, delta: isize, grow: bool) !void {
|
|||||||
// Add our delta to our viewport. If we're less than the max currently
|
// Add our delta to our viewport. If we're less than the max currently
|
||||||
// allowed to scroll to the bottom (the end of the history), then we
|
// allowed to scroll to the bottom (the end of the history), then we
|
||||||
// have space and we just return.
|
// have space and we just return.
|
||||||
self.viewport += @intCast(usize, delta);
|
self.viewport += @as(usize, @intCast(delta));
|
||||||
if (self.viewport <= self.history) return;
|
if (self.viewport <= self.history) return;
|
||||||
|
|
||||||
// If our viewport is past the top of our history then we potentially need
|
// If our viewport is past the top of our history then we potentially need
|
||||||
@ -1614,7 +1614,7 @@ pub fn selectionString(
|
|||||||
|
|
||||||
var buf: [4]u8 = undefined;
|
var buf: [4]u8 = undefined;
|
||||||
const char = if (cell.cell.char > 0) cell.cell.char else ' ';
|
const char = if (cell.cell.char > 0) cell.cell.char else ' ';
|
||||||
count += try std.unicode.utf8Encode(@intCast(u21, char), &buf);
|
count += try std.unicode.utf8Encode(@intCast(char), &buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1658,7 +1658,7 @@ pub fn selectionString(
|
|||||||
cell.attrs.wide_spacer_tail) continue;
|
cell.attrs.wide_spacer_tail) continue;
|
||||||
|
|
||||||
const char = if (cell.char > 0) cell.char else ' ';
|
const char = if (cell.char > 0) cell.char else ' ';
|
||||||
buf_i += try std.unicode.utf8Encode(@intCast(u21, char), buf[buf_i..]);
|
buf_i += try std.unicode.utf8Encode(@intCast(char), buf[buf_i..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this row is not soft-wrapped, add a newline
|
// If this row is not soft-wrapped, add a newline
|
||||||
@ -2293,7 +2293,7 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void {
|
|||||||
if (grapheme.cell) |prev_cell| {
|
if (grapheme.cell) |prev_cell| {
|
||||||
const grapheme_break = brk: {
|
const grapheme_break = brk: {
|
||||||
var state: i32 = 0;
|
var state: i32 = 0;
|
||||||
var cp1 = @intCast(u21, prev_cell.char);
|
var cp1 = @as(u21, @intCast(prev_cell.char));
|
||||||
if (prev_cell.attrs.grapheme) {
|
if (prev_cell.attrs.grapheme) {
|
||||||
var it = row.codepointIterator(grapheme.x);
|
var it = row.codepointIterator(grapheme.x);
|
||||||
while (it.next()) |cp2| {
|
while (it.next()) |cp2| {
|
||||||
@ -2348,7 +2348,7 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void {
|
|||||||
switch (width) {
|
switch (width) {
|
||||||
1 => {
|
1 => {
|
||||||
const cell = row.getCellPtr(x);
|
const cell = row.getCellPtr(x);
|
||||||
cell.char = @intCast(u32, c);
|
cell.char = @intCast(c);
|
||||||
|
|
||||||
grapheme.x = x;
|
grapheme.x = x;
|
||||||
grapheme.cell = cell;
|
grapheme.cell = cell;
|
||||||
@ -2373,7 +2373,7 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void {
|
|||||||
|
|
||||||
{
|
{
|
||||||
const cell = row.getCellPtr(x);
|
const cell = row.getCellPtr(x);
|
||||||
cell.char = @intCast(u32, c);
|
cell.char = @intCast(c);
|
||||||
cell.attrs.wide = true;
|
cell.attrs.wide = true;
|
||||||
|
|
||||||
grapheme.x = x;
|
grapheme.x = x;
|
||||||
@ -2422,7 +2422,7 @@ pub fn testString(self: *Screen, alloc: Allocator, tag: RowIndexTag) ![]const u8
|
|||||||
while (cells.next()) |cell| {
|
while (cells.next()) |cell| {
|
||||||
// TODO: handle character after null
|
// TODO: handle character after null
|
||||||
if (cell.char > 0) {
|
if (cell.char > 0) {
|
||||||
i += try std.unicode.utf8Encode(@intCast(u21, cell.char), buf[i..]);
|
i += try std.unicode.utf8Encode(@intCast(cell.char), buf[i..]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ const prealloc_count = prealloc_columns / unit_bits;
|
|||||||
const masks = blk: {
|
const masks = blk: {
|
||||||
var res: [unit_bits]Unit = undefined;
|
var res: [unit_bits]Unit = undefined;
|
||||||
for (res, 0..) |_, i| {
|
for (res, 0..) |_, i| {
|
||||||
res[i] = @shlExact(@as(Unit, 1), @intCast(u3, i));
|
res[i] = @shlExact(@as(Unit, 1), @as(u3, @intCast(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
break :blk res;
|
break :blk res;
|
||||||
|
@ -310,7 +310,7 @@ pub fn resize(self: *Terminal, alloc: Allocator, cols_req: usize, rows: usize) !
|
|||||||
// columns depending on if mode 3 is set or not.
|
// columns depending on if mode 3 is set or not.
|
||||||
// TODO: test
|
// TODO: test
|
||||||
const cols: usize = if (self.modes.deccolm_supported)
|
const cols: usize = if (self.modes.deccolm_supported)
|
||||||
@as(usize, if (self.modes.deccolm) 132 else 80)
|
if (self.modes.deccolm) 132 else 80
|
||||||
else
|
else
|
||||||
cols_req;
|
cols_req;
|
||||||
|
|
||||||
@ -627,7 +627,7 @@ pub fn print(self: *Terminal, c: u21) !void {
|
|||||||
|
|
||||||
const grapheme_break = brk: {
|
const grapheme_break = brk: {
|
||||||
var state: i32 = 0;
|
var state: i32 = 0;
|
||||||
var cp1 = @intCast(u21, prev.cell.char);
|
var cp1 = @as(u21, @intCast(prev.cell.char));
|
||||||
if (prev.cell.attrs.grapheme) {
|
if (prev.cell.attrs.grapheme) {
|
||||||
var it = row.codepointIterator(prev.x);
|
var it = row.codepointIterator(prev.x);
|
||||||
while (it.next()) |cp2| {
|
while (it.next()) |cp2| {
|
||||||
@ -735,7 +735,7 @@ fn printCell(self: *Terminal, unmapped_c: u21) *Screen.Cell {
|
|||||||
// const tracy = trace(@src());
|
// const tracy = trace(@src());
|
||||||
// defer tracy.end();
|
// defer tracy.end();
|
||||||
|
|
||||||
const c = c: {
|
const c: u21 = c: {
|
||||||
// TODO: non-utf8 handling, gr
|
// TODO: non-utf8 handling, gr
|
||||||
|
|
||||||
// If we're single shifting, then we use the key exactly once.
|
// If we're single shifting, then we use the key exactly once.
|
||||||
@ -754,7 +754,7 @@ fn printCell(self: *Terminal, unmapped_c: u21) *Screen.Cell {
|
|||||||
|
|
||||||
// Get our lookup table and map it
|
// Get our lookup table and map it
|
||||||
const table = set.table();
|
const table = set.table();
|
||||||
break :c @intCast(u21, table[@intCast(u8, unmapped_c)]);
|
break :c @intCast(table[@intCast(unmapped_c)]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const row = self.screen.getRow(.{ .active = self.screen.cursor.y });
|
const row = self.screen.getRow(.{ .active = self.screen.cursor.y });
|
||||||
@ -790,7 +790,7 @@ fn printCell(self: *Terminal, unmapped_c: u21) *Screen.Cell {
|
|||||||
|
|
||||||
// Write
|
// Write
|
||||||
cell.* = self.screen.cursor.pen;
|
cell.* = self.screen.cursor.pen;
|
||||||
cell.char = @intCast(u32, c);
|
cell.char = @intCast(c);
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ const max_u8 = std.math.maxInt(u8);
|
|||||||
fn initTable() [max_u8]u16 {
|
fn initTable() [max_u8]u16 {
|
||||||
var result: [max_u8]u16 = undefined;
|
var result: [max_u8]u16 = undefined;
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
while (i < max_u8) : (i += 1) result[i] = @intCast(u16, i);
|
while (i < max_u8) : (i += 1) result[i] = @intCast(i);
|
||||||
assert(i == max_u8);
|
assert(i == max_u8);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ pub const default: Palette = default: {
|
|||||||
// Named values
|
// Named values
|
||||||
var i: u8 = 0;
|
var i: u8 = 0;
|
||||||
while (i < 16) : (i += 1) {
|
while (i < 16) : (i += 1) {
|
||||||
result[i] = Name.default(@enumFromInt(Name, i)) catch unreachable;
|
result[i] = Name.default(@enumFromInt(i)) catch unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cube
|
// Cube
|
||||||
@ -111,6 +111,6 @@ test "palette: default" {
|
|||||||
// Safety check
|
// Safety check
|
||||||
var i: u8 = 0;
|
var i: u8 = 0;
|
||||||
while (i < 16) : (i += 1) {
|
while (i < 16) : (i += 1) {
|
||||||
try testing.expectEqual(Name.default(@enumFromInt(Name, i)), default[i]);
|
try testing.expectEqual(Name.default(@as(Name, @enumFromInt(i))), default[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,7 @@ pub const Parser = struct {
|
|||||||
|
|
||||||
fn endSemanticExitCode(self: *Parser) void {
|
fn endSemanticExitCode(self: *Parser) void {
|
||||||
switch (self.command) {
|
switch (self.command) {
|
||||||
.end_of_command => |*v| v.exit_code = @truncate(u8, self.temp_state.num),
|
.end_of_command => |*v| v.exit_code = @truncate(self.temp_state.num),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user