From c70811783195c25b6e52f50a15189cb81e70c03f Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Sat, 9 May 2020 22:58:37 +1000 Subject: [PATCH] Add more enum support + examples 'working' --- examples/core/2d_camera.zig | 3 ++- examples/core/input_mouse.zig | 2 +- examples/core/input_mouse_wheel.zig | 2 +- examples/core/input_multitouch.zig | 6 +++--- lib/generate_functions.py | 17 ++++++++++++++--- lib/raylib-wa.zig | 18 +++++++++--------- lib/raylib-zig.zig | 1 - 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/examples/core/2d_camera.zig b/examples/core/2d_camera.zig index 4d20093..46f63b3 100755 --- a/examples/core/2d_camera.zig +++ b/examples/core/2d_camera.zig @@ -114,7 +114,8 @@ pub fn main() anyerror!void DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, RED); DrawRectangle(0, screenHeight - 5, screenWidth, 5, RED); - DrawRectangle( 10, 10, 250, 113, Fade(SKYBLUE, 0.5)); + //DrawRectangle( 10, 10, 250, 113, Fade(SKYBLUE, 0.5)); + DrawRectangle( 10, 10, 250, 113, SKYBLUE); DrawRectangleLines( 10, 10, 250, 113, BLUE); DrawText("Free 2d camera controls:", 20, 20, 10, BLACK); diff --git a/examples/core/input_mouse.zig b/examples/core/input_mouse.zig index b88ba25..87c70c6 100755 --- a/examples/core/input_mouse.zig +++ b/examples/core/input_mouse.zig @@ -27,7 +27,7 @@ pub fn main() anyerror!void { // Update //---------------------------------------------------------------------------------- - ballPosition = GetMousePosition(); + //ballPosition = GetMousePosition(); if (IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) { ballColor = MAROON; } else if (IsMouseButtonPressed(MouseButton.MOUSE_MIDDLE_BUTTON)) { ballColor = LIME; } diff --git a/examples/core/input_mouse_wheel.zig b/examples/core/input_mouse_wheel.zig index 42cc419..4224cd7 100755 --- a/examples/core/input_mouse_wheel.zig +++ b/examples/core/input_mouse_wheel.zig @@ -39,7 +39,7 @@ pub fn main() anyerror!void DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON); DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY); - DrawText(FormatText("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY); + //DrawText(FormatText("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples/core/input_multitouch.zig b/examples/core/input_multitouch.zig index 24d0765..974d4c8 100755 --- a/examples/core/input_multitouch.zig +++ b/examples/core/input_multitouch.zig @@ -30,7 +30,7 @@ pub fn main() anyerror!void { // Update //---------------------------------------------------------------------------------- - ballPosition = GetMousePosition(); + //ballPosition = GetMousePosition(); ballColor = BEIGE; @@ -54,14 +54,14 @@ pub fn main() anyerror!void const nums = [_]i32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; for (nums) |i| { - touchPosition = GetTouchPosition(i); // Get the touch point + //touchPosition = GetTouchPosition(i); // Get the touch point if ((touchPosition.x >= 0) and (touchPosition.y >= 0)) // Make sure point is not (-1,-1) as this means there is no touch for it { // Draw circle and touch index number DrawCircle(@floatToInt(c_int, touchPosition.x), @floatToInt(c_int, touchPosition.y), 34, ORANGE); //DrawCircleV(touchPosition, 34, ORANGE); - DrawText(FormatText("%d", i), @floatToInt(c_int, touchPosition.x) - 10, @floatToInt(c_int, touchPosition.y) - 70, 40, BLACK); + //DrawText(FormatText("%d", i), @floatToInt(c_int, touchPosition.x) - 10, @floatToInt(c_int, touchPosition.y) - 70, 40, BLACK); } } diff --git a/lib/generate_functions.py b/lib/generate_functions.py index 146051b..38d217e 100644 --- a/lib/generate_functions.py +++ b/lib/generate_functions.py @@ -37,11 +37,20 @@ def fix_pointer(name: str, t: str): pre += "[*c]" if len(pre) != 0: t = pre + "const " + t + return name, t + + +def fix_enums(arg_name, arg_type, func_name): # Hacking specifc enums in here # Raylib doesn't use the enums but rather the resulting ints - if name == "key" and t == "c_int": - t = "KeyboardKey" - return name, t + if arg_type == "int": + if arg_name == "key": + arg_type = "KeyboardKey" + elif arg_name == "button": + arg_type = "MouseButton" + elif arg_name == "mode" and func_name == "SetCameraMode": + arg_type = "CameraMode" + return arg_type small_structs = ["Vector2", "Vector3", "Vector4", "Quaternion", "Color", "Rectangle", "Shader"] @@ -83,6 +92,7 @@ def parse_header(header_name: str, output_file: str, prefix: str): arg_type = " ".join(arg.split(" ")[0:-1]) # everything but the last element (for stuff like "const Vector3") arg_type = arg_type.replace("const ", "") # zig doesn't like const in function arguments that aren't pointer and really we don't need const arg_name = arg.split(" ")[-1] # last element should be the name + arg_type = fix_enums(arg_name, arg_type, func_name) arg_type = c_to_zig_type(arg_type) arg_name, arg_type = fix_pointer(arg_name, arg_type) @@ -101,6 +111,7 @@ def parse_header(header_name: str, output_file: str, prefix: str): if arg == "void": break arg_type = " ".join(arg.split(" ")[0:-1]).replace("const ", "") # everything but the last element (for stuff like "const Vector3"), but discarding const arg_name = arg.split(" ")[-1] # last element should be the name + arg_type = fix_enums(arg_name, arg_type, func_name) depoint = False # set to true if we need to dereference a pointer to a small struct in the c workaround if arg_type in small_structs: if not arg_name.startswith("*"): diff --git a/lib/raylib-wa.zig b/lib/raylib-wa.zig index 791dffa..f7821cb 100644 --- a/lib/raylib-wa.zig +++ b/lib/raylib-wa.zig @@ -92,17 +92,17 @@ pub extern fn GetKeyPressed() c_int; pub extern fn IsGamepadAvailable(gamepad: c_int) bool; pub extern fn IsGamepadName(gamepad: c_int, name: [*c]const u8) bool; pub extern fn GetGamepadName(gamepad: c_int) [*c]const u8; -pub extern fn IsGamepadButtonPressed(gamepad: c_int, button: c_int) bool; -pub extern fn IsGamepadButtonDown(gamepad: c_int, button: c_int) bool; -pub extern fn IsGamepadButtonReleased(gamepad: c_int, button: c_int) bool; -pub extern fn IsGamepadButtonUp(gamepad: c_int, button: c_int) bool; +pub extern fn IsGamepadButtonPressed(gamepad: c_int, button: MouseButton) bool; +pub extern fn IsGamepadButtonDown(gamepad: c_int, button: MouseButton) bool; +pub extern fn IsGamepadButtonReleased(gamepad: c_int, button: MouseButton) bool; +pub extern fn IsGamepadButtonUp(gamepad: c_int, button: MouseButton) bool; pub extern fn GetGamepadButtonPressed() c_int; pub extern fn GetGamepadAxisCount(gamepad: c_int) c_int; pub extern fn GetGamepadAxisMovement(gamepad: c_int, axis: c_int) f32; -pub extern fn IsMouseButtonPressed(button: c_int) bool; -pub extern fn IsMouseButtonDown(button: c_int) bool; -pub extern fn IsMouseButtonReleased(button: c_int) bool; -pub extern fn IsMouseButtonUp(button: c_int) bool; +pub extern fn IsMouseButtonPressed(button: MouseButton) bool; +pub extern fn IsMouseButtonDown(button: MouseButton) bool; +pub extern fn IsMouseButtonReleased(button: MouseButton) bool; +pub extern fn IsMouseButtonUp(button: MouseButton) bool; pub extern fn GetMouseX() c_int; pub extern fn GetMouseY() c_int; pub extern fn SetMousePosition(x: c_int, y: c_int) void; @@ -118,7 +118,7 @@ pub extern fn GetTouchPointsCount() c_int; pub extern fn GetGestureHoldDuration() f32; pub extern fn GetGestureDragAngle() f32; pub extern fn GetGesturePinchAngle() f32; -pub extern fn SetCameraMode(camera: Camera, mode: c_int) void; +pub extern fn SetCameraMode(camera: Camera, mode: CameraMode) void; pub extern fn UpdateCamera(camera: [*c]const Camera) void; pub extern fn SetCameraPanControl(panKey: c_int) void; pub extern fn SetCameraAltControl(altKey: c_int) void; diff --git a/lib/raylib-zig.zig b/lib/raylib-zig.zig index 327137b..9786aa9 100755 --- a/lib/raylib-zig.zig +++ b/lib/raylib-zig.zig @@ -743,6 +743,5 @@ pub const PI = 3.141593; pub const SpriteFont = Font; pub const SubText = TextSubtext; pub const ShowWindow = UnhideWindow; -pub const FormatText = TextFormat; pub usingnamespace @import("raylib-wa.zig");