diff --git a/src/Pixi.zig b/src/Pixi.zig index 3c7ed57..86e2c9e 100644 --- a/src/Pixi.zig +++ b/src/Pixi.zig @@ -145,8 +145,6 @@ pub fn init(_app: *App, _core: *Core, app_mod: mach.Mod(App), _editor: *Editor) const path = std.fs.selfExeDirPath(buffer[0..]) catch "."; std.posix.chdir(path) catch {}; - std.log.debug("Root path: {s}", .{path}); - const window = try core.windows.new(.{ .title = "Pixi", .vsync_mode = .double, diff --git a/src/editor/Editor.zig b/src/editor/Editor.zig index 6d8bcdf..303b83c 100644 --- a/src/editor/Editor.zig +++ b/src/editor/Editor.zig @@ -10,6 +10,10 @@ const imgui = @import("zig-imgui"); const zmath = @import("zmath"); pub const Editor = @This(); +pub const Sidebar = @import("sidebar/Sidebar1.zig"); +pub const Explorer = @import("explorer/Explorer1.zig"); +pub const Artboard = @import("artboard/Artboard1.zig"); +pub const Popups = @import("popups/Popups.zig"); pub const mach_module = .editor; pub const mach_systems = .{ .init, .tick, .deinit }; @@ -18,21 +22,7 @@ pub const Theme = @import("Theme.zig"); theme: Theme, -pub const sidebar = @import("sidebar/sidebar.zig"); -pub const explorer = @import("explorer/explorer.zig"); -pub const artboard = @import("artboard/artboard.zig"); - -pub const popup_rename = @import("popups/rename.zig"); -pub const popup_file_setup = @import("popups/file_setup.zig"); -pub const popup_about = @import("popups/about.zig"); -pub const popup_file_confirm_close = @import("popups/file_confirm_close.zig"); -pub const popup_layer_setup = @import("popups/layer_setup.zig"); -pub const popup_export_to_png = @import("popups/export_png.zig"); -pub const popup_animation = @import("popups/animation.zig"); -pub const popup_heightmap = @import("popups/heightmap.zig"); -pub const popup_references = @import("popups/references.zig"); - -pub fn init(app: *Pixi, editor: *Editor) !void { +pub fn init(core: *Core, app: *Pixi, editor: *Editor) !void { const theme_path = try std.fs.path.joinZ(app.allocator, &.{ Pixi.assets.themes, app.settings.theme }); defer app.allocator.free(theme_path); @@ -40,29 +30,20 @@ pub fn init(app: *Pixi, editor: *Editor) !void { .theme = try Editor.Theme.loadFromFile(theme_path), }; - editor.theme.init(Pixi.core, app); + editor.theme.init(core, app); } -pub fn tick(app: *Pixi, core: *Core, editor: *Editor) !void { - imgui.pushStyleVarImVec2(imgui.StyleVar_SeparatorTextAlign, .{ .x = Pixi.app.settings.explorer_title_align, .y = 0.5 }); +pub fn tick(core: *Core, app: *Pixi, editor: *Editor) !void { + imgui.pushStyleVarImVec2(imgui.StyleVar_SeparatorTextAlign, .{ .x = app.settings.explorer_title_align, .y = 0.5 }); defer imgui.popStyleVar(); editor.theme.push(core, app); defer editor.theme.pop(); - try sidebar.draw(); - try explorer.draw(core); - try artboard.draw(core); - - try popup_rename.draw(); - try popup_file_setup.draw(); - try popup_about.draw(); - try popup_file_confirm_close.draw(); - try popup_layer_setup.draw(); - try popup_export_to_png.draw(); - try popup_animation.draw(); - try popup_heightmap.draw(); - try popup_references.draw(); + try Sidebar.draw(core, app); + try Explorer.draw(core, app); + try Artboard.draw(core, app); + try Popups.draw(core, app); } pub fn setProjectFolder(path: [:0]const u8) !void { diff --git a/src/editor/artboard/artboard.zig b/src/editor/artboard/Artboard1.zig similarity index 75% rename from src/editor/artboard/artboard.zig rename to src/editor/artboard/Artboard1.zig index 10028d2..6ba26b3 100644 --- a/src/editor/artboard/artboard.zig +++ b/src/editor/artboard/Artboard1.zig @@ -15,16 +15,16 @@ pub const infobar = @import("infobar.zig"); pub var artboard_0_open_file_index: usize = 0; pub var artboard_1_open_file_index: usize = 0; -pub fn draw(core: *Core) !void { +pub fn draw(core: *Core, app: *Pixi) !void { imgui.pushStyleVar(imgui.StyleVar_WindowRounding, 0.0); defer imgui.popStyleVar(); imgui.setNextWindowPos(.{ - .x = (Pixi.app.settings.sidebar_width + Pixi.app.settings.explorer_width + Pixi.app.settings.explorer_grip) * Pixi.app.content_scale[0], + .x = (app.settings.sidebar_width + app.settings.explorer_width + app.settings.explorer_grip) * app.content_scale[0], .y = 0.0, }, imgui.Cond_Always); imgui.setNextWindowSize(.{ - .x = (Pixi.app.window_size[0] - ((Pixi.app.settings.explorer_width + Pixi.app.settings.sidebar_width + Pixi.app.settings.explorer_grip)) * Pixi.app.content_scale[0]), - .y = (Pixi.app.window_size[1] + 5.0) * Pixi.app.content_scale[1], + .x = (app.window_size[0] - ((app.settings.explorer_width + app.settings.sidebar_width + app.settings.explorer_grip)) * app.content_scale[0]), + .y = (app.window_size[1] + 5.0) * app.content_scale[1], }, imgui.Cond_None); imgui.pushStyleVarImVec2(imgui.StyleVar_WindowPadding, .{ .x = 0.0, .y = 0.5 }); @@ -41,17 +41,17 @@ pub fn draw(core: *Core) !void { art_flags |= imgui.WindowFlags_NoBringToFrontOnFocus; if (imgui.begin("Art", null, art_flags)) { - try menu.draw(); + try menu.draw(app, core); const art_width = imgui.getWindowWidth(); const window_height = imgui.getContentRegionAvail().y; const window_width = imgui.getContentRegionAvail().x; - const artboard_height = if (Pixi.app.open_files.items.len > 0 and Pixi.app.sidebar != .pack) window_height - window_height * Pixi.app.settings.flipbook_height else 0.0; + const artboard_height = if (app.open_files.items.len > 0 and app.sidebar != .pack) window_height - window_height * app.settings.flipbook_height else 0.0; - const artboard_flipbook_ratio = (Pixi.app.mouse.position[1] - imgui.getCursorScreenPos().y) / window_height; + const artboard_flipbook_ratio = (app.mouse.position[1] - imgui.getCursorScreenPos().y) / window_height; - const split_index: usize = if (Pixi.app.settings.split_artboard) 3 else 1; + const split_index: usize = if (app.settings.split_artboard) 3 else 1; for (0..split_index) |artboard_index| { const artboard_0 = artboard_index == 0; @@ -60,17 +60,17 @@ pub fn draw(core: *Core) !void { var artboard_width: f32 = 0.0; - if (artboard_0 and Pixi.app.settings.split_artboard) { - artboard_width = window_width * Pixi.app.settings.split_artboard_ratio; + if (artboard_0 and app.settings.split_artboard) { + artboard_width = window_width * app.settings.split_artboard_ratio; } else if (artboard_grip) { - artboard_width = Pixi.app.settings.explorer_grip; + artboard_width = app.settings.explorer_grip; } else { artboard_width = 0.0; } - const not_active: bool = (artboard_0 and artboard_0_open_file_index != Pixi.app.open_file_index) or (!artboard_0 and !artboard_grip and artboard_1_open_file_index != Pixi.app.open_file_index); + const not_active: bool = (artboard_0 and artboard_0_open_file_index != app.open_file_index) or (!artboard_0 and !artboard_grip and artboard_1_open_file_index != app.open_file_index); - const artboard_color: Pixi.math.Color = if (artboard_grip or (not_active and Pixi.app.settings.split_artboard)) Pixi.editor.theme.foreground else Pixi.editor.theme.background; + const artboard_color: Pixi.math.Color = if (artboard_grip or (not_active and app.settings.split_artboard)) Pixi.editor.theme.foreground else Pixi.editor.theme.background; imgui.pushStyleColor(imgui.Col_ChildBg, artboard_color.toU32()); defer imgui.popStyleColor(); @@ -86,11 +86,11 @@ pub fn draw(core: *Core) !void { }, imgui.ChildFlags_None, imgui.WindowFlags_ChildWindow)) { if (!artboard_grip) { const window_hovered: bool = imgui.isWindowHovered(imgui.HoveredFlags_ChildWindows); - const mouse_clicked: bool = Pixi.app.mouse.anyButtonDown(); + const mouse_clicked: bool = app.mouse.anyButtonDown(); - if (Pixi.app.sidebar == .pack) { - drawCanvasPack(); - } else if (Pixi.app.open_files.items.len > 0) { + if (app.sidebar == .pack) { + drawCanvasPack(core, app); + } else if (app.open_files.items.len > 0) { var files_flags: imgui.TabBarFlags = 0; files_flags |= imgui.TabBarFlags_Reorderable; files_flags |= imgui.TabBarFlags_AutoSelectNewTabs; @@ -98,7 +98,7 @@ pub fn draw(core: *Core) !void { if (imgui.beginTabBar("FilesTabBar", files_flags)) { defer imgui.endTabBar(); - for (Pixi.app.open_files.items, 0..) |file, i| { + for (app.open_files.items, 0..) |file, i| { var open: bool = true; const file_name = std.fs.path.basename(file.path); @@ -106,8 +106,8 @@ pub fn draw(core: *Core) !void { imgui.pushIDInt(@as(c_int, @intCast(i))); defer imgui.popID(); - const label = try std.fmt.allocPrintZ(Pixi.app.allocator, " {s} {s} ", .{ Pixi.fa.file_powerpoint, file_name }); - defer Pixi.app.allocator.free(label); + const label = try std.fmt.allocPrintZ(app.allocator, " {s} {s} ", .{ Pixi.fa.file_powerpoint, file_name }); + defer app.allocator.free(label); var file_tab_flags: imgui.TabItemFlags = 0; file_tab_flags |= imgui.TabItemFlags_None; @@ -138,7 +138,7 @@ pub fn draw(core: *Core) !void { } if (imgui.isItemHovered(imgui.HoveredFlags_DelayNormal)) { - imgui.pushStyleVarImVec2(imgui.StyleVar_WindowPadding, .{ .x = 4.0 * Pixi.app.content_scale[0], .y = 4.0 * Pixi.app.content_scale[1] }); + imgui.pushStyleVarImVec2(imgui.StyleVar_WindowPadding, .{ .x = 4.0 * app.content_scale[0], .y = 4.0 * app.content_scale[1] }); defer imgui.popStyleVar(); if (imgui.beginTooltip()) { defer imgui.endTooltip(); @@ -147,7 +147,7 @@ pub fn draw(core: *Core) !void { } } - const show_rulers: bool = Pixi.app.settings.show_rulers; + const show_rulers: bool = app.settings.show_rulers; // Add ruler child windows to build layout, but wait to draw to them until camera has been updated. if (show_rulers) { @@ -178,7 +178,7 @@ pub fn draw(core: *Core) !void { Pixi.Editor.setActiveFile(open_file_index); } - if (!Pixi.app.settings.split_artboard) open_file_index = Pixi.app.open_file_index; + if (!app.settings.split_artboard) open_file_index = app.open_file_index; if (Pixi.Editor.getFile(open_file_index)) |file| { if (imgui.beginChild( @@ -187,30 +187,30 @@ pub fn draw(core: *Core) !void { imgui.ChildFlags_None, canvas_flags, )) { - try canvas.draw(file, core); + try canvas.draw(file, core, app); } imgui.endChild(); // Now add to ruler children windows, since we have updated the camera. if (show_rulers) { - try rulers.draw(file); + try rulers.draw(file, app, core); } } } } else { - try drawLogoScreen(); + try drawLogoScreen(app); } } else { - drawGrip(art_width); + drawGrip(art_width, app); } } imgui.endChild(); } - if (Pixi.app.sidebar != .pack) { - if (Pixi.app.open_files.items.len > 0) { - const flipbook_height = window_height - artboard_height - Pixi.app.settings.info_bar_height * Pixi.app.content_scale[1]; + if (app.sidebar != .pack) { + if (app.open_files.items.len > 0) { + const flipbook_height = window_height - artboard_height - app.settings.info_bar_height * app.content_scale[1]; var flipbook_flags: imgui.WindowFlags = 0; flipbook_flags |= imgui.WindowFlags_MenuBar; @@ -219,25 +219,25 @@ pub fn draw(core: *Core) !void { .x = 0.0, .y = flipbook_height, }, imgui.ChildFlags_None, flipbook_flags)) { - if (Pixi.Editor.getFile(Pixi.app.open_file_index)) |file| { - try flipbook.menu.draw(file, artboard_flipbook_ratio); - if (Pixi.app.sidebar == .keyframe_animations or file.flipbook_view == .timeline) { - try flipbook.timeline.draw(file); + if (Pixi.Editor.getFile(app.open_file_index)) |file| { + try flipbook.menu.draw(file, artboard_flipbook_ratio, app); + if (app.sidebar == .keyframe_animations or file.flipbook_view == .timeline) { + try flipbook.timeline.draw(file, core, app); } else { if (imgui.beginChild("FlipbookCanvas", .{ .x = 0.0, .y = 0.0 }, imgui.ChildFlags_None, imgui.WindowFlags_ChildWindow)) { defer imgui.endChild(); - try flipbook.canvas.draw(file); + try flipbook.canvas.draw(file, app); } } } } imgui.endChild(); - if (Pixi.app.project_folder != null or Pixi.app.open_files.items.len > 0) { + if (app.project_folder != null or app.open_files.items.len > 0) { imgui.pushStyleColorImVec4(imgui.Col_ChildBg, Pixi.editor.theme.highlight_primary.toImguiVec4()); defer imgui.popStyleColor(); if (imgui.beginChild("InfoBar", .{ .x = -1.0, .y = 0.0 }, imgui.ChildFlags_None, imgui.WindowFlags_ChildWindow)) { - infobar.draw(); + infobar.draw(app, core); } imgui.endChild(); } @@ -247,7 +247,7 @@ pub fn draw(core: *Core) !void { imgui.end(); } -pub fn drawLogoScreen() !void { +pub fn drawLogoScreen(app: *Pixi) !void { imgui.pushStyleColorImVec4(imgui.Col_Button, Pixi.editor.theme.background.toImguiVec4()); imgui.pushStyleColorImVec4(imgui.Col_Border, Pixi.editor.theme.background.toImguiVec4()); imgui.pushStyleColorImVec4(imgui.Col_ButtonActive, Pixi.editor.theme.background.toImguiVec4()); @@ -255,7 +255,7 @@ pub fn drawLogoScreen() !void { imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text_background.toImguiVec4()); defer imgui.popStyleColorEx(5); { // Draw semi-transparent logo - const logo_sprite = Pixi.app.loaded_assets.atlas.sprites[Pixi.assets.pixi_atlas.logo_0_default]; + const logo_sprite = app.loaded_assets.atlas.sprites[Pixi.assets.pixi_atlas.logo_0_default]; const src: [4]f32 = .{ @floatFromInt(logo_sprite.source[0]), @@ -264,17 +264,17 @@ pub fn drawLogoScreen() !void { @floatFromInt(logo_sprite.source[3]), }; - const w = src[2] * 32.0 * Pixi.app.content_scale[0]; - const h = src[3] * 32.0 * Pixi.app.content_scale[0]; + const w = src[2] * 32.0 * app.content_scale[0]; + const h = src[3] * 32.0 * app.content_scale[0]; const center: [2]f32 = .{ imgui.getWindowWidth() / 2.0, imgui.getWindowHeight() / 2.0 }; - const inv_w = 1.0 / @as(f32, @floatFromInt(Pixi.app.loaded_assets.atlas_png.image.width)); - const inv_h = 1.0 / @as(f32, @floatFromInt(Pixi.app.loaded_assets.atlas_png.image.height)); + const inv_w = 1.0 / @as(f32, @floatFromInt(app.loaded_assets.atlas_png.image.width)); + const inv_h = 1.0 / @as(f32, @floatFromInt(app.loaded_assets.atlas_png.image.height)); imgui.setCursorPosX(center[0] - w / 2.0); imgui.setCursorPosY(center[1] - h / 2.0); imgui.imageEx( - Pixi.app.loaded_assets.atlas_png.view_handle, + app.loaded_assets.atlas_png.view_handle, .{ .x = w, .y = h }, .{ .x = src[0] * inv_w, .y = src[1] * inv_h }, .{ .x = (src[0] + src[2]) * inv_w, .y = (src[1] + src[3]) * inv_h }, @@ -288,22 +288,22 @@ pub fn drawLogoScreen() !void { const size = imgui.calcTextSize(text); imgui.setCursorPosX((imgui.getWindowWidth() / 2.0) - size.x / 2.0); if (imgui.buttonEx(text, .{ .x = size.x, .y = 0.0 })) { - Pixi.app.popups.file_dialog_request = .{ + app.popups.file_dialog_request = .{ .state = .folder, .type = .project, }; } - if (Pixi.app.popups.file_dialog_response) |response| { + if (app.popups.file_dialog_response) |response| { if (response.type == .project) { try Pixi.Editor.setProjectFolder(response.path); nfd.freePath(response.path); - Pixi.app.popups.file_dialog_response = null; + app.popups.file_dialog_response = null; } } } } -pub fn drawGrip(window_width: f32) void { +pub fn drawGrip(window_width: f32, app: *Pixi) void { imgui.setCursorPosY(0.0); imgui.setCursorPosX(0.0); @@ -313,7 +313,7 @@ pub fn drawGrip(window_width: f32) void { var color = Pixi.editor.theme.text_background.toImguiVec4(); _ = imgui.invisibleButton("ArtboardGripButton", .{ - .x = Pixi.app.settings.explorer_grip, + .x = app.settings.explorer_grip, .y = -1.0, }, imgui.ButtonFlags_None); @@ -326,31 +326,31 @@ pub fn drawGrip(window_width: f32) void { color = Pixi.editor.theme.text.toImguiVec4(); if (imgui.isMouseDoubleClicked(imgui.MouseButton_Left)) { - Pixi.app.settings.split_artboard = !Pixi.app.settings.split_artboard; + app.settings.split_artboard = !app.settings.split_artboard; } } if (imgui.isItemActive()) { color = Pixi.editor.theme.text.toImguiVec4(); - const prev = Pixi.app.mouse.previous_position; - const cur = Pixi.app.mouse.position; + const prev = app.mouse.previous_position; + const cur = app.mouse.position; const diff = (cur[0] - prev[0]) / window_width; imgui.setMouseCursor(imgui.MouseCursor_ResizeEW); - Pixi.app.settings.split_artboard_ratio = std.math.clamp( - Pixi.app.settings.split_artboard_ratio + diff, + app.settings.split_artboard_ratio = std.math.clamp( + app.settings.split_artboard_ratio + diff, 0.1, 0.9, ); } imgui.setCursorPosY(curs_y + avail / 2.0); - imgui.setCursorPosX(Pixi.app.settings.explorer_grip / 2.0 - imgui.calcTextSize(Pixi.fa.grip_lines_vertical).x / 2.0); + imgui.setCursorPosX(app.settings.explorer_grip / 2.0 - imgui.calcTextSize(Pixi.fa.grip_lines_vertical).x / 2.0); imgui.textColored(color, Pixi.fa.grip_lines_vertical); } -pub fn drawCanvasPack() void { +pub fn drawCanvasPack(core: *Core, app: *Pixi) void { var packed_textures_flags: imgui.TabBarFlags = 0; packed_textures_flags |= imgui.TabBarFlags_Reorderable; @@ -363,7 +363,7 @@ pub fn drawCanvasPack() void { imgui.TabItemFlags_None, )) { defer imgui.endTabItem(); - canvas_pack.draw(.diffusemap); + canvas_pack.draw(.diffusemap, app, core); } if (imgui.beginTabItem( @@ -372,7 +372,7 @@ pub fn drawCanvasPack() void { imgui.TabItemFlags_None, )) { defer imgui.endTabItem(); - canvas_pack.draw(.heightmap); + canvas_pack.draw(.heightmap, app, core); } } } diff --git a/src/editor/artboard/canvas.zig b/src/editor/artboard/canvas.zig index 7034c7e..7c135ab 100644 --- a/src/editor/artboard/canvas.zig +++ b/src/editor/artboard/canvas.zig @@ -4,11 +4,11 @@ const Core = @import("mach").Core; const imgui = @import("zig-imgui"); const zmath = @import("zmath"); -pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { +pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core, app: *Pixi) !void { const transforming = file.transform_texture != null; { - const shadow_color = Pixi.math.Color.initFloats(0.0, 0.0, 0.0, Pixi.app.settings.shadow_opacity).toU32(); + const shadow_color = Pixi.math.Color.initFloats(0.0, 0.0, 0.0, app.settings.shadow_opacity).toU32(); // Draw a shadow fading from bottom to top const pos = imgui.getWindowPos(); const height = imgui.getWindowHeight(); @@ -16,7 +16,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { if (imgui.getWindowDrawList()) |draw_list| { draw_list.addRectFilledMultiColor( - .{ .x = pos.x, .y = (pos.y + height) - Pixi.app.settings.shadow_length * Pixi.app.content_scale[1] }, + .{ .x = pos.x, .y = (pos.y + height) - app.settings.shadow_length * app.content_scale[1] }, .{ .x = pos.x + width, .y = pos.y + height }, 0x0, 0x0, @@ -67,11 +67,11 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { imgui.text("Transformation"); imgui.separator(); - if (imgui.button("Confirm") or (core.keyPressed(Core.Key.enter) and Pixi.app.open_file_index == Pixi.Editor.getFileIndex(file.path).?)) { + if (imgui.button("Confirm") or (core.keyPressed(Core.Key.enter) and app.open_file_index == Pixi.Editor.getFileIndex(file.path).?)) { transform_texture.confirm = true; } imgui.sameLine(); - if (imgui.button("Cancel") or (core.keyPressed(Core.Key.escape) and Pixi.app.open_file_index == Pixi.Editor.getFileIndex(file.path).?)) { + if (imgui.button("Cancel") or (core.keyPressed(Core.Key.escape) and app.open_file_index == Pixi.Editor.getFileIndex(file.path).?)) { var change = try file.buffers.stroke.toChange(@intCast(file.selected_layer_index)); change.pixels.temporary = true; try file.history.append(change); @@ -104,8 +104,8 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { //if (file.transform_texture == null) file.temporary_layer.clear(true); - Pixi.app.selection_time += Pixi.app.delta_time; - if (Pixi.app.selection_time >= 0.3) { + app.selection_time += app.delta_time; + if (app.selection_time >= 0.3) { for (file.selection_layer.pixels()) |*pixel| { if (pixel[3] != 0) { if (pixel[0] != 0) pixel[0] = 0 else pixel[0] = 255; @@ -113,13 +113,13 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { if (pixel[2] != 0) pixel[2] = 0 else pixel[2] = 255; } } - file.selection_layer.texture.update(Pixi.core.windows.get(Pixi.app.window, .device)); - Pixi.app.selection_time = 0.0; - Pixi.app.selection_invert = !Pixi.app.selection_invert; + file.selection_layer.texture.update(core.windows.get(app.window, .device)); + app.selection_time = 0.0; + app.selection_invert = !app.selection_invert; } if (imgui.isWindowHovered(imgui.HoveredFlags_None)) { - const mouse_position = Pixi.app.mouse.position; + const mouse_position = app.mouse.position; if (file.camera.pixelCoordinates(.{ .texture_position = canvas_center_offset, @@ -135,7 +135,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { const x = @as(f32, @floatFromInt(tile_column)) * tile_width + canvas_center_offset[0]; const y = @as(f32, @floatFromInt(tile_row)) * tile_height + canvas_center_offset[1]; - if (Pixi.app.sidebar != .pack) + if (app.sidebar != .pack) file.camera.drawTexture(file.background.view_handle, file.tile_width, file.tile_height, .{ x, y }, 0x88FFFFFF); try file.processStrokeTool(.primary, .{}); @@ -144,14 +144,14 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { try file.processSampleTool(.primary, .{}); try file.processSelectionTool(.primary, .{}); - if (Pixi.app.mouse.button(.primary)) |primary| { + if (app.mouse.button(.primary)) |primary| { if (primary.pressed()) { const tiles_wide = @divExact(@as(usize, @intCast(file.width)), @as(usize, @intCast(file.tile_width))); const tile_index = tile_column + tile_row * tiles_wide; - if (Pixi.app.sidebar == .sprites or file.flipbook_view == .timeline) { + if (app.sidebar == .sprites or file.flipbook_view == .timeline) { try file.makeSpriteSelection(tile_index); - } else if (Pixi.app.tools.current != .animation) { + } else if (app.tools.current != .animation) { // Ensure we only set the request state on the first set. if (file.flipbook_scroll_request) |*request| { request.elapsed = 0.0; @@ -164,9 +164,9 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { } } } else { - if (Pixi.app.mouse.button(.primary)) |primary| { + if (app.mouse.button(.primary)) |primary| { if (primary.released()) { - if (Pixi.app.sidebar == .sprites or file.flipbook_view == .timeline) { + if (app.sidebar == .sprites or file.flipbook_view == .timeline) { file.selected_sprites.clearAndFree(); } } @@ -190,9 +190,9 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { zmath.orthographicLh(width, height, -100, 100), ) }; - try Pixi.app.batcher.begin(.{ - .pipeline_handle = Pixi.app.pipeline_default, - .compute_pipeline_handle = Pixi.app.pipeline_compute, + try app.batcher.begin(.{ + .pipeline_handle = app.pipeline_default, + .compute_pipeline_handle = app.pipeline_compute, .bind_group_handle = transform_bindgroup, .compute_bind_group_handle = compute_bindgroup, .output_texture = &file.temporary_layer.texture, @@ -211,7 +211,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { } //pivot += zmath.loadArr2(.{ canvas_center_offset[0], canvas_center_offset[1] }); - try Pixi.app.batcher.transformTexture( + try app.batcher.transformTexture( transform_texture.vertices, .{ canvas_center_offset[0], -canvas_center_offset[1] }, .{ pivot[0], -pivot[1] }, @@ -220,7 +220,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { }, ); - try Pixi.app.batcher.end(uniforms, Pixi.app.uniform_buffer_default); + try app.batcher.end(uniforms, app.uniform_buffer_default); } } } @@ -255,7 +255,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { } } - if (Pixi.app.tools.current == .selection) { + if (app.tools.current == .selection) { file.camera.drawLayer(file.selection_layer, canvas_center_offset); } @@ -265,14 +265,14 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { if (file.camera.zoom >= 30.0) { if (file.camera.pixelCoordinates(.{ .texture_position = canvas_center_offset, - .position = Pixi.app.mouse.position, + .position = app.mouse.position, .width = file.width, .height = file.height, })) |pixel_coord| { const temp_x = @as(usize, @intFromFloat(pixel_coord[0])); const temp_y = @as(usize, @intFromFloat(pixel_coord[1])); const position = .{ pixel_coord[0] + canvas_center_offset[0] + 0.2, pixel_coord[1] + canvas_center_offset[1] + 0.25 }; - try file.camera.drawText("{d}", .{Pixi.app.colors.height}, position, 0xFFFFFFFF); + try file.camera.drawText("{d}", .{app.colors.height}, position, 0xFFFFFFFF); const min: [2]u32 = .{ @intCast(@max(@as(i32, @intCast(temp_x)) - 5, 0)), @@ -305,7 +305,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { { const tiles_wide = @divExact(file.width, file.tile_width); - if (Pixi.app.sidebar == .sprites and !transforming or file.flipbook_view == .timeline) { + if (app.sidebar == .sprites and !transforming or file.flipbook_view == .timeline) { if (file.selected_sprites.items.len > 0) { for (file.selected_sprites.items) |sprite_index| { const column = @mod(@as(u32, @intCast(sprite_index)), tiles_wide); @@ -332,7 +332,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { ); } } - } else if (Pixi.app.sidebar != .pack and !transforming) { + } else if (app.sidebar != .pack and !transforming) { const column = @mod(@as(u32, @intCast(file.selected_sprite_index)), tiles_wide); const row = @divTrunc(@as(u32, @intCast(file.selected_sprite_index)), tiles_wide); const x = @as(f32, @floatFromInt(column)) * tile_width + canvas_center_offset[0]; @@ -342,17 +342,17 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { file.camera.drawRect(rect, 3.0, Pixi.editor.theme.text.toU32()); } - if (Pixi.app.popups.animation_length > 0 and Pixi.app.tools.current == .animation and !transforming) { - if (Pixi.app.mouse.button(.primary)) |primary| { - if (primary.down() or Pixi.app.popups.animation) { - const start_column = @mod(@as(u32, @intCast(Pixi.app.popups.animation_start)), tiles_wide); - const start_row = @divTrunc(@as(u32, @intCast(Pixi.app.popups.animation_start)), tiles_wide); + if (app.popups.animation_length > 0 and app.tools.current == .animation and !transforming) { + if (app.mouse.button(.primary)) |primary| { + if (primary.down() or app.popups.animation) { + const start_column = @mod(@as(u32, @intCast(app.popups.animation_start)), tiles_wide); + const start_row = @divTrunc(@as(u32, @intCast(app.popups.animation_start)), tiles_wide); const start_x = @as(f32, @floatFromInt(start_column)) * tile_width + canvas_center_offset[0]; const start_y = @as(f32, @floatFromInt(start_row)) * tile_height + canvas_center_offset[1]; const start_rect: [4]f32 = .{ start_x, start_y, tile_width, tile_height }; - const end_column = @mod(@as(u32, @intCast(Pixi.app.popups.animation_start + Pixi.app.popups.animation_length - 1)), tiles_wide); - const end_row = @divTrunc(@as(u32, @intCast(Pixi.app.popups.animation_start + Pixi.app.popups.animation_length - 1)), tiles_wide); + const end_column = @mod(@as(u32, @intCast(app.popups.animation_start + app.popups.animation_length - 1)), tiles_wide); + const end_row = @divTrunc(@as(u32, @intCast(app.popups.animation_start + app.popups.animation_length - 1)), tiles_wide); const end_x = @as(f32, @floatFromInt(end_column)) * tile_width + canvas_center_offset[0]; const end_y = @as(f32, @floatFromInt(end_row)) * tile_height + canvas_center_offset[1]; const end_rect: [4]f32 = .{ end_x, end_y, tile_width, tile_height }; @@ -363,7 +363,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { } if (file.animations.slice().len > 0) { - if (Pixi.app.tools.current == .animation and !transforming) { + if (app.tools.current == .animation and !transforming) { var i: usize = 0; while (i < file.animations.slice().len) : (i += 1) { const animation = &file.animations.slice().get(i); @@ -379,10 +379,10 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core) !void { const end_y = @as(f32, @floatFromInt(end_row)) * tile_height + canvas_center_offset[1]; const end_rect: [4]f32 = .{ end_x, end_y, tile_width, tile_height }; - const thickness: f32 = if (i == file.selected_animation_index and (if (Pixi.app.mouse.button(.primary)) |primary| primary.up() else false and !Pixi.app.popups.animation)) 4.0 else 2.0; + const thickness: f32 = if (i == file.selected_animation_index and (if (app.mouse.button(.primary)) |primary| primary.up() else false and !app.popups.animation)) 4.0 else 2.0; file.camera.drawAnimationRect(start_rect, end_rect, thickness, Pixi.editor.theme.highlight_primary.toU32(), Pixi.editor.theme.text_red.toU32()); } - } else if (Pixi.app.sidebar != .pack and !transforming and Pixi.app.sidebar != .keyframe_animations) { + } else if (app.sidebar != .pack and !transforming and app.sidebar != .keyframe_animations) { const animation = file.animations.slice().get(file.selected_animation_index); const start_column = @mod(@as(u32, @intCast(animation.start)), tiles_wide); diff --git a/src/editor/artboard/canvas_pack.zig b/src/editor/artboard/canvas_pack.zig index 4cd1d02..7749059 100644 --- a/src/editor/artboard/canvas_pack.zig +++ b/src/editor/artboard/canvas_pack.zig @@ -1,6 +1,6 @@ const std = @import("std"); const Pixi = @import("../../Pixi.zig"); -const core = @import("mach").core; +const Core = @import("mach").Core; const imgui = @import("zig-imgui"); pub const PackTexture = enum { @@ -8,10 +8,10 @@ pub const PackTexture = enum { heightmap, }; -pub fn draw(mode: PackTexture) void { +pub fn draw(mode: PackTexture, app: *Pixi, _: *Core) void { if (switch (mode) { - .diffusemap => Pixi.app.atlas.diffusemap, - .heightmap => Pixi.app.atlas.heightmap, + .diffusemap => app.atlas.diffusemap, + .heightmap => app.atlas.heightmap, }) |texture| { var canvas_flags: imgui.WindowFlags = 0; canvas_flags |= imgui.WindowFlags_HorizontalScrollbar; @@ -26,7 +26,7 @@ pub fn draw(mode: PackTexture) void { const file_width = @as(f32, @floatFromInt(texture.image.width)); const file_height = @as(f32, @floatFromInt(texture.image.height)); - var camera = &Pixi.app.packer.camera; + var camera = &app.packer.camera; // Handle zooming, panning and extents { diff --git a/src/editor/artboard/flipbook/canvas.zig b/src/editor/artboard/flipbook/canvas.zig index e1c9e98..82291fe 100644 --- a/src/editor/artboard/flipbook/canvas.zig +++ b/src/editor/artboard/flipbook/canvas.zig @@ -1,9 +1,9 @@ const std = @import("std"); const Pixi = @import("../../../Pixi.zig"); -const core = @import("mach").core; +const Core = @import("mach").Core; const imgui = @import("zig-imgui"); -pub fn draw(file: *Pixi.storage.Internal.PixiFile) !void { +pub fn draw(file: *Pixi.storage.Internal.PixiFile, app: *Pixi) !void { const window_height = imgui.getWindowHeight(); const tile_width = @as(f32, @floatFromInt(file.tile_width)); const tile_height = @as(f32, @floatFromInt(file.tile_height)); @@ -14,7 +14,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile) !void { if (file.flipbook_scroll_request) |*request| { if (request.elapsed < 0.5) { file.selected_animation_state = .pause; - request.elapsed += Pixi.app.delta_time; + request.elapsed += app.delta_time; file.flipbook_scroll = Pixi.math.ease(request.from, request.to, request.elapsed / 0.5, .ease_in_out); } else { file.flipbook_scroll = request.to; @@ -29,7 +29,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile) !void { .zoom = window_height / tile_height, }; - if (Pixi.app.settings.flipbook_view == .sequential) sprite_camera.setNearestZoomFloor() else sprite_camera.setNearZoomFloor(); + if (app.settings.flipbook_view == .sequential) sprite_camera.setNearestZoomFloor() else sprite_camera.setNearZoomFloor(); file.flipbook_camera.min_zoom = sprite_camera.zoom; file.flipbook_camera.processPanZoom(.flipbook); @@ -38,7 +38,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile) !void { // Handle playing animations and locking the current extents if (file.selected_animation_state == .play and file.animations.slice().len > 0) { const animation: Pixi.storage.Internal.Animation = file.animations.slice().get(file.selected_animation_index); - file.selected_animation_elapsed += Pixi.app.delta_time; + file.selected_animation_elapsed += app.delta_time; if (file.selected_animation_elapsed > 1.0 / @as(f32, @floatFromInt(animation.fps))) { file.selected_animation_elapsed = 0.0; @@ -52,7 +52,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile) !void { file.flipbook_scroll = file.flipbookScrollFromSpriteIndex(file.selected_sprite_index); } - switch (Pixi.app.settings.flipbook_view) { + switch (app.settings.flipbook_view) { .sequential => { // Draw all sprites sequentially const tiles_wide = @divExact(file.width, file.tile_width); @@ -131,7 +131,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile) !void { if (file.flipbook_camera.isHovered(dst_rect) and !imgui.isAnyItemHovered()) { if (sprite_index != file.selected_sprite_index) { file.flipbook_camera.drawQuad(dst_p1, dst_p2, dst_p3, dst_p4, Pixi.editor.theme.text.toU32(), 2.0); - if (if (Pixi.app.mouse.button(.primary)) |primary| primary.pressed() else false and file.selected_sprite_index != sprite_index) { + if (if (app.mouse.button(.primary)) |primary| primary.pressed() else false and file.selected_sprite_index != sprite_index) { file.flipbook_scroll_request = .{ .from = file.flipbook_scroll, .to = file.flipbookScrollFromSpriteIndex(sprite_index), .state = file.selected_animation_state }; } } else { diff --git a/src/editor/artboard/flipbook/menu.zig b/src/editor/artboard/flipbook/menu.zig index 7809886..39beae3 100644 --- a/src/editor/artboard/flipbook/menu.zig +++ b/src/editor/artboard/flipbook/menu.zig @@ -6,8 +6,8 @@ const imgui = @import("zig-imgui"); const History = Pixi.storage.Internal.PixiFile.History; -pub fn draw(file: *Pixi.storage.Internal.PixiFile, mouse_ratio: f32) !void { - imgui.pushStyleVarImVec2(imgui.StyleVar_WindowPadding, .{ .x = 10.0 * Pixi.app.content_scale[0], .y = 10.0 * Pixi.app.content_scale[1] }); +pub fn draw(file: *Pixi.storage.Internal.PixiFile, mouse_ratio: f32, app: *Pixi) !void { + imgui.pushStyleVarImVec2(imgui.StyleVar_WindowPadding, .{ .x = 10.0 * app.content_scale[0], .y = 10.0 * app.content_scale[1] }); defer imgui.popStyleVar(); imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text.toImguiVec4()); imgui.pushStyleColorImVec4(imgui.Col_PopupBg, Pixi.editor.theme.foreground.toImguiVec4()); @@ -32,7 +32,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, mouse_ratio: f32) !void { const animation = &file.animations.slice().get(file.selected_animation_index); { // Animation Selection - imgui.setNextItemWidth(imgui.calcTextSize(animation.name).x + 40 * Pixi.app.content_scale[0]); + imgui.setNextItemWidth(imgui.calcTextSize(animation.name).x + 40 * app.content_scale[0]); if (imgui.beginCombo("Animation ", animation.name, imgui.ComboFlags_HeightLargest)) { defer imgui.endCombo(); var animation_index: usize = 0; @@ -48,15 +48,15 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, mouse_ratio: f32) !void { { // Frame Selection const current_frame = if (file.selected_sprite_index > animation.start) file.selected_sprite_index - animation.start else 0; - const frame = try std.fmt.allocPrintZ(Pixi.app.allocator, "{d}/{d}", .{ current_frame + 1, animation.length }); - defer Pixi.app.allocator.free(frame); + const frame = try std.fmt.allocPrintZ(app.allocator, "{d}/{d}", .{ current_frame + 1, animation.length }); + defer app.allocator.free(frame); - imgui.setNextItemWidth(imgui.calcTextSize(frame).x + 40 * Pixi.app.content_scale[0]); + imgui.setNextItemWidth(imgui.calcTextSize(frame).x + 40 * app.content_scale[0]); if (imgui.beginCombo("Frame ", frame, imgui.ComboFlags_None)) { defer imgui.endCombo(); for (0..animation.length) |i| { - const other_frame = try std.fmt.allocPrintZ(Pixi.app.allocator, "{d}/{d}", .{ i + 1, animation.length }); - defer Pixi.app.allocator.free(other_frame); + const other_frame = try std.fmt.allocPrintZ(app.allocator, "{d}/{d}", .{ i + 1, animation.length }); + defer app.allocator.free(other_frame); if (imgui.selectableEx(other_frame, animation.start + i == file.selected_animation_index, imgui.SelectableFlags_None, .{ .x = 0.0, .y = 0.0 })) { file.flipbook_scroll_request = .{ .from = file.flipbook_scroll, .to = file.flipbookScrollFromSpriteIndex(animation.start + i), .state = file.selected_animation_state }; @@ -66,7 +66,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, mouse_ratio: f32) !void { } { // FPS Selection - imgui.setNextItemWidth(100 * Pixi.app.content_scale[0]); + imgui.setNextItemWidth(100 * app.content_scale[0]); var fps = @as(i32, @intCast(animation.fps)); var changed: bool = false; if (imgui.sliderInt( @@ -112,7 +112,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, mouse_ratio: f32) !void { const animation = &file.keyframe_animations.slice().get(file.selected_keyframe_animation_index); { // Animation Selection - imgui.setNextItemWidth(imgui.calcTextSize(animation.name).x + 40 * Pixi.app.content_scale[0]); + imgui.setNextItemWidth(imgui.calcTextSize(animation.name).x + 40 * app.content_scale[0]); if (imgui.beginCombo("Animation ", animation.name, imgui.ComboFlags_HeightLargest)) { defer imgui.endCombo(); var keyframe_animation_index: usize = 0; @@ -150,7 +150,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, mouse_ratio: f32) !void { if (imgui.isItemActive()) { color = Pixi.editor.theme.text.toImguiVec4(); imgui.setMouseCursor(imgui.MouseCursor_ResizeNS); - Pixi.app.settings.flipbook_height = std.math.clamp(1.0 - mouse_ratio, 0.25, 0.85); + app.settings.flipbook_height = std.math.clamp(1.0 - mouse_ratio, 0.25, 0.85); } imgui.setCursorPosX(cursor_x + (avail.x / 2.0)); diff --git a/src/editor/artboard/flipbook/timeline.zig b/src/editor/artboard/flipbook/timeline.zig index c190fc1..da00ac6 100644 --- a/src/editor/artboard/flipbook/timeline.zig +++ b/src/editor/artboard/flipbook/timeline.zig @@ -23,7 +23,7 @@ var ms_hovered: ?usize = null; var keyframe_dragging: ?u32 = null; var mouse_scroll_delta_y: f32 = 0.0; -pub fn draw(file: *Pixi.storage.Internal.PixiFile) !void { +pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core, app: *Pixi) !void { const window_height = imgui.getWindowHeight(); const window_width = imgui.getWindowWidth(); const tile_width = @as(f32, @floatFromInt(file.tile_width)); @@ -364,7 +364,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile) !void { // We are using a load on the gpu texture, so we need to clear this texture on the gpu after we are done @memset(file.keyframe_animation_texture.image.data, 0.0); - file.keyframe_animation_texture.update(Pixi.core.windows.get(Pixi.app.window, .device)); + file.keyframe_animation_texture.update(core.windows.get(app.window, .device)); } } } @@ -487,7 +487,7 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile) !void { // We are using a load on the gpu texture, so we need to clear this texture on the gpu after we are done @memset(file.keyframe_animation_texture.image.data, 0.0); - file.keyframe_animation_texture.update(Pixi.core.windows.get(Pixi.app.window, .device)); + file.keyframe_animation_texture.update(core.windows.get(app.window, .device)); } } } diff --git a/src/editor/artboard/infobar.zig b/src/editor/artboard/infobar.zig index 80a0713..9b0bfed 100644 --- a/src/editor/artboard/infobar.zig +++ b/src/editor/artboard/infobar.zig @@ -1,22 +1,22 @@ const std = @import("std"); const Pixi = @import("../../Pixi.zig"); -const core = @import("mach").core; +const Core = @import("mach").Core; const imgui = @import("zig-imgui"); const spacer: [:0]const u8 = " "; -pub fn draw() void { +pub fn draw(app: *Pixi, _: *Core) void { imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.foreground.toImguiVec4()); defer imgui.popStyleColor(); - const h = imgui.getTextLineHeightWithSpacing() + 6.0 * Pixi.app.content_scale[1]; + const h = imgui.getTextLineHeightWithSpacing() + 6.0 * app.content_scale[1]; const y = (imgui.getContentRegionAvail().y - h) / 2; - const spacing: f32 = 3.0 * Pixi.app.content_scale[0]; + const spacing: f32 = 3.0 * app.content_scale[0]; imgui.setCursorPosY(y); - imgui.setCursorPosX(5.0 * Pixi.app.content_scale[0]); + imgui.setCursorPosX(5.0 * app.content_scale[0]); - if (Pixi.app.project_folder) |path| { - imgui.setCursorPosY(y + 2.0 * Pixi.app.content_scale[1]); + if (app.project_folder) |path| { + imgui.setCursorPosY(y + 2.0 * app.content_scale[1]); imgui.textColored(Pixi.editor.theme.foreground.toImguiVec4(), Pixi.fa.folder_open); imgui.setCursorPosY(y); imgui.sameLineEx(0.0, spacing); @@ -27,7 +27,7 @@ pub fn draw() void { imgui.sameLine(); } - if (Pixi.Editor.getFile(Pixi.app.open_file_index)) |file| { + if (Pixi.Editor.getFile(app.open_file_index)) |file| { imgui.setCursorPosY(y + spacing); imgui.textColored(Pixi.editor.theme.foreground.toImguiVec4(), Pixi.fa.chess_board); imgui.setCursorPosY(y); diff --git a/src/editor/artboard/menu.zig b/src/editor/artboard/menu.zig index ae8b3d5..063dbd8 100644 --- a/src/editor/artboard/menu.zig +++ b/src/editor/artboard/menu.zig @@ -1,13 +1,14 @@ const std = @import("std"); const Pixi = @import("../../Pixi.zig"); +const Core = @import("mach").Core; const settings = Pixi.settings; const zstbi = @import("zstbi"); const nfd = @import("nfd"); const imgui = @import("zig-imgui"); -pub fn draw() !void { - imgui.pushStyleVarImVec2(imgui.StyleVar_WindowPadding, .{ .x = 10.0 * Pixi.app.content_scale[0], .y = 10.0 * Pixi.app.content_scale[1] }); - imgui.pushStyleVarImVec2(imgui.StyleVar_ItemSpacing, .{ .x = 6.0 * Pixi.app.content_scale[0], .y = 6.0 * Pixi.app.content_scale[1] }); +pub fn draw(app: *Pixi, _: *Core) !void { + imgui.pushStyleVarImVec2(imgui.StyleVar_WindowPadding, .{ .x = 10.0 * app.content_scale[0], .y = 10.0 * app.content_scale[1] }); + imgui.pushStyleVarImVec2(imgui.StyleVar_ItemSpacing, .{ .x = 6.0 * app.content_scale[0], .y = 6.0 * app.content_scale[1] }); defer imgui.popStyleVarEx(2); imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text_secondary.toImguiVec4()); imgui.pushStyleColorImVec4(imgui.Col_PopupBg, Pixi.editor.theme.foreground.toImguiVec4()); @@ -19,24 +20,24 @@ pub fn draw() !void { defer imgui.endMenuBar(); if (imgui.beginMenu("File")) { imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text.toImguiVec4()); - if (imgui.menuItemEx("Open Folder...", if (Pixi.app.hotkeys.hotkey(.{ .proc = .folder })) |hotkey| hotkey.shortcut else "", false, true)) { - Pixi.app.popups.file_dialog_request = .{ + if (imgui.menuItemEx("Open Folder...", if (app.hotkeys.hotkey(.{ .proc = .folder })) |hotkey| hotkey.shortcut else "", false, true)) { + app.popups.file_dialog_request = .{ .state = .folder, .type = .project, }; } - if (Pixi.app.popups.file_dialog_response) |response| { + if (app.popups.file_dialog_response) |response| { if (response.type == .project) { try Pixi.Editor.setProjectFolder(response.path); nfd.freePath(response.path); - Pixi.app.popups.file_dialog_response = null; + app.popups.file_dialog_response = null; } } if (imgui.beginMenu("Recents")) { defer imgui.endMenu(); - for (Pixi.app.recents.folders.items) |folder| { + for (app.recents.folders.items) |folder| { if (imgui.menuItem(folder)) { try Pixi.Editor.setProjectFolder(folder); } @@ -45,20 +46,20 @@ pub fn draw() !void { imgui.separator(); - const file = Pixi.Editor.getFile(Pixi.app.open_file_index); + const file = Pixi.Editor.getFile(app.open_file_index); if (imgui.menuItemEx( "Export as .png...", - if (Pixi.app.hotkeys.hotkey(.{ .proc = .export_png })) |hotkey| hotkey.shortcut else "", + if (app.hotkeys.hotkey(.{ .proc = .export_png })) |hotkey| hotkey.shortcut else "", false, file != null, )) { - Pixi.app.popups.export_to_png = true; + app.popups.export_to_png = true; } if (imgui.menuItemEx( "Save", - if (Pixi.app.hotkeys.hotkey(.{ .proc = .save })) |hotkey| hotkey.shortcut else "", + if (app.hotkeys.hotkey(.{ .proc = .save })) |hotkey| hotkey.shortcut else "", false, file != null and file.?.dirty(), )) { @@ -76,14 +77,14 @@ pub fn draw() !void { imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text.toImguiVec4()); defer imgui.popStyleColor(); - if (imgui.menuItemEx("Split Artboard", null, Pixi.app.settings.split_artboard, true)) { - Pixi.app.settings.split_artboard = !Pixi.app.settings.split_artboard; + if (imgui.menuItemEx("Split Artboard", null, app.settings.split_artboard, true)) { + app.settings.split_artboard = !app.settings.split_artboard; } if (imgui.beginMenu("Flipbook")) { defer imgui.endMenu(); - if (Pixi.Editor.getFile(Pixi.app.open_file_index)) |file| { + if (Pixi.Editor.getFile(app.open_file_index)) |file| { if (imgui.beginCombo("Flipbook View", switch (file.flipbook_view) { .canvas => "Canvas", .timeline => "Timeline", @@ -102,20 +103,20 @@ pub fn draw() !void { if (file.flipbook_view == .canvas) { if (imgui.beginMenu("Flipbook Canvas View")) { defer imgui.endMenu(); - if (imgui.menuItemEx("Sequential", null, Pixi.app.settings.flipbook_view == .sequential, true)) { - Pixi.app.settings.flipbook_view = .sequential; + if (imgui.menuItemEx("Sequential", null, app.settings.flipbook_view == .sequential, true)) { + app.settings.flipbook_view = .sequential; } - if (imgui.menuItemEx("Grid", null, Pixi.app.settings.flipbook_view == .grid, true)) { - Pixi.app.settings.flipbook_view = .grid; + if (imgui.menuItemEx("Grid", null, app.settings.flipbook_view == .grid, true)) { + app.settings.flipbook_view = .grid; } } } } } - if (imgui.menuItemEx("References", "r", Pixi.app.popups.references, true)) { - Pixi.app.popups.references = !Pixi.app.popups.references; + if (imgui.menuItemEx("References", "r", app.popups.references, true)) { + app.popups.references = !app.popups.references; } } if (imgui.beginMenu("Edit")) { @@ -124,10 +125,10 @@ pub fn draw() !void { imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text.toImguiVec4()); defer imgui.popStyleColor(); - if (Pixi.Editor.getFile(Pixi.app.open_file_index)) |file| { + if (Pixi.Editor.getFile(app.open_file_index)) |file| { if (imgui.menuItemEx( "Undo", - if (Pixi.app.hotkeys.hotkey(.{ .proc = .undo })) |hotkey| hotkey.shortcut else "", + if (app.hotkeys.hotkey(.{ .proc = .undo })) |hotkey| hotkey.shortcut else "", false, file.history.undo_stack.items.len > 0, )) @@ -135,7 +136,7 @@ pub fn draw() !void { if (imgui.menuItemEx( "Redo", - if (Pixi.app.hotkeys.hotkey(.{ .proc = .redo })) |hotkey| hotkey.shortcut else "", + if (app.hotkeys.hotkey(.{ .proc = .redo })) |hotkey| hotkey.shortcut else "", false, file.history.redo_stack.items.len > 0, )) @@ -148,7 +149,7 @@ pub fn draw() !void { imgui.endMenu(); } if (imgui.menuItem("About")) { - Pixi.app.popups.about = true; + app.popups.about = true; } } } diff --git a/src/editor/artboard/rulers.zig b/src/editor/artboard/rulers.zig index 5b8ac94..cf77083 100644 --- a/src/editor/artboard/rulers.zig +++ b/src/editor/artboard/rulers.zig @@ -1,9 +1,9 @@ const std = @import("std"); const Pixi = @import("../../Pixi.zig"); -const core = @import("mach").core; +const Core = @import("mach").Core; const imgui = @import("zig-imgui"); -pub fn draw(file: *Pixi.storage.Internal.PixiFile) !void { +pub fn draw(file: *Pixi.storage.Internal.PixiFile, app: *Pixi, _: *Core) !void { const file_width = @as(f32, @floatFromInt(file.width)); const file_height = @as(f32, @floatFromInt(file.height)); const tile_width = @as(f32, @floatFromInt(file.tile_width)); @@ -26,11 +26,11 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile) !void { while (i < @as(usize, @intCast(tiles_wide))) : (i += 1) { const offset = .{ (@as(f32, @floatFromInt(i)) * tile_width) * file.camera.zoom, 0.0 }; if (tile_width * file.camera.zoom > text_size.x * 4.0) { - const text = try std.fmt.allocPrintZ(Pixi.app.allocator, "{d}", .{i}); - defer Pixi.app.allocator.free(text); + const text = try std.fmt.allocPrintZ(app.allocator, "{d}", .{i}); + defer app.allocator.free(text); draw_list.addText( - .{ .x = tl[0] + offset[0] + (tile_width / 2.0 * file.camera.zoom) - (text_size.x / 2.0), .y = tl[1] + 4.0 * Pixi.app.content_scale[1] }, + .{ .x = tl[0] + offset[0] + (tile_width / 2.0 * file.camera.zoom) - (text_size.x / 2.0), .y = tl[1] + 4.0 * app.content_scale[1] }, Pixi.editor.theme.text_secondary.toU32(), text.ptr, ); @@ -63,8 +63,8 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile) !void { const offset = .{ 0.0, @as(f32, @floatFromInt(i)) * tile_height * file.camera.zoom }; if (tile_height * file.camera.zoom > text_size.x * 4.0) { - const text = try std.fmt.allocPrintZ(Pixi.app.allocator, "{d}", .{i}); - defer Pixi.app.allocator.free(text); + const text = try std.fmt.allocPrintZ(app.allocator, "{d}", .{i}); + defer app.allocator.free(text); draw_list.addText(.{ .x = tl[0], .y = tl[1] + offset[1] + (tile_height / 2.0 * file.camera.zoom) - (text_size.y / 2.0) }, Pixi.editor.theme.text_secondary.toU32(), text.ptr); } diff --git a/src/editor/explorer/explorer.zig b/src/editor/explorer/Explorer1.zig similarity index 70% rename from src/editor/explorer/explorer.zig rename to src/editor/explorer/Explorer1.zig index 0b25d1c..13d3d13 100644 --- a/src/editor/explorer/explorer.zig +++ b/src/editor/explorer/Explorer1.zig @@ -13,22 +13,22 @@ pub const keyframe_animations = @import("keyframe_animations.zig"); pub const pack = @import("pack.zig"); pub const settings = @import("settings.zig"); -pub fn draw(core: *Core) !void { +pub fn draw(core: *Core, app: *Pixi) !void { imgui.pushStyleVar(imgui.StyleVar_WindowRounding, 0.0); imgui.pushStyleVar(imgui.StyleVar_WindowBorderSize, 0.0); imgui.pushStyleVarImVec2(imgui.StyleVar_WindowPadding, .{ .x = 0.0, .y = 0.0 }); imgui.pushStyleColorImVec4(imgui.Col_WindowBg, Pixi.editor.theme.foreground.toImguiVec4()); defer imgui.popStyleColor(); - const explorer_width = Pixi.app.settings.explorer_width; + const explorer_width = app.settings.explorer_width; imgui.setNextWindowPos(.{ - .x = Pixi.app.settings.sidebar_width * Pixi.app.content_scale[0], + .x = app.settings.sidebar_width * app.content_scale[0], .y = 0, }, imgui.Cond_Always); imgui.setNextWindowSize(.{ - .x = explorer_width * Pixi.app.content_scale[0], - .y = Pixi.app.window_size[1], + .x = explorer_width * app.content_scale[0], + .y = app.window_size[1], }, imgui.Cond_None); var explorer_flags: imgui.WindowFlags = 0; @@ -44,20 +44,20 @@ pub fn draw(core: *Core) !void { defer imgui.end(); imgui.popStyleVarEx(3); - imgui.pushStyleVarImVec2(imgui.StyleVar_ItemSpacing, .{ .x = 4.0 * Pixi.app.content_scale[0], .y = 6.0 * Pixi.app.content_scale[1] }); - imgui.pushStyleVarImVec2(imgui.StyleVar_FramePadding, .{ .x = 0.0, .y = 8.0 * Pixi.app.content_scale[1] }); + imgui.pushStyleVarImVec2(imgui.StyleVar_ItemSpacing, .{ .x = 4.0 * app.content_scale[0], .y = 6.0 * app.content_scale[1] }); + imgui.pushStyleVarImVec2(imgui.StyleVar_FramePadding, .{ .x = 0.0, .y = 8.0 * app.content_scale[1] }); defer imgui.popStyleVarEx(2); imgui.pushStyleColorImVec4(imgui.Col_Separator, Pixi.editor.theme.text_background.toImguiVec4()); imgui.pushStyleColorImVec4(imgui.Col_Header, Pixi.editor.theme.foreground.toImguiVec4()); defer imgui.popStyleColorEx(2); - switch (Pixi.app.sidebar) { + switch (app.sidebar) { .files => { if (imgui.beginMenuBar()) { - if (Pixi.app.hotkeys.hotkey(.{ .sidebar = .files })) |hotkey| { - const title = try std.fmt.allocPrintZ(Pixi.app.allocator, "Explorer ({s})", .{hotkey.shortcut}); - defer Pixi.app.allocator.free(title); + if (app.hotkeys.hotkey(.{ .sidebar = .files })) |hotkey| { + const title = try std.fmt.allocPrintZ(app.allocator, "Explorer ({s})", .{hotkey.shortcut}); + defer app.allocator.free(title); imgui.separatorText(title); } else { @@ -71,9 +71,9 @@ pub fn draw(core: *Core) !void { }, .tools => { if (imgui.beginMenuBar()) { - if (Pixi.app.hotkeys.hotkey(.{ .sidebar = .tools })) |hotkey| { - const title = try std.fmt.allocPrintZ(Pixi.app.allocator, "Tools ({s})", .{hotkey.shortcut}); - defer Pixi.app.allocator.free(title); + if (app.hotkeys.hotkey(.{ .sidebar = .tools })) |hotkey| { + const title = try std.fmt.allocPrintZ(app.allocator, "Tools ({s})", .{hotkey.shortcut}); + defer app.allocator.free(title); imgui.separatorText(title); } else { @@ -88,9 +88,9 @@ pub fn draw(core: *Core) !void { }, .sprites => { if (imgui.beginMenuBar()) { - if (Pixi.app.hotkeys.hotkey(.{ .sidebar = .sprites })) |hotkey| { - const title = try std.fmt.allocPrintZ(Pixi.app.allocator, "Sprites ({s})", .{hotkey.shortcut}); - defer Pixi.app.allocator.free(title); + if (app.hotkeys.hotkey(.{ .sidebar = .sprites })) |hotkey| { + const title = try std.fmt.allocPrintZ(app.allocator, "Sprites ({s})", .{hotkey.shortcut}); + defer app.allocator.free(title); imgui.separatorText(title); } else { @@ -104,9 +104,9 @@ pub fn draw(core: *Core) !void { }, .animations => { if (imgui.beginMenuBar()) { - if (Pixi.app.hotkeys.hotkey(.{ .sidebar = .animations })) |hotkey| { - const title = try std.fmt.allocPrintZ(Pixi.app.allocator, "Animations ({s})", .{hotkey.shortcut}); - defer Pixi.app.allocator.free(title); + if (app.hotkeys.hotkey(.{ .sidebar = .animations })) |hotkey| { + const title = try std.fmt.allocPrintZ(app.allocator, "Animations ({s})", .{hotkey.shortcut}); + defer app.allocator.free(title); imgui.separatorText(title); } else { @@ -120,9 +120,9 @@ pub fn draw(core: *Core) !void { }, .keyframe_animations => { if (imgui.beginMenuBar()) { - if (Pixi.app.hotkeys.hotkey(.{ .sidebar = .keyframe_animations })) |hotkey| { - const title = try std.fmt.allocPrintZ(Pixi.app.allocator, "Keyframe Animations ({s})", .{hotkey.shortcut}); - defer Pixi.app.allocator.free(title); + if (app.hotkeys.hotkey(.{ .sidebar = .keyframe_animations })) |hotkey| { + const title = try std.fmt.allocPrintZ(app.allocator, "Keyframe Animations ({s})", .{hotkey.shortcut}); + defer app.allocator.free(title); imgui.separatorText(title); } else { @@ -136,9 +136,9 @@ pub fn draw(core: *Core) !void { }, .pack => { if (imgui.beginMenuBar()) { - if (Pixi.app.hotkeys.hotkey(.{ .sidebar = .pack })) |hotkey| { - const title = try std.fmt.allocPrintZ(Pixi.app.allocator, "Packing ({s})", .{hotkey.shortcut}); - defer Pixi.app.allocator.free(title); + if (app.hotkeys.hotkey(.{ .sidebar = .pack })) |hotkey| { + const title = try std.fmt.allocPrintZ(app.allocator, "Packing ({s})", .{hotkey.shortcut}); + defer app.allocator.free(title); imgui.separatorText(title); } else { @@ -148,13 +148,13 @@ pub fn draw(core: *Core) !void { } imgui.spacing(); imgui.spacing(); - try pack.draw(); + try pack.draw(core, app); }, .settings => { if (imgui.beginMenuBar()) { - if (Pixi.app.hotkeys.hotkey(.{ .sidebar = .settings })) |hotkey| { - const title = try std.fmt.allocPrintZ(Pixi.app.allocator, "Settings ({s})", .{hotkey.shortcut}); - defer Pixi.app.allocator.free(title); + if (app.hotkeys.hotkey(.{ .sidebar = .settings })) |hotkey| { + const title = try std.fmt.allocPrintZ(app.allocator, "Settings ({s})", .{hotkey.shortcut}); + defer app.allocator.free(title); imgui.separatorText(title); } else { @@ -178,12 +178,12 @@ pub fn draw(core: *Core) !void { defer imgui.popStyleColorEx(3); imgui.setNextWindowPos(.{ - .x = Pixi.app.settings.sidebar_width + explorer_width, + .x = app.settings.sidebar_width + explorer_width, .y = 0, }, imgui.Cond_Always); imgui.setNextWindowSize(.{ - .x = Pixi.app.settings.explorer_grip, - .y = Pixi.app.window_size[1], + .x = app.settings.explorer_grip, + .y = app.window_size[1], }, imgui.Cond_Always); var grip_flags: imgui.WindowFlags = 0; @@ -206,7 +206,7 @@ pub fn draw(core: *Core) !void { var color = Pixi.editor.theme.text_background.toImguiVec4(); _ = imgui.invisibleButton("GripButton", .{ - .x = Pixi.app.settings.explorer_grip, + .x = app.settings.explorer_grip, .y = -1.0, }, imgui.ButtonFlags_None); @@ -219,22 +219,22 @@ pub fn draw(core: *Core) !void { color = Pixi.editor.theme.text.toImguiVec4(); if (imgui.isMouseDoubleClicked(imgui.MouseButton_Left)) { - Pixi.app.settings.split_artboard = !Pixi.app.settings.split_artboard; + app.settings.split_artboard = !app.settings.split_artboard; } } if (imgui.isItemActive()) { color = Pixi.editor.theme.text.toImguiVec4(); - const prev = Pixi.app.mouse.previous_position; - const cur = Pixi.app.mouse.position; + const prev = app.mouse.previous_position; + const cur = app.mouse.position; const diff = cur[0] - prev[0]; imgui.setMouseCursor(imgui.MouseCursor_ResizeEW); - Pixi.app.settings.explorer_width = std.math.clamp( - Pixi.app.settings.explorer_width + diff, + app.settings.explorer_width = std.math.clamp( + app.settings.explorer_width + diff, 200, - Pixi.app.window_size[0] / 2.0 - Pixi.app.settings.sidebar_width, + app.window_size[0] / 2.0 - app.settings.sidebar_width, ); } diff --git a/src/editor/explorer/pack.zig b/src/editor/explorer/pack.zig index 480ea85..66d3c81 100644 --- a/src/editor/explorer/pack.zig +++ b/src/editor/explorer/pack.zig @@ -1,11 +1,11 @@ const std = @import("std"); const Pixi = @import("../../Pixi.zig"); -const core = @import("mach").core; +const Core = @import("mach").Core; const nfd = @import("nfd"); const imgui = @import("zig-imgui"); -pub fn draw() !void { - imgui.pushStyleVarImVec2(imgui.StyleVar_FramePadding, .{ .x = 6.0 * Pixi.app.content_scale[0], .y = 5.0 * Pixi.app.content_scale[1] }); +pub fn draw(_: *Core, app: *Pixi) !void { + imgui.pushStyleVarImVec2(imgui.StyleVar_FramePadding, .{ .x = 6.0 * app.content_scale[0], .y = 5.0 * app.content_scale[1] }); defer imgui.popStyleVar(); imgui.pushStyleColorImVec4(imgui.Col_Button, Pixi.editor.theme.highlight_secondary.toImguiVec4()); imgui.pushStyleColorImVec4(imgui.Col_ButtonActive, Pixi.editor.theme.highlight_secondary.toImguiVec4()); @@ -14,20 +14,20 @@ pub fn draw() !void { const window_size = imgui.getContentRegionAvail(); - switch (Pixi.app.packer.target) { + switch (app.packer.target) { .all_open => { - if (Pixi.app.open_files.items.len <= 1) { - Pixi.app.packer.target = .project; + if (app.open_files.items.len <= 1) { + app.packer.target = .project; } }, .single_open => { - if (Pixi.app.open_files.items.len == 0) - Pixi.app.packer.target = .project; + if (app.open_files.items.len == 0) + app.packer.target = .project; }, else => {}, } - const preview_text = switch (Pixi.app.packer.target) { + const preview_text = switch (app.packer.target) { .project => "Full Project", .all_open => "All Open Files", .single_open => "Current Open File", @@ -36,20 +36,20 @@ pub fn draw() !void { if (imgui.beginCombo("Files", preview_text.ptr, imgui.ComboFlags_None)) { defer imgui.endCombo(); if (imgui.menuItem("Full Project")) { - Pixi.app.packer.target = .project; + app.packer.target = .project; } { - const enabled = if (Pixi.Editor.getFile(Pixi.app.open_file_index)) |_| true else false; + const enabled = if (Pixi.Editor.getFile(app.open_file_index)) |_| true else false; if (imgui.menuItemEx("Current Open File", null, false, enabled)) { - Pixi.app.packer.target = .single_open; + app.packer.target = .single_open; } } { - const enabled = if (Pixi.app.open_files.items.len > 1) true else false; + const enabled = if (app.open_files.items.len > 1) true else false; if (imgui.menuItemEx("All Open Files", null, false, enabled)) { - Pixi.app.packer.target = .all_open; + app.packer.target = .all_open; } } } @@ -64,8 +64,8 @@ pub fn draw() !void { { var packable: bool = true; - if (Pixi.app.packer.target == .project and Pixi.app.project_folder == null) packable = false; - if (Pixi.app.packer.target == .all_open and Pixi.app.open_files.items.len <= 1) packable = false; + if (app.packer.target == .project and app.project_folder == null) packable = false; + if (app.packer.target == .all_open and app.open_files.items.len <= 1) packable = false; if (Pixi.Editor.saving()) { imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text_background.toImguiVec4()); defer imgui.popStyleColor(); @@ -76,23 +76,23 @@ pub fn draw() !void { if (!packable) imgui.beginDisabled(true); if (imgui.buttonEx("Pack", .{ .x = window_size.x, .y = 0.0 })) { - switch (Pixi.app.packer.target) { + switch (app.packer.target) { .project => { - if (Pixi.app.project_folder) |folder| { - try Pixi.Packer.recurseFiles(Pixi.app.allocator, folder); - try Pixi.app.packer.packAndClear(); + if (app.project_folder) |folder| { + try Pixi.Packer.recurseFiles(app.allocator, folder); + try app.packer.packAndClear(); } }, .all_open => { - for (Pixi.app.open_files.items) |*file| { - try Pixi.app.packer.append(file); + for (app.open_files.items) |*file| { + try app.packer.append(file); } - try Pixi.app.packer.packAndClear(); + try app.packer.packAndClear(); }, .single_open => { - if (Pixi.Editor.getFile(Pixi.app.open_file_index)) |file| { - try Pixi.app.packer.append(file); - try Pixi.app.packer.packAndClear(); + if (Pixi.Editor.getFile(app.open_file_index)) |file| { + try app.packer.append(file); + try app.packer.packAndClear(); } }, } @@ -100,63 +100,63 @@ pub fn draw() !void { if (!packable) imgui.endDisabled(); - if (Pixi.app.packer.target == .project and Pixi.app.project_folder == null) { + if (app.packer.target == .project and app.project_folder == null) { imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text_background.toImguiVec4()); defer imgui.popStyleColor(); imgui.textWrapped("Select a project folder to pack."); } - if (Pixi.app.atlas.external) |atlas| { + if (app.atlas.external) |atlas| { imgui.text("Atlas Details"); imgui.text("Sprites: %d", atlas.sprites.len); imgui.text("Animations: %d", atlas.animations.len); - if (Pixi.app.atlas.diffusemap) |diffusemap| { + if (app.atlas.diffusemap) |diffusemap| { imgui.text("Atlas size: %dx%d", diffusemap.image.width, diffusemap.image.height); } if (imgui.buttonEx("Export", .{ .x = window_size.x, .y = 0.0 })) { - Pixi.app.popups.file_dialog_request = .{ + app.popups.file_dialog_request = .{ .state = .save, .type = .export_atlas, }; } - if (Pixi.app.popups.file_dialog_response) |response| { + if (app.popups.file_dialog_response) |response| { if (response.type == .export_atlas) { - try Pixi.app.recents.appendExport(try Pixi.app.allocator.dupeZ(u8, response.path)); - try Pixi.app.recents.save(); - try Pixi.app.atlas.save(response.path); + try app.recents.appendExport(try app.allocator.dupeZ(u8, response.path)); + try app.recents.save(); + try app.atlas.save(response.path); nfd.freePath(response.path); - Pixi.app.popups.file_dialog_response = null; + app.popups.file_dialog_response = null; } } - if (Pixi.app.recents.exports.items.len > 0) { + if (app.recents.exports.items.len > 0) { if (imgui.buttonEx("Repeat Last Export", .{ .x = window_size.x, .y = 0.0 })) { - try Pixi.app.atlas.save(Pixi.app.recents.exports.getLast()); + try app.atlas.save(app.recents.exports.getLast()); } - imgui.textWrapped(Pixi.app.recents.exports.getLast()); + imgui.textWrapped(app.recents.exports.getLast()); imgui.spacing(); imgui.separatorText("Recents"); imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text_secondary.toImguiVec4()); defer imgui.popStyleColor(); if (imgui.beginChild("Recents", .{ - .x = imgui.getWindowWidth() - Pixi.app.settings.explorer_grip * Pixi.app.content_scale[0], + .x = imgui.getWindowWidth() - app.settings.explorer_grip * app.content_scale[0], .y = 0.0, }, imgui.ChildFlags_None, imgui.WindowFlags_ChildWindow)) { defer imgui.endChild(); - var i: usize = Pixi.app.recents.exports.items.len; + var i: usize = app.recents.exports.items.len; while (i > 0) { i -= 1; - const exp = Pixi.app.recents.exports.items[i]; - const label = try std.fmt.allocPrintZ(Pixi.app.allocator, "{s} {s}", .{ Pixi.fa.file_download, std.fs.path.basename(exp) }); - defer Pixi.app.allocator.free(label); + const exp = app.recents.exports.items[i]; + const label = try std.fmt.allocPrintZ(app.allocator, "{s} {s}", .{ Pixi.fa.file_download, std.fs.path.basename(exp) }); + defer app.allocator.free(label); if (imgui.selectable(label)) { - const exp_out = Pixi.app.recents.exports.swapRemove(i); - try Pixi.app.recents.appendExport(exp_out); + const exp_out = app.recents.exports.swapRemove(i); + try app.recents.appendExport(exp_out); } imgui.sameLineEx(0.0, 5.0 * Pixi.app.content_scale[0]); imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text_background.toImguiVec4()); diff --git a/src/editor/popups/Popups.zig b/src/editor/popups/Popups.zig index e0797c0..27ddda8 100644 --- a/src/editor/popups/Popups.zig +++ b/src/editor/popups/Popups.zig @@ -1,8 +1,19 @@ const std = @import("std"); const Popups = @This(); const Pixi = @import("../../Pixi.zig"); +const Core = @import("mach").Core; const zstbi = @import("zstbi"); +pub const popup_rename = @import("rename.zig"); +pub const popup_file_setup = @import("file_setup.zig"); +pub const popup_about = @import("about.zig"); +pub const popup_file_confirm_close = @import("file_confirm_close.zig"); +pub const popup_layer_setup = @import("layer_setup.zig"); +pub const popup_export_to_png = @import("export_png.zig"); +pub const popup_animation = @import("animation.zig"); +pub const popup_heightmap = @import("heightmap.zig"); +pub const popup_references = @import("references.zig"); + // Renaming rename: bool = false, rename_state: RenameState = .none, @@ -78,6 +89,22 @@ pub const FileDialogResponse = struct { type: UserPathType, }; +pub fn init(popups: *Popups) !void { + popups.* = .{}; +} + +pub fn draw(_: *Core, _: *Pixi) !void { + try popup_rename.draw(); + try popup_file_setup.draw(); + try popup_about.draw(); + try popup_file_confirm_close.draw(); + try popup_layer_setup.draw(); + try popup_export_to_png.draw(); + try popup_animation.draw(); + try popup_heightmap.draw(); + try popup_references.draw(); +} + pub fn anyPopupOpen(popups: *Popups) bool { return popups.rename or popups.file_setup or diff --git a/src/editor/sidebar/sidebar.zig b/src/editor/sidebar/Sidebar1.zig similarity index 67% rename from src/editor/sidebar/sidebar.zig rename to src/editor/sidebar/Sidebar1.zig index 48cb3b8..43f3138 100644 --- a/src/editor/sidebar/sidebar.zig +++ b/src/editor/sidebar/Sidebar1.zig @@ -1,8 +1,8 @@ const Pixi = @import("../../Pixi.zig"); -const core = @import("mach").core; +const Core = @import("mach").Core; const imgui = @import("zig-imgui"); -pub fn draw() !void { +pub fn draw(_: *Core, app: *Pixi) !void { imgui.pushStyleVar(imgui.StyleVar_WindowRounding, 0.0); defer imgui.popStyleVar(); imgui.setNextWindowPos(.{ @@ -10,8 +10,8 @@ pub fn draw() !void { .y = 0.0, }, imgui.Cond_Always); imgui.setNextWindowSize(.{ - .x = Pixi.app.settings.sidebar_width * Pixi.app.content_scale[0], - .y = Pixi.app.window_size[1], + .x = app.settings.sidebar_width * app.content_scale[0], + .y = app.window_size[1], }, imgui.Cond_None); imgui.pushStyleVarImVec2(imgui.StyleVar_SelectableTextAlign, .{ .x = 0.5, .y = 0.5 }); imgui.pushStyleColorImVec4(imgui.Col_Header, Pixi.editor.theme.foreground.toImguiVec4()); @@ -33,29 +33,29 @@ pub fn draw() !void { imgui.pushStyleColorImVec4(imgui.Col_HeaderActive, Pixi.editor.theme.foreground.toImguiVec4()); defer imgui.popStyleColorEx(2); - drawOption(.files, Pixi.fa.folder_open); - drawOption(.tools, Pixi.fa.pencil_alt); - drawOption(.sprites, Pixi.fa.th); - drawOption(.animations, Pixi.fa.play_circle); - drawOption(.keyframe_animations, Pixi.fa.key); - drawOption(.pack, Pixi.fa.box_open); - drawOption(.settings, Pixi.fa.cog); + drawOption(.files, Pixi.fa.folder_open, app); + drawOption(.tools, Pixi.fa.pencil_alt, app); + drawOption(.sprites, Pixi.fa.th, app); + drawOption(.animations, Pixi.fa.play_circle, app); + drawOption(.keyframe_animations, Pixi.fa.key, app); + drawOption(.pack, Pixi.fa.box_open, app); + drawOption(.settings, Pixi.fa.cog, app); } imgui.end(); } -fn drawOption(option: Pixi.Sidebar, icon: [:0]const u8) void { +fn drawOption(option: Pixi.Sidebar, icon: [:0]const u8, app: *Pixi) void { const position = imgui.getCursorPos(); - const selectable_width = (Pixi.app.settings.sidebar_width - 8) * Pixi.app.content_scale[0]; - const selectable_height = (Pixi.app.settings.sidebar_width - 8) * Pixi.app.content_scale[1]; + const selectable_width = (app.settings.sidebar_width - 8) * app.content_scale[0]; + const selectable_height = (app.settings.sidebar_width - 8) * app.content_scale[1]; imgui.dummy(.{ .x = selectable_width, .y = selectable_height, }); imgui.setCursorPos(position); - if (Pixi.app.sidebar == option) { + if (app.sidebar == option) { imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.highlight_primary.toImguiVec4()); } else if (imgui.isItemHovered(imgui.HoveredFlags_None)) { imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text.toImguiVec4()); @@ -64,10 +64,10 @@ fn drawOption(option: Pixi.Sidebar, icon: [:0]const u8) void { } const selectable_flags: imgui.SelectableFlags = imgui.SelectableFlags_DontClosePopups; - if (imgui.selectableEx(icon, Pixi.app.sidebar == option, selectable_flags, .{ .x = selectable_width, .y = selectable_height })) { - Pixi.app.sidebar = option; + if (imgui.selectableEx(icon, app.sidebar == option, selectable_flags, .{ .x = selectable_width, .y = selectable_height })) { + app.sidebar = option; if (option == .sprites) - Pixi.app.tools.set(.pointer); + app.tools.set(.pointer); } imgui.popStyleColor(); }