Skip to content

Commit

Permalink
Enable the use of sysgpu alongside Dawn (#44)
Browse files Browse the repository at this point in the history
* sysgpu: Initial attempt, currently only renders demo window with styling

* imgui: Begin switching to generated imgui bindings

* imgui: Continue swapping to generated bindings.

* imgui: Continue swapping over to generated bindings

* imgui: Continue swapping to generated bindings

* imgui: Continue swapping to generated bindings

* imgui: Continue swapping to generated bindings

* imgui: Continue swapping to generated bindings

* imgui: Continue swapping to generated bindings, file load functional

* imgui: Continue swapping to generated bindings. All windows now functional.

* imgui: Fix some memory leaks related to fonts on close

* cursors: Fix oversized cursor

* infobar: Small fixes, wrong axis

* menu: Fix crash on dropdown

* explorer: tweak separator color

* explorer: Add some help texts when no file or folder is open.

* theme: Automatically set new theme on export

* misc: Small bugfixes and cleanups

* build: Cleanup sysgpu steps and remove zgui files

* imgui: Remove zgui reference

* style: Tweaks to styles and spacing

* style: small style and spacing tweaks

* misc: Clean up cursors and add warning for files to contain .pixi in file_setup

* misc: Remove all individual asset images in favor of packed atlas

* cursors: Show dropper cursor when selecting color

* explorer: Finally fix explorer grip and explorer styling

* misc: Fix bug with non-deferred free, and fix horizontal grip

* menu: Fix grip position

* artboard: Reduce size of shadows

* art: Separate cursors and misc

* imgui: Update to 1.90 bindings, fixes unsaved indicator placement

* imgui: Remove unnecessary files

* zig-imgui: Use package manager

* theme: Slightly darker background color on pixi_dark theme

* theme: Various small polish of colors and hover/active colors

* grips: Highlight when hovered or active

* flipbook_menu: Full height grip

* explorer/menu: Change some colors

* License: Update

* flipbook: Refine scrolling animations

* flipbook: Fix drawing on new flipbook animations
  • Loading branch information
foxnne authored Jan 17, 2024
1 parent 619b441 commit 6d7e96e
Show file tree
Hide file tree
Showing 94 changed files with 2,596 additions and 80,902 deletions.
26 changes: 19 additions & 7 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
},
{
"label": "Build and Run Project",
"label": "Build and Run Project (dawn)",
"type": "shell",
"command": "zig build run",
"group": {
Expand All @@ -38,9 +38,9 @@
}
},
{
"label": "Build and Run Project (release-fast)",
"label": "Build and Run Project (sysgpu)",
"type": "shell",
"command": "zig build run -Doptimize=ReleaseFast",
"command": "zig build run -Duse_sysgpu=true",
"group": {
"kind": "build",
"isDefault": true
Expand All @@ -50,9 +50,9 @@
}
},
{
"label": "Build and Run Project (release-small)",
"label": "Build and Run Project (sysgpu/release-fast)",
"type": "shell",
"command": "zig build run -Doptimize=ReleaseSmall",
"command": "zig build run -Doptimize=ReleaseFast -Duse_sysgpu=true",
"group": {
"kind": "build",
"isDefault": true
Expand All @@ -62,9 +62,21 @@
}
},
{
"label": "Build and Run Project (release-safe)",
"label": "Build and Run Project (sysgpu/release-small)",
"type": "shell",
"command": "zig build run -Doptimize=ReleaseSafe",
"command": "zig build run -Doptimize=ReleaseSmall -Duse_sysgpu=true",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"clear": true
}
},
{
"label": "Build and Run Project (sysgpu/release-safe)",
"type": "shell",
"command": "zig build run -Doptimize=ReleaseSafe -Duse_sysgpu=true",
"group": {
"kind": "build",
"isDefault": true
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Colton Franklin
Copyright (c) 2024 Colton Franklin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Binary file removed assets/cursors/eraser32.png
Binary file not shown.
Binary file removed assets/cursors/eraser64.png
Binary file not shown.
Binary file removed assets/cursors/pencil32.png
Binary file not shown.
Binary file removed assets/cursors/pencil64.png
Binary file not shown.
Binary file removed assets/fonts/ProggyTiny.ttf
Binary file not shown.
Binary file removed assets/fox_1024.png
Binary file not shown.
Binary file removed assets/icon_1024.png
Binary file not shown.
1 change: 1 addition & 0 deletions assets/pixi.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"sprites":[{"name":"pencil_0_default","source":[0,0,22,23],"origin":[0,22]},{"name":"eraser_0_default","source":[22,0,22,23],"origin":[0,22]},{"name":"bucket_0_default","source":[96,0,15,19],"origin":[0,13]},{"name":"dropper_0_default","source":[44,0,21,22],"origin":[0,21]},{"name":"fox_0_default","source":[65,0,31,19],"origin":[5,20]},{"name":"logo_0_default","source":[111,0,3,6],"origin":[-10,13]}],"animations":[{"name":"pencil_default","start":0,"length":1,"fps":1},{"name":"eraser_default","start":1,"length":1,"fps":1},{"name":"bucket_default","start":2,"length":1,"fps":1},{"name":"dropper_default","start":3,"length":1,"fps":1},{"name":"fox_default","start":4,"length":1,"fps":1},{"name":"logo_default","start":5,"length":1,"fps":1}]}
Binary file added assets/pixi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/src/cursors.pixi
Binary file not shown.
Binary file added assets/src/misc.pixi
Binary file not shown.
2 changes: 1 addition & 1 deletion assets/themes/pixi_dark.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"pixi_dark.json","background":{"value":[1.5294118225574493e-01,1.568627506494522e-01,1.8431372940540314e-01,1.0e+00]},"foreground":{"value":[1.6470588743686676e-01,1.725490242242813e-01,2.1176470816135406e-01,1.0e+00]},"text":{"value":[9.019607901573181e-01,6.86274528503418e-01,5.372549295425415e-01,1.0e+00]},"text_secondary":{"value":[6.217507719993591e-01,6.217508316040039e-01,6.89373254776001e-01,1.0e+00]},"text_background":{"value":[3.803131878376007e-01,3.803131878376007e-01,4.1416895389556885e-01,1.0e+00]},"text_blue":{"value":[4.313725531101227e-01,5.882353186607361e-01,7.843137383460999e-01,1.0e+00]},"text_orange":{"value":[7.176470756530762e-01,4.431372582912445e-01,3.764705955982208e-01,1.0e+00]},"text_yellow":{"value":[8.392156958580017e-01,7.803921699523926e-01,5.098039507865906e-01,1.0e+00]},"text_red":{"value":[8.078431487083435e-01,4.7058823704719543e-01,4.117647111415863e-01,1.0e+00]},"highlight_primary":{"value":[1.8431372940540314e-01,7.019608020782471e-01,5.29411792755127e-01,1.0e+00]},"hover_primary":{"value":[2.980392277240753e-01,5.803921818733215e-01,4.8235294222831726e-01,1.0e+00]},"highlight_secondary":{"value":[2.980392277240753e-01,1.882352977991104e-01,2.6274511218070984e-01,1.0e+00]},"hover_secondary":{"value":[4.117647111415863e-01,1.9607843458652496e-01,2.666666805744171e-01,1.0e+00]},"checkerboard_primary":{"value":[5.882353186607361e-01,5.882353186607361e-01,5.882353186607361e-01,1.0e+00]},"checkerboard_secondary":{"value":[2.1568627655506134e-01,2.1568627655506134e-01,2.1568627655506134e-01,1.0e+00]},"modal_dim":{"value":[0.0e+00,0.0e+00,0.0e+00,1.882352977991104e-01]}}
{"name":"pixi_dark.json","background":{"value":[1.3333334028720856e-01,1.3725490868091583e-01,1.6470588743686676e-01,1.0e+00]},"foreground":{"value":[1.6470588743686676e-01,1.725490242242813e-01,2.1176470816135406e-01,1.0e+00]},"text":{"value":[9.019607901573181e-01,6.86274528503418e-01,5.372549295425415e-01,1.0e+00]},"text_secondary":{"value":[6.217507719993591e-01,6.217508316040039e-01,6.89373254776001e-01,1.0e+00]},"text_background":{"value":[3.803131878376007e-01,3.803131878376007e-01,4.1416895389556885e-01,1.0e+00]},"text_blue":{"value":[4.313725531101227e-01,5.882353186607361e-01,7.843137383460999e-01,1.0e+00]},"text_orange":{"value":[7.176470756530762e-01,4.431372582912445e-01,3.764705955982208e-01,1.0e+00]},"text_yellow":{"value":[8.392156958580017e-01,7.803921699523926e-01,5.098039507865906e-01,1.0e+00]},"text_red":{"value":[8.078431487083435e-01,4.7058823704719543e-01,4.117647111415863e-01,1.0e+00]},"highlight_primary":{"value":[1.8431372940540314e-01,7.019608020782471e-01,5.29411792755127e-01,1.0e+00]},"hover_primary":{"value":[2.980392277240753e-01,5.803921818733215e-01,4.8235294222831726e-01,1.0e+00]},"highlight_secondary":{"value":[2.980392277240753e-01,1.882352977991104e-01,2.6274511218070984e-01,1.0e+00]},"hover_secondary":{"value":[4.117647111415863e-01,1.9607843458652496e-01,2.666666805744171e-01,1.0e+00]},"checkerboard_primary":{"value":[5.882353186607361e-01,5.882353186607361e-01,5.882353186607361e-01,1.0e+00]},"checkerboard_secondary":{"value":[2.1568627655506134e-01,2.1568627655506134e-01,2.1568627655506134e-01,1.0e+00]},"modal_dim":{"value":[0.0e+00,0.0e+00,0.0e+00,1.882352977991104e-01]}}
87 changes: 73 additions & 14 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const builtin = @import("builtin");

const zmath = @import("src/deps/zig-gamedev/zmath/build.zig");
const zstbi = @import("src/deps/zig-gamedev/zstbi/build.zig");
const zgui = @import("src/deps/zig-gamedev/zgui/build.zig");

const mach_core = @import("mach_core");
const mach_gpu_dawn = @import("mach_gpu_dawn");
Expand All @@ -24,35 +23,95 @@ pub fn build(b: *std.Build) !void {
const zstbi_pkg = zstbi.package(b, target, optimize, .{});
const zmath_pkg = zmath.package(b, target, optimize, .{});

const zgui_pkg = zgui.Package(.{
.gpu_dawn = mach_gpu_dawn,
}).build(b, target, optimize, .{
.options = .{
.backend = .mach,
},
.gpu_dawn_options = .{},
}) catch unreachable;
const use_sysgpu = b.option(bool, "use_sysgpu", "Use sysgpu") orelse false;
const use_freetype = b.option(bool, "use_freetype", "Use freetype") orelse false;

const zip_pkg = zip.package(b, .{});

const mach_core_dep = b.dependency("mach_core", .{
.target = target,
.optimize = optimize,
});

const zig_imgui_dep = b.dependency("zig_imgui", .{});

const imgui_module = b.addModule("zig-imgui", .{
.source_file = zig_imgui_dep.path("src/imgui.zig"),
.dependencies = &.{
.{ .name = "mach-core", .module = mach_core_dep.module("mach-core") },
},
});

const imgui_lib = b.addStaticLibrary(.{
.name = "imgui",
.root_source_file = zig_imgui_dep.path("src/cimgui.cpp"),
.target = target,
.optimize = optimize,
});
imgui_lib.linkLibC();

const imgui_dep = b.dependency("imgui", .{});

var imgui_files = std.ArrayList([]const u8).init(b.allocator);
defer imgui_files.deinit();

var imgui_flags = std.ArrayList([]const u8).init(b.allocator);
defer imgui_flags.deinit();

try imgui_files.appendSlice(&.{
imgui_dep.path("imgui.cpp").getPath(b),
imgui_dep.path("imgui_widgets.cpp").getPath(b),
imgui_dep.path("imgui_tables.cpp").getPath(b),
imgui_dep.path("imgui_draw.cpp").getPath(b),
imgui_dep.path("imgui_demo.cpp").getPath(b),
});

if (use_freetype) {
try imgui_flags.append("-DIMGUI_ENABLE_FREETYPE");
try imgui_files.append("imgui/misc/freetype/imgui_freetype.cpp");

imgui_lib.linkLibrary(b.dependency("freetype", .{
.target = target,
.optimize = optimize,
}).artifact("freetype"));
}

imgui_lib.addIncludePath(imgui_dep.path("."));
imgui_lib.addCSourceFiles(.{
.files = imgui_files.items,
.flags = imgui_flags.items,
});

b.installArtifact(imgui_lib);

const build_options = b.addOptions();
build_options.addOption(bool, "use_sysgpu", use_sysgpu);

const app = try mach_core.App.init(b, mach_core_dep.builder, .{
.name = "pixi",
.src = src_path,
.target = target,
.deps = &[_]std.build.ModuleDependency{
.{ .name = "zstbi", .module = zstbi_pkg.zstbi },
.{ .name = "zmath", .module = zmath_pkg.zmath },
.{ .name = "zgui", .module = zgui_pkg.zgui },
.{ .name = "nfd", .module = nfd.getModule(b) },
.{ .name = "zip", .module = zip_pkg.module },
.{ .name = "zig-imgui", .module = imgui_module },
.{ .name = "build-options", .module = build_options.createModule() },
},
.optimize = optimize,
});

if (use_sysgpu) {
const mach_sysgpu_dep = b.dependency("mach_sysgpu", .{
.target = target,
.optimize = optimize,
});

app.compile.linkLibrary(mach_sysgpu_dep.artifact("mach-dusk"));
@import("mach_sysgpu").link(mach_sysgpu_dep.builder, app.compile);
}

const install_step = b.step("pixi", "Install pixi");
install_step.dependOn(&app.install.step);
b.getInstallStep().dependOn(install_step);
Expand All @@ -67,7 +126,6 @@ pub fn build(b: *std.Build) !void {
});

unit_tests.addModule("zstbi", zstbi_pkg.zstbi);
unit_tests.addModule("zgui", zgui_pkg.zgui);
unit_tests.addModule("zmath", zmath_pkg.zmath);
unit_tests.addModule("nfd", nfd.getModule(b));
unit_tests.addModule("zip", zip_pkg.module);
Expand All @@ -77,10 +135,10 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(&run_unit_tests.step);

app.compile.addModule("zstbi", zstbi_pkg.zstbi);
app.compile.addModule("zgui", zgui_pkg.zgui);
app.compile.addModule("zmath", zmath_pkg.zmath);
app.compile.addModule("nfd", nfd.getModule(b));
app.compile.addModule("zip", zip_pkg.module);
app.compile.addModule("zig-imgui", imgui_module);

const nfd_lib = nfd.makeLib(b, target, optimize);
if (nfd_lib.target_info.target.os.tag == .macos) {
Expand All @@ -91,13 +149,14 @@ pub fn build(b: *std.Build) !void {
xcode_frameworks.addPaths(nfd_lib);
}
app.compile.linkLibrary(nfd_lib);
app.compile.linkLibrary(imgui_lib);
zstbi_pkg.link(app.compile);
zgui_pkg.link(app.compile);
zip.link(app.compile);

const assets = ProcessAssetsStep.init(b, "assets", "src/assets.zig", "src/animations.zig");
const process_assets_step = b.step("process-assets", "generates struct for all assets");
var process_assets_step = b.step("process-assets", "generates struct for all assets");
process_assets_step.dependOn(&assets.step);
app.compile.step.dependOn(process_assets_step);

const install_content_step = b.addInstallDirectory(.{
.source_dir = .{ .path = thisDir() ++ "/" ++ content_dir },
Expand Down
20 changes: 18 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
.version = "0.0.1",
.dependencies = .{
.mach_core = .{
.url = "https://pkg.machengine.org/mach-core/331ce61cb8c075be6d7c46e49da8ccbd5967d9b7.tar.gz",
.hash = "12203bdeb8af9b1da2a521beafb51e3657e1c4f49b058cdd114f607b75dbb95ad306",
.url = "https://pkg.machengine.org/mach-core/90c927e20d045035152d9b0b421ea45db7e5569c.tar.gz",
.hash = "12209c255c69822b57cd8906754bbee815e69678741d48a64e945168e611874da662",
},
.mach_gpu_dawn = .{
.url = "https://pkg.machengine.org/mach-gpu-dawn/ee2fb5066a774238a97ab18dc5620acce538d2e6.tar.gz",
Expand All @@ -27,5 +27,21 @@
.url = "https://pkg.machengine.org/xcode-frameworks/e77a5c6809a0d3f62ec549ee56e9d2dc6807cd5b.tar.gz",
.hash = "12202044ed9fd69af156b0afde619ffd1d111554c557f57ab670ca9960e76d60d0b8",
},
.mach_sysgpu = .{
.url = "https://pkg.machengine.org/mach-sysgpu/ee8abd31daefa617832c590d61c1e1d665a5e55a.tar.gz",
.hash = "1220d0bf732d8291b8629ce7e115efb6adef84dcc1218317ee0a89a6f1663153f2a9",
},
.imgui = .{
.url = "https://github.com/ocornut/imgui/archive/refs/tags/v1.90.tar.gz",
.hash = "12206ca5fe2c3d35964b3a1cd30c4ff4e1050852f0062db0dda122513dc9477d5115",
},
.freetype = .{
.url = "https://pkg.machengine.org/freetype/fa33c2db730c0e888046e863b5550ddc3d24e739.tar.gz",
.hash = "12206ed50a939287c717f76547baf24e54301de4500505c19f10965ef559619baf10",
},
.zig_imgui = .{
.url = "https://github.com/foxnne/zig-imgui/archive/10521deafb3f745ac0611431bc2e256442d06cba.tar.gz",
.hash = "1220cba50a09790cc799b5923b61f65425dd82959408efdc5c221a6801d5af4e4c89",
},
},
}
41 changes: 0 additions & 41 deletions src/Cursors.zig

This file was deleted.

9 changes: 9 additions & 0 deletions src/Settings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ explorer_width: f32 = 200.0,
/// Width of the explorer grip.
explorer_grip: f32 = 18.0,

/// Alignment of explorer separator titles
explorer_title_align: f32 = 0.0,

/// Height of the flipbook window.
flipbook_height: f32 = 0.3,

Expand Down Expand Up @@ -134,6 +137,12 @@ eyedropper_auto_switch_layer: bool = true,
/// Width and height of the eyedropper preview
eyedropper_preview_size: f32 = 64.0,

/// Drop shadow opacity
shadow_opacity: f32 = 0.05,

/// Shadow length
shadow_length: f32 = 10.0,

/// Currently applied theme name
theme: [:0]const u8,

Expand Down
22 changes: 22 additions & 0 deletions src/animations.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This is a generated file, do not edit.
const std = @import("std");
const assets = @import("assets.zig");

pub var pencil_default = [_]usize {
assets.pixi_atlas.pencil_0_default,
};
pub var eraser_default = [_]usize {
assets.pixi_atlas.eraser_0_default,
};
pub var bucket_default = [_]usize {
assets.pixi_atlas.bucket_0_default,
};
pub var dropper_default = [_]usize {
assets.pixi_atlas.dropper_0_default,
};
pub var fox_default = [_]usize {
assets.pixi_atlas.fox_0_default,
};
pub var logo_default = [_]usize {
assets.pixi_atlas.logo_0_default,
};
34 changes: 12 additions & 22 deletions src/assets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,18 @@ pub const palettes = "assets/palettes/";

pub const themes = "assets/themes/";

pub const fox_1024_png = struct {
pub const path = "assets/fox_1024.png";
};

pub const icon_1024_png = struct {
pub const path = "assets/icon_1024.png";
};

pub const eraser64_png = struct {
pub const path = "assets/cursors/eraser64.png";
};

pub const pencil64_png = struct {
pub const path = "assets/cursors/pencil64.png";
};

pub const eraser32_png = struct {
pub const path = "assets/cursors/eraser32.png";
};

pub const pencil32_png = struct {
pub const path = "assets/cursors/pencil32.png";
pub const pixi_atlas = struct {
pub const path = "assets/pixi.atlas";
pub const pencil_0_default = 0;
pub const eraser_0_default = 1;
pub const bucket_0_default = 2;
pub const dropper_0_default = 3;
pub const fox_0_default = 4;
pub const logo_0_default = 5;
};

pub const pixi_png = struct {
pub const path = "assets/pixi.png";
};

pub const pear36_hex = struct {
Expand Down
Loading

0 comments on commit 6d7e96e

Please sign in to comment.