FuncDoodle
Loading...
Searching...
No Matches
Project.h
Go to the documentation of this file.
1
14
15#pragma once
16
25
26#include "Project/DynArr.h"
27#include "Project/Frame.h"
28#include "Util/Ptr.h"
29
30#include <concepts>
31#include <filesystem>
32#include <stack>
33
34#include "Action/Action.h"
35
36#include "Util/MacroUtils.h"
37
38#include <algorithm>
39#include <memory>
40
41#include "Platform/Window.h"
42
43namespace FuncDoodle {
59 public:
73 ProjectFile(char name[256], int width, int height, char author[100],
74 int fps, char desc[512], Platform::Window* win, Col bgCol);
82 [[nodiscard]] const char* AnimName() const;
89 void SetAnimName(char name[256]);
96 [[nodiscard]] int AnimWidth() const;
104 void SetAnimWidth(int width, bool clear = false);
111 [[nodiscard]] int AnimHeight() const;
119 void SetAnimHeight(int height, bool clear = false);
126 [[nodiscard]] const char* AnimAuthor() const;
133 void SetAnimAuthor(char* author);
140 [[nodiscard]] int AnimFPS() const;
147 void SetAnimFPS(int FPS);
154 [[nodiscard]] const char* AnimDesc() const;
161 void SetAnimDesc(char* desc);
168 [[nodiscard]] unsigned long AnimFrameCount() const;
175 void SetAnimFrameCount(unsigned long count);
183 void SetBgCol(const float* bgCol) {
184 // Ensure bgCol is valid and has at least 3 elements
185 if (bgCol) {
186 m_BG = Col{.r = static_cast<unsigned char>(
187 std::clamp(bgCol[0] * 255, 0.0f, 255.0f)),
188 .g = static_cast<unsigned char>(
189 std::clamp(bgCol[1] * 255, 0.0f, 255.0f)),
190 .b = static_cast<unsigned char>(
191 std::clamp(bgCol[2] * 255, 0.0f, 255.0f))};
192 }
193
194 m_Frames =
195 std::make_shared<LongIndexArray>(m_Width, m_Height, m_BG);
196
197 m_Frames->PushBackEmpty();
198 }
199
205 [[nodiscard]] Col BgCol() const { return m_BG; }
212 [[nodiscard]] const char* LastSavePath() const {
213 return m_LastSavePath;
214 };
215
228 void Write(const char* fileName);
235 void ReadAndPopulate(const char* filePath);
243 void Export(const char* filePath, int format);
250 [[nodiscard]] constexpr Platform::Window* Window() const {
251 return m_Window;
252 }
253
259 bool Saved() const { return m_Saved; }
266 void DisplayAltFPS(double fps);
271 void UpdateTitle();
272
273 // Undo management
280 template <typename T>
281 requires std::derived_from<std::remove_cvref_t<T>, Action>
282 void PushUndoable(T&& action) {
283 using U = std::remove_cvref_t<T>;
284
286 m_UndoStack.push(std::make_unique<U>(std::forward<T>(action)));
287 m_Saved = false;
288 }
289
294 void Undo();
299 void Redo();
300
306 while (!m_RedoStack.empty()) {
307 m_RedoStack.pop();
308 }
309 }
310
311 private:
312 char m_Name[256]; // 256
313 int m_Width = 0;
314 int m_Height = 0;
315 char m_Author[100]; // 100
316 int m_FPS = 0;
317 char m_Desc[512]; // 512
320 std::stack<UniquePtr<Action>> m_UndoStack;
321 std::stack<UniquePtr<Action>> m_RedoStack;
322 bool m_Saved = false;
323 const char* m_LastSavePath = "";
325 };
326} // namespace FuncDoodle
Core type definitions used across FuncDoodle.
Dynamic container for storing animation frames in indexed order.
Logging system, assertion macros, platform utilities, and build/config macros.
Defines pixel color structures and frame/image data containers.
Convenience type aliases for standard smart pointers.
std::shared_ptr< T > SharedPtr
Alias for a reference-counted shared smart pointer.
Definition Ptr.h:31
GLFW-based window abstraction for FuncDoodle.
Base interface for undoable and redoable editor actions.
Definition Common.h:24
Abstraction over a GLFW window with input, rendering, and lifecycle utilities.
Definition Window.h:61
ProjectFile(char name[256], int width, int height, char author[100], int fps, char desc[512], Platform::Window *win, Col bgCol)
Creates a new in-memory project file.
Definition Project.cc:32
void SetAnimWidth(int width, bool clear=false)
Sets the animation width.
Definition Project.cc:122
Col m_BG
Definition Project.h:324
const char * AnimDesc() const
Returns the animation description.
Definition Project.cc:153
void Undo()
Undoes the most recent action on the undo stack.
Definition Project.cc:167
SharedPtr< LongIndexArray > AnimFrames()
Returns the animation frame storage.
Definition Project.cc:163
void SetAnimFrameCount(unsigned long count)
Resizes the animation frame count.
void SetAnimHeight(int height, bool clear=false)
Sets the animation height.
Definition Project.cc:132
SharedPtr< LongIndexArray > m_Frames
Definition Project.h:318
int AnimWidth() const
Returns the animation width in pixels.
Definition Project.cc:118
void ReadAndPopulate(const char *filePath)
Loads project data from disk into this instance.
Definition Project.cc:284
unsigned long AnimFrameCount() const
Returns the number of frames in the animation.
Definition Project.cc:160
int m_Height
Definition Project.h:314
constexpr Platform::Window * Window() const
Returns the owning application window.
Definition Project.h:250
char m_Name[256]
Definition Project.h:312
void SetAnimFPS(int FPS)
Sets the animation frame rate.
Definition Project.cc:149
void SetBgCol(const float *bgCol)
Sets the project background color and rebuilds backing frame storage.
Definition Project.h:183
void PushUndoable(T &&action)
Pushes a new undoable action and clears redo history.
Definition Project.h:282
void SetAnimAuthor(char *author)
Sets the animation author.
Definition Project.cc:142
void Redo()
Reapplies the most recent action on the redo stack.
Definition Project.cc:183
Col BgCol() const
Returns the current background color.
Definition Project.h:205
char m_Author[100]
Definition Project.h:315
const char * AnimName() const
Returns the animation name.
Definition Project.cc:52
void UpdateTitle()
Refreshes the window title using current project state.
Definition Project.cc:479
const char * AnimAuthor() const
Returns the animation author.
Definition Project.cc:139
bool m_Saved
Definition Project.h:322
int AnimHeight() const
Returns the animation height in pixels.
Definition Project.cc:129
char m_Desc[512]
Definition Project.h:317
const char * m_LastSavePath
Definition Project.h:323
const char * LastSavePath() const
Returns the last saved file path.
Definition Project.h:212
std::stack< UniquePtr< Action > > m_UndoStack
Definition Project.h:320
void SetAnimName(char name[256])
Sets the animation name.
Definition Project.cc:55
int m_FPS
Definition Project.h:316
void Write(const char *fileName)
Serializes the project to disk.
Definition Project.cc:197
void Export(const char *filePath, int format)
Exports the animation using the chosen format.
Definition Project.cc:59
void ClearRedoStack()
Removes all actions from the redo stack.
Definition Project.h:305
int AnimFPS() const
Returns the animation frame rate.
Definition Project.cc:146
int m_Width
Definition Project.h:313
Platform::Window * m_Window
Definition Project.h:319
void DisplayAltFPS(double fps)
Shows a temporary FPS value in the window title.
Definition Project.cc:467
void SetAnimDesc(char *desc)
Sets the animation description.
Definition Project.cc:156
std::stack< UniquePtr< Action > > m_RedoStack
Definition Project.h:321
bool Saved() const
Returns whether the project matches the last saved state.
Definition Project.h:259
The FuncDoodle C++ namespace.
Definition Common.h:12
A struct holding an RGB8 color.
Definition Frame.h:47