150 lines
7.5 KiB
C++
150 lines
7.5 KiB
C++
//! \~\file piscreendrawer.h
|
||
//! \~\ingroup Console
|
||
//! \~\brief
|
||
//! \~english Drawing helpers for %PIScreen cell buffers
|
||
//! \~russian Вспомогательные средства рисования для буферов ячеек %PIScreen
|
||
/*
|
||
PIP - Platform Independent Primitives
|
||
Drawer for PIScreen
|
||
Ivan Pelipenko peri4ko@yandex.ru
|
||
|
||
This program is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU Lesser General Public License as published by
|
||
the Free Software Foundation, either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU Lesser General Public License for more details.
|
||
|
||
You should have received a copy of the GNU Lesser General Public License
|
||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
|
||
#ifndef PISCREENDRAWER_H
|
||
#define PISCREENDRAWER_H
|
||
|
||
#include "pip_console_export.h"
|
||
#include "piscreentypes.h"
|
||
#include "pistring.h"
|
||
|
||
//! \~\ingroup Console
|
||
//! \~\brief
|
||
//! \~english Helper that draws primitives and text into a %PIScreen cell buffer.
|
||
//! \~russian Вспомогательный класс для рисования примитивов и текста в буфере ячеек %PIScreen.
|
||
//! \~\details
|
||
//! \~english Provides methods for drawing primitives such as pixels, lines, rectangles, and text on console screen.
|
||
//! \~russian Предоставляет методы для рисования примитивов, таких как пиксели, линии, прямоугольники и текст на консольном экране.
|
||
class PIP_CONSOLE_EXPORT PIScreenDrawer {
|
||
friend class PIScreen;
|
||
PIScreenDrawer(PIVector<PIVector<PIScreenTypes::Cell>> & c);
|
||
|
||
public:
|
||
//! \~english Predefined pseudographic and widget-state symbols.
|
||
//! \~russian Предопределенные псевдографические символы и символы состояний виджетов.
|
||
//! \~\details
|
||
//! \~english Defines available characters for drawing ASCII art primitives.
|
||
//! \~russian Определяет доступные символы для рисования ASCII-арта примитивов.
|
||
enum ArtChar {
|
||
LineVertical = 1 /** \~english Vertical line symbol. \~russian Символ вертикальной линии. */,
|
||
LineHorizontal /** \~english Horizontal line symbol. \~russian Символ горизонтальной линии. */,
|
||
Cross /** \~english Line intersection symbol. \~russian Символ пересечения линий. */,
|
||
CornerTopLeft /** \~english Top-left frame corner. \~russian Левый верхний угол рамки. */,
|
||
CornerTopRight /** \~english Top-right frame corner. \~russian Правый верхний угол рамки. */,
|
||
CornerBottomLeft /** \~english Bottom-left frame corner. \~russian Левый нижний угол рамки. */,
|
||
CornerBottomRight /** \~english Bottom-right frame corner. \~russian Правый нижний угол рамки. */,
|
||
Unchecked /** \~english Unchecked box symbol. \~russian Символ неотмеченного флажка. */,
|
||
Checked /** \~english Checked box symbol. \~russian Символ отмеченного флажка. */
|
||
};
|
||
|
||
//! \~english Clears the whole target buffer.
|
||
//! \~russian Очищает весь целевой буфер.
|
||
void clear();
|
||
|
||
//! \~english Clears a rectangular area in the target buffer with spaces.
|
||
//! \~russian Очищает прямоугольную область целевого буфера пробелами.
|
||
void clearRect(int x0, int y0, int x1, int y1) { fillRect(x0, y0, x1, y1, ' '); }
|
||
|
||
//! \~english Draws one cell at position `(x, y)`.
|
||
//! \~russian Рисует одну ячейку в позиции `(x, y)`.
|
||
void drawPixel(int x,
|
||
int y,
|
||
const PIChar & c,
|
||
PIScreenTypes::Color col_char = PIScreenTypes::Default,
|
||
PIScreenTypes::Color col_back = PIScreenTypes::Default,
|
||
PIScreenTypes::CharFlags flags_char = 0);
|
||
|
||
//! \~english Draws a line between two points.
|
||
//! \~russian Рисует линию между двумя точками.
|
||
void drawLine(int x0,
|
||
int y0,
|
||
int x1,
|
||
int y1,
|
||
const PIChar & c,
|
||
PIScreenTypes::Color col_char = PIScreenTypes::Default,
|
||
PIScreenTypes::Color col_back = PIScreenTypes::Default,
|
||
PIScreenTypes::CharFlags flags_char = 0);
|
||
|
||
//! \~english Draws a rectangular outline with the specified symbol.
|
||
//! \~russian Рисует контур прямоугольника указанным символом.
|
||
void drawRect(int x0,
|
||
int y0,
|
||
int x1,
|
||
int y1,
|
||
const PIChar & c,
|
||
PIScreenTypes::Color col_char = PIScreenTypes::Default,
|
||
PIScreenTypes::Color col_back = PIScreenTypes::Default,
|
||
PIScreenTypes::CharFlags flags_char = 0);
|
||
|
||
//! \~english Draws a frame using predefined art symbols.
|
||
//! \~russian Рисует рамку предопределенными псевдографическими символами.
|
||
void drawFrame(int x0,
|
||
int y0,
|
||
int x1,
|
||
int y1,
|
||
PIScreenTypes::Color col_char = PIScreenTypes::Default,
|
||
PIScreenTypes::Color col_back = PIScreenTypes::Default,
|
||
PIScreenTypes::CharFlags flags_char = 0);
|
||
|
||
//! \~english Draws text starting at `(x, y)`.
|
||
//! \~russian Рисует текст, начиная с позиции `(x, y)`.
|
||
void drawText(int x,
|
||
int y,
|
||
const PIString & s,
|
||
PIScreenTypes::Color col_char = PIScreenTypes::Default,
|
||
PIScreenTypes::Color col_back = PIScreenTypes::Transparent,
|
||
PIScreenTypes::CharFlags flags_char = 0);
|
||
|
||
//! \~english Fills a rectangular area with one symbol and cell format.
|
||
//! \~russian Заполняет прямоугольную область одним символом и форматом ячейки.
|
||
void fillRect(int x0,
|
||
int y0,
|
||
int x1,
|
||
int y1,
|
||
const PIChar & c,
|
||
PIScreenTypes::Color col_char = PIScreenTypes::Default,
|
||
PIScreenTypes::Color col_back = PIScreenTypes::Default,
|
||
PIScreenTypes::CharFlags flags_char = 0);
|
||
|
||
//! \~english Copies a cell matrix into a rectangular area.
|
||
//! \~russian Копирует матрицу ячеек в прямоугольную область.
|
||
void fillRect(int x0, int y0, int x1, int y1, PIVector<PIVector<PIScreenTypes::Cell>> & content);
|
||
|
||
//! \~english Returns a predefined art symbol.
|
||
//! \~russian Возвращает предопределенный псевдографический символ.
|
||
PIChar artChar(const ArtChar type) const { return arts_.value(type, PIChar(' ')); }
|
||
|
||
//! \~english Fills an arbitrary cell buffer with default cells.
|
||
//! \~russian Заполняет произвольный буфер ячеек значениями по умолчанию.
|
||
static void clear(PIVector<PIVector<PIScreenTypes::Cell>> & cells);
|
||
|
||
private:
|
||
PIVector<PIVector<PIScreenTypes::Cell>> & cells;
|
||
int width, height;
|
||
PIMap<ArtChar, PIChar> arts_;
|
||
};
|
||
|
||
|
||
#endif // PISCREENDRAWER_H
|