FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
surface.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <algorithm>
5#include <sstream> // IWYU pragma: keep
6#include <string>
7#include <vector>
8
11
12namespace ftxui {
13
14namespace {
15Cell& dev_null_cell() {
16 static Cell cell;
17 return cell;
18}
19} // namespace
20
21Surface::Surface(int dimx, int dimy)
22 : stencil{0, std::max(0, dimx) - 1, 0, std::max(0, dimy) - 1},
23 dimx_(std::max(0, dimx)),
24 dimy_(std::max(0, dimy)),
25 cells_(static_cast<size_t>(dimx_) * static_cast<size_t>(dimy_)) {}
26
27/// @brief 指定された位置のセル内の文字にアクセスします。
28/// @param x x軸に沿ったセルの位置。
29/// @param y y軸に沿ったセルの位置。
30std::string& Surface::at(int x, int y) {
31 return CellAt(x, y).character;
32}
33
34/// @brief 指定された位置のセル内の文字にアクセスします。
35/// @param x x軸に沿ったセルの位置。
36/// @param y y軸に沿ったセルの位置。
37const std::string& Surface::at(int x, int y) const {
38 return CellAt(x, y).character;
39}
40
41/// @brief 指定された位置のセル (Cell) にアクセスします。
42/// @param x x軸方向のセル位置。
43/// @param y y軸方向のセル位置。
44Cell& Surface::CellAt(int x, int y) {
45 return stencil.Contain(x, y) ? FastCellAt(x, y) : dev_null_cell();
46}
47
48/// @brief 指定された位置のセル (Cell) にアクセスします。
49/// @param x x軸方向のセル位置。
50/// @param y y軸方向のセル位置。
51const Cell& Surface::CellAt(int x, int y) const {
52 return stencil.Contain(x, y) ? FastCellAt(x, y) : dev_null_cell();
53}
54
55/// @brief ステンシルチェックなしで、指定された位置のセル (Cell) にアクセスします。
56/// @param x x軸方向のセル位置。
57/// @param y y軸方向のセル位置。
58Cell& Surface::FastCellAt(int x, int y) {
59 return cells_[static_cast<size_t>(y) * static_cast<size_t>(dimx_) +
60 static_cast<size_t>(x)];
61}
62
63/// @brief ステンシルチェックなしで、指定された位置のセル (Cell) にアクセスします。
64/// @param x x軸方向のセル位置。
65/// @param y y軸方向のセル位置。
66const Cell& Surface::FastCellAt(int x, int y) const {
67 return cells_[static_cast<size_t>(y) * static_cast<size_t>(dimx_) +
68 static_cast<size_t>(x)];
69}
70
71/// @brief サーフェスからすべてのセルをクリアします。
72void Surface::Clear() {
73 std::fill(cells_.begin(), cells_.end(), Cell());
74}
75
76void Surface::Reserved1() {}
77void Surface::Reserved2() {}
78void Surface::Reserved3() {}
79void Surface::Reserved4() {}
80void Surface::Reserved5() {}
81void Surface::Reserved6() {}
82void Surface::Reserved7() {}
83void Surface::Reserved8() {}
84
85} // namespace ftxui
FTXUI ftxui::名前空間
Definition animation.hpp:11
int y
Definition elements.hpp:131