add syntax highlighting (WIP)

This commit is contained in:
MihailRis
2024-12-04 22:13:17 +03:00
parent ce1e9f76cf
commit ed3865964b
16 changed files with 168 additions and 43 deletions
+18 -19
View File
@@ -62,7 +62,7 @@ static inline void draw_glyph(
pos.y + offset.y * right.y,
right.x / glyphInterval,
up.y,
-0.2f * style.italic,
-0.15f * style.italic,
16,
c,
batch.getColor() * style.color
@@ -102,11 +102,11 @@ static inline void draw_text(
const glm::vec3& right,
const glm::vec3& up,
float glyphInterval,
const FontStylesScheme* styles
const FontStylesScheme* styles,
size_t styleMapOffset
) {
static FontStylesScheme defStyles {
{{std::numeric_limits<size_t>::max()}},
};
static FontStylesScheme defStyles {{{}}, {0}};
if (styles == nullptr) {
styles = &defStyles;
}
@@ -117,17 +117,12 @@ static inline void draw_text(
int y = 0;
do {
size_t entryIndex = 0;
int styleCharsCounter = -1;
const FontStyle* style = &styles->palette.at(entryIndex);
for (uint c : text) {
styleCharsCounter++;
if (styleCharsCounter > style->n &&
entryIndex + 1 < styles->palette.size()) {
style = &styles->palette.at(++entryIndex);
styleCharsCounter = -1;
}
for (size_t i = 0; i < text.length(); i++) {
uint c = text[i];
size_t styleIndex = styles->map.at(
std::min(styles->map.size() - 1, i + styleMapOffset)
);
const FontStyle& style = styles->palette.at(styleIndex);
if (!font.isPrintableChar(c)) {
x++;
continue;
@@ -143,7 +138,7 @@ static inline void draw_text(
right,
up,
glyphInterval,
*style
style
);
}
else if (charpage > page && charpage < next){
@@ -174,6 +169,7 @@ void Font::draw(
int x,
int y,
const FontStylesScheme* styles,
size_t styleMapOffset,
float scale
) const {
draw_text(
@@ -182,7 +178,8 @@ void Font::draw(
glm::vec3(glyphInterval*scale, 0, 0),
glm::vec3(0, lineHeight*scale, 0),
glyphInterval/static_cast<float>(lineHeight),
styles
styles,
styleMapOffset
);
}
@@ -190,6 +187,7 @@ void Font::draw(
Batch3D& batch,
std::wstring_view text,
const FontStylesScheme* styles,
size_t styleMapOffset,
const glm::vec3& pos,
const glm::vec3& right,
const glm::vec3& up
@@ -199,6 +197,7 @@ void Font::draw(
right * static_cast<float>(glyphInterval),
up * static_cast<float>(lineHeight),
glyphInterval/static_cast<float>(lineHeight),
styles
styles,
styleMapOffset
);
}