diff --git a/doc/en/text-styles.md b/doc/en/text-styles.md index e85437e1..4afce42a 100644 --- a/doc/en/text-styles.md +++ b/doc/en/text-styles.md @@ -19,3 +19,34 @@ Styles can be combined. Example: Output: ***Message*** using *~~combed~~ combined* styles~~.~~ + +# Colors + +Text color can be set using a color code: [#RRGGBB] + + +| Component | Purpose | +| --------- | --------------------------------- | +| R | Represents the intensity of red | +| G | Represents the intensity of green | +| B | Represents the intensity of blue | + +### Example: + + + + [#ff0000] + Red Text + + + + + [#00ff00] + Green Text + + + + + [#0000ff] + Blue Text + diff --git a/doc/ru/text-styles.md b/doc/ru/text-styles.md index 0a09abe3..4fbe3ed5 100644 --- a/doc/ru/text-styles.md +++ b/doc/ru/text-styles.md @@ -19,3 +19,33 @@ Вывод: ***Сообщение***, демонстрирующее *~~обедненные~~ объединенные* стили~~.~~ + +## Цвета + +Цвет текста задается при помощи цветового кода: [#RRGGBB] + +| Компонент | Назначение | +| ------------ | ------------------------- | +| R | Используется для интенсивности красного | +| G | Используется для интенсивности зеленого | +| B | Используется для интенсивности синего | + +### Например: + + + + [#ff0000] + Красный Текст + + + + + [#00ff00] + Зеленый Текст + + + + + [#0000ff] + Синий Текст + \ No newline at end of file diff --git a/src/graphics/ui/markdown.cpp b/src/graphics/ui/markdown.cpp index 8a1b13bf..bbbc298a 100644 --- a/src/graphics/ui/markdown.cpp +++ b/src/graphics/ui/markdown.cpp @@ -1,15 +1,9 @@ #include "markdown.hpp" +#include "coders/commons.hpp" #include "graphics/core/Font.hpp" using namespace markdown; -static inline int hexchar2int(char c) { - if (c >= '0' && c <= '9') return c - '0'; - if (c >= 'a' && c <= 'f') return c - 'a' + 10; - if (c >= 'A' && c <= 'F') return c - 'A' + 10; - return -1; -} - template static inline void emit( CharT c, FontStylesScheme& styles, std::basic_stringstream& ss @@ -28,7 +22,7 @@ static inline void emit_md( template static glm::vec4 parse_color(const std::basic_string_view& color_code) { - if (color_code.size() != 9 || color_code[0] != '#') { + if (color_code.size() != 8 || color_code[0] != '#') { return glm::vec4(1, 1, 1, 1); // default to white } @@ -45,7 +39,7 @@ static glm::vec4 parse_color(const std::basic_string_view& color_code) { hex_to_float(color_code[1], color_code[2]), hex_to_float(color_code[3], color_code[4]), hex_to_float(color_code[5], color_code[6]), - hex_to_float(color_code[7], color_code[8]) + 1 ); } @@ -87,15 +81,15 @@ Result process_markdown( while (pos < source.size()) { CharT first = source[pos]; - if (first == '[' && pos + 10 < source.size() && source[pos + 1] == '#' && source[pos + 9] == ']') { - std::basic_string_view color_code = source.substr(pos + 1, 9); + if (first == '[' && pos + 9 < source.size() && source[pos + 1] == '#' && source[pos + 8] == ']') { + std::basic_string_view color_code = source.substr(pos + 1, 8); apply_color(color_code, styles); if (!eraseMarkdown) { - for (int i = 0; i < 10; ++i) { + for (int i = 0; i < 9; ++i) { emit_md(source[pos + i], styles, ss); } } - pos += 10; // Skip past the color code + pos += 9; // Skip past the color code continue; }