osmanip
Library with useful output stream tools like: color and style manipulators, progress bars and terminal graphics.
Public Member Functions | Protected Attributes | List of all members
osm::Canvas Class Reference

Instances of this class are used to draw in a limited 2D space. All the functions that modify the canvas do it internally; to make the changes effective in the console, you must use the refresh method. More...

#include <canvas.hpp>

Inheritance diagram for osm::Canvas:
Inheritance graph
[legend]

Public Member Functions

 Canvas (uint32_t width, uint32_t height)
 Construct a new Canvas:: Canvas object. The size of the canvas in characters must be specified upon construction. More...
 
void enableFrame (bool frame_enabled)
 Flag to frame or not the canvas. The frame doesn't increase the size taken by the canvas. Instead, reduces the 2D space to draw in two columns and two rows (used to print the frame itself). More...
 
void setFrame (FrameStyle, std::string_view feat="")
 Set the FrameStyle of the canvas and an optional feat. More...
 
void setBackground (char c, std::string_view feat="")
 Set the char that fills the background and an optional feat. More...
 
void setWidth (uint32_t width)
 Set the width of the canvas. More...
 
void setHeight (uint32_t height)
 Set the height of the canvas. More...
 
char getBackground () const
 Get the char that fills the background. More...
 
std::string getBackgroundFeat () const
 Get the optional feat of the background. More...
 
bool isFrameEnabled () const
 Return True if the frame is enabled. Otherwise return False. More...
 
std::string getFrameFeat () const
 Get the frame feature (if set). More...
 
FrameStyle getFrameStyle () const
 Get the frame style. More...
 
uint32_t getWidth () const
 Get the width of the canvas. More...
 
uint32_t getHeight () const
 Get the height of the canvas. More...
 
void clear ()
 Fill the canvas with the background. More...
 
void put (uint32_t x, uint32_t y, char c, std::string_view feat="")
 Put a character in the canvas, given its coordinates and an optional feat. An out-of-bounds exception will be thrown if the coordinates are outside the canvas. More...
 
void refresh ()
 Display the canvas in the console. More...
 

Protected Attributes

uint32_t width_
 
uint32_t height_
 

Detailed Description

Instances of this class are used to draw in a limited 2D space. All the functions that modify the canvas do it internally; to make the changes effective in the console, you must use the refresh method.

Constructor & Destructor Documentation

◆ Canvas()

osm::Canvas::Canvas ( uint32_t  width,
uint32_t  height 
)
explicit

Construct a new Canvas:: Canvas object. The size of the canvas in characters must be specified upon construction.

Parameters
widthWidth of the canvas.
heightHeight of the canvas.

Member Function Documentation

◆ clear()

void osm::Canvas::clear ( )

Fill the canvas with the background.

◆ enableFrame()

void osm::Canvas::enableFrame ( bool  frame_enabled)

Flag to frame or not the canvas. The frame doesn't increase the size taken by the canvas. Instead, reduces the 2D space to draw in two columns and two rows (used to print the frame itself).

Parameters
frame_enabledSet to True to enable the frame. Otherwise set to False.

◆ getBackground()

char osm::Canvas::getBackground ( ) const

Get the char that fills the background.

Returns
char The char that fills the background.

◆ getBackgroundFeat()

std::string osm::Canvas::getBackgroundFeat ( ) const

Get the optional feat of the background.

Returns
std::string The optional feat of the background.

◆ getFrameFeat()

std::string osm::Canvas::getFrameFeat ( ) const

Get the frame feature (if set).

Returns
std::string The frame feature.

◆ getFrameStyle()

FrameStyle osm::Canvas::getFrameStyle ( ) const

Get the frame style.

Returns
FrameStyle The frame style.

◆ getHeight()

uint32_t osm::Canvas::getHeight ( ) const

Get the height of the canvas.

Returns
uint32_t The height of the canvas.

◆ getWidth()

uint32_t osm::Canvas::getWidth ( ) const

Get the width of the canvas.

Returns
uint32_t The width of the canvas.

◆ isFrameEnabled()

bool osm::Canvas::isFrameEnabled ( ) const

Return True if the frame is enabled. Otherwise return False.

Returns
bool The frame enabled flag.

◆ put()

void osm::Canvas::put ( uint32_t  x,
uint32_t  y,
char  c,
std::string_view  feat = "" 
)

Put a character in the canvas, given its coordinates and an optional feat. An out-of-bounds exception will be thrown if the coordinates are outside the canvas.

Parameters
cThe char to put.
xThe x position.
yThe y position.
featThe optional feature.

◆ refresh()

void osm::Canvas::refresh ( )

Display the canvas in the console.

◆ setBackground()

void osm::Canvas::setBackground ( char  c,
std::string_view  feat = "" 
)

Set the char that fills the background and an optional feat.

Parameters
cThe char that fills the background.
featThe optional feat.

◆ setFrame()

void osm::Canvas::setFrame ( FrameStyle  fs,
std::string_view  feat = "" 
)

Set the FrameStyle of the canvas and an optional feat.

Parameters
fsThe FrameStyle of the canvas.
featThe optional feature.

◆ setHeight()

void osm::Canvas::setHeight ( uint32_t  height)

Set the height of the canvas.

Parameters
heightThe canvas height to set.

◆ setWidth()

void osm::Canvas::setWidth ( uint32_t  width)

Set the width of the canvas.

Parameters
widthThe canvas width to set.

Member Data Documentation

◆ height_

uint32_t osm::Canvas::height_
protected

◆ width_

uint32_t osm::Canvas::width_
protected

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