Skip to content

Console Screen Old (v1)

Hapax edited this page Jun 27, 2016 · 1 revision

Introduction

A class to draw a console screen. The object can be used in a similar fashion to console programming. e.g. moving a cursor around, changing foreground and background colours, "printing" and "reading" strings, "stretching" cells to allow double-height cells, scrolling, and accessing colours and cell values (the 'character' at that position) separately, as well as inverting, flipping and darkening cells using simple cell attributes

This class is a particularly complex one so this page will grow as more information is required, especially as the class grows (more features do get added!)

The class has now been updated to version 1.5. For an overview of the changes to the object, read its change log

Usage

Declaration

sw::ConsoleScreenV1 consoleScreen;
creates a Console Screen with the default mode (see below)

sw::ConsoleScreenV1 consoleScreen(sf::Vector2u);
creates a Console Screen with a mode determined by the given sf::Vector2u. A mode is the number of cells used to fit the screen

Drawing

This class inherits from sf::Drawable so it is drawn in the same way as all SFML drawables:
window.draw(consoleScreen);
where window is an sf::RenderWindow.

Transformations

This class inherits from sf::Transformable so it has all the usual SFML transformations available.

Manipulation

Description

Console Screen works similarly to a basic tile map in that it holds values for each cell (tile) and displays a specific part of a texture based on that value, modified by a colour. Console Screen is a specialised version that allows strings to update multiple cells at once. Console Screen also uses a similar "tile map" that draws each cells as individual solid colours beneath the texture cells. This acts as a background colour for the cells and background drawing can be switched off.

"Printing" is the act of changing the cells based on a character or a string. It stores a cursor (position and colour) as well as foreground and background colours that are used for future printing. All of these things can be overridden temporarily which printing.

Version 1.2 brings copying/pasting abilites to Console Screen. The entire screen's content can be copied into a buffer. A specified rectangular region (selection) can be copied into a buffer instead of the entire screen. These buffers can be retrieved and "pasted" with an offset (from the top-left corner). Multiple different buffers can be stored, manipulated and removed.

Also with version 1.2 comes "painting". Painting works like a highlighter - drawing colour over cells without affecting the actual values (characters etc.).

Version 1.3 brings "stretch" abilities. This allows cells to be either unstretched or half of a double-height cell. New printing methods (printStretchedAt) allow printing both halves of a double-height cell together

Also with version 1.3 comes "cell attributes". These are "flags"/switches/booleans that can be switched on or off (or be true or false). Available attributes are: inverse, bright, flip x, and flip y. These affect how the cell is displayed and each cell can have its own set of attributes, independent of other cells

Version 1.4 brings "character mapping". This allows certain characters to be automatically converted to chosen cell values. No longer is the entire ASCII set required; only the characters you use can be included in the texture

Also with version 1.4 comes "reading", which is the act of retrieving a string from consecutive cells's values. Reading can also "unmap" cell values to their mapped characters

Also added to version 1.4 is the ability to specify a texture offset, which allows a sub-texture to be used (or any texture that no longer is required to be at the top-left of the texture)

Console Screen also provides convenient methods of scrolling the cells. That is, moving them all in the same direction. All four axis directions are available and can be scrolled any number of times. Console Screen can also automatically "wrap" the contents of the cells scrolled out of range to appear on the opposite side instead of just clearing them.

Console Screen has colour palettes which can be accessed using indices. It comes with a number of palettes that can be loaded simply by specifying the palette using an enum. It's also possible to create your own palette or add/change one of the provided palettes.

There is also extra control over the cursor with some text-editing-style controls plus the ability to change the cursor's value (tile/character).

Colours

Colours in most cases can be specified in three ways: a direct sf::Color, a colour index (palette colour) or a "colour command". Colour commands are specified using negative values for the colour index. There are enums provided to make these values readable. The colour commands tell Console Screen to generate a colour automatically and how to do so.

An "opposite colour" is the opposite of main and background. Thus, main is the opposite colour of background.

Colour ID

Methods take either a direct sf::Color or a colour ID. A colour ID is used to specify a palette colour index or a colour command. Positive (and zero) values are used for colour indices whereas negative values are used for commands.

Colour command enums are in the namespace of "Color" inside the "ConsoleScreenV1" namespace. e.g. sw::ConsoleScreenV1::Color::Current. Since they are standard enums, they can also be used without the "Color" part of the enum but they make less sense without it.

Commands

The commands are listed here along with their numerical values in brackets, which are possible to be used directly.

  • ConsoleScreenV1::Color::Current (-1)
    uses the colour that is currently stored in current colours. If this command is used for a main (foreground) colour, it uses the current main colour. Conversely, if this command is used for a background colour, it uses the current background colour. However, if this command is used for the cursor colour, it uses the main colour

  • ConsoleScreenV1::Color::Ignore (-2)
    leaves the colour at the cell unchanged. If no cell is required for the method (e.g. setColor), it still changes nothing. If this is used for clear, the current background colour is used

  • ConsoleScreenV1::Color::Invert (-3)
    inverts the opposite colour (see above). If used for setting the cursor colour, it inverts the current background colour. Main colour is always inverted after background colour is decided. If used for clear, it inverts the current main colour. "Invert" means a direct inversion of the colour's channels. e.g. (200, 150, 1) inverted is (55, 105, 254)

  • ConsoleScreenV1::Color::Contrast (-4)
    contrasts the opposite colour (see above). Main colour is always contrasted after background colour is decided. If used for clear, it contrasts the current main colour

Setup

  • setMode(sf::Vector2u)
    takes an sf::Vector2u that represents the mode, which is the number of cells used to fit the screen. The mode can be provided in the constructor (see above in declaration) but can also be used here to change the mode at any time
    Note: this method has been renamed from v1.0 to v1.1 (was create())

Texture Setup

  • setTexture(sf::Texture)
    takes an sf::Texture and stores a pointer to it. This means that the texture should exist (at its current memory position) as long as Console Screen requires it. This texture can be changed whenever you like and should be reset if the current texture is moved in memory. You can also use this method to nullify the texture by omitting the parameter

  • setTextureTileSize(sf::Vector2u)
    takes an sf::Vector2u that specifies the size of each tile (the section of texture to be shown in each cell)

  • setTextureOffset(sf::Vector2u)
    takes an sf::Vector2u that specifies the offset to use inside the texture for that actual texture rectangles

  • setNumberOfTextureTilesPerRow(unsigned int)
    takes an unsigned int that informs Console Screen how many texture tiles there are per row in the texture

Switches

These methods enable or disable the switch depending on the value of the bool. The descriptions here are for when the switches are enabled.
Note: these methods have been renamed from v1.0 to v1.1

  • setThrowExceptions(bool)
    throws exceptions on errors/mis-use

  • setUpdateAutomatically(bool)
    updates automatically (and dynamically) whenever anything changes otherwise a manual update() call is required

  • setShowCursor(bool)
    shows the cursor

  • setShowBackground(bool)
    shows the cells' backgrounds

  • setScroll(bool)
    scrolls the screen upwards once if the cursor runs out of cells while printing or when moving the cursor using the cursorDown, cursorRight, cursorNextLine() or cursorTab() methods.

  • setWrapOnManualScroll(bool)
    wraps the contents to the opposite side when scrolling manually

  • setInvertCursor(bool)
    instructs the cell in which the cursor resides to swap its main and background colours

  • setUseCursorColor(bool)
    displays the cursor using its own colour otherwise it uses the colour from the cell in which it resides

Visual Representation

  • update()
    updates the visual representation of the Console Screen from its current state. Not required if Update Automatically switch is enabled (see above)

  • setSize(sf::Vector2f)
    sets the size of the Console Screen

Global

  • clear(unsigned int backgroundColorId)
    clears all the cells (sets their values to zero) with the colour specified by the color ID (see Colours section above). The default value is a command that clears with current colours

  • clear(sf::Color)
    clears all the cells (sets their values to zero) with the current foreground colour and the specified sf::Color as the new background colours

  • crash()
    randomises all values and colours of all cells to create a crash-like screen

Current Colours

All colours can be of type sf::Color or a Colour ID (see above)

  • setColor(color)
    sets the current main colour (foreground colour/colour of the texture)

  • setBackgroundColor(backgroundColor)
    sets the current background colour

  • setCursorColor(cursorColor)
    sets the current cursor colour (the cursor is shown in this colour regardless of the colour in its cell)

  • setColors(color, backgroundColor [, cursorColor])
    sets the current colours of the main colour (foreground colour/colour of the texture), the background colour, and (optionally) the cursor colour

Current Stretch

  • setStretch(stretch)
    sets the current stretch. This value is an enum class of type ConsoleScreenV1::Stretch and can be any of three values (None, Top, Bottom) that describe how this cell is stretched

Current Attributes

  • setAttributes(attributes)
    sets all attributes to match the passed attributes parameter, which is of type ConsoleScreenV1::CellAttributes and contains all of the boolean attributes for a cell

  • setAttribute(bool, attribute)
    sets the single attribute specified by attribute to the value of the bool. attribute is an enum class of type ConsoleScreenV1::Attribute, which specifies which attribute you wish to set. Valid values are: Inverse, Bright, FlipX, FlipY

Cursor

If "distance" is provided, the cursor is moved that many times, otherwise it is only moved by one cell.
If "tabSize" is provided, the cursor is moved based on tabs of that size, otherwise it will assume the default tab size (4)

  • cursorLeft(unsigned int distance)
    moves the cursor left

  • cursorRight(unsigned int distance)
    moves the cursor right

  • cursorDown(unsigned int distance)
    moves the cursor down

  • cursorUp(unsigned int distance)
    moves the cursor up

  • cursorHome()
    moves the cursor to the home position: top-left or (0, 0)

  • cursorHomeLine()
    moves the cursor to the beginning of the current line

  • cursorEnd()
    moves the cursor to the end position: bottom-right or (getMode().x - 1, getMode().y - 1)

  • cursorEndLine()
    moves the cursor to the end of the current line

  • cursorTab(unsigned int tabSize)
    moves the cursor to the right until it reaches the next tab position, which is determined by tabSize

  • cursorTabReverse(unsigned int tabSize)
    moves the cursor the the left until it reaches a tab position, which is determined by tabSize

  • cursorNextline()
    moves the cursor to the beginning of the line below its current position. If the cursor is already on the bottom line/row before calling this method, the screen will scroll (if ScrollAutomatically switch is set to true) or the cursor will be moved to the end position (see above). Scrolling can affect the contents of the cells

  • cursorBackspace()
    moves the cursor to the left by one cell and then clears the cell that it lands in

  • moveCursor(offset)
    moves the cursor by the amount in offset. The offset parameter is of type sf::Vector2i

  • setCursor(location)
    moves the cursor to the exact location specified. The location parameter is of type sf::Vector2u

  • setCursor(unsigned int cellValue)
    sets the value of the cursor. This is the tile/character that is the cursor's visual representation. A negative value (-1) allows all the cursor features to be used without actually drawing any tile

  • setCursor(char, bool)
    sets the value of the cursor to match the passed char. If the bool is true, the character is also mapped

Printing

Using The Cursor

Cursor is moved to the cell directly after (to the right) of the final cell that is printed.
Colour IDs can be used to alter the colours using the colour palette or colour commands. The default state for these IDs are ConsoleScreenV1::Color::Current, which means that printing uses the current colours

  • print(char, colorId, backgroundColorId)

  • print(std::string, colorId, backgroundColorId)
    prints the char or the entire string, starting from the cursor position. If the right-hand side of the screen is reached, printing will continue from the beginning of the next row down

  • printLine(std::string, bool overwriteColor, bool overwriteBackgroundColor)
    identical to "print()" above but also calls cursorNextline() (see Cursor section above)

Directly

The location parameter is a sf::Vector2u representing the cell to print into (or starting cell in the case of printAt).
The parameters of type "Color" can be either a direct sf::Color or a colour ID (see Colour section above)

  • printAt(sf::Vector2u location, char character, Color color, Color backgroundColor)
  • printAt(sf::Vector2u location, std::string string, Color color, Color backgroundColor)
    prints the char or string starting from the specified location using the specified colours. The default values for Color - if omitted - is ConsoleScreenV1::Color::Ignore, which prints without altering the colours of the cells that are printed to. Does not affect the cursor

Stretched (Directly)

The location parameter is a sf::Vector2u representing the cell to print into (char) or starting cell (string).
The parameters of type "Color" can be either a direct sf::Color or a colour ID (see Colour section above). Printing stretched automatically prints the top and bottom part of the double-height cell together.

  • printStretchedAt(sf::Vector2u location, char character, Stretch stretch, Color color, Color backgroundColor)
  • printStretchedAt(sf::Vector2u location, std::string string, Stretch stretch, Color color, Color backgroundColor)
    prints the char or string starting from the specified location using the specified colours (see printAt for more information). If stretch is Stretch::None, nothing is printed. If stretch is Stretch::Top (or omitted), it prints the top line of the double-height printing on the line of the starting cell and the bottom line on the line below. If stretch is Stretch::Bottom, it prints the bottom line of the printing on the line of the starting cell and the top line on the line above. Note: color and backgroundColor types cannot be mixed here - both must be palette ID/command or both must be sf::Colors

Painting

Directly

The location parameter is a sf::Vector2u representing the cell from which to begin painting.
The parameters of type "Color" can be either a direct sf::Color or a colour ID (see Colour section above)

  • paintAt(sf::Vector2u location, unsigned int length, Color color, Color backgroundColor)
    paints length number of cells starting from the specified location using the specified colours. The default value for color - if omitted - is ConsoleScreenV1::Color::Current, which paints using the current colour. The default value for backgroundColor - if omitted - is ConsoleScreenV1::Color::Ignore, which paints without altering the colours of the cells that are painted to. Does not affect the cursor

Attributes (Directly)

The location parameter is a sf::Vector2u representing the cell from which to begin painting.
The attribute parameter is of type ConsoleScreenV1::Attribute and can be any valid attribute type: Inverse, Bright, FlipX, FlipY

  • paintAt(sf::Vector2u location, unsigned int length, bool attributeValue, Attribute attribute)
    paints length number of cells starting from the specified location using the specified attribute of value attributeValue. The default value for attribute - if omitted - is ConsoleScreenV1::Attribute::Inverse, which paints the Inverse attribute. Does not affect the cursor

Reading

Using The Cursor

Cursor is moved the cell directly after (to the right) of the final cell that is read

  • read(unsigned int length, bool unmapCharacters)
    reads a string of the specified length, starting from the cursor position. If the right-hand side of the screen is reached, reading will continue from the beginning of the next row down. If unmapCharacters is true, the cell's value is attempted to be converted to its mapped character, if it exists, otherwise uses the actual value of the cell. If it is false, it only uses the actual value of the cell. If it is omitted, it is taken as true. If length is omitted, a length of 1 is used

Directly

The location parameter is a sf::Vector2u representing the starting cell to begin reading from

  • readAt(sf::Vector2u location, unsigned int length, bool unmapCharacters)
    reads a string of the specified length, starting from the specified location. See read() above for information about unmapCharacters. Does not affect the cursor

Character Mapping

  • setMappedCharacter(character, value)
    sets the mapping for the specified character to be replaced by the specified cell value when printing. Reading can "unmap", which is finding the character that is mapped to that cell value

  • setMappedCharacters(characters, initialValue)
    sets the mapping for the characters in the specified string (characters) to be replaced by a cell value when printing. The cell value is the specified initial value for the first character and increased by one for each following character in the string. Reading can "unmap", which is finding the character that is mapped to that cell value

  • removeMappedCharacter(character)
    removes the mapping for the specified character, if one exists

  • removeMappedCharacters(characters)
    removes the mapping for all of the characters in the specified string (characters), if each exists

Cells

The location parameter is a sf::Vector2u representing the cell to modify.
The parameters of type "Color" can be either a direct sf::Color or a colour ID (see Colour section above)

  • clearCellAt(sf::Vector2u location)
    clears the cell (sets its value to zero, sets its colours to the current colours) at the given cell location

  • setCellAt(sf::Vector2u location, Cell cell)
    sets the cell at the location to the provided cell (of type ConsoleScreenV1::Cell). This cell contains all of the information for a single cell

  • setValueAt(sf::Vector2u location, unsigned int value)
    sets the cell's value at the location to the provided unsigned int value

  • setColorAt(sf::Vector2u location, Color color)
    sets the cell's main colour at the location

  • setBackgroundColorAt(sf::Vector2u location, Color backgroundColor)
    sets the cell's background colour at the location

  • setColorsAt(sf::Vector2u location, Color color, Color backgroundColor)
    sets both of the cell's colours at the location

  • setStretchAt(sf::Vector2u location, Stretch stretch)
    sets the cell's stretch value at the location

  • setAttributesAt(sf::Vector2u location, CellAttributes attributes)
    sets the cell's attributes at the location

  • setAttributeAt(sf::Vector2u location, bool attributeValue, Attribute attribute)
    sets the cell's single attributes at the location. The attribute affect is selected with attribute

Buffers

Buffers (or "clipboards") store rectangular regions of cells - up to the entire screen size (mode), which is the default if the rectangular region is not specified. They can be used to copy small parts of text or even capture a screenshot!

  • copy(selectionRectangle)
    copies the cells in the selection (sf::IntRect) to a new buffer. If selectionRectangle is omitted, the entire screen is copied

  • paste(offset)
    pastes the buffer onto the screen offset by the specified offset (sf::Vector2i), which can have negative values. If offset is omitted, offset becomes (0, 0), which means that the top-left of the buffer is pasted at the top-left of the screen

  • removeBuffer()
    removes the most recently added buffer. See copy() above

  • copy(index, selectionRectangle)
    as copy() above but instead of creating a new buffer, it copies into (replaces) an already existing buffer specifed by the buffer index. The selectionRectangle can also be omitted here

  • paste(index, offset)
    as paste() above but instead of pasting the most recently added buffer, it pastes from the buffer specified by the buffer index. The offset can also be omitted here

  • removeBuffer(index)
    removes the buffer specified by the buffer index

  • removeAllBuffers()
    removes all stored buffers

Manual Scrolling

If amount is provided, the screen is scrolled that many times, otherwise it is only scrolled once If the Wrap On Manual Scroll switch is enabled, the cells "pushed off the edge" appear on the opposite side, otherwise the new cells are cleared

  • scrollUp(unsigned int amount)
    scrolls the screen up (all cells are moved upwards)

  • scrollDown(unsigned int amount)
    scrolls the screen down (all cells are moved downwards)

  • scrollRight(unsigned int amount)
    scrolls the screen right (all cells are moved to the right)

  • scrollLeft(unsigned int amount)
    scrolls the screen left (all cells are moved to the left)

Colour Palette

  • loadPalette(palette)
    loads a supplied palette. Replaces any current palette. The parameter is a strongly-typed enum that allows a choice of available palettes. The list of enum values is below

  • addColorToPalette(sf::Color)
    adds an sf::Color to the end of the palette

  • setPaletteColor(colorId, sf::Color color)
    sets the palette colour specified by colorId (must be an available palette colour index and commands are not allowed), to the specified sf::Color

  • setPaletteSize(size)
    sets the palette to contain "size" number of colours

  • removePaletteColor(colorId)
    removes the palette colour specified by colorId (must be an available palette colour index and commands are not allowed)

Available Palette Enum Values

  • ConsoleScreenV1::Palette::Default
    A basic 16-colour palette

  • ConsoleScreenV1::Palette::Colors2BlackWhite
    A 2-colour palette: first colour is black; second colour is white

  • ConsoleScreenV1::Palette::Colors2WhiteBlack
    A 2-colour palette: first colour is white; second colour is black

  • ConsoleScreenV1::Palette::Colors16Greenscale
    A 16-colour palette: 16 shades of green from full black (0, 0, 0) to full green (0, 255, 0)

  • ConsoleScreenV1::Palette::Colors16Grayscale
    A 16-colour palette: 16 shades of grey from full black (0, 0, 0) to full white (255, 255, 255)

  • ConsoleScreenV1::Palette::Colors16Sepia
    A 16-colour palette: 16 shades of sepia starting from full black (0, 0, 0), passing through sepia tones to almost white

  • ConsoleScreenV1::Palette::Colors16Cga
    A 16-colour palette based on the CGA display palette

  • ConsoleScreenV1::Palette::Colors16CgaNonIbm
    A 16-colour palette based on the earlier, non-IBM compatible CGA display palette (identical to Colors16ZxSpectrum below)

  • ConsoleScreenV1::Palette::Colors16Windows
    A 16-colour palette based on Windows' default 16-colour palette

  • ConsoleScreenV1::Palette::Colors16Mac
    A 16-colour palette based on Mac's default 16-colour palette

  • ConsoleScreenV1::Palette::Colors16ZxSpectrum
    A 16-colour palette based on the ZX Spectrum's palette

  • ConsoleScreenV1::Palette::Colors216Web
    A 216-colour palette of so-called "web-safe" colours

  • ConsoleScreenV1::Palette::Colors256Greenscale
    A 256-colour palette: 256 shades of green from full black (0, 0, 0) to full green (0, 255, 0)

  • ConsoleScreenV1::Palette::Colors256Grayscale
    A 256-colour palette: 256 shades of grey from full black (0, 0, 0) to full white (255, 255, 255)

  • ConsoleScreenV1::Palette::Colors256Sepia
    A 256-colour palette: 256 shades of sepia starting from full black (0, 0, 0), passing through sepia tones to almost white

Direct manipulation

Similar to cell manipulation above, but takes a cell index rather than a cell location.
Poke cannot use colour IDs and therefore cannot use palette colours or colour commands

  • poke(unsigned int index, Cell cell)
    changes the cell at index to the new cell

  • poke(unsigned int index, unsigned int value)
    changes the value of the cell at index

  • poke(unsigned int index, sf::Color color)
    changes the colour of the cell at index

  • poke(unsigned int index, sf::Color color, sf::Color backgroundColor)
    changes the colours (main/foreground colour and background colour) of the cell at index

  • poke(unsigned int index, Stretch stretch)
    changes the stretch of the cell at index

  • poke(unsigned int index, CellAttributes attributes)
    changes the attributes of the cell at index

  • poke(unsigned int index, bool attributeValue, Attributes attribute)
    changes the single attribute of the cell at index. The attribute is selected with attribute

Information

Setup

  • getMode()
    returns an sf::Vector2u of the current mode (number of cells in each dimension)

  • getNumberOfCells()
    returns an unsigned int of the total number of cells. This is equivalent to getMode().x * getMode().y

Texture Setup

  • getNumberOfTilesInTexture2d()
    returns an sf::Vector2u of the number of tiles that are usable in the texture (within the specified "numberOfTextureTilesPerRow" and within the height of the texture)

  • getNumberOfTilesInTexture()
    returns an unsigned int of the total number of usable tiles in the texture. This is equivalent to getNumberOfTilesInTexture2d().x * getNumberOfTilesInTexture2d().y

Switches

A bool is returns representing if that switch is set to true

  • getThrowExceptions()
  • getUpdateAutomatically()
  • getShowCursor()
  • getShowBackground()
  • getScrollAutomatically()
  • getWrapOnManualScroll()
  • getInvertCursor()
  • getUseCursorColor()

Visual Representation

  • getSize()
    returns an sf::Vector2f of the size of the Console Screen (see setSize above)

  • getLocalBounds()
    returns an sf::FloatRect that contains the Console Screen before any SFML transformations

  • getGlobalBounds()
    returns an sf::FloatRect that contains the Console Screen after any SFML transformations

Current Colours

  • getColor()
    returns an sf::Color of the current colour

  • getBackgroundColor()
    returns an sf::Color of the current background colour

  • getCursorColor()
    returns an sf::Color of the current cursor colour

Current Stretch

  • getStretch()
    returns a type ConsoleScreenV1::Stretch of the current stretch value

Current Attributes

  • getAttributes()
    returns a type ConsoleScreenV1::CellAttributes of the current attributes

  • getAttribute(Attribute attribute)
    returns a bool of the current stated of the attribute selected with attribute

Cursor

  • getCursor()
    returns an sf::Vector2f of the current cursor position

Character Mapping

  • getIsMappedCharacter(character)
    returns a bool representing if the specified character currently has a mapping associated with it

  • getMappedCharacter(character)
    returns an unsigned int representing the cell value to which the specified character is mapped

Palette

  • getPaletteColor(colorId)
    returns an sf::Color of the palette colour at the index provided by the colour ID. Colour commands are not usable here.

  • getPaletteSize()
    returns an unsigned int of the number of colours in the palette. There must always be at least one colour in the palette so this value can never be zero

Buffers

  • getNumberOfBuffers()
    returns an unsigned int of the number of buffers that are currently stored

Cells

  • getValueAt(location)
    returns an unsigned int representing the value of the cell at the specified location (sf::Vector2u)

  • getColorAt(location)
    returns an sf::Color of the cell's colour at the specified location (sf::Vector2u)

  • getBackgroundColorAt(location)
    returns an sf::Color of the cell's background colour at the specified location (sf::Vector2u)

  • getCellAt(location)
    returns the entire cell (of type ConsoleScreenV1::Cell - see setCell()) that is at the specified location (sf::Vector2u)

  • getAttributesAt(location)
    returns the entire cell's attributes (of type ConsoleScreenV1::CellAttributes - see setAttributes()) that is at the specified location (sf::Vector2u)

  • getAttributeAt(location, Attribute attribute)
    returns a bool of the cell's selected attribute - selected with attributevalue - that is at the specified location (sf::Vector2u)

Direct Manipulation

  • peek(unsigned int index)
    returns a type ConsoleScreenV1::Cell (the entire cell) from the cell at index

Simple Example

#include <SFML/Graphics.hpp>
#include <SelbaWard/ConsoleScreenOld.hpp>
int main()
{
    sf::RenderWindow window(sf::VideoMode(320, 300), "Console Screen simple example");
    sf::Texture consoleScreenTexture;
    if (!consoleScreenTexture.loadFromFile("resources/Windows Console ASCII.png"))
        return EXIT_FAILURE;
    sw::ConsoleScreenV1 consoleScreen({ 16, 9 });
    consoleScreen.setTexture(consoleScreenTexture);
    consoleScreen.setTextureTileSize({ 8, 12 });
    consoleScreen.setNumberOfTextureTilesPerRow(16);
    consoleScreen.setSize({ 256.f, 216.f }); // scaled x2
    consoleScreen.setOrigin(consoleScreen.getLocalBounds().width / 2.f, consoleScreen.getLocalBounds().height / 2.f);
    consoleScreen.setPosition(sf::Vector2f(window.getSize() / 2u));
    consoleScreen.setRotation(20);
    consoleScreen.crash(); // randomise cells' values and colours
    consoleScreen.printAt({ 5, 2 }, "Selba", sf::Color::Cyan, sf::Color::Blue);
    consoleScreen.printAt({ 6, 3 }, "Ward!", sf::Color::White, sf::Color::Blue);
    consoleScreen.setColors(sf::Color::Green, sf::Color::Black);
    consoleScreen.setCursor({ 3, 5 });
    consoleScreen.print("Console");
    consoleScreen.setCursor({ 7, 6 });
    consoleScreen.print("Screen");
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        window.clear();
        window.draw(consoleScreen);
        window.display();
    }
    return EXIT_SUCCESS;
}

The code above displays:
Simple Example
(this will display differently every time as the majority of its cells are randomly generated)

Note: the texture for this example is available, along with more examples, in the examples folder, although you can use your own images.

(ConsoleScreen v1.5)