Loading...
Searching...
No Matches
image.cpp
Go to the documentation of this file.
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <sstream> // IWYU pragma: keep
#include <string>
#include <vector>
#include "ftxui/screen/image.hpp"
#include "ftxui/screen/pixel.hpp"
namespace ftxui {
namespace {
Pixel& dev_null_pixel() {
static Pixel pixel;
return pixel;
}
} // namespace
Image::Image(int dimx, int dimy)
: stencil{0, dimx - 1, 0, dimy - 1},
dimx_(dimx),
dimy_(dimy),
pixels_(dimy, std::vector<Pixel>(dimx)) {}
/// @brief Access a character in a cell at a given position.
/// @param x The cell position along the x-axis.
/// @param y The cell position along the y-axis.
std::string& Image::at(int x, int y) {
return PixelAt(x, y).character;
}
/// @brief Access a character in a cell at a given position.
/// @param x The cell position along the x-axis.
/// @param y The cell position along the y-axis.
const std::string& Image::at(int x, int y) const {
return PixelAt(x, y).character;
}
/// @brief Access a cell (Pixel) at a given position.
/// @param x The cell position along the x-axis.
/// @param y The cell position along the y-axis.
Pixel& Image::PixelAt(int x, int y) {
return stencil.Contain(x, y) ? pixels_[y][x] : dev_null_pixel();
}
/// @brief Access a cell (Pixel) at a given position.
/// @param x The cell position along the x-axis.
/// @param y The cell position along the y-axis.
const Pixel& Image::PixelAt(int x, int y) const {
return stencil.Contain(x, y) ? pixels_[y][x] : dev_null_pixel();
}
/// @brief Clear all the pixel from the screen.
void Image::Clear() {
for (auto& line : pixels_) {
for (auto& cell : line) {
cell = Pixel();
}
}
}
} // namespace ftxui
ftxui::Image::dimy
int dimy() const
Definition image.hpp:33
ftxui::Image::dimx_
int dimx_
Definition image.hpp:41
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::dimy_
int dimy_
Definition image.hpp:42
ftxui::Image::Clear
void Clear()
Clear all the pixel from the screen.
Definition image.cpp:55
ftxui::Image::dimx
int dimx() const
Definition image.hpp:32
ftxui::Image::pixels_
std::vector< std::vector< Pixel > > pixels_
Definition image.hpp:43
image.hpp
ftxui
Definition animation.hpp:10
pixel.hpp
ftxui::Pixel
A Unicode character and its associated style.
Definition pixel.hpp:15
ftxui::Pixel::character
std::string character
Definition pixel.hpp:45