diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 03d24c5..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -libraylib.a diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 4219e8c..0000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "3rdparty/raylib"] - path = 3rdparty/raylib - url = https://github.com/raysan5/raylib -[submodule "3rdparty/raygui"] - path = 3rdparty/raygui - url = https://github.com/raysan5/raygui.git diff --git a/3rdparty/raygui b/3rdparty/raygui deleted file mode 160000 index 865bb29..0000000 --- a/3rdparty/raygui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 865bb293764073c01e74314ef647464f1f10fd96 diff --git a/3rdparty/raylib b/3rdparty/raylib deleted file mode 160000 index ca12ef4..0000000 --- a/3rdparty/raylib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ca12ef48e9e9f4eae03b1ca43ec3eb0a78d63dd3 diff --git a/build.zig b/build.zig index bf46761..8992841 100644 --- a/build.zig +++ b/build.zig @@ -1,48 +1,29 @@ const std = @import("std"); -const raylib = @import("./3rdparty/raylib/src/build.zig"); +const capy = @import("capy"); -pub fn build(b: *std.build.Builder) void { - // Standard target options allows the person running `zig build` to choose - // what target to build for. Here we do not override the defaults, which - // means any target is allowed, and the default is native. Other options - // for restricting supported target set are available. +pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); + const mode = b.standardOptimizeOption(.{}); - // Standard release options allow the person running `zig build` to select - // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. - const mode = b.standardReleaseOptions(); + const exe = b.addExecutable(.{ + .name = "doggo", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = mode, + }); - const exe = b.addExecutable("doggo", "src/main.zig"); - exe.setTarget(target); + b.installArtifact(exe); - const ray = raylib.addRaylib(b, exe.target); - exe.linkLibrary(ray); - exe.addIncludeDir("3rdparty/raylib/src"); - exe.addIncludeDir("3rdparty/raygui/src"); - exe.addIncludeDir("3rdparty/raygui/examples"); - const raylib_flags = &[_][]const u8{ - "-std=gnu99", - "-DPLATFORM_DESKTOP", - "-DGL_SILENCE_DEPRECATION=199309L", - "-fno-sanitize=undefined", - }; - exe.addCSourceFile("src/raylib.c", raylib_flags); - - exe.setBuildMode(mode); - exe.install(); - - const run_cmd = exe.run(); - run_cmd.step.dependOn(b.getInstallStep()); - if (b.args) |args| { - run_cmd.addArgs(args); - } + const run_cmd = try capy.install(exe, .{ .args = b.args }); const run_step = b.step("run", "Run the app"); - run_step.dependOn(&run_cmd.step); + run_step.dependOn(run_cmd); - const exe_tests = b.addTest("src/main.zig"); - exe_tests.setTarget(target); - exe_tests.setBuildMode(mode); + const exe_tests = b.addTest(.{ + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = mode, + }); const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&exe_tests.step); diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..7dd480c --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,19 @@ +.{ + .name = "doggo", + .version = "0.1.0", + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + }, + .dependencies = .{ + .capy = .{ + .url = "https://github.com/ffreling/capy/archive/refs/heads/zig-0.12.0.tar.gz", + .hash = "12207fd2f0d02eb929d1e8a05843de4dc3f4b362055e9e47a014fb6b806a592d9808", + }, + .zigimg = .{ + .url = "https://github.com/zigimg/zigimg/archive/8873f29fc449e1b63400e9f4ad86d3c76204f962.tar.gz", + .hash = "122019f6439545235af116d0d8eb81fde1ff05fdb070da57c723772c557f84c5bf39", + }, + }, +} diff --git a/flake.nix b/flake.nix index dfc61b5..9cf7396 100644 --- a/flake.nix +++ b/flake.nix @@ -4,10 +4,6 @@ outputs = { self, nixpkgs }: let pkgs = nixpkgs.legacyPackages.x86_64-linux; in { - # packages.x86_64-linux.hello = pkgs.hello; - # packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello; - # defaultPackage.x86_64-linux = self.packages.x86_64-linux.hello; - devShell.x86_64-linux = with pkgs; mkShell { nativeBuildInputs = [ @@ -16,15 +12,7 @@ zls ]; buildInputs = [ - xorg.libX11 - xorg.libXcursor - xorg.libXi - xorg.libXext - xorg.libXrandr - xorg.libXinerama - wayland - libGL - libGLU + gtk4 ]; }; }; diff --git a/justfile b/justfile index acbc9ed..112626b 100644 --- a/justfile +++ b/justfile @@ -1,2 +1,7 @@ +alias b := build +build: + zig build + +alias r := run run: - nixGL zig build run + zig build run diff --git a/src/main.zig b/src/main.zig index 9b4a4bc..b19dee6 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,40 +1,20 @@ const std = @import("std"); -const r = @import("raylib.zig"); +const capy = @import("capy"); -pub fn main() anyerror!void { - r.InitWindow(800, 450, "doggo"); - defer r.CloseWindow(); +// This is required for your app to build to WebAssembly and other particular architectures +pub usingnamespace capy.cross_platform; - // var selected_filename: [512]u8 = undefined; - var file_dialog_state = r.InitGuiFileDialog(420, 310, r.GetWorkingDirectory(), false); +pub fn main() !void { + try capy.backend.init(); - while (!r.WindowShouldClose()) { - // Update - if (file_dialog_state.SelectFilePressed) { - std.log.info("{s} / {s}", .{ file_dialog_state.dirPathText, file_dialog_state.fileNameText }); - } + var window = try capy.Window.init(); + try window.set( + capy.label(.{ .text = "Hello, World", .alignment = .Center }), + ); - // Draw - r.BeginDrawing(); - defer r.EndDrawing(); + window.setTitle("Hello"); + window.setPreferredSize(250, 100); + window.show(); - r.ClearBackground(r.RAYWHITE); - r.DrawText("Congrats! You created your first window!", 190, 200, 20, r.LIGHTGRAY); - - if (file_dialog_state.fileDialogActive) { - r.GuiLock(); - } - - if (r.GuiButton(r.Rectangle{ .x = 190, .y = 250, .width = 150, .height = 30 }, "Button")) { - std.log.info("Button pressed", .{}); - file_dialog_state.fileDialogActive = true; - } - r.GuiUnlock(); - - r.GuiFileDialog(&file_dialog_state); - } -} - -test "basic test" { - try std.testing.expectEqual(10, 3 + 7); + capy.runEventLoop(); } diff --git a/src/raylib.c b/src/raylib.c deleted file mode 100644 index 0dec298..0000000 --- a/src/raylib.c +++ /dev/null @@ -1,6 +0,0 @@ -#define RAYGUI_IMPLEMENTATION -#include -#undef RAYGUI_IMPLEMENTATION // Avoid including raygui implementation again - -#define GUI_FILE_DIALOG_IMPLEMENTATION -#include diff --git a/src/raylib.zig b/src/raylib.zig deleted file mode 100644 index 78660e4..0000000 --- a/src/raylib.zig +++ /dev/null @@ -1,5 +0,0 @@ -pub usingnamespace @cImport({ - @cInclude("raylib.h"); - @cInclude("raygui.h"); - @cInclude("custom_file_dialog/gui_file_dialog.h"); -});