4#ifndef FTXUI_DOM_CANVAS_HPP
5#define FTXUI_DOM_CANVAS_HPP
10#include <unordered_map>
38struct FTXUI_EXPORT(DOM) Canvas {
41 Canvas(
int width,
int height);
44 int width()
const {
return width_; }
45 int height()
const {
return height_; }
46 Cell GetCell(
int x,
int y)
const;
48 Cell GetPixel(
int x,
int y)
const {
return GetCell(x,
y); }
50 using Stylizer = std::function<void(Cell&)>;
53 void DrawPointOn(
int x,
int y);
54 void DrawPointOff(
int x,
int y);
55 void DrawPointToggle(
int x,
int y);
56 void DrawPoint(
int x,
int y,
bool value);
57 void DrawPoint(
int x,
int y,
bool value,
const Stylizer& s);
58 void DrawPoint(
int x,
int y,
bool value,
const Color& color);
59 void DrawPointLine(
int x1,
int y1,
int x2,
int y2);
60 void DrawPointLine(
int x1,
int y1,
int x2,
int y2,
const Stylizer& s);
61 void DrawPointLine(
int x1,
int y1,
int x2,
int y2,
const Color& color);
62 void DrawPointCircle(
int x,
int y,
int radius);
63 void DrawPointCircle(
int x,
int y,
int radius,
const Stylizer& s);
64 void DrawPointCircle(
int x,
int y,
int radius,
const Color& color);
65 void DrawPointCircleFilled(
int x,
int y,
int radius);
66 void DrawPointCircleFilled(
int x,
int y,
int radius,
const Stylizer& s);
67 void DrawPointCircleFilled(
int x,
int y,
int radius,
const Color& color);
68 void DrawPointEllipse(
int x,
int y,
int r1,
int r2);
69 void DrawPointEllipse(
int x,
int y,
int r1,
int r2,
const Color& color);
70 void DrawPointEllipse(
int x,
int y,
int r1,
int r2,
const Stylizer& s);
71 void DrawPointEllipseFilled(
int x,
int y,
int r1,
int r2);
72 void DrawPointEllipseFilled(
int x,
int y,
int r1,
int r2,
const Color& color);
73 void DrawPointEllipseFilled(
int x,
int y,
int r1,
int r2,
const Stylizer& s);
77 void DrawBlockOn(
int x,
int y);
78 void DrawBlockOff(
int x,
int y);
79 void DrawBlockToggle(
int x,
int y);
80 void DrawBlock(
int x,
int y,
bool value);
81 void DrawBlock(
int x,
int y,
bool value,
const Stylizer& s);
82 void DrawBlock(
int x,
int y,
bool value,
const Color& color);
83 void DrawBlockLine(
int x1,
int y1,
int x2,
int y2);
84 void DrawBlockLine(
int x1,
int y1,
int x2,
int y2,
const Stylizer& s);
85 void DrawBlockLine(
int x1,
int y1,
int x2,
int y2,
const Color& color);
86 void DrawBlockCircle(
int x1,
int y1,
int radius);
87 void DrawBlockCircle(
int x1,
int y1,
int radius,
const Stylizer& s);
88 void DrawBlockCircle(
int x1,
int y1,
int radius,
const Color& color);
89 void DrawBlockCircleFilled(
int x1,
int y1,
int radius);
90 void DrawBlockCircleFilled(
int x1,
int y1,
int radius,
const Stylizer& s);
91 void DrawBlockCircleFilled(
int x1,
int y1,
int radius,
const Color& color);
92 void DrawBlockEllipse(
int x1,
int y1,
int r1,
int r2);
93 void DrawBlockEllipse(
int x1,
int y1,
int r1,
int r2,
const Stylizer& s);
94 void DrawBlockEllipse(
int x1,
int y1,
int r1,
int r2,
const Color& color);
95 void DrawBlockEllipseFilled(
int x1,
int y1,
int r1,
int r2);
96 void DrawBlockEllipseFilled(
int x1,
101 void DrawBlockEllipseFilled(
int x1,
111 void DrawText(
int x,
int y, std::string_view
value);
112 void DrawText(
int x,
int y, std::string_view
value,
const Color& color);
113 void DrawText(
int x,
int y, std::string_view
value,
const Stylizer& style);
118 void DrawCell(
int x,
int y,
const Cell&);
119 void DrawSurface(
int x,
int y,
const Surface&);
122 void DrawPixel(
int x,
int y,
const Cell& cell) { DrawCell(x,
y, cell); }
124 void DrawImage(
int x,
int y,
const Surface& s) { DrawSurface(x,
y, s); }
129 void Style(
int x,
int y,
const Stylizer& style);
132 bool IsIn(
int x,
int y)
const {
133 return x >= 0 && x < width_ && y >= 0 &&
y < height_;
143 CellType type = kCell;
150 bool operator==(
const XY& other)
const {
151 return x == other.x &&
y == other.y;
156 size_t operator()(
const XY& xy)
const {
157 constexpr size_t shift = 1024;
158 return size_t(xy.x) * shift + size_t(xy.y);
164 std::unordered_map<XY, CanvasCell, XYHash> storage_;