remove overlay window, add document overlay + over/under

This commit is contained in:
shweet committed 2026-08-07 14:42:16 -04:00
1 parent e32e781b46
commit a4b34cc0be
22 files changed
+261 -1381

No files matched your search

+6 -135
View File
@@ -61,17 +61,11 @@ namespace anm2ed::imgui
};
if (auto selectedLayerSpritesheet = selected_layer_spritesheet_get();
selectedLayerSpritesheet != -1 && document.editTarget != Document::EditTarget::REGION &&
document.editTarget != Document::EditTarget::OVERLAY && document.editTarget != Document::EditTarget::SPRITESHEET)
document.editTarget != Document::EditTarget::SPRITESHEET)
referenceSpritesheet = selectedLayerSpritesheet;
auto spritesheet = anm2.element_get(ElementType::SPRITESHEET, referenceSpritesheet);
auto baseTexture = document.texture_get(referenceSpritesheet);
auto activeOverlayId = -1;
auto activeOverlay = document.editTarget == Document::EditTarget::OVERLAY ? document.overlay_get() : nullptr;
if (activeOverlay && document.overlay_spritesheet_id_get(activeOverlay->id) == referenceSpritesheet)
activeOverlayId = activeOverlay->id;
else
activeOverlay = nullptr;
auto texture = activeOverlayId != -1 ? document.overlay_texture_get(activeOverlayId) : baseTexture;
auto texture = baseTexture;
auto& tool = settings.tool;
auto& shaderGrid = resources.shaders[shader::GRID];
auto& shaderTexture = resources.shaders[shader::TEXTURE];
@@ -244,24 +238,8 @@ namespace anm2ed::imgui
auto spritesheetModel = math::quad_model_get(viewTexture->size);
auto spritesheetTransform = transform * spritesheetModel;
auto overlay_draw = [&](const Element& overlay)
{
if (overlay.type != ElementType::OVERLAY) return;
if (!overlay.isVisible) return;
auto overlayTexture = document.overlay_texture_get(overlay.id);
if (!overlayTexture || !overlayTexture->is_valid()) return;
auto overlayTransform = transform * math::quad_model_get(overlayTexture->size, overlay.position);
texture_render(shaderTexture, overlayTexture->id, overlayTransform, vec4(1.0f, 1.0f, 1.0f, overlay.tint.a));
};
for (auto& overlay : spritesheet->children)
if (overlay.index == OVERLAY_DRAW_ORDER_BELOW) overlay_draw(overlay);
if (baseTexture && baseTexture->is_valid()) texture_render(shaderTexture, baseTexture->id, spritesheetTransform);
for (auto& overlay : spritesheet->children)
if (overlay.index != OVERLAY_DRAW_ORDER_BELOW) overlay_draw(overlay);
if (isGrid) grid_render(shaderGrid, zoom, pan, gridSize, gridOffset, gridColor);
if (isBorder)
@@ -328,18 +306,6 @@ namespace anm2ed::imgui
}
}
if (activeOverlay)
{
auto overlayTexture = document.overlay_texture_get(activeOverlayId);
if (overlayTexture && overlayTexture->is_valid())
{
auto overlayModel = math::quad_model_get(overlayTexture->size, activeOverlay->position);
auto overlayTransform = transform * overlayModel;
rect_render(dashedShader, overlayTransform, overlayModel, color::RED, BORDER_DASH_LENGTH, BORDER_DASH_GAP,
BORDER_DASH_OFFSET);
}
}
bool isFrameOnSpritesheet = isReferenceLayerOnSpritesheet;
if (isFrameOnSpritesheet && frame->regionId == -1)
{
@@ -429,11 +395,6 @@ namespace anm2ed::imgui
mousePos = position_translate(zoom, pan, to_ivec2(ImGui::GetMousePos()) - to_ivec2(cursorScreenPos));
auto textureMousePos = mousePos;
auto previousTextureMousePos = previousMousePos;
if (activeOverlay)
{
textureMousePos -= activeOverlay->position;
previousTextureMousePos -= activeOverlay->position;
}
auto snap_rect = [&](glm::vec2 minPoint, glm::vec2 maxPoint)
{
@@ -466,29 +427,6 @@ namespace anm2ed::imgui
auto fraction = current - glm::floor(current);
return glm::floor(value) + fraction;
};
auto overlayIsGridSnap = isGridSnap;
auto overlayGridSize = gridSize;
auto overlayGridOffset = gridOffset;
auto overlay_position_snap =
[overlayIsGridSnap, overlayGridSize, overlayGridOffset, clamp_vec2_to_int](vec2 value)
{
if (overlayIsGridSnap)
{
if (overlayGridSize.x != 0)
{
auto offsetX = (float)overlayGridOffset.x;
auto sizeX = (float)overlayGridSize.x;
value.x = std::round((value.x - offsetX) / sizeX) * sizeX + offsetX;
}
if (overlayGridSize.y != 0)
{
auto offsetY = (float)overlayGridOffset.y;
auto sizeY = (float)overlayGridSize.y;
value.y = std::round((value.y - offsetY) / sizeY) * sizeY + offsetY;
}
}
return clamp_vec2_to_int(value);
};
auto frame_snapshot_push = [&](StringType messageType, const std::set<Reference>& frameReferences)
{
auto message = std::string(localize.get(messageType));
@@ -506,12 +444,6 @@ namespace anm2ed::imgui
[message, queuedSpritesheet, queuedRegionIds](Manager&, Document& document)
{ document.regions_snapshot(message, queuedSpritesheet, queuedRegionIds); }});
};
auto overlay_snapshot_push = [&](StringType messageType)
{
auto message = std::string(localize.get(messageType));
manager.command_push(
{manager.selected, [message](Manager&, Document& document) { document.anm2_snapshot(message); }});
};
auto texture_snapshot_push = [&](StringType messageType)
{
auto message = std::string(localize.get(messageType));
@@ -693,36 +625,12 @@ namespace anm2ed::imgui
region.size = clamp_vec2_to_int(maxPoint - minPoint);
});
};
auto overlay_update = [&](int id, auto update)
{
auto queuedSpritesheet = referenceSpritesheet;
manager.command_push({manager.selected, [=](Manager&, Document& document)
{
auto spritesheet =
document.anm2.element_get(ElementType::SPRITESHEET, queuedSpritesheet);
if (!spritesheet) return;
auto overlay = element_child_id_get(*spritesheet, ElementType::OVERLAY, id);
if (!overlay) return;
update(*overlay);
}});
};
auto overlay_position_set = [&](int id, vec2 position)
{
overlay_update(id, [=](Element& overlay) { overlay.position = overlay_position_snap(position); });
};
auto overlay_position_offset = [&](int id, vec2 delta)
{
overlay_update(id,
[=](Element& overlay) { overlay.position = overlay_position_snap(overlay.position + delta); });
};
auto texture_line_apply = [&](ivec2 start, ivec2 end, vec4 color)
{
auto queuedSpritesheet = referenceSpritesheet;
auto queuedOverlay = activeOverlayId;
manager.command_push({manager.selected, [=](Manager&, Document& document)
{
auto texture = queuedOverlay != -1 ? document.overlay_texture_get(queuedOverlay)
: document.texture_get(queuedSpritesheet);
auto texture = document.texture_get(queuedSpritesheet);
if (!texture) return;
texture->pixel_line(start, end, color);
}});
@@ -730,15 +638,9 @@ namespace anm2ed::imgui
auto texture_change_push = [&]()
{
auto queuedSpritesheet = referenceSpritesheet;
auto queuedOverlay = activeOverlayId;
manager.command_push(
{manager.selected, [=](Manager&, Document& document)
{
if (queuedOverlay != -1)
document.overlay_texture_change(queuedOverlay);
else
document.texture_change(queuedSpritesheet);
}});
{ document.texture_change(queuedSpritesheet); }});
};
auto region_selection_set = [&](int id)
@@ -801,9 +703,7 @@ namespace anm2ed::imgui
auto& toolInfo = tool::INFO[useTool];
auto& areaType = toolInfo.areaType;
auto isRegionEditTarget = document.editTarget == Document::EditTarget::REGION;
auto isOverlayEditTarget = document.editTarget == Document::EditTarget::OVERLAY && activeOverlayId != -1;
auto selectedFrameToolReferences =
isRegionEditTarget || isOverlayEditTarget ? std::set<Reference>{} : selectedFrameReferences;
auto selectedFrameToolReferences = isRegionEditTarget ? std::set<Reference>{} : selectedFrameReferences;
bool isAreaAllowed = areaType == tool::ALL || areaType == tool::SPRITESHEET_EDITOR;
bool isFrameRequired =
!(useTool == tool::PAN || useTool == tool::DRAW || useTool == tool::ERASE || useTool == tool::COLOR_PICKER);
@@ -812,8 +712,7 @@ namespace anm2ed::imgui
(useTool == tool::CROP || useTool == tool::MOVE);
bool isFrameAvailable = !isFrameRequired || (frame && !isRegionInUse && !selectedFrameToolReferences.empty()) ||
(useTool == tool::CROP && !regionSelection.empty()) ||
(useTool == tool::MOVE && regionReference != -1) ||
(useTool == tool::MOVE && isOverlayEditTarget);
(useTool == tool::MOVE && regionReference != -1);
bool isSpritesheetRequired = useTool == tool::DRAW || useTool == tool::ERASE || useTool == tool::COLOR_PICKER;
bool isSpritesheetAvailable = !isSpritesheetRequired || (texture && texture->is_valid());
auto cursor = (isAreaAllowed && isFrameAvailable && isSpritesheetAvailable) ? toolInfo.cursor
@@ -848,34 +747,6 @@ namespace anm2ed::imgui
if (isMouseDown || isMouseMiddleDown) pan += mouseDelta;
break;
case tool::MOVE:
if (isOverlayEditTarget)
{
if (!activeOverlay) break;
if (isBegin) overlay_snapshot_push(EDIT_OVERLAY_MOVE);
if (isMouseClicked) cropAnchor = mousePos - activeOverlay->position;
if (isMouseDown) overlay_position_set(activeOverlayId, mousePos - cropAnchor);
if (isLeftPressed) overlay_position_offset(activeOverlayId, vec2(-stepX, 0));
if (isRightPressed) overlay_position_offset(activeOverlayId, vec2(stepX, 0));
if (isUpPressed) overlay_position_offset(activeOverlayId, vec2(0, -stepY));
if (isDownPressed) overlay_position_offset(activeOverlayId, vec2(0, stepY));
if (isDuring)
{
if (ImGui::BeginTooltip())
{
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_POSITION),
std::make_format_args(activeOverlay->position.x, activeOverlay->position.y))
.c_str());
ImGui::EndTooltip();
}
}
if (isEnd) document_change_push(Document::SPRITESHEETS);
break;
}
if ((isRegionEditTarget || isRegionInUse || selectedFrameToolReferences.empty()) && regionReference != -1)
{
if (!spritesheet) break;