![]() |
Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
|
A virtual console. More...
#include <gf/Console.h>
Public Types | |
enum class | PrintAction { None , Clear } |
An action when printing. More... | |
Public Member Functions | |
Console (const ConsoleFont &font, Vector2i size) | |
Constructor. More... | |
int | getWidth () const |
Get the width of the console. More... | |
int | getHeight () const |
Get the height of the console. More... | |
void | blit (const RectI &src, Console &con, Vector2i dst, float foregroundAlpha=1.0f, float backgroundAlpha=1.0f) const |
Blit a console on another console. More... | |
virtual void | draw (RenderTarget &target, const RenderStates &states) override |
Draw the object to a render target. More... | |
Basic printing | |
void | clear (const ConsoleStyle &style=ConsoleStyle()) |
Clear the console. More... | |
void | setCharBackground (Vector2i position, Color4f color, ConsoleEffect effect=ConsoleEffect::Set) |
Set the character background color. More... | |
Color4f | getCharBackground (Vector2i position) const |
Get the character background color. More... | |
void | setCharForeground (Vector2i position, Color4f color) |
Set the character foreground color. More... | |
Color4f | getCharForeground (Vector2i position) const |
Get the character foreground color. More... | |
void | setChar (Vector2i position, char16_t c) |
Set a character. More... | |
char16_t | getChar (Vector2i position) const |
Get a character. More... | |
void | putChar (Vector2i position, char16_t c, const ConsoleStyle &style=ConsoleStyle()) |
Modify a cell in the console. More... | |
void | putChar (Vector2i position, char16_t c, Color4f foreground, Color4f background) |
Modify a cell in the console. More... | |
String printing | |
void | print (Vector2i position, const ConsoleStyle &style, const char *fmt,...) |
Print a formatted string. More... | |
int | printRect (const RectI &rect, const ConsoleStyle &style, const char *fmt,...) |
Print a multi-line formatted string. More... | |
int | getHeight (const RectI &rect, const char *fmt,...) |
Get the expected number of console lines of a multi-line formatted string. More... | |
void | setColorControl (ConsoleColorControl ctrl, Color4f foreground, Color4f background) |
Set a color for color control. More... | |
Advanced printing | |
void | drawRectangle (const RectI &rect, const ConsoleStyle &style, PrintAction action=PrintAction::None) |
Draw a filled rectangle. More... | |
void | drawHorizontalLine (Vector2i left, int width, const ConsoleStyle &style) |
Draw a horizontal line. More... | |
void | drawVerticalLine (Vector2i top, int height, const ConsoleStyle &style) |
Draw a vertical line. More... | |
void | drawFrame (const RectI &rect, const ConsoleStyle &style, PrintAction action=PrintAction::None, const char *title=nullptr,...) |
Draw a frame. More... | |
Screen fading | |
void | setFade (float amount, Color4f color) |
Set the fading parameters. More... | |
float | getFadingAmount () const |
Get the fading amount. More... | |
Color4f | getFadingColor () const |
Get the fading color. More... | |
![]() | |
Transformable () | |
Default constructor. More... | |
void | setOrigin (Vector2f origin) |
Set the local origin of the object. More... | |
Vector2f | getOrigin () const |
Get the local origin of the object. More... | |
void | setPosition (Vector2f position) |
Set the position of the object. More... | |
Vector2f | getPosition () const |
Get the position of the object. More... | |
void | move (Vector2f offset) |
Move the object by a given offset. More... | |
void | setRotation (float angle) |
Set the orientation of the object. More... | |
float | getRotation () const |
Get the orientation of the object. More... | |
void | rotate (float angle) |
Rotate the object. More... | |
void | setScale (Vector2f factors) |
Set the scale factors of the object. More... | |
void | setScale (float factor) |
Set the scale factor of the object. More... | |
Vector2f | getScale () const |
Get the current scale of the object. More... | |
void | scale (Vector2f factors) |
Scale the object. More... | |
void | scale (float factor) |
Scale the object. More... | |
Matrix3f | getTransform () const |
Get the combined transform of the object. More... | |
Matrix3f | getInverseTransform () const |
Get the inverse of the combined transform of the object. More... | |
![]() | |
virtual | ~Drawable () |
Virtual desctructor. More... | |
virtual void | draw (RenderTarget &target, const RenderStates &states)=0 |
Draw the object to a render target. More... | |
Additional Inherited Members | |
![]() | |
void | setOriginFromAnchorAndBounds (Anchor anchor, const RectF &bounds) |
Set the origin from an anchor and bounds. More... | |
A virtual console.
A console is a virtual terminal where you can print the characters from a console font. Each cell of the console has a background color, a foreground color and a 8-bit character.
|
strong |
gf::Console::Console | ( | const ConsoleFont & | font, |
Vector2i | size | ||
) |
Constructor.
font | A console font |
size | The size of the console, in characters |
void gf::Console::blit | ( | const RectI & | src, |
Console & | con, | ||
Vector2i | dst, | ||
float | foregroundAlpha = 1.0f , |
||
float | backgroundAlpha = 1.0f |
||
) | const |
Blit a console on another console.
src | The source rectangle on the source console |
con | The destination console |
dst | The destination position on the destination console |
foregroundAlpha | The alpha of the blitted console foreground color, 0 is a completely transparent source console and 1 is a completely opaque source console |
backgroundAlpha | The alpha of the blitted console background color, 0 is a completely transparent source console and 1 is a completely opaque source console |
void gf::Console::clear | ( | const ConsoleStyle & | style = ConsoleStyle() | ) |
Clear the console.
For each cell of the console, this function:
|
overridevirtual |
Draw the object to a render target.
This is a pure virtual function that has to be implemented by the derived class to define how the drawable should be drawn.
target | Render target to draw to |
states | Current render states |
Implements gf::Drawable.
void gf::Console::drawFrame | ( | const RectI & | rect, |
const ConsoleStyle & | style, | ||
PrintAction | action = PrintAction::None , |
||
const char * | title = nullptr , |
||
... | |||
) |
Draw a frame.
This funtion first draws a rectangle using the specified action and effect. Then it draws a frame. If a title is given, it is printed on the top of the frame with inverted colors.
rect | The rectangle to print the rectangle |
style | The style to apply |
action | The action when drawing |
title | The format string of the title |
void gf::Console::drawHorizontalLine | ( | Vector2i | left, |
int | width, | ||
const ConsoleStyle & | style | ||
) |
Draw a horizontal line.
This function draws a horizontal line using gf::SpecialChar::WallHorizontalLine.
left | The left end point of the line |
width | The width of the line |
style | The style to apply |
void gf::Console::drawRectangle | ( | const RectI & | rect, |
const ConsoleStyle & | style, | ||
PrintAction | action = PrintAction::None |
||
) |
Draw a filled rectangle.
This function fills the specified rectangle with the default background color. If the print action is gf::PrintAction::Clear, then the characters inside the rectangle are set to space (ASCII 32).
rect | The rectangle to print the rectangle |
style | The style to apply |
action | The action when drawing |
void gf::Console::drawVerticalLine | ( | Vector2i | top, |
int | height, | ||
const ConsoleStyle & | style | ||
) |
Draw a vertical line.
This function draws a vertical line using gf::SpecialChar::WallVerticalLine.
top | The top end point of the line |
height | The height of the line |
style | The style to apply |
char16_t gf::Console::getChar | ( | Vector2i | position | ) | const |
Get a character.
position | The position of the cell |
Get the character background color.
position | The position of the cell |
Get the character foreground color.
position | The position of the cell |
|
inline |
Get the fading amount.
|
inline |
Get the fading color.
|
inline |
Get the height of the console.
int gf::Console::getHeight | ( | const RectI & | rect, |
const char * | fmt, | ||
... | |||
) |
Get the expected number of console lines of a multi-line formatted string.
This function does not print anything, it only computes the number of lines that a formatted string would take if it was printed with printRect()
rect | The rectangle to print the string |
fmt | The format string |
|
inline |
Get the width of the console.
void gf::Console::print | ( | Vector2i | position, |
const ConsoleStyle & | style, | ||
const char * | fmt, | ||
... | |||
) |
Print a formatted string.
This function uses the default values for background color, foreground color but uses the specified console effect and alignment.
The specified position indicates:
position | The position of a cell |
style | The style to apply to the text |
fmt | The format string |
int gf::Console::printRect | ( | const RectI & | rect, |
const ConsoleStyle & | style, | ||
const char * | fmt, | ||
... | |||
) |
Print a multi-line formatted string.
The string is split in paragraphs according to new lines and then split in lines to fit the width of the specified rectangle. If the specified height is reached, the string is truncated. I the height is 0, then the string is truncated at the bottom of the console.
rect | The rectangle to print the string |
style | The style to apply to the text |
fmt | The format string |
Modify a cell in the console.
At the specified position, this function:
position | The position of the cell |
c | The character to set |
foreground | The foreground color to set |
background | The background color to set |
void gf::Console::putChar | ( | Vector2i | position, |
char16_t | c, | ||
const ConsoleStyle & | style = ConsoleStyle() |
||
) |
Modify a cell in the console.
At the specified position, this function:
position | The position of the cell |
c | The character to set |
style | The style to apply |
void gf::Console::setChar | ( | Vector2i | position, |
char16_t | c | ||
) |
void gf::Console::setCharBackground | ( | Vector2i | position, |
Color4f | color, | ||
ConsoleEffect | effect = ConsoleEffect::Set |
||
) |
Set the character background color.
position | The position of the cell |
color | The new background color |
effect | The effect to apply to background |
Set the character foreground color.
position | The position of the cell |
color | The new foreground color |
void gf::Console::setColorControl | ( | ConsoleColorControl | ctrl, |
Color4f | foreground, | ||
Color4f | background | ||
) |
Set a color for color control.
Color control codes allow to change color in a string on the fly. There are five color control codes: gf::ConsoleColorControl1, gf::ConsoleColorControl2, gf::ConsoleColorControl3, gf::ConsoleColorControl4 and gf::ConsoleColorControl5. Each one is associated with a foreground and a background color that you can set with this function. The color control code gf::ConsoleColorControlStop changes the colors back to their default.
|
inline |
Set the fading parameters.
amount | The fading amount, with 0 meaning the fading color and 1 meaning no fading |
color | The fading color |