diff --git a/src/canvas.cpp b/src/canvas.cpp index 876790f..cb5ff92 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -253,8 +253,8 @@ static void rect_end(GLuint vao, GLenum mode, int count = 4) canvas_blend_straight_set(); } -void Canvas::dashed_render(ShaderProgram& shader, const Mat4& transform, const Mat4& model, Vec4 color, - float dashLength, float dashGap, float dashOffset, GLenum mode, int count) const +void Canvas::dashed_render(ShaderProgram& shader, const Mat4& transform, const Mat4& model, Vec4 color, Dash dash, + DashedShape shape) const { rect_begin(shader, transform, model, color); @@ -263,12 +263,15 @@ void Canvas::dashed_render(ShaderProgram& shader, const Mat4& transform, const M std::pair{UNIFORM_AXIS_Y, Vec4(0.0f, 1.0f, 0.0f, 1.0f)}}) if (auto location = gl.GetUniformLocation(shader.id, name); location != -1) gl.Uniform2fv(location, 1, values_get(Vec2(model * axis - origin))); - for (auto [name, value] : {std::pair{UNIFORM_DASH_LENGTH, dashLength}, std::pair{UNIFORM_DASH_GAP, dashGap}, - std::pair{UNIFORM_DASH_OFFSET, dashOffset}}) + for (auto [name, value] : {std::pair{UNIFORM_DASH_LENGTH, dash.length}, std::pair{UNIFORM_DASH_GAP, dash.gap}, + std::pair{UNIFORM_DASH_OFFSET, dash.offset}}) if (auto location = gl.GetUniformLocation(shader.id, name); location != -1) gl.Uniform1f(location, value); - rect_end(rectVAO, mode, count); + if (shape == DASHED_RECT) + rect_end(rectVAO, GL_LINE_LOOP, RECT_VERTEX_COUNT); + else + rect_end(rectVAO, GL_LINES, LINE_VERTEX_COUNT); } // A layer draw's crop of its spritesheet. A blurred one (Flash's BlurFilter: a box `blur` canvas pixels wide) grows by @@ -314,21 +317,20 @@ void Canvas::layers_render(ShaderProgram& shader, const Model& model, const Anim } } -void Canvas::rect_render(ShaderProgram& shader, const Mat4& transform, const Mat4& model, Vec4 color, float dashLength, - float dashGap, float dashOffset) const +void Canvas::rect_render(ShaderProgram& shader, const Mat4& transform, const Mat4& model, Vec4 color, Dash dash) const { - dashed_render(shader, transform, model, color, dashLength, dashGap, dashOffset, GL_LINE_LOOP, RECT_VERTEX_COUNT); + dashed_render(shader, transform, model, color, dash, DASHED_RECT); } // A line from start to end: the bottom edge of a rectangle laid along it. void Canvas::line_render(ShaderProgram& shader, const Mat4& transform, Vec2 start, Vec2 end, Vec4 color, - float dashLength, float dashGap, float dashOffset) const + Dash dash) const { auto direction = end - start; auto normal = vec_length(direction) > 0.0f ? vec_normalize(Vec2(-direction.y, direction.x)) : Vec2(0.0f, 1.0f); auto model = Mat4(Vec4(direction, 0.0f, 0.0f), Vec4(normal, 0.0f, 0.0f), Vec4(0.0f, 0.0f, 1.0f, 0.0f), Vec4(start, 0.0f, 1.0f)); - dashed_render(shader, transform, model, color, dashLength, dashGap, dashOffset, GL_LINES, LINE_VERTEX_COUNT); + dashed_render(shader, transform, model, color, dash, DASHED_LINE); } void Canvas::rect_fill_render(ShaderProgram& shader, const Mat4& transform, const Mat4& model, Vec4 color) const diff --git a/src/canvas.h b/src/canvas.h index 89efb7b..d77bb87 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -20,6 +20,24 @@ struct TextureBlur Vec4 region{}; }; +constexpr float DASH_LENGTH = 4.0f; +constexpr float DASH_GAP = 1.0f; +constexpr float DASH_OFFSET = 1.0f; + +// A dashed outline's pattern, in canvas pixels. +struct Dash +{ + float length = DASH_LENGTH; + float gap = DASH_GAP; + float offset = DASH_OFFSET; +}; + +enum DashedShape +{ + DASHED_RECT, + DASHED_LINE +}; + class Canvas : public Framebuffer { public: @@ -28,9 +46,6 @@ public: static constexpr auto PIVOT_SIZE = Vec2(8, 8); static constexpr auto ZOOM_MIN = 1.0f; static constexpr auto ZOOM_MAX = 2000.0f; - static constexpr auto DASH_LENGTH = 4.0f; - static constexpr auto DASH_GAP = 1.0f; - static constexpr auto DASH_OFFSET = 1.0f; static constexpr auto STEP = 1.0f; static constexpr auto STEP_FAST = 5.0f; static constexpr auto ZOOM_LEVEL_STEP = 1; @@ -48,9 +63,7 @@ public: static constexpr int RECT_VERTEX_COUNT = 4; static constexpr int LINE_VERTEX_COUNT = 2; static constexpr GLuint TEXTURE_INDICES[] = {0, 1, 2, 2, 3, 0}; - static constexpr auto BORDER_DASH_LENGTH = 1.0f; - static constexpr auto BORDER_DASH_GAP = 0.5f; - static constexpr auto BORDER_DASH_OFFSET = 0.0f; + static constexpr Dash BORDER_DASH = {.length = 1.0f, .gap = 0.5f, .offset = 0.0f}; static constexpr auto PIVOT_COLOR = COLOR_PINK; GLuint axisVAO = 0; @@ -76,11 +89,9 @@ public: void layers_render(ShaderProgram&, const Model&, const Animation&, const DrawOptions&, const Mat4&, const std::function&, const std::function& = {}) const; - void dashed_render(ShaderProgram&, const Mat4&, const Mat4&, Vec4, float, float, float, GLenum, int) const; - void rect_render(ShaderProgram&, const Mat4&, const Mat4&, Vec4 = Vec4(1.0f), float dashLength = DASH_LENGTH, - float dashGap = DASH_GAP, float dashOffset = DASH_OFFSET) const; - void line_render(ShaderProgram&, const Mat4&, Vec2, Vec2, Vec4 = Vec4(1.0f), float dashLength = DASH_LENGTH, - float dashGap = DASH_GAP, float dashOffset = DASH_OFFSET) const; + void dashed_render(ShaderProgram&, const Mat4&, const Mat4&, Vec4, Dash, DashedShape) const; + void rect_render(ShaderProgram&, const Mat4&, const Mat4&, Vec4 = Vec4(1.0f), Dash = {}) const; + void line_render(ShaderProgram&, const Mat4&, Vec2, Vec2, Vec4 = Vec4(1.0f), Dash = {}) const; float zoom_level_get(float, int) const; void zoom_level_adjust(float&, Vec2&, Vec2, int) const; Vec2 position_translate(float&, Vec2&, Vec2) const; diff --git a/src/cli.cpp b/src/cli.cpp index f1e7b96..21eb832 100644 --- a/src/cli.cpp +++ b/src/cli.cpp @@ -230,20 +230,21 @@ static int draw_run(const Arguments& arguments) ShaderProgram shader(textureInfo.vertex, textureInfo.fragment); Canvas canvas(Vec2(1.0f)); auto isRootTransform = !arguments.is("no-root-transform"); - auto bounds = animation_bounds_get(document, *animation, isRootTransform); - auto scale = arguments.number_get("scale", SCALE_DEFAULT); - auto background = background_get(arguments); - auto frame_render = [&](float time) { - return animation_frame_render(canvas, shader, document, *animation, time, bounds, scale, background, - isRootTransform); - }; + FrameRender render{.canvas = canvas, + .shader = shader, + .document = document, + .animation = *animation, + .bounds = animation_bounds_get(document, *animation, isRootTransform), + .background = background_get(arguments), + .scale = arguments.number_get("scale", SCALE_DEFAULT), + .isRootTransform = isRootTransform}; auto outPath = path_from_utf8(*out); std::error_code ec; std::filesystem::create_directories(type_is_folder(arguments) ? outPath : outPath.parent_path(), ec); if (arguments.command == "frame") { - auto pixels = frame_render(arguments.number_get("time", 0.0f)); + auto pixels = animation_frame_render(render, arguments.number_get("time", 0.0f)); pixels_unpremultiply(pixels); if (!Image::write_pixels_png(outPath, IVec2(canvas.size), pixels.data())) { @@ -278,7 +279,7 @@ static int draw_run(const Arguments& arguments) .rows = arguments.number_get("rows", 0), .columns = arguments.number_get("columns", 0)}; auto count = frame_count_get(options.start, options.end, options.animationFps, options.fps); - if (!animation_record(options, canvas, shader, document, *animation, bounds, scale, background, isRootTransform)) + if (!animation_record(options, render)) { std::println(stderr, "could not write {} (FFmpeg: {})", *out, path_to_utf8(options.ffmpegPath)); return 1; diff --git a/src/edit/edit.h b/src/edit/edit.h index 1e35237..e915d79 100644 --- a/src/edit/edit.h +++ b/src/edit/edit.h @@ -26,6 +26,30 @@ struct RowTarget int groupId = -1; }; +// Tracks and whole groups (of one type, in one animation) moved next to, or into, a target row. +struct ItemsMove +{ + int animationIndex = 0; + int type = NONE; + std::set ids; + std::set groupIds; + RowTarget target = {}; + DropZone zone = DROP_BEFORE; +}; + +// A layer or null added (a new one, from `layer` or `null`, at id -1) with a track in one animation or all of them, +// placed before track `insertBeforeId` (at the end, at -1). +struct ItemAdd +{ + ItemType type = ItemType::LAYER; + int animationIndex = 0; + int id = -1; + int insertBeforeId = -1; + Destination destination = DESTINATION_ALL; + Layer layer = {}; + Null null = {}; +}; + struct GridOptions { IVec2 start{}; @@ -111,9 +135,9 @@ Uids root_bake_into(Model&, const std::set&, const std::set>&, const std::map>&); Uids items_group(Model&, int, int, const std::set&, const std::string&); -void items_move(Model&, int, int, const std::set&, const std::set&, RowTarget, DropZone); +void items_move(Model&, const ItemsMove&); void animation_length_fit(Model&, int); -int item_add(Model&, ItemType, int, int, Layer, Null, int, Destination); +int item_add(Model&, ItemAdd); std::set animation_group_ids_get(const Model&); std::set animation_group_indices_get(const Model&, int); diff --git a/src/edit/tracks.cpp b/src/edit/tracks.cpp index d45c63e..ec9dc24 100644 --- a/src/edit/tracks.cpp +++ b/src/edit/tracks.cpp @@ -35,9 +35,9 @@ Uids items_group(Model& model, int animationIndex, int type, const std::set // Moves tracks and whole groups next to (or into) a target row. Layers are listed bottom-up, so for them "after" on // screen is "before" in the file. -void items_move(Model& model, int animationIndex, int type, const std::set& ids, const std::set& groupIds, - RowTarget target, DropZone zone) +void items_move(Model& model, const ItemsMove& move) { + auto& [animationIndex, type, ids, groupIds, target, zone] = move; auto isDropAfter = zone != DROP_BEFORE; auto isDropIntoGroup = zone == DROP_INSIDE; if ((target.groupId != -1 && groupIds.contains(target.groupId)) || (target.isGroup && groupIds.contains(target.id))) @@ -89,11 +89,10 @@ void animation_length_fit(Model& model, int animationIndex) animation->frameNum = animation_length_get(*animation); } -// Adds a layer or null (or updates the one with the item's id) and gives it a track in one or every animation. -// Adds track `id` (a new item, from `layer` or `null`, at -1) to an animation or all of them. -int item_add(Model& model, ItemType type, int animationIndex, int id, Layer layer, Null null, int insertBeforeId, - Destination destination) +// Adds a layer or null (or reuses the one with the id) and gives it a track in one or every animation. +int item_add(Model& model, ItemAdd add) { + auto& [type, animationIndex, id, insertBeforeId, destination, layer, null] = add; auto& content = model.content; auto item_insert = [&](auto& items, auto item) { if (id == -1) @@ -112,7 +111,7 @@ int item_add(Model& model, ItemType type, int animationIndex, int id, Layer laye else return -1; - auto add = [&](int index) { + auto track_add = [&](int index) { if (model.track_get({index, (int)type, id})) return; auto& entries = animation_entries_get(*model.animation_edit(index), (int)type); @@ -125,8 +124,8 @@ int item_add(Model& model, ItemType type, int animationIndex, int id, Layer laye if (destination == DESTINATION_ALL) for (int i = 0; i < model.animations_count_get(); ++i) - add(i); + track_add(i); else if (model.animation_get(animationIndex)) - add(animationIndex); + track_add(animationIndex); return id; } diff --git a/src/render.cpp b/src/render.cpp index c885d4d..7aebfe4 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -288,10 +288,9 @@ Vec4 animation_bounds_get(const Document& document, const Animation& animation, return bounds != Vec4(-1.0f) ? bounds : BOUNDS_DEFAULT; } -std::vector animation_frame_render(Canvas& canvas, ShaderProgram& shader, Document& document, - const Animation& animation, float time, Vec4 bounds, float scale, - Vec4 background, bool isRootTransform) +std::vector animation_frame_render(const FrameRender& render, float time) { + auto& [canvas, shader, document, animation, bounds, background, scale, isRootTransform] = render; canvas.size_set(Vec2(vec_max(IVec2(vec_ceil(Vec2(bounds.z, bounds.w) * scale)), IVec2(1)))); float zoom = 0; Vec2 pan{}; @@ -411,8 +410,7 @@ void Recorder::cancel() index = count = 0; } -bool animation_record(const RecorderOptions& recorderOptions, Canvas& canvas, ShaderProgram& shader, Document& document, - const Animation& animation, Vec4 bounds, float scale, Vec4 background, bool isRootTransform) +bool animation_record(const RecorderOptions& recorderOptions, const FrameRender& render) { auto options = recorderOptions; options.isIsolated = options.isBounded = true; @@ -421,9 +419,8 @@ bool animation_record(const RecorderOptions& recorderOptions, Canvas& canvas, Sh return false; while (!recorder.is_done()) { - auto pixels = animation_frame_render(canvas, shader, document, animation, recorder.time_get(), bounds, scale, - background, isRootTransform); - if (recorder.frame_capture(std::move(pixels), IVec2(canvas.size))) + auto pixels = animation_frame_render(render, recorder.time_get()); + if (recorder.frame_capture(std::move(pixels), IVec2(render.canvas.size))) continue; recorder.cancel(); return false; diff --git a/src/render.h b/src/render.h index 3d1a4fb..0ee2383 100644 --- a/src/render.h +++ b/src/render.h @@ -134,9 +134,21 @@ public: // The area an animation covers over all its frames (or a default one when it draws nothing). Vec4 animation_bounds_get(const Document&, const Animation&, bool); -// One frame drawn over `bounds` at `scale`, as premultiplied RGBA rows from the top. -std::vector animation_frame_render(Canvas&, ShaderProgram&, Document&, const Animation&, float, Vec4, float, - Vec4, bool); +// How a render draws an animation's frames: onto `canvas` through `shader`, over `bounds` at `scale`, on `background`. +struct FrameRender +{ + Canvas& canvas; + ShaderProgram& shader; + Document& document; + const Animation& animation; + Vec4 bounds{}; + Vec4 background{}; + float scale = 1.0f; + bool isRootTransform = true; +}; + +// The frame at `time`, as premultiplied RGBA rows from the top. +std::vector animation_frame_render(const FrameRender&, float time); void pixels_unpremultiply(std::vector&); void frames_bake(Document&, Model&, const std::filesystem::path&); @@ -186,8 +198,7 @@ private: // Records a whole animation with these options (bounded and isolated), each frame drawn as animation_frame_render // draws it. False when a frame or the output can't be written. -bool animation_record(const RecorderOptions&, Canvas&, ShaderProgram&, Document&, const Animation&, Vec4, float, Vec4, - bool); +bool animation_record(const RecorderOptions&, const FrameRender&); bool animation_render(const std::filesystem::path&, const std::filesystem::path&, const std::vector&, const std::vector&, RenderType, int); diff --git a/src/ui/animation_preview.cpp b/src/ui/animation_preview.cpp index 8eba1a1..623225a 100644 --- a/src/ui/animation_preview.cpp +++ b/src/ui/animation_preview.cpp @@ -889,8 +889,9 @@ void AnimationPreview::update(Manager& manager, Settings& settings, Resources& r } if (tool == TOOL_PAN) - view_context_menu_draw("##Animation Preview Context Menu", manager, settings, document, zoom, pan, center_view, - fit_view, animation != nullptr); + view_context_menu_draw( + "##Animation Preview Context Menu", manager, settings, document, + {.zoom = zoom, .pan = pan, .center = center_view, .fit = fit_view, .isFitEnabled = animation != nullptr}); if (manager.progressPopup.begin()) { diff --git a/src/ui/canvas_view.cpp b/src/ui/canvas_view.cpp index b0b35b5..bc0ef89 100644 --- a/src/ui/canvas_view.cpp +++ b/src/ui/canvas_view.cpp @@ -190,9 +190,9 @@ void CanvasView::view_buttons_draw(Manager& manager, Settings& settings, const s } void CanvasView::view_context_menu_draw(const char* label, Manager& manager, Settings& settings, Document& document, - float& zoom, Vec2& pan, const std::function& center, - const std::function& fit, bool isFitEnabled) + const ViewCamera& camera) { + auto& [zoom, pan, center, fit, isFitEnabled] = camera; auto zoom_center_step = [&](int levelDelta) { zoom_step(zoom, pan, position_translate(zoom, pan, size * 0.5f), levelDelta); }; @@ -201,7 +201,7 @@ void CanvasView::view_context_menu_draw(const char* label, Manager& manager, Set actions_undo_redo_add(actions, manager, document); actions.separator(); actions.add(ACTION_CENTER_VIEW, []() { return true; }, center); - actions.add(ACTION_FIT_VIEW, [isFitEnabled]() { return isFitEnabled; }, fit); + actions.add(ACTION_FIT_VIEW, [&isFitEnabled]() { return isFitEnabled; }, fit); actions.separator(); actions.add(ACTION_ZOOM_IN, []() { return true; }, [&]() { zoom_center_step(ZOOM_LEVEL_STEP); }); actions.add(ACTION_ZOOM_OUT, []() { return true; }, [&]() { zoom_center_step(-ZOOM_LEVEL_STEP); }); diff --git a/src/ui/canvas_view.h b/src/ui/canvas_view.h index 25a1943..c566c14 100644 --- a/src/ui/canvas_view.h +++ b/src/ui/canvas_view.h @@ -44,6 +44,16 @@ std::pair rect_snap(Vec2, Vec2, bool, IVec2, IVec2); void tooltip_lines_draw(std::initializer_list); void tool_cursor_update(Tool, ToolArea, bool, bool, bool, StringType); +// A canvas view's camera, and how it centers and fits what it shows. +struct ViewCamera +{ + float& zoom; + Vec2& pan; + std::function center; + std::function fit; + bool isFitEnabled = false; +}; + class CanvasView : public Canvas { protected: @@ -60,8 +70,7 @@ protected: void zoom_step(float&, Vec2&, Vec2, int); void grid_child_draw(ImVec2, bool&, Vec4&, IVec2&, IVec2&, bool* = nullptr); void view_buttons_draw(Manager&, Settings&, const std::function&, const std::function&); - void view_context_menu_draw(const char*, Manager&, Settings&, Document&, float&, Vec2&, - const std::function&, const std::function&, bool); + void view_context_menu_draw(const char*, Manager&, Settings&, Document&, const ViewCamera&); public: CanvasView(); diff --git a/src/ui/item_properties.cpp b/src/ui/item_properties.cpp index 11b2095..7039edb 100644 --- a/src/ui/item_properties.cpp +++ b/src/ui/item_properties.cpp @@ -138,33 +138,29 @@ bool ItemProperties::update(Manager& manager, Settings& settings, Document& docu .isConfirmEnabled = source != SOURCE_EXISTING || edit.id != -1}); if (result == PopupButton::CONFIRM) { - auto queuedType = type; - auto queuedDestination = destination; - auto queuedAnimationIndex = reference.animationIndex; - auto queuedInsertBeforeID = reference.itemType == LAYER && type == LAYER ? reference.itemID : -1; - auto queuedAddItemID = source == SOURCE_NEW ? -1 : edit.id; - auto queuedLayer = item_edit_layer_get(edit); - auto queuedNull = item_edit_null_get(edit); + ItemAdd add = {.type = (ItemType)type, + .animationIndex = reference.animationIndex, + .id = source == SOURCE_NEW ? -1 : edit.id, + .insertBeforeId = reference.itemType == LAYER && type == LAYER ? reference.itemID : -1, + .destination = (Destination)destination, + .layer = item_edit_layer_get(edit), + .null = item_edit_null_get(edit)}; - manager.command_push({manager.selected, [=](Manager&, Document& document) { - int addId = -1; - document.edit_apply(EDIT_ADD_ITEM, [&](Model& model) { - addId = item_add(model, (ItemType)queuedType, queuedAnimationIndex, - queuedAddItemID, queuedLayer, queuedNull, - queuedInsertBeforeID, (Destination)queuedDestination); - }); + manager.command_push( + {manager.selected, [=](Manager&, Document& document) { + int addId = -1; + document.edit_apply(EDIT_ADD_ITEM, [&](Model& model) { addId = item_add(model, add); }); - if (addId != -1) - { - document.reference_set({queuedAnimationIndex, (int)queuedType, addId}); - document.selected_set(SelectionKind::TRACKS, {document.reference_get()}); - document.frame_references_clear(); - if (queuedType == LAYER) - if (auto layer = item_get(document.model.content.layers, addId)) - document.focused_id_set(SelectionKind::SPRITESHEETS, - layer->spritesheetId); - } - }}); + if (addId != -1) + { + document.reference_set({add.animationIndex, (int)add.type, addId}); + document.selected_set(SelectionKind::TRACKS, {document.reference_get()}); + document.frame_references_clear(); + if (add.type == ItemType::LAYER) + if (auto layer = item_get(document.model.content.layers, addId)) + document.focused_id_set(SelectionKind::SPRITESHEETS, layer->spritesheetId); + } + }}); isAdded = true; } diff --git a/src/ui/spritesheet_editor.cpp b/src/ui/spritesheet_editor.cpp index 655cc5d..1cfd57a 100644 --- a/src/ui/spritesheet_editor.cpp +++ b/src/ui/spritesheet_editor.cpp @@ -437,8 +437,7 @@ void SpritesheetEditor::update(Manager& manager, Settings& settings, Resources& grid_render(shaderGrid, zoom, pan, gridSize, gridOffset, gridColor); if (isBorder) - rect_render(dashedShader, spritesheetTransform, spritesheetModel, COLOR_WHITE, BORDER_DASH_LENGTH, - BORDER_DASH_GAP, BORDER_DASH_OFFSET); + rect_render(dashedShader, spritesheetTransform, spritesheetModel, COLOR_WHITE, BORDER_DASH); if (hoveredRegionId != -1) { @@ -466,8 +465,7 @@ void SpritesheetEditor::update(Manager& manager, Settings& settings, Resources& auto draw_region_rect = [&](const Region& region, Vec4 regionColor) { auto cropModel = quad_model_get(region.size, region.crop); auto cropTransform = transform * cropModel; - rect_render(dashedShader, cropTransform, cropModel, regionColor, BORDER_DASH_LENGTH, BORDER_DASH_GAP, - BORDER_DASH_OFFSET); + rect_render(dashedShader, cropTransform, cropModel, regionColor, BORDER_DASH); }; for (auto& region : spritesheet->regions) @@ -518,8 +516,13 @@ void SpritesheetEditor::update(Manager& manager, Settings& settings, Resources& } if (tool == TOOL_PAN) - view_context_menu_draw("##Spritesheet Editor Context Menu", manager, settings, document, zoom, pan, center_view, - fit_view, (baseTexture && baseTexture->is_valid()) || (texture && texture->is_valid())); + view_context_menu_draw( + "##Spritesheet Editor Context Menu", manager, settings, document, + {.zoom = zoom, + .pan = pan, + .center = center_view, + .fit = fit_view, + .isFitEnabled = (baseTexture && baseTexture->is_valid()) || (texture && texture->is_valid())}); if (!document.isSpritesheetEditorSet) { diff --git a/src/ui/timeline_edit.cpp b/src/ui/timeline_edit.cpp index 2574690..4304b4c 100644 --- a/src/ui/timeline_edit.cpp +++ b/src/ui/timeline_edit.cpp @@ -232,7 +232,14 @@ void TimelineContext::rows_move_to_row(std::vector draggedRows, Tim edit_push( EDIT_MOVE_ITEMS, - [=](Model& model) { return items_move(model, animationIndex, targetType, ids, groupIds, target, zone); }, + [=](Model& model) { + return items_move(model, {.animationIndex = animationIndex, + .type = targetType, + .ids = ids, + .groupIds = groupIds, + .target = target, + .zone = zone}); + }, [=](Document& document, const Uids&) { document.selection.uids[SelectionKind::TRACKS] = moved.uids.at(SelectionKind::TRACKS); document.selection.uids[SelectionKind::GROUPS] = moved.uids.at(SelectionKind::GROUPS); diff --git a/tests/operations.cpp b/tests/operations.cpp index dba31f7..5bf9799 100644 --- a/tests/operations.cpp +++ b/tests/operations.cpp @@ -57,8 +57,11 @@ TEST_CASE("file_merge presets") TEST_CASE("item_add") { auto model = fixture_load("02_items.anm2"); - CHECK(item_add(model, ItemType::LAYER, 0, -1, {.name = "added", .spritesheetId = 1}, {}, 1, DESTINATION_ALL) == 2); - CHECK(item_add(model, ItemType::NULL_, 1, -1, {}, {.name = "thisOnly"}, -1, DESTINATION_THIS) == 2); + CHECK(item_add(model, {.insertBeforeId = 1, .layer = {.name = "added", .spritesheetId = 1}}) == 2); + CHECK(item_add(model, {.type = ItemType::NULL_, + .animationIndex = 1, + .destination = DESTINATION_THIS, + .null = {.name = "thisOnly"}}) == 2); operation_check("item_add", model); } @@ -190,7 +193,7 @@ TEST_CASE("edit layer operations") [&](Model& anm2) { return items_group(anm2, 0, LAYER, {2}, "New"); }, 1}, {"items_move", "03b_groups_legacy_flat.anm2", [&](Model& anm2) { - items_move(anm2, 0, LAYER, {2}, {}, {true, LAYER, 0, -1}, DROP_INSIDE); + items_move(anm2, {.type = LAYER, .ids = {2}, .target = {true, LAYER, 0, -1}, .zone = DROP_INSIDE}); return Uids{}; }, 0}, diff --git a/tests/render/render.cpp b/tests/render/render.cpp index 1bcfe01..42da892 100644 --- a/tests/render/render.cpp +++ b/tests/render/render.cpp @@ -71,12 +71,22 @@ struct RenderFixture std::vector frame_get(float time) { - auto pixels = - animation_frame_render(*canvas, *shader, *document, *animation, time, bounds, SCALE, BACKGROUND, true); + auto pixels = animation_frame_render(render_get(), time); pixels_unpremultiply(pixels); return pixels; } + FrameRender render_get() + { + return {.canvas = *canvas, + .shader = *shader, + .document = *document, + .animation = *animation, + .bounds = bounds, + .background = BACKGROUND, + .scale = SCALE}; + } + TVec4 pixel_get(const std::vector& pixels, Vec2 point) { auto position = IVec2((point - Vec2(bounds.x, bounds.y)) * SCALE); @@ -126,8 +136,7 @@ TEST_CASE("a recorded spritesheet holds every frame") .end = fixture.animation->frameNum - 1, .animationFps = fixture.document->model.info.fps, .fps = fixture.document->model.info.fps}; - REQUIRE(animation_record(options, *fixture.canvas, *fixture.shader, *fixture.document, *fixture.animation, - fixture.bounds, SCALE, BACKGROUND, true)); + REQUIRE(animation_record(options, fixture.render_get())); Image sheet(options.path); auto layout = spritesheet_layout_get(0, 0, fixture.animation->frameNum); CHECK(sheet.size == IVec2(fixture.canvas->size) * IVec2(layout.columns, layout.rows)); @@ -152,8 +161,7 @@ TEST_CASE("a PNG sequence without a placeholder numbers each frame") .end = fixture.animation->frameNum - 1, .animationFps = fixture.document->model.info.fps, .fps = fixture.document->model.info.fps}; - REQUIRE(animation_record(options, *fixture.canvas, *fixture.shader, *fixture.document, *fixture.animation, - fixture.bounds, SCALE, BACKGROUND, true)); + REQUIRE(animation_record(options, fixture.render_get())); auto count = std::ranges::distance(std::filesystem::directory_iterator(directory)); CHECK(count == fixture.animation->frameNum); CHECK(std::filesystem::exists(directory / "spin_000000.png")); @@ -334,10 +342,15 @@ TEST_CASE("the game's copy bakes skew and blur into a spritesheet that draws the for (int time = 0; time < animation.frameNum; ++time) { INFO("time: ", time); - auto expected = animation_frame_render(canvas, shader, document, animation, (float)time, bounds, 1.0f, - Vec4(0.0f), true); - auto actual = animation_frame_render(canvas, shader, gameDocument, gameAnimation, (float)time, bounds, 1.0f, - Vec4(0.0f), true); + auto expected = animation_frame_render( + {.canvas = canvas, .shader = shader, .document = document, .animation = animation, .bounds = bounds}, + (float)time); + auto actual = animation_frame_render({.canvas = canvas, + .shader = shader, + .document = gameDocument, + .animation = gameAnimation, + .bounds = bounds}, + (float)time); REQUIRE(actual.size() == expected.size()); CHECK(std::ranges::any_of(expected, [](uint8_t channel) { return channel != 0; })); int mismatches = 0; diff --git a/tests/selection.cpp b/tests/selection.cpp index 1e43f21..fd80d4b 100644 --- a/tests/selection.cpp +++ b/tests/selection.cpp @@ -81,7 +81,8 @@ TEST_CASE("track and group selection follow regrouping") selection_references_set(selection, anm2, SelectionKind::TRACKS, {{0, LAYER, 0, -1, LAYER, groupId}}); selection_references_set(selection, anm2, SelectionKind::GROUPS, {{0, LAYER, groupId}}); - selection_edit(anm2, selection, [&] { items_move(anm2, 0, LAYER, {0}, {}, {false, LAYER, 2, -1}, DROP_BEFORE); }); + selection_edit(anm2, selection, + [&] { items_move(anm2, {.type = LAYER, .ids = {0}, .target = {false, LAYER, 2, -1}}); }); UidIndex index(anm2); CHECK(selection_references_get(selection, index, SelectionKind::TRACKS) == std::set{{0, LAYER, 0}});