diff --git a/flake.lock b/flake.lock index 5e264c1e7..3b2739b62 100644 --- a/flake.lock +++ b/flake.lock @@ -126,11 +126,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1687694884, - "narHash": "sha256-TLXEykE/LSMwGETveZ9lI8fvd7nuJgq0+6tQwvCvP1k=", + "lastModified": 1688126918, + "narHash": "sha256-A4j6rWShGZf2wf7RwTd1sWhN9qLAINDYsExqZD6N09k=", "owner": "mitchellh", "repo": "zig-overlay", - "rev": "1c1c9f9ecc76ec222826770e10e6fef4c54d1e82", + "rev": "601ed4533722f87b9e97580d30ddd687e58c6b16", "type": "github" }, "original": { diff --git a/pkg/fontconfig/char_set.zig b/pkg/fontconfig/char_set.zig index 932058a23..7bf385e32 100644 --- a/pkg/fontconfig/char_set.zig +++ b/pkg/fontconfig/char_set.zig @@ -4,7 +4,7 @@ const c = @import("c.zig"); pub const CharSet = opaque { pub fn create() *CharSet { - return @ptrCast(*CharSet, c.FcCharSetCreate()); + return @ptrCast(c.FcCharSetCreate()); } pub fn destroy(self: *CharSet) void { @@ -20,17 +20,11 @@ pub const CharSet = opaque { } pub inline fn cval(self: *CharSet) *c.struct__FcCharSet { - return @ptrCast( - *c.struct__FcCharSet, - self, - ); + return @ptrCast(self); } pub inline fn cvalConst(self: *const CharSet) *const c.struct__FcCharSet { - return @ptrCast( - *const c.struct__FcCharSet, - self, - ); + return @ptrCast(self); } }; diff --git a/pkg/fontconfig/config.zig b/pkg/fontconfig/config.zig index f26b88784..70a1158a6 100644 --- a/pkg/fontconfig/config.zig +++ b/pkg/fontconfig/config.zig @@ -10,11 +10,11 @@ const MatchKind = @import("main.zig").MatchKind; pub const Config = opaque { 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 { - return @ptrCast(*FontSet, c.FcFontList(self.cval(), pat.cval(), os.cval())); + return @ptrCast(c.FcFontList(self.cval(), pat.cval(), os.cval())); } pub fn fontSort( @@ -24,21 +24,21 @@ pub const Config = opaque { charset: ?[*]*CharSet, ) FontSortResult { var result: FontSortResult = undefined; - result.fs = @ptrCast(*FontSet, c.FcFontSort( + result.fs = @ptrCast(c.FcFontSort( self.cval(), pat.cval(), if (trim) c.FcTrue else c.FcFalse, - @ptrCast([*c]?*c.struct__FcCharSet, charset), - @ptrCast([*c]c_uint, &result.result), + @ptrCast(charset), + @ptrCast(&result.result), )); return result; } pub fn fontRenderPrepare(self: *Config, pat: *Pattern, font: *Pattern) Error!*Pattern { - return @ptrCast( + return @as( ?*Pattern, - c.FcFontRenderPrepare(self.cval(), pat.cval(), font.cval()), + @ptrCast(c.FcFontRenderPrepare(self.cval(), pat.cval(), font.cval())), ) orelse Error.FontconfigFailed; } @@ -51,7 +51,7 @@ pub const Config = opaque { } pub inline fn cval(self: *Config) *c.struct__FcConfig { - return @ptrCast(*c.struct__FcConfig, self); + return @ptrCast(self); } }; diff --git a/pkg/fontconfig/font_set.zig b/pkg/fontconfig/font_set.zig index 0651d275c..4a942c1e0 100644 --- a/pkg/fontconfig/font_set.zig +++ b/pkg/fontconfig/font_set.zig @@ -5,7 +5,7 @@ const Pattern = @import("pattern.zig").Pattern; pub const FontSet = opaque { pub fn create() *FontSet { - return @ptrCast(*FontSet, c.FcFontSetCreate()); + return @ptrCast(c.FcFontSetCreate()); } pub fn destroy(self: *FontSet) void { @@ -16,8 +16,8 @@ pub const FontSet = opaque { const empty: [0]*Pattern = undefined; const s = self.cval(); if (s.fonts == null) return ∅ - const ptr = @ptrCast([*]*Pattern, @alignCast(@alignOf(*Pattern), s.fonts)); - const len = @intCast(usize, s.nfont); + const ptr: [*]*Pattern = @ptrCast(@alignCast(s.fonts)); + const len: usize = @intCast(s.nfont); return ptr[0..len]; } @@ -30,10 +30,7 @@ pub const FontSet = opaque { } pub inline fn cval(self: *FontSet) *c.struct__FcFontSet { - return @ptrCast( - *c.struct__FcFontSet, - @alignCast(@alignOf(c.struct__FcFontSet), self), - ); + return @ptrCast(@alignCast(self)); } }; diff --git a/pkg/fontconfig/init.zig b/pkg/fontconfig/init.zig index 2dce4afea..290555bb9 100644 --- a/pkg/fontconfig/init.zig +++ b/pkg/fontconfig/init.zig @@ -11,15 +11,15 @@ pub fn fini() void { } pub fn initLoadConfig() *Config { - return @ptrCast(*Config, c.FcInitLoadConfig()); + return @ptrCast(c.FcInitLoadConfig()); } pub fn initLoadConfigAndFonts() *Config { - return @ptrCast(*Config, c.FcInitLoadConfigAndFonts()); + return @ptrCast(c.FcInitLoadConfigAndFonts()); } pub fn version() u32 { - return @intCast(u32, c.FcGetVersion()); + return @intCast(c.FcGetVersion()); } test "version" { diff --git a/pkg/fontconfig/lang_set.zig b/pkg/fontconfig/lang_set.zig index 779ff1719..9f0ffd06e 100644 --- a/pkg/fontconfig/lang_set.zig +++ b/pkg/fontconfig/lang_set.zig @@ -4,7 +4,7 @@ const c = @import("c.zig"); pub const LangSet = opaque { pub fn create() *LangSet { - return @ptrCast(*LangSet, c.FcLangSetCreate()); + return @ptrCast(c.FcLangSetCreate()); } pub fn destroy(self: *LangSet) void { @@ -16,17 +16,11 @@ pub const LangSet = opaque { } pub inline fn cval(self: *LangSet) *c.struct__FcLangSet { - return @ptrCast( - *c.struct__FcLangSet, - self, - ); + return @ptrCast(self); } pub inline fn cvalConst(self: *const LangSet) *const c.struct__FcLangSet { - return @ptrCast( - *const c.struct__FcLangSet, - self, - ); + return @ptrCast(self); } }; diff --git a/pkg/fontconfig/object_set.zig b/pkg/fontconfig/object_set.zig index 778bd5c6e..defc47fbd 100644 --- a/pkg/fontconfig/object_set.zig +++ b/pkg/fontconfig/object_set.zig @@ -4,7 +4,7 @@ const Property = @import("main.zig").Property; pub const ObjectSet = opaque { pub fn create() *ObjectSet { - return @ptrCast(*ObjectSet, c.FcObjectSetCreate()); + return @ptrCast(c.FcObjectSetCreate()); } pub fn destroy(self: *ObjectSet) void { @@ -16,10 +16,7 @@ pub const ObjectSet = opaque { } pub inline fn cval(self: *ObjectSet) *c.struct__FcObjectSet { - return @ptrCast( - *c.struct__FcObjectSet, - @alignCast(@alignOf(c.struct__FcObjectSet), self), - ); + return @ptrCast(@alignCast(self)); } }; diff --git a/pkg/fontconfig/pattern.zig b/pkg/fontconfig/pattern.zig index 4510157e8..db67d1e3f 100644 --- a/pkg/fontconfig/pattern.zig +++ b/pkg/fontconfig/pattern.zig @@ -11,11 +11,11 @@ const Weight = @import("main.zig").Weight; pub const Pattern = opaque { pub fn create() *Pattern { - return @ptrCast(*Pattern, c.FcPatternCreate()); + return @ptrCast(c.FcPatternCreate()); } 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 { @@ -37,12 +37,12 @@ pub const Pattern = opaque { pub fn get(self: *Pattern, prop: Property, id: u32) Error!Value { var val: c.struct__FcValue = undefined; - try @enumFromInt(Result, c.FcPatternGet( + try @as(Result, @enumFromInt(c.FcPatternGet( self.cval(), prop.cval().ptr, - @intCast(c_int, id), + @intCast(id), &val, - )).toError(); + ))).toError(); return Value.init(&val); } @@ -52,7 +52,7 @@ pub const Pattern = opaque { } 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 { @@ -64,7 +64,7 @@ pub const Pattern = opaque { } pub inline fn cval(self: *Pattern) *c.struct__FcPattern { - return @ptrCast(*c.struct__FcPattern, self); + return @ptrCast(self); } pub const ObjectIterator = struct { @@ -93,10 +93,7 @@ pub const Pattern = opaque { return true; } - return c.FcPatternIterNext( - self.pat, - @ptrCast([*c]c.struct__FcPatternIter, &self.iter), - ) == c.FcTrue; + return c.FcPatternIterNext(self.pat, @ptrCast(&self.iter)) == c.FcTrue; } pub fn object(self: *ObjectIterator) []const u8 { @@ -107,7 +104,7 @@ pub const Pattern = opaque { } 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 { @@ -139,8 +136,8 @@ pub const Pattern = opaque { self.id += 1; return Entry{ - .result = @enumFromInt(Result, result), - .binding = @enumFromInt(ValueBinding, binding), + .result = @enumFromInt(result), + .binding = @enumFromInt(binding), .value = Value.init(&value), }; } diff --git a/pkg/fontconfig/range.zig b/pkg/fontconfig/range.zig index fd7addaa8..f1dfe3443 100644 --- a/pkg/fontconfig/range.zig +++ b/pkg/fontconfig/range.zig @@ -8,9 +8,6 @@ pub const Range = opaque { } pub inline fn cval(self: *Range) *c.struct__FcRange { - return @ptrCast( - *c.struct__FcRange, - self, - ); + return @ptrCast(self); } }; diff --git a/pkg/fontconfig/value.zig b/pkg/fontconfig/value.zig index 9b74450d1..de725c313 100644 --- a/pkg/fontconfig/value.zig +++ b/pkg/fontconfig/value.zig @@ -34,18 +34,18 @@ pub const Value = union(Type) { range: *const Range, pub fn init(cvalue: *c.struct__FcValue) Value { - return switch (@enumFromInt(Type, cvalue.type)) { + return switch (@as(Type, @enumFromInt(cvalue.type))) { .unknown => .{ .unknown = {} }, .void => .{ .void = {} }, .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 }, .bool => .{ .bool = cvalue.u.b == c.FcTrue }, - .matrix => .{ .matrix = @ptrCast(*const Matrix, cvalue.u.m) }, - .char_set => .{ .char_set = @ptrCast(*const CharSet, cvalue.u.c) }, - .ft_face => .{ .ft_face = @ptrCast(*anyopaque, cvalue.u.f) }, - .lang_set => .{ .lang_set = @ptrCast(*const LangSet, cvalue.u.l) }, - .range => .{ .range = @ptrCast(*const Range, cvalue.u.r) }, + .matrix => .{ .matrix = @ptrCast(cvalue.u.m) }, + .char_set => .{ .char_set = @ptrCast(cvalue.u.c) }, + .ft_face => .{ .ft_face = @ptrCast(cvalue.u.f) }, + .lang_set => .{ .lang_set = @ptrCast(cvalue.u.l) }, + .range => .{ .range = @ptrCast(cvalue.u.r) }, }; } @@ -55,15 +55,15 @@ pub const Value = union(Type) { .u = switch (self) { .unknown => undefined, .void => undefined, - .integer => |v| .{ .i = @intCast(c_int, v) }, + .integer => |v| .{ .i = @intCast(v) }, .double => |v| .{ .d = v }, .string => |v| .{ .s = v.ptr }, .bool => |v| .{ .b = if (v) c.FcTrue else c.FcFalse }, - .matrix => |v| .{ .m = @ptrCast(*const c.struct__FcMatrix, v) }, - .char_set => |v| .{ .c = @ptrCast(*const c.struct__FcCharSet, v) }, + .matrix => |v| .{ .m = @ptrCast(v) }, + .char_set => |v| .{ .c = @ptrCast(v) }, .ft_face => |v| .{ .f = v }, - .lang_set => |v| .{ .l = @ptrCast(*const c.struct__FcLangSet, v) }, - .range => |v| .{ .r = @ptrCast(*const c.struct__FcRange, v) }, + .lang_set => |v| .{ .l = @ptrCast(v) }, + .range => |v| .{ .r = @ptrCast(v) }, }, }; } diff --git a/pkg/freetype/Library.zig b/pkg/freetype/Library.zig index df99d2b94..dad6fc30a 100644 --- a/pkg/freetype/Library.zig +++ b/pkg/freetype/Library.zig @@ -50,7 +50,7 @@ pub fn initMemoryFace(self: Library, data: []const u8, index: i32) Error!Face { try intToError(c.FT_New_Memory_Face( self.handle, data.ptr, - @intCast(c_long, data.len), + @intCast(data.len), index, &face.handle, )); diff --git a/pkg/freetype/computations.zig b/pkg/freetype/computations.zig index f3f8f9832..82a95cdeb 100644 --- a/pkg/freetype/computations.zig +++ b/pkg/freetype/computations.zig @@ -4,5 +4,5 @@ const c = @import("c.zig"); /// Compute (a*b)/0x10000 with maximum accuracy. Its main use is to multiply /// a given value by a 16.16 fixed-point factor. pub fn mulFix(a: i32, b: i32) i32 { - return @intCast(i32, c.FT_MulFix(a, b)); + return @intCast(c.FT_MulFix(a, b)); } diff --git a/pkg/freetype/face.zig b/pkg/freetype/face.zig index d684601f6..732876aef 100644 --- a/pkg/freetype/face.zig +++ b/pkg/freetype/face.zig @@ -72,14 +72,13 @@ pub const Face = struct { return intToError(c.FT_Load_Glyph( self.handle, glyph_index, - @bitCast(i32, load_flags), + @bitCast(load_flags), )); } /// Return a pointer to a given SFNT table stored within a face. pub fn getSfntTable(self: Face, comptime tag: SfntTag) ?*tag.DataType() { - const T = tag.DataType(); - return @ptrCast(?*T, @alignCast(@alignOf(T), c.FT_Get_Sfnt_Table( + return @ptrCast(@alignCast(c.FT_Get_Sfnt_Table( self.handle, @intFromEnum(tag), ))); @@ -163,7 +162,7 @@ pub const LoadFlags = packed struct { test "bitcast" { const testing = std.testing; 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.render); try testing.expect(flags.pedantic); diff --git a/pkg/harfbuzz/blob.zig b/pkg/harfbuzz/blob.zig index 1dd2caff1..c4d8c5936 100644 --- a/pkg/harfbuzz/blob.zig +++ b/pkg/harfbuzz/blob.zig @@ -54,7 +54,7 @@ pub const Blob = struct { pub fn create(data: []const u8, mode: MemoryMode) Error!Blob { const handle = c.hb_blob_create_or_fail( data.ptr, - @intCast(c_uint, data.len), + @intCast(data.len), @intFromEnum(mode), null, null, @@ -83,14 +83,14 @@ pub const Blob = struct { const Callback = struct { pub fn callback(data: ?*anyopaque) callconv(.C) void { @call(.{ .modifier = .always_inline }, destroycb, .{ - @ptrCast(?*T, @alignCast(@alignOf(T), data)), + @as(?*T, @ptrCast(@alignCast(data))), }); } }; return c.hb_blob_set_user_data( self.handle, - @ptrCast([*c]c.hb_user_data_key_t, key), + @ptrCast(key), ptr, if (destroycb != null) Callback.callback else null, if (replace) 1 else 0, @@ -104,13 +104,9 @@ pub const Blob = struct { comptime T: type, key: ?*anyopaque, ) ?*T { - const opt = c.hb_blob_get_user_data( - self.handle, - @ptrCast([*c]c.hb_user_data_key_t, key), - ); - + const opt = c.hb_blob_get_user_data(self.handle, @ptrCast(key)); if (opt) |ptr| - return @ptrCast(?*T, @alignCast(@alignOf(T), ptr)) + return @ptrCast(@alignCast(ptr)) else return null; } diff --git a/pkg/harfbuzz/buffer.zig b/pkg/harfbuzz/buffer.zig index 4508e2f15..f52385417 100644 --- a/pkg/harfbuzz/buffer.zig +++ b/pkg/harfbuzz/buffer.zig @@ -45,7 +45,7 @@ pub const Buffer = struct { /// Fetches the type of buffer contents. Buffers are either empty, contain /// characters (before shaping), or contain glyphs (the result of shaping). 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, @@ -76,9 +76,9 @@ pub const Buffer = struct { c.hb_buffer_add_codepoints( self.handle, text.ptr, - @intCast(c_int, text.len), + @intCast(text.len), 0, - @intCast(c_int, text.len), + @intCast(text.len), ); } @@ -90,9 +90,9 @@ pub const Buffer = struct { c.hb_buffer_add_utf32( self.handle, text.ptr, - @intCast(c_int, text.len), + @intCast(text.len), 0, - @intCast(c_int, text.len), + @intCast(text.len), ); } @@ -104,9 +104,9 @@ pub const Buffer = struct { c.hb_buffer_add_utf16( self.handle, text.ptr, - @intCast(c_int, text.len), + @intCast(text.len), 0, - @intCast(c_int, text.len), + @intCast(text.len), ); } @@ -118,9 +118,9 @@ pub const Buffer = struct { c.hb_buffer_add_utf8( self.handle, text.ptr, - @intCast(c_int, text.len), + @intCast(text.len), 0, - @intCast(c_int, text.len), + @intCast(text.len), ); } @@ -130,9 +130,9 @@ pub const Buffer = struct { c.hb_buffer_add_latin1( self.handle, text.ptr, - @intCast(c_int, text.len), + @intCast(text.len), 0, - @intCast(c_int, text.len), + @intCast(text.len), ); } @@ -149,7 +149,7 @@ pub const Buffer = struct { /// See hb_buffer_set_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. @@ -167,7 +167,7 @@ pub const Buffer = struct { /// See hb_buffer_set_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 . @@ -192,10 +192,7 @@ pub const Buffer = struct { /// long as buffer contents are not modified. pub fn getGlyphInfos(self: Buffer) []GlyphInfo { var length: u32 = 0; - const ptr = @ptrCast( - [*c]GlyphInfo, - c.hb_buffer_get_glyph_infos(self.handle, &length), - ); + const ptr: [*c]GlyphInfo = @ptrCast(c.hb_buffer_get_glyph_infos(self.handle, &length)); return ptr[0..length]; } @@ -210,7 +207,7 @@ pub const Buffer = struct { var length: u32 = 0; 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]; } diff --git a/pkg/harfbuzz/common.zig b/pkg/harfbuzz/common.zig index a4cff17b5..7ecea502c 100644 --- a/pkg/harfbuzz/common.zig +++ b/pkg/harfbuzz/common.zig @@ -194,18 +194,15 @@ pub const Language = struct { /// hb_language_t. pub fn fromString(str: []const u8) Language { return .{ - .handle = c.hb_language_from_string( - str.ptr, - @intCast(c_int, str.len), - ), + .handle = c.hb_language_from_string(str.ptr, @intCast(str.len)), }; } /// Converts an hb_language_t to a string. pub fn toString(self: Language) [:0]const u8 { - return std.mem.span(@ptrCast( + return std.mem.span(@as( [*: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; return if (c.hb_feature_from_string( str.ptr, - @intCast(c_int, str.len), + @intCast(str.len), &f, ) > 0) - @bitCast(Feature, f) + @bitCast(f) else null; } 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)); } }; diff --git a/pkg/harfbuzz/freetype.zig b/pkg/harfbuzz/freetype.zig index c7d96b6b7..570403061 100644 --- a/pkg/harfbuzz/freetype.zig +++ b/pkg/harfbuzz/freetype.zig @@ -63,7 +63,7 @@ test { try testing.expect(ftc.FT_New_Memory_Face( ft_lib, testFont, - @intCast(c_long, testFont.len), + @intCast(testFont.len), 0, &ft_face, ) == ftok); diff --git a/pkg/harfbuzz/shape.zig b/pkg/harfbuzz/shape.zig index 3567c8b11..be197e5de 100644 --- a/pkg/harfbuzz/shape.zig +++ b/pkg/harfbuzz/shape.zig @@ -12,9 +12,7 @@ const Feature = @import("common.zig").Feature; pub fn shape(font: Font, buf: Buffer, features: ?[]const Feature) void { const hb_feats: [*c]const c.hb_feature_t = feats: { if (features) |fs| { - if (fs.len > 0) { - break :feats @ptrCast([*]const c.hb_feature_t, fs.ptr); - } + if (fs.len > 0) break :feats @ptrCast(fs.ptr); } break :feats null; @@ -24,6 +22,6 @@ pub fn shape(font: Font, buf: Buffer, features: ?[]const Feature) void { font.handle, buf.handle, hb_feats, - if (features) |f| @intCast(c_uint, f.len) else 0, + if (features) |f| @intCast(f.len) else 0, ); } diff --git a/pkg/imgui/context.zig b/pkg/imgui/context.zig index c2830f65c..d9f403856 100644 --- a/pkg/imgui/context.zig +++ b/pkg/imgui/context.zig @@ -4,9 +4,9 @@ const Allocator = std.mem.Allocator; pub const Context = opaque { pub fn create() Allocator.Error!*Context { - return @ptrCast( + return @as( ?*Context, - c.igCreateContext(null), + @ptrCast(c.igCreateContext(null)), ) orelse Allocator.Error.OutOfMemory; } @@ -19,10 +19,7 @@ pub const Context = opaque { } pub inline fn cval(self: *Context) *c.ImGuiContext { - return @ptrCast( - *c.ImGuiContext, - @alignCast(@alignOf(c.ImGuiContext), self), - ); + return @ptrCast(@alignCast(self)); } }; diff --git a/pkg/imgui/core.zig b/pkg/imgui/core.zig index dcb8a0d09..17393f112 100644 --- a/pkg/imgui/core.zig +++ b/pkg/imgui/core.zig @@ -27,14 +27,14 @@ pub const tableHeadersRow = c.igTableHeadersRow; pub const tableNextColumn = c.igTableNextColumn; 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 { return c.igBegin( name.ptr, - @ptrCast([*c]bool, if (open) |v| v else null), - @bitCast(c_int, flags), + @ptrCast(if (open) |v| v else null), + @bitCast(flags), ); } @@ -45,14 +45,14 @@ pub fn collapsingHeader( ) bool { return c.igCollapsingHeader_BoolPtr( label.ptr, - @ptrCast([*c]bool, if (visible) |v| v else null), - @bitCast(c_int, flags), + @ptrCast(if (visible) |v| v else null), + @bitCast(flags), ); } pub fn isItemHovered(flags: HoveredFlags) bool { return c.igIsItemHovered( - @bitCast(c_int, flags), + @bitCast(flags), ); } @@ -62,7 +62,7 @@ pub fn treeNode( ) bool { return c.igTreeNodeEx_Str( label.ptr, - @bitCast(c_int, flags), + @bitCast(flags), ); } @@ -74,7 +74,7 @@ pub fn beginTable( return c.igBeginTable( id.ptr, cols, - @bitCast(c_int, flags), + @bitCast(flags), .{ .x = 0, .y = 0 }, 0, ); @@ -91,7 +91,7 @@ pub fn tableSetupColumn( ) void { c.igTableSetupColumn( label.ptr, - @bitCast(c_int, flags), + @bitCast(flags), init_size, 0, ); @@ -108,7 +108,7 @@ pub fn inputTextMultiline( buf.ptr, buf.len, size, - @bitCast(c_int, flags), + @bitCast(flags), null, null, ); diff --git a/pkg/imgui/draw_data.zig b/pkg/imgui/draw_data.zig index 9f7f04fd1..65341472b 100644 --- a/pkg/imgui/draw_data.zig +++ b/pkg/imgui/draw_data.zig @@ -5,16 +5,13 @@ const Allocator = std.mem.Allocator; pub const DrawData = opaque { pub fn get() Allocator.Error!*DrawData { - return @ptrCast( + return @as( ?*DrawData, - c.igGetDrawData(), + @ptrCast(c.igGetDrawData()), ) orelse Allocator.Error.OutOfMemory; } pub inline fn cval(self: *DrawData) *c.ImGuiDrawData { - return @ptrCast( - *c.ImGuiDrawData, - @alignCast(@alignOf(c.ImGuiDrawData), self), - ); + return @ptrCast(@alignCast(self)); } }; diff --git a/pkg/imgui/font_atlas.zig b/pkg/imgui/font_atlas.zig index e1c225086..d880e33a5 100644 --- a/pkg/imgui/font_atlas.zig +++ b/pkg/imgui/font_atlas.zig @@ -17,8 +17,8 @@ pub const FontAtlas = opaque { _ = c.ImFontAtlas_AddFontFromMemoryTTF( self.cval(), - @ptrFromInt(?*anyopaque, @intFromPtr(data.ptr)), - @intCast(c_int, data.len), + @ptrFromInt(@intFromPtr(data.ptr)), + @intCast(data.len), size_px, cfg, null, @@ -26,9 +26,6 @@ pub const FontAtlas = opaque { } pub inline fn cval(self: *FontAtlas) *c.ImFontAtlas { - return @ptrCast( - *c.ImFontAtlas, - @alignCast(@alignOf(c.ImFontAtlas), self), - ); + return @ptrCast(@alignCast(self)); } }; diff --git a/pkg/imgui/io.zig b/pkg/imgui/io.zig index b473c61b6..811796764 100644 --- a/pkg/imgui/io.zig +++ b/pkg/imgui/io.zig @@ -5,17 +5,14 @@ const Allocator = std.mem.Allocator; pub const IO = opaque { pub fn get() Allocator.Error!*IO { - return @ptrCast( + return @as( ?*IO, - c.igGetIO(), + @ptrCast(c.igGetIO()), ) orelse Allocator.Error.OutOfMemory; } pub inline fn cval(self: *IO) *c.ImGuiIO { - return @ptrCast( - *c.ImGuiIO, - @alignCast(@alignOf(c.ImGuiIO), self), - ); + return @ptrCast(@alignCast(self)); } }; diff --git a/pkg/imgui/style.zig b/pkg/imgui/style.zig index 623494ed1..3d3d68145 100644 --- a/pkg/imgui/style.zig +++ b/pkg/imgui/style.zig @@ -4,9 +4,9 @@ const Allocator = std.mem.Allocator; pub const Style = opaque { pub fn get() Allocator.Error!*Style { - return @ptrCast( + return @as( ?*Style, - c.igGetStyle(), + @ptrCast(c.igGetStyle()), ) orelse Allocator.Error.OutOfMemory; } @@ -27,9 +27,6 @@ pub const Style = opaque { } pub inline fn cval(self: *Style) *c.ImGuiStyle { - return @ptrCast( - *c.ImGuiStyle, - @alignCast(@alignOf(c.ImGuiStyle), self), - ); + return @ptrCast(@alignCast(self)); } }; diff --git a/pkg/macos/foundation/array.zig b/pkg/macos/foundation/array.zig index 9ab5fa293..35d3a0aba 100644 --- a/pkg/macos/foundation/array.zig +++ b/pkg/macos/foundation/array.zig @@ -6,8 +6,8 @@ pub const Array = opaque { pub fn create(comptime T: type, values: []*const T) Allocator.Error!*Array { return CFArrayCreate( null, - @ptrCast([*]*const anyopaque, values.ptr), - @intCast(usize, values.len), + @ptrCast(values.ptr), + @intCast(values.len), null, ) orelse error.OutOfMemory; } @@ -24,7 +24,7 @@ pub const Array = opaque { /// constness so that further API calls work correctly. The Foundation /// API doesn't properly mark things const/non-const. 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( diff --git a/pkg/macos/foundation/attributed_string.zig b/pkg/macos/foundation/attributed_string.zig index 13e573641..a8e647ec9 100644 --- a/pkg/macos/foundation/attributed_string.zig +++ b/pkg/macos/foundation/attributed_string.zig @@ -11,30 +11,24 @@ pub const AttributedString = opaque { } pub fn getLength(self: *AttributedString) usize { - return @intCast( - usize, - c.CFAttributedStringGetLength(@ptrCast(c.CFAttributedStringRef, self)), - ); + return @intCast(c.CFAttributedStringGetLength(@ptrCast(self))); } pub fn getString(self: *AttributedString) *foundation.String { - return @ptrFromInt( - *foundation.String, - @intFromPtr( - c.CFAttributedStringGetString(@ptrCast(c.CFAttributedStringRef, self)), - ), - ); + return @ptrFromInt(@intFromPtr( + c.CFAttributedStringGetString(@ptrCast(self)), + )); } }; pub const MutableAttributedString = opaque { pub fn create(cap: usize) Allocator.Error!*MutableAttributedString { - return @ptrFromInt( + return @as( ?*MutableAttributedString, - @intFromPtr(c.CFAttributedStringCreateMutable( + @ptrFromInt(@intFromPtr(c.CFAttributedStringCreateMutable( null, - @intCast(c.CFIndex, cap), - )), + @intCast(cap), + ))), ) orelse Allocator.Error.OutOfMemory; } @@ -48,9 +42,9 @@ pub const MutableAttributedString = opaque { replacement: *foundation.String, ) void { c.CFAttributedStringReplaceString( - @ptrCast(c.CFMutableAttributedStringRef, self), + @ptrCast(self), range.cval(), - @ptrCast(c.CFStringRef, replacement), + @ptrCast(replacement), ); } @@ -69,9 +63,9 @@ pub const MutableAttributedString = opaque { key; c.CFAttributedStringSetAttribute( - @ptrCast(c.CFMutableAttributedStringRef, self), + @ptrCast(self), range.cval(), - @ptrCast(c.CFStringRef, key_arg), + @ptrCast(key_arg), value, ); } diff --git a/pkg/macos/foundation/base.zig b/pkg/macos/foundation/base.zig index 1b8f75661..0584a1767 100644 --- a/pkg/macos/foundation/base.zig +++ b/pkg/macos/foundation/base.zig @@ -11,10 +11,10 @@ pub const Range = extern struct { length: c.CFIndex, 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 { - return @bitCast(c.CFRange, self); + return @bitCast(self); } }; diff --git a/pkg/macos/foundation/character_set.zig b/pkg/macos/foundation/character_set.zig index cf1955284..62438a052 100644 --- a/pkg/macos/foundation/character_set.zig +++ b/pkg/macos/foundation/character_set.zig @@ -8,19 +8,19 @@ pub const CharacterSet = opaque { pub fn createWithCharactersInString( str: *foundation.String, ) Allocator.Error!*CharacterSet { - return @ptrFromInt(?*CharacterSet, @intFromPtr(c.CFCharacterSetCreateWithCharactersInString( + return @as(?*CharacterSet, @ptrFromInt(@intFromPtr(c.CFCharacterSetCreateWithCharactersInString( null, - @ptrCast(c.CFStringRef, str), - ))) orelse Allocator.Error.OutOfMemory; + @ptrCast(str), + )))) orelse Allocator.Error.OutOfMemory; } pub fn createWithCharactersInRange( range: foundation.Range, ) Allocator.Error!*CharacterSet { - return @ptrFromInt(?*CharacterSet, @intFromPtr(c.CFCharacterSetCreateWithCharactersInRange( + return @as(?*CharacterSet, @ptrFromInt(@intFromPtr(c.CFCharacterSetCreateWithCharactersInRange( null, range.cval(), - ))) orelse Allocator.Error.OutOfMemory; + )))) orelse Allocator.Error.OutOfMemory; } pub fn release(self: *CharacterSet) void { diff --git a/pkg/macos/foundation/data.zig b/pkg/macos/foundation/data.zig index 10db75860..7f3a6b455 100644 --- a/pkg/macos/foundation/data.zig +++ b/pkg/macos/foundation/data.zig @@ -5,14 +5,14 @@ const c = @import("c.zig"); pub const Data = opaque { pub fn createWithBytesNoCopy(data: []const u8) Allocator.Error!*Data { - return @ptrFromInt( + return @as( ?*Data, - @intFromPtr(c.CFDataCreateWithBytesNoCopy( + @ptrFromInt(@intFromPtr(c.CFDataCreateWithBytesNoCopy( null, data.ptr, - @intCast(c_long, data.len), + @intCast(data.len), c.kCFAllocatorNull, - )), + ))), ) orelse error.OutOfMemory; } diff --git a/pkg/macos/foundation/dictionary.zig b/pkg/macos/foundation/dictionary.zig index cdd16020c..0b6aa48be 100644 --- a/pkg/macos/foundation/dictionary.zig +++ b/pkg/macos/foundation/dictionary.zig @@ -15,14 +15,14 @@ pub const Dictionary = opaque { assert(keys.?.len == values.?.len); } - return @ptrFromInt(?*Dictionary, @intFromPtr(c.CFDictionaryCreate( + return @as(?*Dictionary, @ptrFromInt(@intFromPtr(c.CFDictionaryCreate( null, - @ptrCast([*c]?*const anyopaque, if (keys) |slice| slice.ptr else null), - @ptrCast([*c]?*const anyopaque, if (values) |slice| slice.ptr else null), - @intCast(c.CFIndex, if (keys) |slice| slice.len else 0), + @ptrCast(if (keys) |slice| slice.ptr else null), + @ptrCast(if (values) |slice| slice.ptr else null), + @intCast(if (keys) |slice| slice.len else 0), &c.kCFTypeDictionaryKeyCallBacks, &c.kCFTypeDictionaryValueCallBacks, - ))) orelse Allocator.Error.OutOfMemory; + )))) orelse Allocator.Error.OutOfMemory; } pub fn release(self: *Dictionary) void { @@ -30,12 +30,12 @@ pub const Dictionary = opaque { } 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 { - return @ptrFromInt(?*V, @intFromPtr(c.CFDictionaryGetValue( - @ptrCast(c.CFDictionaryRef, self), + return @ptrFromInt(@intFromPtr(c.CFDictionaryGetValue( + @ptrCast(self), key, ))); } @@ -43,20 +43,20 @@ pub const Dictionary = opaque { pub const MutableDictionary = opaque { pub fn create(cap: usize) Allocator.Error!*MutableDictionary { - return @ptrFromInt(?*MutableDictionary, @intFromPtr(c.CFDictionaryCreateMutable( + return @as(?*MutableDictionary, @ptrFromInt(@intFromPtr(c.CFDictionaryCreateMutable( null, - @intCast(c.CFIndex, cap), + @intCast(cap), &c.kCFTypeDictionaryKeyCallBacks, &c.kCFTypeDictionaryValueCallBacks, - ))) orelse Allocator.Error.OutOfMemory; + )))) orelse Allocator.Error.OutOfMemory; } pub fn createMutableCopy(cap: usize, src: *Dictionary) Allocator.Error!*MutableDictionary { - return @ptrFromInt(?*MutableDictionary, @intFromPtr(c.CFDictionaryCreateMutableCopy( + return @as(?*MutableDictionary, @ptrFromInt(@intFromPtr(c.CFDictionaryCreateMutableCopy( null, - @intCast(c.CFIndex, cap), - @ptrCast(c.CFDictionaryRef, src), - ))) orelse Allocator.Error.OutOfMemory; + @intCast(cap), + @ptrCast(src), + )))) orelse Allocator.Error.OutOfMemory; } 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 { c.CFDictionarySetValue( - @ptrCast(c.CFMutableDictionaryRef, self), + @ptrCast(self), key, value, ); @@ -100,7 +100,7 @@ test "mutable dictionary" { 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.expect(imm.getValue(foundation.String, c.kCFURLIsPurgeableKey) != null); try testing.expect(imm.getValue(foundation.String, c.kCFURLIsVolumeKey) == null); diff --git a/pkg/macos/foundation/number.zig b/pkg/macos/foundation/number.zig index 9d580c998..0cf91538d 100644 --- a/pkg/macos/foundation/number.zig +++ b/pkg/macos/foundation/number.zig @@ -8,16 +8,16 @@ pub const Number = opaque { comptime type_: NumberType, value: *const type_.ValueType(), ) Allocator.Error!*Number { - return @ptrFromInt(?*Number, @intFromPtr(c.CFNumberCreate( + return @as(?*Number, @ptrFromInt(@intFromPtr(c.CFNumberCreate( null, @intFromEnum(type_), value, - ))) orelse Allocator.Error.OutOfMemory; + )))) orelse Allocator.Error.OutOfMemory; } pub fn getValue(self: *Number, comptime t: NumberType, ptr: *t.ValueType()) bool { return c.CFNumberGetValue( - @ptrCast(c.CFNumberRef, self), + @ptrCast(self), @intFromEnum(t), ptr, ) == 1; diff --git a/pkg/macos/foundation/string.zig b/pkg/macos/foundation/string.zig index 7ed8e5ab6..5f794ae66 100644 --- a/pkg/macos/foundation/string.zig +++ b/pkg/macos/foundation/string.zig @@ -10,13 +10,13 @@ pub const String = opaque { encoding: StringEncoding, external: bool, ) Allocator.Error!*String { - return @ptrFromInt(?*String, @intFromPtr(c.CFStringCreateWithBytes( + return @as(?*String, @ptrFromInt(@intFromPtr(c.CFStringCreateWithBytes( null, bs.ptr, - @intCast(c_long, bs.len), + @intCast(bs.len), @intFromEnum(encoding), @intFromBool(external), - ))) orelse Allocator.Error.OutOfMemory; + )))) orelse Allocator.Error.OutOfMemory; } pub fn release(self: *String) void { @@ -24,13 +24,13 @@ pub const String = opaque { } 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 { return c.CFStringHasPrefix( - @ptrCast(c.CFStringRef, self), - @ptrCast(c.CFStringRef, prefix), + @ptrCast(self), + @ptrCast(prefix), ) == 1; } @@ -39,21 +39,18 @@ pub const String = opaque { other: *String, options: StringComparison, ) foundation.ComparisonResult { - return @enumFromInt( - foundation.ComparisonResult, - c.CFStringCompare( - @ptrCast(c.CFStringRef, self), - @ptrCast(c.CFStringRef, other), - @intCast(c_ulong, @bitCast(c_int, options)), - ), - ); + return @enumFromInt(c.CFStringCompare( + @ptrCast(self), + @ptrCast(other), + @intCast(@as(c_int, @bitCast(options))), + )); } pub fn cstring(self: *String, buf: []u8, encoding: StringEncoding) ?[]const u8 { if (c.CFStringGetCString( - @ptrCast(c.CFStringRef, self), + @ptrCast(self), buf.ptr, - @intCast(c_long, buf.len), + @intCast(buf.len), @intFromEnum(encoding), ) == 0) return null; return std.mem.sliceTo(buf, 0); @@ -61,7 +58,7 @@ pub const String = opaque { pub fn cstringPtr(self: *String, encoding: StringEncoding) ?[:0]const u8 { const ptr = c.CFStringGetCStringPtr( - @ptrCast(c.CFStringRef, self), + @ptrCast(self), @intFromEnum(encoding), ); if (ptr == null) return null; diff --git a/pkg/macos/foundation/url.zig b/pkg/macos/foundation/url.zig index 549bd28a1..88cf4bcdb 100644 --- a/pkg/macos/foundation/url.zig +++ b/pkg/macos/foundation/url.zig @@ -17,14 +17,14 @@ pub const URL = opaque { style: URLPathStyle, dir: bool, ) Allocator.Error!*URL { - return @ptrFromInt( + return @as( ?*URL, - @intFromPtr(c.CFURLCreateWithFileSystemPath( + @ptrFromInt(@intFromPtr(c.CFURLCreateWithFileSystemPath( null, - @ptrCast(c.CFStringRef, path), + @ptrCast(path), @intFromEnum(style), if (dir) 1 else 0, - )), + ))), ) orelse error.OutOfMemory; } diff --git a/pkg/macos/graphics/affine_transform.zig b/pkg/macos/graphics/affine_transform.zig index 30528702e..9cbde25e8 100644 --- a/pkg/macos/graphics/affine_transform.zig +++ b/pkg/macos/graphics/affine_transform.zig @@ -11,10 +11,10 @@ pub const AffineTransform = extern struct { ty: c.CGFloat, pub fn identity() AffineTransform { - return @bitCast(AffineTransform, c.CGAffineTransformIdentity); + return @bitCast(c.CGAffineTransformIdentity); } pub fn cval(self: AffineTransform) c.struct_CGAffineTransform { - return @bitCast(c.struct_CGAffineTransform, self); + return @bitCast(self); } }; diff --git a/pkg/macos/graphics/bitmap_context.zig b/pkg/macos/graphics/bitmap_context.zig index be319f229..8b633f36e 100644 --- a/pkg/macos/graphics/bitmap_context.zig +++ b/pkg/macos/graphics/bitmap_context.zig @@ -17,17 +17,17 @@ pub const BitmapContext = opaque { space: *graphics.ColorSpace, opts: c_uint, ) Allocator.Error!*BitmapContext { - return @ptrFromInt( + return @as( ?*BitmapContext, - @intFromPtr(c.CGBitmapContextCreate( - @ptrCast(?*anyopaque, if (data) |d| d.ptr else null), + @ptrFromInt(@intFromPtr(c.CGBitmapContextCreate( + @ptrCast(if (data) |d| d.ptr else null), width, height, bits_per_component, bytes_per_row, - @ptrCast(c.CGColorSpaceRef, space), + @ptrCast(space), opts, - )), + ))), ) orelse Allocator.Error.OutOfMemory; } }; diff --git a/pkg/macos/graphics/color_space.zig b/pkg/macos/graphics/color_space.zig index 52b355fee..e5735b22e 100644 --- a/pkg/macos/graphics/color_space.zig +++ b/pkg/macos/graphics/color_space.zig @@ -5,21 +5,21 @@ const c = @import("c.zig"); pub const ColorSpace = opaque { pub fn createDeviceGray() Allocator.Error!*ColorSpace { - return @ptrFromInt( + return @as( ?*ColorSpace, - @intFromPtr(c.CGColorSpaceCreateDeviceGray()), + @ptrFromInt(@intFromPtr(c.CGColorSpaceCreateDeviceGray())), ) orelse Allocator.Error.OutOfMemory; } pub fn createDeviceRGB() Allocator.Error!*ColorSpace { - return @ptrFromInt( + return @as( ?*ColorSpace, - @intFromPtr(c.CGColorSpaceCreateDeviceRGB()), + @ptrFromInt(@intFromPtr(c.CGColorSpaceCreateDeviceRGB())), ) orelse Allocator.Error.OutOfMemory; } pub fn release(self: *ColorSpace) void { - c.CGColorSpaceRelease(@ptrCast(c.CGColorSpaceRef, self)); + c.CGColorSpaceRelease(@ptrCast(self)); } }; diff --git a/pkg/macos/graphics/context.zig b/pkg/macos/graphics/context.zig index a627e58b1..7ba03b31c 100644 --- a/pkg/macos/graphics/context.zig +++ b/pkg/macos/graphics/context.zig @@ -9,40 +9,40 @@ const c = @import("c.zig"); pub fn Context(comptime T: type) type { return struct { pub fn release(self: *T) void { - c.CGContextRelease(@ptrCast(c.CGContextRef, self)); + c.CGContextRelease(@ptrCast(self)); } pub fn setLineWidth(self: *T, width: f64) void { c.CGContextSetLineWidth( - @ptrCast(c.CGContextRef, self), + @ptrCast(self), width, ); } pub fn setAllowsAntialiasing(self: *T, v: bool) void { c.CGContextSetAllowsAntialiasing( - @ptrCast(c.CGContextRef, self), + @ptrCast(self), v, ); } pub fn setShouldAntialias(self: *T, v: bool) void { c.CGContextSetShouldAntialias( - @ptrCast(c.CGContextRef, self), + @ptrCast(self), v, ); } pub fn setShouldSmoothFonts(self: *T, v: bool) void { c.CGContextSetShouldSmoothFonts( - @ptrCast(c.CGContextRef, self), + @ptrCast(self), v, ); } pub fn setGrayFillColor(self: *T, gray: f64, alpha: f64) void { c.CGContextSetGrayFillColor( - @ptrCast(c.CGContextRef, self), + @ptrCast(self), gray, alpha, ); @@ -50,7 +50,7 @@ pub fn Context(comptime T: type) type { pub fn setGrayStrokeColor(self: *T, gray: f64, alpha: f64) void { c.CGContextSetGrayStrokeColor( - @ptrCast(c.CGContextRef, self), + @ptrCast(self), gray, 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 { c.CGContextSetRGBFillColor( - @ptrCast(c.CGContextRef, self), + @ptrCast(self), r, g, b, @@ -68,21 +68,21 @@ pub fn Context(comptime T: type) type { pub fn setTextDrawingMode(self: *T, mode: TextDrawingMode) void { c.CGContextSetTextDrawingMode( - @ptrCast(c.CGContextRef, self), + @ptrCast(self), @intFromEnum(mode), ); } pub fn setTextMatrix(self: *T, matrix: graphics.AffineTransform) void { c.CGContextSetTextMatrix( - @ptrCast(c.CGContextRef, self), + @ptrCast(self), matrix.cval(), ); } pub fn setTextPosition(self: *T, x: f64, y: f64) void { c.CGContextSetTextPosition( - @ptrCast(c.CGContextRef, self), + @ptrCast(self), x, y, ); @@ -90,8 +90,8 @@ pub fn Context(comptime T: type) type { pub fn fillRect(self: *T, rect: graphics.Rect) void { c.CGContextFillRect( - @ptrCast(c.CGContextRef, self), - @bitCast(c.CGRect, rect), + @ptrCast(self), + @bitCast(rect), ); } }; diff --git a/pkg/macos/graphics/geometry.zig b/pkg/macos/graphics/geometry.zig index ca67a7130..77e67d770 100644 --- a/pkg/macos/graphics/geometry.zig +++ b/pkg/macos/graphics/geometry.zig @@ -5,7 +5,7 @@ pub const Point = extern struct { y: c.CGFloat, 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, 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 { - return @bitCast(c.struct_CGRect, self); + return @bitCast(self); } pub fn isNull(self: Rect) bool { @@ -31,6 +31,6 @@ pub const Size = extern struct { height: c.CGFloat, pub fn cval(self: Size) c.struct_CGSize { - return @bitCast(c.struct_CGSize, self); + return @bitCast(self); } }; diff --git a/pkg/macos/graphics/path.zig b/pkg/macos/graphics/path.zig index 151614735..8a7bf7f6c 100644 --- a/pkg/macos/graphics/path.zig +++ b/pkg/macos/graphics/path.zig @@ -10,12 +10,12 @@ pub const Path = opaque { rect: graphics.Rect, transform: ?*const graphics.AffineTransform, ) Allocator.Error!*Path { - return @ptrFromInt( + return @as( ?*Path, - @intFromPtr(c.CGPathCreateWithRect( + @ptrFromInt(@intFromPtr(c.CGPathCreateWithRect( rect.cval(), - @ptrCast(?[*]const c.struct_CGAffineTransform, transform), - )), + @ptrCast(transform), + ))), ) orelse Allocator.Error.OutOfMemory; } @@ -26,9 +26,9 @@ pub const Path = opaque { pub const MutablePath = opaque { pub fn create() Allocator.Error!*MutablePath { - return @ptrFromInt( + return @as( ?*MutablePath, - @intFromPtr(c.CGPathCreateMutable()), + @ptrFromInt(@intFromPtr(c.CGPathCreateMutable())), ) orelse Allocator.Error.OutOfMemory; } @@ -42,8 +42,8 @@ pub const MutablePath = opaque { rect: graphics.Rect, ) void { c.CGPathAddRect( - @ptrCast(c.CGMutablePathRef, self), - @ptrCast(?[*]const c.struct_CGAffineTransform, transform), + @ptrCast(self), + @ptrCast(transform), rect.cval(), ); } diff --git a/pkg/macos/os/log.zig b/pkg/macos/os/log.zig index eb47a22fc..0e1b32f29 100644 --- a/pkg/macos/os/log.zig +++ b/pkg/macos/os/log.zig @@ -8,10 +8,10 @@ pub const Log = opaque { subsystem: [:0]const u8, category: [:0]const u8, ) *Log { - return @ptrFromInt(?*Log, @intFromPtr(c.os_log_create( + return @as(?*Log, @ptrFromInt(@intFromPtr(c.os_log_create( subsystem.ptr, category.ptr, - ))).?; + )))).?; } pub fn release(self: *Log) void { @@ -20,7 +20,7 @@ pub const Log = opaque { pub fn typeEnabled(self: *Log, typ: LogType) bool { return c.os_log_type_enabled( - @ptrCast(c.os_log_t, self), + @ptrCast(self), @intFromEnum(typ), ); } diff --git a/pkg/macos/text/font.zig b/pkg/macos/text/font.zig index f17325bbd..6db9fa5c9 100644 --- a/pkg/macos/text/font.zig +++ b/pkg/macos/text/font.zig @@ -8,25 +8,25 @@ const c = @import("c.zig"); pub const Font = opaque { pub fn createWithFontDescriptor(desc: *text.FontDescriptor, size: f32) Allocator.Error!*Font { - return @ptrFromInt( + return @as( ?*Font, - @intFromPtr(c.CTFontCreateWithFontDescriptor( - @ptrCast(c.CTFontDescriptorRef, desc), + @ptrFromInt(@intFromPtr(c.CTFontCreateWithFontDescriptor( + @ptrCast(desc), size, null, - )), + ))), ) orelse Allocator.Error.OutOfMemory; } pub fn copyWithAttributes(self: *Font, size: f32, attrs: ?*text.FontDescriptor) Allocator.Error!*Font { - return @ptrFromInt( + return @as( ?*Font, - @intFromPtr(c.CTFontCreateCopyWithAttributes( - @ptrCast(c.CTFontRef, self), + @ptrFromInt(@intFromPtr(c.CTFontCreateCopyWithAttributes( + @ptrCast(self), size, null, - @ptrCast(c.CTFontDescriptorRef, attrs), - )), + @ptrCast(attrs), + ))), ) orelse Allocator.Error.OutOfMemory; } @@ -37,10 +37,10 @@ pub const Font = opaque { pub fn getGlyphsForCharacters(self: *Font, chars: []const u16, glyphs: []graphics.Glyph) bool { assert(chars.len == glyphs.len); return c.CTFontGetGlyphsForCharacters( - @ptrCast(c.CTFontRef, self), + @ptrCast(self), chars.ptr, glyphs.ptr, - @intCast(c_long, chars.len), + @intCast(chars.len), ); } @@ -52,11 +52,11 @@ pub const Font = opaque { ) void { assert(positions.len == glyphs.len); c.CTFontDrawGlyphs( - @ptrCast(c.CTFontRef, self), + @ptrCast(self), glyphs.ptr, - @ptrCast([*]const c.struct_CGPoint, positions.ptr), + @ptrCast(positions.ptr), glyphs.len, - @ptrCast(c.CGContextRef, context), + @ptrCast(context), ); } @@ -67,12 +67,12 @@ pub const Font = opaque { rects: ?[]graphics.Rect, ) graphics.Rect { if (rects) |s| assert(glyphs.len == s.len); - return @bitCast(graphics.Rect, c.CTFontGetBoundingRectsForGlyphs( - @ptrCast(c.CTFontRef, self), + return @bitCast(c.CTFontGetBoundingRectsForGlyphs( + @ptrCast(self), @intFromEnum(orientation), glyphs.ptr, - @ptrCast(?[*]c.struct_CGRect, if (rects) |s| s.ptr else null), - @intCast(c_long, glyphs.len), + @ptrCast(if (rects) |s| s.ptr else null), + @intCast(glyphs.len), )); } @@ -84,56 +84,51 @@ pub const Font = opaque { ) f64 { if (advances) |s| assert(glyphs.len == s.len); return c.CTFontGetAdvancesForGlyphs( - @ptrCast(c.CTFontRef, self), + @ptrCast(self), @intFromEnum(orientation), glyphs.ptr, - @ptrCast(?[*]c.struct_CGSize, if (advances) |s| s.ptr else null), - @intCast(c_long, glyphs.len), + @ptrCast(if (advances) |s| s.ptr else null), + @intCast(glyphs.len), ); } pub fn copyAttribute(self: *Font, comptime attr: text.FontAttribute) attr.Value() { - return @ptrFromInt(attr.Value(), @intFromPtr(c.CTFontCopyAttribute( - @ptrCast(c.CTFontRef, self), - @ptrCast(c.CFStringRef, attr.key()), + return @ptrFromInt(@intFromPtr(c.CTFontCopyAttribute( + @ptrCast(self), + @ptrCast(attr.key()), ))); } pub fn copyDisplayName(self: *Font) *foundation.String { - return @ptrFromInt( - *foundation.String, - @intFromPtr(c.CTFontCopyDisplayName(@ptrCast(c.CTFontRef, self))), - ); + return @ptrFromInt(@intFromPtr(c.CTFontCopyDisplayName(@ptrCast(self)))); } pub fn getSymbolicTraits(self: *Font) text.FontSymbolicTraits { - return @bitCast(text.FontSymbolicTraits, c.CTFontGetSymbolicTraits( - @ptrCast(c.CTFontRef, self), - )); + return @bitCast(c.CTFontGetSymbolicTraits(@ptrCast(self))); } pub fn getAscent(self: *Font) f64 { - return c.CTFontGetAscent(@ptrCast(c.CTFontRef, self)); + return c.CTFontGetAscent(@ptrCast(self)); } pub fn getDescent(self: *Font) f64 { - return c.CTFontGetDescent(@ptrCast(c.CTFontRef, self)); + return c.CTFontGetDescent(@ptrCast(self)); } 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 { - return @bitCast(graphics.Rect, c.CTFontGetBoundingBox(@ptrCast(c.CTFontRef, self))); + return @bitCast(c.CTFontGetBoundingBox(@ptrCast(self))); } pub fn getUnderlinePosition(self: *Font) f64 { - return c.CTFontGetUnderlinePosition(@ptrCast(c.CTFontRef, self)); + return c.CTFontGetUnderlinePosition(@ptrCast(self)); } pub fn getUnderlineThickness(self: *Font) f64 { - return c.CTFontGetUnderlineThickness(@ptrCast(c.CTFontRef, self)); + return c.CTFontGetUnderlineThickness(@ptrCast(self)); } }; diff --git a/pkg/macos/text/font_collection.zig b/pkg/macos/text/font_collection.zig index d5a286def..163d51189 100644 --- a/pkg/macos/text/font_collection.zig +++ b/pkg/macos/text/font_collection.zig @@ -6,19 +6,19 @@ const c = @import("c.zig"); pub const FontCollection = opaque { pub fn createFromAvailableFonts() Allocator.Error!*FontCollection { - return @ptrFromInt( + return @as( ?*FontCollection, - @intFromPtr(c.CTFontCollectionCreateFromAvailableFonts(null)), + @ptrFromInt(@intFromPtr(c.CTFontCollectionCreateFromAvailableFonts(null))), ) orelse Allocator.Error.OutOfMemory; } pub fn createWithFontDescriptors(descs: *foundation.Array) Allocator.Error!*FontCollection { - return @ptrFromInt( + return @as( ?*FontCollection, - @intFromPtr(c.CTFontCollectionCreateWithFontDescriptors( - @ptrCast(c.CFArrayRef, descs), + @ptrFromInt(@intFromPtr(c.CTFontCollectionCreateWithFontDescriptors( + @ptrCast(descs), null, - )), + ))), ) orelse Allocator.Error.OutOfMemory; } @@ -27,12 +27,8 @@ pub const FontCollection = opaque { } pub fn createMatchingFontDescriptors(self: *FontCollection) *foundation.Array { - const result = c.CTFontCollectionCreateMatchingFontDescriptors( - @ptrCast(c.CTFontCollectionRef, self), - ); - if (result) |ptr| { - return @ptrFromInt(*foundation.Array, @intFromPtr(ptr)); - } + const result = c.CTFontCollectionCreateMatchingFontDescriptors(@ptrCast(self)); + if (result) |ptr| return @ptrFromInt(@intFromPtr(ptr)); // 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 diff --git a/pkg/macos/text/font_descriptor.zig b/pkg/macos/text/font_descriptor.zig index e75d21758..6a33cf245 100644 --- a/pkg/macos/text/font_descriptor.zig +++ b/pkg/macos/text/font_descriptor.zig @@ -5,16 +5,16 @@ const c = @import("c.zig"); pub const FontDescriptor = opaque { pub fn createWithNameAndSize(name: *foundation.String, size: f64) Allocator.Error!*FontDescriptor { - return @ptrFromInt( + return @as( ?*FontDescriptor, - @intFromPtr(c.CTFontDescriptorCreateWithNameAndSize(@ptrCast(c.CFStringRef, name), size)), + @ptrFromInt(@intFromPtr(c.CTFontDescriptorCreateWithNameAndSize(@ptrCast(name), size))), ) orelse Allocator.Error.OutOfMemory; } pub fn createWithAttributes(dict: *foundation.Dictionary) Allocator.Error!*FontDescriptor { - return @ptrFromInt( + return @as( ?*FontDescriptor, - @intFromPtr(c.CTFontDescriptorCreateWithAttributes(@ptrCast(c.CFDictionaryRef, dict))), + @ptrFromInt(@intFromPtr(c.CTFontDescriptorCreateWithAttributes(@ptrCast(dict)))), ) orelse Allocator.Error.OutOfMemory; } @@ -22,12 +22,12 @@ pub const FontDescriptor = opaque { original: *FontDescriptor, dict: *foundation.Dictionary, ) Allocator.Error!*FontDescriptor { - return @ptrFromInt( + return @as( ?*FontDescriptor, - @intFromPtr(c.CTFontDescriptorCreateCopyWithAttributes( - @ptrCast(c.CTFontDescriptorRef, original), - @ptrCast(c.CFDictionaryRef, dict), - )), + @ptrFromInt(@intFromPtr(c.CTFontDescriptorCreateCopyWithAttributes( + @ptrCast(original), + @ptrCast(dict), + ))), ) orelse Allocator.Error.OutOfMemory; } @@ -36,15 +36,15 @@ pub const FontDescriptor = opaque { } pub fn copyAttribute(self: *FontDescriptor, comptime attr: FontAttribute) attr.Value() { - return @ptrFromInt(attr.Value(), @intFromPtr(c.CTFontDescriptorCopyAttribute( - @ptrCast(c.CTFontDescriptorRef, self), - @ptrCast(c.CFStringRef, attr.key()), + return @ptrFromInt(@intFromPtr(c.CTFontDescriptorCopyAttribute( + @ptrCast(self), + @ptrCast(attr.key()), ))); } pub fn copyAttributes(self: *FontDescriptor) *foundation.Dictionary { - return @ptrFromInt(*foundation.Dictionary, @intFromPtr(c.CTFontDescriptorCopyAttributes( - @ptrCast(c.CTFontDescriptorRef, self), + return @ptrFromInt(@intFromPtr(c.CTFontDescriptorCopyAttributes( + @ptrCast(self), ))); } }; @@ -76,7 +76,7 @@ pub const FontAttribute = enum { downloaded, 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, .name => c.kCTFontNameAttribute, .display_name => c.kCTFontDisplayNameAttribute, @@ -101,7 +101,7 @@ pub const FontAttribute = enum { .enabled => c.kCTFontEnabledAttribute, .downloadable => c.kCTFontDownloadableAttribute, .downloaded => c.kCTFontDownloadedAttribute, - })); + }))); } pub fn Value(comptime self: FontAttribute) type { @@ -141,12 +141,12 @@ pub const FontTraitKey = enum { slant, 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, .weight => c.kCTFontWeightTrait, .width => c.kCTFontWidthTrait, .slant => c.kCTFontSlantTrait, - })); + }))); } pub fn Value(self: FontTraitKey) type { @@ -176,11 +176,11 @@ pub const FontSymbolicTraits = packed struct { pub fn init(num: *foundation.Number) FontSymbolicTraits { var raw: i32 = undefined; _ = num.getValue(.sint32, &raw); - return @bitCast(FontSymbolicTraits, raw); + return @as(FontSymbolicTraits, @bitCast(raw)); } pub fn cval(self: FontSymbolicTraits) c.CTFontSymbolicTraits { - return @bitCast(c.CTFontSymbolicTraits, self); + return @as(c.CTFontSymbolicTraits, @bitCast(self)); } test { @@ -197,7 +197,7 @@ pub const FontSymbolicTraits = packed struct { .expanded = true, }; - try std.testing.expectEqual(actual, @bitCast(c.CTFontSymbolicTraits, expected)); + try std.testing.expectEqual(actual, @as(c.CTFontSymbolicTraits, @bitCast(expected))); } test "number" { diff --git a/pkg/macos/text/font_manager.zig b/pkg/macos/text/font_manager.zig index 115acbf0e..24a25660f 100644 --- a/pkg/macos/text/font_manager.zig +++ b/pkg/macos/text/font_manager.zig @@ -4,19 +4,13 @@ const foundation = @import("../foundation.zig"); const c = @import("c.zig"); pub fn createFontDescriptorsFromURL(url: *foundation.URL) ?*foundation.Array { - return @ptrFromInt( - ?*foundation.Array, - @intFromPtr(c.CTFontManagerCreateFontDescriptorsFromURL( - @ptrCast(c.CFURLRef, url), - )), - ); + return @ptrFromInt(@intFromPtr(c.CTFontManagerCreateFontDescriptorsFromURL( + @ptrCast(url), + ))); } pub fn createFontDescriptorsFromData(data: *foundation.Data) ?*foundation.Array { - return @ptrFromInt( - ?*foundation.Array, - @intFromPtr(c.CTFontManagerCreateFontDescriptorsFromData( - @ptrCast(c.CFDataRef, data), - )), - ); + return @ptrFromInt(@intFromPtr(c.CTFontManagerCreateFontDescriptorsFromData( + @ptrCast(data), + ))); } diff --git a/pkg/macos/text/frame.zig b/pkg/macos/text/frame.zig index aff7efa7d..f37ca3383 100644 --- a/pkg/macos/text/frame.zig +++ b/pkg/macos/text/frame.zig @@ -17,17 +17,14 @@ pub const Frame = opaque { points: []graphics.Point, ) void { c.CTFrameGetLineOrigins( - @ptrCast(c.CTFrameRef, self), - @bitCast(c.CFRange, range), - @ptrCast(*c.CGPoint, points.ptr), + @ptrCast(self), + @bitCast(range), + @ptrCast(points.ptr), ); } pub fn getLines(self: *Frame) *foundation.Array { - return @ptrFromInt( - *foundation.Array, - @intFromPtr(c.CTFrameGetLines(@ptrCast(c.CTFrameRef, self))), - ); + return @ptrFromInt(@intFromPtr(c.CTFrameGetLines(@ptrCast(self)))); } }; diff --git a/pkg/macos/text/framesetter.zig b/pkg/macos/text/framesetter.zig index 3c8df8cd0..5088057d6 100644 --- a/pkg/macos/text/framesetter.zig +++ b/pkg/macos/text/framesetter.zig @@ -8,11 +8,11 @@ const c = @import("c.zig"); pub const Framesetter = opaque { pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Framesetter { - return @ptrFromInt( + return @as( ?*Framesetter, - @intFromPtr(c.CTFramesetterCreateWithAttributedString( - @ptrCast(c.CFAttributedStringRef, str), - )), + @ptrFromInt(@intFromPtr(c.CTFramesetterCreateWithAttributedString( + @ptrCast(str), + ))), ) orelse Allocator.Error.OutOfMemory; } @@ -26,14 +26,14 @@ pub const Framesetter = opaque { path: *graphics.Path, attrs: ?*foundation.Dictionary, ) !*text.Frame { - return @ptrFromInt( + return @as( ?*text.Frame, - @intFromPtr(c.CTFramesetterCreateFrame( - @ptrCast(c.CTFramesetterRef, self), - @bitCast(c.CFRange, range), - @ptrCast(c.CGPathRef, path), - @ptrCast(c.CFDictionaryRef, attrs), - )), + @ptrFromInt(@intFromPtr(c.CTFramesetterCreateFrame( + @ptrCast(self), + @bitCast(range), + @ptrCast(path), + @ptrCast(attrs), + ))), ) orelse error.FrameCreateFailed; } }; @@ -47,7 +47,7 @@ test { 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(); const path = try graphics.Path.createWithRect(graphics.Rect.init(0, 0, 100, 200), null); diff --git a/pkg/macos/text/line.zig b/pkg/macos/text/line.zig index 124b51821..e6a506de9 100644 --- a/pkg/macos/text/line.zig +++ b/pkg/macos/text/line.zig @@ -8,11 +8,11 @@ const c = @import("c.zig"); pub const Line = opaque { pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Line { - return @ptrFromInt( + return @as( ?*Line, - @intFromPtr(c.CTLineCreateWithAttributedString( - @ptrCast(c.CFAttributedStringRef, str), - )), + @ptrFromInt(@intFromPtr(c.CTLineCreateWithAttributedString( + @ptrCast(str), + ))), ) orelse Allocator.Error.OutOfMemory; } @@ -21,8 +21,8 @@ pub const Line = opaque { } pub fn getGlyphCount(self: *Line) usize { - return @intCast(usize, c.CTLineGetGlyphCount( - @ptrCast(c.CTLineRef, self), + return @intCast(c.CTLineGetGlyphCount( + @ptrCast(self), )); } @@ -39,9 +39,9 @@ pub const Line = opaque { // C ABI issue happening. var result: graphics.Rect = undefined; zig_cabi_CTLineGetBoundsWithOptions( - @ptrCast(c.CTLineRef, self), + @ptrCast(self), opts.cval(), - @ptrCast(*c.CGRect, &result), + @ptrCast(&result), ); return result; @@ -61,7 +61,7 @@ pub const Line = opaque { leading: ?*f64, ) f64 { return c.CTLineGetTypographicBounds( - @ptrCast(c.CTLineRef, self), + @ptrCast(self), ascent, descent, leading, @@ -79,7 +79,7 @@ pub const LineBoundsOptions = packed struct { _padding: u58 = 0, pub fn cval(self: LineBoundsOptions) c.CTLineBoundsOptions { - return @bitCast(c.CTLineBoundsOptions, self); + return @bitCast(self); } test { @@ -97,7 +97,7 @@ pub const LineBoundsOptions = packed struct { .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, ); - const line = try Line.createWithAttributedString(@ptrCast(*foundation.AttributedString, str)); + const line = try Line.createWithAttributedString(@as(*foundation.AttributedString, @ptrCast(str))); defer line.release(); try testing.expectEqual(@as(usize, 5), line.getGlyphCount()); diff --git a/pkg/macos/text/stylized_strings.zig b/pkg/macos/text/stylized_strings.zig index 1064b3722..b922a8650 100644 --- a/pkg/macos/text/stylized_strings.zig +++ b/pkg/macos/text/stylized_strings.zig @@ -5,7 +5,7 @@ pub const StringAttribute = enum { font, pub fn key(self: StringAttribute) *foundation.String { - return @ptrFromInt(*foundation.String, @intFromPtr(switch (self) { + return @ptrFromInt(@intFromPtr(switch (self) { .font => c.kCTFontAttributeName, })); } diff --git a/pkg/pixman/format.zig b/pkg/pixman/format.zig index c471fd15f..9cea4308c 100644 --- a/pkg/pixman/format.zig +++ b/pkg/pixman/format.zig @@ -87,7 +87,7 @@ pub const FormatCode = enum(c_uint) { /// Calculates a valid stride for the bpp and width. Based on Cairo. pub fn strideForWidth(self: FormatCode, width: u32) c_int { 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; } @@ -96,7 +96,7 @@ pub const FormatCode = enum(c_uint) { const val = @intFromEnum(self); const v1 = val >> ofs; 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); } }; diff --git a/pkg/pixman/image.zig b/pkg/pixman/image.zig index bd8317038..0c87167f5 100644 --- a/pkg/pixman/image.zig +++ b/pkg/pixman/image.zig @@ -10,25 +10,25 @@ pub const Image = opaque { bits: [*]u32, stride: c_int, ) 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), width, height, bits, stride, - )) orelse return pixman.Error.PixmanFailure; + ))) orelse return pixman.Error.PixmanFailure; } pub fn createSolidFill( color: pixman.Color, ) pixman.Error!*Image { - return @ptrCast(?*Image, c.pixman_image_create_solid_fill( - @ptrCast(*const c.pixman_color_t, &color), - )) orelse return pixman.Error.PixmanFailure; + return @as(?*Image, @ptrCast(c.pixman_image_create_solid_fill( + @ptrCast(&color), + ))) orelse return pixman.Error.PixmanFailure; } 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 @@ -39,24 +39,24 @@ pub const Image = opaque { const height = self.getHeight(); const stride = self.getStride(); const ptr = self.getDataUnsafe(); - const len = @intCast(usize, height * stride); + const len = @as(usize, @intCast(height * stride)); return ptr[0..len]; } 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 { - 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 { - 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 { - return c.pixman_image_get_stride(@ptrCast(*c.pixman_image_t, self)); + return c.pixman_image_get_stride(@ptrCast(self)); } pub fn fillBoxes( @@ -67,10 +67,10 @@ pub const Image = opaque { ) pixman.Error!void { if (c.pixman_image_fill_boxes( @intFromEnum(op), - @ptrCast(*c.pixman_image_t, self), - @ptrCast(*const c.pixman_color_t, &color), - @intCast(c_int, boxes.len), - @ptrCast([*c]const c.pixman_box32_t, boxes.ptr), + @ptrCast(self), + @ptrCast(&color), + @intCast(boxes.len), + @ptrCast(boxes.ptr), ) == 0) return pixman.Error.PixmanFailure; } @@ -82,10 +82,10 @@ pub const Image = opaque { ) pixman.Error!void { if (c.pixman_image_fill_rectangles( @intFromEnum(op), - @ptrCast(*c.pixman_image_t, self), - @ptrCast(*const c.pixman_color_t, &color), - @intCast(c_int, rects.len), - @ptrCast([*c]const c.pixman_rectangle16_t, rects.ptr), + @ptrCast(self), + @ptrCast(&color), + @intCast(rects.len), + @ptrCast(rects.ptr), ) == 0) return pixman.Error.PixmanFailure; } @@ -96,8 +96,8 @@ pub const Image = opaque { y_off: c_int, ) void { c.pixman_rasterize_trapezoid( - @ptrCast(*c.pixman_image_t, self), - @ptrCast(*const c.pixman_trapezoid_t, &trap), + @ptrCast(self), + @ptrCast(&trap), x_off, y_off, ); @@ -119,9 +119,9 @@ pub const Image = opaque { ) void { c.pixman_image_composite( @intFromEnum(op), - @ptrCast(*c.pixman_image_t, src), - @ptrCast(?*c.pixman_image_t, mask), - @ptrCast(*c.pixman_image_t, self), + @ptrCast(src), + @ptrCast(mask), + @ptrCast(self), src_x, src_y, mask_x, @@ -146,15 +146,15 @@ pub const Image = opaque { ) void { c.pixman_composite_triangles( @intFromEnum(op), - @ptrCast(*c.pixman_image_t, src), - @ptrCast(*c.pixman_image_t, self), + @ptrCast(src), + @ptrCast(self), @intFromEnum(mask_format), x_src, y_src, x_dst, y_dst, - @intCast(c_int, tris.len), - @ptrCast([*c]const c.pixman_triangle_t, tris.ptr), + @intCast(tris.len), + @ptrCast(tris.ptr), ); } }; @@ -168,7 +168,7 @@ test "create and destroy" { const format: pixman.FormatCode = .g1; 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); defer alloc.free(data); @memset(data, 0); @@ -190,7 +190,7 @@ test "fill boxes a1" { const stride = format.strideForWidth(width); // Image - const len = height * @intCast(usize, stride); + const len = height * @as(usize, @intCast(stride)); var data = try alloc.alloc(u32, len); defer alloc.free(data); @memset(data, 0); diff --git a/pkg/pixman/types.zig b/pkg/pixman/types.zig index 49ef0f4aa..cc15c1ef7 100644 --- a/pkg/pixman/types.zig +++ b/pkg/pixman/types.zig @@ -73,8 +73,8 @@ pub const Fixed = enum(i32) { pub fn init(v: anytype) Fixed { return switch (@TypeOf(v)) { - comptime_int, i32, u32 => @enumFromInt(Fixed, v << 16), - f64 => @enumFromInt(Fixed, @intFromFloat(i32, v * 65536)), + comptime_int, i32, u32 => @enumFromInt(v << 16), + f64 => @enumFromInt(@as(i32, @intFromFloat(v * 65536))), else => { @compileLog(@TypeOf(v)); @compileError("unsupported type"); diff --git a/pkg/tracy/tracy.zig b/pkg/tracy/tracy.zig index d761414ae..aedc77d06 100644 --- a/pkg/tracy/tracy.zig +++ b/pkg/tracy/tracy.zig @@ -106,7 +106,7 @@ const Impl = struct { log2_ptr_align: u8, ret_addr: usize, ) ?[*]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); if (result) |data| { if (len != 0) { @@ -128,7 +128,7 @@ const Impl = struct { new_len: usize, ret_addr: usize, ) 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 (name) |n| { freeNamed(buf.ptr, n); @@ -152,7 +152,7 @@ const Impl = struct { log2_buf_align: u8, ret_addr: usize, ) 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); if (buf.len != 0) { diff --git a/pkg/utf8proc/main.zig b/pkg/utf8proc/main.zig index e99e0d005..a351fff4b 100644 --- a/pkg/utf8proc/main.zig +++ b/pkg/utf8proc/main.zig @@ -4,15 +4,15 @@ pub const c = @import("c.zig"); /// except that a width of 0 is returned for non-printable codepoints /// instead of -1 as in `wcwidth`. 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 /// permitted between them (as defined by the extended grapheme clusters in UAX#29). pub fn graphemeBreakStateful(cp1: u21, cp2: u21, state: *i32) bool { return c.utf8proc_grapheme_break_stateful( - @intCast(i32, cp1), - @intCast(i32, cp2), + @intCast(cp1), + @intCast(cp2), state, ); } diff --git a/src/Command.zig b/src/Command.zig index 1a9307fc5..2f8b871e8 100644 --- a/src/Command.zig +++ b/src/Command.zig @@ -126,7 +126,7 @@ pub fn start(self: *Command, alloc: Allocator) !void { const pid = try std.os.fork(); if (pid != 0) { // Parent, return immediately. - self.pid = @intCast(i32, pid); + self.pid = @intCast(pid); return; } @@ -201,10 +201,7 @@ pub fn setData(self: *Command, pointer: ?*anyopaque) void { /// Returns command->data. pub fn getData(self: Command, comptime DT: type) ?*DT { - return if (self.data) |ptr| - @ptrCast(?*DT, @alignCast(@alignOf(DT), ptr)) - else - null; + return if (self.data) |ptr| @ptrCast(@alignCast(ptr)) else null; } /// Search for "cmd" in the PATH and return the absolute path. This will diff --git a/src/DevMode.zig b/src/DevMode.zig index 92279b04e..5bb25952a 100644 --- a/src/DevMode.zig +++ b/src/DevMode.zig @@ -97,8 +97,8 @@ pub fn update(self: *const DevMode) !void { if (imgui.treeNode("Atlas: Greyscale", .{ .default_open = true })) { defer imgui.treePop(); const atlas = &surface.font_group.atlas_greyscale; - const tex = switch (Renderer) { - renderer.OpenGL => @intCast(usize, surface.renderer.texture.id), + const tex: usize = switch (Renderer) { + renderer.OpenGL => @intCast(surface.renderer.texture.id), renderer.Metal => @intFromPtr(surface.renderer.texture_greyscale.value), 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 })) { defer imgui.treePop(); const atlas = &surface.font_group.atlas_color; - const tex = switch (Renderer) { - renderer.OpenGL => @intCast(usize, surface.renderer.texture_color.id), + const tex: usize = switch (Renderer) { + renderer.OpenGL => @intCast(surface.renderer.texture_color.id), renderer.Metal => @intFromPtr(surface.renderer.texture_color.value), else => @compileError("renderer unsupported, add it!"), }; @@ -166,10 +166,10 @@ fn atlasInfo(self: *const DevMode, atlas: *font.Atlas, tex: ?usize) !void { if (tex) |id| { imgui.c.igImage( - @ptrFromInt(*anyopaque, id), + @ptrFromInt(id), .{ - .x = @floatFromInt(f32, atlas.size), - .y = @floatFromInt(f32, atlas.size), + .x = @floatFromInt(atlas.size), + .y = @floatFromInt(atlas.size), }, .{ .x = 0, .y = 0 }, .{ .x = 1, .y = 1 }, diff --git a/src/Pty.zig b/src/Pty.zig index 816ada451..b8db3ee7c 100644 --- a/src/Pty.zig +++ b/src/Pty.zig @@ -55,7 +55,7 @@ pub fn open(size: winsize) !Pty { &slave_fd, null, null, - @ptrCast([*c]c.struct_winsize, &sizeCopy), + @ptrCast(&sizeCopy), ) < 0) return error.OpenptyFailed; errdefer { diff --git a/src/Surface.zig b/src/Surface.zig index 6cf4e28c4..d557482f9 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -200,8 +200,8 @@ pub fn init( // The font size we desire along with the DPI determined for the surface const font_size: font.face.DesiredSize = .{ .points = config.@"font-size", - .xdpi = @intFromFloat(u16, x_dpi), - .ydpi = @intFromFloat(u16, y_dpi), + .xdpi = @intFromFloat(x_dpi), + .ydpi = @intFromFloat(y_dpi), }; // Find all the fonts for this surface @@ -324,8 +324,8 @@ pub fn init( const cell_size = try renderer.CellSize.init(alloc, font_group); // Convert our padding from points to pixels - const padding_x = (@floatFromInt(f32, config.@"window-padding-x") * x_dpi) / 72; - const padding_y = (@floatFromInt(f32, config.@"window-padding-y") * y_dpi) / 72; + const padding_x = (@as(f32, @floatFromInt(config.@"window-padding-x")) * x_dpi) / 72; + const padding_y = (@as(f32, @floatFromInt(config.@"window-padding-y")) * y_dpi) / 72; const padding: renderer.Padding = .{ .top = 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 // but is otherwise somewhat arbitrary. try rt_surface.setSizeLimits(.{ - .width = @intFromFloat(u32, cell_size.width * 10), - .height = @intFromFloat(u32, cell_size.height * 4), + .width = @intFromFloat(cell_size.width * 10), + .height = @intFromFloat(cell_size.height * 4), }, null); // 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"; // 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( face_ttf, - @floatFromInt(f32, font_size.pixels()), + @floatFromInt(font_size.pixels()), ); // Default dark style @@ -561,7 +561,7 @@ pub fn handleMessage(self: *Surface, msg: Message) !void { .set_title => |*v| { // The ptrCast just gets sliceTo to return the proper type. // 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}); try self.rt_surface.setTitle(slice); }, @@ -662,7 +662,7 @@ pub fn imePoint(self: *const Surface) apprt.IMEPos { const x: f64 = x: { // 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 x += self.cell_size.width / 2; @@ -675,7 +675,7 @@ pub fn imePoint(self: *const Surface) apprt.IMEPos { const y: f64 = y: { // 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 y += self.cell_size.height; @@ -1157,8 +1157,8 @@ pub fn keyCallback( // Handle non-printables const char: u8 = char: { - const mods_int = @bitCast(u8, mods); - const ctrl_only = @bitCast(u8, input.Mods{ .ctrl = true }); + const mods_int: u8 = @bitCast(mods); + const ctrl_only: u8 = @bitCast(input.Mods{ .ctrl = true }); // If we're only pressing control, check if this is a character // 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. - break :char @as(u8, switch (key) { + break :char switch (key) { .backspace => 0x7F, .enter => '\r', .tab => '\t', .escape => 0x1B, else => 0, - }); + }; }; if (char > 0) { // Ask our IO thread to write the data var data: termio.Message.WriteReq.Small.Array = undefined; - data[0] = @intCast(u8, char); + data[0] = @intCast(char); _ = self.io_thread.mailbox.push(.{ .write_small = .{ .data = data, @@ -1306,7 +1306,7 @@ pub fn scrollCallback( if (!scroll_mods.precision) { 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: 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 }; } @@ -1337,8 +1337,8 @@ pub fn scrollCallback( self.mouse.pending_scroll_y = poff - (amount * cell_size); break :y .{ - .delta_unsigned = @intFromFloat(usize, @fabs(amount)), - .delta = @intFromFloat(isize, amount), + .delta_unsigned = @intFromFloat(@fabs(amount)), + .delta = @intFromFloat(amount), }; }; @@ -1347,7 +1347,7 @@ pub fn scrollCallback( if (!scroll_mods.precision) { const x_sign: isize = if (xoff < 0) -1 else 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 }; } @@ -1362,8 +1362,8 @@ pub fn scrollCallback( self.mouse.pending_scroll_x = poff - (amount * cell_size); break :x .{ - .delta_unsigned = @intFromFloat(usize, @fabs(amount)), - .delta = @intFromFloat(isize, amount), + .delta_unsigned = @intFromFloat(@fabs(amount)), + .delta = @intFromFloat(amount), }; }; @@ -1524,8 +1524,8 @@ fn mouseReport( data[1] = '['; data[2] = 'M'; data[3] = 32 + button_code; - data[4] = 32 + @intCast(u8, viewport_point.x) + 1; - data[5] = 32 + @intCast(u8, viewport_point.y) + 1; + data[4] = 32 + @as(u8, @intCast(viewport_point.x)) + 1; + data[5] = 32 + @as(u8, @intCast(viewport_point.y)) + 1; // Ask our IO thread to write the data _ = self.io_thread.mailbox.push(.{ @@ -1549,14 +1549,14 @@ fn mouseReport( // UTF-8 encode the x/y var i: usize = 4; - i += try std.unicode.utf8Encode(@intCast(u21, 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.x + 1), data[i..]); + i += try std.unicode.utf8Encode(@intCast(32 + viewport_point.y + 1), data[i..]); // Ask our IO thread to write the data _ = self.io_thread.mailbox.push(.{ .write_small = .{ .data = data, - .len = @intCast(u8, i), + .len = @intCast(i), }, }, .{ .forever = {} }); }, @@ -1579,7 +1579,7 @@ fn mouseReport( _ = self.io_thread.mailbox.push(.{ .write_small = .{ .data = data, - .len = @intCast(u8, resp.len), + .len = @intCast(resp.len), }, }, .{ .forever = {} }); }, @@ -1598,7 +1598,7 @@ fn mouseReport( _ = self.io_thread.mailbox.push(.{ .write_small = .{ .data = data, - .len = @intCast(u8, resp.len), + .len = @intCast(resp.len), }, }, .{ .forever = {} }); }, @@ -1621,7 +1621,7 @@ fn mouseReport( _ = self.io_thread.mailbox.push(.{ .write_small = .{ .data = data, - .len = @intCast(u8, resp.len), + .len = @intCast(resp.len), }, }, .{ .forever = {} }); }, @@ -1652,8 +1652,8 @@ pub fn mouseButtonCallback( } // Always record our latest mouse state - self.mouse.click_state[@intCast(usize, @intFromEnum(button))] = action; - self.mouse.mods = @bitCast(input.Mods, mods); + self.mouse.click_state[@intCast(@intFromEnum(button))] = action; + self.mouse.mods = @bitCast(mods); // 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 @@ -1815,7 +1815,7 @@ pub fn cursorPosCallback( // since the spec (afaict) does not say... const button: ?input.MouseButton = button: for (self.mouse.click_state, 0..) |state, i| { if (state == .press) - break :button @enumFromInt(input.MouseButton, i); + break :button @enumFromInt(i); } else null; 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. // Note: one day, we can change this from distance to time based if we want. //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) { const delta: isize = if (pos.y < 0) -1 else 1; try self.io.terminal.scrollViewport(.{ .delta = delta }); @@ -1947,7 +1947,7 @@ fn dragLeftClickSingle( const cell_xboundary = self.cell_size.width * 0.6; // 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; // 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 .{ .x = if (xpos < 0) 0 else x: { // Our cell is the mouse divided by cell width - const cell_width = @floatCast(f64, self.cell_size.width); - const x = @intFromFloat(usize, xpos / cell_width); + const cell_width: f64 = @floatCast(self.cell_size.width); + const x: usize = @intFromFloat(xpos / cell_width); // Can be off the screen if the user drags it out, so max // 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: { - const cell_height = @floatCast(f64, self.cell_size.height); - const y = @intFromFloat(usize, ypos / cell_height); + const cell_height: f64 = @floatCast(self.cell_size.height); + const y: usize = @intFromFloat(ypos / cell_height); break :y @min(y, self.grid_size.rows - 1); }, }; diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 9dd835e52..43886df57 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -149,8 +149,8 @@ pub const Surface = struct { .core_surface = undefined, .nsview = objc.Object.fromId(opts.nsview), .content_scale = .{ - .x = @floatCast(f32, opts.scale_factor), - .y = @floatCast(f32, opts.scale_factor), + .x = @floatCast(opts.scale_factor), + .y = @floatCast(opts.scale_factor), }, .size = .{ .width = 800, .height = 600 }, .cursor_pos = .{ .x = 0, .y = 0 }, @@ -263,8 +263,8 @@ pub const Surface = struct { pub fn updateContentScale(self: *Surface, x: f64, y: f64) void { self.content_scale = .{ - .x = @floatCast(f32, x), - .y = @floatCast(f32, y), + .x = @floatCast(x), + .y = @floatCast(y), }; } @@ -314,8 +314,8 @@ pub const Surface = struct { pub fn cursorPosCallback(self: *Surface, x: f64, y: f64) void { // Convert our unscaled x/y to scaled. self.cursor_pos = self.cursorPosToPixels(.{ - .x = @floatCast(f32, x), - .y = @floatCast(f32, y), + .x = @floatCast(x), + .y = @floatCast(y), }) catch |err| { log.err( "error converting cursor pos to scaled pixels in cursor pos callback err={}", @@ -479,7 +479,7 @@ pub const CAPI = struct { action, 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( action, 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( x, y, - @bitCast(input.ScrollMods, @truncate(u8, @bitCast(c_uint, scroll_mods))), + @bitCast(@as(u8, @truncate(@as(c_uint, @bitCast(scroll_mods))))), ); } diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index ad90b4362..47bf9c422 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -291,8 +291,8 @@ pub const Surface = struct { }; const physical_size = monitor.getPhysicalSize(); 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_y_dpi = @floatFromInt(f32, video_mode.getHeight()) / (@floatFromInt(f32, physical_size.height_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 = @as(f32, @floatFromInt(video_mode.getHeight())) / (@as(f32, @floatFromInt(physical_size.height_mm)) / 25.4); log.debug("physical dpi x={} y={}", .{ physical_x_dpi, physical_y_dpi, @@ -463,8 +463,8 @@ pub const Surface = struct { const unscaled_pos = self.window.getCursorPos(); const pos = try self.cursorPosToPixels(unscaled_pos); return apprt.CursorPos{ - .x = @floatCast(f32, pos.xpos), - .y = @floatCast(f32, pos.ypos), + .x = @floatCast(pos.xpos), + .y = @floatCast(pos.ypos), }; } @@ -512,8 +512,8 @@ pub const Surface = struct { if (fb_size.width == size.width and fb_size.height == size.height) return pos; - const x_scale = @floatFromInt(f64, fb_size.width) / @floatFromInt(f64, size.width); - const y_scale = @floatFromInt(f64, fb_size.height) / @floatFromInt(f64, size.height); + const x_scale = @as(f64, @floatFromInt(fb_size.width)) / @as(f64, @floatFromInt(size.width)); + const y_scale = @as(f64, @floatFromInt(fb_size.height)) / @as(f64, @floatFromInt(size.height)); return .{ .xpos = pos.xpos * x_scale, .ypos = pos.ypos * y_scale, @@ -564,7 +564,7 @@ pub const Surface = struct { defer tracy.end(); // 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) { .release => .release, .press => .press, @@ -764,8 +764,8 @@ pub const Surface = struct { }; core_win.cursorPosCallback(.{ - .x = @floatCast(f32, pos.xpos), - .y = @floatCast(f32, pos.ypos), + .x = @floatCast(pos.xpos), + .y = @floatCast(pos.ypos), }) catch |err| { log.err("error in cursor pos callback err={}", .{err}); return; @@ -784,7 +784,7 @@ pub const Surface = struct { const core_win = window.getUserPointer(CoreSurface) orelse return; // 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) { .left => .left, .right => .right, diff --git a/src/apprt/gtk.zig b/src/apprt/gtk.zig index 0548e33dd..a722c8e09 100644 --- a/src/apprt/gtk.zig +++ b/src/apprt/gtk.zig @@ -63,7 +63,7 @@ pub const App = struct { errdefer config.deinit(); // 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, // GTK >= 2.74 @@ -71,7 +71,7 @@ pub const App = struct { c.G_APPLICATION_DEFAULT_FLAGS else c.G_APPLICATION_FLAGS_NONE, - )) orelse return error.GtkInitFailed; + ))) orelse return error.GtkInitFailed; errdefer c.g_object_unref(app); _ = c.g_signal_connect_data( app, @@ -89,12 +89,12 @@ pub const App = struct { if (c.g_main_context_acquire(ctx) == 0) return error.GtkContextAcquireFailed; 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; if (c.g_application_register( gapp, null, - @ptrCast([*c][*c]c.GError, &err_), + @ptrCast(&err_), ) == 0) { if (err_) |err| { log.warn("error registering application: {s}", .{err.message}); @@ -213,20 +213,20 @@ pub const App = struct { "Quit Ghostty?", ); c.gtk_message_dialog_format_secondary_text( - @ptrCast(*c.GtkMessageDialog, alert), + @ptrCast(alert), "All active terminal sessions will be terminated.", ); // We want the "yes" to appear destructive. const yes_widget = c.gtk_dialog_get_widget_for_response( - @ptrCast(*c.GtkDialog, alert), + @ptrCast(alert), c.GTK_RESPONSE_YES, ); c.gtk_widget_add_css_class(yes_widget, "destructive-action"); // We want the "no" to be the default action c.gtk_dialog_set_default_response( - @ptrCast(*c.GtkDialog, alert), + @ptrCast(alert), c.GTK_RESPONSE_NO, ); @@ -243,7 +243,7 @@ pub const App = struct { _ = ud; // 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 (response != c.GTK_RESPONSE_YES) return; @@ -254,8 +254,8 @@ pub const App = struct { c.g_list_foreach(list, struct { fn callback(data: c.gpointer, _: c.gpointer) callconv(.C) void { const ptr = data orelse return; - const widget = @ptrCast(*c.GtkWidget, @alignCast(@alignOf(c.GtkWidget), ptr)); - const window = @ptrCast(*c.GtkWindow, widget); + const widget: *c.GtkWidget = @ptrCast(@alignCast(ptr)); + const window: *c.GtkWindow = @ptrCast(widget); c.gtk_window_destroy(window); } }.callback, null); @@ -296,7 +296,7 @@ const Window = struct { // Create the window 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); self.window = gtk_window; c.gtk_window_set_title(gtk_window, "Ghostty"); @@ -307,7 +307,7 @@ const Window = struct { // Create a notebook to hold our tabs. const notebook_widget = c.gtk_notebook_new(); - const notebook = @ptrCast(*c.GtkNotebook, notebook_widget); + const notebook: *c.GtkNotebook = @ptrCast(notebook_widget); self.notebook = notebook; c.gtk_notebook_set_tab_pos(notebook, c.GTK_POS_TOP); c.gtk_notebook_set_scrollable(notebook, 1); @@ -339,12 +339,12 @@ const Window = struct { // Build our tab label 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"); c.gtk_box_append(label_box, label_text); 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_box_append(label_box, label_close_widget); _ = 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(); try surface.init(self.app, .{ .window = self, - .gl_area = @ptrCast(*c.GtkGLArea, gl_area), - .title_label = @ptrCast(*c.GtkLabel, label_text), + .gl_area = @ptrCast(gl_area), + .title_label = @ptrCast(label_text), }); errdefer surface.deinit(); 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. const page = c.gtk_notebook_get_page(self.notebook, gl_area) orelse return error.GtkNotebookPageNotFound; - c.g_object_set_data(@ptrCast(*c.GObject, 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(*c.GObject, gl_area), TAB_CLOSE_PAGE, page); + c.g_object_set_data(@ptrCast(label_close), TAB_CLOSE_SURFACE, surface); + c.g_object_set_data(@ptrCast(label_close), TAB_CLOSE_PAGE, page); + c.g_object_set_data(@ptrCast(gl_area), TAB_CLOSE_PAGE, page); // Switch to the new tab c.gtk_notebook_set_current_page(self.notebook, page_idx); // We need to grab focus after it is added to the window. When // 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); } @@ -415,12 +415,12 @@ const Window = struct { /// Close the surface. This surface must be definitely part of this window. fn closeSurface(self: *Window, surface: *Surface) void { 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. 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); // 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. 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 max = c.gtk_notebook_get_n_pages(self.notebook) -| 1; 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 { _ = ud; - const surface = @ptrCast(*Surface, @alignCast( - @alignOf(Surface), - c.g_object_get_data(@ptrCast(*c.GObject, btn), TAB_CLOSE_SURFACE) orelse return, + const surface: *Surface = @ptrCast(@alignCast( + c.g_object_get_data(@ptrCast(btn), TAB_CLOSE_SURFACE) orelse return, )); surface.core_surface.close(); @@ -498,20 +497,20 @@ const Window = struct { "Close this window?", ); c.gtk_message_dialog_format_secondary_text( - @ptrCast(*c.GtkMessageDialog, alert), + @ptrCast(alert), "All terminal sessions in this window will be terminated.", ); // We want the "yes" to appear destructive. const yes_widget = c.gtk_dialog_get_widget_for_response( - @ptrCast(*c.GtkDialog, alert), + @ptrCast(alert), c.GTK_RESPONSE_YES, ); c.gtk_widget_add_css_class(yes_widget, "destructive-action"); // We want the "no" to be the default action c.gtk_dialog_set_default_response( - @ptrCast(*c.GtkDialog, alert), + @ptrCast(alert), c.GTK_RESPONSE_NO, ); @@ -526,7 +525,7 @@ const Window = struct { response: c.gint, ud: ?*anyopaque, ) callconv(.C) void { - c.gtk_window_destroy(@ptrCast(*c.GtkWindow, alert)); + c.gtk_window_destroy(@ptrCast(alert)); if (response == c.GTK_RESPONSE_YES) { const self = userdataSelf(ud.?); 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 /// object has the notebook page property set. fn getNotebookPage(obj: *c.GObject) ?*c.GtkNotebookPage { - return @ptrCast(*c.GtkNotebookPage, @alignCast( - @alignOf(c.GtkNotebookPage), + return @ptrCast(@alignCast( 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); _ = c.g_value_init(&value, c.G_TYPE_INT); c.g_object_get_property( - @ptrCast(*c.GObject, @alignCast(@alignOf(c.GObject), page)), + @ptrCast(@alignCast(page)), "position", &value, ); @@ -567,7 +565,7 @@ const Window = struct { } 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, 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_has_stencil_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(); errdefer c.g_object_unref(im_context); c.gtk_event_controller_key_set_im_context( - @ptrCast(*c.GtkEventControllerKey, ec_key), + @ptrCast(ec_key), im_context, ); @@ -656,14 +654,8 @@ pub const Surface = struct { // Clicks const gesture_click = c.gtk_gesture_click_new(); errdefer c.g_object_unref(gesture_click); - c.gtk_gesture_single_set_button(@ptrCast( - *c.GtkGestureSingle, - gesture_click, - ), 0); - c.gtk_widget_add_controller(widget, @ptrCast( - *c.GtkEventController, - gesture_click, - )); + c.gtk_gesture_single_set_button(@ptrCast(gesture_click), 0); + c.gtk_widget_add_controller(widget, @ptrCast(gesture_click)); // Mouse movement const ec_motion = c.gtk_event_controller_motion_new(); @@ -778,7 +770,7 @@ pub const Surface = struct { "Close this terminal?", ); c.gtk_message_dialog_format_secondary_text( - @ptrCast(*c.GtkMessageDialog, alert), + @ptrCast(alert), "There is still a running process in the terminal. " ++ "Closing the terminal will kill this process. " ++ "Are you sure you want to close the terminal?" ++ @@ -787,14 +779,14 @@ pub const Surface = struct { // We want the "yes" to appear destructive. const yes_widget = c.gtk_dialog_get_widget_for_response( - @ptrCast(*c.GtkDialog, alert), + @ptrCast(alert), c.GTK_RESPONSE_YES, ); c.gtk_widget_add_css_class(yes_widget, "destructive-action"); // We want the "no" to be the default action c.gtk_dialog_set_default_response( - @ptrCast(*c.GtkDialog, alert), + @ptrCast(alert), c.GTK_RESPONSE_NO, ); @@ -861,10 +853,7 @@ pub const Surface = struct { } pub fn getClipboardString(self: *Surface) ![:0]const u8 { - const clipboard = c.gtk_widget_get_clipboard(@ptrCast( - *c.GtkWidget, - self.gl_area, - )); + const clipboard = c.gtk_widget_get_clipboard(@ptrCast(self.gl_area)); const content = c.gdk_clipboard_get_content(clipboard) orelse { // 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 { - const clipboard = c.gtk_widget_get_clipboard(@ptrCast( - *c.GtkWidget, - self.gl_area, - )); + const clipboard = c.gtk_widget_get_clipboard(@ptrCast(self.gl_area)); 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. { 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); }; 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); break :scale c.gdk_surface_get_scale_factor(gdk_surface); }; @@ -956,8 +942,8 @@ pub const Surface = struct { } self.size = .{ - .width = @intCast(u32, width), - .height = @intCast(u32, height), + .width = @intCast(width), + .height = @intCast(height), }; // Call the primary callback. @@ -988,13 +974,10 @@ pub const Surface = struct { ud: ?*anyopaque, ) callconv(.C) void { const self = userdataSelf(ud.?); - const button = translateMouseButton(c.gtk_gesture_single_get_current_button(@ptrCast( - *c.GtkGestureSingle, - gesture, - ))); + const button = translateMouseButton(c.gtk_gesture_single_get_current_button(@ptrCast(gesture))); // 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) { _ = c.gtk_widget_grab_focus(gl_widget); } @@ -1012,11 +995,7 @@ pub const Surface = struct { _: c.gdouble, ud: ?*anyopaque, ) callconv(.C) void { - const button = translateMouseButton(c.gtk_gesture_single_get_current_button(@ptrCast( - *c.GtkGestureSingle, - gesture, - ))); - + const button = translateMouseButton(c.gtk_gesture_single_get_current_button(@ptrCast(gesture))); const self = userdataSelf(ud.?); self.core_surface.mouseButtonCallback(.release, button, .{}) catch |err| { log.err("error in key callback err={}", .{err}); @@ -1032,8 +1011,8 @@ pub const Surface = struct { ) callconv(.C) void { const self = userdataSelf(ud.?); self.cursor_pos = .{ - .x = @max(@as(f32, 0), @floatCast(f32, x)), - .y = @floatCast(f32, y), + .x = @max(@as(f32, 0), @as(f32, @floatCast(x))), + .y = @floatCast(y), }; self.core_surface.cursorPosCallback(self.cursor_pos) catch |err| { @@ -1067,7 +1046,7 @@ pub const Surface = struct { ud: ?*anyopaque, ) callconv(.C) c.gboolean { 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. // I suspect this logic is actually wrong for customized keyboards, @@ -1087,7 +1066,7 @@ pub const Surface = struct { // that assumption is true. const keyval = keyval: { 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) break :keyval keyvals[i]; } @@ -1183,7 +1162,7 @@ pub const Surface = struct { response: c.gint, ud: ?*anyopaque, ) callconv(.C) void { - c.gtk_window_destroy(@ptrCast(*c.GtkWindow, alert)); + c.gtk_window_destroy(@ptrCast(alert)); if (response == c.GTK_RESPONSE_YES) { const self = userdataSelf(ud.?); self.window.closeSurface(self); @@ -1191,7 +1170,7 @@ pub const Surface = struct { } fn userdataSelf(ud: *anyopaque) *Surface { - return @ptrCast(*Surface, @alignCast(@alignOf(Surface), ud)); + return @ptrCast(@alignCast(ud)); } }; diff --git a/src/blocking_queue.zig b/src/blocking_queue.zig index 1684b4751..06bc8267f 100644 --- a/src/blocking_queue.zig +++ b/src/blocking_queue.zig @@ -40,7 +40,7 @@ pub fn BlockingQueue( pub const Size = u32; // 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. pub const Timeout = union(enum) { diff --git a/src/config.zig b/src/config.zig index 442b17eec..a6c7c3b59 100644 --- a/src/config.zig +++ b/src/config.zig @@ -431,7 +431,7 @@ pub const Config = struct { try result.keybind.set.put( alloc, - .{ .key = @enumFromInt(inputpkg.Key, i), .mods = mods }, + .{ .key = @enumFromInt(i), .mods = mods }, .{ .goto_tab = (i - start) + 1 }, ); } diff --git a/src/font/Atlas.zig b/src/font/Atlas.zig index 8f9d7812f..50c0d85a9 100644 --- a/src/font/Atlas.zig +++ b/src/font/Atlas.zig @@ -317,7 +317,7 @@ pub const Wasm = struct { const atlas = init( alloc, size, - @enumFromInt(Format, format), + @enumFromInt(format), ) catch return null; const result = alloc.create(Atlas) catch return null; result.* = atlas; @@ -449,7 +449,7 @@ pub const Wasm = struct { // Draw it 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; } @@ -561,7 +561,7 @@ test "writing RGB data" { }); // 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, 2), atlas.data[33 * depth + 1]); 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 // 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; try testing.expectEqual(@as(u8, 10), atlas.data[tl]); try testing.expectEqual(@as(u8, 11), atlas.data[tl + 1]); diff --git a/src/font/DeferredFace.zig b/src/font/DeferredFace.zig index a8a3ec346..7625876e2 100644 --- a/src/font/DeferredFace.zig +++ b/src/font/DeferredFace.zig @@ -353,7 +353,7 @@ pub const Wasm = struct { .wc = .{ .alloc = alloc, .font_str = font_str, - .presentation = @enumFromInt(font.Presentation, presentation), + .presentation = @enumFromInt(presentation), }, }; errdefer face.deinit(); diff --git a/src/font/Group.zig b/src/font/Group.zig index ae0ed11ba..804438c44 100644 --- a/src/font/Group.zig +++ b/src/font/Group.zig @@ -143,7 +143,7 @@ pub const FontIndex = packed struct(u8) { /// Convert to int 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 @@ -151,7 +151,7 @@ pub const FontIndex = packed struct(u8) { /// this font. pub fn special(self: FontIndex) ?Special { if (self.idx < Special.start) return null; - return @enumFromInt(Special, self.idx); + return @enumFromInt(self.idx); } test { @@ -223,7 +223,7 @@ fn indexForCodepointExact(self: Group, cp: u32, style: Style, p: ?Presentation) if (deferred.hasCodepoint(cp, p)) { return FontIndex{ .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. pub fn faceFromIndex(self: Group, index: FontIndex) !*Face { 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); 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); 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 self.sprite = font.sprite.Face{ - .width = @intFromFloat(u32, metrics.cell_width), - .height = @intFromFloat(u32, metrics.cell_height), + .width = @intFromFloat(metrics.cell_width), + .height = @intFromFloat(metrics.cell_height), .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 { - 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}); return; }; @@ -350,13 +350,13 @@ pub const Wasm = struct { /// Presentation is negative for doesn't matter. 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( cp, - @enumFromInt(Style, style), + @enumFromInt(style), presentation, ) orelse return -1; - return @intCast(i16, @bitCast(u8, idx)); + return @intCast(@as(u8, @bitCast(idx))); } export fn group_render_glyph( @@ -379,7 +379,7 @@ pub const Wasm = struct { cp: u32, max_height_: u16, ) !*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 glyph = try self.renderGlyph(alloc, atlas, idx, cp, max_height); diff --git a/src/font/GroupCache.zig b/src/font/GroupCache.zig index 33c11027b..57a4f1acb 100644 --- a/src/font/GroupCache.zig +++ b/src/font/GroupCache.zig @@ -266,14 +266,14 @@ pub const Wasm = struct { /// Presentation is negative for doesn't matter. 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( alloc, cp, - @enumFromInt(Style, style), + @enumFromInt(style), presentation, )) |idx| { - return @intCast(i16, @bitCast(u8, idx orelse return -1)); + return @intCast(@as(u8, @bitCast(idx orelse return -1))); } else |err| { log.warn("error getting index for codepoint from group cache size err={}", .{err}); return -1; @@ -298,7 +298,7 @@ pub const Wasm = struct { cp: u32, max_height_: u16, ) !*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 glyph = try self.renderGlyph(alloc, idx, cp, max_height); diff --git a/src/font/discovery.zig b/src/font/discovery.zig index 1d931f9df..6cfc0d888 100644 --- a/src/font/discovery.zig +++ b/src/font/discovery.zig @@ -107,7 +107,7 @@ pub const Descriptor = struct { // Set our size attribute if set if (self.size > 0) { - const size32 = @intCast(i32, self.size); + const size32 = @as(i32, @intCast(self.size)); const size = try macos.foundation.Number.create( .sint32, &size32, @@ -132,7 +132,7 @@ pub const Descriptor = struct { // of the symbolic traits value, and set that in our attributes. const traits_num = try macos.foundation.Number.create( .sint32, - @ptrCast(*const i32, &traits_cval), + @as(*const i32, @ptrCast(&traits_cval)), ); defer traits_num.release(); @@ -149,10 +149,7 @@ pub const Descriptor = struct { ); } - return try macos.text.FontDescriptor.createWithAttributes(@ptrCast( - *macos.foundation.Dictionary, - attrs, - )); + return try macos.text.FontDescriptor.createWithAttributes(@ptrCast(attrs)); } }; @@ -291,9 +288,7 @@ pub const CoreText = struct { // the descriptor removes the charset restriction. This is tested. const attrs = original.copyAttributes(); defer attrs.release(); - break :desc try macos.text.FontDescriptor.createWithAttributes( - @ptrCast(*macos.foundation.Dictionary, attrs), - ); + break :desc try macos.text.FontDescriptor.createWithAttributes(@ptrCast(attrs)); }; defer desc.release(); diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index 2604c32e5..a95fcb70a 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -42,7 +42,7 @@ pub const Face = struct { /// adjusted to the final size for final load. pub fn initFontCopy(base: *macos.text.Font, size: font.face.DesiredSize) !Face { // 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(); 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. 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 @@ -109,14 +109,14 @@ pub const Face = struct { _ = 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 // of the bitmap. We use the rounded up width/height of the bounding rect. var bounding: [1]macos.graphics.Rect = undefined; _ = self.font.getBoundingRectForGlyphs(.horizontal, &glyphs, &bounding); - const glyph_width = @intFromFloat(u32, @ceil(bounding[0].size.width)); - const glyph_height = @intFromFloat(u32, @ceil(bounding[0].size.height)); + const glyph_width = @as(u32, @intFromFloat(@ceil(bounding[0].size.width))); + const glyph_height = @as(u32, @intFromFloat(@ceil(bounding[0].size.height))); // Width and height. Note the padding doubling is because we want // 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) // 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. - 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{ .width = glyph_width, .height = glyph_height, - .offset_x = @intFromFloat(i32, @ceil(bounding[0].origin.x)), + .offset_x = @intFromFloat(@ceil(bounding[0].origin.x)), .offset_y = offset_y, .atlas_x = region.x + 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); } - break :cell_width @floatCast(f32, max); + break :cell_width @floatCast(max); }; // 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 // emit "frames" for the layout. - const fs = try macos.text.Framesetter.createWithAttributedString( - @ptrCast(*macos.foundation.AttributedString, string), - ); + const fs = try macos.text.Framesetter.createWithAttributedString(@ptrCast(string)); defer fs.release(); // 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(); const frame = try fs.createFrame( macos.foundation.Range.init(0, 0), - @ptrCast(*macos.graphics.Path, path), + @ptrCast(path), null, ); defer frame.release(); @@ -305,8 +303,8 @@ pub const Face = struct { //std.log.warn("ascent={} descent={} leading={}", .{ ascent, descent, leading }); break :metrics .{ - .height = @floatCast(f32, points[0].y - points[1].y), - .ascent = @floatCast(f32, ascent), + .height = @floatCast(points[0].y - points[1].y), + .ascent = @floatCast(ascent), }; }; @@ -314,8 +312,8 @@ pub const Face = struct { const cell_height = layout_metrics.height; const cell_baseline = layout_metrics.ascent; const underline_position = @ceil(layout_metrics.ascent - - @floatCast(f32, ct_font.getUnderlinePosition())); - const underline_thickness = @ceil(@floatCast(f32, ct_font.getUnderlineThickness())); + @as(f32, @floatCast(ct_font.getUnderlinePosition()))); + const underline_thickness = @ceil(@as(f32, @floatCast(ct_font.getUnderlineThickness()))); const strikethrough_position = cell_baseline * 0.6; const strikethrough_thickness = underline_thickness; diff --git a/src/font/face/freetype.zig b/src/font/face/freetype.zig index f84a0f191..fdeb27e82 100644 --- a/src/font/face/freetype.zig +++ b/src/font/face/freetype.zig @@ -82,7 +82,7 @@ pub const Face = struct { // to what the user requested. Otherwise, we can choose an arbitrary // pixel size. 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); } else try selectSizeNearest(face, size.pixels()); } @@ -94,8 +94,8 @@ pub const Face = struct { var best_i: i32 = 0; var best_diff: i32 = 0; while (i < face.handle.*.num_fixed_sizes) : (i += 1) { - const width = face.handle.*.available_sizes[@intCast(usize, i)].width; - const diff = @intCast(i32, size) - @intCast(i32, width); + const width = face.handle.*.available_sizes[@intCast(i)].width; + const diff = @as(i32, @intCast(size)) - @as(i32, @intCast(width)); if (i == 0 or diff < best_diff) { best_diff = diff; best_i = i; @@ -175,7 +175,7 @@ pub const Face = struct { break :blk try func(alloc, bitmap_ft); } else null; 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]); }; @@ -195,23 +195,23 @@ pub const Face = struct { var result = bm; result.rows = max; 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( u8, - @intCast(usize, result.pitch) * @intCast(usize, result.rows), + @as(usize, @intCast(result.pitch)) * @as(usize, @intCast(result.rows)), ); result.buffer = buf.ptr; errdefer alloc.free(buf); if (resize.stbir_resize_uint8( bm.buffer, - @intCast(c_int, bm.width), - @intCast(c_int, bm.rows), + @intCast(bm.width), + @intCast(bm.rows), bm.pitch, result.buffer, - @intCast(c_int, result.width), - @intCast(c_int, result.rows), + @intCast(result.width), + @intCast(result.rows), result.pitch, atlas.format.depth(), ) == 0) { @@ -223,7 +223,7 @@ pub const Face = struct { break :resized result; }; 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]); }; @@ -242,14 +242,14 @@ pub const Face = struct { const glyph_metrics = if (bitmap_resized) |bm| metrics: { // Our ratio for the resize const ratio = ratio: { - const new = @floatFromInt(f64, bm.rows); - const old = @floatFromInt(f64, bitmap_original.rows); + const new: f64 = @floatFromInt(bm.rows); + const old: f64 = @floatFromInt(bitmap_original.rows); break :ratio new / old; }; var copy = glyph.*; - copy.bitmap_top = @intFromFloat(c_int, @round(@floatFromInt(f64, copy.bitmap_top) * ratio)); - copy.bitmap_left = @intFromFloat(c_int, @round(@floatFromInt(f64, copy.bitmap_left) * ratio)); + copy.bitmap_top = @as(c_int, @intFromFloat(@round(@as(f64, @floatFromInt(copy.bitmap_top)) * ratio))); + copy.bitmap_left = @as(c_int, @intFromFloat(@round(@as(f64, @floatFromInt(copy.bitmap_left)) * ratio))); break :metrics copy; } else glyph.*; @@ -296,7 +296,7 @@ pub const Face = struct { while (i < bitmap.rows) : (i += 1) { fastmem.copy(u8, dst_ptr, src_ptr[0 .. bitmap.width * depth]); dst_ptr = dst_ptr[tgt_w * depth ..]; - src_ptr += @intCast(usize, bitmap.pitch); + src_ptr += @as(usize, @intCast(bitmap.pitch)); } break :buffer temp; } else bitmap.buffer[0..(tgt_w * tgt_h * depth)]; @@ -308,7 +308,7 @@ pub const Face = struct { 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 // and just center the glyph. So far this has only applied to emoji // 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 // _feel_ right, but it makes all my limited test cases work. 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 // baseline calculation. The baseline calculation is so that everything // 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. - 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 @@ -343,15 +343,15 @@ pub const Face = struct { /// Convert 16.6 pixel format to pixels based on the scale factor of the /// current font size. fn unitsToPxY(self: Face, units: i32) i32 { - return @intCast(i32, freetype.mulFix( + return @intCast(freetype.mulFix( units, - @intCast(i32, self.face.handle.*.size.*.metrics.y_scale), + @intCast(self.face.handle.*.size.*.metrics.y_scale), ) >> 6); } /// Convert 26.6 pixel format to 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 @@ -398,8 +398,8 @@ pub const Face = struct { if (face.getCharIndex('_')) |glyph_index| { if (face.loadGlyph(glyph_index, .{ .render = true })) { var res: f32 = f26dot6ToFloat(size_metrics.ascender); - res -= @floatFromInt(f32, face.handle.*.glyph.*.bitmap_top); - res += @floatFromInt(f32, face.handle.*.glyph.*.bitmap.rows); + res -= @floatFromInt(face.handle.*.glyph.*.bitmap_top); + res += @floatFromInt(face.handle.*.glyph.*.bitmap.rows); break :underscore res; } else |_| { // 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 // underline should go. - const underline_position = underline_pos: { + const underline_position: f32 = underline_pos: { // The ascender is already scaled for scalable fonts, but the // 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( face.handle.*.underline_position, - @intCast(i32, face.handle.*.size.*.metrics.y_scale), + @intCast(face.handle.*.size.*.metrics.y_scale), ) >> 6; // We use the declared underline position if its available const declared = ascender_px - declared_px; 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 // cell height (mainly: non-scalable fonts, i.e. emoji) @@ -453,13 +453,13 @@ pub const Face = struct { } = if (face.getSfntTable(.os2)) |os2| .{ .pos = pos: { // 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( os2.yStrikeoutPosition, - @intCast(i32, face.handle.*.size.*.metrics.y_scale), + @as(i32, @intCast(face.handle.*.size.*.metrics.y_scale)), ) >> 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)), } else .{ @@ -490,8 +490,8 @@ pub const Face = struct { /// Convert freetype "font units" to pixels using the Y scale. fn fontUnitsToPxY(face: freetype.Face, x: i32) f32 { - const mul = freetype.mulFix(x, @intCast(i32, face.handle.*.size.*.metrics.y_scale)); - const div = @floatFromInt(f32, mul) / 64; + const mul = freetype.mulFix(x, @as(i32, @intCast(face.handle.*.size.*.metrics.y_scale))); + const div = @as(f32, @floatFromInt(mul)) / 64; return @ceil(div); } }; diff --git a/src/font/face/freetype_convert.zig b/src/font/face/freetype_convert.zig index a53518f2f..7686ad425 100644 --- a/src/font/face/freetype_convert.zig +++ b/src/font/face/freetype_convert.zig @@ -55,20 +55,20 @@ pub fn monoToGreyscale(alloc: Allocator, bm: Bitmap) Allocator.Error!Bitmap { while (j > 0) : (j -= 1) { var bit: u4 = 8; 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; buf[target_i] = bitval; target_i += 1; } } - source_i += @intCast(usize, bm.pitch); + source_i += @intCast(bm.pitch); } var copy = bm; copy.buffer = buf.ptr; 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; } @@ -86,7 +86,7 @@ test "mono to greyscale" { .rows = 1, .width = 8, .pitch = 1, - .buffer = @ptrCast([*c]u8, &mono_data), + .buffer = @ptrCast(&mono_data), .num_grays = 0, .pixel_mode = freetype.c.FT_PIXEL_MODE_MONO, .palette_mode = 0, diff --git a/src/font/face/web_canvas.zig b/src/font/face/web_canvas.zig index 513645d90..821b5f422 100644 --- a/src/font/face/web_canvas.zig +++ b/src/font/face/web_canvas.zig @@ -352,7 +352,7 @@ pub const Face = struct { // If we are a normal glyph then we are a single codepoint and // we just UTF8 encode it as-is. 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]); } @@ -370,14 +370,14 @@ pub const Face = struct { // Get the width and height of the render const metrics = try measure_ctx.call(js.Object, "measureText", .{glyph_str}); 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 // text such as emoji do not have a bounding box set so we use // the full run width instead. const bounding_right = try metrics.get(f32, "actualBoundingBoxRight"); if (bounding_right > 0) break :width bounding_right; break :width try metrics.get(f32, "width"); - })) + 1; + }))) + 1; const left = try metrics.get(f32, "actualBoundingBoxLeft"); const asc = try metrics.get(f32, "actualBoundingBoxAscent"); @@ -389,7 +389,7 @@ pub const Face = struct { const broken_bbox = asc + desc < 0.001; // 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 // is important so that there is a 1px border around the glyph to avoid @@ -424,8 +424,8 @@ pub const Face = struct { // Draw background try ctx.set("fillStyle", js.string("transparent")); try ctx.call(void, "fillRect", .{ - @as(u32, 0), - @as(u32, 0), + 0, + 0, width, height, }); @@ -435,7 +435,7 @@ pub const Face = struct { try ctx.call(void, "fillText", .{ glyph_str, 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 @@ -449,7 +449,7 @@ pub const Face = struct { // Allocate our local memory to copy the data to. 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); // Create our target Uint8Array that we can use to copy from src. @@ -501,7 +501,7 @@ pub const Wasm = struct { alloc, ptr[0..len], .{ .points = pts }, - @enumFromInt(font.Presentation, presentation), + @enumFromInt(presentation), ); errdefer face.deinit(); diff --git a/src/font/shaper/harfbuzz.zig b/src/font/shaper/harfbuzz.zig index 5a090b5db..335ef6ad7 100644 --- a/src/font/shaper/harfbuzz.zig +++ b/src/font/shaper/harfbuzz.zig @@ -101,7 +101,7 @@ pub const Shaper = struct { for (info, 0..) |v, i| { self.cell_buf[i] = .{ - .x = @intCast(u16, v.cluster), + .x = @intCast(v.cluster), .glyph_index = v.codepoint, }; diff --git a/src/font/shaper/run.zig b/src/font/shaper/run.zig index c95c74a41..7d9cbac66 100644 --- a/src/font/shaper/run.zig +++ b/src/font/shaper/run.zig @@ -118,7 +118,7 @@ pub const RunIterator = struct { if (font_idx.int() != current_font.int()) break; // 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 // data points. @@ -126,7 +126,7 @@ pub const RunIterator = struct { var it = self.row.codepointIterator(j); while (it.next()) |cp| { 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; return TextRun{ - .offset = @intCast(u16, self.i), - .cells = @intCast(u16, j - self.i), + .offset = @intCast(self.i), + .cells = @intCast(j - self.i), .group = self.group, .font_index = current_font, }; diff --git a/src/font/shaper/web_canvas.zig b/src/font/shaper/web_canvas.zig index 278967617..3507f89e7 100644 --- a/src/font/shaper/web_canvas.zig +++ b/src/font/shaper/web_canvas.zig @@ -92,7 +92,7 @@ pub const Shaper = struct { // we can't have any more information to do anything else. 1 => { self.cell_buf[0] = .{ - .x = @intCast(u16, clusters[0]), + .x = @intCast(clusters[0]), .glyph_index = codepoints[0], }; @@ -110,7 +110,7 @@ pub const Shaper = struct { // This means we can render things like skin tone emoji but // we can't render things like single glyph "=>". var break_state: i32 = 0; - var cp1 = @intCast(u21, codepoints[0]); + var cp1: u21 = @intCast(codepoints[0]); var start: usize = 0; var i: usize = 1; @@ -121,7 +121,7 @@ pub const Shaper = struct { // break. This isn't strictly true but its how terminals // work today. const grapheme_break = i == codepoints.len or blk: { - const cp2 = @intCast(u21, codepoints[i]); + const cp2: u21 = @intCast(codepoints[i]); defer cp1 = cp2; break :blk utf8proc.graphemeBreakStateful( @@ -144,7 +144,7 @@ pub const Shaper = struct { // If we have only a single codepoint then just render it // as-is. 1 => self.cell_buf[cur] = .{ - .x = @intCast(u16, clusters[start]), + .x = @intCast(clusters[start]), .glyph_index = codepoints[start], }, @@ -161,7 +161,7 @@ pub const Shaper = struct { var acc: usize = 0; for (cluster_points) |cp| { acc += try std.unicode.utf8CodepointSequenceLength( - @intCast(u21, cp), + @intCast(cp), ); } @@ -173,7 +173,7 @@ pub const Shaper = struct { var buf_i: usize = 0; for (cluster_points) |cp| { buf_i += try std.unicode.utf8Encode( - @intCast(u21, cp), + @intCast(cp), buf[buf_i..], ); } @@ -186,7 +186,7 @@ pub const Shaper = struct { const index = try face.graphemeGlyphIndex(cluster); self.cell_buf[cur] = .{ - .x = @intCast(u16, clusters[start]), + .x = @intCast(clusters[start]), .glyph_index = index, }; }, diff --git a/src/font/sprite/Box.zig b/src/font/sprite/Box.zig index ff22eec81..694893758 100644 --- a/src/font/sprite/Box.zig +++ b/src/font/sprite/Box.zig @@ -66,7 +66,7 @@ pub fn renderGlyph( // 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 // cell. - const offset_y = @intCast(i32, self.height); + const offset_y = @as(i32, @intCast(self.height)); return font.Glyph{ .width = self.width, @@ -75,7 +75,7 @@ pub fn renderGlyph( .offset_y = offset_y, .atlas_x = region.x, .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); canvas.trapezoid(.{ .top = 0, - .bottom = @intCast(i32, self.height), + .bottom = @as(i32, @intCast(self.height)), .left = .{ .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, }, .p2 = .{ - .x = @intFromFloat(i32, 0 - @floatFromInt(f64, thick_px) / 2), - .y = @intCast(i32, self.height), + .x = @as(i32, @intFromFloat(0 - @as(f64, @floatFromInt(thick_px)) / 2)), + .y = @as(i32, @intCast(self.height)), }, }, .right = .{ .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, }, .p2 = .{ - .x = @intFromFloat(i32, 0 + @floatFromInt(f64, thick_px) / 2), - .y = @intCast(i32, self.height), + .x = @as(i32, @intFromFloat(0 + @as(f64, @floatFromInt(thick_px)) / 2)), + .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); canvas.trapezoid(.{ .top = 0, - .bottom = @intCast(i32, self.height), + .bottom = @as(i32, @intCast(self.height)), .left = .{ .p1 = .{ - .x = @intFromFloat(i32, 0 - @floatFromInt(f64, thick_px) / 2), + .x = @as(i32, @intFromFloat(0 - @as(f64, @floatFromInt(thick_px)) / 2)), .y = 0, }, .p2 = .{ - .x = @intFromFloat(i32, @floatFromInt(f64, self.width) - @floatFromInt(f64, thick_px) / 2), - .y = @intCast(i32, self.height), + .x = @as(i32, @intFromFloat(@as(f64, @floatFromInt(self.width)) - @as(f64, @floatFromInt(thick_px)) / 2)), + .y = @as(i32, @intCast(self.height)), }, }, .right = .{ .p1 = .{ - .x = @intFromFloat(i32, 0 + @floatFromInt(f64, thick_px) / 2), + .x = @as(i32, @intFromFloat(0 + @as(f64, @floatFromInt(thick_px)) / 2)), .y = 0, }, .p2 = .{ - .x = @intFromFloat(i32, @floatFromInt(f64, self.width) + @floatFromInt(f64, thick_px) / 2), - .y = @intCast(i32, self.height), + .x = @as(i32, @intFromFloat(@as(f64, @floatFromInt(self.width)) + @as(f64, @floatFromInt(thick_px)) / 2)), + .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( canvas, 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.height, ); @@ -1204,7 +1204,7 @@ fn draw_lower_half_block(self: Box, canvas: *font.sprite.Canvas) void { self.rect( canvas, 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.height, ); @@ -1214,7 +1214,7 @@ fn draw_lower_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void { self.rect( canvas, 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.height, ); @@ -1224,7 +1224,7 @@ fn draw_lower_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void self.rect( canvas, 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.height, ); @@ -1234,7 +1234,7 @@ fn draw_lower_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void { self.rect( canvas, 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.height, ); @@ -1246,7 +1246,7 @@ fn draw_upper_one_quarter_block(self: Box, canvas: *font.sprite.Canvas) void { 0, 0, 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, 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, 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, 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, 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, 0, 0, - @intFromFloat(u32, @round(7 * @floatFromInt(f64, self.width) / 8)), + @as(u32, @intFromFloat(@round(7 * @as(f64, @floatFromInt(self.width)) / 8))), self.height, ); } @@ -1309,7 +1309,7 @@ fn draw_left_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void { canvas, 0, 0, - @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.width) / 4)), + @as(u32, @intFromFloat(@round(3 * @as(f64, @floatFromInt(self.width)) / 4))), self.height, ); } @@ -1319,7 +1319,7 @@ fn draw_left_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void { canvas, 0, 0, - @intFromFloat(u32, @round(5 * @floatFromInt(f64, self.width) / 8)), + @as(u32, @intFromFloat(@round(5 * @as(f64, @floatFromInt(self.width)) / 8))), self.height, ); } @@ -1329,7 +1329,7 @@ fn draw_left_half_block(self: Box, canvas: *font.sprite.Canvas) void { canvas, 0, 0, - @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 2)), + @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 2))), self.height, ); } @@ -1339,7 +1339,7 @@ fn draw_left_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void { canvas, 0, 0, - @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.width) / 8)), + @as(u32, @intFromFloat(@round(3 * @as(f64, @floatFromInt(self.width)) / 8))), self.height, ); } @@ -1349,14 +1349,14 @@ fn draw_left_one_quarter_block(self: Box, canvas: *font.sprite.Canvas) void { canvas, 0, 0, - @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 4)), + @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 4))), self.height, ); } 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 w = @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 8)); + const x = @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(n)) * @as(f64, @floatFromInt(self.width)) / 8))); + const w = @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 8))); 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 { self.rect( canvas, - @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 2)), + @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 2))), 0, self.width, self.height, @@ -1378,9 +1378,9 @@ fn draw_pixman_shade(self: Box, canvas: *font.sprite.Canvas, v: u16) void { canvas.rect((font.sprite.Box{ .x1 = 0, .y1 = 0, - .x2 = @intCast(i32, self.width), - .y2 = @intCast(i32, self.height), - }).rect(), @enumFromInt(font.sprite.Color, v)); + .x2 = @as(i32, @intCast(self.width)), + .y2 = @as(i32, @intCast(self.height)), + }).rect(), @as(font.sprite.Color, @enumFromInt(v))); } 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 { - const y = @intFromFloat(u32, @round(@floatFromInt(f64, n) * @floatFromInt(f64, self.height) / 8)); - const h = @intFromFloat(u32, @round(@floatFromInt(f64, self.height) / 8)); + const y = @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(n)) * @as(f64, @floatFromInt(self.height)) / 8))); + const h = @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.height)) / 8))); 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 { self.rect( canvas, - self.width - @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 8)), + self.width - @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 8))), 0, self.width, 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 { self.rect( canvas, - self.width - @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 4)), + self.width - @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(self.width)) / 4))), 0, self.width, 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 { self.rect( 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, self.width, 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 { self.rect( 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, self.width, 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 { self.rect( 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, self.width, 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 { self.rect( 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, self.width, self.height, @@ -1502,18 +1502,18 @@ fn quad_upper_left(self: Box, canvas: *font.sprite.Canvas) void { canvas, 0, 0, - @intFromFloat(u32, @ceil(@floatFromInt(f64, self.width) / 2)), - @intFromFloat(u32, @ceil(@floatFromInt(f64, self.height) / 2)), + @as(u32, @intFromFloat(@ceil(@as(f64, @floatFromInt(self.width)) / 2))), + @as(u32, @intFromFloat(@ceil(@as(f64, @floatFromInt(self.height)) / 2))), ); } fn quad_upper_right(self: Box, canvas: *font.sprite.Canvas) void { self.rect( canvas, - @intFromFloat(u32, @floor(@floatFromInt(f64, self.width) / 2)), + @as(u32, @intFromFloat(@floor(@as(f64, @floatFromInt(self.width)) / 2))), 0, 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( canvas, 0, - @intFromFloat(u32, @floor(@floatFromInt(f64, self.height) / 2)), - @intFromFloat(u32, @ceil(@floatFromInt(f64, self.width) / 2)), + @as(u32, @intFromFloat(@floor(@as(f64, @floatFromInt(self.height)) / 2))), + @as(u32, @intFromFloat(@ceil(@as(f64, @floatFromInt(self.width)) / 2))), 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 { self.rect( canvas, - @intFromFloat(u32, @floor(@floatFromInt(f64, self.width) / 2)), - @intFromFloat(u32, @floor(@floatFromInt(f64, self.height) / 2)), + @as(u32, @intFromFloat(@floor(@as(f64, @floatFromInt(self.width)) / 2))), + @as(u32, @intFromFloat(@floor(@as(f64, @floatFromInt(self.height)) / 2))), self.width, self.height, ); @@ -1755,8 +1755,8 @@ fn draw_sextant(self: Box, canvas: *font.sprite.Canvas, cp: u32) void { fn xHalfs(self: Box) [2]u32 { return .{ - @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 2)), - @intFromFloat(u32, @floatFromInt(f64, self.width) / 2), + @as(u32, @intFromFloat(@round(@as(f64, @floatFromInt(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(.{ - .p1 = .{ .x = @intCast(i32, p1_x), .y = @intCast(i32, p1_y) }, - .p2 = .{ .x = @intCast(i32, p2_x), .y = @intCast(i32, p2_y) }, - .p3 = .{ .x = @intCast(i32, p3_x), .y = @intCast(i32, p3_y) }, + .p1 = .{ .x = @as(i32, @intCast(p1_x)), .y = @as(i32, @intCast(p1_y)) }, + .p2 = .{ .x = @as(i32, @intCast(p2_x)), .y = @as(i32, @intCast(p2_y)) }, + .p3 = .{ .x = @as(i32, @intCast(p3_x)), .y = @as(i32, @intCast(p3_y)) }, }, .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) { 0x1fb46, 0x1fb51 => .{ .x1 = 0, - .y1 = @intCast(i32, y_thirds[1]), - .x2 = @intCast(i32, self.width), - .y2 = @intCast(i32, self.height), + .y1 = @as(i32, @intCast(y_thirds[1])), + .x2 = @as(i32, @intCast(self.width)), + .y2 = @as(i32, @intCast(self.height)), }, 0x1fb5c, 0x1fb67 => .{ .x1 = 0, .y1 = 0, - .x2 = @intCast(i32, self.width), - .y2 = @intCast(i32, y_thirds[0]), + .x2 = @as(i32, @intCast(self.width)), + .y2 = @as(i32, @intCast(y_thirds[0])), }, else => unreachable, @@ -2191,7 +2191,7 @@ fn draw_light_arc( // 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 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 // 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 // uneven number helps hit that exactly. { - var i: f64 = @floatFromInt(f64, y_min) * 16; - while (i <= @floatFromInt(f64, y_max) * 16) : (i += 1) { + var i: f64 = @as(f64, @floatFromInt(y_min)) * 16; + while (i <= @as(f64, @floatFromInt(y_max)) * 16) : (i += 1) { const y = i / 16; const x = x: { // circle_hemisphere * sqrt(c_r2 - (y - c_y) * (y - c_y)) + c_x; - const hemi = @floatFromInt(f64, circle_hemisphere); - const y_part = y - @floatFromInt(f64, c_y); + const hemi = @as(f64, @floatFromInt(circle_hemisphere)); + const y_part = y - @as(f64, @floatFromInt(c_y)); const y_squared = y_part * y_part; 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 const a = hemi * sqrt; @@ -2326,15 +2326,15 @@ fn draw_light_arc( break :x b; }; - const row = @intFromFloat(i32, @round(y)); - const col = @intFromFloat(i32, @round(x)); + const row = @as(i32, @intFromFloat(@round(y))); + const col = @as(i32, @intFromFloat(@round(x))); if (col < 0) continue; // rectangle big enough to fit entire circle with radius thick/2. - const row1 = row - @intCast(i32, thick / 2 + 1); - const row2 = row + @intCast(i32, thick / 2 + 1); - const col1 = col - @intCast(i32, thick / 2 + 1); - const col2 = col + @intCast(i32, thick / 2 + 1); + const row1 = row - @as(i32, @intCast(thick / 2 + 1)); + const row2 = row + @as(i32, @intCast(thick / 2 + 1)); + const col1 = col - @as(i32, @intCast(thick / 2 + 1)); + const col2 = col + @as(i32, @intCast(thick / 2 + 1)); const row_start = @min(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 // their center to x,y is greater than thick/2. 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) { - const r_midpoint = @floatFromInt(f64, r) + 0.5; + const r_midpoint = @as(f64, @floatFromInt(r)) + 0.5; 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) { - 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. const center_midpoint_x = c_midpoint - x; @@ -2364,10 +2364,10 @@ fn draw_light_arc( // distance from current point to circle-center. const dist = @sqrt(center_midpoint_x * center_midpoint_x + center_midpoint_y * center_midpoint_y); // 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 - const idx = @intCast(usize, r * @intCast(i32, width) + c); + const idx = @as(usize, @intCast(r * @as(i32, @intCast(width)) + c)); 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( .{ - .x = @intCast(i32, c), - .y = @intCast(i32, r), + .x = @as(i32, @intCast(c)), + .y = @as(i32, @intCast(r)), .width = 1, .height = 1, }, - @enumFromInt(font.sprite.Color, average), + @as(font.sprite.Color, @enumFromInt(average)), ); } } @@ -2649,10 +2649,10 @@ fn vline( thickness_px: u32, ) void { canvas.rect((font.sprite.Box{ - .x1 = @intCast(i32, @min(@max(x, 0), self.width)), - .x2 = @intCast(i32, @min(@max(x + thickness_px, 0), self.width)), - .y1 = @intCast(i32, @min(@max(y1, 0), self.height)), - .y2 = @intCast(i32, @min(@max(y2, 0), self.height)), + .x1 = @as(i32, @intCast(@min(@max(x, 0), self.width))), + .x2 = @as(i32, @intCast(@min(@max(x + thickness_px, 0), self.width))), + .y1 = @as(i32, @intCast(@min(@max(y1, 0), self.height))), + .y2 = @as(i32, @intCast(@min(@max(y2, 0), self.height))), }).rect(), .on); } @@ -2665,10 +2665,10 @@ fn hline( thickness_px: u32, ) void { canvas.rect((font.sprite.Box{ - .x1 = @intCast(i32, @min(@max(x1, 0), self.width)), - .x2 = @intCast(i32, @min(@max(x2, 0), self.width)), - .y1 = @intCast(i32, @min(@max(y, 0), self.height)), - .y2 = @intCast(i32, @min(@max(y + thickness_px, 0), self.height)), + .x1 = @as(i32, @intCast(@min(@max(x1, 0), self.width))), + .x2 = @as(i32, @intCast(@min(@max(x2, 0), self.width))), + .y1 = @as(i32, @intCast(@min(@max(y, 0), self.height))), + .y2 = @as(i32, @intCast(@min(@max(y + thickness_px, 0), self.height))), }).rect(), .on); } @@ -2681,10 +2681,10 @@ fn rect( y2: u32, ) void { canvas.rect((font.sprite.Box{ - .x1 = @intCast(i32, @min(@max(x1, 0), self.width)), - .y1 = @intCast(i32, @min(@max(y1, 0), self.height)), - .x2 = @intCast(i32, @min(@max(x2, 0), self.width)), - .y2 = @intCast(i32, @min(@max(y2, 0), self.height)), + .x1 = @as(i32, @intCast(@min(@max(x1, 0), self.width))), + .y1 = @as(i32, @intCast(@min(@max(y1, 0), self.height))), + .x2 = @as(i32, @intCast(@min(@max(x2, 0), self.width))), + .y2 = @as(i32, @intCast(@min(@max(y2, 0), self.height))), }).rect(), .on); } diff --git a/src/font/sprite/Face.zig b/src/font/sprite/Face.zig index b23ec5481..1191272a4 100644 --- a/src/font/sprite/Face.zig +++ b/src/font/sprite/Face.zig @@ -72,7 +72,7 @@ pub fn renderGlyph( .underline => try underline.renderGlyph( alloc, atlas, - @enumFromInt(Sprite, cp), + @enumFromInt(cp), self.width, self.height, self.underline_position, @@ -88,7 +88,7 @@ const Kind = enum { pub fn init(cp: u32) ?Kind { return switch (cp) { - Sprite.start...Sprite.end => switch (@enumFromInt(Sprite, cp)) { + Sprite.start...Sprite.end => switch (@as(Sprite, @enumFromInt(cp))) { .underline, .underline_double, .underline_dotted, diff --git a/src/font/sprite/canvas.zig b/src/font/sprite/canvas.zig index c9312da9f..8603a7eec 100644 --- a/src/font/sprite/canvas.zig +++ b/src/font/sprite/canvas.zig @@ -31,8 +31,8 @@ pub const Box = struct { return .{ .x = tl_x, .y = tl_y, - .width = @intCast(u32, br_x - tl_x), - .height = @intCast(u32, br_y - tl_y), + .width = @intCast(br_x - tl_x), + .height = @intCast(br_y - tl_y), }; } }; @@ -68,16 +68,16 @@ pub const Color = enum(u8) { fn pixmanColor(self: Color) pixman.Color { // pixman uses u16 for color while our color value is u8 so we // scale it up proportionally. - const max = @floatFromInt(f32, std.math.maxInt(u8)); - const max_u16 = @floatFromInt(f32, std.math.maxInt(u16)); - const unscaled = @floatFromInt(f32, @intFromEnum(self)); - const scaled = @intFromFloat(u16, (unscaled * max_u16) / max); + const max = @as(f32, @floatFromInt(std.math.maxInt(u8))); + const max_u16 = @as(f32, @floatFromInt(std.math.maxInt(u16))); + const unscaled = @as(f32, @floatFromInt(@intFromEnum(self))); + const scaled = @as(u16, @intFromFloat((unscaled * max_u16) / max)); return .{ .red = 0, .green = 0, .blue = 0, .alpha = scaled }; } fn cssColor(self: Color, buf: []u8) ![]u8 { 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; defer ctx.deinit(); ctx.call(void, "fillRect", .{ - @intCast(u32, v.x), - @intCast(u32, v.y), + @as(u32, @intCast(v.x)), + @as(u32, @intCast(v.y)), v.width, v.height, }) catch return; @@ -235,7 +235,7 @@ const WebCanvasImpl = struct { // Allocate our local memory to copy the data to. 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); // Create our target Uint8Array that we can use to copy from src. @@ -304,7 +304,7 @@ const PixmanImpl = struct { // for boxes are always 8bpp const format: pixman.FormatCode = .a8; 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 // by 4 since u32 / u8 = 4. @@ -315,8 +315,8 @@ const PixmanImpl = struct { // Create the image we'll draw to const img = try pixman.Image.createBitsNoClear( format, - @intCast(c_int, width), - @intCast(c_int, height), + @intCast(width), + @intCast(height), data.ptr, stride, ); @@ -338,18 +338,15 @@ const PixmanImpl = struct { pub fn writeAtlas(self: *Canvas, alloc: Allocator, atlas: *font.Atlas) !font.Atlas.Region { assert(atlas.format == .greyscale); - const width = @intCast(u32, self.image.getWidth()); - const height = @intCast(u32, self.image.getHeight()); + const width = @as(u32, @intCast(self.image.getWidth())); + const height = @as(u32, @intCast(self.image.getHeight())); const region = try atlas.reserve(alloc, width, height); if (region.width > 0 and region.height > 0) { const depth = atlas.format.depth(); // Convert our []u32 to []u8 since we use 8bpp formats const stride = self.image.getStride(); - const data = @alignCast( - @alignOf(u8), - @ptrCast([*]u8, self.data.ptr)[0 .. self.data.len * 4], - ); + const data = @as([*]u8, @ptrCast(self.data.ptr))[0 .. self.data.len * 4]; // We can avoid a buffer copy if our atlas width and bitmap // width match and the bitmap pitch is just the width (meaning @@ -365,7 +362,7 @@ const PixmanImpl = struct { while (i < height) : (i += 1) { std.mem.copy(u8, dst_ptr, src_ptr[0 .. width * depth]); dst_ptr = dst_ptr[width * depth ..]; - src_ptr += @intCast(usize, stride); + src_ptr += @as(usize, @intCast(stride)); } break :buffer temp; } else data[0..(width * height * depth)]; @@ -385,10 +382,10 @@ const PixmanImpl = struct { pub fn rect(self: *Canvas, v: Rect, color: Color) void { const boxes = &[_]pixman.Box32{ .{ - .x1 = @intCast(i32, v.x), - .y1 = @intCast(i32, v.y), - .x2 = @intCast(i32, v.x + @intCast(i32, v.width)), - .y2 = @intCast(i32, v.y + @intCast(i32, v.height)), + .x1 = @intCast(v.x), + .y1 = @intCast(v.y), + .x2 = @intCast(v.x + @as(i32, @intCast(v.width))), + .y2 = @intCast(v.y + @as(i32, @intCast(v.height))), }, }; @@ -448,10 +445,10 @@ const PixmanImpl = struct { 0, 0, 0, - @intCast(i16, dest.x), - @intCast(i16, dest.y), - @intCast(u16, dest.width), - @intCast(u16, dest.height), + @intCast(dest.x), + @intCast(dest.y), + @intCast(dest.width), + @intCast(dest.height), ); } }; diff --git a/src/font/sprite/underline.zig b/src/font/sprite/underline.zig index 593b20e61..8979f2065 100644 --- a/src/font/sprite/underline.zig +++ b/src/font/sprite/underline.zig @@ -43,7 +43,7 @@ pub fn renderGlyph( // 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 // cell. - const offset_y = @intCast(i32, height); + const offset_y = @as(i32, @intCast(height)); return font.Glyph{ .width = width, @@ -52,7 +52,7 @@ pub fn renderGlyph( .offset_y = offset_y, .atlas_x = region.x, .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 const y_max = self.height -| 1; 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(.{ .x = 0, @@ -104,14 +104,14 @@ const Draw = struct { canvas.rect(.{ .x = 0, - .y = @intCast(i32, top), + .y = @intCast(top), .width = self.width, .height = self.thickness, }, .on); canvas.rect(.{ .x = 0, - .y = @intCast(i32, bottom), + .y = @intCast(bottom), .width = self.width, .height = self.thickness, }, .on); @@ -130,8 +130,8 @@ const Draw = struct { const x = @min(i * dot_width, self.width - 1); const width = @min(self.width - 1 - x, dot_width); canvas.rect(.{ - .x = @intCast(i32, i * dot_width), - .y = @intCast(i32, y), + .x = @intCast(i * dot_width), + .y = @intCast(y), .width = width, .height = self.thickness, }, .on); @@ -151,8 +151,8 @@ const Draw = struct { const x = @min(i * dash_width, self.width - 1); const width = @min(self.width - 1 - x, dash_width); canvas.rect(.{ - .x = @intCast(i32, x), - .y = @intCast(i32, y), + .x = @intCast(x), + .y = @intCast(y), .width = width, .height = self.thickness, }, .on); @@ -178,24 +178,24 @@ const Draw = struct { // The full heightof the wave can be from the bottom to the // underline position. We also calculate our starting y which is // 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 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; while (x < self.width) : (x += 1) { - const vertical = @intFromFloat( + const vertical = @as( 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; while (row < self.thickness) : (row += 1) { const y1 = @min(row + y + vertical, y_max); canvas.rect(.{ - .x = @intCast(i32, x), - .y = @intCast(i32, y1), + .x = @intCast(x), + .y = @intCast(y1), .width = 1, .height = 1, }, .on); diff --git a/src/input/key.zig b/src/input/key.zig index cf0cb4bca..f7a8a244a 100644 --- a/src/input/key.zig +++ b/src/input/key.zig @@ -17,9 +17,9 @@ pub const Mods = packed struct(u8) { // For our own understanding test { 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( - @bitCast(u8, Mods{ .shift = true }), + @as(u8, @bitCast(Mods{ .shift = true })), @as(u8, 0b0000_0001), ); } diff --git a/src/input/mouse.zig b/src/input/mouse.zig index 2073cbb18..2233c4494 100644 --- a/src/input/mouse.zig +++ b/src/input/mouse.zig @@ -79,9 +79,9 @@ pub const ScrollMods = packed struct(u8) { // For our own understanding test { 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( - @bitCast(u8, ScrollMods{ .precision = true }), + @as(u8, @bitCast(ScrollMods{ .precision = true })), @as(u8, 0b0000_0001), ); } diff --git a/src/os/flatpak.zig b/src/os/flatpak.zig index e40217d12..b27abc67d 100644 --- a/src/os/flatpak.zig +++ b/src/os/flatpak.zig @@ -164,7 +164,7 @@ pub const FlatpakHostCommand = struct { "(uub)", pid, sig, - @intCast(c_int, @intFromBool(pg)), + @as(c_int, @intCast(@intFromBool(pg))), ), c.G_VARIANT_TYPE("()"), c.G_DBUS_CALL_FLAGS_NONE, @@ -273,7 +273,7 @@ pub const FlatpakHostCommand = struct { } } 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 // 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, ud: ?*anyopaque, ) callconv(.C) void { - const self = @ptrCast(*FlatpakHostCommand, @alignCast(@alignOf(FlatpakHostCommand), ud)); + const self = @as(*FlatpakHostCommand, @ptrCast(@alignCast(ud))); const state = state: { self.state_mutex.lock(); defer self.state_mutex.unlock(); diff --git a/src/os/mouse.zig b/src/os/mouse.zig index 8051bbe6d..e8b6f0f10 100644 --- a/src/os/mouse.zig +++ b/src/os/mouse.zig @@ -16,7 +16,7 @@ pub fn clickInterval() ?u32 { // Get the interval and convert to ms 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; } diff --git a/src/os/wasm.zig b/src/os/wasm.zig index 4edfd5ab4..e8f32965b 100644 --- a/src/os/wasm.zig +++ b/src/os/wasm.zig @@ -70,7 +70,7 @@ pub fn toHostOwned(ptr: anytype) ![*]u8 { const info = @typeInfo(@TypeOf(ptr)).Pointer; const T = info.child; const size = @sizeOf(T); - const casted = @ptrFromInt([*]u8, @intFromPtr(ptr)); + const casted = @as([*]u8, @ptrFromInt(@intFromPtr(ptr))); // Store the information about it try allocs.putNoClobber(alloc, casted, size); @@ -81,14 +81,14 @@ pub fn toHostOwned(ptr: anytype) ![*]u8 { /// Returns true if the value is host owned. pub fn isHostOwned(ptr: anytype) bool { - const casted = @ptrFromInt([*]u8, @intFromPtr(ptr)); + const casted = @as([*]u8, @ptrFromInt(@intFromPtr(ptr))); return allocs.contains(casted); } /// Convert a pointer back to a module-owned value. The caller is expected /// to cast or have the valid pointer for alloc calls. pub fn toModuleOwned(ptr: anytype) void { - const casted = @ptrFromInt([*]u8, @intFromPtr(ptr)); + const casted = @as([*]u8, @ptrFromInt(@intFromPtr(ptr))); _ = allocs.remove(casted); } diff --git a/src/os/wasm/target.zig b/src/os/wasm/target.zig index 76a059f81..cd8b2dd33 100644 --- a/src/os/wasm/target.zig +++ b/src/os/wasm/target.zig @@ -11,7 +11,7 @@ pub const Target = enum { /// Our specific target platform. 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 // 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. diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 4240fc91b..7d41f2bc2 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -213,10 +213,10 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal { // Set the sprite font up options.font_group.group.sprite = font.sprite.Face{ - .width = @intFromFloat(u32, metrics.cell_width), - .height = @intFromFloat(u32, metrics.cell_height), + .width = @intFromFloat(metrics.cell_width), + .height = @intFromFloat(metrics.cell_height), .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 @@ -238,8 +238,8 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal { objc.Object, objc.sel("newBufferWithBytes:length:options:"), .{ - @ptrCast(*const anyopaque, &data), - @intCast(c_ulong, data.len * @sizeOf(u16)), + @as(*const anyopaque, @ptrCast(&data)), + @as(c_ulong, @intCast(data.len * @sizeOf(u16))), MTLResourceStorageModeShared, }, ); @@ -254,7 +254,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal { objc.Object, objc.sel("newBufferWithLength:options:"), .{ - @intCast(c_ulong, prealloc * @sizeOf(GPUCell)), + @as(c_ulong, @intCast(prealloc * @sizeOf(GPUCell))), MTLResourceStorageModeShared, }, ); @@ -269,7 +269,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal { objc.Object, objc.sel("newBufferWithLength:options:"), .{ - @intCast(c_ulong, prealloc * @sizeOf(GPUCell)), + @as(c_ulong, @intCast(prealloc * @sizeOf(GPUCell))), MTLResourceStorageModeShared, }, ); @@ -362,7 +362,7 @@ pub fn finalizeSurfaceInit(self: *const Metal, surface: *apprt.Surface) !void { apprt.embedded => .{ .view = surface.nsview, - .scaleFactor = @floatCast(f64, surface.content_scale.x), + .scaleFactor = @floatCast(surface.content_scale.x), }, 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 { if (DevMode.enabled) { // Initialize for our window - assert(imgui.ImplGlfw.initForOther( - @ptrCast(*imgui.ImplGlfw.GLFWWindow, surface.window.handle), - true, - )); + assert(imgui.ImplGlfw.initForOther(@ptrCast(surface.window.handle), true)); 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 self.font_group.group.sprite = font.sprite.Face{ - .width = @intFromFloat(u32, self.cell_size.width), - .height = @intFromFloat(u32, self.cell_size.height), + .width = @intFromFloat(self.cell_size.width), + .height = @intFromFloat(self.cell_size.height), .thickness = 2, - .underline_position = @intFromFloat(u32, metrics.underline_position), + .underline_position = @intFromFloat(metrics.underline_position), }; // Notify the window that the cell size changed. @@ -622,9 +619,9 @@ pub fn render( attachment.setProperty("storeAction", @intFromEnum(MTLStoreAction.store)); attachment.setProperty("texture", texture); attachment.setProperty("clearColor", MTLClearColor{ - .red = @floatFromInt(f32, critical.bg.r) / 255, - .green = @floatFromInt(f32, critical.bg.g) / 255, - .blue = @floatFromInt(f32, critical.bg.b) / 255, + .red = @as(f32, @floatFromInt(critical.bg.r)) / 255, + .green = @as(f32, @floatFromInt(critical.bg.g)) / 255, + .blue = @as(f32, @floatFromInt(critical.bg.b)) / 255, .alpha = 1.0, }); } @@ -651,7 +648,7 @@ pub fn render( void, 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, 1), }, @@ -771,8 +768,8 @@ pub fn setScreenSize(self: *Metal, dim: renderer.ScreenSize) !void { // Set the size of the drawable surface to the bounds self.swapchain.setProperty("drawableSize", macos.graphics.Size{ - .width = @floatFromInt(f64, dim.width), - .height = @floatFromInt(f64, dim.height), + .width = @floatFromInt(dim.width), + .height = @floatFromInt(dim.height), }); // Setup our uniforms @@ -780,8 +777,8 @@ pub fn setScreenSize(self: *Metal, dim: renderer.ScreenSize) !void { self.uniforms = .{ .projection_matrix = math.ortho2d( -1 * padding.left, - @floatFromInt(f32, padded_dim.width) + padding.right, - @floatFromInt(f32, padded_dim.height) + padding.bottom, + @as(f32, @floatFromInt(padded_dim.width)) + padding.right, + @as(f32, @floatFromInt(padded_dim.height)) + padding.bottom, -1 * padding.top, ), .cell_size = .{ self.cell_size.width, self.cell_size.height }, @@ -836,7 +833,7 @@ fn rebuildCells( y == screen.cursor.y) { 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) { cursor_cell = cell; @@ -986,7 +983,7 @@ pub fn updateCell( if (colors.bg) |rgb| { self.cells_bg.appendAssumeCapacity(.{ .mode = .bg, - .grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) }, + .grid_pos = .{ @as(f32, @floatFromInt(x)), @as(f32, @floatFromInt(y)) }, .cell_width = cell.widthLegacy(), .color = .{ rgb.r, rgb.g, rgb.b, alpha }, }); @@ -999,7 +996,7 @@ pub fn updateCell( self.alloc, shaper_run.font_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 @@ -1011,7 +1008,7 @@ pub fn updateCell( self.cells.appendAssumeCapacity(.{ .mode = mode, - .grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) }, + .grid_pos = .{ @as(f32, @floatFromInt(x)), @as(f32, @floatFromInt(y)) }, .cell_width = cell.widthLegacy(), .color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha }, .glyph_pos = .{ glyph.atlas_x, glyph.atlas_y }, @@ -1041,7 +1038,7 @@ pub fn updateCell( self.cells.appendAssumeCapacity(.{ .mode = .fg, - .grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) }, + .grid_pos = .{ @as(f32, @floatFromInt(x)), @as(f32, @floatFromInt(y)) }, .cell_width = cell.widthLegacy(), .color = .{ color.r, color.g, color.b, alpha }, .glyph_pos = .{ glyph.atlas_x, glyph.atlas_y }, @@ -1053,7 +1050,7 @@ pub fn updateCell( if (cell.attrs.strikethrough) { self.cells.appendAssumeCapacity(.{ .mode = .strikethrough, - .grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) }, + .grid_pos = .{ @as(f32, @floatFromInt(x)), @as(f32, @floatFromInt(y)) }, .cell_width = cell.widthLegacy(), .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(.{ .mode = .fg, .grid_pos = .{ - @floatFromInt(f32, screen.cursor.x), - @floatFromInt(f32, screen.cursor.y), + @as(f32, @floatFromInt(screen.cursor.x)), + @as(f32, @floatFromInt(screen.cursor.y)), }, .cell_width = if (cell.attrs.wide) 2 else 1, .color = .{ color.r, color.g, color.b, 0xFF }, @@ -1128,7 +1125,7 @@ fn syncCells( objc.Object, objc.sel("newBufferWithLength:options:"), .{ - @intCast(c_ulong, size * @sizeOf(GPUCell)), + @as(c_ulong, @intCast(size * @sizeOf(GPUCell))), MTLResourceStorageModeShared, }, ); @@ -1145,7 +1142,7 @@ fn syncCells( }; 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]; }; @@ -1172,12 +1169,12 @@ fn syncAtlasTexture(device: objc.Object, atlas: *const font.Atlas, texture: *obj MTLRegion{ .origin = .{ .x = 0, .y = 0, .z = 0 }, .size = .{ - .width = @intCast(c_ulong, atlas.size), - .height = @intCast(c_ulong, atlas.size), + .width = @intCast(atlas.size), + .height = @intCast(atlas.size), .depth = 1, }, }, - @as(c_ulong, 0), + 0, atlas.data.ptr, @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 desc.setProperty("pixelFormat", @intFromEnum(pixel_format)); - desc.setProperty("width", @intCast(c_ulong, atlas.size)); - desc.setProperty("height", @intCast(c_ulong, atlas.size)); + desc.setProperty("width", @as(c_ulong, @intCast(atlas.size))); + desc.setProperty("height", @as(c_ulong, @intCast(atlas.size))); // Initialize const id = device.msgSend( @@ -1462,9 +1459,9 @@ fn deinitMTLResource(obj: objc.Object) void { fn checkError(err_: ?*anyopaque) !void { if (err_) |err| { const nserr = objc.Object.fromId(err); - const str = @ptrCast( + const str = @as( *macos.foundation.String, - nserr.getProperty(?*anyopaque, "localizedDescription").?, + @ptrCast(nserr.getProperty(?*anyopaque, "localizedDescription").?), ); log.err("metal error={s}", .{str.cstringPtr(.ascii).?}); diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 4b13bf531..26dfc015f 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -136,8 +136,8 @@ const SetScreenSize = struct { try gl.viewport( 0, 0, - @intCast(i32, self.size.width), - @intCast(i32, self.size.height), + @intCast(self.size.width), + @intCast(self.size.height), ); // Update the projection uniform within our shader @@ -147,8 +147,8 @@ const SetScreenSize = struct { // 2D orthographic projection with the full w/h math.ortho2d( -1 * padding.left, - @floatFromInt(f32, padded_size.width) + padding.right, - @floatFromInt(f32, padded_size.height) + padding.bottom, + @as(f32, @floatFromInt(padded_size.width)) + padding.right, + @as(f32, @floatFromInt(padded_size.height)) + padding.bottom, -1 * padding.top, ), ); @@ -218,10 +218,7 @@ const GPUCellMode = enum(u8) { /// Apply a mask to the mode. pub fn mask(self: GPUCellMode, m: GPUCellMode) GPUCellMode { - return @enumFromInt( - GPUCellMode, - @intFromEnum(self) | @intFromEnum(m), - ); + return @enumFromInt(@intFromEnum(self) | @intFromEnum(m)); } }; @@ -357,8 +354,8 @@ pub fn init(alloc: Allocator, options: renderer.Options) !OpenGL { try texbind.image2D( 0, .Red, - @intCast(c_int, options.font_group.atlas_greyscale.size), - @intCast(c_int, options.font_group.atlas_greyscale.size), + @intCast(options.font_group.atlas_greyscale.size), + @intCast(options.font_group.atlas_greyscale.size), 0, .Red, .UnsignedByte, @@ -378,8 +375,8 @@ pub fn init(alloc: Allocator, options: renderer.Options) !OpenGL { try texbind.image2D( 0, .RGBA, - @intCast(c_int, options.font_group.atlas_color.size), - @intCast(c_int, options.font_group.atlas_color.size), + @intCast(options.font_group.atlas_color.size), + @intCast(options.font_group.atlas_color.size), 0, .BGRA, .UnsignedByte, @@ -476,8 +473,8 @@ pub fn surfaceInit(surface: *apprt.Surface) !void { const version = try gl.glad.load(null); errdefer gl.glad.unload(); log.info("loaded OpenGL {}.{}", .{ - gl.glad.versionMajor(@intCast(c_uint, version)), - gl.glad.versionMinor(@intCast(c_uint, version)), + gl.glad.versionMajor(@intCast(version)), + gl.glad.versionMinor(@intCast(version)), }); }, @@ -515,7 +512,7 @@ pub fn initDevMode(self: *const OpenGL, surface: *apprt.Surface) !void { if (DevMode.enabled) { // Initialize for our window assert(imgui.ImplGlfw.initForOpenGL( - @ptrCast(*imgui.ImplGlfw.GLFWWindow, surface.window.handle), + @ptrCast(surface.window.handle), true, )); 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); errdefer gl.glad.unload(); log.info("loaded OpenGL {}.{}", .{ - gl.glad.versionMajor(@intCast(c_uint, version)), - gl.glad.versionMinor(@intCast(c_uint, version)), + gl.glad.versionMajor(@intCast(version)), + gl.glad.versionMinor(@intCast(version)), }); }, } @@ -661,10 +658,10 @@ fn resetFontMetrics( // Set details for our sprite font font_group.group.sprite = font.sprite.Face{ - .width = @intFromFloat(u32, metrics.cell_width), - .height = @intFromFloat(u32, metrics.cell_height), + .width = @intFromFloat(metrics.cell_width), + .height = @intFromFloat(metrics.cell_height), .thickness = 2, - .underline_position = @intFromFloat(u32, metrics.underline_position), + .underline_position = @intFromFloat(metrics.underline_position), }; return metrics; @@ -895,7 +892,7 @@ pub fn rebuildCells( var i: usize = self.cells.items.len; for (gop.value_ptr.items) |cell| { self.cells.appendAssumeCapacity(cell); - self.cells.items[i].grid_row = @intCast(u16, y); + self.cells.items[i].grid_row = @intCast(y); i += 1; } @@ -1002,8 +999,8 @@ fn addCursor(self: *OpenGL, screen: *terminal.Screen) void { self.cells.appendAssumeCapacity(.{ .mode = .fg, - .grid_col = @intCast(u16, screen.cursor.x), - .grid_row = @intCast(u16, screen.cursor.y), + .grid_col = @intCast(screen.cursor.x), + .grid_row = @intCast(screen.cursor.y), .grid_width = if (cell.attrs.wide) 2 else 1, .fg_r = color.r, .fg_g = color.g, @@ -1120,8 +1117,8 @@ pub fn updateCell( self.cells_bg.appendAssumeCapacity(.{ .mode = mode, - .grid_col = @intCast(u16, x), - .grid_row = @intCast(u16, y), + .grid_col = @intCast(x), + .grid_row = @intCast(y), .grid_width = cell.widthLegacy(), .glyph_x = 0, .glyph_y = 0, @@ -1147,7 +1144,7 @@ pub fn updateCell( self.alloc, shaper_run.font_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 @@ -1159,8 +1156,8 @@ pub fn updateCell( self.cells.appendAssumeCapacity(.{ .mode = mode, - .grid_col = @intCast(u16, x), - .grid_row = @intCast(u16, y), + .grid_col = @intCast(x), + .grid_row = @intCast(y), .grid_width = cell.widthLegacy(), .glyph_x = glyph.atlas_x, .glyph_y = glyph.atlas_y, @@ -1200,8 +1197,8 @@ pub fn updateCell( self.cells.appendAssumeCapacity(.{ .mode = .fg, - .grid_col = @intCast(u16, x), - .grid_row = @intCast(u16, y), + .grid_col = @intCast(x), + .grid_row = @intCast(y), .grid_width = cell.widthLegacy(), .glyph_x = underline_glyph.atlas_x, .glyph_y = underline_glyph.atlas_y, @@ -1223,8 +1220,8 @@ pub fn updateCell( if (cell.attrs.strikethrough) { self.cells.appendAssumeCapacity(.{ .mode = .strikethrough, - .grid_col = @intCast(u16, x), - .grid_row = @intCast(u16, y), + .grid_col = @intCast(x), + .grid_row = @intCast(y), .grid_width = cell.widthLegacy(), .glyph_x = 0, .glyph_y = 0, @@ -1312,8 +1309,8 @@ fn flushAtlas(self: *OpenGL) !void { try texbind.image2D( 0, .Red, - @intCast(c_int, atlas.size), - @intCast(c_int, atlas.size), + @intCast(atlas.size), + @intCast(atlas.size), 0, .Red, .UnsignedByte, @@ -1324,8 +1321,8 @@ fn flushAtlas(self: *OpenGL) !void { 0, 0, 0, - @intCast(c_int, atlas.size), - @intCast(c_int, atlas.size), + @intCast(atlas.size), + @intCast(atlas.size), .Red, .UnsignedByte, atlas.data.ptr, @@ -1346,8 +1343,8 @@ fn flushAtlas(self: *OpenGL) !void { try texbind.image2D( 0, .RGBA, - @intCast(c_int, atlas.size), - @intCast(c_int, atlas.size), + @intCast(atlas.size), + @intCast(atlas.size), 0, .BGRA, .UnsignedByte, @@ -1358,8 +1355,8 @@ fn flushAtlas(self: *OpenGL) !void { 0, 0, 0, - @intCast(c_int, atlas.size), - @intCast(c_int, atlas.size), + @intCast(atlas.size), + @intCast(atlas.size), .BGRA, .UnsignedByte, atlas.data.ptr, @@ -1388,9 +1385,9 @@ pub fn draw(self: *OpenGL) !void { // Clear the surface gl.clearColor( - @floatFromInt(f32, self.draw_background.r) / 255, - @floatFromInt(f32, self.draw_background.g) / 255, - @floatFromInt(f32, self.draw_background.b) / 255, + @as(f32, @floatFromInt(self.draw_background.r)) / 255, + @as(f32, @floatFromInt(self.draw_background.g)) / 255, + @as(f32, @floatFromInt(self.draw_background.b)) / 255, 1.0, ); gl.clear(gl.c.GL_COLOR_BUFFER_BIT); diff --git a/src/renderer/opengl/Buffer.zig b/src/renderer/opengl/Buffer.zig index 12fab5294..b794ca4f0 100644 --- a/src/renderer/opengl/Buffer.zig +++ b/src/renderer/opengl/Buffer.zig @@ -54,7 +54,7 @@ pub const Binding = struct { data: anytype, ) !void { 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(); } @@ -76,7 +76,7 @@ pub const Binding = struct { size: usize, usage: Usage, ) !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(); } @@ -91,7 +91,7 @@ pub const Binding = struct { .ptr = data, }, .Slice => .{ - .size = @intCast(isize, @sizeOf(ptr.child) * data.len), + .size = @intCast(@sizeOf(ptr.child) * data.len), .ptr = data.ptr, }, else => { @@ -169,7 +169,7 @@ pub const Binding = struct { ) !void { const normalized_c: c.GLboolean = if (normalized) c.GL_TRUE else c.GL_FALSE; const offsetPtr = if (offset > 0) - @ptrFromInt(*const anyopaque, offset) + @as(*const anyopaque, @ptrFromInt(offset)) else null; @@ -186,7 +186,7 @@ pub const Binding = struct { offset: usize, ) !void { const offsetPtr = if (offset > 0) - @ptrFromInt(*const anyopaque, offset) + @as(*const anyopaque, @ptrFromInt(offset)) else null; diff --git a/src/renderer/opengl/Program.zig b/src/renderer/opengl/Program.zig index 2e2978363..fa5eee8dc 100644 --- a/src/renderer/opengl/Program.zig +++ b/src/renderer/opengl/Program.zig @@ -81,7 +81,7 @@ pub inline fn setUniform( ) !void { const loc = glad.context.GetUniformLocation.?( p.id, - @ptrCast([*c]const u8, n.ptr), + @ptrCast(n.ptr), ); if (loc < 0) { return error.UniformNameInvalid; @@ -99,7 +99,7 @@ pub inline fn setUniform( loc, 1, c.GL_FALSE, - @ptrCast([*c]const f32, &value), + @ptrCast(&value), ), else => unreachable, } diff --git a/src/renderer/opengl/Shader.zig b/src/renderer/opengl/Shader.zig index d5962c875..beaae9e94 100644 --- a/src/renderer/opengl/Shader.zig +++ b/src/renderer/opengl/Shader.zig @@ -23,7 +23,7 @@ pub inline fn create(typ: c.GLenum) errors.Error!Shader { /// Set the source and compile a shader. 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); // Check if compilation succeeded diff --git a/src/renderer/opengl/draw.zig b/src/renderer/opengl/draw.zig index 2a2ffabb3..ea6b63103 100644 --- a/src/renderer/opengl/draw.zig +++ b/src/renderer/opengl/draw.zig @@ -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 { - 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); try errors.getError(); } @@ -27,7 +27,7 @@ pub fn drawElementsInstanced( typ: c.GLenum, primcount: usize, ) !void { - glad.context.DrawElementsInstanced.?(mode, count, typ, null, @intCast(c.GLsizei, primcount)); + glad.context.DrawElementsInstanced.?(mode, count, typ, null, @intCast(primcount)); try errors.getError(); } diff --git a/src/renderer/opengl/extensions.zig b/src/renderer/opengl/extensions.zig index e58da3084..ca8a4973d 100644 --- a/src/renderer/opengl/extensions.zig +++ b/src/renderer/opengl/extensions.zig @@ -8,7 +8,7 @@ pub fn len() !u32 { var n: c.GLint = undefined; glad.context.GetIntegerv.?(c.GL_NUM_EXTENSIONS, &n); try errors.getError(); - return @intCast(u32, n); + return @intCast(n); } /// Returns an iterator for the extensions. diff --git a/src/renderer/opengl/glad.zig b/src/renderer/opengl/glad.zig index e1e763da6..4ee85c549 100644 --- a/src/renderer/opengl/glad.zig +++ b/src/renderer/opengl/glad.zig @@ -18,10 +18,7 @@ pub fn load(getProcAddress: anytype) !c_int { const res = switch (@TypeOf(getProcAddress)) { // glfw - GlfwFn => c.gladLoadGLContext(&context, @ptrCast( - *const fn ([*c]const u8) callconv(.C) ?GlProc, - getProcAddress, - )), + GlfwFn => c.gladLoadGLContext(&context, @ptrCast(getProcAddress)), // null proc address means that we are just loading the globally // pointed gl functions diff --git a/src/renderer/size.zig b/src/renderer/size.zig index d1e2224dc..b84298fa8 100644 --- a/src/renderer/size.zig +++ b/src/renderer/size.zig @@ -48,8 +48,8 @@ pub const ScreenSize = struct { /// Subtract padding from the screen size. pub fn subPadding(self: ScreenSize, padding: Padding) ScreenSize { return .{ - .width = self.width -| @intFromFloat(u32, padding.left + padding.right), - .height = self.height -| @intFromFloat(u32, padding.top + padding.bottom), + .width = self.width -| @as(u32, @intFromFloat(padding.left + padding.right)), + .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 /// cell size. pub fn update(self: *GridSize, screen: ScreenSize, cell: CellSize) void { - self.columns = @max(1, @intFromFloat(Unit, @floatFromInt(f32, screen.width) / cell.width)); - self.rows = @max(1, @intFromFloat(Unit, @floatFromInt(f32, screen.height) / cell.height)); + self.columns = @max(1, @as(Unit, @intFromFloat(@as(f32, @floatFromInt(screen.width)) / cell.width))); + 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. pub fn balanced(screen: ScreenSize, grid: GridSize, cell: CellSize) Padding { // The size of our full grid - const grid_width = @floatFromInt(f32, grid.columns) * cell.width; - const grid_height = @floatFromInt(f32, grid.rows) * cell.height; + const grid_width = @as(f32, @floatFromInt(grid.columns)) * cell.width; + 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 - const space_right = @floatFromInt(f32, screen.width) - grid_width; - const space_bot = @floatFromInt(f32, screen.height) - grid_height; + const space_right = @as(f32, @floatFromInt(screen.width)) - grid_width; + const space_bot = @as(f32, @floatFromInt(screen.height)) - grid_height; // The left/right padding is just an equal split. const padding_right = @floor(space_right / 2); diff --git a/src/terminal/Parser.zig b/src/terminal/Parser.zig index 99d26b3b4..b47260ffb 100644 --- a/src/terminal/Parser.zig +++ b/src/terminal/Parser.zig @@ -348,8 +348,8 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action { // If this is our first time seeing a parameter, we track // the separator used so that we can't mix separators later. - if (self.params_idx == 0) self.params_sep = @enumFromInt(ParamSepState, c); - if (@enumFromInt(ParamSepState, c) != self.params_sep) self.params_sep = .mixed; + if (self.params_idx == 0) self.params_sep = @enumFromInt(c); + if (@as(ParamSepState, @enumFromInt(c)) != self.params_sep) self.params_sep = .mixed; // Set param final value self.params[self.params_idx] = self.param_acc; diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index ba58bd678..7167ab962 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -228,7 +228,7 @@ pub const Cell = struct { } }); // 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. @@ -967,7 +967,7 @@ pub fn getRow(self: *Screen, index: RowIndex) Row { if (row.storage[0].header.id == 0) { const Id = @TypeOf(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 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. // We just clamp at 0 which blocks us from scrolling off the top. if (delta < 0) { - self.viewport -|= @intCast(usize, -delta); + self.viewport -|= @as(usize, @intCast(-delta)); return; } @@ -1472,7 +1472,7 @@ fn scrollDelta(self: *Screen, delta: isize, grow: bool) !void { if (!grow) { self.viewport = @min( self.history, - self.viewport + @intCast(usize, delta), + self.viewport + @as(usize, @intCast(delta)), ); 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 // allowed to scroll to the bottom (the end of the history), then we // have space and we just return. - self.viewport += @intCast(usize, delta); + self.viewport += @as(usize, @intCast(delta)); if (self.viewport <= self.history) return; // 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; 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; 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 @@ -2293,7 +2293,7 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void { if (grapheme.cell) |prev_cell| { const grapheme_break = brk: { var state: i32 = 0; - var cp1 = @intCast(u21, prev_cell.char); + var cp1 = @as(u21, @intCast(prev_cell.char)); if (prev_cell.attrs.grapheme) { var it = row.codepointIterator(grapheme.x); while (it.next()) |cp2| { @@ -2348,7 +2348,7 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void { switch (width) { 1 => { const cell = row.getCellPtr(x); - cell.char = @intCast(u32, c); + cell.char = @intCast(c); grapheme.x = x; grapheme.cell = cell; @@ -2373,7 +2373,7 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void { { const cell = row.getCellPtr(x); - cell.char = @intCast(u32, c); + cell.char = @intCast(c); cell.attrs.wide = true; grapheme.x = x; @@ -2422,7 +2422,7 @@ pub fn testString(self: *Screen, alloc: Allocator, tag: RowIndexTag) ![]const u8 while (cells.next()) |cell| { // TODO: handle character after null 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..]); } } } diff --git a/src/terminal/Tabstops.zig b/src/terminal/Tabstops.zig index 894e9964b..d3ddfbbfb 100644 --- a/src/terminal/Tabstops.zig +++ b/src/terminal/Tabstops.zig @@ -33,7 +33,7 @@ const prealloc_count = prealloc_columns / unit_bits; const masks = blk: { var res: [unit_bits]Unit = undefined; 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; diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 058977379..b17c6e542 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -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. // TODO: test 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 cols_req; @@ -627,7 +627,7 @@ pub fn print(self: *Terminal, c: u21) !void { const grapheme_break = brk: { var state: i32 = 0; - var cp1 = @intCast(u21, prev.cell.char); + var cp1 = @as(u21, @intCast(prev.cell.char)); if (prev.cell.attrs.grapheme) { var it = row.codepointIterator(prev.x); while (it.next()) |cp2| { @@ -735,7 +735,7 @@ fn printCell(self: *Terminal, unmapped_c: u21) *Screen.Cell { // const tracy = trace(@src()); // defer tracy.end(); - const c = c: { + const c: u21 = c: { // TODO: non-utf8 handling, gr // 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 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 }); @@ -790,7 +790,7 @@ fn printCell(self: *Terminal, unmapped_c: u21) *Screen.Cell { // Write cell.* = self.screen.cursor.pen; - cell.char = @intCast(u32, c); + cell.char = @intCast(c); return cell; } diff --git a/src/terminal/charsets.zig b/src/terminal/charsets.zig index e6ebe21aa..a42d7b0bc 100644 --- a/src/terminal/charsets.zig +++ b/src/terminal/charsets.zig @@ -91,7 +91,7 @@ const max_u8 = std.math.maxInt(u8); fn initTable() [max_u8]u16 { var result: [max_u8]u16 = undefined; 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); return result; } diff --git a/src/terminal/color.zig b/src/terminal/color.zig index 9414af52f..5ec739bf4 100644 --- a/src/terminal/color.zig +++ b/src/terminal/color.zig @@ -8,7 +8,7 @@ pub const default: Palette = default: { // Named values var i: u8 = 0; while (i < 16) : (i += 1) { - result[i] = Name.default(@enumFromInt(Name, i)) catch unreachable; + result[i] = Name.default(@enumFromInt(i)) catch unreachable; } // Cube @@ -111,6 +111,6 @@ test "palette: default" { // Safety check var i: u8 = 0; 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]); } } diff --git a/src/terminal/osc.zig b/src/terminal/osc.zig index ccbdd044e..6adebf430 100644 --- a/src/terminal/osc.zig +++ b/src/terminal/osc.zig @@ -397,7 +397,7 @@ pub const Parser = struct { fn endSemanticExitCode(self: *Parser) void { 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 => {}, } } diff --git a/src/terminal/parse_table.zig b/src/terminal/parse_table.zig index 450e5a266..3910653d7 100644 --- a/src/terminal/parse_table.zig +++ b/src/terminal/parse_table.zig @@ -61,7 +61,7 @@ fn genTable() Table { // anywhere transitions const stateInfo = @typeInfo(State); inline for (stateInfo.Enum.fields) |field| { - const source = @enumFromInt(State, field.value); + const source: State = @enumFromInt(field.value); // anywhere => ground single(&result, 0x18, source, .ground, .execute); @@ -357,7 +357,7 @@ fn genTable() Table { var final: Table = undefined; for (0..final.len) |i| { for (0..final[0].len) |j| { - final[i][j] = result[i][j] orelse transition(@enumFromInt(State, j), .none); + final[i][j] = result[i][j] orelse transition(@enumFromInt(j), .none); } } diff --git a/src/terminal/sgr.zig b/src/terminal/sgr.zig index 5272c1fb0..4ba19209f 100644 --- a/src/terminal/sgr.zig +++ b/src/terminal/sgr.zig @@ -186,7 +186,7 @@ pub const Parser = struct { 29 => return Attribute{ .reset_strikethrough = {} }, 30...37 => return Attribute{ - .@"8_fg" = @enumFromInt(color.Name, slice[0] - 30), + .@"8_fg" = @enumFromInt(slice[0] - 30), }, 38 => if (slice.len >= 5 and slice[1] == 2) { @@ -199,22 +199,22 @@ pub const Parser = struct { // it isn't, the behavior is undefined so we just... truncate it. return Attribute{ .direct_color_fg = .{ - .r = @truncate(u8, rgb[0]), - .g = @truncate(u8, rgb[1]), - .b = @truncate(u8, rgb[2]), + .r = @truncate(rgb[0]), + .g = @truncate(rgb[1]), + .b = @truncate(rgb[2]), }, }; } else if (slice.len >= 2 and slice[1] == 5) { self.idx += 2; return Attribute{ - .@"256_fg" = @truncate(u8, slice[2]), + .@"256_fg" = @truncate(slice[2]), }; }, 39 => return Attribute{ .reset_fg = {} }, 40...47 => return Attribute{ - .@"8_bg" = @enumFromInt(color.Name, slice[0] - 40), + .@"8_bg" = @enumFromInt(slice[0] - 40), }, 48 => if (slice.len >= 5 and slice[1] == 2) { @@ -231,15 +231,15 @@ pub const Parser = struct { // it isn't, the behavior is undefined so we just... truncate it. return Attribute{ .direct_color_bg = .{ - .r = @truncate(u8, rgb[0]), - .g = @truncate(u8, rgb[1]), - .b = @truncate(u8, rgb[2]), + .r = @truncate(rgb[0]), + .g = @truncate(rgb[1]), + .b = @truncate(rgb[2]), }, }; } else if (slice.len >= 2 and slice[1] == 5) { self.idx += 2; return Attribute{ - .@"256_bg" = @truncate(u8, slice[2]), + .@"256_bg" = @truncate(slice[2]), }; }, @@ -259,9 +259,9 @@ pub const Parser = struct { // it isn't, the behavior is undefined so we just... truncate it. return Attribute{ .underline_color = .{ - .r = @truncate(u8, rgb[0]), - .g = @truncate(u8, rgb[1]), - .b = @truncate(u8, rgb[2]), + .r = @truncate(rgb[0]), + .g = @truncate(rgb[1]), + .b = @truncate(rgb[2]), }, }; }, @@ -270,11 +270,11 @@ pub const Parser = struct { 90...97 => return Attribute{ // 82 instead of 90 to offset to "bright" colors - .@"8_bright_fg" = @enumFromInt(color.Name, slice[0] - 82), + .@"8_bright_fg" = @enumFromInt(slice[0] - 82), }, 100...107 => return Attribute{ - .@"8_bright_bg" = @enumFromInt(color.Name, slice[0] - 92), + .@"8_bright_bg" = @enumFromInt(slice[0] - 92), }, else => {}, diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index c0b3cfc5d..564d184ea 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -45,7 +45,7 @@ pub fn Stream(comptime Handler: type) type { /// Process the next character and call any callbacks if necessary. pub fn next(self: *Self, c: u8) !void { const tracy = trace(@src()); - tracy.value(@intCast(u64, c)); + tracy.value(@as(u64, @intCast(c))); defer tracy.end(); // log.debug("char: {c}", .{c}); @@ -70,10 +70,10 @@ pub fn Stream(comptime Handler: type) type { pub fn execute(self: *Self, c: u8) !void { const tracy = trace(@src()); - tracy.value(@intCast(u64, c)); + tracy.value(@as(u64, @intCast(c))); defer tracy.end(); - switch (@enumFromInt(ansi.C0, c)) { + switch (@as(ansi.C0, @enumFromInt(c))) { .NUL => {}, .ENQ => if (@hasDecl(T, "enquiry")) @@ -229,10 +229,7 @@ pub fn Stream(comptime Handler: type) type { return; } - break :mode @enumFromInt( - csi.EraseDisplay, - action.params[0], - ); + break :mode @enumFromInt(action.params[0]); }, else => { log.warn("invalid erase display command: {}", .{action}); @@ -252,10 +249,7 @@ pub fn Stream(comptime Handler: type) type { return; } - break :mode @enumFromInt( - csi.EraseLine, - action.params[0], - ); + break :mode @enumFromInt(action.params[0]); }, else => { log.warn("invalid erase line command: {}", .{action}); @@ -422,7 +416,7 @@ pub fn Stream(comptime Handler: type) type { // TODO: test 'g' => if (@hasDecl(T, "tabClear")) try self.handler.tabClear( switch (action.params.len) { - 1 => @enumFromInt(csi.TabClear, action.params[0]), + 1 => @enumFromInt(action.params[0]), else => { log.warn("invalid tab clear command: {}", .{action}); return; @@ -433,13 +427,13 @@ pub fn Stream(comptime Handler: type) type { // SM - Set Mode 'h' => if (@hasDecl(T, "setMode")) { for (action.params) |mode| - try self.handler.setMode(@enumFromInt(ansi.Mode, mode), true); + try self.handler.setMode(@enumFromInt(mode), true); } else log.warn("unimplemented CSI callback: {}", .{action}), // RM - Reset Mode 'l' => if (@hasDecl(T, "setMode")) { for (action.params) |mode| - try self.handler.setMode(@enumFromInt(ansi.Mode, mode), false); + try self.handler.setMode(@enumFromInt(mode), false); } else log.warn("unimplemented CSI callback: {}", .{action}), // SGR - Select Graphic Rendition @@ -455,7 +449,7 @@ pub fn Stream(comptime Handler: type) type { // TODO: test 'n' => if (@hasDecl(T, "deviceStatusReport")) try self.handler.deviceStatusReport( switch (action.params.len) { - 1 => @enumFromInt(ansi.DeviceStatusReq, action.params[0]), + 1 => @enumFromInt(action.params[0]), else => { log.warn("invalid erase characters command: {}", .{action}); return; @@ -468,7 +462,7 @@ pub fn Stream(comptime Handler: type) type { 'q' => if (@hasDecl(T, "setCursorStyle")) try self.handler.setCursorStyle( switch (action.params.len) { 0 => ansi.CursorStyle.default, - 1 => @enumFromInt(ansi.CursorStyle, action.params[0]), + 1 => @enumFromInt(action.params[0]), else => { log.warn("invalid set curor style command: {}", .{action}); return; @@ -504,9 +498,7 @@ pub fn Stream(comptime Handler: type) type { if (!@hasDecl(T, "setActiveStatusDisplay")) break :decsasd false; - try self.handler.setActiveStatusDisplay( - @enumFromInt(ansi.StatusDisplay, action.params[0]), - ); + try self.handler.setActiveStatusDisplay(@enumFromInt(action.params[0])); break :decsasd true; }; @@ -799,10 +791,10 @@ test "stream: cursor right (CUF)" { test "stream: set mode (SM) and reset mode (RM)" { const H = struct { - mode: ansi.Mode = @enumFromInt(ansi.Mode, 0), + mode: ansi.Mode = @as(ansi.Mode, @enumFromInt(0)), pub fn setMode(self: *@This(), mode: ansi.Mode, v: bool) !void { - self.mode = @enumFromInt(ansi.Mode, 0); + self.mode = @as(ansi.Mode, @enumFromInt(0)); if (v) self.mode = mode; } }; @@ -812,5 +804,5 @@ test "stream: set mode (SM) and reset mode (RM)" { try testing.expectEqual(@as(ansi.Mode, .origin), s.handler.mode); try s.nextSlice("\x1B[?6l"); - try testing.expectEqual(@enumFromInt(ansi.Mode, 0), s.handler.mode); + try testing.expectEqual(@as(ansi.Mode, @enumFromInt(0)), s.handler.mode); } diff --git a/src/terminal/wasm.zig b/src/terminal/wasm.zig index 009ff56e8..3450a6829 100644 --- a/src/terminal/wasm.zig +++ b/src/terminal/wasm.zig @@ -27,6 +27,6 @@ export fn terminal_free(ptr: ?*Terminal) void { export fn terminal_print(ptr: ?*Terminal, char: u32) void { if (ptr) |t| { - t.print(@intCast(u21, char)) catch return; + t.print(@intCast(char)) catch return; } } diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 6596be7a3..91d3d2633 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -581,10 +581,10 @@ const Subprocess = struct { // Create our pty var pty = try Pty.open(.{ - .ws_row = @intCast(u16, self.grid_size.rows), - .ws_col = @intCast(u16, self.grid_size.columns), - .ws_xpixel = @intCast(u16, self.screen_size.width), - .ws_ypixel = @intCast(u16, self.screen_size.height), + .ws_row = @intCast(self.grid_size.rows), + .ws_col = @intCast(self.grid_size.columns), + .ws_xpixel = @intCast(self.screen_size.width), + .ws_ypixel = @intCast(self.screen_size.height), }); self.pty = pty; errdefer { @@ -720,10 +720,10 @@ const Subprocess = struct { if (self.pty) |pty| { try pty.setSize(.{ - .ws_row = @intCast(u16, grid_size.rows), - .ws_col = @intCast(u16, grid_size.columns), - .ws_xpixel = @intCast(u16, screen_size.width), - .ws_ypixel = @intCast(u16, screen_size.height), + .ws_row = @intCast(grid_size.rows), + .ws_col = @intCast(grid_size.columns), + .ws_xpixel = @intCast(screen_size.width), + .ws_ypixel = @intCast(screen_size.height), }); } } @@ -883,7 +883,7 @@ const ReadThread = struct { for (buf[i..end]) |ch| { switch (terminal.parse_table.table[ch][@intFromEnum(terminal.Parser.State.ground)].action) { // Print, call directly. - .print => ev.terminal_stream.handler.print(@intCast(u21, ch)) catch |err| + .print => ev.terminal_stream.handler.print(@intCast(ch)) catch |err| log.err("error processing terminal data: {}", .{err}), // C0 execute, let our stream handle this one but otherwise @@ -1196,7 +1196,7 @@ const StreamHandler = struct { pos.y + 1, pos.x + 1, }); - msg.write_small.len = @intCast(u8, resp.len); + msg.write_small.len = @intCast(resp.len); self.messageWriter(msg); }, diff --git a/src/termio/message.zig b/src/termio/message.zig index fe4fc535d..e19af749e 100644 --- a/src/termio/message.zig +++ b/src/termio/message.zig @@ -116,7 +116,7 @@ pub fn MessageData(comptime Elem: type, comptime small_size: comptime_int) type return Self{ .small = .{ .data = buf, - .len = @intCast(u8, data.len), + .len = @intCast(data.len), }, }; } diff --git a/vendor/libxev b/vendor/libxev index b17acd118..e2d972363 160000 --- a/vendor/libxev +++ b/vendor/libxev @@ -1 +1 @@ -Subproject commit b17acd118d3442b5e937f509cfbc95e17bed47ba +Subproject commit e2d972363c4985375648396ba5b27a42a15aebd6 diff --git a/vendor/mach-glfw b/vendor/mach-glfw index 1bc121e0b..70ff87ba8 160000 --- a/vendor/mach-glfw +++ b/vendor/mach-glfw @@ -1 +1 @@ -Subproject commit 1bc121e0b1fcc0d367b750eb12893febd887d3a9 +Subproject commit 70ff87ba8af0820bbcfdbdf3b15555cb4c19f7ab diff --git a/vendor/zig-js b/vendor/zig-js index b4648de08..3639752be 160000 --- a/vendor/zig-js +++ b/vendor/zig-js @@ -1 +1 @@ -Subproject commit b4648de08943f7b3d5eb462cfd062270a8c5f037 +Subproject commit 3639752be98d5168f821704dca02b5eb8b915ea9 diff --git a/vendor/zig-objc b/vendor/zig-objc index 1e3537ab9..51584a2f7 160000 --- a/vendor/zig-objc +++ b/vendor/zig-objc @@ -1 +1 @@ -Subproject commit 1e3537ab97144c5c0fe0979c12c92121912a5e89 +Subproject commit 51584a2f7842ae10c9859b76ba5722ddf3f58e24