KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
KTech::Texture Struct Reference

A CellA-based sprite. More...

#include <texture.hpp>

Public Member Functions

auto Simple (UPoint size, CellA value) -> Texture &
 Create a simple Texture (uniform rectangle).
 
auto Simple (UPoint size, CellA value, Point relativePosition) -> Texture &
 Create a simple Texture (uniform rectangle), and set its relative position.
 
auto Rectangle (UPoint size, CellA value) -> Texture &
 Create a complex Texture that is a uniform rectangle.
 
auto Rectangle (UPoint size, CellA value, Point relativePosition) -> Texture &
 Create a complex Texture that is a uniform rectangle, and set its relative position.
 
auto File (const std::filesystem::path &filePath) -> Texture &
 Import a complex Texture from file.
 
auto File (const std::filesystem::path &filePath, Point relativePosition) -> Texture &
 Import a complex Texture from file, and set its relative position.
 
auto Write (const std::vector< std::string > &stringVector, RGBA foreground, RGBA background) -> Texture &
 Write a complex Texture from a vector of strings.
 
auto Write (const std::vector< std::string > &stringVector, RGBA foreground, RGBA background, Point relativePosition) -> Texture &
 Write a complex Texture from a vector of strings, and set its relative position.
 
auto Null () -> Texture &
 Create a complex Texture that represents a missing Texture.
 
auto Null (Point relativePosition) -> Texture &
 Create a complex Texture that represents a missing Texture, and set its relative position.
 
auto operator() (size_t x, size_t y) -> CellA &
 Get a value from the 2D bitmap by-reference (complex Textures only).
 
auto operator() (size_t x, size_t y) const -> const CellA &
 Get a value from the 2D bitmap by-reference (complex Textures only).
 
auto Resize (UPoint size, CellA newValue=CellA(' ', RGBA(0, 0, 0, 0), RGBA(0, 0, 0, 0))) -> Texture &
 Resize the Texture (whether simple or complex).
 
auto Transform (const std::function< void(CellA &)> &operation, UPoint from=UPoint(0, 0), UPoint to=UPoint(0, 0)) -> Texture &
 Transform the Texture using a operation callback function (whether simple or complex).
 
void ExportToFile (const std::filesystem::path &filePath) const
 Export Texture to a file (complex Textures only).
 
void Print () const
 Print the Texture to the terminal (complex Textures only).
 

Public Attributes

bool m_active = true
 Activation status: true means enabled. false means disabled, and will be skipped in rendering.
 
bool m_simple
 true means simple, false means complex.
 
CellA m_value
 Uniform value (applies only to simple Textures).
 
Point m_rPos
 Position relative to the parent Object or Widget.
 
UPoint m_size
 Rectangle size (used in both simple and complex Textures).
 
std::vector< CellAm_t
 1D vector of the 2D bitmap (used only in complex Textures).
 

Detailed Description

A CellA-based sprite.

Objects and Widgets have a vector of these Textures (Object::m_textures and Widget::m_textures, respectively), which represents their visual appearance. Textures are used to render Objects and Widgets in Camera::Render() and UI::Render(), respectively.

Similarly to Collider, there are 2 forms of Textures: "simple" and "complex".

  • Simple Textures are just efficient uniform rectangles, which take the least amount of processing and memory. So, you should prefer using simple Textures.
  • Complex Textures are 2D bitmaps of CellAs which allow them to hold a detailed shape (in contrary to a uniform rectangle). This makes them the least efficient in terms of processing and memory. So, minimize your use of complex Textures to when you need such detailed shapes.

Texture has various functions to design itself. These functions can be "chained", because they all return a self-reference. Also note that some of these functions have an override that accepts a new a relative position to set. Usually you will first call one of the overrides that sets a relative position, and then continue using the ones that don't to further design the Texture.

Member Function Documentation

◆ ExportToFile()

void KTech::Texture::ExportToFile ( const std::filesystem::path & filePath) const

Export Texture to a file (complex Textures only).

Parameters
filePathPath to output the texture file (.ktecht).

◆ File() [1/2]

auto KTech::Texture::File ( const std::filesystem::path & filePath) -> Texture&

Import a complex Texture from file.

Such files can be created with TextureCreator, or with Texture::Export().

Parameters
filePathPath to the texture file (.ktecht).
See also
TextureCreator
Texture::Export()
Returns
Self-reference for function chaining.

◆ File() [2/2]

auto KTech::Texture::File ( const std::filesystem::path & filePath,
Point relativePosition ) -> Texture&

Import a complex Texture from file, and set its relative position.

Parameters
relativePositionRelative position to set.
filePathPath to the texture file (.ktecht).
Returns
Self-reference for function chaining.
See also
KTech::Texture::File(const std::filesystem::path& filePath)

◆ Null() [1/2]

auto KTech::Texture::Null ( ) -> Texture&

Create a complex Texture that represents a missing Texture.

Used by Texture::File() if it failed to open or read the given file.

Returns
Self-reference for function chaining.

◆ Null() [2/2]

auto KTech::Texture::Null ( Point relativePosition) -> Texture&

Create a complex Texture that represents a missing Texture, and set its relative position.

Parameters
relativePositionRelative position to set.
Returns
Self-reference for function chaining.
See also
Texture::Null()

◆ operator()() [1/2]

auto KTech::Texture::operator() ( size_t x,
size_t y ) -> CellA&

Get a value from the 2D bitmap by-reference (complex Textures only).

Useful if you don't want to convert the 2D position into the corresponding index on the bitmap vector (Texture::m_t).

Parameters
xX axis.
yY axis.
Returns
The value of the 2D bitmap at the given location, by-reference.

◆ operator()() [2/2]

auto KTech::Texture::operator() ( size_t x,
size_t y ) const -> const CellA&

Get a value from the 2D bitmap by-reference (complex Textures only).

Useful if you don't want to convert the 2D position into the corresponding index on the bitmap vector (Texture::m_t).

Parameters
xX axis.
yY axis.
Returns
The value of the 2D bitmap at the given location, by-const-reference.

◆ Print()

void KTech::Texture::Print ( ) const

Print the Texture to the terminal (complex Textures only).

Can be useful in debugging.

◆ Rectangle() [1/2]

auto KTech::Texture::Rectangle ( UPoint size,
CellA value ) -> Texture&

Create a complex Texture that is a uniform rectangle.

Even though a simple Texture (created using Texture::Simple()) is capable of the same result at first glance, you can use this function to create a base for further modifications.

Parameters
sizeRectangle's size.
valueRectangle's uniform CellA value.
Returns
Self-reference for function chaining.

◆ Rectangle() [2/2]

auto KTech::Texture::Rectangle ( UPoint size,
CellA value,
Point relativePosition ) -> Texture&

Create a complex Texture that is a uniform rectangle, and set its relative position.

Parameters
relativePositionRelative position to set.
sizeRectangle's size.
valueRectangle's uniform CellA value.
Returns
Self-reference for function chaining.
See also
KTech::Texture::Rectangle(UPoint size, CellA value)

◆ Resize()

auto KTech::Texture::Resize ( UPoint size,
CellA newValue = CellA(' ', RGBA(0, 0, 0, 0), RGBA(0, 0, 0, 0)) ) -> Texture&

Resize the Texture (whether simple or complex).

Parameters
sizeThe new size.
newValueValue for new cells. Does not affect simple Textures.
Returns
Self-reference for function chaining.

◆ Simple() [1/2]

auto KTech::Texture::Simple ( UPoint size,
CellA value ) -> Texture&

Create a simple Texture (uniform rectangle).

Parameters
sizeRectangle's size.
valueRectangle's CellA value.
Returns
Self-reference for function chaining.

◆ Simple() [2/2]

auto KTech::Texture::Simple ( UPoint size,
CellA value,
Point relativePosition ) -> Texture&

Create a simple Texture (uniform rectangle), and set its relative position.

Parameters
relativePositionRelative position to set.
sizeRectangle's size.
valueRectangle's CellA value.
Returns
Self-reference for function chaining.

◆ Transform()

auto KTech::Texture::Transform ( const std::function< void(CellA &)> & operation,
UPoint from = UPoint(0, 0),
UPoint to = UPoint(0, 0) ) -> Texture&

Transform the Texture using a operation callback function (whether simple or complex).

Parameters
[in]operationCallback function that receives a CellA (old value) and returns a CellA (new value).
[in]fromTop-left corner of area to transform. Default: (0, 0).
[in]toBottom-right corner of area to transform. Default: size of Texture.

Example that reverses the background colors of a Texture:

Example missing!
Returns
Self-reference for function chaining.

◆ Write() [1/2]

auto KTech::Texture::Write ( const std::vector< std::string > & stringVector,
RGBA foreground,
RGBA background ) -> Texture&

Write a complex Texture from a vector of strings.

Creates a complex Texture with different characters but uniform foreground and background colors. For example:

m_textures[0].Write(
{
" O ",
"/|\\",
"/ \\"
}, RGBA( 255, 255, 0, 255 ), RGBAColors::transparent, Point(0, 0)
);
2D vector, mostly used to store positions and directions.
Definition point.hpp:30
Like RGB, but also has an alpha channel representing transparency.
Definition rgba.hpp:30
Parameters
stringVectorVector of strings that will be converted into the Texture's characters.
foregroundUniform foreground (character) color.
backgroundUniform background color.
Returns
Self-reference for function chaining.

◆ Write() [2/2]

auto KTech::Texture::Write ( const std::vector< std::string > & stringVector,
RGBA foreground,
RGBA background,
Point relativePosition ) -> Texture&

Write a complex Texture from a vector of strings, and set its relative position.

Parameters
relativePositionRelative position to set.
stringVectorVector of strings that will be converted into the Texture's characters.
foregroundUniform foreground (character) color.
backgroundUniform background color.
Returns
Self-reference for function chaining.

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