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