Clean up menus and text drawing

FossilOrigin-Name: f17992369e439fa68605017c6ffb0d11eece9d29a4cdb5768656bd874248d623
This commit is contained in:
Jonathan Schleifer 2025-03-06 00:34:42 +00:00
parent 623076a034
commit 0bd8f1920f
14 changed files with 331 additions and 225 deletions

View file

@ -100,90 +100,116 @@ short char_coords[96][4] = {
};
int
text_width(char *str)
text_width(OFString *string)
{
int x = 0;
for (int i = 0; str[i] != 0; i++) {
int c = str[i];
if (c == '\t') {
x = (x + PIXELTAB) / PIXELTAB * PIXELTAB;
continue;
};
if (c == '\f')
continue;
if (c == ' ') {
x += FONTH / 2;
continue;
};
c -= 33;
if (c < 0 || c >= 95)
continue;
int in_width = char_coords[c][2] - char_coords[c][0];
x += in_width + 1;
@autoreleasepool {
const char *str = string.UTF8String;
size_t len = string.UTF8StringLength;
int x = 0;
for (int i = 0; i < len; i++) {
int c = str[i];
if (c == '\t') {
x = (x + PIXELTAB) / PIXELTAB * PIXELTAB;
continue;
}
if (c == '\f')
continue;
if (c == ' ') {
x += FONTH / 2;
continue;
}
c -= 33;
if (c < 0 || c >= 95)
continue;
int in_width = char_coords[c][2] - char_coords[c][0];
x += in_width + 1;
}
return x;
}
return x;
}
void
draw_textf(char *fstr, int left, int top, int gl_num, ...)
draw_textf(OFConstantString *format, int left, int top, int gl_num, ...)
{
sprintf_sdlv(str, gl_num, fstr);
draw_text(str, left, top, gl_num);
};
@autoreleasepool {
va_list arguments;
va_start(arguments, gl_num);
OFString *str = [[OFString alloc] initWithFormat:format
arguments:arguments];
va_end(arguments);
draw_text(str, left, top, gl_num);
}
}
void
draw_text(char *str, int left, int top, int gl_num)
draw_text(OFString *string, int left, int top, int gl_num)
{
glBlendFunc(GL_ONE, GL_ONE);
glBindTexture(GL_TEXTURE_2D, gl_num);
glColor3ub(255, 255, 255);
@autoreleasepool {
glBlendFunc(GL_ONE, GL_ONE);
glBindTexture(GL_TEXTURE_2D, gl_num);
glColor3ub(255, 255, 255);
int x = left;
int y = top;
int x = left;
int y = top;
int i;
float in_left, in_top, in_right, in_bottom;
int in_width, in_height;
int i;
float in_left, in_top, in_right, in_bottom;
int in_width, in_height;
for (i = 0; str[i] != 0; i++) {
int c = str[i];
if (c == '\t') {
x = (x - left + PIXELTAB) / PIXELTAB * PIXELTAB + left;
continue;
};
if (c == '\f') {
glColor3ub(64, 255, 128);
continue;
};
if (c == ' ') {
x += FONTH / 2;
continue;
};
c -= 33;
if (c < 0 || c >= 95)
continue;
const char *str = string.UTF8String;
size_t len = string.UTF8StringLength;
for (i = 0; i < len; i++) {
int c = str[i];
in_left = ((float)char_coords[c][0]) / 512.0f;
in_top = ((float)char_coords[c][1] + 2) / 512.0f;
in_right = ((float)char_coords[c][2]) / 512.0f;
in_bottom = ((float)char_coords[c][3] - 2) / 512.0f;
if (c == '\t') {
x = (x - left + PIXELTAB) / PIXELTAB *
PIXELTAB +
left;
continue;
}
in_width = char_coords[c][2] - char_coords[c][0];
in_height = char_coords[c][3] - char_coords[c][1];
if (c == '\f') {
glColor3ub(64, 255, 128);
continue;
}
glBegin(GL_QUADS);
glTexCoord2f(in_left, in_top);
glVertex2i(x, y);
glTexCoord2f(in_right, in_top);
glVertex2i(x + in_width, y);
glTexCoord2f(in_right, in_bottom);
glVertex2i(x + in_width, y + in_height);
glTexCoord2f(in_left, in_bottom);
glVertex2i(x, y + in_height);
glEnd();
if (c == ' ') {
x += FONTH / 2;
continue;
}
xtraverts += 4;
x += in_width + 1;
c -= 33;
if (c < 0 || c >= 95)
continue;
in_left = ((float)char_coords[c][0]) / 512.0f;
in_top = ((float)char_coords[c][1] + 2) / 512.0f;
in_right = ((float)char_coords[c][2]) / 512.0f;
in_bottom = ((float)char_coords[c][3] - 2) / 512.0f;
in_width = char_coords[c][2] - char_coords[c][0];
in_height = char_coords[c][3] - char_coords[c][1];
glBegin(GL_QUADS);
glTexCoord2f(in_left, in_top);
glVertex2i(x, y);
glTexCoord2f(in_right, in_top);
glVertex2i(x + in_width, y);
glTexCoord2f(in_right, in_bottom);
glVertex2i(x + in_width, y + in_height);
glTexCoord2f(in_left, in_bottom);
glVertex2i(x, y + in_height);
glEnd();
xtraverts += 4;
x += in_width + 1;
}
}
}