Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
RuntimeBitmapSurface.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "BitmapRuntime.hpp"
4
5#include <cstddef>
6#include <cstdint>
7#include <expected>
8#include <memory>
9#include <optional>
10#include <string>
11#include <unordered_map>
12
13namespace monopoly::data
14{
15 inline constexpr std::uint16_t RuntimeBitmapGroup = 0xFFFEU;
16
17 enum class BitmapBlitMode
18 {
19 Replace,
21 };
22
23 [[nodiscard]] bool isRuntimeBitmapDataId(DataId id) noexcept;
24
25 [[nodiscard]] std::expected<void, std::string> blitStraightRGBA8(
26 LegacyBitmapRGBA8& destination,
27 const LegacyBitmapRGBA8& source,
28 std::int32_t destinationX,
29 std::int32_t destinationY,
30 BitmapBlitMode mode);
31
33 {
34 std::uint32_t width{};
35 std::uint32_t height{};
36 };
37
39 {
40 public:
41 [[nodiscard]] std::expected<DataId, std::string> create(
42 std::uint32_t width, std::uint32_t height, bool transparent,
43 std::uint8_t globalAlpha = 255);
44 [[nodiscard]] std::expected<void, std::string> update(
46 std::optional<std::array<float, 4>> presentationRect = {},
47 bool preferLinearFiltering = false);
48 [[nodiscard]] std::expected<void, std::string> fill(
49 DataId id, std::int32_t x, std::int32_t y,
50 std::int32_t width, std::int32_t height,
51 std::uint32_t colorRef);
52 [[nodiscard]] std::expected<void, std::string> blit(
54 std::int32_t x, std::int32_t y,
56 [[nodiscard]] std::expected<void, std::string> setGlobalAlpha(
57 DataId id, std::uint8_t alpha);
58 [[nodiscard]] std::optional<RuntimeBitmapExtent> extent(
59 DataId id) const noexcept;
60 [[nodiscard]] std::optional<std::uint8_t> globalAlpha(
61 DataId id) const noexcept;
62 [[nodiscard]] std::shared_ptr<const BitmapRuntimeAsset> asset(
63 DataId id) const noexcept;
64 [[nodiscard]] bool contains(DataId id) const noexcept
65 { return static_cast<bool>(asset(id)); }
66 [[nodiscard]] bool remove(DataId id) noexcept;
67 void clear() noexcept;
68 [[nodiscard]] std::size_t size() const noexcept { return surfaces_.size(); }
69
70 private:
71 struct Surface
72 {
73 LegacyBitmapRGBA8 baseImage;
74 bool colourKeyTransparent{};
75 std::uint8_t globalAlpha{255};
76 std::shared_ptr<const BitmapRuntimeAsset> published;
77 RuntimeBitmapExtent logicalExtent{};
78 std::optional<std::array<float, 4>> presentationRect;
79 bool preferLinearFiltering{};
80 };
81
82 void publish(DataId id, Surface& surface);
83
84 std::uint32_t nextTag_{1};
85 std::unordered_map<DataId, Surface> surfaces_;
86 };
87}
LegacyBitmapRGBA8 image
bool published
Definition Engine.cpp:170
std::shared_ptr< const data::HmdTextureImage > source
std::uint32_t height
std::uint32_t width
unsigned index
bool contains(DataId id) const noexcept
std::expected< void, std::string > blit(DataId id, const LegacyBitmapRGBA8 &source, std::int32_t x, std::int32_t y, BitmapBlitMode mode=BitmapBlitMode::SourceOver)
std::optional< RuntimeBitmapExtent > extent(DataId id) const noexcept
std::optional< std::uint8_t > globalAlpha(DataId id) const noexcept
std::expected< void, std::string > update(DataId id, LegacyBitmapRGBA8 image, std::optional< std::array< float, 4 > > presentationRect={}, bool preferLinearFiltering=false)
std::expected< void, std::string > setGlobalAlpha(DataId id, std::uint8_t alpha)
std::shared_ptr< const BitmapRuntimeAsset > asset(DataId id) const noexcept
std::expected< DataId, std::string > create(std::uint32_t width, std::uint32_t height, bool transparent, std::uint8_t globalAlpha=255)
std::expected< void, std::string > fill(DataId id, std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height, std::uint32_t colorRef)
std::uint32_t DataId
Definition DataBanks.hpp:10
std::expected< void, std::string > blitStraightRGBA8(LegacyBitmapRGBA8 &destination, const LegacyBitmapRGBA8 &source, std::int32_t destinationX, std::int32_t destinationY, BitmapBlitMode mode)
bool isRuntimeBitmapDataId(DataId id) noexcept
constexpr std::uint16_t RuntimeBitmapGroup