Skip to content

Commit

Permalink
Editor: Move popups to Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
foxnne committed Jan 16, 2025
1 parent 58a099d commit 33b36b9
Show file tree
Hide file tree
Showing 26 changed files with 372 additions and 534 deletions.
31 changes: 16 additions & 15 deletions src/Pixi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -236,20 +237,20 @@ 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) {
.file => try nfd.openFileDialog(request.filter, initial),
.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,
};
Expand All @@ -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;
}
Expand All @@ -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;
},
Expand Down
176 changes: 0 additions & 176 deletions src/assets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};
Expand All @@ -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";
};
Expand All @@ -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";
};

Loading

0 comments on commit 33b36b9

Please sign in to comment.