![]() |
KTech 1.1.0
C++ 2D terminal game engine library
|
#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< CellA > | m_t |
1D vector of the 2D bitmap (used only in complex Textures). | |
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".
Textures are just efficient uniform rectangles, which take the least amount of processing and memory. So, you should prefer using simple Textures.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.
| void KTech::Texture::ExportToFile | ( | const std::filesystem::path & | filePath | ) | const |
| 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().
| filePath | Path to the texture file (.ktecht). |
Texture::Export() | auto KTech::Texture::File | ( | const std::filesystem::path & | filePath, |
| Point | relativePosition ) -> Texture& |
Import a complex Texture from file, and set its relative position.
| relativePosition | Relative position to set. |
| filePath | Path to the texture file (.ktecht). |
KTech::Texture::File(const std::filesystem::path& filePath) | 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.
Create a complex Texture that represents a missing Texture, and set its relative position.
| relativePosition | Relative position to set. |
Texture::Null() | 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).
| x | X axis. |
| y | Y axis. |
| 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).
| x | X axis. |
| y | Y axis. |
| void KTech::Texture::Print | ( | ) | const |
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.
| size | Rectangle's size. |
| value | Rectangle's uniform CellA value. |
| 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).
| [in] | operation | Callback function that receives a CellA (old value) and returns a CellA (new value). |
| [in] | from | Top-left corner of area to transform. Default: (0, 0). |
| [in] | to | Bottom-right corner of area to transform. Default: size of Texture. |
Example that reverses the background colors of a Texture:
| 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:
| stringVector | Vector of strings that will be converted into the Texture's characters. |
| foreground | Uniform foreground (character) color. |
| background | Uniform background color. |
| 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.
| relativePosition | Relative position to set. |
| stringVector | Vector of strings that will be converted into the Texture's characters. |
| foreground | Uniform foreground (character) color. |
| background | Uniform background color. |