2024-02-25 14:46:47 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-07-22 12:31:04 +00:00
|
|
|
#include "StarString.hpp"
|
|
|
|
#include "StarStringView.hpp"
|
2024-04-21 20:07:59 +00:00
|
|
|
#include "StarVector.hpp"
|
|
|
|
#include "StarDirectives.hpp"
|
|
|
|
#include "StarJson.hpp"
|
2023-07-22 12:31:04 +00:00
|
|
|
|
|
|
|
namespace Star {
|
2024-04-21 20:07:59 +00:00
|
|
|
|
|
|
|
unsigned const DefaultFontSize = 8;
|
|
|
|
float const DefaultLineSpacing = 1.3f;
|
|
|
|
|
|
|
|
struct TextStyle {
|
|
|
|
float lineSpacing = DefaultLineSpacing;
|
|
|
|
Vec4B color = Vec4B::filled(255);
|
|
|
|
Vec4B shadow = Vec4B::filled(0);
|
|
|
|
unsigned fontSize = DefaultFontSize;
|
|
|
|
String font = "";
|
|
|
|
Directives directives;
|
|
|
|
Directives backDirectives;
|
|
|
|
|
|
|
|
TextStyle() = default;
|
|
|
|
TextStyle(Json const& config);
|
|
|
|
TextStyle& loadJson(Json const& config);
|
|
|
|
};
|
|
|
|
|
2023-07-22 12:31:04 +00:00
|
|
|
namespace Text {
|
|
|
|
unsigned char const StartEsc = '\x1b';
|
|
|
|
unsigned char const EndEsc = ';';
|
|
|
|
unsigned char const CmdEsc = '^';
|
|
|
|
unsigned char const SpecialCharLimit = ' ';
|
2024-04-23 03:27:57 +00:00
|
|
|
extern std::string const AllEsc;
|
|
|
|
extern std::string const AllEscEnd;
|
2023-07-22 12:31:04 +00:00
|
|
|
|
|
|
|
String stripEscapeCodes(String const& s);
|
2023-10-27 01:24:22 +00:00
|
|
|
inline bool isEscapeCode(Utf32Type c) { return c == CmdEsc || c == StartEsc; }
|
2023-07-22 12:31:04 +00:00
|
|
|
|
|
|
|
typedef function<bool(StringView text)> TextCallback;
|
|
|
|
typedef function<bool(StringView commands)> CommandsCallback;
|
|
|
|
bool processText(StringView text, TextCallback textFunc, CommandsCallback commandsFunc = CommandsCallback(), bool includeCommandSides = false);
|
|
|
|
String preprocessEscapeCodes(String const& s);
|
|
|
|
String extractCodes(String const& s);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|