From 56f8e39e5bc4f7c96a5f5c661604d6a10390875f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 25 Jun 2023 11:08:12 -0700 Subject: [PATCH 1/4] Update zig, mach, fmt --- build.zig | 6 +- flake.lock | 6 +- pkg/fontconfig/config.zig | 2 +- pkg/fontconfig/pattern.zig | 8 +- pkg/fontconfig/value.zig | 4 +- pkg/freetype/face.zig | 4 +- pkg/harfbuzz/blob.zig | 2 +- pkg/harfbuzz/buffer.zig | 12 +- pkg/imgui/font_atlas.zig | 2 +- pkg/macos/foundation/attributed_string.zig | 8 +- pkg/macos/foundation/character_set.zig | 4 +- pkg/macos/foundation/data.zig | 4 +- pkg/macos/foundation/dictionary.zig | 8 +- pkg/macos/foundation/number.zig | 6 +- pkg/macos/foundation/string.zig | 12 +- pkg/macos/foundation/url.zig | 6 +- pkg/macos/graphics/bitmap_context.zig | 4 +- pkg/macos/graphics/color_space.zig | 8 +- pkg/macos/graphics/context.zig | 2 +- pkg/macos/graphics/path.zig | 8 +- pkg/macos/os/log.zig | 4 +- pkg/macos/text/font.zig | 18 +-- pkg/macos/text/font_collection.zig | 10 +- pkg/macos/text/font_descriptor.zig | 20 ++-- pkg/macos/text/font_manager.zig | 8 +- pkg/macos/text/frame.zig | 4 +- pkg/macos/text/framesetter.zig | 8 +- pkg/macos/text/line.zig | 4 +- pkg/macos/text/stylized_strings.zig | 2 +- pkg/pixman/format.zig | 2 +- pkg/pixman/image.zig | 12 +- pkg/pixman/types.zig | 4 +- src/DevMode.zig | 10 +- src/Pty.zig | 4 +- src/Surface.zig | 34 +++--- src/apprt/glfw.zig | 8 +- src/config.zig | 6 +- src/font/Atlas.zig | 6 +- src/font/DeferredFace.zig | 2 +- src/font/Group.zig | 20 ++-- src/font/GroupCache.zig | 4 +- src/font/discovery.zig | 4 +- src/font/face/coretext.zig | 14 +-- src/font/face/freetype.zig | 22 ++-- src/font/face/web_canvas.zig | 8 +- src/font/sprite.zig | 2 +- src/font/sprite/Box.zig | 124 ++++++++++----------- src/font/sprite/Face.zig | 4 +- src/font/sprite/canvas.zig | 10 +- src/font/sprite/underline.zig | 12 +- src/os/flatpak.zig | 2 +- src/os/mouse.zig | 2 +- src/os/wasm.zig | 6 +- src/os/wasm/target.zig | 2 +- src/renderer/Metal.zig | 86 +++++++------- src/renderer/OpenGL.zig | 26 ++--- src/renderer/opengl/Buffer.zig | 16 +-- src/renderer/opengl/Texture.zig | 24 ++-- src/renderer/opengl/draw.zig | 2 +- src/renderer/size.zig | 16 +-- src/terminal/Parser.zig | 8 +- src/terminal/Screen.zig | 4 +- src/terminal/Terminal.zig | 8 +- src/terminal/color.zig | 4 +- src/terminal/parse_table.zig | 6 +- src/terminal/sgr.zig | 8 +- src/terminal/stream.zig | 24 ++-- src/termio/Exec.zig | 2 +- vendor/mach-glfw | 2 +- 69 files changed, 377 insertions(+), 377 deletions(-) diff --git a/build.zig b/build.zig index b846894b7..552d17fe1 100644 --- a/build.zig +++ b/build.zig @@ -48,7 +48,7 @@ comptime { } /// The version of the next release. -const app_version = std.builtin.Version{ .major = 0, .minor = 1, .patch = 0 }; +const app_version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 }; /// Build options, see the build options help for more info. var tracy: bool = false; @@ -63,12 +63,12 @@ pub fn build(b: *std.Build) !void { if (result.isLinux() and result.isGnuLibC()) { // https://github.com/ziglang/zig/issues/9485 - result.glibc_version = .{ .major = 2, .minor = 28 }; + result.glibc_version = .{ .major = 2, .minor = 28, .patch = 0 }; } if (result.isDarwin()) { if (result.os_version_min == null) { - result.os_version_min = .{ .semver = .{ .major = 12, .minor = 0 } }; + result.os_version_min = .{ .semver = .{ .major = 12, .minor = 0, .patch = 0 } }; } } diff --git a/flake.lock b/flake.lock index e277a76d8..5e264c1e7 100644 --- a/flake.lock +++ b/flake.lock @@ -126,11 +126,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1686917286, - "narHash": "sha256-dbs4tcFlJqLyrrZrvdMsKjUe9B86N6INKvkG4uSnUfM=", + "lastModified": 1687694884, + "narHash": "sha256-TLXEykE/LSMwGETveZ9lI8fvd7nuJgq0+6tQwvCvP1k=", "owner": "mitchellh", "repo": "zig-overlay", - "rev": "18cb1c5a59b38e2054a76a296f2fac659cd6eed4", + "rev": "1c1c9f9ecc76ec222826770e10e6fef4c54d1e82", "type": "github" }, "original": { diff --git a/pkg/fontconfig/config.zig b/pkg/fontconfig/config.zig index 0b2fd5127..f26b88784 100644 --- a/pkg/fontconfig/config.zig +++ b/pkg/fontconfig/config.zig @@ -46,7 +46,7 @@ pub const Config = opaque { return c.FcConfigSubstitute( self.cval(), pat.cval(), - @enumToInt(kind), + @intFromEnum(kind), ) == c.FcTrue; } diff --git a/pkg/fontconfig/pattern.zig b/pkg/fontconfig/pattern.zig index 6d3f8f843..4510157e8 100644 --- a/pkg/fontconfig/pattern.zig +++ b/pkg/fontconfig/pattern.zig @@ -37,7 +37,7 @@ pub const Pattern = opaque { pub fn get(self: *Pattern, prop: Property, id: u32) Error!Value { var val: c.struct__FcValue = undefined; - try @intToEnum(Result, c.FcPatternGet( + try @enumFromInt(Result, c.FcPatternGet( self.cval(), prop.cval().ptr, @intCast(c_int, id), @@ -139,8 +139,8 @@ pub const Pattern = opaque { self.id += 1; return Entry{ - .result = @intToEnum(Result, result), - .binding = @intToEnum(ValueBinding, binding), + .result = @enumFromInt(Result, result), + .binding = @enumFromInt(ValueBinding, binding), .value = Value.init(&value), }; } @@ -154,7 +154,7 @@ test "create" { defer pat.destroy(); try testing.expect(pat.add(.family, .{ .string = "monospace" }, false)); - try testing.expect(pat.add(.weight, .{ .integer = @enumToInt(Weight.bold) }, false)); + try testing.expect(pat.add(.weight, .{ .integer = @intFromEnum(Weight.bold) }, false)); { const val = try pat.get(.family, 0); diff --git a/pkg/fontconfig/value.zig b/pkg/fontconfig/value.zig index d1cde25f1..9b74450d1 100644 --- a/pkg/fontconfig/value.zig +++ b/pkg/fontconfig/value.zig @@ -34,7 +34,7 @@ pub const Value = union(Type) { range: *const Range, pub fn init(cvalue: *c.struct__FcValue) Value { - return switch (@intToEnum(Type, cvalue.type)) { + return switch (@enumFromInt(Type, cvalue.type)) { .unknown => .{ .unknown = {} }, .void => .{ .void = {} }, .string => .{ .string = std.mem.sliceTo(cvalue.u.s, 0) }, @@ -51,7 +51,7 @@ pub const Value = union(Type) { pub fn cval(self: Value) c.struct__FcValue { return .{ - .type = @enumToInt(std.meta.activeTag(self)), + .type = @intFromEnum(std.meta.activeTag(self)), .u = switch (self) { .unknown => undefined, .void => undefined, diff --git a/pkg/freetype/face.zig b/pkg/freetype/face.zig index e6b6df90c..d684601f6 100644 --- a/pkg/freetype/face.zig +++ b/pkg/freetype/face.zig @@ -33,7 +33,7 @@ pub const Face = struct { /// Select a given charmap by its encoding tag (as listed in freetype.h). pub fn selectCharmap(self: Face, encoding: Encoding) Error!void { - return intToError(c.FT_Select_Charmap(self.handle, @enumToInt(encoding))); + return intToError(c.FT_Select_Charmap(self.handle, @intFromEnum(encoding))); } /// Call FT_Request_Size to request the nominal size (in points). @@ -81,7 +81,7 @@ pub const Face = struct { const T = tag.DataType(); return @ptrCast(?*T, @alignCast(@alignOf(T), c.FT_Get_Sfnt_Table( self.handle, - @enumToInt(tag), + @intFromEnum(tag), ))); } }; diff --git a/pkg/harfbuzz/blob.zig b/pkg/harfbuzz/blob.zig index 071a4da88..1dd2caff1 100644 --- a/pkg/harfbuzz/blob.zig +++ b/pkg/harfbuzz/blob.zig @@ -55,7 +55,7 @@ pub const Blob = struct { const handle = c.hb_blob_create_or_fail( data.ptr, @intCast(c_uint, data.len), - @enumToInt(mode), + @intFromEnum(mode), null, null, ) orelse return Error.HarfbuzzFailed; diff --git a/pkg/harfbuzz/buffer.zig b/pkg/harfbuzz/buffer.zig index b48fc985b..4508e2f15 100644 --- a/pkg/harfbuzz/buffer.zig +++ b/pkg/harfbuzz/buffer.zig @@ -39,13 +39,13 @@ pub const Buffer = struct { /// Sets the type of buffer contents. Buffers are either empty, contain /// characters (before shaping), or contain glyphs (the result of shaping). pub fn setContentType(self: Buffer, ct: ContentType) void { - c.hb_buffer_set_content_type(self.handle, @enumToInt(ct)); + c.hb_buffer_set_content_type(self.handle, @intFromEnum(ct)); } /// 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 @intToEnum(ContentType, c.hb_buffer_get_content_type(self.handle)); + return @enumFromInt(ContentType, c.hb_buffer_get_content_type(self.handle)); } /// Appends a character with the Unicode value of codepoint to buffer, @@ -144,12 +144,12 @@ pub const Buffer = struct { /// direction is not the same as keeping the text in logical order and /// shaping with RTL direction. pub fn setDirection(self: Buffer, dir: Direction) void { - c.hb_buffer_set_direction(self.handle, @enumToInt(dir)); + c.hb_buffer_set_direction(self.handle, @intFromEnum(dir)); } /// See hb_buffer_set_direction() pub fn getDirection(self: Buffer) Direction { - return @intToEnum(Direction, c.hb_buffer_get_direction(self.handle)); + return @enumFromInt(Direction, c.hb_buffer_get_direction(self.handle)); } /// Sets the script of buffer to script. @@ -162,12 +162,12 @@ pub const Buffer = struct { /// hb_script_from_string() or hb_script_from_iso15924_tag() to get the /// corresponding script from an ISO 15924 script tag. pub fn setScript(self: Buffer, script: Script) void { - c.hb_buffer_set_script(self.handle, @enumToInt(script)); + c.hb_buffer_set_script(self.handle, @intFromEnum(script)); } /// See hb_buffer_set_script() pub fn getScript(self: Buffer) Script { - return @intToEnum(Script, c.hb_buffer_get_script(self.handle)); + return @enumFromInt(Script, c.hb_buffer_get_script(self.handle)); } /// Sets the language of buffer to language . diff --git a/pkg/imgui/font_atlas.zig b/pkg/imgui/font_atlas.zig index ba34670c9..e1c225086 100644 --- a/pkg/imgui/font_atlas.zig +++ b/pkg/imgui/font_atlas.zig @@ -17,7 +17,7 @@ pub const FontAtlas = opaque { _ = c.ImFontAtlas_AddFontFromMemoryTTF( self.cval(), - @intToPtr(?*anyopaque, @ptrToInt(data.ptr)), + @ptrFromInt(?*anyopaque, @intFromPtr(data.ptr)), @intCast(c_int, data.len), size_px, cfg, diff --git a/pkg/macos/foundation/attributed_string.zig b/pkg/macos/foundation/attributed_string.zig index 4c03c2859..13e573641 100644 --- a/pkg/macos/foundation/attributed_string.zig +++ b/pkg/macos/foundation/attributed_string.zig @@ -18,9 +18,9 @@ pub const AttributedString = opaque { } pub fn getString(self: *AttributedString) *foundation.String { - return @intToPtr( + return @ptrFromInt( *foundation.String, - @ptrToInt( + @intFromPtr( c.CFAttributedStringGetString(@ptrCast(c.CFAttributedStringRef, self)), ), ); @@ -29,9 +29,9 @@ pub const AttributedString = opaque { pub const MutableAttributedString = opaque { pub fn create(cap: usize) Allocator.Error!*MutableAttributedString { - return @intToPtr( + return @ptrFromInt( ?*MutableAttributedString, - @ptrToInt(c.CFAttributedStringCreateMutable( + @intFromPtr(c.CFAttributedStringCreateMutable( null, @intCast(c.CFIndex, cap), )), diff --git a/pkg/macos/foundation/character_set.zig b/pkg/macos/foundation/character_set.zig index ace4b1953..cf1955284 100644 --- a/pkg/macos/foundation/character_set.zig +++ b/pkg/macos/foundation/character_set.zig @@ -8,7 +8,7 @@ pub const CharacterSet = opaque { pub fn createWithCharactersInString( str: *foundation.String, ) Allocator.Error!*CharacterSet { - return @intToPtr(?*CharacterSet, @ptrToInt(c.CFCharacterSetCreateWithCharactersInString( + return @ptrFromInt(?*CharacterSet, @intFromPtr(c.CFCharacterSetCreateWithCharactersInString( null, @ptrCast(c.CFStringRef, str), ))) orelse Allocator.Error.OutOfMemory; @@ -17,7 +17,7 @@ pub const CharacterSet = opaque { pub fn createWithCharactersInRange( range: foundation.Range, ) Allocator.Error!*CharacterSet { - return @intToPtr(?*CharacterSet, @ptrToInt(c.CFCharacterSetCreateWithCharactersInRange( + return @ptrFromInt(?*CharacterSet, @intFromPtr(c.CFCharacterSetCreateWithCharactersInRange( null, range.cval(), ))) orelse Allocator.Error.OutOfMemory; diff --git a/pkg/macos/foundation/data.zig b/pkg/macos/foundation/data.zig index eafb93595..10db75860 100644 --- a/pkg/macos/foundation/data.zig +++ b/pkg/macos/foundation/data.zig @@ -5,9 +5,9 @@ const c = @import("c.zig"); pub const Data = opaque { pub fn createWithBytesNoCopy(data: []const u8) Allocator.Error!*Data { - return @intToPtr( + return @ptrFromInt( ?*Data, - @ptrToInt(c.CFDataCreateWithBytesNoCopy( + @intFromPtr(c.CFDataCreateWithBytesNoCopy( null, data.ptr, @intCast(c_long, data.len), diff --git a/pkg/macos/foundation/dictionary.zig b/pkg/macos/foundation/dictionary.zig index 710fd1e4f..cdd16020c 100644 --- a/pkg/macos/foundation/dictionary.zig +++ b/pkg/macos/foundation/dictionary.zig @@ -15,7 +15,7 @@ pub const Dictionary = opaque { assert(keys.?.len == values.?.len); } - return @intToPtr(?*Dictionary, @ptrToInt(c.CFDictionaryCreate( + return @ptrFromInt(?*Dictionary, @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), @@ -34,7 +34,7 @@ pub const Dictionary = opaque { } pub fn getValue(self: *Dictionary, comptime V: type, key: ?*const anyopaque) ?*V { - return @intToPtr(?*V, @ptrToInt(c.CFDictionaryGetValue( + return @ptrFromInt(?*V, @intFromPtr(c.CFDictionaryGetValue( @ptrCast(c.CFDictionaryRef, self), key, ))); @@ -43,7 +43,7 @@ pub const Dictionary = opaque { pub const MutableDictionary = opaque { pub fn create(cap: usize) Allocator.Error!*MutableDictionary { - return @intToPtr(?*MutableDictionary, @ptrToInt(c.CFDictionaryCreateMutable( + return @ptrFromInt(?*MutableDictionary, @intFromPtr(c.CFDictionaryCreateMutable( null, @intCast(c.CFIndex, cap), &c.kCFTypeDictionaryKeyCallBacks, @@ -52,7 +52,7 @@ pub const MutableDictionary = opaque { } pub fn createMutableCopy(cap: usize, src: *Dictionary) Allocator.Error!*MutableDictionary { - return @intToPtr(?*MutableDictionary, @ptrToInt(c.CFDictionaryCreateMutableCopy( + return @ptrFromInt(?*MutableDictionary, @intFromPtr(c.CFDictionaryCreateMutableCopy( null, @intCast(c.CFIndex, cap), @ptrCast(c.CFDictionaryRef, src), diff --git a/pkg/macos/foundation/number.zig b/pkg/macos/foundation/number.zig index df9e3b1f8..9d580c998 100644 --- a/pkg/macos/foundation/number.zig +++ b/pkg/macos/foundation/number.zig @@ -8,9 +8,9 @@ pub const Number = opaque { comptime type_: NumberType, value: *const type_.ValueType(), ) Allocator.Error!*Number { - return @intToPtr(?*Number, @ptrToInt(c.CFNumberCreate( + return @ptrFromInt(?*Number, @intFromPtr(c.CFNumberCreate( null, - @enumToInt(type_), + @intFromEnum(type_), value, ))) orelse Allocator.Error.OutOfMemory; } @@ -18,7 +18,7 @@ pub const Number = opaque { pub fn getValue(self: *Number, comptime t: NumberType, ptr: *t.ValueType()) bool { return c.CFNumberGetValue( @ptrCast(c.CFNumberRef, self), - @enumToInt(t), + @intFromEnum(t), ptr, ) == 1; } diff --git a/pkg/macos/foundation/string.zig b/pkg/macos/foundation/string.zig index 164b139b0..7ed8e5ab6 100644 --- a/pkg/macos/foundation/string.zig +++ b/pkg/macos/foundation/string.zig @@ -10,12 +10,12 @@ pub const String = opaque { encoding: StringEncoding, external: bool, ) Allocator.Error!*String { - return @intToPtr(?*String, @ptrToInt(c.CFStringCreateWithBytes( + return @ptrFromInt(?*String, @intFromPtr(c.CFStringCreateWithBytes( null, bs.ptr, @intCast(c_long, bs.len), - @enumToInt(encoding), - @boolToInt(external), + @intFromEnum(encoding), + @intFromBool(external), ))) orelse Allocator.Error.OutOfMemory; } @@ -39,7 +39,7 @@ pub const String = opaque { other: *String, options: StringComparison, ) foundation.ComparisonResult { - return @intToEnum( + return @enumFromInt( foundation.ComparisonResult, c.CFStringCompare( @ptrCast(c.CFStringRef, self), @@ -54,7 +54,7 @@ pub const String = opaque { @ptrCast(c.CFStringRef, self), buf.ptr, @intCast(c_long, buf.len), - @enumToInt(encoding), + @intFromEnum(encoding), ) == 0) return null; return std.mem.sliceTo(buf, 0); } @@ -62,7 +62,7 @@ pub const String = opaque { pub fn cstringPtr(self: *String, encoding: StringEncoding) ?[:0]const u8 { const ptr = c.CFStringGetCStringPtr( @ptrCast(c.CFStringRef, self), - @enumToInt(encoding), + @intFromEnum(encoding), ); if (ptr == null) return null; return std.mem.sliceTo(ptr, 0); diff --git a/pkg/macos/foundation/url.zig b/pkg/macos/foundation/url.zig index 255d85f76..549bd28a1 100644 --- a/pkg/macos/foundation/url.zig +++ b/pkg/macos/foundation/url.zig @@ -17,12 +17,12 @@ pub const URL = opaque { style: URLPathStyle, dir: bool, ) Allocator.Error!*URL { - return @intToPtr( + return @ptrFromInt( ?*URL, - @ptrToInt(c.CFURLCreateWithFileSystemPath( + @intFromPtr(c.CFURLCreateWithFileSystemPath( null, @ptrCast(c.CFStringRef, path), - @enumToInt(style), + @intFromEnum(style), if (dir) 1 else 0, )), ) orelse error.OutOfMemory; diff --git a/pkg/macos/graphics/bitmap_context.zig b/pkg/macos/graphics/bitmap_context.zig index 742c82c2a..be319f229 100644 --- a/pkg/macos/graphics/bitmap_context.zig +++ b/pkg/macos/graphics/bitmap_context.zig @@ -17,9 +17,9 @@ pub const BitmapContext = opaque { space: *graphics.ColorSpace, opts: c_uint, ) Allocator.Error!*BitmapContext { - return @intToPtr( + return @ptrFromInt( ?*BitmapContext, - @ptrToInt(c.CGBitmapContextCreate( + @intFromPtr(c.CGBitmapContextCreate( @ptrCast(?*anyopaque, if (data) |d| d.ptr else null), width, height, diff --git a/pkg/macos/graphics/color_space.zig b/pkg/macos/graphics/color_space.zig index a381f4c6d..52b355fee 100644 --- a/pkg/macos/graphics/color_space.zig +++ b/pkg/macos/graphics/color_space.zig @@ -5,16 +5,16 @@ const c = @import("c.zig"); pub const ColorSpace = opaque { pub fn createDeviceGray() Allocator.Error!*ColorSpace { - return @intToPtr( + return @ptrFromInt( ?*ColorSpace, - @ptrToInt(c.CGColorSpaceCreateDeviceGray()), + @intFromPtr(c.CGColorSpaceCreateDeviceGray()), ) orelse Allocator.Error.OutOfMemory; } pub fn createDeviceRGB() Allocator.Error!*ColorSpace { - return @intToPtr( + return @ptrFromInt( ?*ColorSpace, - @ptrToInt(c.CGColorSpaceCreateDeviceRGB()), + @intFromPtr(c.CGColorSpaceCreateDeviceRGB()), ) orelse Allocator.Error.OutOfMemory; } diff --git a/pkg/macos/graphics/context.zig b/pkg/macos/graphics/context.zig index 7efa754b8..a627e58b1 100644 --- a/pkg/macos/graphics/context.zig +++ b/pkg/macos/graphics/context.zig @@ -69,7 +69,7 @@ pub fn Context(comptime T: type) type { pub fn setTextDrawingMode(self: *T, mode: TextDrawingMode) void { c.CGContextSetTextDrawingMode( @ptrCast(c.CGContextRef, self), - @enumToInt(mode), + @intFromEnum(mode), ); } diff --git a/pkg/macos/graphics/path.zig b/pkg/macos/graphics/path.zig index 8b3280572..151614735 100644 --- a/pkg/macos/graphics/path.zig +++ b/pkg/macos/graphics/path.zig @@ -10,9 +10,9 @@ pub const Path = opaque { rect: graphics.Rect, transform: ?*const graphics.AffineTransform, ) Allocator.Error!*Path { - return @intToPtr( + return @ptrFromInt( ?*Path, - @ptrToInt(c.CGPathCreateWithRect( + @intFromPtr(c.CGPathCreateWithRect( rect.cval(), @ptrCast(?[*]const c.struct_CGAffineTransform, transform), )), @@ -26,9 +26,9 @@ pub const Path = opaque { pub const MutablePath = opaque { pub fn create() Allocator.Error!*MutablePath { - return @intToPtr( + return @ptrFromInt( ?*MutablePath, - @ptrToInt(c.CGPathCreateMutable()), + @intFromPtr(c.CGPathCreateMutable()), ) orelse Allocator.Error.OutOfMemory; } diff --git a/pkg/macos/os/log.zig b/pkg/macos/os/log.zig index 49c93f491..eb47a22fc 100644 --- a/pkg/macos/os/log.zig +++ b/pkg/macos/os/log.zig @@ -8,7 +8,7 @@ pub const Log = opaque { subsystem: [:0]const u8, category: [:0]const u8, ) *Log { - return @intToPtr(?*Log, @ptrToInt(c.os_log_create( + return @ptrFromInt(?*Log, @intFromPtr(c.os_log_create( subsystem.ptr, category.ptr, ))).?; @@ -21,7 +21,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), - @enumToInt(typ), + @intFromEnum(typ), ); } diff --git a/pkg/macos/text/font.zig b/pkg/macos/text/font.zig index 988d0e666..f17325bbd 100644 --- a/pkg/macos/text/font.zig +++ b/pkg/macos/text/font.zig @@ -8,9 +8,9 @@ const c = @import("c.zig"); pub const Font = opaque { pub fn createWithFontDescriptor(desc: *text.FontDescriptor, size: f32) Allocator.Error!*Font { - return @intToPtr( + return @ptrFromInt( ?*Font, - @ptrToInt(c.CTFontCreateWithFontDescriptor( + @intFromPtr(c.CTFontCreateWithFontDescriptor( @ptrCast(c.CTFontDescriptorRef, desc), size, null, @@ -19,9 +19,9 @@ pub const Font = opaque { } pub fn copyWithAttributes(self: *Font, size: f32, attrs: ?*text.FontDescriptor) Allocator.Error!*Font { - return @intToPtr( + return @ptrFromInt( ?*Font, - @ptrToInt(c.CTFontCreateCopyWithAttributes( + @intFromPtr(c.CTFontCreateCopyWithAttributes( @ptrCast(c.CTFontRef, self), size, null, @@ -69,7 +69,7 @@ pub const Font = opaque { if (rects) |s| assert(glyphs.len == s.len); return @bitCast(graphics.Rect, c.CTFontGetBoundingRectsForGlyphs( @ptrCast(c.CTFontRef, self), - @enumToInt(orientation), + @intFromEnum(orientation), glyphs.ptr, @ptrCast(?[*]c.struct_CGRect, if (rects) |s| s.ptr else null), @intCast(c_long, glyphs.len), @@ -85,7 +85,7 @@ pub const Font = opaque { if (advances) |s| assert(glyphs.len == s.len); return c.CTFontGetAdvancesForGlyphs( @ptrCast(c.CTFontRef, self), - @enumToInt(orientation), + @intFromEnum(orientation), glyphs.ptr, @ptrCast(?[*]c.struct_CGSize, if (advances) |s| s.ptr else null), @intCast(c_long, glyphs.len), @@ -93,16 +93,16 @@ pub const Font = opaque { } pub fn copyAttribute(self: *Font, comptime attr: text.FontAttribute) attr.Value() { - return @intToPtr(attr.Value(), @ptrToInt(c.CTFontCopyAttribute( + return @ptrFromInt(attr.Value(), @intFromPtr(c.CTFontCopyAttribute( @ptrCast(c.CTFontRef, self), @ptrCast(c.CFStringRef, attr.key()), ))); } pub fn copyDisplayName(self: *Font) *foundation.String { - return @intToPtr( + return @ptrFromInt( *foundation.String, - @ptrToInt(c.CTFontCopyDisplayName(@ptrCast(c.CTFontRef, self))), + @intFromPtr(c.CTFontCopyDisplayName(@ptrCast(c.CTFontRef, self))), ); } diff --git a/pkg/macos/text/font_collection.zig b/pkg/macos/text/font_collection.zig index 395e566b7..d5a286def 100644 --- a/pkg/macos/text/font_collection.zig +++ b/pkg/macos/text/font_collection.zig @@ -6,16 +6,16 @@ const c = @import("c.zig"); pub const FontCollection = opaque { pub fn createFromAvailableFonts() Allocator.Error!*FontCollection { - return @intToPtr( + return @ptrFromInt( ?*FontCollection, - @ptrToInt(c.CTFontCollectionCreateFromAvailableFonts(null)), + @intFromPtr(c.CTFontCollectionCreateFromAvailableFonts(null)), ) orelse Allocator.Error.OutOfMemory; } pub fn createWithFontDescriptors(descs: *foundation.Array) Allocator.Error!*FontCollection { - return @intToPtr( + return @ptrFromInt( ?*FontCollection, - @ptrToInt(c.CTFontCollectionCreateWithFontDescriptors( + @intFromPtr(c.CTFontCollectionCreateWithFontDescriptors( @ptrCast(c.CFArrayRef, descs), null, )), @@ -31,7 +31,7 @@ pub const FontCollection = opaque { @ptrCast(c.CTFontCollectionRef, self), ); if (result) |ptr| { - return @intToPtr(*foundation.Array, @ptrToInt(ptr)); + return @ptrFromInt(*foundation.Array, @intFromPtr(ptr)); } // If we have no results, we create an empty array. This is not diff --git a/pkg/macos/text/font_descriptor.zig b/pkg/macos/text/font_descriptor.zig index 78685801b..e75d21758 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 @intToPtr( + return @ptrFromInt( ?*FontDescriptor, - @ptrToInt(c.CTFontDescriptorCreateWithNameAndSize(@ptrCast(c.CFStringRef, name), size)), + @intFromPtr(c.CTFontDescriptorCreateWithNameAndSize(@ptrCast(c.CFStringRef, name), size)), ) orelse Allocator.Error.OutOfMemory; } pub fn createWithAttributes(dict: *foundation.Dictionary) Allocator.Error!*FontDescriptor { - return @intToPtr( + return @ptrFromInt( ?*FontDescriptor, - @ptrToInt(c.CTFontDescriptorCreateWithAttributes(@ptrCast(c.CFDictionaryRef, dict))), + @intFromPtr(c.CTFontDescriptorCreateWithAttributes(@ptrCast(c.CFDictionaryRef, dict))), ) orelse Allocator.Error.OutOfMemory; } @@ -22,9 +22,9 @@ pub const FontDescriptor = opaque { original: *FontDescriptor, dict: *foundation.Dictionary, ) Allocator.Error!*FontDescriptor { - return @intToPtr( + return @ptrFromInt( ?*FontDescriptor, - @ptrToInt(c.CTFontDescriptorCreateCopyWithAttributes( + @intFromPtr(c.CTFontDescriptorCreateCopyWithAttributes( @ptrCast(c.CTFontDescriptorRef, original), @ptrCast(c.CFDictionaryRef, dict), )), @@ -36,14 +36,14 @@ pub const FontDescriptor = opaque { } pub fn copyAttribute(self: *FontDescriptor, comptime attr: FontAttribute) attr.Value() { - return @intToPtr(attr.Value(), @ptrToInt(c.CTFontDescriptorCopyAttribute( + return @ptrFromInt(attr.Value(), @intFromPtr(c.CTFontDescriptorCopyAttribute( @ptrCast(c.CTFontDescriptorRef, self), @ptrCast(c.CFStringRef, attr.key()), ))); } pub fn copyAttributes(self: *FontDescriptor) *foundation.Dictionary { - return @intToPtr(*foundation.Dictionary, @ptrToInt(c.CTFontDescriptorCopyAttributes( + return @ptrFromInt(*foundation.Dictionary, @intFromPtr(c.CTFontDescriptorCopyAttributes( @ptrCast(c.CTFontDescriptorRef, self), ))); } @@ -76,7 +76,7 @@ pub const FontAttribute = enum { downloaded, pub fn key(self: FontAttribute) *foundation.String { - return @intToPtr(*foundation.String, @ptrToInt(switch (self) { + return @ptrFromInt(*foundation.String, @intFromPtr(switch (self) { .url => c.kCTFontURLAttribute, .name => c.kCTFontNameAttribute, .display_name => c.kCTFontDisplayNameAttribute, @@ -141,7 +141,7 @@ pub const FontTraitKey = enum { slant, pub fn key(self: FontTraitKey) *foundation.String { - return @intToPtr(*foundation.String, @ptrToInt(switch (self) { + return @ptrFromInt(*foundation.String, @intFromPtr(switch (self) { .symbolic => c.kCTFontSymbolicTrait, .weight => c.kCTFontWeightTrait, .width => c.kCTFontWidthTrait, diff --git a/pkg/macos/text/font_manager.zig b/pkg/macos/text/font_manager.zig index 9cbbd8cba..115acbf0e 100644 --- a/pkg/macos/text/font_manager.zig +++ b/pkg/macos/text/font_manager.zig @@ -4,18 +4,18 @@ const foundation = @import("../foundation.zig"); const c = @import("c.zig"); pub fn createFontDescriptorsFromURL(url: *foundation.URL) ?*foundation.Array { - return @intToPtr( + return @ptrFromInt( ?*foundation.Array, - @ptrToInt(c.CTFontManagerCreateFontDescriptorsFromURL( + @intFromPtr(c.CTFontManagerCreateFontDescriptorsFromURL( @ptrCast(c.CFURLRef, url), )), ); } pub fn createFontDescriptorsFromData(data: *foundation.Data) ?*foundation.Array { - return @intToPtr( + return @ptrFromInt( ?*foundation.Array, - @ptrToInt(c.CTFontManagerCreateFontDescriptorsFromData( + @intFromPtr(c.CTFontManagerCreateFontDescriptorsFromData( @ptrCast(c.CFDataRef, data), )), ); diff --git a/pkg/macos/text/frame.zig b/pkg/macos/text/frame.zig index 08866af50..aff7efa7d 100644 --- a/pkg/macos/text/frame.zig +++ b/pkg/macos/text/frame.zig @@ -24,9 +24,9 @@ pub const Frame = opaque { } pub fn getLines(self: *Frame) *foundation.Array { - return @intToPtr( + return @ptrFromInt( *foundation.Array, - @ptrToInt(c.CTFrameGetLines(@ptrCast(c.CTFrameRef, self))), + @intFromPtr(c.CTFrameGetLines(@ptrCast(c.CTFrameRef, self))), ); } }; diff --git a/pkg/macos/text/framesetter.zig b/pkg/macos/text/framesetter.zig index ee3c4edd9..3c8df8cd0 100644 --- a/pkg/macos/text/framesetter.zig +++ b/pkg/macos/text/framesetter.zig @@ -8,9 +8,9 @@ const c = @import("c.zig"); pub const Framesetter = opaque { pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Framesetter { - return @intToPtr( + return @ptrFromInt( ?*Framesetter, - @ptrToInt(c.CTFramesetterCreateWithAttributedString( + @intFromPtr(c.CTFramesetterCreateWithAttributedString( @ptrCast(c.CFAttributedStringRef, str), )), ) orelse Allocator.Error.OutOfMemory; @@ -26,9 +26,9 @@ pub const Framesetter = opaque { path: *graphics.Path, attrs: ?*foundation.Dictionary, ) !*text.Frame { - return @intToPtr( + return @ptrFromInt( ?*text.Frame, - @ptrToInt(c.CTFramesetterCreateFrame( + @intFromPtr(c.CTFramesetterCreateFrame( @ptrCast(c.CTFramesetterRef, self), @bitCast(c.CFRange, range), @ptrCast(c.CGPathRef, path), diff --git a/pkg/macos/text/line.zig b/pkg/macos/text/line.zig index abe9b114b..124b51821 100644 --- a/pkg/macos/text/line.zig +++ b/pkg/macos/text/line.zig @@ -8,9 +8,9 @@ const c = @import("c.zig"); pub const Line = opaque { pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Line { - return @intToPtr( + return @ptrFromInt( ?*Line, - @ptrToInt(c.CTLineCreateWithAttributedString( + @intFromPtr(c.CTLineCreateWithAttributedString( @ptrCast(c.CFAttributedStringRef, str), )), ) orelse Allocator.Error.OutOfMemory; diff --git a/pkg/macos/text/stylized_strings.zig b/pkg/macos/text/stylized_strings.zig index 2e1e8721f..1064b3722 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 @intToPtr(*foundation.String, @ptrToInt(switch (self) { + return @ptrFromInt(*foundation.String, @intFromPtr(switch (self) { .font => c.kCTFontAttributeName, })); } diff --git a/pkg/pixman/format.zig b/pkg/pixman/format.zig index 39dc704f3..c471fd15f 100644 --- a/pkg/pixman/format.zig +++ b/pkg/pixman/format.zig @@ -93,7 +93,7 @@ pub const FormatCode = enum(c_uint) { // Converted from pixman.h fn reshift(self: FormatCode, ofs: u5, num: u5) u32 { - const val = @enumToInt(self); + const val = @intFromEnum(self); const v1 = val >> ofs; const v2 = @as(c_uint, 1) << num; const v3 = @intCast(u5, (val >> 22) & 3); diff --git a/pkg/pixman/image.zig b/pkg/pixman/image.zig index 7a2645d6d..bd8317038 100644 --- a/pkg/pixman/image.zig +++ b/pkg/pixman/image.zig @@ -11,7 +11,7 @@ pub const Image = opaque { stride: c_int, ) pixman.Error!*Image { return @ptrCast(?*Image, c.pixman_image_create_bits_no_clear( - @enumToInt(format), + @intFromEnum(format), width, height, bits, @@ -66,7 +66,7 @@ pub const Image = opaque { boxes: []const pixman.Box32, ) pixman.Error!void { if (c.pixman_image_fill_boxes( - @enumToInt(op), + @intFromEnum(op), @ptrCast(*c.pixman_image_t, self), @ptrCast(*const c.pixman_color_t, &color), @intCast(c_int, boxes.len), @@ -81,7 +81,7 @@ pub const Image = opaque { rects: []const pixman.Rectangle16, ) pixman.Error!void { if (c.pixman_image_fill_rectangles( - @enumToInt(op), + @intFromEnum(op), @ptrCast(*c.pixman_image_t, self), @ptrCast(*const c.pixman_color_t, &color), @intCast(c_int, rects.len), @@ -118,7 +118,7 @@ pub const Image = opaque { height: u16, ) void { c.pixman_image_composite( - @enumToInt(op), + @intFromEnum(op), @ptrCast(*c.pixman_image_t, src), @ptrCast(?*c.pixman_image_t, mask), @ptrCast(*c.pixman_image_t, self), @@ -145,10 +145,10 @@ pub const Image = opaque { tris: []const pixman.Triangle, ) void { c.pixman_composite_triangles( - @enumToInt(op), + @intFromEnum(op), @ptrCast(*c.pixman_image_t, src), @ptrCast(*c.pixman_image_t, self), - @enumToInt(mask_format), + @intFromEnum(mask_format), x_src, y_src, x_dst, diff --git a/pkg/pixman/types.zig b/pkg/pixman/types.zig index 94e4813ea..49ef0f4aa 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 => @intToEnum(Fixed, v << 16), - f64 => @intToEnum(Fixed, @floatToInt(i32, v * 65536)), + comptime_int, i32, u32 => @enumFromInt(Fixed, v << 16), + f64 => @enumFromInt(Fixed, @intFromFloat(i32, v * 65536)), else => { @compileLog(@TypeOf(v)); @compileError("unsupported type"); diff --git a/src/DevMode.zig b/src/DevMode.zig index 29288046a..92279b04e 100644 --- a/src/DevMode.zig +++ b/src/DevMode.zig @@ -99,7 +99,7 @@ pub fn update(self: *const DevMode) !void { const atlas = &surface.font_group.atlas_greyscale; const tex = switch (Renderer) { renderer.OpenGL => @intCast(usize, surface.renderer.texture.id), - renderer.Metal => @ptrToInt(surface.renderer.texture_greyscale.value), + renderer.Metal => @intFromPtr(surface.renderer.texture_greyscale.value), else => @compileError("renderer unsupported, add it!"), }; try self.atlasInfo(atlas, tex); @@ -110,7 +110,7 @@ pub fn update(self: *const DevMode) !void { const atlas = &surface.font_group.atlas_color; const tex = switch (Renderer) { renderer.OpenGL => @intCast(usize, surface.renderer.texture_color.id), - renderer.Metal => @ptrToInt(surface.renderer.texture_color.value), + renderer.Metal => @intFromPtr(surface.renderer.texture_color.value), else => @compileError("renderer unsupported, add it!"), }; try self.atlasInfo(atlas, tex); @@ -166,10 +166,10 @@ fn atlasInfo(self: *const DevMode, atlas: *font.Atlas, tex: ?usize) !void { if (tex) |id| { imgui.c.igImage( - @intToPtr(*anyopaque, id), + @ptrFromInt(*anyopaque, id), .{ - .x = @intToFloat(f32, atlas.size), - .y = @intToFloat(f32, atlas.size), + .x = @floatFromInt(f32, atlas.size), + .y = @floatFromInt(f32, atlas.size), }, .{ .x = 0, .y = 0 }, .{ .x = 1, .y = 1 }, diff --git a/src/Pty.zig b/src/Pty.zig index 09a3f9a1a..816ada451 100644 --- a/src/Pty.zig +++ b/src/Pty.zig @@ -87,7 +87,7 @@ pub fn deinit(self: *Pty) void { /// Return the size of the pty. pub fn getSize(self: Pty) !winsize { var ws: winsize = undefined; - if (c.ioctl(self.master, TIOCGWINSZ, @ptrToInt(&ws)) < 0) + if (c.ioctl(self.master, TIOCGWINSZ, @intFromPtr(&ws)) < 0) return error.IoctlFailed; return ws; @@ -95,7 +95,7 @@ pub fn getSize(self: Pty) !winsize { /// Set the size of the pty. pub fn setSize(self: Pty, size: winsize) !void { - if (c.ioctl(self.master, TIOCSWINSZ, @ptrToInt(&size)) < 0) + if (c.ioctl(self.master, TIOCSWINSZ, @intFromPtr(&size)) < 0) return error.IoctlFailed; } diff --git a/src/Surface.zig b/src/Surface.zig index 87a2d7c6a..950ef2b85 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -196,8 +196,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 = @floatToInt(u16, x_dpi), - .ydpi = @floatToInt(u16, y_dpi), + .xdpi = @intFromFloat(u16, x_dpi), + .ydpi = @intFromFloat(u16, y_dpi), }; // Find all the fonts for this surface @@ -320,8 +320,8 @@ pub fn init( const cell_size = try renderer.CellSize.init(alloc, font_group); // Convert our padding from points to pixels - const padding_x = (@intToFloat(f32, config.@"window-padding-x") * x_dpi) / 72; - const padding_y = (@intToFloat(f32, config.@"window-padding-y") * y_dpi) / 72; + 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: renderer.Padding = .{ .top = padding_y, .bottom = padding_y, @@ -425,8 +425,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 = @floatToInt(u32, cell_size.width * 10), - .height = @floatToInt(u32, cell_size.height * 4), + .width = @intFromFloat(u32, cell_size.width * 10), + .height = @intFromFloat(u32, cell_size.height * 4), }, null); // Call our size callback which handles all our retina setup @@ -446,7 +446,7 @@ pub fn init( const dev_atlas = @ptrCast(*imgui.FontAtlas, dev_io.cval().Fonts); dev_atlas.addFontFromMemoryTTF( face_ttf, - @intToFloat(f32, font_size.pixels()), + @floatFromInt(f32, font_size.pixels()), ); // Default dark style @@ -524,7 +524,7 @@ pub fn deinit(self: *Surface) void { self.alloc.destroy(self.renderer_state.mutex); self.config.deinit(); - log.info("surface closed addr={x}", .{@ptrToInt(self)}); + log.info("surface closed addr={x}", .{@intFromPtr(self)}); } /// Close this surface. This will trigger the runtime to start the @@ -658,7 +658,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, @intToFloat(f32, cursor.x) * self.cell_size.width); + var x: f64 = @floatCast(f64, @floatFromInt(f32, cursor.x) * self.cell_size.width); // We want the midpoint x += self.cell_size.width / 2; @@ -671,7 +671,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, @intToFloat(f32, cursor.y) * self.cell_size.height); + var y: f64 = @floatCast(f64, @floatFromInt(f32, cursor.y) * self.cell_size.height); // We want the bottom y += self.cell_size.height; @@ -1572,7 +1572,7 @@ pub fn mouseButtonCallback( } // Always record our latest mouse state - self.mouse.click_state[@intCast(usize, @enumToInt(button))] = action; + self.mouse.click_state[@intCast(usize, @intFromEnum(button))] = action; self.mouse.mods = @bitCast(input.Mods, mods); // Shift-click continues the previous mouse state. cursorPosCallback @@ -1713,7 +1713,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 @intToEnum(input.MouseButton, i); + break :button @enumFromInt(input.MouseButton, i); } else null; try self.mouseReport(button, .motion, self.mouse.mods, pos); @@ -1724,7 +1724,7 @@ pub fn cursorPosCallback( } // If the cursor isn't clicked currently, it doesn't matter - if (self.mouse.click_state[@enumToInt(input.MouseButton.left)] != .press) return; + if (self.mouse.click_state[@intFromEnum(input.MouseButton.left)] != .press) return; // All roads lead to requiring a re-render at this pont. try self.queueRender(); @@ -1733,7 +1733,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 = @intToFloat(f32, self.screen_size.height); + const max_y = @floatFromInt(f32, 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 }); @@ -1845,7 +1845,7 @@ fn dragLeftClickSingle( const cell_xboundary = self.cell_size.width * 0.6; // first xpos of the clicked cell - const cell_xstart = @intToFloat(f32, self.mouse.left_click_point.x) * self.cell_size.width; + const cell_xstart = @floatFromInt(f32, 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 @@ -1921,7 +1921,7 @@ fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Viewport { .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 = @floatToInt(usize, xpos / cell_width); + const x = @intFromFloat(usize, xpos / cell_width); // Can be off the screen if the user drags it out, so max // it out on our available columns @@ -1930,7 +1930,7 @@ 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 = @floatToInt(usize, ypos / cell_height); + const y = @intFromFloat(usize, ypos / cell_height); break :y @min(y, self.grid_size.rows - 1); }, }; diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index 822437b50..619df6a9d 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 = @intToFloat(f32, video_mode.getWidth()) / (@intToFloat(f32, physical_size.width_mm) / 25.4); - const physical_y_dpi = @intToFloat(f32, video_mode.getHeight()) / (@intToFloat(f32, physical_size.height_mm) / 25.4); + 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); log.debug("physical dpi x={} y={}", .{ physical_x_dpi, physical_y_dpi, @@ -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 = @intToFloat(f64, fb_size.width) / @intToFloat(f64, size.width); - const y_scale = @intToFloat(f64, fb_size.height) / @intToFloat(f64, size.height); + const x_scale = @floatFromInt(f64, fb_size.width) / @floatFromInt(f64, size.width); + const y_scale = @floatFromInt(f64, fb_size.height) / @floatFromInt(f64, size.height); return .{ .xpos = pos.xpos * x_scale, .ypos = pos.ypos * y_scale, diff --git a/src/config.zig b/src/config.zig index 9a82c59d2..442b17eec 100644 --- a/src/config.zig +++ b/src/config.zig @@ -418,8 +418,8 @@ pub const Config = struct { } { // Cmd+N for goto tab N - const start = @enumToInt(inputpkg.Key.one); - const end = @enumToInt(inputpkg.Key.nine); + const start = @intFromEnum(inputpkg.Key.one); + const end = @intFromEnum(inputpkg.Key.nine); var i: usize = start; while (i <= end) : (i += 1) { // On macOS we default to super but everywhere else @@ -431,7 +431,7 @@ pub const Config = struct { try result.keybind.set.put( alloc, - .{ .key = @intToEnum(inputpkg.Key, i), .mods = mods }, + .{ .key = @enumFromInt(inputpkg.Key, i), .mods = mods }, .{ .goto_tab = (i - start) + 1 }, ); } diff --git a/src/font/Atlas.zig b/src/font/Atlas.zig index 4630bbed4..8f9d7812f 100644 --- a/src/font/Atlas.zig +++ b/src/font/Atlas.zig @@ -317,7 +317,7 @@ pub const Wasm = struct { const atlas = init( alloc, size, - @intToEnum(Format, format), + @enumFromInt(Format, format), ) catch return null; const result = alloc.create(Atlas) catch return null; result.* = atlas; @@ -449,12 +449,12 @@ pub const Wasm = struct { // Draw it try ctx.call(void, "putImageData", .{ image_data, 0, 0 }); - const id = @bitCast(js.Ref, @enumToInt(canvas.value)).id; + const id = @bitCast(js.Ref, @intFromEnum(canvas.value)).id; return id; } test "happy path" { - var atlas = atlas_new(512, @enumToInt(Format.greyscale)).?; + var atlas = atlas_new(512, @intFromEnum(Format.greyscale)).?; defer atlas_free(atlas); const reg = atlas_reserve(atlas, 2, 2).?; diff --git a/src/font/DeferredFace.zig b/src/font/DeferredFace.zig index a91589b59..a8a3ec346 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 = @intToEnum(font.Presentation, presentation), + .presentation = @enumFromInt(font.Presentation, presentation), }, }; errdefer face.deinit(); diff --git a/src/font/Group.zig b/src/font/Group.zig index dc238ea34..ae0ed11ba 100644 --- a/src/font/Group.zig +++ b/src/font/Group.zig @@ -138,7 +138,7 @@ pub const FontIndex = packed struct(u8) { /// Initialize a special font index. pub fn initSpecial(v: Special) FontIndex { - return .{ .style = .regular, .idx = @enumToInt(v) }; + return .{ .style = .regular, .idx = @intFromEnum(v) }; } /// Convert to int @@ -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 @intToEnum(Special, self.idx); + return @enumFromInt(Special, self.idx); } test { @@ -327,15 +327,15 @@ pub const Wasm = struct { // Set details for our sprite font self.sprite = font.sprite.Face{ - .width = @floatToInt(u32, metrics.cell_width), - .height = @floatToInt(u32, metrics.cell_height), + .width = @intFromFloat(u32, metrics.cell_width), + .height = @intFromFloat(u32, metrics.cell_height), .thickness = 2, - .underline_position = @floatToInt(u32, metrics.underline_position), + .underline_position = @intFromFloat(u32, metrics.underline_position), }; } export fn group_add_face(self: *Group, style: u16, face: *font.DeferredFace) void { - return self.addFace(alloc, @intToEnum(Style, style), face.*) catch |err| { + return self.addFace(alloc, @enumFromInt(Style, style), face.*) catch |err| { log.warn("error adding face to group err={}", .{err}); return; }; @@ -350,10 +350,10 @@ 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 @intToEnum(Presentation, p); + const presentation = if (p < 0) null else @enumFromInt(Presentation, p); const idx = self.indexForCodepoint( cp, - @intToEnum(Style, style), + @enumFromInt(Style, style), presentation, ) orelse return -1; return @intCast(i16, @bitCast(u8, idx)); @@ -473,7 +473,7 @@ test "box glyph" { // Should find a box glyph const idx = group.indexForCodepoint(0x2500, .regular, null).?; try testing.expectEqual(Style.regular, idx.style); - try testing.expectEqual(@enumToInt(FontIndex.Special.sprite), idx.idx); + try testing.expectEqual(@intFromEnum(FontIndex.Special.sprite), idx.idx); // Should render it const glyph = try group.renderGlyph( @@ -597,6 +597,6 @@ test "faceFromIndex returns pointer" { const idx = group.indexForCodepoint('A', .regular, null).?; const face1 = try group.faceFromIndex(idx); const face2 = try group.faceFromIndex(idx); - try testing.expectEqual(@ptrToInt(face1), @ptrToInt(face2)); + try testing.expectEqual(@intFromPtr(face1), @intFromPtr(face2)); } } diff --git a/src/font/GroupCache.zig b/src/font/GroupCache.zig index 6a69e1c7c..33c11027b 100644 --- a/src/font/GroupCache.zig +++ b/src/font/GroupCache.zig @@ -266,11 +266,11 @@ 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 @intToEnum(Presentation, p); + const presentation = if (p < 0) null else @enumFromInt(Presentation, p); if (self.indexForCodepoint( alloc, cp, - @intToEnum(Style, style), + @enumFromInt(Style, style), presentation, )) |idx| { return @intCast(i16, @bitCast(u8, idx orelse return -1)); diff --git a/src/font/discovery.zig b/src/font/discovery.zig index b392613a7..1d931f9df 100644 --- a/src/font/discovery.zig +++ b/src/font/discovery.zig @@ -64,12 +64,12 @@ pub const Descriptor = struct { )); if (self.bold) assert(pat.add( .weight, - .{ .integer = @enumToInt(fontconfig.Weight.bold) }, + .{ .integer = @intFromEnum(fontconfig.Weight.bold) }, false, )); if (self.italic) assert(pat.add( .slant, - .{ .integer = @enumToInt(fontconfig.Slant.italic) }, + .{ .integer = @intFromEnum(fontconfig.Slant.italic) }, false, )); diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index 5452bcd68..2604c32e5 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(@intToFloat(f32, size.points), null); + const ct_font = try base.copyWithAttributes(@floatFromInt(f32, size.points), null); errdefer ct_font.release(); var hb_font = try harfbuzz.coretext.createFont(ct_font); @@ -115,8 +115,8 @@ pub const Face = struct { // 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 = @floatToInt(u32, @ceil(bounding[0].size.width)); - const glyph_height = @floatToInt(u32, @ceil(bounding[0].size.height)); + const glyph_width = @intFromFloat(u32, @ceil(bounding[0].size.width)); + const glyph_height = @intFromFloat(u32, @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). @@ -156,8 +156,8 @@ pub const Face = struct { 8, width, space, - @enumToInt(macos.graphics.BitmapInfo.alpha_mask) & - @enumToInt(macos.graphics.ImageAlphaInfo.none), + @intFromEnum(macos.graphics.BitmapInfo.alpha_mask) & + @intFromEnum(macos.graphics.ImageAlphaInfo.none), ); defer ctx.release(); @@ -195,13 +195,13 @@ 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) + @floatToInt(i32, @ceil(baseline_with_offset)); + break :offset_y @intCast(i32, height) + @intFromFloat(i32, @ceil(baseline_with_offset)); }; return font.Glyph{ .width = glyph_width, .height = glyph_height, - .offset_x = @floatToInt(i32, @ceil(bounding[0].origin.x)), + .offset_x = @intFromFloat(i32, @ceil(bounding[0].origin.x)), .offset_y = offset_y, .atlas_x = region.x + padding, .atlas_y = region.y + padding, diff --git a/src/font/face/freetype.zig b/src/font/face/freetype.zig index 19c886edc..f84a0f191 100644 --- a/src/font/face/freetype.zig +++ b/src/font/face/freetype.zig @@ -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 = @intToFloat(f64, bm.rows); - const old = @intToFloat(f64, bitmap_original.rows); + const new = @floatFromInt(f64, bm.rows); + const old = @floatFromInt(f64, bitmap_original.rows); break :ratio new / old; }; var copy = glyph.*; - copy.bitmap_top = @floatToInt(c_int, @round(@intToFloat(f64, copy.bitmap_top) * ratio)); - copy.bitmap_left = @floatToInt(c_int, @round(@intToFloat(f64, copy.bitmap_left) * ratio)); + 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)); break :metrics copy; } else glyph.*; @@ -325,7 +325,7 @@ pub const Face = struct { // 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 + @floatToInt(c_int, self.metrics.cell_baseline); + break :offset_y glyph_metrics.bitmap_top + @intFromFloat(c_int, self.metrics.cell_baseline); }; // Store glyph metadata @@ -351,7 +351,7 @@ pub const Face = struct { /// Convert 26.6 pixel format to f32 fn f26dot6ToFloat(v: freetype.c.FT_F26Dot6) f32 { - return @intToFloat(f32, v >> 6); + return @floatFromInt(f32, 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 -= @intToFloat(f32, face.handle.*.glyph.*.bitmap_top); - res += @intToFloat(f32, face.handle.*.glyph.*.bitmap.rows); + res -= @floatFromInt(f32, face.handle.*.glyph.*.bitmap_top); + res += @floatFromInt(f32, face.handle.*.glyph.*.bitmap.rows); break :underscore res; } else |_| { // Ignore the error since we just fall back below @@ -434,7 +434,7 @@ pub const Face = struct { // We use the declared underline position if its available const declared = ascender_px - declared_px; if (declared > 0) - break :underline_pos @intToFloat(f32, declared); + break :underline_pos @floatFromInt(f32, declared); // If we have no declared underline position, we go slightly under the // cell height (mainly: non-scalable fonts, i.e. emoji) @@ -459,7 +459,7 @@ pub const Face = struct { @intCast(i32, face.handle.*.size.*.metrics.y_scale), ) >> 6; - break :pos @intToFloat(f32, ascender_px - declared_px); + break :pos @floatFromInt(f32, ascender_px - declared_px); }, .thickness = @max(@as(f32, 1), fontUnitsToPxY(face, os2.yStrikeoutSize)), } else .{ @@ -491,7 +491,7 @@ 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 = @intToFloat(f32, mul) / 64; + const div = @floatFromInt(f32, mul) / 64; return @ceil(div); } }; diff --git a/src/font/face/web_canvas.zig b/src/font/face/web_canvas.zig index 500f356d4..513645d90 100644 --- a/src/font/face/web_canvas.zig +++ b/src/font/face/web_canvas.zig @@ -370,7 +370,7 @@ 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 = @floatToInt(u32, @ceil(width: { + const width: u32 = @intFromFloat(u32, @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. @@ -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) @floatToInt(u32, @ceil(asc + desc)) + 1 else width; + const height = if (!broken_bbox) @intFromFloat(u32, @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 @@ -435,7 +435,7 @@ pub const Face = struct { try ctx.call(void, "fillText", .{ glyph_str, left + 1, - if (!broken_bbox) asc + 1 else @intToFloat(f32, height), + if (!broken_bbox) asc + 1 else @floatFromInt(f32, height), }); // Read the image data and get it into a []u8 on our side @@ -501,7 +501,7 @@ pub const Wasm = struct { alloc, ptr[0..len], .{ .points = pts }, - @intToEnum(font.Presentation, presentation), + @enumFromInt(font.Presentation, presentation), ); errdefer face.deinit(); diff --git a/src/font/sprite.zig b/src/font/sprite.zig index d026bccb5..fd37bc852 100644 --- a/src/font/sprite.zig +++ b/src/font/sprite.zig @@ -32,7 +32,7 @@ pub const Sprite = enum(u32) { test { const testing = std.testing; - try testing.expectEqual(start, @enumToInt(Sprite.underline)); + try testing.expectEqual(start, @intFromEnum(Sprite.underline)); } }; diff --git a/src/font/sprite/Box.zig b/src/font/sprite/Box.zig index 3e5d87b74..ff22eec81 100644 --- a/src/font/sprite/Box.zig +++ b/src/font/sprite/Box.zig @@ -75,7 +75,7 @@ pub fn renderGlyph( .offset_y = offset_y, .atlas_x = region.x, .atlas_y = region.y, - .advance_x = @intToFloat(f32, self.width), + .advance_x = @floatFromInt(f32, self.width), }; } @@ -308,9 +308,9 @@ fn draw(self: Box, alloc: Allocator, canvas: *font.sprite.Canvas, cp: u32) !void // Not official box characters but special characters we hide // in the high bits of a unicode codepoint. - @enumToInt(Sprite.cursor_rect) => self.draw_cursor_rect(canvas), - @enumToInt(Sprite.cursor_hollow_rect) => self.draw_cursor_hollow_rect(canvas), - @enumToInt(Sprite.cursor_bar) => self.draw_cursor_bar(canvas), + @intFromEnum(Sprite.cursor_rect) => self.draw_cursor_rect(canvas), + @intFromEnum(Sprite.cursor_hollow_rect) => self.draw_cursor_hollow_rect(canvas), + @intFromEnum(Sprite.cursor_bar) => self.draw_cursor_bar(canvas), else => return error.InvalidCodepoint, } @@ -1068,23 +1068,23 @@ fn draw_light_diagonal_upper_right_to_lower_left(self: Box, canvas: *font.sprite .bottom = @intCast(i32, self.height), .left = .{ .p1 = .{ - .x = @floatToInt(i32, @intToFloat(f64, self.width) - @intToFloat(f64, thick_px) / 2), + .x = @intFromFloat(i32, @floatFromInt(f64, self.width) - @floatFromInt(f64, thick_px) / 2), .y = 0, }, .p2 = .{ - .x = @floatToInt(i32, 0 - @intToFloat(f64, thick_px) / 2), + .x = @intFromFloat(i32, 0 - @floatFromInt(f64, thick_px) / 2), .y = @intCast(i32, self.height), }, }, .right = .{ .p1 = .{ - .x = @floatToInt(i32, @intToFloat(f64, self.width) + @intToFloat(f64, thick_px) / 2), + .x = @intFromFloat(i32, @floatFromInt(f64, self.width) + @floatFromInt(f64, thick_px) / 2), .y = 0, }, .p2 = .{ - .x = @floatToInt(i32, 0 + @intToFloat(f64, thick_px) / 2), + .x = @intFromFloat(i32, 0 + @floatFromInt(f64, thick_px) / 2), .y = @intCast(i32, self.height), }, }, @@ -1098,23 +1098,23 @@ fn draw_light_diagonal_upper_left_to_lower_right(self: Box, canvas: *font.sprite .bottom = @intCast(i32, self.height), .left = .{ .p1 = .{ - .x = @floatToInt(i32, 0 - @intToFloat(f64, thick_px) / 2), + .x = @intFromFloat(i32, 0 - @floatFromInt(f64, thick_px) / 2), .y = 0, }, .p2 = .{ - .x = @floatToInt(i32, @intToFloat(f64, self.width) - @intToFloat(f64, thick_px) / 2), + .x = @intFromFloat(i32, @floatFromInt(f64, self.width) - @floatFromInt(f64, thick_px) / 2), .y = @intCast(i32, self.height), }, }, .right = .{ .p1 = .{ - .x = @floatToInt(i32, 0 + @intToFloat(f64, thick_px) / 2), + .x = @intFromFloat(i32, 0 + @floatFromInt(f64, thick_px) / 2), .y = 0, }, .p2 = .{ - .x = @floatToInt(i32, @intToFloat(f64, self.width) + @intToFloat(f64, thick_px) / 2), + .x = @intFromFloat(i32, @floatFromInt(f64, self.width) + @floatFromInt(f64, thick_px) / 2), .y = @intCast(i32, 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 - @floatToInt(u32, @round(3 * @intToFloat(f64, self.height) / 8)), + self.height - @intFromFloat(u32, @round(3 * @floatFromInt(f64, 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 - @floatToInt(u32, @round(@intToFloat(f64, self.height) / 2)), + self.height - @intFromFloat(u32, @round(@floatFromInt(f64, 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 - @floatToInt(u32, @round(5 * @intToFloat(f64, self.height) / 8)), + self.height - @intFromFloat(u32, @round(5 * @floatFromInt(f64, 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 - @floatToInt(u32, @round(3 * @intToFloat(f64, self.height) / 4)), + self.height - @intFromFloat(u32, @round(3 * @floatFromInt(f64, 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 - @floatToInt(u32, @round(7 * @intToFloat(f64, self.height) / 8)), + self.height - @intFromFloat(u32, @round(7 * @floatFromInt(f64, 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, - @floatToInt(u32, @round(@intToFloat(f64, self.height) / 4)), + @intFromFloat(u32, @round(@floatFromInt(f64, self.height) / 4)), ); } @@ -1256,7 +1256,7 @@ fn draw_upper_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void { 0, 0, self.width, - @floatToInt(u32, @round(3 * @intToFloat(f64, self.height) / 8)), + @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.height) / 8)), ); } @@ -1266,7 +1266,7 @@ fn draw_upper_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void { 0, 0, self.width, - @floatToInt(u32, @round(5 * @intToFloat(f64, self.height) / 8)), + @intFromFloat(u32, @round(5 * @floatFromInt(f64, self.height) / 8)), ); } @@ -1276,7 +1276,7 @@ fn draw_upper_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void 0, 0, self.width, - @floatToInt(u32, @round(3 * @intToFloat(f64, self.height) / 4)), + @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.height) / 4)), ); } @@ -1286,7 +1286,7 @@ fn draw_upper_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void { 0, 0, self.width, - @floatToInt(u32, @round(7 * @intToFloat(f64, self.height) / 8)), + @intFromFloat(u32, @round(7 * @floatFromInt(f64, self.height) / 8)), ); } @@ -1299,7 +1299,7 @@ fn draw_left_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void { canvas, 0, 0, - @floatToInt(u32, @round(7 * @intToFloat(f64, self.width) / 8)), + @intFromFloat(u32, @round(7 * @floatFromInt(f64, 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, - @floatToInt(u32, @round(3 * @intToFloat(f64, self.width) / 4)), + @intFromFloat(u32, @round(3 * @floatFromInt(f64, 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, - @floatToInt(u32, @round(5 * @intToFloat(f64, self.width) / 8)), + @intFromFloat(u32, @round(5 * @floatFromInt(f64, self.width) / 8)), self.height, ); } @@ -1329,7 +1329,7 @@ fn draw_left_half_block(self: Box, canvas: *font.sprite.Canvas) void { canvas, 0, 0, - @floatToInt(u32, @round(@intToFloat(f64, self.width) / 2)), + @intFromFloat(u32, @round(@floatFromInt(f64, 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, - @floatToInt(u32, @round(3 * @intToFloat(f64, self.width) / 8)), + @intFromFloat(u32, @round(3 * @floatFromInt(f64, 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, - @floatToInt(u32, @round(@intToFloat(f64, self.width) / 4)), + @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 4)), self.height, ); } fn draw_vertical_one_eighth_block_n(self: Box, canvas: *font.sprite.Canvas, n: u32) void { - const x = @floatToInt(u32, @round(@intToFloat(f64, n) * @intToFloat(f64, self.width) / 8)); - const w = @floatToInt(u32, @round(@intToFloat(f64, self.width) / 8)); + const x = @intFromFloat(u32, @round(@floatFromInt(f64, n) * @floatFromInt(f64, self.width) / 8)); + const w = @intFromFloat(u32, @round(@floatFromInt(f64, 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, - @floatToInt(u32, @round(@intToFloat(f64, self.width) / 2)), + @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 2)), 0, self.width, self.height, @@ -1380,7 +1380,7 @@ fn draw_pixman_shade(self: Box, canvas: *font.sprite.Canvas, v: u16) void { .y1 = 0, .x2 = @intCast(i32, self.width), .y2 = @intCast(i32, self.height), - }).rect(), @intToEnum(font.sprite.Color, v)); + }).rect(), @enumFromInt(font.sprite.Color, 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 = @floatToInt(u32, @round(@intToFloat(f64, n) * @intToFloat(f64, self.height) / 8)); - const h = @floatToInt(u32, @round(@intToFloat(f64, self.height) / 8)); + const y = @intFromFloat(u32, @round(@floatFromInt(f64, n) * @floatFromInt(f64, self.height) / 8)); + const h = @intFromFloat(u32, @round(@floatFromInt(f64, 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 - @floatToInt(u32, @round(@intToFloat(f64, self.width) / 8)), + self.width - @intFromFloat(u32, @round(@floatFromInt(f64, 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 - @floatToInt(u32, @round(@intToFloat(f64, self.width) / 4)), + self.width - @intFromFloat(u32, @round(@floatFromInt(f64, 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 - @floatToInt(u32, @round(3 * @intToFloat(f64, self.width) / 4)), + self.width - @intFromFloat(u32, @round(3 * @floatFromInt(f64, 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 - @floatToInt(u32, @round(3 * @intToFloat(f64, self.width) / 8)), + self.width - @intFromFloat(u32, @round(3 * @floatFromInt(f64, 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 - @floatToInt(u32, @round(5 * @intToFloat(f64, self.width) / 8)), + self.width - @intFromFloat(u32, @round(5 * @floatFromInt(f64, 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 - @floatToInt(u32, @round(7 * @intToFloat(f64, self.width) / 8)), + self.width - @intFromFloat(u32, @round(7 * @floatFromInt(f64, 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, - @floatToInt(u32, @ceil(@intToFloat(f64, self.width) / 2)), - @floatToInt(u32, @ceil(@intToFloat(f64, self.height) / 2)), + @intFromFloat(u32, @ceil(@floatFromInt(f64, self.width) / 2)), + @intFromFloat(u32, @ceil(@floatFromInt(f64, self.height) / 2)), ); } fn quad_upper_right(self: Box, canvas: *font.sprite.Canvas) void { self.rect( canvas, - @floatToInt(u32, @floor(@intToFloat(f64, self.width) / 2)), + @intFromFloat(u32, @floor(@floatFromInt(f64, self.width) / 2)), 0, self.width, - @floatToInt(u32, @ceil(@intToFloat(f64, self.height) / 2)), + @intFromFloat(u32, @ceil(@floatFromInt(f64, self.height) / 2)), ); } @@ -1521,8 +1521,8 @@ fn quad_lower_left(self: Box, canvas: *font.sprite.Canvas) void { self.rect( canvas, 0, - @floatToInt(u32, @floor(@intToFloat(f64, self.height) / 2)), - @floatToInt(u32, @ceil(@intToFloat(f64, self.width) / 2)), + @intFromFloat(u32, @floor(@floatFromInt(f64, self.height) / 2)), + @intFromFloat(u32, @ceil(@floatFromInt(f64, 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, - @floatToInt(u32, @floor(@intToFloat(f64, self.width) / 2)), - @floatToInt(u32, @floor(@intToFloat(f64, self.height) / 2)), + @intFromFloat(u32, @floor(@floatFromInt(f64, self.width) / 2)), + @intFromFloat(u32, @floor(@floatFromInt(f64, 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 .{ - @floatToInt(u32, @round(@intToFloat(f64, self.width) / 2)), - @floatToInt(u32, @intToFloat(f64, self.width) / 2), + @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 2)), + @intFromFloat(u32, @floatFromInt(f64, self.width) / 2), }; } @@ -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 = @intToFloat(f64, circle_inner_edge) + @intToFloat(f64, thick_pixels) / 2; + var c_r: f64 = @floatFromInt(f64, circle_inner_edge) + @floatFromInt(f64, 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 = @intToFloat(f64, y_min) * 16; - while (i <= @intToFloat(f64, y_max) * 16) : (i += 1) { + var i: f64 = @floatFromInt(f64, y_min) * 16; + while (i <= @floatFromInt(f64, 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 = @intToFloat(f64, circle_hemisphere); - const y_part = y - @intToFloat(f64, c_y); + const hemi = @floatFromInt(f64, circle_hemisphere); + const y_part = y - @floatFromInt(f64, c_y); const y_squared = y_part * y_part; const sqrt = @sqrt(c_r2 - y_squared); - const f_c_x = @intToFloat(f64, c_x); + const f_c_x = @floatFromInt(f64, c_x); // We need to detect overflows and just skip this i const a = hemi * sqrt; @@ -2326,8 +2326,8 @@ fn draw_light_arc( break :x b; }; - const row = @floatToInt(i32, @round(y)); - const col = @floatToInt(i32, @round(x)); + const row = @intFromFloat(i32, @round(y)); + const col = @intFromFloat(i32, @round(x)); if (col < 0) continue; // rectangle big enough to fit entire circle with radius thick/2. @@ -2350,12 +2350,12 @@ fn draw_light_arc( var r: i32 = @max(row_start, 0); const r_end = @max(@min(row_end, @intCast(i32, height)), 0); while (r < r_end) : (r += 1) { - const r_midpoint = @intToFloat(f64, r) + 0.5; + const r_midpoint = @floatFromInt(f64, r) + 0.5; var c: i32 = @max(col_start, 0); const c_end = @max(@min(col_end, @intCast(i32, width)), 0); while (c < c_end) : (c += 1) { - const c_midpoint = @intToFloat(f64, c) + 0.5; + const c_midpoint = @floatFromInt(f64, c) + 0.5; // vector from point on quartercircle to midpoint of the current pixel. const center_midpoint_x = c_midpoint - x; @@ -2364,7 +2364,7 @@ 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 > @intToFloat(f64, thick) / 2) continue; + if (dist > @floatFromInt(f64, thick) / 2) continue; // Set our pixel const idx = @intCast(usize, r * @intCast(i32, width) + c); @@ -2398,7 +2398,7 @@ fn draw_light_arc( .width = 1, .height = 1, }, - @intToEnum(font.sprite.Color, average), + @enumFromInt(font.sprite.Color, average), ); } } diff --git a/src/font/sprite/Face.zig b/src/font/sprite/Face.zig index a7615c110..b23ec5481 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, - @intToEnum(Sprite, cp), + @enumFromInt(Sprite, 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 (@intToEnum(Sprite, cp)) { + Sprite.start...Sprite.end => switch (@enumFromInt(Sprite, cp)) { .underline, .underline_double, .underline_dotted, diff --git a/src/font/sprite/canvas.zig b/src/font/sprite/canvas.zig index 5cc4842d3..c9312da9f 100644 --- a/src/font/sprite/canvas.zig +++ b/src/font/sprite/canvas.zig @@ -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 = @intToFloat(f32, std.math.maxInt(u8)); - const max_u16 = @intToFloat(f32, std.math.maxInt(u16)); - const unscaled = @intToFloat(f32, @enumToInt(self)); - const scaled = @floatToInt(u16, (unscaled * max_u16) / max); + 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); 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})", .{ - @intToFloat(f32, @enumToInt(self)) / 255, + @floatFromInt(f32, @intFromEnum(self)) / 255, }); } }; diff --git a/src/font/sprite/underline.zig b/src/font/sprite/underline.zig index 362a1832e..593b20e61 100644 --- a/src/font/sprite/underline.zig +++ b/src/font/sprite/underline.zig @@ -52,7 +52,7 @@ pub fn renderGlyph( .offset_y = offset_y, .atlas_x = region.x, .atlas_y = region.y, - .advance_x = @intToFloat(f32, width), + .advance_x = @floatFromInt(f32, width), }; } @@ -178,16 +178,16 @@ 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 = @intToFloat(f64, y_max - pos); + const wave_height = @floatFromInt(f64, y_max - pos); const half_height = wave_height / 4; - const y = pos + @floatToInt(u32, half_height); + const y = pos + @intFromFloat(u32, half_height); - const x_factor = (2 * std.math.pi) / @intToFloat(f64, self.width); + const x_factor = (2 * std.math.pi) / @floatFromInt(f64, self.width); var x: u32 = 0; while (x < self.width) : (x += 1) { - const vertical = @floatToInt( + const vertical = @intFromFloat( u32, - (-1 * half_height) * @sin(@intToFloat(f64, x) * x_factor) + half_height, + (-1 * half_height) * @sin(@floatFromInt(f64, x) * x_factor) + half_height, ); var row: u32 = 0; diff --git a/src/os/flatpak.zig b/src/os/flatpak.zig index 0d72f2a3c..e40217d12 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, @boolToInt(pg)), + @intCast(c_int, @intFromBool(pg)), ), c.G_VARIANT_TYPE("()"), c.G_DBUS_CALL_FLAGS_NONE, diff --git a/src/os/mouse.zig b/src/os/mouse.zig index cff78d4dc..8051bbe6d 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 = @floatToInt(u32, @ceil(interval * 1000)); + const ms = @intFromFloat(u32, @ceil(interval * 1000)); return ms; } diff --git a/src/os/wasm.zig b/src/os/wasm.zig index 1be8bb011..4edfd5ab4 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 = @intToPtr([*]u8, @ptrToInt(ptr)); + const casted = @ptrFromInt([*]u8, @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 = @intToPtr([*]u8, @ptrToInt(ptr)); + const casted = @ptrFromInt([*]u8, @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 = @intToPtr([*]u8, @ptrToInt(ptr)); + const casted = @ptrFromInt([*]u8, @intFromPtr(ptr)); _ = allocs.remove(casted); } diff --git a/src/os/wasm/target.zig b/src/os/wasm/target.zig index c8bf51778..76a059f81 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 = @intToEnum(Target, @enumToInt(options.wasm_target)); + const result = @enumFromInt(Target, @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 753d155c3..4240fc91b 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 = @floatToInt(u32, metrics.cell_width), - .height = @floatToInt(u32, metrics.cell_height), + .width = @intFromFloat(u32, metrics.cell_width), + .height = @intFromFloat(u32, metrics.cell_height), .thickness = 2, - .underline_position = @floatToInt(u32, metrics.underline_position), + .underline_position = @intFromFloat(u32, metrics.underline_position), }; // Create the font shaper. We initially create a shaper that can support @@ -480,10 +480,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 = @floatToInt(u32, self.cell_size.width), - .height = @floatToInt(u32, self.cell_size.height), + .width = @intFromFloat(u32, self.cell_size.width), + .height = @intFromFloat(u32, self.cell_size.height), .thickness = 2, - .underline_position = @floatToInt(u32, metrics.underline_position), + .underline_position = @intFromFloat(u32, metrics.underline_position), }; // Notify the window that the cell size changed. @@ -618,13 +618,13 @@ pub fn render( // which ironically doesn't implement CAMetalDrawable as a // property so we just send a message. const texture = drawable.msgSend(objc.c.id, objc.sel("texture"), .{}); - attachment.setProperty("loadAction", @enumToInt(MTLLoadAction.clear)); - attachment.setProperty("storeAction", @enumToInt(MTLStoreAction.store)); + attachment.setProperty("loadAction", @intFromEnum(MTLLoadAction.clear)); + attachment.setProperty("storeAction", @intFromEnum(MTLStoreAction.store)); attachment.setProperty("texture", texture); attachment.setProperty("clearColor", MTLClearColor{ - .red = @intToFloat(f32, critical.bg.r) / 255, - .green = @intToFloat(f32, critical.bg.g) / 255, - .blue = @intToFloat(f32, critical.bg.b) / 255, + .red = @floatFromInt(f32, critical.bg.r) / 255, + .green = @floatFromInt(f32, critical.bg.g) / 255, + .blue = @floatFromInt(f32, critical.bg.b) / 255, .alpha = 1.0, }); } @@ -728,9 +728,9 @@ fn drawCells( void, objc.sel("drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:"), .{ - @enumToInt(MTLPrimitiveType.triangle), + @intFromEnum(MTLPrimitiveType.triangle), @as(c_ulong, 6), - @enumToInt(MTLIndexType.uint16), + @intFromEnum(MTLIndexType.uint16), self.buf_instance.value, @as(c_ulong, 0), @as(c_ulong, cells.items.len), @@ -771,8 +771,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 = @intToFloat(f64, dim.width), - .height = @intToFloat(f64, dim.height), + .width = @floatFromInt(f64, dim.width), + .height = @floatFromInt(f64, dim.height), }); // Setup our uniforms @@ -780,8 +780,8 @@ pub fn setScreenSize(self: *Metal, dim: renderer.ScreenSize) !void { self.uniforms = .{ .projection_matrix = math.ortho2d( -1 * padding.left, - @intToFloat(f32, padded_dim.width) + padding.right, - @intToFloat(f32, padded_dim.height) + padding.bottom, + @floatFromInt(f32, padded_dim.width) + padding.right, + @floatFromInt(f32, padded_dim.height) + padding.bottom, -1 * padding.top, ), .cell_size = .{ self.cell_size.width, self.cell_size.height }, @@ -836,7 +836,7 @@ fn rebuildCells( y == screen.cursor.y) { for (self.cells.items[start_i..]) |cell| { - if (cell.grid_pos[0] == @intToFloat(f32, screen.cursor.x) and + if (cell.grid_pos[0] == @floatFromInt(f32, screen.cursor.x) and cell.mode == .fg) { cursor_cell = cell; @@ -986,7 +986,7 @@ pub fn updateCell( if (colors.bg) |rgb| { self.cells_bg.appendAssumeCapacity(.{ .mode = .bg, - .grid_pos = .{ @intToFloat(f32, x), @intToFloat(f32, y) }, + .grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) }, .cell_width = cell.widthLegacy(), .color = .{ rgb.r, rgb.g, rgb.b, alpha }, }); @@ -999,7 +999,7 @@ pub fn updateCell( self.alloc, shaper_run.font_index, shaper_cell.glyph_index, - @floatToInt(u16, @ceil(self.cell_size.height)), + @intFromFloat(u16, @ceil(self.cell_size.height)), ); // If we're rendering a color font, we use the color atlas @@ -1011,7 +1011,7 @@ pub fn updateCell( self.cells.appendAssumeCapacity(.{ .mode = mode, - .grid_pos = .{ @intToFloat(f32, x), @intToFloat(f32, y) }, + .grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) }, .cell_width = cell.widthLegacy(), .color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha }, .glyph_pos = .{ glyph.atlas_x, glyph.atlas_y }, @@ -1033,7 +1033,7 @@ pub fn updateCell( const glyph = try self.font_group.renderGlyph( self.alloc, font.sprite_index, - @enumToInt(sprite), + @intFromEnum(sprite), null, ); @@ -1041,7 +1041,7 @@ pub fn updateCell( self.cells.appendAssumeCapacity(.{ .mode = .fg, - .grid_pos = .{ @intToFloat(f32, x), @intToFloat(f32, y) }, + .grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) }, .cell_width = cell.widthLegacy(), .color = .{ color.r, color.g, color.b, alpha }, .glyph_pos = .{ glyph.atlas_x, glyph.atlas_y }, @@ -1053,7 +1053,7 @@ pub fn updateCell( if (cell.attrs.strikethrough) { self.cells.appendAssumeCapacity(.{ .mode = .strikethrough, - .grid_pos = .{ @intToFloat(f32, x), @intToFloat(f32, y) }, + .grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) }, .cell_width = cell.widthLegacy(), .color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha }, }); @@ -1085,7 +1085,7 @@ fn addCursor(self: *Metal, screen: *terminal.Screen) void { const glyph = self.font_group.renderGlyph( self.alloc, font.sprite_index, - @enumToInt(sprite), + @intFromEnum(sprite), null, ) catch |err| { log.warn("error rendering cursor glyph err={}", .{err}); @@ -1095,8 +1095,8 @@ fn addCursor(self: *Metal, screen: *terminal.Screen) void { self.cells.appendAssumeCapacity(.{ .mode = .fg, .grid_pos = .{ - @intToFloat(f32, screen.cursor.x), - @intToFloat(f32, screen.cursor.y), + @floatFromInt(f32, screen.cursor.x), + @floatFromInt(f32, screen.cursor.y), }, .cell_width = if (cell.attrs.wide) 2 else 1, .color = .{ color.r, color.g, color.b, 0xFF }, @@ -1285,7 +1285,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object { .{@as(c_ulong, 0)}, ); - attr.setProperty("format", @enumToInt(MTLVertexFormat.uchar)); + attr.setProperty("format", @intFromEnum(MTLVertexFormat.uchar)); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "mode"))); attr.setProperty("bufferIndex", @as(c_ulong, 0)); } @@ -1296,7 +1296,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object { .{@as(c_ulong, 1)}, ); - attr.setProperty("format", @enumToInt(MTLVertexFormat.float2)); + attr.setProperty("format", @intFromEnum(MTLVertexFormat.float2)); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "grid_pos"))); attr.setProperty("bufferIndex", @as(c_ulong, 0)); } @@ -1307,7 +1307,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object { .{@as(c_ulong, 2)}, ); - attr.setProperty("format", @enumToInt(MTLVertexFormat.uint2)); + attr.setProperty("format", @intFromEnum(MTLVertexFormat.uint2)); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "glyph_pos"))); attr.setProperty("bufferIndex", @as(c_ulong, 0)); } @@ -1318,7 +1318,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object { .{@as(c_ulong, 3)}, ); - attr.setProperty("format", @enumToInt(MTLVertexFormat.uint2)); + attr.setProperty("format", @intFromEnum(MTLVertexFormat.uint2)); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "glyph_size"))); attr.setProperty("bufferIndex", @as(c_ulong, 0)); } @@ -1329,7 +1329,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object { .{@as(c_ulong, 4)}, ); - attr.setProperty("format", @enumToInt(MTLVertexFormat.int2)); + attr.setProperty("format", @intFromEnum(MTLVertexFormat.int2)); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "glyph_offset"))); attr.setProperty("bufferIndex", @as(c_ulong, 0)); } @@ -1340,7 +1340,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object { .{@as(c_ulong, 5)}, ); - attr.setProperty("format", @enumToInt(MTLVertexFormat.uchar4)); + attr.setProperty("format", @intFromEnum(MTLVertexFormat.uchar4)); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "color"))); attr.setProperty("bufferIndex", @as(c_ulong, 0)); } @@ -1351,7 +1351,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object { .{@as(c_ulong, 6)}, ); - attr.setProperty("format", @enumToInt(MTLVertexFormat.uchar)); + attr.setProperty("format", @intFromEnum(MTLVertexFormat.uchar)); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "cell_width"))); attr.setProperty("bufferIndex", @as(c_ulong, 0)); } @@ -1366,7 +1366,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object { ); // Access each GPUCell per instance, not per vertex. - layout.setProperty("stepFunction", @enumToInt(MTLVertexStepFunction.per_instance)); + layout.setProperty("stepFunction", @intFromEnum(MTLVertexStepFunction.per_instance)); layout.setProperty("stride", @as(c_ulong, @sizeOf(GPUCell))); } @@ -1401,12 +1401,12 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object { // Blending. This is required so that our text we render on top // of our drawable properly blends into the bg. attachment.setProperty("blendingEnabled", true); - attachment.setProperty("rgbBlendOperation", @enumToInt(MTLBlendOperation.add)); - attachment.setProperty("alphaBlendOperation", @enumToInt(MTLBlendOperation.add)); - attachment.setProperty("sourceRGBBlendFactor", @enumToInt(MTLBlendFactor.one)); - attachment.setProperty("sourceAlphaBlendFactor", @enumToInt(MTLBlendFactor.one)); - attachment.setProperty("destinationRGBBlendFactor", @enumToInt(MTLBlendFactor.one_minus_source_alpha)); - attachment.setProperty("destinationAlphaBlendFactor", @enumToInt(MTLBlendFactor.one_minus_source_alpha)); + attachment.setProperty("rgbBlendOperation", @intFromEnum(MTLBlendOperation.add)); + attachment.setProperty("alphaBlendOperation", @intFromEnum(MTLBlendOperation.add)); + attachment.setProperty("sourceRGBBlendFactor", @intFromEnum(MTLBlendFactor.one)); + attachment.setProperty("sourceAlphaBlendFactor", @intFromEnum(MTLBlendFactor.one)); + attachment.setProperty("destinationRGBBlendFactor", @intFromEnum(MTLBlendFactor.one_minus_source_alpha)); + attachment.setProperty("destinationAlphaBlendFactor", @intFromEnum(MTLBlendFactor.one_minus_source_alpha)); } // Make our state @@ -1439,7 +1439,7 @@ fn initAtlasTexture(device: objc.Object, atlas: *const font.Atlas) !objc.Object }; // Set our properties - desc.setProperty("pixelFormat", @enumToInt(pixel_format)); + desc.setProperty("pixelFormat", @intFromEnum(pixel_format)); desc.setProperty("width", @intCast(c_ulong, atlas.size)); desc.setProperty("height", @intCast(c_ulong, atlas.size)); @@ -1569,7 +1569,7 @@ const MTLBlendOperation = enum(c_ulong) { /// https://developer.apple.com/documentation/metal/mtlresourceoptions?language=objc /// (incomplete, we only use this mode so we just hardcode it) -const MTLResourceStorageModeShared: c_ulong = @enumToInt(MTLStorageMode.shared) << 4; +const MTLResourceStorageModeShared: c_ulong = @intFromEnum(MTLStorageMode.shared) << 4; const MTLClearColor = extern struct { red: f64, diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index e0c393c52..4b13bf531 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -147,8 +147,8 @@ const SetScreenSize = struct { // 2D orthographic projection with the full w/h math.ortho2d( -1 * padding.left, - @intToFloat(f32, padded_size.width) + padding.right, - @intToFloat(f32, padded_size.height) + padding.bottom, + @floatFromInt(f32, padded_size.width) + padding.right, + @floatFromInt(f32, padded_size.height) + padding.bottom, -1 * padding.top, ), ); @@ -218,9 +218,9 @@ const GPUCellMode = enum(u8) { /// Apply a mask to the mode. pub fn mask(self: GPUCellMode, m: GPUCellMode) GPUCellMode { - return @intToEnum( + return @enumFromInt( GPUCellMode, - @enumToInt(self) | @enumToInt(m), + @intFromEnum(self) | @intFromEnum(m), ); } }; @@ -661,10 +661,10 @@ fn resetFontMetrics( // Set details for our sprite font font_group.group.sprite = font.sprite.Face{ - .width = @floatToInt(u32, metrics.cell_width), - .height = @floatToInt(u32, metrics.cell_height), + .width = @intFromFloat(u32, metrics.cell_width), + .height = @intFromFloat(u32, metrics.cell_height), .thickness = 2, - .underline_position = @floatToInt(u32, metrics.underline_position), + .underline_position = @intFromFloat(u32, metrics.underline_position), }; return metrics; @@ -993,7 +993,7 @@ fn addCursor(self: *OpenGL, screen: *terminal.Screen) void { const glyph = self.font_group.renderGlyph( self.alloc, font.sprite_index, - @enumToInt(sprite), + @intFromEnum(sprite), null, ) catch |err| { log.warn("error rendering cursor glyph err={}", .{err}); @@ -1147,7 +1147,7 @@ pub fn updateCell( self.alloc, shaper_run.font_index, shaper_cell.glyph_index, - @floatToInt(u16, @ceil(self.cell_size.height)), + @intFromFloat(u16, @ceil(self.cell_size.height)), ); // If we're rendering a color font, we use the color atlas @@ -1192,7 +1192,7 @@ pub fn updateCell( const underline_glyph = try self.font_group.renderGlyph( self.alloc, font.sprite_index, - @enumToInt(sprite), + @intFromEnum(sprite), null, ); @@ -1388,9 +1388,9 @@ pub fn draw(self: *OpenGL) !void { // Clear the surface gl.clearColor( - @intToFloat(f32, self.draw_background.r) / 255, - @intToFloat(f32, self.draw_background.g) / 255, - @intToFloat(f32, self.draw_background.b) / 255, + @floatFromInt(f32, self.draw_background.r) / 255, + @floatFromInt(f32, self.draw_background.g) / 255, + @floatFromInt(f32, 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 647656640..12fab5294 100644 --- a/src/renderer/opengl/Buffer.zig +++ b/src/renderer/opengl/Buffer.zig @@ -42,7 +42,7 @@ pub const Binding = struct { usage: Usage, ) !void { const info = dataInfo(&data); - glad.context.BufferData.?(@enumToInt(b.target), info.size, info.ptr, @enumToInt(usage)); + glad.context.BufferData.?(@intFromEnum(b.target), info.size, info.ptr, @intFromEnum(usage)); try errors.getError(); } @@ -54,7 +54,7 @@ pub const Binding = struct { data: anytype, ) !void { const info = dataInfo(data); - glad.context.BufferSubData.?(@enumToInt(b.target), @intCast(c_long, offset), info.size, info.ptr); + glad.context.BufferSubData.?(@intFromEnum(b.target), @intCast(c_long, offset), info.size, info.ptr); try errors.getError(); } @@ -66,7 +66,7 @@ pub const Binding = struct { comptime T: type, usage: Usage, ) !void { - glad.context.BufferData.?(@enumToInt(b.target), @sizeOf(T), null, @enumToInt(usage)); + glad.context.BufferData.?(@intFromEnum(b.target), @sizeOf(T), null, @intFromEnum(usage)); try errors.getError(); } @@ -76,7 +76,7 @@ pub const Binding = struct { size: usize, usage: Usage, ) !void { - glad.context.BufferData.?(@enumToInt(b.target), @intCast(c_long, size), null, @enumToInt(usage)); + glad.context.BufferData.?(@intFromEnum(b.target), @intCast(c_long, size), null, @intFromEnum(usage)); try errors.getError(); } @@ -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) - @intToPtr(*const anyopaque, offset) + @ptrFromInt(*const anyopaque, offset) else null; @@ -186,7 +186,7 @@ pub const Binding = struct { offset: usize, ) !void { const offsetPtr = if (offset > 0) - @intToPtr(*const anyopaque, offset) + @ptrFromInt(*const anyopaque, offset) else null; @@ -195,7 +195,7 @@ pub const Binding = struct { } pub inline fn unbind(b: *Binding) void { - glad.context.BindBuffer.?(@enumToInt(b.target), 0); + glad.context.BindBuffer.?(@intFromEnum(b.target), 0); b.* = undefined; } }; @@ -209,7 +209,7 @@ pub inline fn create() !Buffer { /// glBindBuffer pub inline fn bind(v: Buffer, target: Target) !Binding { - glad.context.BindBuffer.?(@enumToInt(target), v.id); + glad.context.BindBuffer.?(@intFromEnum(target), v.id); return Binding{ .target = target }; } diff --git a/src/renderer/opengl/Texture.zig b/src/renderer/opengl/Texture.zig index f52d12859..91a65b565 100644 --- a/src/renderer/opengl/Texture.zig +++ b/src/renderer/opengl/Texture.zig @@ -76,19 +76,19 @@ pub const Binding = struct { target: Target, pub inline fn unbind(b: *Binding) void { - glad.context.BindTexture.?(@enumToInt(b.target), 0); + glad.context.BindTexture.?(@intFromEnum(b.target), 0); b.* = undefined; } pub fn generateMipmap(b: Binding) void { - glad.context.GenerateMipmap.?(@enumToInt(b.target)); + glad.context.GenerateMipmap.?(@intFromEnum(b.target)); } pub fn parameter(b: Binding, name: Parameter, value: anytype) !void { switch (@TypeOf(value)) { c.GLint => glad.context.TexParameteri.?( - @enumToInt(b.target), - @enumToInt(name), + @intFromEnum(b.target), + @intFromEnum(name), value, ), else => unreachable, @@ -107,14 +107,14 @@ pub const Binding = struct { data: ?*const anyopaque, ) !void { glad.context.TexImage2D.?( - @enumToInt(b.target), + @intFromEnum(b.target), level, - @enumToInt(internal_format), + @intFromEnum(internal_format), width, height, border, - @enumToInt(format), - @enumToInt(typ), + @intFromEnum(format), + @intFromEnum(typ), data, ); } @@ -131,14 +131,14 @@ pub const Binding = struct { data: ?*const anyopaque, ) !void { glad.context.TexSubImage2D.?( - @enumToInt(b.target), + @intFromEnum(b.target), level, xoffset, yoffset, width, height, - @enumToInt(format), - @enumToInt(typ), + @intFromEnum(format), + @intFromEnum(typ), data, ); } @@ -153,7 +153,7 @@ pub inline fn create() !Texture { /// glBindTexture pub inline fn bind(v: Texture, target: Target) !Binding { - glad.context.BindTexture.?(@enumToInt(target), v.id); + glad.context.BindTexture.?(@intFromEnum(target), v.id); try errors.getError(); return Binding{ .target = target }; } diff --git a/src/renderer/opengl/draw.zig b/src/renderer/opengl/draw.zig index e23997471..2a2ffabb3 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 @intToPtr(*const anyopaque, offset); + const offsetPtr = if (offset == 0) null else @ptrFromInt(*const anyopaque, offset); glad.context.DrawElements.?(mode, count, typ, offsetPtr); try errors.getError(); } diff --git a/src/renderer/size.zig b/src/renderer/size.zig index 7f3f3578b..d1e2224dc 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 -| @floatToInt(u32, padding.left + padding.right), - .height = self.height -| @floatToInt(u32, padding.top + padding.bottom), + .width = self.width -| @intFromFloat(u32, padding.left + padding.right), + .height = self.height -| @intFromFloat(u32, 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, @floatToInt(Unit, @intToFloat(f32, screen.width) / cell.width)); - self.rows = @max(1, @floatToInt(Unit, @intToFloat(f32, screen.height) / cell.height)); + self.columns = @max(1, @intFromFloat(Unit, @floatFromInt(f32, screen.width) / cell.width)); + self.rows = @max(1, @intFromFloat(Unit, @floatFromInt(f32, 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 = @intToFloat(f32, grid.columns) * cell.width; - const grid_height = @intToFloat(f32, grid.rows) * cell.height; + const grid_width = @floatFromInt(f32, grid.columns) * cell.width; + const grid_height = @floatFromInt(f32, grid.rows) * cell.height; // The empty space to the right of a line and bottom of the last row - const space_right = @intToFloat(f32, screen.width) - grid_width; - const space_bot = @intToFloat(f32, screen.height) - grid_height; + const space_right = @floatFromInt(f32, screen.width) - grid_width; + const space_bot = @floatFromInt(f32, 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 07466e19e..99d26b3b4 100644 --- a/src/terminal/Parser.zig +++ b/src/terminal/Parser.zig @@ -171,7 +171,7 @@ pub const Action = union(enum) { try writer.writeAll(" }"); } else { - try format(writer, "@{x}", .{@ptrToInt(&self)}); + try format(writer, "@{x}", .{@intFromPtr(&self)}); } } }; @@ -224,7 +224,7 @@ pub fn next(self: *Parser, c: u8) [3]?Action { return .{ self.next_utf8(c), null, null }; } - const effect = table[c][@enumToInt(self.state)]; + const effect = table[c][@intFromEnum(self.state)]; // log.info("next: {x}", .{c}); @@ -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 = @intToEnum(ParamSepState, c); - if (@intToEnum(ParamSepState, c) != self.params_sep) self.params_sep = .mixed; + if (self.params_idx == 0) self.params_sep = @enumFromInt(ParamSepState, c); + if (@enumFromInt(ParamSepState, 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 887f55acd..ba58bd678 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -1048,7 +1048,7 @@ pub fn scrollRegionUp(self: *Screen, top: RowIndex, bottom: RowIndex, count: usi const dst = buf; const src_offset = count * (self.cols + 1); const src = buf[src_offset..]; - assert(@ptrToInt(dst.ptr) < @ptrToInt(src.ptr)); + assert(@intFromPtr(dst.ptr) < @intFromPtr(src.ptr)); fastmem.move(StorageCell, dst, src); } @@ -1093,7 +1093,7 @@ pub fn scrollRegionUp(self: *Screen, top: RowIndex, bottom: RowIndex, count: usi // Source starts in the top... so we can copy some from there. const dst = slices[0]; const src = slices[0][src_offset..]; - assert(@ptrToInt(dst.ptr) < @ptrToInt(src.ptr)); + assert(@intFromPtr(dst.ptr) < @intFromPtr(src.ptr)); fastmem.move(StorageCell, dst, src); remaining = total_copy - src.len; if (remaining == 0) break :zero_offset .{ src.len, 0 }; diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 13193a692..058977379 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -527,12 +527,12 @@ pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void { .@"8_fg" => |n| { self.screen.cursor.pen.attrs.has_fg = true; - self.screen.cursor.pen.fg = self.color_palette[@enumToInt(n)]; + self.screen.cursor.pen.fg = self.color_palette[@intFromEnum(n)]; }, .@"8_bg" => |n| { self.screen.cursor.pen.attrs.has_bg = true; - self.screen.cursor.pen.bg = self.color_palette[@enumToInt(n)]; + self.screen.cursor.pen.bg = self.color_palette[@intFromEnum(n)]; }, .reset_fg => self.screen.cursor.pen.attrs.has_fg = false, @@ -541,12 +541,12 @@ pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void { .@"8_bright_fg" => |n| { self.screen.cursor.pen.attrs.has_fg = true; - self.screen.cursor.pen.fg = self.color_palette[@enumToInt(n)]; + self.screen.cursor.pen.fg = self.color_palette[@intFromEnum(n)]; }, .@"8_bright_bg" => |n| { self.screen.cursor.pen.attrs.has_bg = true; - self.screen.cursor.pen.bg = self.color_palette[@enumToInt(n)]; + self.screen.cursor.pen.bg = self.color_palette[@intFromEnum(n)]; }, .@"256_fg" => |idx| { diff --git a/src/terminal/color.zig b/src/terminal/color.zig index 3bbfd3d41..9414af52f 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(@intToEnum(Name, i)) catch unreachable; + result[i] = Name.default(@enumFromInt(Name, 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(@intToEnum(Name, i)), default[i]); + try testing.expectEqual(Name.default(@enumFromInt(Name, i)), default[i]); } } diff --git a/src/terminal/parse_table.zig b/src/terminal/parse_table.zig index 0ada758f2..450e5a266 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 = @intToEnum(State, field.value); + const source = @enumFromInt(State, 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(@intToEnum(State, j), .none); + final[i][j] = result[i][j] orelse transition(@enumFromInt(State, j), .none); } } @@ -365,7 +365,7 @@ fn genTable() Table { } fn single(t: *OptionalTable, c: u8, s0: State, s1: State, a: Action) void { - const s0_int = @enumToInt(s0); + const s0_int = @intFromEnum(s0); // TODO: enable this but it thinks we're in runtime right now // if (t[c][s0_int]) |existing| { diff --git a/src/terminal/sgr.zig b/src/terminal/sgr.zig index 2f127b017..5272c1fb0 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" = @intToEnum(color.Name, slice[0] - 30), + .@"8_fg" = @enumFromInt(color.Name, slice[0] - 30), }, 38 => if (slice.len >= 5 and slice[1] == 2) { @@ -214,7 +214,7 @@ pub const Parser = struct { 39 => return Attribute{ .reset_fg = {} }, 40...47 => return Attribute{ - .@"8_bg" = @intToEnum(color.Name, slice[0] - 40), + .@"8_bg" = @enumFromInt(color.Name, slice[0] - 40), }, 48 => if (slice.len >= 5 and slice[1] == 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" = @intToEnum(color.Name, slice[0] - 82), + .@"8_bright_fg" = @enumFromInt(color.Name, slice[0] - 82), }, 100...107 => return Attribute{ - .@"8_bright_bg" = @intToEnum(color.Name, slice[0] - 92), + .@"8_bright_bg" = @enumFromInt(color.Name, slice[0] - 92), }, else => {}, diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index 6301e9b16..c0b3cfc5d 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -73,7 +73,7 @@ pub fn Stream(comptime Handler: type) type { tracy.value(@intCast(u64, c)); defer tracy.end(); - switch (@intToEnum(ansi.C0, c)) { + switch (@enumFromInt(ansi.C0, c)) { .NUL => {}, .ENQ => if (@hasDecl(T, "enquiry")) @@ -229,7 +229,7 @@ pub fn Stream(comptime Handler: type) type { return; } - break :mode @intToEnum( + break :mode @enumFromInt( csi.EraseDisplay, action.params[0], ); @@ -252,7 +252,7 @@ pub fn Stream(comptime Handler: type) type { return; } - break :mode @intToEnum( + break :mode @enumFromInt( csi.EraseLine, action.params[0], ); @@ -422,7 +422,7 @@ pub fn Stream(comptime Handler: type) type { // TODO: test 'g' => if (@hasDecl(T, "tabClear")) try self.handler.tabClear( switch (action.params.len) { - 1 => @intToEnum(csi.TabClear, action.params[0]), + 1 => @enumFromInt(csi.TabClear, action.params[0]), else => { log.warn("invalid tab clear command: {}", .{action}); return; @@ -433,13 +433,13 @@ pub fn Stream(comptime Handler: type) type { // SM - Set Mode 'h' => if (@hasDecl(T, "setMode")) { for (action.params) |mode| - try self.handler.setMode(@intToEnum(ansi.Mode, mode), true); + try self.handler.setMode(@enumFromInt(ansi.Mode, 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(@intToEnum(ansi.Mode, mode), false); + try self.handler.setMode(@enumFromInt(ansi.Mode, mode), false); } else log.warn("unimplemented CSI callback: {}", .{action}), // SGR - Select Graphic Rendition @@ -455,7 +455,7 @@ pub fn Stream(comptime Handler: type) type { // TODO: test 'n' => if (@hasDecl(T, "deviceStatusReport")) try self.handler.deviceStatusReport( switch (action.params.len) { - 1 => @intToEnum(ansi.DeviceStatusReq, action.params[0]), + 1 => @enumFromInt(ansi.DeviceStatusReq, action.params[0]), else => { log.warn("invalid erase characters command: {}", .{action}); return; @@ -468,7 +468,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 => @intToEnum(ansi.CursorStyle, action.params[0]), + 1 => @enumFromInt(ansi.CursorStyle, action.params[0]), else => { log.warn("invalid set curor style command: {}", .{action}); return; @@ -505,7 +505,7 @@ pub fn Stream(comptime Handler: type) type { break :decsasd false; try self.handler.setActiveStatusDisplay( - @intToEnum(ansi.StatusDisplay, action.params[0]), + @enumFromInt(ansi.StatusDisplay, action.params[0]), ); break :decsasd true; }; @@ -799,10 +799,10 @@ test "stream: cursor right (CUF)" { test "stream: set mode (SM) and reset mode (RM)" { const H = struct { - mode: ansi.Mode = @intToEnum(ansi.Mode, 0), + mode: ansi.Mode = @enumFromInt(ansi.Mode, 0), pub fn setMode(self: *@This(), mode: ansi.Mode, v: bool) !void { - self.mode = @intToEnum(ansi.Mode, 0); + self.mode = @enumFromInt(ansi.Mode, 0); if (v) self.mode = mode; } }; @@ -812,5 +812,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(@intToEnum(ansi.Mode, 0), s.handler.mode); + try testing.expectEqual(@enumFromInt(ansi.Mode, 0), s.handler.mode); } diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 75491dc6f..6596be7a3 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -881,7 +881,7 @@ const ReadThread = struct { const end = buf.len; if (ev.terminal_stream.parser.state == .ground) { for (buf[i..end]) |ch| { - switch (terminal.parse_table.table[ch][@enumToInt(terminal.Parser.State.ground)].action) { + 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| log.err("error processing terminal data: {}", .{err}), diff --git a/vendor/mach-glfw b/vendor/mach-glfw index 936bfeafa..1bc121e0b 160000 --- a/vendor/mach-glfw +++ b/vendor/mach-glfw @@ -1 +1 @@ -Subproject commit 936bfeafa317314a1141e8f4521b1cb1f9743d4d +Subproject commit 1bc121e0b1fcc0d367b750eb12893febd887d3a9 From e3affae38170d64c90ae463611c206b962f28bf3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 25 Jun 2023 11:17:47 -0700 Subject: [PATCH 2/4] update libxev --- vendor/libxev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/libxev b/vendor/libxev index 9024a57ef..b17acd118 160000 --- a/vendor/libxev +++ b/vendor/libxev @@ -1 +1 @@ -Subproject commit 9024a57ef9133382f95927eaf4b6c2b1662598e0 +Subproject commit b17acd118d3442b5e937f509cfbc95e17bed47ba From 8a83a1e4a95990fbadaaf91bebeb972d665db6b7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 25 Jun 2023 11:17:51 -0700 Subject: [PATCH 3/4] fix min usage in src/os --- src/os/file.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/file.zig b/src/os/file.zig index cdbcd5ced..ae4f5907d 100644 --- a/src/os/file.zig +++ b/src/os/file.zig @@ -20,7 +20,7 @@ pub fn fixMaxFiles() void { // setrlimit() now returns with errno set to EINVAL in places that historically succeeded. // It no longer accepts "rlim_cur = RLIM.INFINITY" for RLIM.NOFILE. // Use "rlim_cur = min(OPEN_MAX, rlim_max)". - lim.max = std.math.min(std.os.darwin.OPEN_MAX, lim.max); + lim.max = @min(std.os.darwin.OPEN_MAX, lim.max); } // If we're already at the max, we're done. From b7b3b9e7f2bd7ba5f8dad95a291f03e3863cb50f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 25 Jun 2023 11:18:09 -0700 Subject: [PATCH 4/4] build.zig update min version --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 552d17fe1..911d012b1 100644 --- a/build.zig +++ b/build.zig @@ -36,7 +36,7 @@ const system_sdk = @import("vendor/mach-glfw/system_sdk.zig"); // but we liberally update it. In the future, we'll be more careful about // using released versions so that package managers can integrate better. comptime { - const required_zig = "0.11.0-dev.3312+ab37ab33c"; + const required_zig = "0.11.0-dev.3803+7ad104227"; const current_zig = builtin.zig_version; const min_zig = std.SemanticVersion.parse(required_zig) catch unreachable; if (current_zig.order(min_zig) == .lt) {