diff --git a/src/Pixi.zig b/src/Pixi.zig index 86e2c9e..2508190 100644 --- a/src/Pixi.zig +++ b/src/Pixi.zig @@ -12,6 +12,7 @@ const imgui_mach = imgui.backends.mach; const Core = mach.Core; pub const App = @This(); pub const Editor = @import("editor/Editor.zig"); +pub const Popups = @import("editor/popups/Popups.zig"); // Global pointers pub var core: *Core = undefined; @@ -44,13 +45,11 @@ recents: Recents = undefined, previous_atlas_export: ?[:0]const u8 = null, open_files: std.ArrayList(storage.Internal.PixiFile) = undefined, open_references: std.ArrayList(storage.Internal.Reference) = undefined, -packer: Packer = undefined, -atlas: storage.Internal.Atlas = .{}, open_file_index: usize = 0, open_reference_index: usize = 0, +packer: Packer = undefined, +atlas: storage.Internal.Atlas = .{}, tools: Tools = .{}, -popups: Popups = .{}, -should_close: bool = false, fonts: Fonts = .{}, colors: Colors = .{}, delta_time: f32 = 0.0, @@ -67,10 +66,10 @@ uniform_buffer_default: *gpu.Buffer = undefined, content_scale: [2]f32 = undefined, window_size: [2]f32 = undefined, framebuffer_size: [2]f32 = undefined, +should_close: bool = false, pub const version: std.SemanticVersion = .{ .major = 0, .minor = 2, .patch = 0 }; -pub const Popups = @import("editor/popups/Popups.zig"); pub const Packer = @import("tools/Packer.zig"); pub const assets = @import("assets.zig"); @@ -130,7 +129,7 @@ pub const Fonts = struct { fa_standard_solid: *imgui.Font = undefined, }; -pub fn init(_app: *App, _core: *Core, app_mod: mach.Mod(App), _editor: *Editor) !void { +pub fn init(_app: *App, _core: *Core, app_mod: mach.Mod(App), _editor: *Editor, editor_mod: mach.Mod(Editor)) !void { app = _app; core = _core; editor = _editor; @@ -156,6 +155,8 @@ pub fn init(_app: *App, _core: *Core, app_mod: mach.Mod(App), _editor: *Editor) .window = window, .root_path = try allocator.dupeZ(u8, path), }; + + editor_mod.call(.init); } /// This is called from the event fired when the window is done being @@ -236,12 +237,12 @@ pub fn lateInit(editor_mod: mach.Mod(Editor)) !void { app.fonts.fa_standard_regular = io.fonts.?.addFontFromFileTTF(assets.root ++ "fonts/fa-regular-400.ttf", app.settings.font_size * scale_factor, &fa_config, @ptrCast(ranges.ptr)).?; // Initialize the editor which loads our theme - editor_mod.call(.init); + editor_mod.call(.lateInit); } pub fn tick(app_mod: mach.Mod(App), editor_mod: mach.Mod(Editor)) !void { - if (app.popups.file_dialog_request) |request| { - defer app.popups.file_dialog_request = null; + if (editor.popups.file_dialog_request) |request| { + defer editor.popups.file_dialog_request = null; const initial = if (request.initial) |initial| initial else app.project_folder; if (switch (request.state) { @@ -249,7 +250,7 @@ pub fn tick(app_mod: mach.Mod(App), editor_mod: mach.Mod(Editor)) !void { .folder => try nfd.openFolderDialog(initial), .save => try nfd.saveFileDialog(request.filter, initial), }) |path| { - app.popups.file_dialog_response = .{ + editor.popups.file_dialog_response = .{ .path = path, .type = request.type, }; @@ -272,7 +273,7 @@ pub fn tick(app_mod: mach.Mod(App), editor_mod: mach.Mod(Editor)) !void { app.hotkeys.setHotkeyState(key_release.key, key_release.mods, .release); }, .mouse_scroll => |mouse_scroll| { - if (!app.popups.anyPopupOpen()) { // Only record mouse scrolling for canvases when popups are closed + if (!editor.popups.anyPopupOpen()) { // Only record mouse scrolling for canvases when popups are closed app.mouse.scroll_x = mouse_scroll.xoffset; app.mouse.scroll_y = mouse_scroll.yoffset; } @@ -297,10 +298,10 @@ pub fn tick(app_mod: mach.Mod(App), editor_mod: mach.Mod(Editor)) !void { } } - if (!should_close and !app.popups.file_confirm_close_exit) { - app.popups.file_confirm_close = true; - app.popups.file_confirm_close_state = .all; - app.popups.file_confirm_close_exit = true; + if (!should_close and !editor.popups.file_confirm_close_exit) { + editor.popups.file_confirm_close = true; + editor.popups.file_confirm_close_state = .all; + editor.popups.file_confirm_close_exit = true; } app.should_close = should_close; }, diff --git a/src/assets.zig b/src/assets.zig index 8151978..d1e8611 100644 --- a/src/assets.zig +++ b/src/assets.zig @@ -32,22 +32,6 @@ pub const fox_bg_png = struct { pub const path = "assets/fox_bg.png"; }; -pub const atari2600_ntsc_hex = struct { - pub const path = "assets/palettes/atari2600-ntsc.hex"; -}; - -pub const dawnbringer_16_hex = struct { - pub const path = "assets/palettes/dawnbringer-16.hex"; -}; - -pub const nyx8_hex = struct { - pub const path = "assets/palettes/nyx8.hex"; -}; - -pub const win16_hex = struct { - pub const path = "assets/palettes/win16.hex"; -}; - pub const endesga_16_hex = struct { pub const path = "assets/palettes/endesga-16.hex"; }; @@ -56,34 +40,6 @@ pub const pear36_hex = struct { pub const path = "assets/palettes/pear36.hex"; }; -pub const aap_16_hex = struct { - pub const path = "assets/palettes/aap-16.hex"; -}; - -pub const google_ui_hex = struct { - pub const path = "assets/palettes/google-ui.hex"; -}; - -pub const matriax8c_hex = struct { - pub const path = "assets/palettes/matriax8c.hex"; -}; - -pub const arne_32_hex = struct { - pub const path = "assets/palettes/arne-32.hex"; -}; - -pub const gameboy_hex = struct { - pub const path = "assets/palettes/gameboy.hex"; -}; - -pub const smile_basic_hex = struct { - pub const path = "assets/palettes/smile-basic.hex"; -}; - -pub const mail24_hex = struct { - pub const path = "assets/palettes/mail24.hex"; -}; - pub const pico_8_hex = struct { pub const path = "assets/palettes/pico-8.hex"; }; @@ -96,147 +52,15 @@ pub const lospec500_hex = struct { pub const path = "assets/palettes/lospec500.hex"; }; -pub const arne_paldac_hex = struct { - pub const path = "assets/palettes/arne-paldac.hex"; -}; - -pub const gameboy_color_type1_hex = struct { - pub const path = "assets/palettes/gameboy-color-type1.hex"; -}; - -pub const aap_64_hex = struct { - pub const path = "assets/palettes/aap-64.hex"; -}; - -pub const simplejpc_16_hex = struct { - pub const path = "assets/palettes/simplejpc-16.hex"; -}; - -pub const nes_ntsc_hex = struct { - pub const path = "assets/palettes/nes-ntsc.hex"; -}; - -pub const cg_arne_hex = struct { - pub const path = "assets/palettes/cg-arne.hex"; -}; - -pub const jmp_hex = struct { - pub const path = "assets/palettes/jmp.hex"; -}; - -pub const x11_hex = struct { - pub const path = "assets/palettes/x11.hex"; -}; - -pub const teletext_hex = struct { - pub const path = "assets/palettes/teletext.hex"; -}; - -pub const master_system_hex = struct { - pub const path = "assets/palettes/master-system.hex"; -}; - -pub const cga_hex = struct { - pub const path = "assets/palettes/cga.hex"; -}; - -pub const aap_micro12_hex = struct { - pub const path = "assets/palettes/aap-micro12.hex"; -}; - -pub const apple_ii_hex = struct { - pub const path = "assets/palettes/apple-ii.hex"; -}; - -pub const monokai_hex = struct { - pub const path = "assets/palettes/monokai.hex"; -}; - -pub const zx_spectrum_hex = struct { - pub const path = "assets/palettes/zx-spectrum.hex"; -}; - -pub const web_safe_colors_hex = struct { - pub const path = "assets/palettes/web-safe-colors.hex"; -}; - -pub const aap_splendor128_hex = struct { - pub const path = "assets/palettes/aap-splendor128.hex"; -}; - -pub const commodore64_hex = struct { - pub const path = "assets/palettes/commodore64.hex"; -}; - -pub const solarized_hex = struct { - pub const path = "assets/palettes/solarized.hex"; -}; - -pub const copper_tech_hex = struct { - pub const path = "assets/palettes/copper-tech.hex"; -}; - -pub const cpc_boy_hex = struct { - pub const path = "assets/palettes/cpc-boy.hex"; -}; - -pub const arne_16_hex = struct { - pub const path = "assets/palettes/arne-16.hex"; -}; - -pub const zughy_32_hex = struct { - pub const path = "assets/palettes/zughy-32.hex"; -}; - -pub const a64_hex = struct { - pub const path = "assets/palettes/a64.hex"; -}; - -pub const atari2600_pal_hex = struct { - pub const path = "assets/palettes/atari2600-pal.hex"; -}; - -pub const rosy_42_hex = struct { - pub const path = "assets/palettes/rosy-42.hex"; -}; - pub const resurrect_64_hex = struct { pub const path = "assets/palettes/resurrect-64.hex"; }; -pub const commodore_plus4_hex = struct { - pub const path = "assets/palettes/commodore-plus4.hex"; -}; - -pub const nes_hex = struct { - pub const path = "assets/palettes/nes.hex"; -}; - pub const endesga_32_hex = struct { pub const path = "assets/palettes/endesga-32.hex"; }; -pub const eroge_copper_hex = struct { - pub const path = "assets/palettes/eroge-copper.hex"; -}; - -pub const commodore_vic20_hex = struct { - pub const path = "assets/palettes/commodore-vic20.hex"; -}; - -pub const psygnork_hex = struct { - pub const path = "assets/palettes/psygnork.hex"; -}; - pub const apollo_hex = struct { pub const path = "assets/palettes/apollo.hex"; }; -pub const vga_13h_hex = struct { - pub const path = "assets/palettes/vga-13h.hex"; -}; - -pub const dawnbringer_32_hex = struct { - pub const path = "assets/palettes/dawnbringer-32.hex"; -}; - diff --git a/src/editor/Editor.zig b/src/editor/Editor.zig index 2bdfd11..50c8f00 100644 --- a/src/editor/Editor.zig +++ b/src/editor/Editor.zig @@ -19,36 +19,40 @@ pub const Artboard = @import("artboard/Artboard.zig"); pub const Popups = @import("popups/Popups.zig"); pub const mach_module = .editor; -pub const mach_systems = .{ .init, .tick, .deinit }; +pub const mach_systems = .{ .init, .lateInit, .tick, .deinit }; pub const Theme = @import("Theme.zig"); theme: Theme, +popups: *Popups, pub fn init( - core: *Core, - app: *Pixi, editor: *Editor, + _popups: *Popups, sidebar_mod: mach.Mod(Sidebar), explorer_mod: mach.Mod(Explorer), artboard_mod: mach.Mod(Artboard), popups_mod: mach.Mod(Popups), ) !void { - const theme_path = try std.fs.path.joinZ(app.allocator, &.{ Pixi.assets.themes, app.settings.theme }); - defer app.allocator.free(theme_path); - editor.* = .{ - .theme = try Editor.Theme.loadFromFile(theme_path), + .theme = undefined, + .popups = _popups, }; - editor.theme.init(core, app); - sidebar_mod.call(.init); explorer_mod.call(.init); artboard_mod.call(.init); popups_mod.call(.init); } +pub fn lateInit(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); + + editor.theme = try Theme.loadFromFile(theme_path); + editor.theme.init(core, app); +} + pub fn tick( core: *Core, app: *Pixi, @@ -100,10 +104,10 @@ pub fn newFile(path: [:0]const u8, import_path: ?[:0]const u8) !bool { var internal: Pixi.storage.Internal.PixiFile = .{ .path = try Pixi.app.allocator.dupeZ(u8, path), - .width = @as(u32, @intCast(Pixi.app.popups.file_setup_tiles[0] * Pixi.app.popups.file_setup_tile_size[0])), - .height = @as(u32, @intCast(Pixi.app.popups.file_setup_tiles[1] * Pixi.app.popups.file_setup_tile_size[1])), - .tile_width = @as(u32, @intCast(Pixi.app.popups.file_setup_tile_size[0])), - .tile_height = @as(u32, @intCast(Pixi.app.popups.file_setup_tile_size[1])), + .width = @as(u32, @intCast(Pixi.editor.popups.file_setup_tiles[0] * Pixi.editor.popups.file_setup_tile_size[0])), + .height = @as(u32, @intCast(Pixi.editor.popups.file_setup_tiles[1] * Pixi.editor.popups.file_setup_tile_size[1])), + .tile_width = @as(u32, @intCast(Pixi.editor.popups.file_setup_tile_size[0])), + .tile_height = @as(u32, @intCast(Pixi.editor.popups.file_setup_tile_size[1])), .layers = .{}, .deleted_layers = .{}, .deleted_heightmap_layers = .{}, @@ -159,7 +163,7 @@ pub fn newFile(path: [:0]const u8, import_path: ?[:0]const u8) !bool { const ext = std.fs.path.extension(base_name); const ext_ind = if (std.mem.indexOf(u8, base_name, ext)) |index| index else base_name.len - 1; - const tiles = @as(usize, @intCast(Pixi.app.popups.file_setup_tiles[0] * Pixi.app.popups.file_setup_tiles[1])); + const tiles = @as(usize, @intCast(Pixi.editor.popups.file_setup_tiles[0] * Pixi.editor.popups.file_setup_tiles[1])); var i: usize = 0; while (i < tiles) : (i += 1) { const sprite: Pixi.storage.Internal.Sprite = .{ @@ -384,8 +388,8 @@ pub fn openReference(path: [:0]const u8) !bool { try Pixi.app.open_references.insert(0, reference); setActiveReference(0); - if (!Pixi.app.popups.references) - Pixi.app.popups.references = true; + if (!Pixi.editor.popups.references) + Pixi.editor.popups.references = true; return true; } @@ -466,9 +470,9 @@ pub fn closeFile(index: usize) !void { { const file = Pixi.app.open_files.items[index]; if (file.dirty()) { - Pixi.app.popups.file_confirm_close = true; - Pixi.app.popups.file_confirm_close_state = .one; - Pixi.app.popups.file_confirm_close_index = index; + Pixi.editor.popups.file_confirm_close = true; + Pixi.editor.popups.file_confirm_close_state = .one; + Pixi.editor.popups.file_confirm_close_index = index; return; } } diff --git a/src/editor/artboard/Artboard.zig b/src/editor/artboard/Artboard.zig index 6b80c40..6ad1647 100644 --- a/src/editor/artboard/Artboard.zig +++ b/src/editor/artboard/Artboard.zig @@ -2,7 +2,7 @@ const std = @import("std"); const Pixi = @import("../../Pixi.zig"); const Core = @import("mach").Core; - +const Editor = Pixi.Editor; const nfd = @import("nfd"); const imgui = @import("zig-imgui"); @@ -31,7 +31,7 @@ pub fn init(artboard: *Artboard) void { pub fn deinit() void {} -pub fn draw(artboard: *Artboard, core: *Core, app: *Pixi) !void { +pub fn draw(artboard: *Artboard, core: *Core, app: *Pixi, editor: *Editor) !void { imgui.pushStyleVar(imgui.StyleVar_WindowRounding, 0.0); defer imgui.popStyleVar(); imgui.setNextWindowPos(.{ @@ -57,7 +57,7 @@ pub fn draw(artboard: *Artboard, core: *Core, app: *Pixi) !void { art_flags |= imgui.WindowFlags_NoBringToFrontOnFocus; if (imgui.begin("Art", null, art_flags)) { - try menu.draw(app, core); + try menu.draw(app, core, editor); const art_width = imgui.getWindowWidth(); @@ -141,7 +141,7 @@ pub fn draw(artboard: *Artboard, core: *Core, app: *Pixi) !void { if (artboard.open_file_index_0 == i) artboard.open_file_index_0 = 0; if (artboard.open_file_index_1 == i) artboard.open_file_index_1 = 0; - try Pixi.Editor.closeFile(i); + try Editor.closeFile(i); break; // This ensures we dont use after free } @@ -158,7 +158,7 @@ pub fn draw(artboard: *Artboard, core: *Core, app: *Pixi) !void { defer imgui.popStyleVar(); if (imgui.beginTooltip()) { defer imgui.endTooltip(); - imgui.textColored(Pixi.editor.theme.text_secondary.toImguiVec4(), file.path); + imgui.textColored(editor.theme.text_secondary.toImguiVec4(), file.path); } } } @@ -191,19 +191,19 @@ pub fn draw(artboard: *Artboard, core: *Core, app: *Pixi) !void { var open_file_index = if (artboard_0) artboard.open_file_index_0 else if (!artboard_grip) artboard.open_file_index_1 else 0; if (window_hovered and mouse_clicked) { - Pixi.Editor.setActiveFile(open_file_index); + Editor.setActiveFile(open_file_index); } if (!app.settings.split_artboard) open_file_index = app.open_file_index; - if (Pixi.Editor.getFile(open_file_index)) |file| { + if (Editor.getFile(open_file_index)) |file| { if (imgui.beginChild( file.path, .{ .x = 0.0, .y = 0.0 }, imgui.ChildFlags_None, canvas_flags, )) { - try canvas.draw(file, core, app); + try canvas.draw(file, core, app, editor); } imgui.endChild(); @@ -214,10 +214,10 @@ pub fn draw(artboard: *Artboard, core: *Core, app: *Pixi) !void { } } } else { - try drawLogoScreen(app); + try drawLogoScreen(app, editor); } } else { - drawGrip(art_width, app); + drawGrip(art_width, app, editor); } } @@ -235,7 +235,7 @@ pub fn draw(artboard: *Artboard, core: *Core, app: *Pixi) !void { .x = 0.0, .y = flipbook_height, }, imgui.ChildFlags_None, flipbook_flags)) { - if (Pixi.Editor.getFile(app.open_file_index)) |file| { + if (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); @@ -263,12 +263,12 @@ pub fn draw(artboard: *Artboard, core: *Core, app: *Pixi) !void { imgui.end(); } -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()); - imgui.pushStyleColorImVec4(imgui.Col_ButtonHovered, Pixi.editor.theme.foreground.toImguiVec4()); - imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text_background.toImguiVec4()); +pub fn drawLogoScreen(app: *Pixi, editor: *Editor) !void { + imgui.pushStyleColorImVec4(imgui.Col_Button, editor.theme.background.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_Border, editor.theme.background.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_ButtonActive, editor.theme.background.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_ButtonHovered, editor.theme.foreground.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_Text, editor.theme.text_background.toImguiVec4()); defer imgui.popStyleColorEx(5); { // Draw semi-transparent logo const logo_sprite = app.loaded_assets.atlas.sprites[Pixi.assets.pixi_atlas.logo_0_default]; @@ -304,29 +304,29 @@ pub fn drawLogoScreen(app: *Pixi) !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 })) { - app.popups.file_dialog_request = .{ + editor.popups.file_dialog_request = .{ .state = .folder, .type = .project, }; } - if (app.popups.file_dialog_response) |response| { + if (editor.popups.file_dialog_response) |response| { if (response.type == .project) { - try Pixi.Editor.setProjectFolder(response.path); + try Editor.setProjectFolder(response.path); nfd.freePath(response.path); - app.popups.file_dialog_response = null; + editor.popups.file_dialog_response = null; } } } } -pub fn drawGrip(window_width: f32, app: *Pixi) void { +pub fn drawGrip(window_width: f32, app: *Pixi, editor: *Editor) void { imgui.setCursorPosY(0.0); imgui.setCursorPosX(0.0); const avail = imgui.getContentRegionAvail().y; const curs_y = imgui.getCursorPosY(); - var color = Pixi.editor.theme.text_background.toImguiVec4(); + var color = editor.theme.text_background.toImguiVec4(); _ = imgui.invisibleButton("ArtboardGripButton", .{ .x = app.settings.explorer_grip, @@ -339,7 +339,7 @@ pub fn drawGrip(window_width: f32, app: *Pixi) void { if (imgui.isItemHovered(hovered_flags)) { imgui.setMouseCursor(imgui.MouseCursor_ResizeEW); - color = Pixi.editor.theme.text.toImguiVec4(); + color = editor.theme.text.toImguiVec4(); if (imgui.isMouseDoubleClicked(imgui.MouseButton_Left)) { app.settings.split_artboard = !app.settings.split_artboard; @@ -347,7 +347,7 @@ pub fn drawGrip(window_width: f32, app: *Pixi) void { } if (imgui.isItemActive()) { - color = Pixi.editor.theme.text.toImguiVec4(); + color = editor.theme.text.toImguiVec4(); const prev = app.mouse.previous_position; const cur = app.mouse.position; diff --git a/src/editor/artboard/canvas.zig b/src/editor/artboard/canvas.zig index 7c135ab..1c4c045 100644 --- a/src/editor/artboard/canvas.zig +++ b/src/editor/artboard/canvas.zig @@ -1,10 +1,11 @@ const std = @import("std"); const Pixi = @import("../../Pixi.zig"); const Core = @import("mach").Core; +const Editor = Pixi.Editor; const imgui = @import("zig-imgui"); const zmath = @import("zmath"); -pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core, app: *Pixi) !void { +pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core, app: *Pixi, editor: *Editor) !void { const transforming = file.transform_texture != null; { @@ -67,11 +68,11 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core, app: *Pixi) !voi imgui.text("Transformation"); imgui.separator(); - if (imgui.button("Confirm") or (core.keyPressed(Core.Key.enter) and app.open_file_index == Pixi.Editor.getFileIndex(file.path).?)) { + if (imgui.button("Confirm") or (core.keyPressed(Core.Key.enter) and app.open_file_index == Editor.getFileIndex(file.path).?)) { transform_texture.confirm = true; } imgui.sameLine(); - if (imgui.button("Cancel") or (core.keyPressed(Core.Key.escape) and app.open_file_index == Pixi.Editor.getFileIndex(file.path).?)) { + if (imgui.button("Cancel") or (core.keyPressed(Core.Key.escape) and app.open_file_index == 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); @@ -342,17 +343,17 @@ pub fn draw(file: *Pixi.storage.Internal.PixiFile, core: *Core, app: *Pixi) !voi file.camera.drawRect(rect, 3.0, Pixi.editor.theme.text.toU32()); } - if (app.popups.animation_length > 0 and app.tools.current == .animation and !transforming) { + if (editor.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); + if (primary.down() or editor.popups.animation) { + const start_column = @mod(@as(u32, @intCast(editor.popups.animation_start)), tiles_wide); + const start_row = @divTrunc(@as(u32, @intCast(editor.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(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_column = @mod(@as(u32, @intCast(editor.popups.animation_start + editor.popups.animation_length - 1)), tiles_wide); + const end_row = @divTrunc(@as(u32, @intCast(editor.popups.animation_start + editor.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 }; diff --git a/src/editor/artboard/menu.zig b/src/editor/artboard/menu.zig index 063dbd8..af56f37 100644 --- a/src/editor/artboard/menu.zig +++ b/src/editor/artboard/menu.zig @@ -1,36 +1,37 @@ const std = @import("std"); const Pixi = @import("../../Pixi.zig"); const Core = @import("mach").Core; +const Editor = Pixi.Editor; const settings = Pixi.settings; const zstbi = @import("zstbi"); const nfd = @import("nfd"); const imgui = @import("zig-imgui"); -pub fn draw(app: *Pixi, _: *Core) !void { +pub fn draw(app: *Pixi, _: *Core, editor: *Editor) !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()); - imgui.pushStyleColorImVec4(imgui.Col_HeaderHovered, Pixi.editor.theme.background.toImguiVec4()); - imgui.pushStyleColorImVec4(imgui.Col_HeaderActive, Pixi.editor.theme.background.toImguiVec4()); - imgui.pushStyleColorImVec4(imgui.Col_Header, Pixi.editor.theme.background.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_Text, editor.theme.text_secondary.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_PopupBg, editor.theme.foreground.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_HeaderHovered, editor.theme.background.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_HeaderActive, editor.theme.background.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_Header, editor.theme.background.toImguiVec4()); defer imgui.popStyleColorEx(5); if (imgui.beginMenuBar()) { defer imgui.endMenuBar(); if (imgui.beginMenu("File")) { - imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_Text, editor.theme.text.toImguiVec4()); if (imgui.menuItemEx("Open Folder...", if (app.hotkeys.hotkey(.{ .proc = .folder })) |hotkey| hotkey.shortcut else "", false, true)) { - app.popups.file_dialog_request = .{ + editor.popups.file_dialog_request = .{ .state = .folder, .type = .project, }; } - if (app.popups.file_dialog_response) |response| { + if (editor.popups.file_dialog_response) |response| { if (response.type == .project) { - try Pixi.Editor.setProjectFolder(response.path); + try Editor.setProjectFolder(response.path); nfd.freePath(response.path); - app.popups.file_dialog_response = null; + editor.popups.file_dialog_response = null; } } @@ -39,14 +40,14 @@ pub fn draw(app: *Pixi, _: *Core) !void { for (app.recents.folders.items) |folder| { if (imgui.menuItem(folder)) { - try Pixi.Editor.setProjectFolder(folder); + try Editor.setProjectFolder(folder); } } } imgui.separator(); - const file = Pixi.Editor.getFile(app.open_file_index); + const file = Editor.getFile(app.open_file_index); if (imgui.menuItemEx( "Export as .png...", @@ -54,7 +55,7 @@ pub fn draw(app: *Pixi, _: *Core) !void { false, file != null, )) { - app.popups.export_to_png = true; + editor.popups.export_to_png = true; } if (imgui.menuItemEx( @@ -74,7 +75,7 @@ pub fn draw(app: *Pixi, _: *Core) !void { if (imgui.beginMenu("View")) { defer imgui.endMenu(); - imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_Text, editor.theme.text.toImguiVec4()); defer imgui.popStyleColor(); if (imgui.menuItemEx("Split Artboard", null, app.settings.split_artboard, true)) { @@ -84,7 +85,7 @@ pub fn draw(app: *Pixi, _: *Core) !void { if (imgui.beginMenu("Flipbook")) { defer imgui.endMenu(); - if (Pixi.Editor.getFile(app.open_file_index)) |file| { + if (Editor.getFile(app.open_file_index)) |file| { if (imgui.beginCombo("Flipbook View", switch (file.flipbook_view) { .canvas => "Canvas", .timeline => "Timeline", @@ -115,17 +116,17 @@ pub fn draw(app: *Pixi, _: *Core) !void { } } - if (imgui.menuItemEx("References", "r", app.popups.references, true)) { - app.popups.references = !app.popups.references; + if (imgui.menuItemEx("References", "r", editor.popups.references, true)) { + editor.popups.references = !editor.popups.references; } } if (imgui.beginMenu("Edit")) { defer imgui.endMenu(); - imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_Text, editor.theme.text.toImguiVec4()); defer imgui.popStyleColor(); - if (Pixi.Editor.getFile(app.open_file_index)) |file| { + if (Editor.getFile(app.open_file_index)) |file| { if (imgui.menuItemEx( "Undo", if (app.hotkeys.hotkey(.{ .proc = .undo })) |hotkey| hotkey.shortcut else "", @@ -144,12 +145,12 @@ pub fn draw(app: *Pixi, _: *Core) !void { } } if (imgui.beginMenu("Tools")) { - imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_Text, editor.theme.text.toImguiVec4()); imgui.popStyleColor(); imgui.endMenu(); } if (imgui.menuItem("About")) { - app.popups.about = true; + editor.popups.about = true; } } } diff --git a/src/editor/explorer/Explorer.zig b/src/editor/explorer/Explorer.zig index 5b24de5..ebd61c2 100644 --- a/src/editor/explorer/Explorer.zig +++ b/src/editor/explorer/Explorer.zig @@ -1,8 +1,11 @@ const std = @import("std"); + const Pixi = @import("../../Pixi.zig"); +const Core = @import("mach").Core; +const Editor = Pixi.Editor; + const nfd = @import("nfd"); const imgui = @import("zig-imgui"); -const Core = @import("mach").Core; pub const Explorer = @This(); @@ -26,7 +29,7 @@ pub fn deinit() void { // TODO: Free memory } -pub fn draw(core: *Core, app: *Pixi) !void { +pub fn draw(core: *Core, app: *Pixi, editor: *Editor) !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 }); @@ -61,8 +64,8 @@ pub fn draw(core: *Core, app: *Pixi) !void { 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()); + imgui.pushStyleColorImVec4(imgui.Col_Separator, editor.theme.text_background.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_Header, editor.theme.foreground.toImguiVec4()); defer imgui.popStyleColorEx(2); switch (app.sidebar) { @@ -161,7 +164,7 @@ pub fn draw(core: *Core, app: *Pixi) !void { } imgui.spacing(); imgui.spacing(); - try pack.draw(core, app); + try pack.draw(core, app, editor); }, .settings => { if (imgui.beginMenuBar()) { @@ -216,7 +219,7 @@ pub fn draw(core: *Core, app: *Pixi) !void { const avail = imgui.getContentRegionAvail().y; const curs_y = imgui.getCursorPosY(); - var color = Pixi.editor.theme.text_background.toImguiVec4(); + var color = editor.theme.text_background.toImguiVec4(); _ = imgui.invisibleButton("GripButton", .{ .x = app.settings.explorer_grip, @@ -229,7 +232,7 @@ pub fn draw(core: *Core, app: *Pixi) !void { if (imgui.isItemHovered(hovered_flags)) { imgui.setMouseCursor(imgui.MouseCursor_ResizeEW); - color = Pixi.editor.theme.text.toImguiVec4(); + color = editor.theme.text.toImguiVec4(); if (imgui.isMouseDoubleClicked(imgui.MouseButton_Left)) { app.settings.split_artboard = !app.settings.split_artboard; @@ -237,7 +240,7 @@ pub fn draw(core: *Core, app: *Pixi) !void { } if (imgui.isItemActive()) { - color = Pixi.editor.theme.text.toImguiVec4(); + color = editor.theme.text.toImguiVec4(); const prev = app.mouse.previous_position; const cur = app.mouse.position; diff --git a/src/editor/explorer/animations.zig b/src/editor/explorer/animations.zig index d8850af..96ab0b7 100644 --- a/src/editor/explorer/animations.zig +++ b/src/editor/explorer/animations.zig @@ -125,12 +125,12 @@ fn contextMenu(animation_index: usize, file: *Pixi.storage.Internal.PixiFile) !v if (imgui.menuItem("Rename...")) { const animation = file.animations.slice().get(animation_index); - Pixi.app.popups.animation_name = [_:0]u8{0} ** 128; - @memcpy(Pixi.app.popups.animation_name[0..animation.name.len], animation.name); - Pixi.app.popups.animation_index = animation_index; - Pixi.app.popups.animation_fps = animation.fps; - Pixi.app.popups.animation_state = .edit; - Pixi.app.popups.animation = true; + Pixi.editor.popups.animation_name = [_:0]u8{0} ** 128; + @memcpy(Pixi.editor.popups.animation_name[0..animation.name.len], animation.name); + Pixi.editor.popups.animation_index = animation_index; + Pixi.editor.popups.animation_fps = animation.fps; + Pixi.editor.popups.animation_state = .edit; + Pixi.editor.popups.animation = true; } imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text_red.toImguiVec4()); diff --git a/src/editor/explorer/files.zig b/src/editor/explorer/files.zig index 6772847..9a8dc23 100644 --- a/src/editor/explorer/files.zig +++ b/src/editor/explorer/files.zig @@ -309,24 +309,24 @@ fn contextMenuFolder(folder: [:0]const u8) !void { if (imgui.menuItem("New File...")) { const new_file_path = try std.fs.path.joinZ(Pixi.app.allocator, &[_][]const u8{ folder, "New_file.pixi" }); defer Pixi.app.allocator.free(new_file_path); - Pixi.app.popups.fileSetupNew(new_file_path); + Pixi.editor.popups.fileSetupNew(new_file_path); } if (imgui.menuItem("New File from PNG...")) { - Pixi.app.popups.file_dialog_request = .{ + Pixi.editor.popups.file_dialog_request = .{ .state = .file, .type = .new_png, .filter = "png", }; } - if (Pixi.app.popups.file_dialog_response) |response| { + if (Pixi.editor.popups.file_dialog_response) |response| { if (response.type == .new_png) { const new_file_path = try std.fmt.allocPrintZ(Pixi.app.allocator, "{s}.pixi", .{response.path[0 .. response.path.len - 4]}); defer Pixi.app.allocator.free(new_file_path); - Pixi.app.popups.fileSetupImportPng(new_file_path, response.path); + Pixi.editor.popups.fileSetupImportPng(new_file_path, response.path); nfd.freePath(response.path); - Pixi.app.popups.file_dialog_response = null; + Pixi.editor.popups.file_dialog_response = null; } } if (imgui.menuItem("New Folder...")) { @@ -347,12 +347,12 @@ fn contextMenuFile(file: [:0]const u8) !void { if (imgui.menuItem("Import...")) { const new_file_path = try std.fmt.allocPrintZ(Pixi.app.allocator, "{s}.pixi", .{file[0 .. file.len - 4]}); defer Pixi.app.allocator.free(new_file_path); - Pixi.app.popups.fileSetupImportPng(new_file_path, file); + Pixi.editor.popups.fileSetupImportPng(new_file_path, file); } }, .pixi => { if (imgui.menuItem("Re-slice...")) { - Pixi.app.popups.fileSetupSlice(file); + Pixi.editor.popups.fileSetupSlice(file); } }, else => {}, @@ -361,28 +361,28 @@ fn contextMenuFile(file: [:0]const u8) !void { imgui.separator(); if (imgui.menuItem("Rename...")) { - Pixi.app.popups.rename_path = [_:0]u8{0} ** std.fs.max_path_bytes; - Pixi.app.popups.rename_old_path = [_:0]u8{0} ** std.fs.max_path_bytes; - @memcpy(Pixi.app.popups.rename_path[0..file.len], file); - @memcpy(Pixi.app.popups.rename_old_path[0..file.len], file); - Pixi.app.popups.rename = true; - Pixi.app.popups.rename_state = .rename; + Pixi.editor.popups.rename_path = [_:0]u8{0} ** std.fs.max_path_bytes; + Pixi.editor.popups.rename_old_path = [_:0]u8{0} ** std.fs.max_path_bytes; + @memcpy(Pixi.editor.popups.rename_path[0..file.len], file); + @memcpy(Pixi.editor.popups.rename_old_path[0..file.len], file); + Pixi.editor.popups.rename = true; + Pixi.editor.popups.rename_state = .rename; } if (imgui.menuItem("Duplicate...")) { - Pixi.app.popups.rename_path = [_:0]u8{0} ** std.fs.max_path_bytes; - Pixi.app.popups.rename_old_path = [_:0]u8{0} ** std.fs.max_path_bytes; - @memcpy(Pixi.app.popups.rename_old_path[0..file.len], file); + Pixi.editor.popups.rename_path = [_:0]u8{0} ** std.fs.max_path_bytes; + Pixi.editor.popups.rename_old_path = [_:0]u8{0} ** std.fs.max_path_bytes; + @memcpy(Pixi.editor.popups.rename_old_path[0..file.len], file); const ex = std.fs.path.extension(file); if (std.mem.indexOf(u8, file, ex)) |ext_i| { const new_base_name = try std.fmt.allocPrintZ(Pixi.app.allocator, "{s}{s}{s}", .{ file[0..ext_i], "_copy", ex }); defer Pixi.app.allocator.free(new_base_name); - @memcpy(Pixi.app.popups.rename_path[0..new_base_name.len], new_base_name); + @memcpy(Pixi.editor.popups.rename_path[0..new_base_name.len], new_base_name); - Pixi.app.popups.rename = true; - Pixi.app.popups.rename_state = .duplicate; + Pixi.editor.popups.rename = true; + Pixi.editor.popups.rename_state = .duplicate; } } imgui.separator(); diff --git a/src/editor/explorer/keyframe_animations.zig b/src/editor/explorer/keyframe_animations.zig index 0578a4c..d346c4b 100644 --- a/src/editor/explorer/keyframe_animations.zig +++ b/src/editor/explorer/keyframe_animations.zig @@ -168,12 +168,12 @@ fn contextMenu(animation_index: usize, file: *Pixi.storage.Internal.PixiFile) !v // if (imgui.menuItem("Rename...")) { // const animation = file.transform_animations.items[animation_index]; - // Pixi.app.popups.animation_name = [_:0]u8{0} ** 128; - // @memcpy(Pixi.app.popups.animation_name[0..animation.name.len], animation.name); - // Pixi.app.popups.animation_index = animation_index; - // Pixi.app.popups.animation_fps = animation.fps; - // Pixi.app.popups.animation_state = .edit; - // Pixi.app.popups.animation = true; + // Pixi.editor.popups.animation_name = [_:0]u8{0} ** 128; + // @memcpy(Pixi.editor.popups.animation_name[0..animation.name.len], animation.name); + // Pixi.editor.popups.animation_index = animation_index; + // Pixi.editor.popups.animation_fps = animation.fps; + // Pixi.editor.popups.animation_state = .edit; + // Pixi.editor.popups.animation = true; // } imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text_red.toImguiVec4()); diff --git a/src/editor/explorer/layers.zig b/src/editor/explorer/layers.zig index 9583f0d..2ba7d50 100644 --- a/src/editor/explorer/layers.zig +++ b/src/editor/explorer/layers.zig @@ -33,10 +33,10 @@ pub fn draw() !void { imgui.spacing(); if (imgui.smallButton(Pixi.fa.plus)) { - Pixi.app.popups.layer_setup_name = [_:0]u8{0} ** 128; - std.mem.copyForwards(u8, &Pixi.app.popups.layer_setup_name, "New Layer"); - Pixi.app.popups.layer_setup_state = .none; - Pixi.app.popups.layer_setup = true; + Pixi.editor.popups.layer_setup_name = [_:0]u8{0} ** 128; + std.mem.copyForwards(u8, &Pixi.editor.popups.layer_setup_name, "New Layer"); + Pixi.editor.popups.layer_setup_state = .none; + Pixi.editor.popups.layer_setup = true; } imgui.sameLine(); @@ -131,21 +131,21 @@ pub fn draw() !void { defer imgui.endPopup(); if (imgui.menuItem("Rename...")) { - Pixi.app.popups.layer_setup_name = [_:0]u8{0} ** 128; - @memcpy(Pixi.app.popups.layer_setup_name[0..layer.name.len], layer.name); - Pixi.app.popups.layer_setup_index = i; - Pixi.app.popups.layer_setup_state = .rename; - Pixi.app.popups.layer_setup = true; + Pixi.editor.popups.layer_setup_name = [_:0]u8{0} ** 128; + @memcpy(Pixi.editor.popups.layer_setup_name[0..layer.name.len], layer.name); + Pixi.editor.popups.layer_setup_index = i; + Pixi.editor.popups.layer_setup_state = .rename; + Pixi.editor.popups.layer_setup = true; } if (imgui.menuItem("Duplicate...")) { const new_name = try std.fmt.allocPrint(Pixi.app.allocator, "{s}_copy", .{layer.name}); defer Pixi.app.allocator.free(new_name); - Pixi.app.popups.layer_setup_name = [_:0]u8{0} ** 128; - @memcpy(Pixi.app.popups.layer_setup_name[0..new_name.len], new_name); - Pixi.app.popups.layer_setup_index = i; - Pixi.app.popups.layer_setup_state = .duplicate; - Pixi.app.popups.layer_setup = true; + Pixi.editor.popups.layer_setup_name = [_:0]u8{0} ** 128; + @memcpy(Pixi.editor.popups.layer_setup_name[0..new_name.len], new_name); + Pixi.editor.popups.layer_setup_index = i; + Pixi.editor.popups.layer_setup_state = .duplicate; + Pixi.editor.popups.layer_setup = true; } imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text_red.toImguiVec4()); imgui.pushStyleColorImVec4(imgui.Col_Separator, Pixi.editor.theme.foreground.toImguiVec4()); diff --git a/src/editor/explorer/pack.zig b/src/editor/explorer/pack.zig index 66d3c81..1040f69 100644 --- a/src/editor/explorer/pack.zig +++ b/src/editor/explorer/pack.zig @@ -1,15 +1,16 @@ const std = @import("std"); const Pixi = @import("../../Pixi.zig"); const Core = @import("mach").Core; +const Editor = Pixi.Editor; const nfd = @import("nfd"); const imgui = @import("zig-imgui"); -pub fn draw(_: *Core, app: *Pixi) !void { +pub fn draw(_: *Core, app: *Pixi, editor: *Editor) !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()); - imgui.pushStyleColorImVec4(imgui.Col_ButtonHovered, Pixi.editor.theme.hover_secondary.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_Button, editor.theme.highlight_secondary.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_ButtonActive, editor.theme.highlight_secondary.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_ButtonHovered, editor.theme.hover_secondary.toImguiVec4()); defer imgui.popStyleColorEx(3); const window_size = imgui.getContentRegionAvail(); @@ -40,7 +41,7 @@ pub fn draw(_: *Core, app: *Pixi) !void { } { - const enabled = if (Pixi.Editor.getFile(app.open_file_index)) |_| true else false; + const enabled = if (Editor.getFile(app.open_file_index)) |_| true else false; if (imgui.menuItemEx("Current Open File", null, false, enabled)) { app.packer.target = .single_open; } @@ -66,8 +67,8 @@ pub fn draw(_: *Core, app: *Pixi) !void { var packable: bool = true; 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()); + if (Editor.saving()) { + imgui.pushStyleColorImVec4(imgui.Col_Text, editor.theme.text_background.toImguiVec4()); defer imgui.popStyleColor(); imgui.textWrapped("Please wait until all files are done saving."); packable = false; @@ -90,7 +91,7 @@ pub fn draw(_: *Core, app: *Pixi) !void { try app.packer.packAndClear(); }, .single_open => { - if (Pixi.Editor.getFile(app.open_file_index)) |file| { + if (Editor.getFile(app.open_file_index)) |file| { try app.packer.append(file); try app.packer.packAndClear(); } @@ -101,7 +102,7 @@ pub fn draw(_: *Core, app: *Pixi) !void { imgui.endDisabled(); if (app.packer.target == .project and app.project_folder == null) { - imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text_background.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_Text, editor.theme.text_background.toImguiVec4()); defer imgui.popStyleColor(); imgui.textWrapped("Select a project folder to pack."); } @@ -115,19 +116,19 @@ pub fn draw(_: *Core, app: *Pixi) !void { } if (imgui.buttonEx("Export", .{ .x = window_size.x, .y = 0.0 })) { - app.popups.file_dialog_request = .{ + editor.popups.file_dialog_request = .{ .state = .save, .type = .export_atlas, }; } - if (app.popups.file_dialog_response) |response| { + if (editor.popups.file_dialog_response) |response| { if (response.type == .export_atlas) { 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); - app.popups.file_dialog_response = null; + editor.popups.file_dialog_response = null; } } @@ -139,7 +140,7 @@ pub fn draw(_: *Core, app: *Pixi) !void { imgui.spacing(); imgui.separatorText("Recents"); - imgui.pushStyleColorImVec4(imgui.Col_Text, Pixi.editor.theme.text_secondary.toImguiVec4()); + imgui.pushStyleColorImVec4(imgui.Col_Text, editor.theme.text_secondary.toImguiVec4()); defer imgui.popStyleColor(); if (imgui.beginChild("Recents", .{ .x = imgui.getWindowWidth() - app.settings.explorer_grip * app.content_scale[0], @@ -159,7 +160,7 @@ pub fn draw(_: *Core, app: *Pixi) !void { 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()); + imgui.pushStyleColorImVec4(imgui.Col_Text, editor.theme.text_background.toImguiVec4()); imgui.text(exp); imgui.popStyleColor(); } diff --git a/src/editor/explorer/settings.zig b/src/editor/explorer/settings.zig index aeb6a98..91380e6 100644 --- a/src/editor/explorer/settings.zig +++ b/src/editor/explorer/settings.zig @@ -147,7 +147,7 @@ pub fn draw(core: *Core) !void { imgui.spacing(); if (imgui.buttonEx("Save As...", .{ .x = imgui.getWindowWidth() - Pixi.app.settings.explorer_grip * Pixi.app.content_scale[0], .y = 0.0 })) { - Pixi.app.popups.file_dialog_request = .{ + Pixi.editor.popups.file_dialog_request = .{ .state = .save, .type = .export_theme, .filter = "json", @@ -155,7 +155,7 @@ pub fn draw(core: *Core) !void { }; } - if (Pixi.app.popups.file_dialog_response) |response| { + if (Pixi.editor.popups.file_dialog_response) |response| { if (response.type == .export_theme) { try Pixi.editor.theme.save(response.path); Pixi.app.allocator.free(Pixi.editor.theme.name); @@ -163,7 +163,7 @@ pub fn draw(core: *Core) !void { Pixi.app.settings.theme = Pixi.editor.theme.name; } nfd.freePath(response.path); - Pixi.app.popups.file_dialog_response = null; + Pixi.editor.popups.file_dialog_response = null; } imgui.popItemWidth(); diff --git a/src/editor/popups/Popups.zig b/src/editor/popups/Popups.zig index 0d69c95..b8ae518 100644 --- a/src/editor/popups/Popups.zig +++ b/src/editor/popups/Popups.zig @@ -2,7 +2,7 @@ const std = @import("std"); const Pixi = @import("../../Pixi.zig"); const Core = @import("mach").Core; - +const Editor = Pixi.Editor; const zstbi = @import("zstbi"); const Popups = @This(); @@ -99,8 +99,8 @@ pub fn init(popups: *Popups) !void { popups.* = .{}; } -pub fn draw() !void { - try popup_rename.draw(); +pub fn draw(popups: *Popups, app: *Pixi) !void { + try popup_rename.draw(popups, app); try popup_file_setup.draw(); try popup_about.draw(); try popup_file_confirm_close.draw(); diff --git a/src/editor/popups/about.zig b/src/editor/popups/about.zig index 1195b73..d1f6c59 100644 --- a/src/editor/popups/about.zig +++ b/src/editor/popups/about.zig @@ -4,7 +4,7 @@ const core = @import("mach").core; const imgui = @import("zig-imgui"); pub fn draw() !void { - if (Pixi.app.popups.about) { + if (Pixi.editor.popups.about) { imgui.openPopup("About", imgui.PopupFlags_None); } else return; @@ -29,7 +29,7 @@ pub fn draw() !void { if (imgui.beginPopupModal( "About", - &Pixi.app.popups.about, + &Pixi.editor.popups.about, modal_flags, )) { defer imgui.endPopup(); diff --git a/src/editor/popups/animation.zig b/src/editor/popups/animation.zig index 8730efc..47a9abd 100644 --- a/src/editor/popups/animation.zig +++ b/src/editor/popups/animation.zig @@ -6,13 +6,13 @@ const History = Pixi.storage.Internal.PixiFile.History; pub fn draw() !void { if (Pixi.Editor.getFile(Pixi.app.open_file_index)) |file| { - const dialog_name = switch (Pixi.app.popups.animation_state) { + const dialog_name = switch (Pixi.editor.popups.animation_state) { .none => "None...", .create => "Create animation...", .edit => "Edit animation...", }; - if (Pixi.app.popups.animation) { + if (Pixi.editor.popups.animation) { imgui.openPopup(dialog_name, imgui.PopupFlags_None); } else return; @@ -37,7 +37,7 @@ pub fn draw() !void { if (imgui.beginPopupModal( dialog_name, - &Pixi.app.popups.animation, + &Pixi.editor.popups.animation, modal_flags, )) { defer imgui.endPopup(); @@ -55,48 +55,48 @@ pub fn draw() !void { imgui.pushItemWidth(full_width); const enter = imgui.inputText( "Name", - Pixi.app.popups.animation_name[0.. :0], - Pixi.app.popups.animation_name[0.. :0].len, + Pixi.editor.popups.animation_name[0.. :0], + Pixi.editor.popups.animation_name[0.. :0].len, input_text_flags, ); imgui.spacing(); - if (Pixi.app.popups.animation_state == .create) { - var fps = @as(i32, @intCast(Pixi.app.popups.animation_fps)); + if (Pixi.editor.popups.animation_state == .create) { + var fps = @as(i32, @intCast(Pixi.editor.popups.animation_fps)); if (imgui.sliderInt("FPS", &fps, 1, 60)) { - Pixi.app.popups.animation_fps = @as(usize, @intCast(fps)); + Pixi.editor.popups.animation_fps = @as(usize, @intCast(fps)); } imgui.spacing(); } imgui.separator(); if (imgui.buttonEx("Cancel", .{ .x = half_width, .y = 0.0 })) { - Pixi.app.popups.animation = false; + Pixi.editor.popups.animation = false; } imgui.sameLine(); if (imgui.buttonEx("Ok", .{ .x = half_width, .y = 0.0 }) or enter) { - switch (Pixi.app.popups.animation_state) { + switch (Pixi.editor.popups.animation_state) { .create => { - const name = std.mem.trimRight(u8, &Pixi.app.popups.animation_name, "\u{0}"); + const name = std.mem.trimRight(u8, &Pixi.editor.popups.animation_name, "\u{0}"); if (std.mem.indexOf(u8, name, "\u{0}")) |index| { - try file.createAnimation(name[0..index], Pixi.app.popups.animation_fps, Pixi.app.popups.animation_start, Pixi.app.popups.animation_length); + try file.createAnimation(name[0..index], Pixi.editor.popups.animation_fps, Pixi.editor.popups.animation_start, Pixi.editor.popups.animation_length); } else { - try file.createAnimation(name, Pixi.app.popups.animation_fps, Pixi.app.popups.animation_start, Pixi.app.popups.animation_length); + try file.createAnimation(name, Pixi.editor.popups.animation_fps, Pixi.editor.popups.animation_start, Pixi.editor.popups.animation_length); } }, .edit => { - const name = std.mem.trimRight(u8, &Pixi.app.popups.animation_name, "\u{0}"); + const name = std.mem.trimRight(u8, &Pixi.editor.popups.animation_name, "\u{0}"); if (std.mem.indexOf(u8, name, "\u{0}")) |index| { - try file.renameAnimation(name[0..index], Pixi.app.popups.animation_index); + try file.renameAnimation(name[0..index], Pixi.editor.popups.animation_index); } else { - try file.renameAnimation(name, Pixi.app.popups.animation_index); + try file.renameAnimation(name, Pixi.editor.popups.animation_index); } }, else => unreachable, } - Pixi.app.popups.animation_state = .none; - Pixi.app.popups.animation = false; + Pixi.editor.popups.animation_state = .none; + Pixi.editor.popups.animation = false; } imgui.popItemWidth(); diff --git a/src/editor/popups/export_png.zig b/src/editor/popups/export_png.zig index 21a4255..7bdf6b7 100644 --- a/src/editor/popups/export_png.zig +++ b/src/editor/popups/export_png.zig @@ -6,7 +6,7 @@ const nfd = @import("nfd"); const zstbi = @import("zstbi"); pub fn draw() !void { - if (Pixi.app.popups.export_to_png) { + if (Pixi.editor.popups.export_to_png) { imgui.openPopup("Export to .png...", imgui.PopupFlags_None); } else return; @@ -31,7 +31,7 @@ pub fn draw() !void { if (imgui.beginPopupModal( "Export to .png...", - &Pixi.app.popups.export_to_png, + &Pixi.editor.popups.export_to_png, modal_flags, )) { defer imgui.endPopup(); @@ -41,7 +41,7 @@ pub fn draw() !void { const content = imgui.getContentRegionAvail(); const half_width = (popup_width - (style.frame_padding.x * 2.0 * Pixi.app.content_scale[0]) - spacing) / 2.0; - const plot_name = switch (Pixi.app.popups.export_to_png_state) { + const plot_name = switch (Pixi.editor.popups.export_to_png_state) { .selected_sprite => "Selected Sprite", .selected_animation => "Selected Animation", .selected_layer => "Selected Layer", @@ -65,8 +65,8 @@ pub fn draw() !void { .all_layers => "All Layers Individually", .full_image => "Full Flattened Image", }; - if (imgui.selectableEx(current_plot_name, current == Pixi.app.popups.export_to_png_state, imgui.SelectableFlags_None, .{ .x = 0.0, .y = 0.0 })) { - Pixi.app.popups.export_to_png_state = current; + if (imgui.selectableEx(current_plot_name, current == Pixi.editor.popups.export_to_png_state, imgui.SelectableFlags_None, .{ .x = 0.0, .y = 0.0 })) { + Pixi.editor.popups.export_to_png_state = current; } } } @@ -76,9 +76,9 @@ pub fn draw() !void { var image_scale: i32 = 1; - switch (Pixi.app.popups.export_to_png_state) { + switch (Pixi.editor.popups.export_to_png_state) { .selected_sprite, .selected_animation => { - image_scale = @as(i32, @intCast(Pixi.app.popups.export_to_png_scale)); + image_scale = @as(i32, @intCast(Pixi.editor.popups.export_to_png_scale)); imgui.text("Select an export scale:"); if (imgui.sliderInt( @@ -87,7 +87,7 @@ pub fn draw() !void { 1, 16, )) { - Pixi.app.popups.export_to_png_scale = @as(u32, @intCast(image_scale)); + Pixi.editor.popups.export_to_png_scale = @as(u32, @intCast(image_scale)); } }, else => { @@ -96,13 +96,13 @@ pub fn draw() !void { } imgui.spacing(); - switch (Pixi.app.popups.export_to_png_state) { + switch (Pixi.editor.popups.export_to_png_state) { .selected_sprite, .selected_animation, .selected_layer, .all_layers, => { - _ = imgui.checkbox("Preserve names", &Pixi.app.popups.export_to_png_preserve_names); + _ = imgui.checkbox("Preserve names", &Pixi.editor.popups.export_to_png_preserve_names); imgui.spacing(); }, else => { @@ -113,19 +113,19 @@ pub fn draw() !void { imgui.popItemWidth(); if (imgui.buttonEx("Cancel", .{ .x = half_width, .y = 0.0 })) { - Pixi.app.popups.export_to_png = false; + Pixi.editor.popups.export_to_png = false; } imgui.sameLine(); if (imgui.buttonEx("Export", .{ .x = half_width, .y = 0.0 })) { - switch (Pixi.app.popups.export_to_png_state) { + switch (Pixi.editor.popups.export_to_png_state) { .selected_sprite => { - if (Pixi.app.popups.export_to_png_preserve_names) { - Pixi.app.popups.file_dialog_request = .{ + if (Pixi.editor.popups.export_to_png_preserve_names) { + Pixi.editor.popups.file_dialog_request = .{ .state = .folder, .type = .export_sprite, }; } else { - Pixi.app.popups.file_dialog_request = .{ + Pixi.editor.popups.file_dialog_request = .{ .state = .save, .type = .export_sprite, .filter = "png", @@ -133,13 +133,13 @@ pub fn draw() !void { } }, .selected_animation => { - if (Pixi.app.popups.export_to_png_preserve_names) { - Pixi.app.popups.file_dialog_request = .{ + if (Pixi.editor.popups.export_to_png_preserve_names) { + Pixi.editor.popups.file_dialog_request = .{ .state = .folder, .type = .export_animation, }; } else { - Pixi.app.popups.file_dialog_request = .{ + Pixi.editor.popups.file_dialog_request = .{ .state = .save, .type = .export_animation, .filter = "png", @@ -147,13 +147,13 @@ pub fn draw() !void { } }, .selected_layer => { - if (Pixi.app.popups.export_to_png_preserve_names) { - Pixi.app.popups.file_dialog_request = .{ + if (Pixi.editor.popups.export_to_png_preserve_names) { + Pixi.editor.popups.file_dialog_request = .{ .state = .folder, .type = .export_layer, }; } else { - Pixi.app.popups.file_dialog_request = .{ + Pixi.editor.popups.file_dialog_request = .{ .state = .save, .type = .export_layer, .filter = "png", @@ -161,13 +161,13 @@ pub fn draw() !void { } }, .all_layers => { - if (Pixi.app.popups.export_to_png_preserve_names) { - Pixi.app.popups.file_dialog_request = .{ + if (Pixi.editor.popups.export_to_png_preserve_names) { + Pixi.editor.popups.file_dialog_request = .{ .state = .folder, .type = .export_all_layers, }; } else { - Pixi.app.popups.file_dialog_request = .{ + Pixi.editor.popups.file_dialog_request = .{ .state = .save, .type = .export_all_layers, .filter = "png", @@ -175,7 +175,7 @@ pub fn draw() !void { } }, .full_image => { - Pixi.app.popups.file_dialog_request = .{ + Pixi.editor.popups.file_dialog_request = .{ .state = .save, .type = .export_full_image, .filter = "png", @@ -185,7 +185,7 @@ pub fn draw() !void { } if (Pixi.Editor.getFile(Pixi.app.open_file_index)) |file| { - if (Pixi.app.popups.file_dialog_response) |response| { + if (Pixi.editor.popups.file_dialog_response) |response| { switch (response.type) { .export_sprite => { const ext = std.fs.path.extension(response.path); @@ -200,14 +200,14 @@ pub fn draw() !void { var sprite_image = try file.spriteToImage(file.selected_sprite_index, true); defer sprite_image.deinit(); - if (Pixi.app.popups.export_to_png_scale > 1) { - var scaled_image = sprite_image.resize(file.tile_width * Pixi.app.popups.export_to_png_scale, file.tile_height * Pixi.app.popups.export_to_png_scale); + if (Pixi.editor.popups.export_to_png_scale > 1) { + var scaled_image = sprite_image.resize(file.tile_width * Pixi.editor.popups.export_to_png_scale, file.tile_height * Pixi.editor.popups.export_to_png_scale); defer scaled_image.deinit(); try scaled_image.writeToFile(full_path, .png); } else { try sprite_image.writeToFile(full_path, .png); } - Pixi.app.popups.export_to_png = false; + Pixi.editor.popups.export_to_png = false; }, .export_animation => { @@ -215,7 +215,7 @@ pub fn draw() !void { var i: usize = animation.start; while (i < animation.start + animation.length) : (i += 1) { - if (Pixi.app.popups.export_to_png_preserve_names) { + if (Pixi.editor.popups.export_to_png_preserve_names) { const folder = response.path; const name = file.sprites.items(.name)[i]; const full_path = try std.fmt.allocPrintZ(Pixi.app.allocator, "{s}{c}{s}.png", .{ folder, std.fs.path.sep, name }); @@ -223,14 +223,14 @@ pub fn draw() !void { var sprite_image = try file.spriteToImage(i, true); defer sprite_image.deinit(); - if (Pixi.app.popups.export_to_png_scale > 1) { - var scaled_image = sprite_image.resize(file.tile_width * Pixi.app.popups.export_to_png_scale, file.tile_height * Pixi.app.popups.export_to_png_scale); + if (Pixi.editor.popups.export_to_png_scale > 1) { + var scaled_image = sprite_image.resize(file.tile_width * Pixi.editor.popups.export_to_png_scale, file.tile_height * Pixi.editor.popups.export_to_png_scale); defer scaled_image.deinit(); try scaled_image.writeToFile(full_path, .png); } else { try sprite_image.writeToFile(full_path, .png); } - Pixi.app.popups.export_to_png = false; + Pixi.editor.popups.export_to_png = false; } else { const base_name = std.fs.path.basename(response.path); if (std.mem.indexOf(u8, response.path, base_name)) |folder_index| { @@ -245,14 +245,14 @@ pub fn draw() !void { var sprite_image = try file.spriteToImage(i, true); defer sprite_image.deinit(); - if (Pixi.app.popups.export_to_png_scale > 1) { - var scaled_image = sprite_image.resize(file.tile_width * Pixi.app.popups.export_to_png_scale, file.tile_height * Pixi.app.popups.export_to_png_scale); + if (Pixi.editor.popups.export_to_png_scale > 1) { + var scaled_image = sprite_image.resize(file.tile_width * Pixi.editor.popups.export_to_png_scale, file.tile_height * Pixi.editor.popups.export_to_png_scale); defer scaled_image.deinit(); try scaled_image.writeToFile(full_path, .png); } else { try sprite_image.writeToFile(full_path, .png); } - Pixi.app.popups.export_to_png = false; + Pixi.editor.popups.export_to_png = false; } } } @@ -271,18 +271,18 @@ pub fn draw() !void { } try file.layers.items(.texture)[file.selected_layer_index].image.writeToFile(full_path, .png); - Pixi.app.popups.export_to_png = false; + Pixi.editor.popups.export_to_png = false; }, .export_all_layers => { var i: usize = 0; while (i < file.layers.slice().len) : (i += 1) { - if (Pixi.app.popups.export_to_png_preserve_names) { + if (Pixi.editor.popups.export_to_png_preserve_names) { const folder = response.path; const name = file.layers.items(.name)[i]; const full_path = try std.fmt.allocPrintZ(Pixi.app.allocator, "{s}{c}{s}.png", .{ folder, std.fs.path.sep, name }); try file.layers.items(.texture)[i].image.writeToFile(full_path, .png); - Pixi.app.popups.export_to_png = false; + Pixi.editor.popups.export_to_png = false; } else { const base_name = std.fs.path.basename(response.path); if (std.mem.indexOf(u8, response.path, base_name)) |folder_index| { @@ -295,7 +295,7 @@ pub fn draw() !void { const full_path = try std.fmt.allocPrintZ(Pixi.app.allocator, "{s}{s}_{d}.png", .{ folder, name, i }); try file.layers.items(.texture)[i].image.writeToFile(full_path, .png); - Pixi.app.popups.export_to_png = false; + Pixi.editor.popups.export_to_png = false; } } } @@ -318,7 +318,7 @@ pub fn draw() !void { } } try dest_image.writeToFile(response.path, .png); - Pixi.app.popups.export_to_png = false; + Pixi.editor.popups.export_to_png = false; }, else => {}, } @@ -326,7 +326,7 @@ pub fn draw() !void { switch (response.type) { .export_sprite, .export_animation, .export_layer, .export_all_layers, .export_full_image => { nfd.freePath(response.path); - Pixi.app.popups.file_dialog_response = null; + Pixi.editor.popups.file_dialog_response = null; }, else => {}, } diff --git a/src/editor/popups/file_confirm_close.zig b/src/editor/popups/file_confirm_close.zig index 75d6e77..3e68f82 100644 --- a/src/editor/popups/file_confirm_close.zig +++ b/src/editor/popups/file_confirm_close.zig @@ -4,12 +4,12 @@ const core = @import("mach").core; const imgui = @import("zig-imgui"); pub fn draw() !void { - if (Pixi.app.popups.file_confirm_close) { + if (Pixi.editor.popups.file_confirm_close) { imgui.openPopup("Confirm close...", imgui.PopupFlags_None); } else return; const popup_width = 350 * Pixi.app.content_scale[0]; - const popup_height = if (Pixi.app.popups.file_confirm_close_state == .one) 120 * Pixi.app.content_scale[1] else 250 * Pixi.app.content_scale[1]; + const popup_height = if (Pixi.editor.popups.file_confirm_close_state == .one) 120 * Pixi.app.content_scale[1] else 250 * Pixi.app.content_scale[1]; const window_size = Pixi.app.window_size; const window_center: [2]f32 = .{ window_size[0] / 2.0, window_size[1] / 2.0 }; @@ -29,7 +29,7 @@ pub fn draw() !void { if (imgui.beginPopupModal( "Confirm close...", - &Pixi.app.popups.file_confirm_close, + &Pixi.editor.popups.file_confirm_close, modal_flags, )) { defer imgui.endPopup(); @@ -40,9 +40,9 @@ pub fn draw() !void { const full_width = popup_width - (style.frame_padding.x * 2.0 * Pixi.app.content_scale[0]) - imgui.calcTextSize("Name").x; const third_width = (popup_width - (style.frame_padding.x * 2.0 * Pixi.app.content_scale[0]) - spacing * 2.0) / 3.0; - switch (Pixi.app.popups.file_confirm_close_state) { + switch (Pixi.editor.popups.file_confirm_close_state) { .one => { - if (Pixi.Editor.getFile(Pixi.app.popups.file_confirm_close_index)) |file| { + if (Pixi.Editor.getFile(Pixi.editor.popups.file_confirm_close_index)) |file| { const base_name = std.fs.path.basename(file.path); const file_name = try std.fmt.allocPrintZ(Pixi.app.allocator, "The file {s} has unsaved changes, are you sure you want to close?", .{base_name}); defer Pixi.app.allocator.free(file_name); @@ -78,15 +78,15 @@ pub fn draw() !void { imgui.pushItemWidth(full_width); if (imgui.buttonEx("Cancel", .{ .x = third_width, .y = 0.0 })) { - Pixi.app.popups.file_confirm_close = false; - if (Pixi.app.popups.file_confirm_close_exit) - Pixi.app.popups.file_confirm_close_exit = false; + Pixi.editor.popups.file_confirm_close = false; + if (Pixi.editor.popups.file_confirm_close_exit) + Pixi.editor.popups.file_confirm_close_exit = false; } imgui.sameLine(); - if (imgui.buttonEx(if (Pixi.app.popups.file_confirm_close_state == .one) "Close" else "Close All", .{ .x = third_width, .y = 0.0 })) { - switch (Pixi.app.popups.file_confirm_close_state) { + if (imgui.buttonEx(if (Pixi.editor.popups.file_confirm_close_state == .one) "Close" else "Close All", .{ .x = third_width, .y = 0.0 })) { + switch (Pixi.editor.popups.file_confirm_close_state) { .one => { - try Pixi.Editor.forceCloseFile(Pixi.app.popups.file_confirm_close_index); + try Pixi.Editor.forceCloseFile(Pixi.editor.popups.file_confirm_close_index); }, .all => { const len = Pixi.app.open_files.items.len; @@ -97,16 +97,16 @@ pub fn draw() !void { }, else => unreachable, } - Pixi.app.popups.file_confirm_close = false; + Pixi.editor.popups.file_confirm_close = false; } imgui.sameLine(); - if (imgui.buttonEx(if (Pixi.app.popups.file_confirm_close_state == .one) "Save & Close" else "Save & Close All", .{ .x = third_width, .y = 0.0 })) { - switch (Pixi.app.popups.file_confirm_close_state) { + if (imgui.buttonEx(if (Pixi.editor.popups.file_confirm_close_state == .one) "Save & Close" else "Save & Close All", .{ .x = third_width, .y = 0.0 })) { + switch (Pixi.editor.popups.file_confirm_close_state) { .one => { - if (Pixi.Editor.getFile(Pixi.app.popups.file_confirm_close_index)) |file| { + if (Pixi.Editor.getFile(Pixi.editor.popups.file_confirm_close_index)) |file| { _ = try file.save(); } - try Pixi.Editor.closeFile(Pixi.app.popups.file_confirm_close_index); + try Pixi.Editor.closeFile(Pixi.editor.popups.file_confirm_close_index); }, .all => { try Pixi.Editor.saveAllFiles(); @@ -115,16 +115,16 @@ pub fn draw() !void { else => unreachable, } - Pixi.app.popups.file_confirm_close = false; + Pixi.editor.popups.file_confirm_close = false; } - if (Pixi.app.popups.file_confirm_close_exit and !Pixi.app.popups.file_confirm_close) { - Pixi.app.popups.file_confirm_close_exit = false; + if (Pixi.editor.popups.file_confirm_close_exit and !Pixi.editor.popups.file_confirm_close) { + Pixi.editor.popups.file_confirm_close_exit = false; Pixi.app.should_close = true; } imgui.popItemWidth(); } - if (!Pixi.app.popups.file_confirm_close) - Pixi.app.popups.file_confirm_close_exit = false; + if (!Pixi.editor.popups.file_confirm_close) + Pixi.editor.popups.file_confirm_close_exit = false; } diff --git a/src/editor/popups/file_setup.zig b/src/editor/popups/file_setup.zig index 5255ac9..324faa4 100644 --- a/src/editor/popups/file_setup.zig +++ b/src/editor/popups/file_setup.zig @@ -4,7 +4,7 @@ const core = @import("mach").core; const imgui = @import("zig-imgui"); pub fn draw() !void { - if (Pixi.app.popups.file_setup) { + if (Pixi.editor.popups.file_setup) { imgui.openPopup("File Setup...", imgui.PopupFlags_None); } else return; @@ -27,14 +27,14 @@ pub fn draw() !void { modal_flags |= imgui.WindowFlags_NoResize; modal_flags |= imgui.WindowFlags_NoCollapse; - if (imgui.beginPopupModal("File Setup...", &Pixi.app.popups.file_setup, modal_flags)) { + if (imgui.beginPopupModal("File Setup...", &Pixi.editor.popups.file_setup, modal_flags)) { defer imgui.endPopup(); const style = imgui.getStyle(); const full_width = popup_width - (style.frame_padding.x * 3 * Pixi.app.content_scale[0]) - imgui.calcTextSize("Tile Height").x; - const base_name = std.fs.path.basename(&Pixi.app.popups.file_setup_path); - const base_name_index = if (std.mem.indexOf(u8, Pixi.app.popups.file_setup_path[0..], base_name)) |index| index else 0; + const base_name = std.fs.path.basename(&Pixi.editor.popups.file_setup_path); + const base_name_index = if (std.mem.indexOf(u8, Pixi.editor.popups.file_setup_path[0..], base_name)) |index| index else 0; imgui.spacing(); imgui.pushItemWidth(full_width); @@ -45,53 +45,53 @@ pub fn draw() !void { const enter = imgui.inputText( "Name", - Pixi.app.popups.file_setup_path[base_name_index..], - Pixi.app.popups.file_setup_path[base_name_index..].len, + Pixi.editor.popups.file_setup_path[base_name_index..], + Pixi.editor.popups.file_setup_path[base_name_index..].len, input_text_flags, ); const max_file_size = Pixi.app.settings.max_file_size; - const max_file_width = switch (Pixi.app.popups.file_setup_state) { - .slice, .import_png => Pixi.app.popups.file_setup_width, + const max_file_width = switch (Pixi.editor.popups.file_setup_state) { + .slice, .import_png => Pixi.editor.popups.file_setup_width, else => max_file_size[0], }; - const max_file_height = switch (Pixi.app.popups.file_setup_state) { - .slice, .import_png => Pixi.app.popups.file_setup_height, + const max_file_height = switch (Pixi.editor.popups.file_setup_state) { + .slice, .import_png => Pixi.editor.popups.file_setup_height, else => max_file_size[1], }; imgui.spacing(); - if (inputIntClamp("Tile Width", &Pixi.app.popups.file_setup_tile_size[0], 1, max_file_width)) { - Pixi.app.popups.file_setup_tiles[0] = std.math.clamp(switch (Pixi.app.popups.file_setup_state) { - .slice, .import_png => @divTrunc(max_file_width, Pixi.app.popups.file_setup_tile_size[0]), - else => Pixi.app.popups.file_setup_tiles[0], - }, 1, @divTrunc(max_file_width, Pixi.app.popups.file_setup_tile_size[0])); + if (inputIntClamp("Tile Width", &Pixi.editor.popups.file_setup_tile_size[0], 1, max_file_width)) { + Pixi.editor.popups.file_setup_tiles[0] = std.math.clamp(switch (Pixi.editor.popups.file_setup_state) { + .slice, .import_png => @divTrunc(max_file_width, Pixi.editor.popups.file_setup_tile_size[0]), + else => Pixi.editor.popups.file_setup_tiles[0], + }, 1, @divTrunc(max_file_width, Pixi.editor.popups.file_setup_tile_size[0])); } - if (inputIntClamp("Tile Height", &Pixi.app.popups.file_setup_tile_size[1], 1, max_file_height)) { - Pixi.app.popups.file_setup_tiles[1] = std.math.clamp(switch (Pixi.app.popups.file_setup_state) { - .slice, .import_png => @divTrunc(max_file_height, Pixi.app.popups.file_setup_tile_size[1]), - else => Pixi.app.popups.file_setup_tiles[1], - }, 1, @divTrunc(max_file_height, Pixi.app.popups.file_setup_tile_size[1])); + if (inputIntClamp("Tile Height", &Pixi.editor.popups.file_setup_tile_size[1], 1, max_file_height)) { + Pixi.editor.popups.file_setup_tiles[1] = std.math.clamp(switch (Pixi.editor.popups.file_setup_state) { + .slice, .import_png => @divTrunc(max_file_height, Pixi.editor.popups.file_setup_tile_size[1]), + else => Pixi.editor.popups.file_setup_tiles[1], + }, 1, @divTrunc(max_file_height, Pixi.editor.popups.file_setup_tile_size[1])); } imgui.spacing(); imgui.separator(); imgui.spacing(); - switch (Pixi.app.popups.file_setup_state) { + switch (Pixi.editor.popups.file_setup_state) { .slice, .import_png => imgui.beginDisabled(true), else => {}, } - if (imgui.inputInt("Tiles Wide", &Pixi.app.popups.file_setup_tiles[0])) { - Pixi.app.popups.file_setup_tiles[0] = std.math.clamp(Pixi.app.popups.file_setup_tiles[0], 1, @divTrunc(max_file_width, Pixi.app.popups.file_setup_tile_size[0])); + if (imgui.inputInt("Tiles Wide", &Pixi.editor.popups.file_setup_tiles[0])) { + Pixi.editor.popups.file_setup_tiles[0] = std.math.clamp(Pixi.editor.popups.file_setup_tiles[0], 1, @divTrunc(max_file_width, Pixi.editor.popups.file_setup_tile_size[0])); } - if (imgui.inputInt("Tiles Tall", &Pixi.app.popups.file_setup_tiles[1])) { - Pixi.app.popups.file_setup_tiles[1] = std.math.clamp(Pixi.app.popups.file_setup_tiles[1], 1, @divTrunc(max_file_height, Pixi.app.popups.file_setup_tile_size[1])); + if (imgui.inputInt("Tiles Tall", &Pixi.editor.popups.file_setup_tiles[1])) { + Pixi.editor.popups.file_setup_tiles[1] = std.math.clamp(Pixi.editor.popups.file_setup_tiles[1], 1, @divTrunc(max_file_height, Pixi.editor.popups.file_setup_tile_size[1])); } - switch (Pixi.app.popups.file_setup_state) { + switch (Pixi.editor.popups.file_setup_state) { .slice, .import_png => imgui.endDisabled(), else => {}, } @@ -99,24 +99,24 @@ pub fn draw() !void { imgui.spacing(); const combined_size: [2]i32 = .{ - Pixi.app.popups.file_setup_tile_size[0] * Pixi.app.popups.file_setup_tiles[0], - Pixi.app.popups.file_setup_tile_size[1] * Pixi.app.popups.file_setup_tiles[1], + Pixi.editor.popups.file_setup_tile_size[0] * Pixi.editor.popups.file_setup_tiles[0], + Pixi.editor.popups.file_setup_tile_size[1] * Pixi.editor.popups.file_setup_tiles[1], }; - const sizes_match = switch (Pixi.app.popups.file_setup_state) { - .slice, .import_png => combined_size[0] == Pixi.app.popups.file_setup_width and combined_size[1] == Pixi.app.popups.file_setup_height, + const sizes_match = switch (Pixi.editor.popups.file_setup_state) { + .slice, .import_png => combined_size[0] == Pixi.editor.popups.file_setup_width and combined_size[1] == Pixi.editor.popups.file_setup_height, else => true, }; imgui.text( "Image size: %dx%d", - if (!sizes_match) Pixi.app.popups.file_setup_width else combined_size[0], - if (!sizes_match) Pixi.app.popups.file_setup_height else combined_size[1], + if (!sizes_match) Pixi.editor.popups.file_setup_width else combined_size[0], + if (!sizes_match) Pixi.editor.popups.file_setup_height else combined_size[1], ); imgui.spacing(); - const file_setup_path = std.mem.trimRight(u8, &Pixi.app.popups.file_setup_path, "\u{0}"); - const ext = std.fs.path.extension(&Pixi.app.popups.file_setup_path); + const file_setup_path = std.mem.trimRight(u8, &Pixi.editor.popups.file_setup_path, "\u{0}"); + const ext = std.fs.path.extension(&Pixi.editor.popups.file_setup_path); if (!sizes_match) { imgui.textColored(Pixi.editor.theme.text_red.toImguiVec4(), "Tile sizes and count do not match image size! %dx%d", combined_size[0], combined_size[1]); @@ -129,7 +129,7 @@ pub fn draw() !void { const spacing = 5.0 * Pixi.app.content_scale[0]; const half_width = (popup_width - (style.frame_padding.x * 2.0 * Pixi.app.content_scale[0]) - spacing) / 2.0; if (imgui.buttonEx("Cancel", .{ .x = half_width, .y = 0.0 })) { - Pixi.app.popups.fileSetupClose(); + Pixi.editor.popups.fileSetupClose(); } imgui.sameLineEx(0.0, spacing); if (!sizes_match) { @@ -138,7 +138,7 @@ pub fn draw() !void { if (imgui.buttonEx("Ok", .{ .x = half_width, .y = 0.0 }) or enter) { if (ext.len > 0 and std.mem.eql(u8, ".pixi", ext[0..5])) { - switch (Pixi.app.popups.file_setup_state) { + switch (Pixi.editor.popups.file_setup_state) { .new => { if (try Pixi.Editor.newFile(try Pixi.app.allocator.dupeZ(u8, file_setup_path), null)) { if (Pixi.Editor.getFile(0)) |file| { @@ -147,7 +147,7 @@ pub fn draw() !void { } }, .import_png => { - const file_setup_png_path = std.mem.trimRight(u8, &Pixi.app.popups.file_setup_png_path, "\u{0}"); + const file_setup_png_path = std.mem.trimRight(u8, &Pixi.editor.popups.file_setup_png_path, "\u{0}"); if (try Pixi.Editor.importPng(try Pixi.app.allocator.dupeZ(u8, file_setup_png_path), try Pixi.app.allocator.dupeZ(u8, file_setup_path))) { if (Pixi.Editor.getFile(0)) |file| { try file.save(); @@ -155,17 +155,17 @@ pub fn draw() !void { } }, .slice => { - if (Pixi.Editor.getFileIndex(Pixi.app.popups.file_setup_path[0..file_setup_path.len :0])) |index| { + if (Pixi.Editor.getFileIndex(Pixi.editor.popups.file_setup_path[0..file_setup_path.len :0])) |index| { if (Pixi.Editor.getFile(index)) |file| { - file.tile_width = @as(u32, @intCast(Pixi.app.popups.file_setup_tile_size[0])); - file.tile_height = @as(u32, @intCast(Pixi.app.popups.file_setup_tile_size[1])); + file.tile_width = @as(u32, @intCast(Pixi.editor.popups.file_setup_tile_size[0])); + file.tile_height = @as(u32, @intCast(Pixi.editor.popups.file_setup_tile_size[1])); } } }, else => {}, } - Pixi.app.popups.fileSetupClose(); + Pixi.editor.popups.fileSetupClose(); } } diff --git a/src/editor/popups/heightmap.zig b/src/editor/popups/heightmap.zig index 1bb0af7..c4e496c 100644 --- a/src/editor/popups/heightmap.zig +++ b/src/editor/popups/heightmap.zig @@ -5,7 +5,7 @@ const imgui = @import("zig-imgui"); pub fn draw() !void { if (Pixi.Editor.getFile(Pixi.app.open_file_index)) |file| { - if (Pixi.app.popups.heightmap) { + if (Pixi.editor.popups.heightmap) { imgui.openPopup("Heightmap", imgui.PopupFlags_None); } else return; @@ -30,7 +30,7 @@ pub fn draw() !void { if (imgui.beginPopupModal( "Heightmap", - &Pixi.app.popups.heightmap, + &Pixi.editor.popups.heightmap, modal_flags, )) { defer imgui.endPopup(); @@ -45,7 +45,7 @@ pub fn draw() !void { imgui.spacing(); if (imgui.buttonEx("Cancel", .{ .x = half_width, .y = 0.0 })) { - Pixi.app.popups.heightmap = false; + Pixi.editor.popups.heightmap = false; } imgui.sameLine(); if (imgui.buttonEx("Create", .{ .x = half_width, .y = 0.0 })) { @@ -55,7 +55,7 @@ pub fn draw() !void { .id = file.newId(), }; try file.history.append(.{ .heightmap_restore_delete = .{ .action = .delete } }); - Pixi.app.popups.heightmap = false; + Pixi.editor.popups.heightmap = false; Pixi.app.tools.set(.heightmap); } } diff --git a/src/editor/popups/layer_setup.zig b/src/editor/popups/layer_setup.zig index c84fef3..5df9809 100644 --- a/src/editor/popups/layer_setup.zig +++ b/src/editor/popups/layer_setup.zig @@ -5,13 +5,13 @@ const imgui = @import("zig-imgui"); pub fn draw() !void { if (Pixi.Editor.getFile(Pixi.app.open_file_index)) |file| { - const dialog_name = switch (Pixi.app.popups.layer_setup_state) { + const dialog_name = switch (Pixi.editor.popups.layer_setup_state) { .none => "New Layer...", .rename => "Rename Layer...", .duplicate => "Duplicate Layer...", }; - if (Pixi.app.popups.layer_setup) { + if (Pixi.editor.popups.layer_setup) { imgui.openPopup(dialog_name, imgui.PopupFlags_None); } else return; @@ -36,7 +36,7 @@ pub fn draw() !void { if (imgui.beginPopupModal( dialog_name, - &Pixi.app.popups.layer_setup, + &Pixi.editor.popups.layer_setup, modal_flags, )) { defer imgui.endPopup(); @@ -55,46 +55,46 @@ pub fn draw() !void { const enter = imgui.inputText( "Name", - Pixi.app.popups.layer_setup_name[0.. :0], - Pixi.app.popups.layer_setup_name[0.. :0].len, + Pixi.editor.popups.layer_setup_name[0.. :0], + Pixi.editor.popups.layer_setup_name[0.. :0].len, input_text_flags, ); imgui.setCursorPosY(popup_height - imgui.getTextLineHeightWithSpacing() * 2.0); if (imgui.buttonEx("Cancel", .{ .x = half_width, .y = 0.0 })) { - Pixi.app.popups.layer_setup = false; + Pixi.editor.popups.layer_setup = false; } imgui.sameLine(); if (imgui.buttonEx("Ok", .{ .x = half_width, .y = 0.0 }) or enter) { - switch (Pixi.app.popups.layer_setup_state) { + switch (Pixi.editor.popups.layer_setup_state) { .none => { - const new_name = std.mem.trimRight(u8, Pixi.app.popups.layer_setup_name[0..], "\u{0}"); + const new_name = std.mem.trimRight(u8, Pixi.editor.popups.layer_setup_name[0..], "\u{0}"); if (std.mem.indexOf(u8, new_name, "\u{0}")) |index| { - try file.createLayer(Pixi.app.popups.layer_setup_name[0..index :0]); + try file.createLayer(Pixi.editor.popups.layer_setup_name[0..index :0]); } else { - try file.createLayer(Pixi.app.popups.layer_setup_name[0..new_name.len :0]); + try file.createLayer(Pixi.editor.popups.layer_setup_name[0..new_name.len :0]); } }, .rename => { - const new_name = std.mem.trimRight(u8, Pixi.app.popups.layer_setup_name[0..], "\u{0}"); + const new_name = std.mem.trimRight(u8, Pixi.editor.popups.layer_setup_name[0..], "\u{0}"); if (std.mem.indexOf(u8, new_name, "\u{0}")) |index| { - try file.renameLayer(Pixi.app.popups.layer_setup_name[0..index :0], Pixi.app.popups.layer_setup_index); + try file.renameLayer(Pixi.editor.popups.layer_setup_name[0..index :0], Pixi.editor.popups.layer_setup_index); } else { - try file.renameLayer(Pixi.app.popups.layer_setup_name[0..new_name.len :0], Pixi.app.popups.layer_setup_index); + try file.renameLayer(Pixi.editor.popups.layer_setup_name[0..new_name.len :0], Pixi.editor.popups.layer_setup_index); } }, .duplicate => { - const new_name = std.mem.trimRight(u8, Pixi.app.popups.layer_setup_name[0.. :0], "\u{0}"); + const new_name = std.mem.trimRight(u8, Pixi.editor.popups.layer_setup_name[0.. :0], "\u{0}"); if (std.mem.indexOf(u8, new_name, "\u{0}")) |index| { - try file.duplicateLayer(Pixi.app.popups.layer_setup_name[0..index :0], Pixi.app.popups.layer_setup_index); + try file.duplicateLayer(Pixi.editor.popups.layer_setup_name[0..index :0], Pixi.editor.popups.layer_setup_index); } else { - try file.duplicateLayer(Pixi.app.popups.layer_setup_name[0..new_name.len :0], Pixi.app.popups.layer_setup_index); + try file.duplicateLayer(Pixi.editor.popups.layer_setup_name[0..new_name.len :0], Pixi.editor.popups.layer_setup_index); } }, } - Pixi.app.popups.layer_setup_state = .none; - Pixi.app.popups.layer_setup = false; + Pixi.editor.popups.layer_setup_state = .none; + Pixi.editor.popups.layer_setup = false; } imgui.popItemWidth(); diff --git a/src/editor/popups/references.zig b/src/editor/popups/references.zig index 564854d..9b73f06 100644 --- a/src/editor/popups/references.zig +++ b/src/editor/popups/references.zig @@ -6,7 +6,7 @@ const imgui = @import("zig-imgui"); var open: bool = false; pub fn draw() !void { - if (!Pixi.app.popups.references) return; + if (!Pixi.editor.popups.references) return; const popup_size = 200 * Pixi.app.content_scale[0]; @@ -32,7 +32,7 @@ pub fn draw() !void { if (imgui.begin( "References", - &Pixi.app.popups.references, + &Pixi.editor.popups.references, popup_flags, )) { var ref_flags: imgui.TabBarFlags = 0; diff --git a/src/editor/popups/rename.zig b/src/editor/popups/rename.zig index 1e98b6f..42c8e0f 100644 --- a/src/editor/popups/rename.zig +++ b/src/editor/popups/rename.zig @@ -3,21 +3,24 @@ const Pixi = @import("../../Pixi.zig"); const core = @import("mach").core; const imgui = @import("zig-imgui"); -pub fn draw() !void { - const dialog_name = switch (Pixi.app.popups.rename_state) { +const Popups = @import("Popups.zig"); +const Editor = Pixi.Editor; + +pub fn draw(popups: *Popups, app: *Pixi) !void { + const dialog_name = switch (popups.rename_state) { .none => "None...", .rename => "Rename...", .duplicate => "Duplicate...", }; - if (Pixi.app.popups.rename) { + if (popups.rename) { imgui.openPopup(dialog_name, imgui.PopupFlags_None); } else return; - const popup_width = 350 * Pixi.app.content_scale[0]; - const popup_height = 115 * Pixi.app.content_scale[1]; + const popup_width = 350 * app.content_scale[0]; + const popup_height = 115 * app.content_scale[1]; - const window_size = Pixi.app.window_size; + const window_size = app.window_size; const window_center: [2]f32 = .{ window_size[0] / 2.0, window_size[1] / 2.0 }; imgui.setNextWindowPos(.{ @@ -33,18 +36,18 @@ pub fn draw() !void { modal_flags |= imgui.WindowFlags_NoResize; modal_flags |= imgui.WindowFlags_NoCollapse; - if (imgui.beginPopupModal(dialog_name, &Pixi.app.popups.rename, modal_flags)) { + if (imgui.beginPopupModal(dialog_name, &popups.rename, modal_flags)) { defer imgui.endPopup(); imgui.spacing(); const style = imgui.getStyle(); const spacing = style.item_spacing.x; - const full_width = popup_width - (style.frame_padding.x * 2.0 * Pixi.app.content_scale[0]) - imgui.calcTextSize("Name").x; - const half_width = (popup_width - (style.frame_padding.x * 2.0 * Pixi.app.content_scale[0]) - spacing) / 2.0; + const full_width = popup_width - (style.frame_padding.x * 2.0 * app.content_scale[0]) - imgui.calcTextSize("Name").x; + const half_width = (popup_width - (style.frame_padding.x * 2.0 * app.content_scale[0]) - spacing) / 2.0; - const base_name = std.fs.path.basename(Pixi.app.popups.rename_path[0..]); + const base_name = std.fs.path.basename(popups.rename_path[0..]); var base_index: usize = 0; - if (std.mem.indexOf(u8, Pixi.app.popups.rename_path[0..], base_name)) |index| { + if (std.mem.indexOf(u8, popups.rename_path[0..], base_name)) |index| { base_index = index; } imgui.pushItemWidth(full_width); @@ -55,41 +58,41 @@ pub fn draw() !void { const enter = imgui.inputText( "Name", - Pixi.app.popups.rename_path[base_index.. :0], - Pixi.app.popups.rename_path[base_index.. :0].len, + popups.rename_path[base_index.. :0], + popups.rename_path[base_index.. :0].len, input_text_flags, ); if (imgui.buttonEx("Cancel", .{ .x = half_width, .y = 0.0 })) { - Pixi.app.popups.rename = false; + popups.rename = false; } imgui.sameLine(); if (imgui.buttonEx("Ok", .{ .x = half_width, .y = 0.0 }) or enter) { - switch (Pixi.app.popups.rename_state) { + switch (popups.rename_state) { .rename => { - const old_path = std.mem.trimRight(u8, Pixi.app.popups.rename_old_path[0..], "\u{0}"); - const new_path = std.mem.trimRight(u8, Pixi.app.popups.rename_path[0..], "\u{0}"); + const old_path = std.mem.trimRight(u8, popups.rename_old_path[0..], "\u{0}"); + const new_path = std.mem.trimRight(u8, popups.rename_path[0..], "\u{0}"); try std.fs.renameAbsolute(old_path[0..], new_path[0..]); - const old_path_z = Pixi.app.popups.rename_old_path[0..old_path.len :0]; - for (Pixi.app.open_files.items) |*open_file| { + const old_path_z = popups.rename_old_path[0..old_path.len :0]; + for (app.open_files.items) |*open_file| { if (std.mem.eql(u8, open_file.path, old_path_z)) { - Pixi.app.allocator.free(open_file.path); - open_file.path = try Pixi.app.allocator.dupeZ(u8, new_path); + app.allocator.free(open_file.path); + open_file.path = try app.allocator.dupeZ(u8, new_path); } } }, .duplicate => { - const original_path = std.mem.trimRight(u8, Pixi.app.popups.rename_old_path[0..], "\u{0}"); - const new_path = std.mem.trimRight(u8, Pixi.app.popups.rename_path[0..], "\u{0}"); + const original_path = std.mem.trimRight(u8, popups.rename_old_path[0..], "\u{0}"); + const new_path = std.mem.trimRight(u8, popups.rename_path[0..], "\u{0}"); try std.fs.copyFileAbsolute(original_path, new_path, .{}); }, else => unreachable, } - Pixi.app.popups.rename_state = .none; - Pixi.app.popups.rename = false; + popups.rename_state = .none; + popups.rename = false; } imgui.popItemWidth(); diff --git a/src/input/Hotkeys.zig b/src/input/Hotkeys.zig index 5ddbb42..45b72cb 100644 --- a/src/input/Hotkeys.zig +++ b/src/input/Hotkeys.zig @@ -174,7 +174,7 @@ pub fn process(self: *Self) !void { if (self.hotkey(.{ .proc = .export_png })) |hk| { if (hk.pressed()) - Pixi.app.popups.export_to_png = true; + Pixi.editor.popups.export_to_png = true; } if (self.hotkey(.{ .proc = .size_up })) |hk| { @@ -340,7 +340,7 @@ pub fn process(self: *Self) !void { if (self.hotkey(.{ .proc = .folder })) |hk| { if (hk.pressed()) { - Pixi.app.popups.file_dialog_request = .{ + Pixi.editor.popups.file_dialog_request = .{ .state = .folder, .type = .project, }; @@ -349,7 +349,7 @@ pub fn process(self: *Self) !void { if (self.hotkey(.{ .proc = .toggle_references })) |hk| { if (hk.pressed()) { - Pixi.app.popups.references = !Pixi.app.popups.references; + Pixi.editor.popups.references = !Pixi.editor.popups.references; } } diff --git a/src/input/input.zig b/src/input/input.zig index f701639..3fedb0a 100644 --- a/src/input/input.zig +++ b/src/input/input.zig @@ -4,7 +4,7 @@ pub const Mouse = @import("Mouse.zig"); pub const Hotkeys = @import("Hotkeys.zig"); pub fn process() !void { - if (!Pixi.app.popups.anyPopupOpen()) { + if (!Pixi.editor.popups.anyPopupOpen()) { try Pixi.app.hotkeys.process(); } } diff --git a/src/storage/internal.zig b/src/storage/internal.zig index 32050ff..ab57c2d 100644 --- a/src/storage/internal.zig +++ b/src/storage/internal.zig @@ -112,7 +112,7 @@ pub const PixiFile = struct { if (self.layer != null) { self.visible = true; } else { - Pixi.app.popups.heightmap = true; + Pixi.editor.popups.heightmap = true; } } @@ -719,22 +719,22 @@ pub const PixiFile = struct { 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 (tile_index >= Pixi.app.popups.animation_start) { - Pixi.app.popups.animation_length = (tile_index - Pixi.app.popups.animation_start) + 1; + if (tile_index >= Pixi.editor.popups.animation_start) { + Pixi.editor.popups.animation_length = (tile_index - Pixi.editor.popups.animation_start) + 1; } else { - Pixi.app.popups.animation_start = tile_index; - Pixi.app.popups.animation_length = 1; + Pixi.editor.popups.animation_start = tile_index; + Pixi.editor.popups.animation_length = 1; } if (if (Pixi.app.mouse.button(.primary)) |primary| primary.pressed() else false) - Pixi.app.popups.animation_start = tile_index; + Pixi.editor.popups.animation_start = tile_index; if (if (Pixi.app.mouse.button(.primary)) |primary| primary.released() else false) { if (Pixi.app.hotkeys.hotkey(.{ .proc = .primary })) |primary| { if (primary.down()) { var valid: bool = true; - var i: usize = Pixi.app.popups.animation_start; - while (i < Pixi.app.popups.animation_start + Pixi.app.popups.animation_length) : (i += 1) { + var i: usize = Pixi.editor.popups.animation_start; + while (i < Pixi.editor.popups.animation_start + Pixi.editor.popups.animation_length) : (i += 1) { if (file.getAnimationIndexFromSpriteIndex(i)) |_| { valid = false; break; @@ -742,19 +742,19 @@ pub const PixiFile = struct { } if (valid) { // Create new animation - Pixi.app.popups.animation_name = [_:0]u8{0} ** 128; + Pixi.editor.popups.animation_name = [_:0]u8{0} ** 128; const new_name = "New_Animation"; - @memcpy(Pixi.app.popups.animation_name[0..new_name.len], new_name); - Pixi.app.popups.animation_state = .create; - Pixi.app.popups.animation_fps = Pixi.app.popups.animation_length; - Pixi.app.popups.animation = true; + @memcpy(Pixi.editor.popups.animation_name[0..new_name.len], new_name); + Pixi.editor.popups.animation_state = .create; + Pixi.editor.popups.animation_fps = Pixi.editor.popups.animation_length; + Pixi.editor.popups.animation = true; } } else { if (file.animations.slice().len > 0) { const animation = file.animations.slice().get(file.selected_animation_index); var valid: bool = true; - var i: usize = Pixi.app.popups.animation_start; - while (i < Pixi.app.popups.animation_start + Pixi.app.popups.animation_length) : (i += 1) { + var i: usize = Pixi.editor.popups.animation_start; + while (i < Pixi.editor.popups.animation_start + Pixi.editor.popups.animation_length) : (i += 1) { if (file.getAnimationIndexFromSpriteIndex(i)) |match_index| { if (match_index != file.selected_animation_index) { valid = false; @@ -782,8 +782,8 @@ pub const PixiFile = struct { file.sprites.set(sprite_index, sprite); } - file.animations.items(.start)[file.selected_animation_index] = Pixi.app.popups.animation_start; - file.animations.items(.length)[file.selected_animation_index] = Pixi.app.popups.animation_length; + file.animations.items(.start)[file.selected_animation_index] = Pixi.editor.popups.animation_start; + file.animations.items(.length)[file.selected_animation_index] = Pixi.editor.popups.animation_length; sprite_index = animation.start; var animation_index: usize = 0; @@ -1876,7 +1876,7 @@ pub const PixiFile = struct { } }; @memcpy(change.layer_name.name[0..file.layers.items(.name)[index].len], file.layers.items(.name)[index]); Pixi.app.allocator.free(file.layers.items(.name)[index]); - file.layers.items(.name)[Pixi.app.popups.layer_setup_index] = try Pixi.app.allocator.dupeZ(u8, name); + file.layers.items(.name)[Pixi.editor.popups.layer_setup_index] = try Pixi.app.allocator.dupeZ(u8, name); try file.history.append(change); }