![]() |
Gamedev Framework (gf)
0.10.0
A C++14 framework for 2D games
|
A virtual console. More...
#include <gf/Console.h>
Public Types | |
enum | PrintAction { PrintAction::None, PrintAction::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 | setDefaultBackground (const Color4f &color) |
Set the default background color. More... | |
const Color4f & | getDefaultBackground () const |
Get the default background color. More... | |
void | setDefaultForeground (const Color4f &color) |
Set the default foreground color. More... | |
const Color4f & | getDefaultForeground () const |
Get the default foreground color. More... | |
void | clear () |
Clear the console. More... | |
void | setCharBackground (Vector2i position, const Color4f &color, ConsoleEffect effect=ConsoleEffect::Set) |
Set the character background color. More... | |
const Color4f & | getCharBackground (Vector2i position) const |
Get the character background color. More... | |
void | setCharForeground (Vector2i position, const Color4f &color) |
Set the character foreground color. More... | |
const 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, ConsoleEffect effect=ConsoleEffect::Default) |
Modify a cell in the console. More... | |
void | putChar (Vector2i position, char16_t c, const Color4f &foreground, const Color4f &background) |
Modify a cell in the console. More... | |
String printing | |
void | setDefaultConsoleEffect (ConsoleEffect effect) |
Set the default console effect. More... | |
ConsoleEffect | getDefaultConsoleEffect () const |
Get the default console effect. More... | |
void | setDefaultAlignment (ConsoleAlignment alignment) |
Set the default alignment. More... | |
ConsoleAlignment | getDefaultAlignment () const |
Get the default alignment. More... | |
void | print (Vector2i position, const char *fmt,...) |
Print a formatted string. More... | |
void | print (Vector2i position, ConsoleEffect effect, ConsoleAlignment alignment, const char *fmt,...) |
Print a formatted string. More... | |
int | printRect (const RectI &rect, const char *fmt,...) |
Print a multi-line formatted string. More... | |
int | printRect (const RectI &rect, ConsoleEffect effect, ConsoleAlignment alignment, 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, const Color4f &foreground, const Color4f &background) |
Set a color for color control. More... | |
Advanced printing | |
void | drawRectangle (const RectI &rect, PrintAction action=PrintAction::None, ConsoleEffect effect=ConsoleEffect::Default) |
Draw a filled rectangle. More... | |
void | drawHorizontalLine (Vector2i left, int width, ConsoleEffect effect=ConsoleEffect::Default) |
Draw a horizontal line. More... | |
void | drawVerticalLine (Vector2i top, int height, ConsoleEffect effect=ConsoleEffect::Default) |
Draw a vertical line. More... | |
void | drawFrame (const RectI &rect, PrintAction action=PrintAction::None, ConsoleEffect effect=ConsoleEffect::Default, const char *title=nullptr,...) |
Draw a frame. More... | |
Screen fading | |
void | setFade (float amount, const Color4f &color) |
Set the fading parameters. More... | |
float | getFadingAmount () const |
Get the fading amount. More... | |
const 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... | |
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.
A console has a state with default values for different aspects:
Several functions use this state to determine actual values.
|
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 | ( | ) |
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, |
PrintAction | action = PrintAction::None , |
||
ConsoleEffect | effect = ConsoleEffect::Default , |
||
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 |
action | The action when drawing |
effect | The effect to apply to the background |
title | The format string of the title |
void gf::Console::drawHorizontalLine | ( | Vector2i | left, |
int | width, | ||
ConsoleEffect | effect = ConsoleEffect::Default |
||
) |
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 |
effect | The effect to apply to the background |
void gf::Console::drawRectangle | ( | const RectI & | rect, |
PrintAction | action = PrintAction::None , |
||
ConsoleEffect | effect = ConsoleEffect::Default |
||
) |
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 |
action | The action when drawing |
effect | The effect to apply to the background |
void gf::Console::drawVerticalLine | ( | Vector2i | top, |
int | height, | ||
ConsoleEffect | effect = ConsoleEffect::Default |
||
) |
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 |
effect | The effect to apply to the background |
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 |
|
inline |
Get the default background color.
|
inline |
Get the default console effect.
|
inline |
Get the default foreground color.
|
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 char * | fmt, | ||
... | |||
) |
Print a formatted string.
This function uses the default values for background color, foreground color, console effect and alignment.
The specified position indicates:
position | The position of a cell |
fmt | The format string |
void gf::Console::print | ( | Vector2i | position, |
ConsoleEffect | effect, | ||
ConsoleAlignment | alignment, | ||
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 |
effect | The effect to apply to the background |
alignment | The alignment of the text |
fmt | The format string |
int gf::Console::printRect | ( | const RectI & | rect, |
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 |
fmt | The format string |
int gf::Console::printRect | ( | const RectI & | rect, |
ConsoleEffect | effect, | ||
ConsoleAlignment | alignment, | ||
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 |
effect | The effect to apply to the background |
alignment | The alignment of the text |
fmt | The format string |
void gf::Console::putChar | ( | Vector2i | position, |
char16_t | c, | ||
ConsoleEffect | effect = ConsoleEffect::Default |
||
) |
Modify a cell in the console.
At the specified position, this function:
position | The position of the cell |
c | The character to set |
effect | The effect to apply to the background |
void gf::Console::putChar | ( | Vector2i | position, |
char16_t | c, | ||
const Color4f & | foreground, | ||
const Color4f & | background | ||
) |
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::setChar | ( | Vector2i | position, |
char16_t | c | ||
) |
void gf::Console::setCharBackground | ( | Vector2i | position, |
const 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, |
const Color4f & | foreground, | ||
const 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 |
|
inline |
Set the default background color.
color | The new background color |
|
inline |
|
inline |
Set the default foreground color.
color | The new foreground color |
|
inline |
Set the fading parameters.
amount | The fading amount, with 0 meaning the fading color and 1 meaning no fading |
color | The fading color |