coastline 0.0.4
Loading...
Searching...
No Matches
menutext.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <array>
9#include <filesystem>
10#include <memory>
11#include <optional>
12#include <span>
13#include <string_view>
14#include <unordered_map>
15#include <vector>
16
17#include "scenerenderer.h"
18
19namespace coastline {
20
49
60int CenterLines(std::string_view text, int y, int lines, int lineHeight);
61
63class MenuText {
64public:
73 const std::filesystem::path &fonts);
77 MenuText(const MenuText &) = delete;
79 MenuText &operator=(const MenuText &) = delete;
80
93 void Draw(SceneRenderer &renderer,
95 int x,
96 int y,
97 const TextStyle &style,
98 const Matrix4 &projection) const;
99
108 int Width(std::string_view text, int size, bool doubled = true) const;
109
110private:
112 struct Font {
115 std::unique_ptr<RenderTexture> shadowGradient;
116 int cell = 0;
117 int padding = 0;
118 std::vector<int> glyphStarts;
119 };
121 struct JapaneseFont {
123 int width = 0;
124 int columns = 0;
126 };
127 MenuText() = default;
128 const Font &FontFor(int size) const;
129
130 Font m_large;
131 Font m_small;
133 int m_firstRowGlyphs = 0;
135};
136
137} // namespace coastline
static std::unique_ptr< MenuText > Load(SceneRenderer &renderer, const std::filesystem::path &fonts)
Read the fonts of a release.
MenuText & operator=(const MenuText &)=delete
Prevent assignment of GPU-backed font resources.
int Width(std::string_view text, int size, bool doubled=true) const
MenuText(const MenuText &)=delete
Prevent copying GPU-backed font resources.
void Draw(SceneRenderer &renderer, std::string_view text, int x, int y, const TextStyle &style, const Matrix4 &projection) const
Draw a string as DrawText() of the console draws it on a frame of high resolution.
~MenuText()
Release font textures before the renderer's GPU device is destroyed.
The renderer of a frame.
Definition scenerenderer.h:467
Definition assetimport.h:11
std::array< float, 16 > Matrix4
A 4 by 4 matrix, column by column.
Definition scenerenderer.h:28
int CenterLines(std::string_view text, int y, int lines, int lineHeight)
Centre a string on the place of a block of a number of lines, as a release that draws a message in fe...
The renderer of the converted models and of flat pictures and text, on the GPU of SDL.
How a string of the menus is drawn.
Definition menutext.h:22
int lineHeight
The distance between the baselines of two lines of a string with a newline, in the units of size,...
Definition menutext.h:40
int size
Definition menutext.h:30
Align align
Definition menutext.h:31
Align
Where a string stands from its x.
Definition menutext.h:24
@ Center
Definition menutext.h:26
@ Right
Definition menutext.h:27
@ Left
Definition menutext.h:25
std::span< const int > lineGaps
The distance from the baseline of each line to the next, in place of lineHeight, for a string of one ...
Definition menutext.h:44
bool doubled
Whether the place and the size are of the 320 by 240 screen a frame of high resolution doubles,...
Definition menutext.h:37
bool bold
Definition menutext.h:33
bool shadow
Definition menutext.h:32
std::optional< std::array< int, 6 > > colors
The red, green, and blue of the bottom and then of the top of the gradient, if not default.
Definition menutext.h:47