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