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,12 +363988,7 @@ 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])) {
|
words_space += font_rect(words[k]).x;
|
||||||
array_erase_slow(words, k);
|
|
||||||
--k;
|
|
||||||
} else {
|
|
||||||
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;
|
||||||
|
@ -364013,7 +364008,7 @@ vec2 font_print_rect(const char *text, vec4 rect) {
|
||||||
font_draw_ex(line, gotoxy, NULL, font_draw_cmd);
|
font_draw_ex(line, gotoxy, NULL, font_draw_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
gotoxy.y += text_rect.y;
|
gotoxy.y += text_rect.y;
|
||||||
}
|
}
|
||||||
return text_dims;
|
return text_dims;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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,12 +2430,7 @@ 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])) {
|
words_space += font_rect(words[k]).x;
|
||||||
array_erase_slow(words, k);
|
|
||||||
--k;
|
|
||||||
} else {
|
|
||||||
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;
|
||||||
|
@ -2455,7 +2450,7 @@ vec2 font_print_rect(const char *text, vec4 rect) {
|
||||||
font_draw_ex(line, gotoxy, NULL, font_draw_cmd);
|
font_draw_ex(line, gotoxy, NULL, font_draw_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
gotoxy.y += text_rect.y;
|
gotoxy.y += text_rect.y;
|
||||||
}
|
}
|
||||||
return text_dims;
|
return text_dims;
|
||||||
} else {
|
} else {
|
||||||
|
|
15
engine/v4k.c
15
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,12 +11128,7 @@ 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])) {
|
words_space += font_rect(words[k]).x;
|
||||||
array_erase_slow(words, k);
|
|
||||||
--k;
|
|
||||||
} else {
|
|
||||||
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;
|
||||||
|
@ -11153,7 +11148,7 @@ vec2 font_print_rect(const char *text, vec4 rect) {
|
||||||
font_draw_ex(line, gotoxy, NULL, font_draw_cmd);
|
font_draw_ex(line, gotoxy, NULL, font_draw_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
gotoxy.y += text_rect.y;
|
gotoxy.y += text_rect.y;
|
||||||
}
|
}
|
||||||
return text_dims;
|
return text_dims;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue