mirror of
https://github.com/raylib-zig/raylib-zig.git
synced 2026-02-21 00:34:46 +00:00
Add more enum support + examples 'working'
This commit is contained in:
parent
63b0fed263
commit
c708117831
@ -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);
|
||||
|
||||
@ -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; }
|
||||
|
||||
@ -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();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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("*"):
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user