font: small improvements
parent
87d1439207
commit
64994fe27a
|
@ -127,7 +127,7 @@ int main() {
|
||||||
{
|
{
|
||||||
vec2 pos = vec2(1490,820);
|
vec2 pos = vec2(1490,820);
|
||||||
ddraw_push_2d();
|
ddraw_push_2d();
|
||||||
char *txt = FONT_JUSTIFY FONT_MIDDLE "This is the first line.\nAnd now the second line.\nYou can do a third great line, too!\n";
|
char *txt = FONT_JUSTIFY FONT_MIDDLE "This is the first line.\nAnd now the second line.\nYou can do a third great line, too!\nNow this is a very long line aaaaaaaaaa!\n";
|
||||||
font_goto(pos.x, pos.y);
|
font_goto(pos.x, pos.y);
|
||||||
vec2 size=font_rect(txt);
|
vec2 size=font_rect(txt);
|
||||||
font_metrics_t m=font_metrics(txt);
|
font_metrics_t m=font_metrics(txt);
|
||||||
|
@ -139,7 +139,7 @@ int main() {
|
||||||
{
|
{
|
||||||
vec2 pos = vec2(1990,820);
|
vec2 pos = vec2(1990,820);
|
||||||
ddraw_push_2d();
|
ddraw_push_2d();
|
||||||
char *txt = FONT_RIGHT FONT_BOTTOM "This is the first line.\nAnd now the second line.\nYou can do a third great line, too!\n";
|
char *txt = FONT_RIGHT FONT_BOTTOM "This is the first line.\nAnd now the second line.\n \nYou can do a third great line, too!\n";
|
||||||
font_goto(pos.x, pos.y);
|
font_goto(pos.x, pos.y);
|
||||||
vec2 size=font_rect(txt);
|
vec2 size=font_rect(txt);
|
||||||
font_metrics_t m=font_metrics(txt);
|
font_metrics_t m=font_metrics(txt);
|
||||||
|
|
|
@ -363956,11 +363956,8 @@ vec2 font_print_rect(const char *text, vec4 rect) {
|
||||||
|
|
||||||
if (num_newlines > 1) {
|
if (num_newlines > 1) {
|
||||||
vec2 text_dims = font_rect(text);
|
vec2 text_dims = font_rect(text);
|
||||||
array(char *) lines = strsplit(text, "\n");
|
|
||||||
char tags[4] = {0};
|
char tags[4] = {0};
|
||||||
for (int i = 0, t = 0, end = strlen(text); i < end; ++i) {
|
for (int i = 0, t = 0, end = strlen(text); i < end; ++i) {
|
||||||
if (t == 4) break;
|
|
||||||
|
|
||||||
char ch = text[i];
|
char ch = text[i];
|
||||||
|
|
||||||
if( (ch >= 1 && ch <= 6) ||
|
if( (ch >= 1 && ch <= 6) ||
|
||||||
|
@ -363969,7 +363966,10 @@ vec2 font_print_rect(const char *text, vec4 rect) {
|
||||||
tags[t++] = ch;
|
tags[t++] = ch;
|
||||||
++text;
|
++text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (t == 3) break;
|
||||||
}
|
}
|
||||||
|
array(char *) lines = strsplit(text, "\n");
|
||||||
if (b) {
|
if (b) {
|
||||||
gotoxy.y += (rect.w - text_dims.y);
|
gotoxy.y += (rect.w - text_dims.y);
|
||||||
}
|
}
|
||||||
|
@ -363988,13 +363988,8 @@ vec2 font_print_rect(const char *text, vec4 rect) {
|
||||||
float words_space = 0.0f;
|
float words_space = 0.0f;
|
||||||
array(char *) words = strsplit(lines[i], " ");
|
array(char *) words = strsplit(lines[i], " ");
|
||||||
for (int k = 0; k < array_count(words); ++k) {
|
for (int k = 0; k < array_count(words); ++k) {
|
||||||
if (!strlen(words[k])) {
|
|
||||||
array_erase_slow(words, k);
|
|
||||||
--k;
|
|
||||||
} else {
|
|
||||||
words_space += font_rect(words[k]).x;
|
words_space += font_rect(words[k]).x;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (array_count(words) == 0) {
|
if (array_count(words) == 0) {
|
||||||
gotoxy.y += text_rect.y;
|
gotoxy.y += text_rect.y;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -2398,11 +2398,8 @@ vec2 font_print_rect(const char *text, vec4 rect) {
|
||||||
|
|
||||||
if (num_newlines > 1) {
|
if (num_newlines > 1) {
|
||||||
vec2 text_dims = font_rect(text);
|
vec2 text_dims = font_rect(text);
|
||||||
array(char *) lines = strsplit(text, "\n");
|
|
||||||
char tags[4] = {0};
|
char tags[4] = {0};
|
||||||
for (int i = 0, t = 0, end = strlen(text); i < end; ++i) {
|
for (int i = 0, t = 0, end = strlen(text); i < end; ++i) {
|
||||||
if (t == 4) break;
|
|
||||||
|
|
||||||
char ch = text[i];
|
char ch = text[i];
|
||||||
|
|
||||||
if( (ch >= 1 && ch <= 6) ||
|
if( (ch >= 1 && ch <= 6) ||
|
||||||
|
@ -2411,7 +2408,10 @@ vec2 font_print_rect(const char *text, vec4 rect) {
|
||||||
tags[t++] = ch;
|
tags[t++] = ch;
|
||||||
++text;
|
++text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (t == 3) break;
|
||||||
}
|
}
|
||||||
|
array(char *) lines = strsplit(text, "\n");
|
||||||
if (b) {
|
if (b) {
|
||||||
gotoxy.y += (rect.w - text_dims.y);
|
gotoxy.y += (rect.w - text_dims.y);
|
||||||
}
|
}
|
||||||
|
@ -2430,13 +2430,8 @@ vec2 font_print_rect(const char *text, vec4 rect) {
|
||||||
float words_space = 0.0f;
|
float words_space = 0.0f;
|
||||||
array(char *) words = strsplit(lines[i], " ");
|
array(char *) words = strsplit(lines[i], " ");
|
||||||
for (int k = 0; k < array_count(words); ++k) {
|
for (int k = 0; k < array_count(words); ++k) {
|
||||||
if (!strlen(words[k])) {
|
|
||||||
array_erase_slow(words, k);
|
|
||||||
--k;
|
|
||||||
} else {
|
|
||||||
words_space += font_rect(words[k]).x;
|
words_space += font_rect(words[k]).x;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (array_count(words) == 0) {
|
if (array_count(words) == 0) {
|
||||||
gotoxy.y += text_rect.y;
|
gotoxy.y += text_rect.y;
|
||||||
continue;
|
continue;
|
||||||
|
|
11
engine/v4k.c
11
engine/v4k.c
|
@ -11096,11 +11096,8 @@ vec2 font_print_rect(const char *text, vec4 rect) {
|
||||||
|
|
||||||
if (num_newlines > 1) {
|
if (num_newlines > 1) {
|
||||||
vec2 text_dims = font_rect(text);
|
vec2 text_dims = font_rect(text);
|
||||||
array(char *) lines = strsplit(text, "\n");
|
|
||||||
char tags[4] = {0};
|
char tags[4] = {0};
|
||||||
for (int i = 0, t = 0, end = strlen(text); i < end; ++i) {
|
for (int i = 0, t = 0, end = strlen(text); i < end; ++i) {
|
||||||
if (t == 4) break;
|
|
||||||
|
|
||||||
char ch = text[i];
|
char ch = text[i];
|
||||||
|
|
||||||
if( (ch >= 1 && ch <= 6) ||
|
if( (ch >= 1 && ch <= 6) ||
|
||||||
|
@ -11109,7 +11106,10 @@ vec2 font_print_rect(const char *text, vec4 rect) {
|
||||||
tags[t++] = ch;
|
tags[t++] = ch;
|
||||||
++text;
|
++text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (t == 3) break;
|
||||||
}
|
}
|
||||||
|
array(char *) lines = strsplit(text, "\n");
|
||||||
if (b) {
|
if (b) {
|
||||||
gotoxy.y += (rect.w - text_dims.y);
|
gotoxy.y += (rect.w - text_dims.y);
|
||||||
}
|
}
|
||||||
|
@ -11128,13 +11128,8 @@ vec2 font_print_rect(const char *text, vec4 rect) {
|
||||||
float words_space = 0.0f;
|
float words_space = 0.0f;
|
||||||
array(char *) words = strsplit(lines[i], " ");
|
array(char *) words = strsplit(lines[i], " ");
|
||||||
for (int k = 0; k < array_count(words); ++k) {
|
for (int k = 0; k < array_count(words); ++k) {
|
||||||
if (!strlen(words[k])) {
|
|
||||||
array_erase_slow(words, k);
|
|
||||||
--k;
|
|
||||||
} else {
|
|
||||||
words_space += font_rect(words[k]).x;
|
words_space += font_rect(words[k]).x;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (array_count(words) == 0) {
|
if (array_count(words) == 0) {
|
||||||
gotoxy.y += text_rect.y;
|
gotoxy.y += text_rect.y;
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue