KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
aboutbox.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#include "../ktech.hpp"
24
28class AboutBox : public KTech::Widget
29{
30public:
43 KTech::Point position,
44 const std::vector<std::string>& text,
45 KTech::RGBA foreground = KTech::RGBAColors::black,
46 KTech::RGBA background = KTech::RGBAColors::gray)
47 : Widget(engine, ui, position), m_foregroundRGBA(foreground), m_backgroundRGBA(background)
48 {
49 // Texture
50 SetText(text);
51 }
52
58 void SetText(const std::vector<std::string>& text)
59 {
60 m_textures.resize(TEXTURES_SIZE);
61 m_textures[ti_text].Write(text, m_foregroundRGBA, m_backgroundRGBA, KTech::Point(1, 1))
62 .Transform([](KTech::CellA& cell){ if (cell.c == ' ') cell.c = '\0'; })
63 .Transform([&](KTech::CellA& cell){ cell.b = m_backgroundRGBA; });
64 m_textures[ti_topLeftCorner].Simple(KTech::UPoint(1, 1), KTech::CellA('#', m_foregroundRGBA, m_backgroundRGBA), KTech::Point(0, 0));
65 m_textures[ti_topRightCorner].Simple(KTech::UPoint(1, 1), KTech::CellA('#', m_foregroundRGBA, m_backgroundRGBA), KTech::Point(m_textures[0].m_size.x + 1, 0));
66 m_textures[ti_bottomLeftCorner].Simple(KTech::UPoint(1, 1), KTech::CellA('#', m_foregroundRGBA, m_backgroundRGBA), KTech::Point(0, m_textures[0].m_size.y + 1));
67 m_textures[ti_bottomRightCorner].Simple(KTech::UPoint(1, 1), KTech::CellA('#', m_foregroundRGBA, m_backgroundRGBA), KTech::Point(m_textures[0].m_size.x + 1, m_textures[0].m_size.y + 1));
68 m_textures[ti_topFrame].Simple(KTech::UPoint(m_textures[0].m_size.x, 1), KTech::CellA('-', m_foregroundRGBA, m_backgroundRGBA), KTech::Point(1, 0));
69 m_textures[ti_leftFrame].Simple(KTech::UPoint(1, m_textures[0].m_size.y), KTech::CellA('|', m_foregroundRGBA, m_backgroundRGBA), KTech::Point(0, 1));
70 m_textures[ti_bottomFrame].Simple(KTech::UPoint(m_textures[0].m_size.x, 1), KTech::CellA('-', m_foregroundRGBA, m_backgroundRGBA), KTech::Point(1, m_textures[0].m_size.y + 1));
71 m_textures[ti_rightFrame].Simple(KTech::UPoint(1, m_textures[0].m_size.y), KTech::CellA('|', m_foregroundRGBA, m_backgroundRGBA), KTech::Point(m_textures[0].m_size.x + 1, 1));
72 }
73
74private:
75 enum TextureIndex : size_t
76 {
77 ti_text,
78 ti_topLeftCorner,
79 ti_topRightCorner,
80 ti_bottomLeftCorner,
81 ti_bottomRightCorner,
82 ti_topFrame,
83 ti_leftFrame,
84 ti_bottomFrame,
85 ti_rightFrame,
86 TEXTURES_SIZE
87 };
88
89 KTech::RGBA m_foregroundRGBA, m_backgroundRGBA;
90};
Widget that displays framed text.
Definition aboutbox.hpp:29
AboutBox(KTech::Engine &engine, KTech::ID< KTech::UI > ui, KTech::Point position, const std::vector< std::string > &text, KTech::RGBA foreground=KTech::RGBAColors::black, KTech::RGBA background=KTech::RGBAColors::gray)
Construct an AboutBox.
Definition aboutbox.hpp:41
void SetText(const std::vector< std::string > &text)
Change the displayed text.
Definition aboutbox.hpp:58
Complete engine containing all engine components.
Definition engine.hpp:41
World structure that comprises Textures, behaves as a user interface element, and exists within UI.
Definition widget.hpp:45
Engine & engine
Parent Engine.
Definition widget.hpp:57
std::vector< Texture > m_textures
Comprising Textures.
Definition widget.hpp:67
Widget(Engine &engine, Point position=Point(0, 0), std::string name="")
Construct a Widget.
Definition widget.cpp:34
Like Cell, but with RGBA foreground and background colors, instead of RGB.
Definition cella.hpp:32
RGBA b
Background color.
Definition cella.hpp:34
char c
ASCII character.
Definition cella.hpp:35
Serializable world structure identifier.
Definition id.hpp:38
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
Unsigned 2D vector, mostly used to store sizes and 2D indexes.
Definition upoint.hpp:29