FuncDoodle
Loading...
Searching...
No Matches
EditorController.h
Go to the documentation of this file.
1
19
20#pragma once
21
33
34#include "Action/Action.h"
35#include "Core/AppSettings.h"
36#include "Core/Grid.h"
37#include "Core/Player.h"
38#include "Project/Frame.h"
39#include "Selection/Selection.h"
40#include "Tool/ToolManager.h"
41#include "Util/Ptr.h"
42#include "imgui.h"
43
44#include <unordered_map>
45#include <vector>
46
47namespace FuncDoodle {
55 public:
62 class Frame* Frame =
63 nullptr;
65 nullptr;
66 uint64_t Index = 0;
68 nullptr;
70 nullptr;
72 nullptr;
73 int PixelScale = 8;
74 ImVec2 LastMousePos = {-1,
75 -1};
77 -1, -1};
80
87 CanvasContext(AppSettings& settings) : Settings(settings) {}
88 };
89
95
111 bool Paint(Frame* frame, uint64_t frameI, ToolManager* toolManager,
112 AnimationPlayer* player, int pixelX, int pixelY, bool mouseDown,
113 bool mouseClicked);
123 void SetUndoByStroke(bool undoByStroke, AnimationPlayer* player);
130 void RenderCanvas(CanvasContext& context);
137 void EndStroke(AnimationPlayer* player);
142 void ResetState();
157 m_Sel = sel;
159 }
160
161 private:
162 bool PaintPencil(Frame* frame, uint64_t frameI,
163 ToolManager* toolManager, AnimationPlayer* player, int pixelX,
164 int pixelY, bool mouseDown);
165 bool PaintEraser(Frame* frame, uint64_t frameI,
166 ToolManager* toolManager, AnimationPlayer* player, int pixelX,
167 int pixelY, bool mouseDown);
168 bool PaintBucket(Frame* frame, uint64_t frameI,
169 ToolManager* toolManager, AnimationPlayer* player, int pixelX,
170 int pixelY, bool mouseClicked);
171 static bool PaintPicker(
172 Frame* frame, ToolManager* toolManager, int pixelX, int pixelY);
173 bool PaintSelect(
174 Frame* frame, ToolManager* toolManager, int pixelX, int pixelY);
175 static void FloodFill(int x, int y, ToolManager* toolManager,
176 Col targetCol, Col fillCol, Frame* targetFrame,
177 std::vector<std::tuple<int, int, Col>>& changed);
179 uint64_t frameI, int x, int y, const Col& prev, const Col& next);
180 static void HandleCanvasInput(CanvasContext& context);
181 void ApplyToolAt(CanvasContext& context, const ImageArray* pixels,
182 float startX, float startY, float frameWidth, float frameHeight);
183 void DrawCanvas(CanvasContext& context, const ImageArray* pixels,
184 ImDrawList* drawList, float startX, float startY, float frameWidth,
185 float frameHeight);
186 void FinalizeStroke(AnimationPlayer* player);
187
188 bool m_UndoByStroke = false;
189 bool m_StrokeActive = false;
190 uint64_t m_StrokeFrameI = 0;
191 std::vector<StrokeAction::PixelChange> m_StrokeChanges;
192 std::unordered_map<uint64_t, size_t> m_StrokeIndexByKey;
195 };
196} // namespace FuncDoodle
Core type definitions used across FuncDoodle.
Runtime configuration and user-adjustable application settings.
Renders and manages the editor grid overlay.
Defines AnimationPlayer, responsible for animation playback control.
Defines pixel color structures and frame/image data containers.
Convenience type aliases for standard smart pointers.
std::unique_ptr< T > UniquePtr
Alias for an exclusively owned smart pointer.
Definition Ptr.h:28
std::shared_ptr< T > SharedPtr
Alias for a reference-counted shared smart pointer.
Definition Ptr.h:31
Defines selection primitives for editing regions of pixels.
Manages tools, tool state, and tool-related UI in FuncDoodle.
Responsible for playing a users' animation.
Definition Player.h:39
void FinalizeStroke(AnimationPlayer *player)
Definition EditorController.cc:306
void ApplyToolAt(CanvasContext &context, const ImageArray *pixels, float startX, float startY, float frameWidth, float frameHeight)
Definition EditorController.cc:395
EditorController()
Creates an editor controller.
std::vector< StrokeAction::PixelChange > m_StrokeChanges
Definition EditorController.h:191
static void HandleCanvasInput(CanvasContext &context)
Definition EditorController.cc:354
SharedPtr< Selection > Sel()
Returns the active selection object.
Definition EditorController.h:149
bool PaintSelect(Frame *frame, ToolManager *toolManager, int pixelX, int pixelY)
Definition EditorController.cc:214
void ResetState()
Clears transient editor state tied to the active project.
Definition EditorController.cc:66
static void FloodFill(int x, int y, ToolManager *toolManager, Col targetCol, Col fillCol, Frame *targetFrame, std::vector< std::tuple< int, int, Col > > &changed)
Definition EditorController.cc:235
bool PaintEraser(Frame *frame, uint64_t frameI, ToolManager *toolManager, AnimationPlayer *player, int pixelX, int pixelY, bool mouseDown)
Definition EditorController.cc:125
void RenderCanvas(CanvasContext &context)
Renders the frame canvas and handles its live interaction.
Definition EditorController.cc:321
bool PaintBucket(Frame *frame, uint64_t frameI, ToolManager *toolManager, AnimationPlayer *player, int pixelX, int pixelY, bool mouseClicked)
Definition EditorController.cc:168
void RecordStrokeChange(uint64_t frameI, int x, int y, const Col &prev, const Col &next)
Definition EditorController.cc:280
SharedPtr< Selection > m_Sel
Definition EditorController.h:193
std::unordered_map< uint64_t, size_t > m_StrokeIndexByKey
Definition EditorController.h:192
bool Paint(Frame *frame, uint64_t frameI, ToolManager *toolManager, AnimationPlayer *player, int pixelX, int pixelY, bool mouseDown, bool mouseClicked)
Applies the active tool to a frame at a specific pixel.
Definition EditorController.cc:24
bool m_UndoByStroke
Definition EditorController.h:188
SquareSelection m_SquareSel
Definition EditorController.h:194
bool PaintPencil(Frame *frame, uint64_t frameI, ToolManager *toolManager, AnimationPlayer *player, int pixelX, int pixelY, bool mouseDown)
Definition EditorController.cc:76
void SetSel(SharedPtr< Selection > sel)
Sets the active selection object.
Definition EditorController.h:156
void EndStroke(AnimationPlayer *player)
Finalizes the active stroke and pushes its undo record.
Definition EditorController.cc:62
void DrawCanvas(CanvasContext &context, const ImageArray *pixels, ImDrawList *drawList, float startX, float startY, float frameWidth, float frameHeight)
Definition EditorController.cc:550
static bool PaintPicker(Frame *frame, ToolManager *toolManager, int pixelX, int pixelY)
Definition EditorController.cc:202
uint64_t m_StrokeFrameI
Definition EditorController.h:190
bool m_StrokeActive
Definition EditorController.h:189
void SetUndoByStroke(bool undoByStroke, AnimationPlayer *player)
Enables or disables stroke-grouped undo behavior.
Definition EditorController.cc:51
Wraps an ImageArray with higher-level frame editing operations.
Definition Frame.h:248
2D array of RGB8 color pixels.
Definition Frame.h:126
Manages tools in FuncDoodle.
Definition ToolManager.h:68
The FuncDoodle C++ namespace.
Definition Common.h:12
Represents the application's current settings and loaded from imgui.ini.
Definition AppSettings.h:22
A struct holding an RGB8 color.
Definition Frame.h:47
Bundles per-frame canvas state used during rendering and input handling.
Definition EditorController.h:61
ToolManager * ToolManager
Tool state used for painting.
Definition EditorController.h:67
AppSettings & Settings
Application settings affecting canvas behavior.
Definition EditorController.h:79
UniquePtr< Grid > Grid
Optional grid overlay for the canvas.
Definition EditorController.h:71
AnimationPlayer * Player
Player attached to the current project.
Definition EditorController.h:69
int PixelScale
Screen-space size of one pixel.
Definition EditorController.h:73
class Frame * Frame
Frame currently being rendered and edited.
Definition EditorController.h:62
class Frame * PreviousFrame
Previous frame used for preview rendering.
Definition EditorController.h:64
ImVec2 LastHoverMousePos
Last hovered mouse position over the canvas.
Definition EditorController.h:76
uint64_t Index
Timeline index of the active frame.
Definition EditorController.h:66
ImVec2 LastMousePos
Last mouse position used for stroke interpolation.
Definition EditorController.h:74
CanvasContext(AppSettings &settings)
Creates a canvas context bound to application settings.
Definition EditorController.h:87
Rectangular selection defined by two corner points.
Definition Selection.h:51