Start document model tests

This commit is contained in:
2026-06-01 00:02:42 +02:00
parent 8014345b99
commit 23eba07901
12 changed files with 352 additions and 15 deletions

51
src/document/document.h Normal file
View File

@@ -0,0 +1,51 @@
#pragma once
#include "foundation/result.h"
#include "paint/blend.h"
#include <cstdint>
#include <span>
#include <string>
#include <string_view>
#include <vector>
namespace pp::document {
constexpr std::uint32_t max_canvas_dimension = 131072;
constexpr std::uint32_t max_layer_count = 1024;
struct DocumentConfig {
std::uint32_t width = 0;
std::uint32_t height = 0;
std::uint32_t layer_count = 1;
};
struct Layer {
std::string name;
bool visible = true;
float opacity = 1.0F;
pp::paint::BlendMode blend_mode = pp::paint::BlendMode::normal;
};
class CanvasDocument {
public:
[[nodiscard]] static pp::foundation::Result<CanvasDocument> create(DocumentConfig config);
[[nodiscard]] std::uint32_t width() const noexcept;
[[nodiscard]] std::uint32_t height() const noexcept;
[[nodiscard]] std::size_t active_layer_index() const noexcept;
[[nodiscard]] std::span<const Layer> layers() const noexcept;
[[nodiscard]] pp::foundation::Result<std::size_t> add_layer(std::string_view name);
[[nodiscard]] pp::foundation::Status remove_layer(std::size_t index);
[[nodiscard]] pp::foundation::Status move_layer(std::size_t from, std::size_t to);
[[nodiscard]] pp::foundation::Status set_active_layer(std::size_t index) noexcept;
private:
std::uint32_t width_ = 0;
std::uint32_t height_ = 0;
std::size_t active_layer_index_ = 0;
std::vector<Layer> layers_;
};
}