Polyphase Game Engine
Loading...
Searching...
No Matches
SpriteAnimationAtlasEditor.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include <cstdint>
6#include <vector>
7#include "imgui.h"
8
9class Texture;
10class SpriteAnimation;
11
12// Modal popup for editing the atlas-mode frame layout of a SpriteAnimation
13// asset. Shows the atlas texture with a configurable grid overlay; the user
14// clicks cells to append them to the playback order, right-clicks to remove,
15// and applies to write the grid + frame-index list back to the asset.
16//
17// Mirrors the lifecycle of TextureCropEditor: a single static instance, open
18// from anywhere, draws itself when DrawPopup() is called per frame.
19//
20// Grid metadata (cols/rows/margin/spacing) carries over between editor
21// sessions so users authoring multiple SpriteAnimations from the same atlas
22// don't have to re-enter the grid each time. The carry-over only seeds *fresh*
23// SpriteAnimations (those still at default cols=1, rows=1, with no frames).
24class SpriteAnimationAtlasEditor
25{
26public:
27 ~SpriteAnimationAtlasEditor();
28
29 void Open(SpriteAnimation* anim);
30 void DrawPopup();
31
32 bool IsOpen() const { return mIsOpen; }
33
34private:
35 void SetTexture(Texture* tex);
36 void ClearTexture();
37 void DrawGridControls();
38 void DrawAtlasCanvas();
39 void DrawFrameList();
40 int32_t CellCount() const { return mCols * mRows; }
41
42 // Asset being edited (raw pointer — editor session is short-lived; user can't
43 // delete the asset while the modal is open via the same UI).
44 SpriteAnimation* mAsset = nullptr;
45
46 // Vulkan descriptor for the atlas texture (same lifecycle as the other editors).
47 Texture* mTexture = nullptr;
48 ImTextureID mImGuiTexId = 0;
49 uint32_t mAtlasWidth = 0;
50 uint32_t mAtlasHeight = 0;
51
52 // Working copy of the asset's grid metadata + frame list. Committed on Apply.
53 int32_t mCols = 1;
54 int32_t mRows = 1;
55 int32_t mMarginX = 0;
56 int32_t mMarginY = 0;
57 int32_t mSpacingX = 0;
58 int32_t mSpacingY = 0;
59 std::vector<int32_t> mFrameIndices;
60
61 int32_t mHoveredCell = -1;
62
63 bool mIsOpen = false;
64 bool mJustOpened = false;
65 float mZoom = 2.0f;
66 uint64_t mLastDrawFrame = 0;
67
68 // Carry-over defaults for the next *fresh* SpriteAnimation opened. Set on
69 // every Apply. Reused only when the incoming asset has not yet been
70 // configured (cols=1, rows=1, no frames).
71 static int32_t sLastCols;
72 static int32_t sLastRows;
73 static int32_t sLastMarginX;
74 static int32_t sLastMarginY;
75 static int32_t sLastSpacingX;
76 static int32_t sLastSpacingY;
77 static bool sHasCarryover;
78};
79
80SpriteAnimationAtlasEditor* GetSpriteAnimationAtlasEditor();
81
82#endif
Definition SpriteAnimation.h:31
Definition Texture.h:10