FuncDoodle
Loading...
Searching...
No Matches
Project.h
Go to the documentation of this file.
1
14
15#pragma once
16
25
26#include "Conf/FuncPCH.h"
27
28#include "Project/DynArr.h"
29#include "Project/Frame.h"
30#include "Util/Ptr.h"
31
32#include <concepts>
33#include <stack>
34
35#include "Action/Action.h"
36
37#include <algorithm>
38#include <memory>
39
40#include "Platform/Window.h"
41
42namespace FuncDoodle {
58 public:
72 ProjectFile(char name[256], int width, int height, char author[100],
73 int fps, char desc[512], Platform::Window* win, Col bgCol);
81 [[nodiscard]] const char* AnimName() const;
88 void SetAnimName(char name[256]);
95 [[nodiscard]] int AnimWidth() const;
103 void SetAnimWidth(int width, bool clear = false);
110 [[nodiscard]] int AnimHeight() const;
118 void SetAnimHeight(int height, bool clear = false);
125 [[nodiscard]] const char* AnimAuthor() const;
132 void SetAnimAuthor(char* author);
139 [[nodiscard]] int AnimFPS() const;
146 void SetAnimFPS(int FPS);
153 [[nodiscard]] const char* AnimDesc() const;
160 void SetAnimDesc(char* desc);
167 [[nodiscard]] uint64_t AnimFrameCount() const;
174 void SetAnimFrameCount(uint64_t count);
182 void SetBgCol(const float* bgCol) {
183 // Ensure bgCol is valid and has at least 3 elements
184 if (bgCol) {
185 m_BG = Col{.r = static_cast<unsigned char>(
186 std::clamp(bgCol[0] * 255, 0.0f, 255.0f)),
187 .g = static_cast<unsigned char>(
188 std::clamp(bgCol[1] * 255, 0.0f, 255.0f)),
189 .b = static_cast<unsigned char>(
190 std::clamp(bgCol[2] * 255, 0.0f, 255.0f))};
191 }
192
193 m_Frames =
194 std::make_shared<LongIndexArray>(m_Width, m_Height, m_BG);
195
196 m_Frames->PushBackEmpty();
197 }
198
204 [[nodiscard]] Col BgCol() const { return m_BG; }
211 [[nodiscard]] const char* LastSavePath() const {
212 return m_LastSavePath;
213 };
214
227 void Write(const char* fileName);
234 void ReadAndPopulate(const char* filePath);
242 void Export(const char* filePath, ExportFormat format);
249 [[nodiscard]] constexpr Platform::Window* Window() const {
250 return m_Window;
251 }
252
258 bool Saved() const { return m_Saved; }
265 void DisplayAltFPS(double fps);
270 void UpdateTitle();
271
272 // Undo management
279 template <typename T>
280 requires std::derived_from<std::remove_cvref_t<T>, Action>
281 void PushUndoable(T&& action) {
282 using U = std::remove_cvref_t<T>;
283
285 m_UndoStack.push(std::make_unique<U>(std::forward<T>(action)));
286 m_Saved = false;
287 }
288
293 void Undo();
298 void Redo();
299
305 while (!m_RedoStack.empty()) {
306 m_RedoStack.pop();
307 }
308 }
309
310 private:
311 char m_Name[256]; // 256
312 int m_Width = 0;
313 int m_Height = 0;
314 char m_Author[100]; // 100
315 int m_FPS = 0;
316 char m_Desc[512]; // 512
319 std::stack<UniquePtr<Action>> m_UndoStack;
320 std::stack<UniquePtr<Action>> m_RedoStack;
321 bool m_Saved = false;
322 const char* m_LastSavePath = "";
324 };
325} // 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:44
void SetAnimWidth(int width, bool clear=false)
Sets the animation width.
Definition Project.cc:214
Col m_BG
Definition Project.h:323
const char * AnimDesc() const
Returns the animation description.
Definition Project.cc:245
void Undo()
Undoes the most recent action on the undo stack.
Definition Project.cc:259
SharedPtr< LongIndexArray > AnimFrames()
Returns the animation frame storage.
Definition Project.cc:255
void SetAnimHeight(int height, bool clear=false)
Sets the animation height.
Definition Project.cc:224
SharedPtr< LongIndexArray > m_Frames
Definition Project.h:317
int AnimWidth() const
Returns the animation width in pixels.
Definition Project.cc:210
void ReadAndPopulate(const char *filePath)
Loads project data from disk into this instance.
Definition Project.cc:377
int m_Height
Definition Project.h:313
constexpr Platform::Window * Window() const
Returns the owning application window.
Definition Project.h:249
char m_Name[256]
Definition Project.h:311
void SetAnimFPS(int FPS)
Sets the animation frame rate.
Definition Project.cc:241
void SetBgCol(const float *bgCol)
Sets the project background color and rebuilds backing frame storage.
Definition Project.h:182
void PushUndoable(T &&action)
Pushes a new undoable action and clears redo history.
Definition Project.h:281
void Export(const char *filePath, ExportFormat format)
Exports the animation using the chosen format.
Definition Project.cc:71
void SetAnimAuthor(char *author)
Sets the animation author.
Definition Project.cc:234
void Redo()
Reapplies the most recent action on the redo stack.
Definition Project.cc:275
Col BgCol() const
Returns the current background color.
Definition Project.h:204
char m_Author[100]
Definition Project.h:314
const char * AnimName() const
Returns the animation name.
Definition Project.cc:64
void UpdateTitle()
Refreshes the window title using current project state.
Definition Project.cc:579
const char * AnimAuthor() const
Returns the animation author.
Definition Project.cc:231
bool m_Saved
Definition Project.h:321
int AnimHeight() const
Returns the animation height in pixels.
Definition Project.cc:221
char m_Desc[512]
Definition Project.h:316
const char * m_LastSavePath
Definition Project.h:322
const char * LastSavePath() const
Returns the last saved file path.
Definition Project.h:211
std::stack< UniquePtr< Action > > m_UndoStack
Definition Project.h:319
void SetAnimName(char name[256])
Sets the animation name.
Definition Project.cc:67
void SetAnimFrameCount(uint64_t count)
Resizes the animation frame count.
int m_FPS
Definition Project.h:315
uint64_t AnimFrameCount() const
Returns the number of frames in the animation.
Definition Project.cc:252
void Write(const char *fileName)
Serializes the project to disk.
Definition Project.cc:289
void ClearRedoStack()
Removes all actions from the redo stack.
Definition Project.h:304
int AnimFPS() const
Returns the animation frame rate.
Definition Project.cc:238
int m_Width
Definition Project.h:312
Platform::Window * m_Window
Definition Project.h:318
void DisplayAltFPS(double fps)
Shows a temporary FPS value in the window title.
Definition Project.cc:567
void SetAnimDesc(char *desc)
Sets the animation description.
Definition Project.cc:248
std::stack< UniquePtr< Action > > m_RedoStack
Definition Project.h:320
bool Saved() const
Returns whether the project matches the last saved state.
Definition Project.h:258
The FuncDoodle C++ namespace.
Definition Common.h:12
ExportFormat
Definition Constants.h:288
A struct holding an RGB8 color.
Definition Frame.h:47