FTXUI
6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
image.cpp
浏览该文件的文档.
1
// Copyright 2020 Arthur Sonzogni. All rights reserved.
2
// 本源代码受 MIT 许可证的约束,该许可证可在 LICENSE 文件中找到。
3
#include <sstream>
// IWYU pragma: keep
4
#include <string>
5
#include <vector>
6
7
#include "
ftxui/screen/image.hpp
"
8
#include "
ftxui/screen/pixel.hpp
"
9
10
namespace
ftxui
{
11
12
namespace
{
13
Pixel& dev_null_pixel() {
14
static
Pixel pixel;
15
return
pixel;
16
}
17
}
// namespace
18
19
Image::Image
(
int
dimx,
int
dimy)
20
: stencil{0, dimx - 1, 0, dimy - 1},
21
dimx_(dimx),
22
dimy_(dimy),
23
pixels_(dimy, std::vector<
Pixel
>(dimx)) {}
24
25
/// @brief 访问给定位置单元格中的字符。
26
/// @param x 沿 x 轴的单元格位置。
27
/// @param y 沿 y 轴的单元格位置。
28
std::string&
Image::at
(
int
x,
int
y) {
29
return
PixelAt
(x, y).
character
;
30
}
31
32
/// @brief 访问给定位置单元格中的字符。
33
/// @param x 沿 x 轴的单元格位置。
34
/// @param y 沿 y 轴的单元格位置。
35
const
std::string&
Image::at
(
int
x,
int
y)
const
{
36
return
PixelAt
(x, y).
character
;
37
}
38
39
/// @brief 访问给定位置的单元格 (Pixel)。
40
/// @param x 沿 x 轴的单元格位置。
41
/// @param y 沿 y 轴的单元格位置。
42
Pixel
&
Image::PixelAt
(
int
x,
int
y) {
43
return
stencil
.
Contain
(x, y) ?
pixels_
[y][x] : dev_null_pixel();
44
}
45
46
/// @brief 访问给定位置的单元格 (Pixel)。
47
/// @param x 沿 x 轴的单元格位置。
48
/// @param y 沿 y 轴的单元格位置。
49
const
Pixel
&
Image::PixelAt
(
int
x,
int
y)
const
{
50
return
stencil
.
Contain
(x, y) ?
pixels_
[y][x] : dev_null_pixel();
51
}
52
53
/// @brief 清除屏幕上的所有像素。
54
void
Image::Clear
() {
55
for
(
auto
& line :
pixels_
) {
56
for
(
auto
& cell : line) {
57
cell =
Pixel
();
58
}
59
}
60
}
61
62
}
// namespace ftxui
ftxui::Box::Contain
bool Contain(int x, int y) const
定义
box.cpp:42
ftxui::Pixel::character
std::string character
定义
pixel.hpp:44
ftxui::Image::PixelAt
Pixel & PixelAt(int x, int y)
访问给定位置的单元格 (Pixel)。
定义
image.cpp:42
ftxui::Image::at
std::string & at(int x, int y)
访问给定位置单元格中的字符。
定义
image.cpp:28
ftxui::Image::Image
Image()=delete
ftxui::Image::stencil
Box stencil
定义
image.hpp:40
ftxui::Image::Clear
void Clear()
清除屏幕上的所有像素。
定义
image.cpp:54
ftxui::Image::pixels_
std::vector< std::vector< Pixel > > pixels_
定义
image.hpp:45
ftxui::Pixel
一个 Unicode 字符及其相关样式。
定义
pixel.hpp:14
image.hpp
ftxui
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
定义
animation.hpp:9
pixel.hpp