Skip to content

Commit 6d7e96e

Browse files
authored
Enable the use of sysgpu alongside Dawn (#44)
* 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
1 parent 619b441 commit 6d7e96e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+2596
-80902
lines changed

.vscode/tasks.json

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
}
2727
},
2828
{
29-
"label": "Build and Run Project",
29+
"label": "Build and Run Project (dawn)",
3030
"type": "shell",
3131
"command": "zig build run",
3232
"group": {
@@ -38,9 +38,9 @@
3838
}
3939
},
4040
{
41-
"label": "Build and Run Project (release-fast)",
41+
"label": "Build and Run Project (sysgpu)",
4242
"type": "shell",
43-
"command": "zig build run -Doptimize=ReleaseFast",
43+
"command": "zig build run -Duse_sysgpu=true",
4444
"group": {
4545
"kind": "build",
4646
"isDefault": true
@@ -50,9 +50,9 @@
5050
}
5151
},
5252
{
53-
"label": "Build and Run Project (release-small)",
53+
"label": "Build and Run Project (sysgpu/release-fast)",
5454
"type": "shell",
55-
"command": "zig build run -Doptimize=ReleaseSmall",
55+
"command": "zig build run -Doptimize=ReleaseFast -Duse_sysgpu=true",
5656
"group": {
5757
"kind": "build",
5858
"isDefault": true
@@ -62,9 +62,21 @@
6262
}
6363
},
6464
{
65-
"label": "Build and Run Project (release-safe)",
65+
"label": "Build and Run Project (sysgpu/release-small)",
6666
"type": "shell",
67-
"command": "zig build run -Doptimize=ReleaseSafe",
67+
"command": "zig build run -Doptimize=ReleaseSmall -Duse_sysgpu=true",
68+
"group": {
69+
"kind": "build",
70+
"isDefault": true
71+
},
72+
"presentation": {
73+
"clear": true
74+
}
75+
},
76+
{
77+
"label": "Build and Run Project (sysgpu/release-safe)",
78+
"type": "shell",
79+
"command": "zig build run -Doptimize=ReleaseSafe -Duse_sysgpu=true",
6880
"group": {
6981
"kind": "build",
7082
"isDefault": true

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Colton Franklin
3+
Copyright (c) 2024 Colton Franklin
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

assets/cursors/eraser32.png

-375 Bytes
Binary file not shown.

assets/cursors/eraser64.png

-535 Bytes
Binary file not shown.

assets/cursors/pencil32.png

-389 Bytes
Binary file not shown.

assets/cursors/pencil64.png

-533 Bytes
Binary file not shown.

assets/fonts/ProggyTiny.ttf

-34.8 KB
Binary file not shown.

assets/fox_1024.png

-7.07 KB
Binary file not shown.

assets/icon_1024.png

-7.19 KB
Binary file not shown.

assets/pixi.atlas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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}]}

assets/pixi.png

4.14 KB
Loading

assets/src/cursors.pixi

5.59 KB
Binary file not shown.

assets/src/misc.pixi

5.35 KB
Binary file not shown.

assets/themes/pixi_dark.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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]}}
1+
{"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]}}

build.zig

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const builtin = @import("builtin");
33

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

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

27-
const zgui_pkg = zgui.Package(.{
28-
.gpu_dawn = mach_gpu_dawn,
29-
}).build(b, target, optimize, .{
30-
.options = .{
31-
.backend = .mach,
32-
},
33-
.gpu_dawn_options = .{},
34-
}) catch unreachable;
26+
const use_sysgpu = b.option(bool, "use_sysgpu", "Use sysgpu") orelse false;
27+
const use_freetype = b.option(bool, "use_freetype", "Use freetype") orelse false;
3528

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

3831
const mach_core_dep = b.dependency("mach_core", .{
3932
.target = target,
4033
.optimize = optimize,
4134
});
35+
36+
const zig_imgui_dep = b.dependency("zig_imgui", .{});
37+
38+
const imgui_module = b.addModule("zig-imgui", .{
39+
.source_file = zig_imgui_dep.path("src/imgui.zig"),
40+
.dependencies = &.{
41+
.{ .name = "mach-core", .module = mach_core_dep.module("mach-core") },
42+
},
43+
});
44+
45+
const imgui_lib = b.addStaticLibrary(.{
46+
.name = "imgui",
47+
.root_source_file = zig_imgui_dep.path("src/cimgui.cpp"),
48+
.target = target,
49+
.optimize = optimize,
50+
});
51+
imgui_lib.linkLibC();
52+
53+
const imgui_dep = b.dependency("imgui", .{});
54+
55+
var imgui_files = std.ArrayList([]const u8).init(b.allocator);
56+
defer imgui_files.deinit();
57+
58+
var imgui_flags = std.ArrayList([]const u8).init(b.allocator);
59+
defer imgui_flags.deinit();
60+
61+
try imgui_files.appendSlice(&.{
62+
imgui_dep.path("imgui.cpp").getPath(b),
63+
imgui_dep.path("imgui_widgets.cpp").getPath(b),
64+
imgui_dep.path("imgui_tables.cpp").getPath(b),
65+
imgui_dep.path("imgui_draw.cpp").getPath(b),
66+
imgui_dep.path("imgui_demo.cpp").getPath(b),
67+
});
68+
69+
if (use_freetype) {
70+
try imgui_flags.append("-DIMGUI_ENABLE_FREETYPE");
71+
try imgui_files.append("imgui/misc/freetype/imgui_freetype.cpp");
72+
73+
imgui_lib.linkLibrary(b.dependency("freetype", .{
74+
.target = target,
75+
.optimize = optimize,
76+
}).artifact("freetype"));
77+
}
78+
79+
imgui_lib.addIncludePath(imgui_dep.path("."));
80+
imgui_lib.addCSourceFiles(.{
81+
.files = imgui_files.items,
82+
.flags = imgui_flags.items,
83+
});
84+
85+
b.installArtifact(imgui_lib);
86+
87+
const build_options = b.addOptions();
88+
build_options.addOption(bool, "use_sysgpu", use_sysgpu);
89+
4290
const app = try mach_core.App.init(b, mach_core_dep.builder, .{
4391
.name = "pixi",
4492
.src = src_path,
4593
.target = target,
4694
.deps = &[_]std.build.ModuleDependency{
4795
.{ .name = "zstbi", .module = zstbi_pkg.zstbi },
4896
.{ .name = "zmath", .module = zmath_pkg.zmath },
49-
.{ .name = "zgui", .module = zgui_pkg.zgui },
5097
.{ .name = "nfd", .module = nfd.getModule(b) },
5198
.{ .name = "zip", .module = zip_pkg.module },
99+
.{ .name = "zig-imgui", .module = imgui_module },
100+
.{ .name = "build-options", .module = build_options.createModule() },
52101
},
53102
.optimize = optimize,
54103
});
55104

105+
if (use_sysgpu) {
106+
const mach_sysgpu_dep = b.dependency("mach_sysgpu", .{
107+
.target = target,
108+
.optimize = optimize,
109+
});
110+
111+
app.compile.linkLibrary(mach_sysgpu_dep.artifact("mach-dusk"));
112+
@import("mach_sysgpu").link(mach_sysgpu_dep.builder, app.compile);
113+
}
114+
56115
const install_step = b.step("pixi", "Install pixi");
57116
install_step.dependOn(&app.install.step);
58117
b.getInstallStep().dependOn(install_step);
@@ -67,7 +126,6 @@ pub fn build(b: *std.Build) !void {
67126
});
68127

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

79137
app.compile.addModule("zstbi", zstbi_pkg.zstbi);
80-
app.compile.addModule("zgui", zgui_pkg.zgui);
81138
app.compile.addModule("zmath", zmath_pkg.zmath);
82139
app.compile.addModule("nfd", nfd.getModule(b));
83140
app.compile.addModule("zip", zip_pkg.module);
141+
app.compile.addModule("zig-imgui", imgui_module);
84142

85143
const nfd_lib = nfd.makeLib(b, target, optimize);
86144
if (nfd_lib.target_info.target.os.tag == .macos) {
@@ -91,13 +149,14 @@ pub fn build(b: *std.Build) !void {
91149
xcode_frameworks.addPaths(nfd_lib);
92150
}
93151
app.compile.linkLibrary(nfd_lib);
152+
app.compile.linkLibrary(imgui_lib);
94153
zstbi_pkg.link(app.compile);
95-
zgui_pkg.link(app.compile);
96154
zip.link(app.compile);
97155

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

102161
const install_content_step = b.addInstallDirectory(.{
103162
.source_dir = .{ .path = thisDir() ++ "/" ++ content_dir },

build.zig.zon

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
.version = "0.0.1",
1313
.dependencies = .{
1414
.mach_core = .{
15-
.url = "https://pkg.machengine.org/mach-core/331ce61cb8c075be6d7c46e49da8ccbd5967d9b7.tar.gz",
16-
.hash = "12203bdeb8af9b1da2a521beafb51e3657e1c4f49b058cdd114f607b75dbb95ad306",
15+
.url = "https://pkg.machengine.org/mach-core/90c927e20d045035152d9b0b421ea45db7e5569c.tar.gz",
16+
.hash = "12209c255c69822b57cd8906754bbee815e69678741d48a64e945168e611874da662",
1717
},
1818
.mach_gpu_dawn = .{
1919
.url = "https://pkg.machengine.org/mach-gpu-dawn/ee2fb5066a774238a97ab18dc5620acce538d2e6.tar.gz",
@@ -27,5 +27,21 @@
2727
.url = "https://pkg.machengine.org/xcode-frameworks/e77a5c6809a0d3f62ec549ee56e9d2dc6807cd5b.tar.gz",
2828
.hash = "12202044ed9fd69af156b0afde619ffd1d111554c557f57ab670ca9960e76d60d0b8",
2929
},
30+
.mach_sysgpu = .{
31+
.url = "https://pkg.machengine.org/mach-sysgpu/ee8abd31daefa617832c590d61c1e1d665a5e55a.tar.gz",
32+
.hash = "1220d0bf732d8291b8629ce7e115efb6adef84dcc1218317ee0a89a6f1663153f2a9",
33+
},
34+
.imgui = .{
35+
.url = "https://github.com/ocornut/imgui/archive/refs/tags/v1.90.tar.gz",
36+
.hash = "12206ca5fe2c3d35964b3a1cd30c4ff4e1050852f0062db0dda122513dc9477d5115",
37+
},
38+
.freetype = .{
39+
.url = "https://pkg.machengine.org/freetype/fa33c2db730c0e888046e863b5550ddc3d24e739.tar.gz",
40+
.hash = "12206ed50a939287c717f76547baf24e54301de4500505c19f10965ef559619baf10",
41+
},
42+
.zig_imgui = .{
43+
.url = "https://github.com/foxnne/zig-imgui/archive/10521deafb3f745ac0611431bc2e256442d06cba.tar.gz",
44+
.hash = "1220cba50a09790cc799b5923b61f65425dd82959408efdc5c221a6801d5af4e4c89",
45+
},
3046
},
3147
}

src/Cursors.zig

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/Settings.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ explorer_width: f32 = 200.0,
7070
/// Width of the explorer grip.
7171
explorer_grip: f32 = 18.0,
7272

73+
/// Alignment of explorer separator titles
74+
explorer_title_align: f32 = 0.0,
75+
7376
/// Height of the flipbook window.
7477
flipbook_height: f32 = 0.3,
7578

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

140+
/// Drop shadow opacity
141+
shadow_opacity: f32 = 0.05,
142+
143+
/// Shadow length
144+
shadow_length: f32 = 10.0,
145+
137146
/// Currently applied theme name
138147
theme: [:0]const u8,
139148

src/animations.zig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This is a generated file, do not edit.
2+
const std = @import("std");
3+
const assets = @import("assets.zig");
4+
5+
pub var pencil_default = [_]usize {
6+
assets.pixi_atlas.pencil_0_default,
7+
};
8+
pub var eraser_default = [_]usize {
9+
assets.pixi_atlas.eraser_0_default,
10+
};
11+
pub var bucket_default = [_]usize {
12+
assets.pixi_atlas.bucket_0_default,
13+
};
14+
pub var dropper_default = [_]usize {
15+
assets.pixi_atlas.dropper_0_default,
16+
};
17+
pub var fox_default = [_]usize {
18+
assets.pixi_atlas.fox_0_default,
19+
};
20+
pub var logo_default = [_]usize {
21+
assets.pixi_atlas.logo_0_default,
22+
};

src/assets.zig

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,18 @@ pub const palettes = "assets/palettes/";
77

88
pub const themes = "assets/themes/";
99

10-
pub const fox_1024_png = struct {
11-
pub const path = "assets/fox_1024.png";
12-
};
13-
14-
pub const icon_1024_png = struct {
15-
pub const path = "assets/icon_1024.png";
16-
};
17-
18-
pub const eraser64_png = struct {
19-
pub const path = "assets/cursors/eraser64.png";
20-
};
21-
22-
pub const pencil64_png = struct {
23-
pub const path = "assets/cursors/pencil64.png";
24-
};
25-
26-
pub const eraser32_png = struct {
27-
pub const path = "assets/cursors/eraser32.png";
28-
};
29-
30-
pub const pencil32_png = struct {
31-
pub const path = "assets/cursors/pencil32.png";
10+
pub const pixi_atlas = struct {
11+
pub const path = "assets/pixi.atlas";
12+
pub const pencil_0_default = 0;
13+
pub const eraser_0_default = 1;
14+
pub const bucket_0_default = 2;
15+
pub const dropper_0_default = 3;
16+
pub const fox_0_default = 4;
17+
pub const logo_0_default = 5;
18+
};
19+
20+
pub const pixi_png = struct {
21+
pub const path = "assets/pixi.png";
3222
};
3323

3424
pub const pear36_hex = struct {

0 commit comments

Comments
 (0)