Skip to content

Commit

Permalink
Pixi -> PixiFile
Browse files Browse the repository at this point in the history
  • Loading branch information
foxnne committed Dec 12, 2024
1 parent 12d5d09 commit 3c4fa4e
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 90 deletions.
4 changes: 2 additions & 2 deletions src/Pixi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub const PixiState = struct {
root_path: [:0]const u8 = undefined,
recents: Recents = undefined,
previous_atlas_export: ?[:0]const u8 = null,
open_files: std.ArrayList(storage.Internal.Pixi) = undefined,
open_files: std.ArrayList(storage.Internal.PixiFile) = undefined,
open_references: std.ArrayList(storage.Internal.Reference) = undefined,
pack_target: PackTarget = .project,
pack_camera: gfx.Camera = .{},
Expand Down Expand Up @@ -201,7 +201,7 @@ fn lateInit(pixi: *App, core: *Core) !void {

zstbi.init(core.allocator);

state.open_files = std.ArrayList(storage.Internal.Pixi).init(state.allocator);
state.open_files = std.ArrayList(storage.Internal.PixiFile).init(state.allocator);
state.open_references = std.ArrayList(storage.Internal.Reference).init(state.allocator);

state.colors.keyframe_palette = try storage.Internal.Palette.loadFromFile(assets.pear36_hex.path);
Expand Down
2 changes: 1 addition & 1 deletion src/editor/artboard/canvas.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Core = @import("mach").Core;
const imgui = @import("zig-imgui");
const zmath = @import("zmath");

pub fn draw(file: *pixi.storage.Internal.Pixi, core: *Core) void {
pub fn draw(file: *pixi.storage.Internal.PixiFile, core: *Core) void {
const transforming = file.transform_texture != null;

{
Expand Down
2 changes: 1 addition & 1 deletion src/editor/artboard/flipbook/canvas.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const pixi = @import("../../../Pixi.zig");
const core = @import("mach").core;
const imgui = @import("zig-imgui");

pub fn draw(file: *pixi.storage.Internal.Pixi) void {
pub fn draw(file: *pixi.storage.Internal.PixiFile) void {
const window_height = imgui.getWindowHeight();
const tile_width = @as(f32, @floatFromInt(file.tile_width));
const tile_height = @as(f32, @floatFromInt(file.tile_height));
Expand Down
4 changes: 2 additions & 2 deletions src/editor/artboard/flipbook/menu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const core = @import("mach").core;
const nfd = @import("nfd");
const imgui = @import("zig-imgui");

const History = pixi.storage.Internal.Pixi.History;
const History = pixi.storage.Internal.PixiFile.History;

pub fn draw(file: *pixi.storage.Internal.Pixi, mouse_ratio: f32) void {
pub fn draw(file: *pixi.storage.Internal.PixiFile, mouse_ratio: f32) void {
imgui.pushStyleVarImVec2(imgui.StyleVar_WindowPadding, .{ .x = 10.0 * pixi.content_scale[0], .y = 10.0 * pixi.content_scale[1] });
defer imgui.popStyleVar();
imgui.pushStyleColorImVec4(imgui.Col_Text, pixi.state.theme.text.toImguiVec4());
Expand Down
10 changes: 5 additions & 5 deletions src/editor/artboard/flipbook/timeline.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var ms_hovered: ?usize = null;
var keyframe_dragging: ?u32 = null;
var mouse_scroll_delta_y: f32 = 0.0;

pub fn draw(file: *pixi.storage.Internal.Pixi) void {
pub fn draw(file: *pixi.storage.Internal.PixiFile) void {
const window_height = imgui.getWindowHeight();
const window_width = imgui.getWindowWidth();
const tile_width = @as(f32, @floatFromInt(file.tile_width));
Expand Down Expand Up @@ -402,14 +402,14 @@ pub fn draw(file: *pixi.storage.Internal.Pixi) void {

const t: f32 = progress / total;

const tween_vertices: [4]pixi.storage.Internal.Pixi.TransformVertex = .{
const tween_vertices: [4]pixi.storage.Internal.PixiFile.TransformVertex = .{
.{ .position = zmath.lerp(from_frame.vertices[0].position, to_frame.vertices[0].position, t) },
.{ .position = zmath.lerp(from_frame.vertices[1].position, to_frame.vertices[1].position, t) },
.{ .position = zmath.lerp(from_frame.vertices[2].position, to_frame.vertices[2].position, t) },
.{ .position = zmath.lerp(from_frame.vertices[3].position, to_frame.vertices[3].position, t) },
};

const tween_pivot: pixi.storage.Internal.Pixi.TransformVertex = .{ .position = zmath.lerp(from_frame.pivot.position, to_frame.pivot.position, t) };
const tween_pivot: pixi.storage.Internal.PixiFile.TransformVertex = .{ .position = zmath.lerp(from_frame.pivot.position, to_frame.pivot.position, t) };

var from_rotation: f32 = from_frame.rotation;

Expand Down Expand Up @@ -497,7 +497,7 @@ pub fn draw(file: *pixi.storage.Internal.Pixi) void {
}
}

pub fn drawVerticalLines(file: *pixi.storage.Internal.Pixi, animation_length: usize, scroll: [2]f32) void {
pub fn drawVerticalLines(file: *pixi.storage.Internal.PixiFile, animation_length: usize, scroll: [2]f32) void {
const tile_width = @as(f32, @floatFromInt(file.tile_width));
const tile_height = @as(f32, @floatFromInt(file.tile_height));

Expand Down Expand Up @@ -592,7 +592,7 @@ pub fn drawVerticalLines(file: *pixi.storage.Internal.Pixi, animation_length: us
}
}

pub fn drawNodeArea(file: *pixi.storage.Internal.Pixi, animation_length: usize, scroll: [2]f32) void {
pub fn drawNodeArea(file: *pixi.storage.Internal.PixiFile, animation_length: usize, scroll: [2]f32) void {
const window_position = imgui.getWindowPos();
const window_hovered: bool = imgui.isWindowHovered(imgui.HoveredFlags_ChildWindows);

Expand Down
2 changes: 1 addition & 1 deletion src/editor/artboard/rulers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const pixi = @import("../../Pixi.zig");
const core = @import("mach").core;
const imgui = @import("zig-imgui");

pub fn draw(file: *pixi.storage.Internal.Pixi) void {
pub fn draw(file: *pixi.storage.Internal.PixiFile) void {
const file_width = @as(f32, @floatFromInt(file.width));
const file_height = @as(f32, @floatFromInt(file.height));
const tile_width = @as(f32, @floatFromInt(file.tile_width));
Expand Down
22 changes: 11 additions & 11 deletions src/editor/editor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn newFile(path: [:0]const u8, import_path: ?[:0]const u8) !bool {
}
}

var internal: pixi.storage.Internal.Pixi = .{
var internal: pixi.storage.Internal.PixiFile = .{
.path = try pixi.state.allocator.dupeZ(u8, path),
.width = @as(u32, @intCast(pixi.state.popups.file_setup_tiles[0] * pixi.state.popups.file_setup_tile_size[0])),
.height = @as(u32, @intCast(pixi.state.popups.file_setup_tiles[1] * pixi.state.popups.file_setup_tile_size[1])),
Expand All @@ -89,8 +89,8 @@ pub fn newFile(path: [:0]const u8, import_path: ?[:0]const u8) !bool {
.keyframe_transform_texture = undefined,
.deleted_animations = std.ArrayList(pixi.storage.Internal.Animation).init(pixi.state.allocator),
.background = undefined,
.history = pixi.storage.Internal.Pixi.History.init(pixi.state.allocator),
.buffers = pixi.storage.Internal.Pixi.Buffers.init(pixi.state.allocator),
.history = pixi.storage.Internal.PixiFile.History.init(pixi.state.allocator),
.buffers = pixi.storage.Internal.PixiFile.Buffers.init(pixi.state.allocator),
.temporary_layer = undefined,
.selection_layer = undefined,
};
Expand Down Expand Up @@ -164,12 +164,12 @@ pub fn importPng(path: [:0]const u8, new_file_path: [:0]const u8) !bool {
return try newFile(new_file_path, path);
}

pub fn loadFileAsync(path: [:0]const u8) !?pixi.storage.Internal.Pixi {
pub fn loadFileAsync(path: [:0]const u8) !?pixi.storage.Internal.PixiFile {
std.log.warn("loadFileAsync not implemented!", .{});
_ = path;
}

pub fn loadFile(path: [:0]const u8) !?pixi.storage.Internal.Pixi {
pub fn loadFile(path: [:0]const u8) !?pixi.storage.Internal.PixiFile {
if (!std.mem.eql(u8, std.fs.path.extension(path[0..path.len]), ".pixi"))
return null;

Expand All @@ -194,7 +194,7 @@ pub fn loadFile(path: [:0]const u8) !?pixi.storage.Internal.Pixi {

const external = parsed.value;

var internal: pixi.storage.Internal.Pixi = .{
var internal: pixi.storage.Internal.PixiFile = .{
.path = try pixi.state.allocator.dupeZ(u8, path),
.width = external.width,
.height = external.height,
Expand All @@ -211,8 +211,8 @@ pub fn loadFile(path: [:0]const u8) !?pixi.storage.Internal.Pixi {
.keyframe_transform_texture = undefined,
.deleted_animations = std.ArrayList(pixi.storage.Internal.Animation).init(pixi.state.allocator),
.background = undefined,
.history = pixi.storage.Internal.Pixi.History.init(pixi.state.allocator),
.buffers = pixi.storage.Internal.Pixi.Buffers.init(pixi.state.allocator),
.history = pixi.storage.Internal.PixiFile.History.init(pixi.state.allocator),
.buffers = pixi.storage.Internal.PixiFile.Buffers.init(pixi.state.allocator),
.temporary_layer = undefined,
.selection_layer = undefined,
};
Expand Down Expand Up @@ -402,7 +402,7 @@ pub fn getFileIndex(path: [:0]const u8) ?usize {
return null;
}

pub fn getFile(index: usize) ?*pixi.storage.Internal.Pixi {
pub fn getFile(index: usize) ?*pixi.storage.Internal.PixiFile {
if (pixi.state.open_files.items.len == 0) return null;
if (index >= pixi.state.open_files.items.len) return null;

Expand Down Expand Up @@ -454,7 +454,7 @@ pub fn closeFile(index: usize) !void {

pub fn rawCloseFile(index: usize) !void {
pixi.state.open_file_index = 0;
var file: pixi.storage.Internal.Pixi = pixi.state.open_files.orderedRemove(index);
var file: pixi.storage.Internal.PixiFile = pixi.state.open_files.orderedRemove(index);
deinitFile(&file);
}

Expand All @@ -469,7 +469,7 @@ pub fn deinitReference(reference: *pixi.storage.Internal.Reference) void {
pixi.state.allocator.free(reference.path);
}

pub fn deinitFile(file: *pixi.storage.Internal.Pixi) void {
pub fn deinitFile(file: *pixi.storage.Internal.PixiFile) void {
file.history.deinit();
file.buffers.deinit();
file.background.deinit();
Expand Down
2 changes: 1 addition & 1 deletion src/editor/explorer/animations.zig
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub fn draw() void {
}
}

fn contextMenu(animation_index: usize, file: *pixi.storage.Internal.Pixi) void {
fn contextMenu(animation_index: usize, file: *pixi.storage.Internal.PixiFile) void {
if (imgui.beginPopupContextItem()) {
defer imgui.endPopup();

Expand Down
2 changes: 1 addition & 1 deletion src/editor/explorer/keyframe_animations.zig
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub fn draw() void {
}
}

fn contextMenu(animation_index: usize, file: *pixi.storage.Internal.Pixi) void {
fn contextMenu(animation_index: usize, file: *pixi.storage.Internal.PixiFile) void {
if (imgui.beginPopupContextItem()) {
defer imgui.endPopup();

Expand Down
2 changes: 1 addition & 1 deletion src/editor/explorer/layers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const std = @import("std");
const pixi = @import("../../Pixi.zig");
const core = @import("mach").core;
const imgui = @import("zig-imgui");
const History = pixi.storage.Internal.Pixi.History;
const History = pixi.storage.Internal.PixiFile.History;

pub fn draw() void {
if (pixi.editor.getFile(pixi.state.open_file_index)) |file| {
Expand Down
2 changes: 1 addition & 1 deletion src/editor/popups/animation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const std = @import("std");
const pixi = @import("../../Pixi.zig");
const core = @import("mach").core;
const imgui = @import("zig-imgui");
const History = pixi.storage.Internal.Pixi.History;
const History = pixi.storage.Internal.PixiFile.History;

pub fn draw() void {
if (pixi.editor.getFile(pixi.state.open_file_index)) |file| {
Expand Down
4 changes: 2 additions & 2 deletions src/gfx/batcher.zig
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub const Batcher = struct {
data_2: f32 = 0.0,
};
/// Appends a quad at the passed position set to the size needed to render the target texture.
pub fn transformTexture(self: *Batcher, vertices: [4]pixi.storage.Internal.Pixi.TransformVertex, offset: [2]f32, pivot: [2]f32, options: TransformTextureOptions) !void {
pub fn transformTexture(self: *Batcher, vertices: [4]pixi.storage.Internal.PixiFile.TransformVertex, offset: [2]f32, pivot: [2]f32, options: TransformTextureOptions) !void {
var color: [4]f32 = [_]f32{ 1.0, 1.0, 1.0, 1.0 };
zmath.store(&color, options.color, 4);

Expand Down Expand Up @@ -296,7 +296,7 @@ pub const Batcher = struct {
}

/// Appends a quad at the passed position set to the size needed to render the target sprite.
pub fn transformSprite(self: *Batcher, t: *gfx.Texture, s: gfx.Sprite, vertices: [4]pixi.storage.Internal.Pixi.TransformVertex, offset: [2]f32, pivot: [2]f32, options: TransformTextureOptions) !void {
pub fn transformSprite(self: *Batcher, t: *gfx.Texture, s: gfx.Sprite, vertices: [4]pixi.storage.Internal.PixiFile.TransformVertex, offset: [2]f32, pivot: [2]f32, options: TransformTextureOptions) !void {
var color: [4]f32 = [_]f32{ 1.0, 1.0, 1.0, 1.0 };
zmath.store(&color, options.color, 4);

Expand Down
2 changes: 1 addition & 1 deletion src/gfx/camera.zig
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ pub const Camera = struct {
height: u32,
};

pub fn flipbookPixelCoordinates(camera: Camera, file: *pixi.storage.Internal.Pixi, options: FlipbookPixelCoordinatesOptions) ?[2]f32 {
pub fn flipbookPixelCoordinates(camera: Camera, file: *pixi.storage.Internal.PixiFile, options: FlipbookPixelCoordinatesOptions) ?[2]f32 {
const i = file.selected_sprite_index;
const tile_width = @as(f32, @floatFromInt(file.tile_width));
const tile_height = @as(f32, @floatFromInt(file.tile_height));
Expand Down
2 changes: 1 addition & 1 deletion src/storage/History.zig
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub fn append(self: *History, change: Change) !void {

// Handling cases in this function details how an undo/redo action works, and must be symmetrical.
// This means that `change` needs to be modified to contain the active state prior to changing the active state
pub fn undoRedo(self: *History, file: *pixi.storage.Internal.Pixi, action: Action) !void {
pub fn undoRedo(self: *History, file: *pixi.storage.Internal.PixiFile, action: Action) !void {
var active_stack = switch (action) {
.undo => &self.undo_stack,
.redo => &self.redo_stack,
Expand Down
Loading

0 comments on commit 3c4fa4e

Please sign in to comment.