KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
texture.hpp
1/*
2 KTech, Kaup's C++ 2D terminal game engine library.
3 Copyright (C) 2023-2025 Ethan Kaufman (AKA Kaup)
4
5 This file is part of KTech.
6
7 KTech is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 any later version.
11
12 KTech is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with KTech. If not, see <https://www.gnu.org/licenses/>.
19*/
20
21#pragma once
22
23#define KTECH_DEFINITION
24#include "../ktech.hpp"
25#undef KTECH_DEFINITION
26#include "../basic/point.hpp"
27#include "../basic/upoint.hpp"
28#include "../basic/rgba.hpp"
29#include "../basic/cella.hpp"
30
31#include <filesystem>
32#include <functional>
33#include <string>
34#include <vector>
35
48{
49 bool m_active = true;
50
51 bool m_simple;
55 std::vector<CellA> m_t;
56
57 auto Simple(UPoint size, CellA value) -> Texture&;
58 auto Simple(UPoint size, CellA value, Point relativePosition) -> Texture&;
59 auto Rectangle(UPoint size, CellA value) -> Texture&;
60 auto Rectangle(UPoint size, CellA value, Point relativePosition) -> Texture&;
61 auto File(const std::filesystem::path& filePath) -> Texture&;
62 auto File(const std::filesystem::path& filePath, Point relativePosition) -> Texture&;
63 auto Write(const std::vector<std::string>& stringVector, RGBA foreground, RGBA background) -> Texture&;
64 auto Write(const std::vector<std::string>& stringVector, RGBA foreground, RGBA background, Point relativePosition) -> Texture&;
65 auto Null() -> Texture&;
66 auto Null(Point relativePosition) -> Texture&;
67
68 auto operator()(size_t x, size_t y) -> CellA&;
69 auto operator()(size_t x, size_t y) const -> const CellA&;
70
71 // `newValue` - only fills the new cells.
72 auto Resize(UPoint size, CellA newValue = CellA(' ', RGBA(0, 0, 0, 0), RGBA(0, 0, 0, 0))) -> Texture&;
73 auto Transform(const std::function<void(CellA&)>& operation, UPoint from = UPoint(0, 0), UPoint to = UPoint(0, 0)) -> Texture&;
74
75 void ExportToFile(const std::filesystem::path& filePath) const;
76 void Print() const;
77};
Like Cell, but with RGBA foreground and background colors, instead of RGB.
Definition cella.hpp:32
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
A CellA-based sprite.
Definition texture.hpp:48
Point m_rPos
Position relative to the parent Object or Widget.
Definition texture.hpp:53
void Print() const
Print the Texture to the terminal (complex Textures only).
Definition texture.cpp:406
auto Write(const std::vector< std::string > &stringVector, RGBA foreground, RGBA background) -> Texture &
Write a complex Texture from a vector of strings.
Definition texture.cpp:172
auto operator()(size_t x, size_t y) -> CellA &
Get a value from the 2D bitmap by-reference (complex Textures only).
Definition texture.cpp:268
UPoint m_size
Rectangle size (used in both simple and complex Textures).
Definition texture.hpp:54
auto Null() -> Texture &
Create a complex Texture that represents a missing Texture.
Definition texture.cpp:232
std::vector< CellA > m_t
1D vector of the 2D bitmap (used only in complex Textures).
Definition texture.hpp:55
CellA m_value
Uniform value (applies only to simple Textures).
Definition texture.hpp:52
void ExportToFile(const std::filesystem::path &filePath) const
Export Texture to a file (complex Textures only).
Definition texture.cpp:386
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).
Definition texture.cpp:341
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).
Definition texture.cpp:299
auto File(const std::filesystem::path &filePath) -> Texture &
Import a complex Texture from file.
Definition texture.cpp:111
bool m_simple
true means simple, false means complex.
Definition texture.hpp:51
bool m_active
Activation status: true means enabled. false means disabled, and will be skipped in rendering.
Definition texture.hpp:49
auto Simple(UPoint size, CellA value) -> Texture &
Create a simple Texture (uniform rectangle).
Definition texture.cpp:38
auto Rectangle(UPoint size, CellA value) -> Texture &
Create a complex Texture that is a uniform rectangle.
Definition texture.cpp:70
Unsigned 2D vector, mostly used to store sizes and 2D indexes.
Definition upoint.hpp:29