switch from raylib to capy
This commit is contained in:
parent
f5a5157e80
commit
b4202d4120
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
libraylib.a
|
6
.gitmodules
vendored
6
.gitmodules
vendored
|
@ -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
|
1
3rdparty/raygui
vendored
1
3rdparty/raygui
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit 865bb293764073c01e74314ef647464f1f10fd96
|
1
3rdparty/raylib
vendored
1
3rdparty/raylib
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit ca12ef48e9e9f4eae03b1ca43ec3eb0a78d63dd3
|
53
build.zig
53
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);
|
||||
|
|
19
build.zig.zon
Normal file
19
build.zig.zon
Normal file
|
@ -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",
|
||||
},
|
||||
},
|
||||
}
|
14
flake.nix
14
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
|
||||
];
|
||||
};
|
||||
};
|
||||
|
|
7
justfile
7
justfile
|
@ -1,2 +1,7 @@
|
|||
alias b := build
|
||||
build:
|
||||
zig build
|
||||
|
||||
alias r := run
|
||||
run:
|
||||
nixGL zig build run
|
||||
zig build run
|
||||
|
|
46
src/main.zig
46
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();
|
||||
}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
#define RAYGUI_IMPLEMENTATION
|
||||
#include <raygui.h>
|
||||
#undef RAYGUI_IMPLEMENTATION // Avoid including raygui implementation again
|
||||
|
||||
#define GUI_FILE_DIALOG_IMPLEMENTATION
|
||||
#include <custom_file_dialog/gui_file_dialog.h>
|
|
@ -1,5 +0,0 @@
|
|||
pub usingnamespace @cImport({
|
||||
@cInclude("raylib.h");
|
||||
@cInclude("raygui.h");
|
||||
@cInclude("custom_file_dialog/gui_file_dialog.h");
|
||||
});
|
Loading…
Reference in a new issue