FuncDoodle
Loading...
Searching...
No Matches
Core.h
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <utility>
12
13#include "Common.h"
14#include "Project/Frame.h"
15#include "Project/Project.h"
16
17namespace FuncDoodle {
18
26 class DrawAction : public Action {
27 public:
31 DrawAction(int x, int y, Col prev, Col next, unsigned long frameI,
32 const SharedPtr<ProjectFile>& proj)
33 : m_X(x), m_Y(y), m_Prev(prev), m_Next(next), m_FrameIndex(frameI),
34 m_Proj(proj) {};
35
39 DrawAction(const DrawAction& other) = default;
40
44 ~DrawAction() override = default;
45
49 void Undo() override;
50
54 void Redo() override;
55
56 private:
57 int m_X, m_Y;
60 unsigned long m_FrameIndex;
62 };
63
70 class FillAction : public Action {
71 public:
75 FillAction(Col prev, Col next, unsigned long frameI,
76 const SharedPtr<ProjectFile>& proj,
77 std::vector<std::pair<int, int>> affected)
78 : m_Prev(prev), m_Next(next), m_FrameIndex(frameI), m_Proj(proj),
79 m_Pixels(std::move(affected)) {};
80
84 FillAction(const FillAction& other)
85
86 = default;
87
91 ~FillAction() override = default;
92
96 void Undo() override;
97
101 void Redo() override;
102
103 private:
106 unsigned long m_FrameIndex;
108 std::vector<std::pair<int, int>> m_Pixels;
109 };
110
117 class StrokeAction : public Action {
118 public:
123 struct PixelChange {
124 int x;
125 int y;
128 };
129
133 StrokeAction(unsigned long frameI, const SharedPtr<ProjectFile>& proj,
134 std::vector<PixelChange> changes)
135 : m_FrameIndex(frameI), m_Proj(proj),
136 m_Changes(std::move(changes)) {}
137
141 void Undo() override;
142
146 void Redo() override;
147
148 private:
149 unsigned long m_FrameIndex;
151 std::vector<PixelChange> m_Changes;
152 };
153
154} // namespace FuncDoodle
Defines the base interface for undoable and redoable editor actions.
Defines pixel color structures and frame/image data containers.
Defines the ProjectFile class, which manages animation project data.
std::weak_ptr< T > WeakPtr
Alias for a non-owning observer of a SharedPtr.
Definition Ptr.h:34
std::shared_ptr< T > SharedPtr
Alias for a reference-counted shared smart pointer.
Definition Ptr.h:31
Base interface for undoable and redoable editor actions.
Definition Common.h:24
~DrawAction() override=default
Destructor.
int m_X
Definition Core.h:57
WeakPtr< ProjectFile > m_Proj
Definition Core.h:61
Col m_Prev
Definition Core.h:58
DrawAction(const DrawAction &other)=default
Copy constructor.
void Redo() override
Applies the new pixel color.
Definition Core.cc:13
unsigned long m_FrameIndex
Definition Core.h:60
DrawAction(int x, int y, Col prev, Col next, unsigned long frameI, const SharedPtr< ProjectFile > &proj)
Creates a draw action for a single pixel change.
Definition Core.h:31
Col m_Next
Definition Core.h:59
void Undo() override
Reverts the pixel to its previous color.
Definition Core.cc:8
int m_Y
Definition Core.h:57
~FillAction() override=default
Destructor.
void Undo() override
Reverts the fill operation.
Definition Core.cc:19
void Redo() override
Reapplies the fill operation.
Definition Core.cc:28
FillAction(const FillAction &other)=default
Copy constructor.
Col m_Prev
Definition Core.h:104
FillAction(Col prev, Col next, unsigned long frameI, const SharedPtr< ProjectFile > &proj, std::vector< std::pair< int, int > > affected)
Creates a fill action from a flood-fill operation.
Definition Core.h:75
unsigned long m_FrameIndex
Definition Core.h:106
Col m_Next
Definition Core.h:105
std::vector< std::pair< int, int > > m_Pixels
Definition Core.h:108
WeakPtr< ProjectFile > m_Proj
Definition Core.h:107
std::vector< PixelChange > m_Changes
Definition Core.h:151
WeakPtr< ProjectFile > m_Proj
Definition Core.h:150
void Redo() override
Reapplies all pixel changes in the stroke.
Definition Core.cc:47
StrokeAction(unsigned long frameI, const SharedPtr< ProjectFile > &proj, std::vector< PixelChange > changes)
Creates a stroke action from a list of pixel changes.
Definition Core.h:133
void Undo() override
Reverts all pixel changes in the stroke.
Definition Core.cc:37
unsigned long m_FrameIndex
Definition Core.h:149
The FuncDoodle C++ namespace.
Definition Common.h:12
A struct holding an RGB8 color.
Definition Frame.h:47
Represents a single pixel modification in a stroke.
Definition Core.h:123
int x
X coordinate of the changed pixel.
Definition Core.h:124
int y
Y coordinate of the changed pixel.
Definition Core.h:125
Col prev
Pixel color before the stroke touched it.
Definition Core.h:126
Col next
Pixel color after the stroke applied.
Definition Core.h:127