Console Library 4.7.0
A header-only library that makes C++ simple
Loading...
Searching...
No Matches
console::Screen< COLS, ROWS > Class Template Reference

用于表示虚拟屏幕的类。 More...

#include <screen.h>

Public Member Functions

 Screen ()
 默认构造函数,构造一个空白的 Screen
void point (unsigned x, unsigned y, bool on=true)
 在屏幕上绘制一个点。
void line (int x0, int y0, int x1, int y1, bool on=true)
 在屏幕上绘制一条直线。
void rect (int x0, int y0, int x1, int y1, bool on=true)
 在屏幕上绘制空心矩形。
void fillRect (int x0, int y0, int x1, int y1, bool on=true)
 在屏幕上绘制实心矩形。
void circle (int cx, int cy, int r, bool on=true)
 在屏幕上绘制空心圆。
void fillCircle (int cx, int cy, int r, bool on=true)
 在屏幕上绘制实心圆。
void clear ()
 清空屏幕。
void update (std::ostream &os=std::cout, bool clear=false) const
 Screen 存储的虚拟屏幕输出到指定流。

Detailed Description

template<unsigned COLS, unsigned ROWS>
class console::Screen< COLS, ROWS >

用于表示虚拟屏幕的类。

使用八点位位盲文,每像素占用一比特位存储空间。

Template Parameters
COLS列数,必须是 2 的倍数。
ROWS行数,必须是 4 的倍数。

Constructor & Destructor Documentation

◆ Screen()

template<unsigned COLS, unsigned ROWS>
console::Screen< COLS, ROWS >::Screen ( )
inline

默认构造函数,构造一个空白的 Screen

Member Function Documentation

◆ circle()

template<unsigned COLS, unsigned ROWS>
void console::Screen< COLS, ROWS >::circle ( int cx,
int cy,
int r,
bool on = true )
inline

在屏幕上绘制空心圆。

Bresenham 中点圆算法,效率通常足够。

Parameters
cx圆中点的 x 坐标。
cy中点的 y 坐标。
r圆的半径。
on绘制 or 擦除?

◆ clear()

template<unsigned COLS, unsigned ROWS>
void console::Screen< COLS, ROWS >::clear ( )
inline

清空屏幕。

◆ fillCircle()

template<unsigned COLS, unsigned ROWS>
void console::Screen< COLS, ROWS >::fillCircle ( int cx,
int cy,
int r,
bool on = true )
inline

在屏幕上绘制实心圆。

基于中点圆的扫描线填充算法,效率通常足够。

Parameters
cx圆中点的 x 坐标。
cy中点的 y 坐标。
r圆的半径。
on绘制 or 擦除?

◆ fillRect()

template<unsigned COLS, unsigned ROWS>
void console::Screen< COLS, ROWS >::fillRect ( int x0,
int y0,
int x1,
int y1,
bool on = true )
inline

在屏幕上绘制实心矩形。

仅调用若干次 point,效率通常足够。

Parameters
x0点 A 的 x 坐标。
y0点 A 的 y 坐标。
x1点 B 的 x 坐标。
y1点 B 的 y 坐标。
on绘制 or 擦除?

◆ line()

template<unsigned COLS, unsigned ROWS>
void console::Screen< COLS, ROWS >::line ( int x0,
int y0,
int x1,
int y1,
bool on = true )
inline

在屏幕上绘制一条直线。

Bresenham 画线算法,效率通常足够。

Parameters
x0起始点的 x 坐标。
y0起始点的 y 坐标。
x1终止点的 x 坐标。
y1终止点的 y 坐标。
on绘制 or 擦除?

◆ point()

template<unsigned COLS, unsigned ROWS>
void console::Screen< COLS, ROWS >::point ( unsigned x,
unsigned y,
bool on = true )
inline

在屏幕上绘制一个点。

Parameters
x点的 X 坐标,向右为正。
y点的 y 坐标,向下为正。
on绘制 or 擦除?

< 静默忽略,就当画在外边了

◆ rect()

template<unsigned COLS, unsigned ROWS>
void console::Screen< COLS, ROWS >::rect ( int x0,
int y0,
int x1,
int y1,
bool on = true )
inline

在屏幕上绘制空心矩形。

仅调用 4 次 line,效率通常足够。

Parameters
x0点 A 的 x 坐标。
y0点 A 的 y 坐标。
x1点 B 的 x 坐标。
y1点 B 的 y 坐标。
on绘制 or 擦除?

◆ update()

template<unsigned COLS, unsigned ROWS>
void console::Screen< COLS, ROWS >::update ( std::ostream & os = std::cout,
bool clear = false ) const
inline

Screen 存储的虚拟屏幕输出到指定流。

内部使用临时字符串减少输出次数,减少 IO 导致的效率问题。

Parameters
os发送到的输出流。
Note
控制台 IO 通常是效率瓶颈,建议手动控制帧率。

The documentation for this class was generated from the following file: