cpp-terminal 1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
window.hpp
Go to the documentation of this file.
1/*
2* cpp-terminal
3* C++ library for writing multi-platform terminal applications.
4*
5* SPDX-FileCopyrightText: 2019-2024 cpp-terminal
6*
7* SPDX-License-Identifier: MIT
8*/
9
10#pragma once
11
14#include "cpp-terminal/size.hpp"
16
17#include <cstddef>
18#include <vector>
19
20namespace Term
21{
22
23class Screen;
29//
30// @note the characters are represented by char32_t, representing their UTF-32 code point.
33class Window
34{
35public:
36 explicit Window(const Size& size);
37 explicit Window(const Screen& screen);
38 const Columns& columns() const noexcept;
39 const Rows& rows() const noexcept;
40
41 void set_char(const std::size_t& column, const std::size_t& row, const char32_t& character);
42
43 void set_fg_reset(const std::size_t& column, const std::size_t& row);
44
45 void set_bg_reset(const std::size_t& column, const std::size_t& row);
46
47 void set_fg(const std::size_t& column, const std::size_t& row, const Color& color);
48
49 void set_bg(const std::size_t& column, const std::size_t& row, const Color& color);
50
51 void set_style(const std::size_t& column, const std::size_t& row, const Style& style);
52
53 void set_cursor_pos(const std::size_t& column, const std::size_t& row);
54
55 void set_h(const std::size_t&);
56
57 void print_str(const std::size_t& column, const std::size_t&, const std::string&, const std::size_t& = 0, bool = false);
58
59 void fill_fg(const std::size_t& column, const std::size_t&, const std::size_t&, const std::size_t&, const Color&);
60
61 void fill_bg(const std::size_t& column, const std::size_t&, const std::size_t&, const std::size_t&, const Color&);
62
63 void fill_style(const std::size_t& column, const std::size_t&, const std::size_t&, const std::size_t&, const Style&);
64
65 void print_border();
66
67 void print_rect(const std::size_t& column, const std::size_t&, const std::size_t&, const std::size_t&);
68
69 void clear();
70
71 bool insideWindow(const std::size_t& column, const std::size_t& row) const;
72
73 // TODO: add Window/Screen parameter here, to be used like this:
74 // old_scr = scr;
75 // scr.print_str(...)
76 // scr.render(1, 1, old_scr)
77 std::string render(const std::size_t&, const std::size_t&, bool);
78
79private:
80 std::size_t index(const std::size_t& column, const std::size_t& row) const;
83 std::vector<char32_t> m_chars; // the characters in row first order
84 std::vector<Term::Color> m_fg;
85 std::vector<Term::Color> m_bg;
86 std::vector<bool> m_fg_reset;
87 std::vector<bool> m_bg_reset;
88 std::vector<Style> m_style;
89
90 char32_t get_char(const std::size_t& column, const std::size_t& row);
91
92 bool get_fg_reset(const std::size_t& column, const std::size_t& row);
93 bool get_bg_reset(const std::size_t& column, const std::size_t& row);
94 Term::Color get_fg(const std::size_t& column, const std::size_t& row);
95 Term::Color get_bg(const std::size_t& column, const std::size_t& row);
96 Term::Style get_style(const std::size_t& column, const std::size_t& row);
97};
98
99} // namespace Term
Represents a rectangular window, as a 2D array of characters and their attributes.
Definition window.hpp:34
std::vector< Term::Color > m_bg
Definition window.hpp:85
void set_h(const std::size_t &)
Definition window.cpp:80
std::vector< bool > m_fg_reset
Definition window.hpp:86
const Rows & rows() const noexcept
Definition window.cpp:44
void print_str(const std::size_t &column, const std::size_t &, const std::string &, const std::size_t &=0, bool=false)
Definition window.cpp:97
void set_char(const std::size_t &column, const std::size_t &row, const char32_t &character)
Definition window.cpp:46
void print_rect(const std::size_t &column, const std::size_t &, const std::size_t &, const std::size_t &)
Definition window.cpp:150
Term::Color get_fg(const std::size_t &column, const std::size_t &row)
Definition window.cpp:36
void fill_bg(const std::size_t &column, const std::size_t &, const std::size_t &, const std::size_t &, const Color &)
Definition window.cpp:132
const Columns & columns() const noexcept
Definition window.cpp:42
void set_fg(const std::size_t &column, const std::size_t &row, const Color &color)
Definition window.cpp:64
void fill_style(const std::size_t &column, const std::size_t &, const std::size_t &, const std::size_t &, const Style &)
Definition window.cpp:140
void set_bg_reset(const std::size_t &column, const std::size_t &row)
Definition window.cpp:58
std::string render(const std::size_t &, const std::size_t &, bool)
Definition window.cpp:199
Term::Cursor m_cursor
Definition window.hpp:82
Term::Color get_bg(const std::size_t &column, const std::size_t &row)
Definition window.cpp:38
std::vector< Term::Color > m_fg
Definition window.hpp:84
void set_cursor_pos(const std::size_t &column, const std::size_t &row)
Definition window.cpp:78
char32_t get_char(const std::size_t &column, const std::size_t &row)
Definition window.cpp:30
bool get_bg_reset(const std::size_t &column, const std::size_t &row)
Definition window.cpp:34
void set_fg_reset(const std::size_t &column, const std::size_t &row)
Definition window.cpp:52
void fill_fg(const std::size_t &column, const std::size_t &, const std::size_t &, const std::size_t &, const Color &)
Definition window.cpp:124
bool insideWindow(const std::size_t &column, const std::size_t &row) const
Definition window.cpp:305
std::vector< bool > m_bg_reset
Definition window.hpp:87
void set_bg(const std::size_t &column, const std::size_t &row, const Color &color)
Definition window.cpp:70
std::vector< Style > m_style
Definition window.hpp:88
bool get_fg_reset(const std::size_t &column, const std::size_t &row)
Definition window.cpp:32
void set_style(const std::size_t &column, const std::size_t &row, const Style &style)
Definition window.cpp:76
std::vector< char32_t > m_chars
Definition window.hpp:83
std::size_t index(const std::size_t &column, const std::size_t &row) const
Definition window.cpp:299
Term::Size m_size
Definition window.hpp:81
Term::Style get_style(const std::size_t &column, const std::size_t &row)
Definition window.cpp:40
void print_border()
Definition window.cpp:148
Window(const Size &size)
Definition window.cpp:26
void clear()
Definition window.cpp:189
Definition args.cpp:13
std::string style(const Term::Style &style)
Definition style.cpp:12
Style
Definition style.hpp:24