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
8
#include "
ftxui/screen/image.hpp
"
9
#include "
ftxui/screen/pixel.hpp
"
10
11
namespace
ftxui
{
12
13
namespace
{
14
Pixel& dev_null_pixel() {
15
static
Pixel pixel;
16
return
pixel;
17
}
18
}
// namespace
19
20
Image::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 軸的單元格位置。
29
std::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 軸的單元格位置。
36
const
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 軸的單元格位置。
43
Pixel
&
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 軸的單元格位置。
50
const
Pixel
&
Image::PixelAt
(
int
x,
int
y)
const
{
51
return
stencil
.
Contain
(x, y) ?
pixels_
[y][x] : dev_null_pixel();
52
}
53
54
/// @brief 清除螢幕上的所有像素。
55
void
Image::Clear
() {
56
for
(
auto
& line :
pixels_
) {
57
for
(
auto
& cell : line) {
58
cell =
Pixel
();
59
}
60
}
61
}
62
63
}
// namespace ftxui
ftxui::Box::Contain
bool Contain(int x, int y) const
Definition
box.cpp:42
ftxui::Pixel::character
std::string character
Definition
pixel.hpp:44
ftxui::Image::PixelAt
Pixel & PixelAt(int x, int y)
存取給定位置的單元格 (Pixel)。
Definition
image.cpp:43
ftxui::Image::at
std::string & at(int x, int y)
存取給定位置的單元格中的字元。
Definition
image.cpp:29
ftxui::Image::Image
Image()=delete
ftxui::Image::stencil
Box stencil
Definition
image.hpp:41
ftxui::Image::Clear
void Clear()
清除螢幕上的所有像素。
Definition
image.cpp:55
ftxui::Image::pixels_
std::vector< std::vector< Pixel > > pixels_
Definition
image.hpp:46
ftxui::Pixel
一個 Unicode 字元及其相關樣式。
Definition
pixel.hpp:14
image.hpp
ftxui
FTXUI 的 ftxui:: 命名空間
Definition
animation.hpp:10
pixel.hpp