FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
image.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. 保留所有權利。
2// 本原始碼的使用受 MIT 授權條款約束,詳情請參閱
3// LICENSE 文件。
4#include <sstream> // IWYU pragma: keep
5#include <string>
6#include <vector>
7
10
11namespace ftxui {
12
13namespace {
14Pixel& dev_null_pixel() {
15 static Pixel pixel;
16 return pixel;
17}
18} // namespace
19
20Image::Image(int dimx, int dimy)
21 : stencil{0, dimx - 1, 0, dimy - 1},
22 dimx_(dimx),
23 dimy_(dimy),
24 pixels_(dimy, std::vector<Pixel>(dimx)) {}
25
26/// @brief 存取給定位置的單元格中的字元。
27/// @param x 沿 X 軸的單元格位置。
28/// @param y 沿 Y 軸的單元格位置。
29std::string& Image::at(int x, int y) {
30 return PixelAt(x, y).character;
31}
32
33/// @brief 存取給定位置的單元格中的字元。
34/// @param x 沿 X 軸的單元格位置。
35/// @param y 沿 Y 軸的單元格位置。
36const std::string& Image::at(int x, int y) const {
37 return PixelAt(x, y).character;
38}
39
40/// @brief 存取給定位置的單元格 (Pixel)。
41/// @param x 沿 X 軸的單元格位置。
42/// @param y 沿 Y 軸的單元格位置。
43Pixel& Image::PixelAt(int x, int y) {
44 return stencil.Contain(x, y) ? pixels_[y][x] : dev_null_pixel();
45}
46
47/// @brief 存取給定位置的單元格 (Pixel)。
48/// @param x 沿 X 軸的單元格位置。
49/// @param y 沿 Y 軸的單元格位置。
50const Pixel& Image::PixelAt(int x, int y) const {
51 return stencil.Contain(x, y) ? pixels_[y][x] : dev_null_pixel();
52}
53
54/// @brief 清除螢幕上的所有像素。
56 for (auto& line : pixels_) {
57 for (auto& cell : line) {
58 cell = Pixel();
59 }
60 }
61}
62
63} // namespace ftxui
bool Contain(int x, int y) const
Definition box.cpp:42
std::string character
Definition pixel.hpp:44
Pixel & PixelAt(int x, int y)
存取給定位置的單元格 (Pixel)。
Definition image.cpp:43
std::string & at(int x, int y)
存取給定位置的單元格中的字元。
Definition image.cpp:29
Image()=delete
Box stencil
Definition image.hpp:41
void Clear()
清除螢幕上的所有像素。
Definition image.cpp:55
std::vector< std::vector< Pixel > > pixels_
Definition image.hpp:46
一個 Unicode 字元及其相關樣式。
Definition pixel.hpp:14
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10