diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03d24c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +libraylib.a diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4219e8c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[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 new file mode 160000 index 0000000..865bb29 --- /dev/null +++ b/3rdparty/raygui @@ -0,0 +1 @@ +Subproject commit 865bb293764073c01e74314ef647464f1f10fd96 diff --git a/3rdparty/raylib b/3rdparty/raylib new file mode 160000 index 0000000..ca12ef4 --- /dev/null +++ b/3rdparty/raylib @@ -0,0 +1 @@ +Subproject commit ca12ef48e9e9f4eae03b1ca43ec3eb0a78d63dd3 diff --git a/build.zig b/build.zig index 8992841..bf46761 100644 --- a/build.zig +++ b/build.zig @@ -1,29 +1,48 @@ const std = @import("std"); -const capy = @import("capy"); +const raylib = @import("./3rdparty/raylib/src/build.zig"); -pub fn build(b: *std.Build) !void { +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. const target = b.standardTargetOptions(.{}); - const mode = b.standardOptimizeOption(.{}); - const exe = b.addExecutable(.{ - .name = "doggo", - .root_source_file = .{ .path = "src/main.zig" }, - .target = target, - .optimize = mode, - }); + // Standard release options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. + const mode = b.standardReleaseOptions(); - b.installArtifact(exe); + const exe = b.addExecutable("doggo", "src/main.zig"); + exe.setTarget(target); - const run_cmd = try capy.install(exe, .{ .args = b.args }); + 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_step = b.step("run", "Run the app"); - run_step.dependOn(run_cmd); + run_step.dependOn(&run_cmd.step); - const exe_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, - .target = target, - .optimize = mode, - }); + const exe_tests = b.addTest("src/main.zig"); + exe_tests.setTarget(target); + exe_tests.setBuildMode(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 deleted file mode 100644 index 7dd480c..0000000 --- a/build.zig.zon +++ /dev/null @@ -1,19 +0,0 @@ -.{ - .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.lock b/flake.lock index 66a0d8f..79a3116 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1714750952, - "narHash": "sha256-oOUdvPrO8CbupgDSaPou+Jv6GL+uQA2QlE33D7OLzkM=", + "lastModified": 1651369430, + "narHash": "sha256-d86uUm0s11exU9zLo2K1AwtJQJDKubFpoF0Iw767uT4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5fd8536a9a5932d4ae8de52b7dc08d92041237fc", + "rev": "b283b64580d1872333a99af2b4cef91bb84580cf", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 9cf7396..4196042 100644 --- a/flake.nix +++ b/flake.nix @@ -4,15 +4,24 @@ 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 = [ + buildInputs = [ just zig - zls - ]; - buildInputs = [ - gtk4 + + xorg.libX11 + xorg.libXcursor + xorg.libXi + xorg.libXext + xorg.libXrandr + xorg.libXinerama + libGL + libGLU ]; }; }; diff --git a/justfile b/justfile index 112626b..acbc9ed 100644 --- a/justfile +++ b/justfile @@ -1,7 +1,2 @@ -alias b := build -build: - zig build - -alias r := run run: - zig build run + nixGL zig build run diff --git a/src/main.zig b/src/main.zig index fd613fb..9b4a4bc 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,61 +1,40 @@ const std = @import("std"); -const capy = @import("capy"); +const r = @import("raylib.zig"); -// This is required for your app to build to WebAssembly and other particular architectures -pub usingnamespace capy.cross_platform; +pub fn main() anyerror!void { + r.InitWindow(800, 450, "doggo"); + defer r.CloseWindow(); -pub fn main() !void { - try capy.backend.init(); + // var selected_filename: [512]u8 = undefined; + var file_dialog_state = r.InitGuiFileDialog(420, 310, r.GetWorkingDirectory(), false); - var window = try capy.Window.init(); - try window.set( - capy.label(.{ .text = "Hello, World", .alignment = .Center }), - ); + while (!r.WindowShouldClose()) { + // Update + if (file_dialog_state.SelectFilePressed) { + std.log.info("{s} / {s}", .{ file_dialog_state.dirPathText, file_dialog_state.fileNameText }); + } - window.setTitle("Hello"); - window.setPreferredSize(250, 100); - window.show(); + // Draw + r.BeginDrawing(); + defer r.EndDrawing(); - capy.runEventLoop(); + 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); + } } -// const std = @import("std"); -// const r = @import("raylib.zig"); - -// pub fn main() anyerror!void { -// r.InitWindow(800, 450, "doggo"); -// defer r.CloseWindow(); - -// // var selected_filename: [512]u8 = undefined; -// var file_dialog_state = r.InitGuiWindowFileDialog(r.GetWorkingDirectory()); - -// while (!r.WindowShouldClose()) { -// // Update -// if (file_dialog_state.SelectFilePressed) { -// std.log.info("{s} / {s}", .{ file_dialog_state.dirPathText, file_dialog_state.fileNameText }); -// } - -// // Draw -// r.BeginDrawing(); -// defer r.EndDrawing(); - -// r.ClearBackground(r.RAYWHITE); -// r.DrawText("Congrats! You created your first window!", 190, 200, 20, r.LIGHTGRAY); - -// if (file_dialog_state.windowActive) { -// r.GuiLock(); -// } - -// if (r.GuiButton(r.Rectangle{ .x = 190, .y = 250, .width = 150, .height = 30 }, "Button") == 1) { -// std.log.info("Button pressed", .{}); -// file_dialog_state.windowActive = true; -// } -// r.GuiUnlock(); - -// r.GuiWindowFileDialog(&file_dialog_state); -// } -// } - -// test "basic test" { -// try std.testing.expectEqual(10, 3 + 7); -// } +test "basic test" { + try std.testing.expectEqual(10, 3 + 7); +} diff --git a/src/raylib.c b/src/raylib.c new file mode 100644 index 0000000..0dec298 --- /dev/null +++ b/src/raylib.c @@ -0,0 +1,6 @@ +#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 new file mode 100644 index 0000000..78660e4 --- /dev/null +++ b/src/raylib.zig @@ -0,0 +1,5 @@ +pub usingnamespace @cImport({ + @cInclude("raylib.h"); + @cInclude("raygui.h"); + @cInclude("custom_file_dialog/gui_file_dialog.h"); +});