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, uint64_t 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 uint64_t m_FrameIndex;
62 };
63
70 class FillAction : public Action {
71 public:
75 FillAction(Col next, uint64_t frameI,
76 const SharedPtr<ProjectFile>& proj,
77 std::vector<std::tuple<int, int, Col>> affected)
78 : 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:
105 uint64_t m_FrameIndex;
107 std::vector<std::tuple<int, int, Col>> m_Pixels;
108 };
109
116 class StrokeAction : public Action {
117 public:
122 struct PixelChange {
123 int x;
124 int y;
127 };
128
132 StrokeAction(uint64_t frameI, const SharedPtr<ProjectFile>& proj,
133 std::vector<PixelChange> changes)
134 : m_FrameIndex(frameI), m_Proj(proj),
135 m_Changes(std::move(changes)) {}
136
140 void Undo() override;
141
145 void Redo() override;
146
147 private:
148 uint64_t m_FrameIndex;
150 std::vector<PixelChange> m_Changes;
151 };
152
153} // 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
uint64_t m_FrameIndex
Definition Core.h:60
DrawAction(int x, int y, Col prev, Col next, uint64_t frameI, const SharedPtr< ProjectFile > &proj)
Creates a draw action for a single pixel change.
Definition Core.h:31
DrawAction(const DrawAction &other)=default
Copy constructor.
void Redo() override
Applies the new pixel color.
Definition Core.cc:15
Col m_Next
Definition Core.h:59
void Undo() override
Reverts the pixel to its previous color.
Definition Core.cc:10
int m_Y
Definition Core.h:57
std::vector< std::tuple< int, int, Col > > m_Pixels
Definition Core.h:107
~FillAction() override=default
Destructor.
void Undo() override
Reverts the fill operation.
Definition Core.cc:21
void Redo() override
Reapplies the fill operation.
Definition Core.cc:31
FillAction(const FillAction &other)=default
Copy constructor.
Col m_Next
Definition Core.h:104
FillAction(Col next, uint64_t frameI, const SharedPtr< ProjectFile > &proj, std::vector< std::tuple< int, int, Col > > affected)
Creates a fill action from a flood-fill operation.
Definition Core.h:75
uint64_t m_FrameIndex
Definition Core.h:105
WeakPtr< ProjectFile > m_Proj
Definition Core.h:106
std::vector< PixelChange > m_Changes
Definition Core.h:150
WeakPtr< ProjectFile > m_Proj
Definition Core.h:149
void Redo() override
Reapplies all pixel changes in the stroke.
Definition Core.cc:50
void Undo() override
Reverts all pixel changes in the stroke.
Definition Core.cc:40
StrokeAction(uint64_t frameI, const SharedPtr< ProjectFile > &proj, std::vector< PixelChange > changes)
Creates a stroke action from a list of pixel changes.
Definition Core.h:132
uint64_t m_FrameIndex
Definition Core.h:148
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:122
int x
X coordinate of the changed pixel.
Definition Core.h:123
int y
Y coordinate of the changed pixel.
Definition Core.h:124
Col prev
Pixel color before the stroke touched it.
Definition Core.h:125
Col next
Pixel color after the stroke applied.
Definition Core.h:126