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. 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 <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 {
14Pixel& 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 Access a character in a cell at a given position.
27/// @param x The cell position along the x-axis.
28/// @param y The cell position along the y-axis.
29 std::string& Image::at(int x, int y) {
30 return PixelAt(x, y).character;
31}
32
33/// @brief Access a character in a cell at a given position.
34/// @param x The cell position along the x-axis.
35/// @param y The cell position along the y-axis.
36 const std::string& Image::at(int x, int y) const {
37 return PixelAt(x, y).character;
38}
39
40/// @brief Access a cell (Pixel) at a given position.
41/// @param x The cell position along the x-axis.
42/// @param y The cell position along the y-axis.
43 Pixel& Image::PixelAt(int x, int y) {
44 return stencil.Contain(x, y) ? pixels_[y][x] : dev_null_pixel();
45}
46
47/// @brief Access a cell (Pixel) at a given position.
48/// @param x The cell position along the x-axis.
49/// @param y The cell position along the y-axis.
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 Clear all the pixel from the screen.
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:45
ftxui::Image::PixelAt
Pixel & PixelAt(int x, int y)
Access a cell (Pixel) at a given position.
Definition image.cpp:43
ftxui::Image::at
std::string & at(int x, int y)
Access a character in a cell at a given position.
Definition image.cpp:29
ftxui::Image::Image
Image()=delete
ftxui::Image::stencil
Box stencil
Definition image.hpp:38
ftxui::Image::Clear
void Clear()
Clear all the pixel from the screen.
Definition image.cpp:55
ftxui::Image::pixels_
std::vector< std::vector< Pixel > > pixels_
Definition image.hpp:43
ftxui::Pixel
A Unicode character and its associated style.
Definition pixel.hpp:15
image.hpp
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
pixel.hpp