fixing menus now where we have diffrent fonts with colors

origin
stpohle 23 years ago
parent d73b3af7ad
commit 1a144c9021

@ -1,4 +1,4 @@
/* $Id: menu.c,v 1.24 2003/06/06 23:22:03 stpohle Exp $ */
/* $Id: menu.c,v 1.25 2003/06/07 01:24:52 stpohle Exp $ */
/* menu's for the game */
#include <SDL.h>
@ -52,30 +52,36 @@ draw_menu (char *text, _menu menu[], int *x, int *y)
{
int last,
maxlen,
x1,
y1,
i;
char vers[20];
// count the number of entrys
for (last = 0, maxlen = 0; menu[last].index != -1; last++)
if (strlen (menu[last].text) > maxlen)
maxlen = strlen (menu[last].text);
if (strlen (text) > maxlen)
maxlen = strlen (text);
*x = x1 = gfx.res.x / 2 - ((font[0].size.x + (maxlen * (font[0].size.x - 2))) / 2);
y1 = gfx.res.y / 2 - ((last + 2) * font[0].size.y / 2);
x1 = x1 + font[0].size.x;
draw_menubox (maxlen * font[0].size.x, (last + 3) * font[0].size.y);
if (((3+strlen (menu[last].text))*font[0].size.x) > maxlen) {
*x = gfx.res.x / 2 - (3+strlen (menu[last].text))*font[0].size.x / 2;
maxlen = (3+strlen (menu[last].text))*font[0].size.x;
}
if ((1+strlen (text))*font[2].size.x > maxlen)
maxlen = (1 + strlen (text))*font[2].size.x;
y1 = 2 * font[2].size.y + (last) * font[0].size.y;
draw_menubox (maxlen + 8, y1);
y1 = gfx.res.y / 2 - y1 / 2;
font_setcolor (128,128,0, 2);
font_draw (x1, y1, text, 2);
font_draw ((gfx.res.x / 2) - ((font[2].size.x * strlen (text))/2) - 2, y1 - 2, text, 2);
font_setcolor (255,255,0, 2);
font_draw ((gfx.res.x / 2) - ((font[2].size.x * strlen (text))/2), y1, text, 2);
*y = y1 = y1 + (font[0].size.y * 2);
*y = y1 = y1 + (font[2].size.y * 2);
font_setcolor (255,255,255,0);
for (i = 0; i < last; i++) {
font_draw (x1, y1, menu[i].text, 0);
font_draw ((gfx.res.x / 2) - ((font[0].size.x * strlen (menu[i].text))/2) , y1, menu[i].text, 0);
y1 = y1 + font[0].size.y;
}
font_setcolor (255,255,255,1);
sprintf (vers, "v%s", VERSION);
font_draw (gfx.res.x - font[1].size.x * strlen (vers), gfx.res.y - font[1].size.y, vers, 1);
};
@ -212,7 +218,8 @@ menu_get_text (char *title, char *text, int len)
y,
i,
len_,
eventstate;
eventstate,
maxwidth;
SDL_Event event;
Uint8 *keys;
@ -221,31 +228,35 @@ menu_get_text (char *title, char *text, int len)
if (curpos >= len)
curpos = len - 1;
strcpy (t, text);
if (len > strlen (title)) {
len_ = len;
}
else {
len_ = strlen (title);
}
draw_logo ();
y = (gfx.res.y - 2 * font[0].size.y) / 2;
x = (gfx.res.x - (font[0].size.x - 4) * len_) / 2;
draw_menubox ((font[0].size.x - 1) * len_, 4 * font[0].size.y);
font_draw (x, y, title, 1);
y = y + font[0].size.y;
x = (gfx.res.x - (font[0].size.x - 4) * len) / 2;
if ((len - 1) * (font[0].size.x - 4) > gfx.res.x)
maxwidth = len * font[0].size.x;
if (maxwidth < font[1].size.x * strlen (title))
maxwidth = font[1].size.x * strlen (title);
draw_menubox (maxwidth + 8, font[1].size.y + font[0].size.y + 8);
x = gfx.res.x / 2 - maxwidth / 2;
y = gfx.res.y / 2 - (font[1].size.y + font[0].size.y) / 2;
font_setcolor (128,64,0,1);
font_draw (x - 2, y - 2, title, 1);
font_setcolor (192,128,0,1);
font_draw (x, y, title, 1);
font_setcolor (192,192,192,0);
y = y + font[1].size.y;
if ((len - 1) * (font[0].size.x) > gfx.res.x)
len_ = 40;
else
len_ = len;
while (!done || keypressed == 1) {
redraw_logo_shaded (x, y, (font[0].size.x - 4) * len_, font[0].size.y,
redraw_logo_shaded (x, y, font[0].size.x * len_, font[0].size.y,
MENU_BG_SHADE_DARK);
font_draw (x, y, t, 1);
font_draw (x + (font[0].size.x - 4) * curpos, y, "_", 1);
font_draw (x, y, t, 0);
font_draw (x + font[0].size.x * curpos, y, "_", 0);
SDL_Flip (gfx.screen);
/* do the network loop if we have to */
@ -319,28 +330,37 @@ menu_displaytext (char *title, char *text, Uint8 r, Uint8 g, Uint8 b)
x1,
y,
y1,
len;
len,
maxwidth;
SDL_Rect dest;
len = strlen (title);
if (len < strlen (text))
len = strlen (text);
y = (gfx.res.y - 2 * gfx.block.y) / 2;
x = (gfx.res.x - (font[0].size.x - 4) * len) / 2;
maxwidth = strlen(title) * font[1].size.x;
if (maxwidth < font[0].size.x * strlen (text))
maxwidth = font[0].size.x * strlen (text);
y1 = font[0].size.y * 3;
x1 = ((font[0].size.x - 4) * len);
y = (gfx.res.y - (font[1].size.y + font[1].size.y)) / 2;
x = (gfx.res.x - maxwidth) / 2;
dest.x = x;
y1 = font[0].size.y + font[1].size.y;
x1 = maxwidth + 8;
dest.x = x - 4;
dest.y = y - 4;
dest.h = y1;
dest.w = x1;
dest.h = y1 + 8;
dest.w = x1 + 8;
SDL_FillRect (gfx.screen, &dest, SDL_MapRGB (gfx.screen->format, r, g, b));
y = (gfx.res.y - 2 * gfx.block.y) / 2;
font_draw ((gfx.res.x - (font[1].size.x - 4) * strlen (title)) / 2, y, title, 1);
font_draw ((gfx.res.x - (font[0].size.x - 4) * strlen (text)) / 2, y + font[0].size.y, text,
font_setcolor (128,128,128, 1);
font_draw ((gfx.res.x - font[1].size.x * strlen (title)) / 2 - 2, y - 2, title, 1);
font_setcolor (255,255,255, 1);
font_draw ((gfx.res.x - font[1].size.x * strlen (title)) / 2, y, title, 1);
font_setcolor (255,255,0, 1);
font_draw ((gfx.res.x - font[0].size.x * strlen (text)) / 2, y + font[1].size.y + 2, text,
0);
SDL_Flip (gfx.screen);
@ -432,34 +452,43 @@ int
menu_dir_draw (char *title, _direntry * dirstart, int start, int selected)
{
_direntry *de = dirstart;
int maxlen = 0,
int maxlen = 0, maxchar = 0,
pos = 0;
SDL_Rect wnd;
/* look for the longest name */
for (; de != NULL; de = de->next)
if (maxlen < strlen (de->name))
maxlen = strlen (de->name);
maxlen = font[1].size.x * strlen (title);
if (maxlen < strlen (title))
maxlen = strlen (title);
for (; de != NULL; de = de->next)
if (maxlen < font[0].size.x * strlen (de->name))
maxlen = font[0].size.x * strlen (de->name);
if (maxlen * font[0].size.x > gfx.res.x - 32)
maxlen = (gfx.res.x - 40) / font[0].size.x;
if (maxlen > gfx.res.x - 32)
maxchar = (gfx.res.x - 40) / font[0].size.x;
else
maxchar = maxlen / font[0].size.x;
wnd.h = DIRSCRMAX * font[0].size.y * 2;
wnd.w = maxlen * font[0].size.x;
wnd.w = maxlen;
wnd.x = (gfx.res.x - wnd.w) / 2;
wnd.y = (gfx.res.y - wnd.h) / 2;
draw_menubox (wnd.w, wnd.h);
font_draw ((gfx.res.x - (font[0].size.x / 1.17) * strlen (title)) / 2, wnd.y + 4, title, 1);
draw_menubox (wnd.w + 8, wnd.h + 8);
font_setcolor (128,64,0,1);
font_draw ((gfx.res.x - font[1].size.x * strlen (title)) / 2 - 2, wnd.y - 2, title, 1);
font_setcolor (192,128,0,1);
font_draw ((gfx.res.x - font[1].size.x * strlen (title)) / 2, wnd.y, title, 1);
for (de = dirstart, pos = 0; de != NULL && pos < start + DIRSCRMAX - 1; de = de->next, pos++) {
if (pos >= start && pos < (start + DIRSCRMAX - 1))
font_draw (wnd.x + gfx.menuselect.image->w + 2,
8 + wnd.y + (1 + pos - start) * font[0].size.y * 2, de->name,
(pos == selected));
if (pos >= start && pos < (start + DIRSCRMAX - 1)) {
if (pos == selected)
font_setcolor (255,255,255, 0);
else
font_setcolor (128,128,128, 0);
font_draw (wnd.x + gfx.menuselect.image->w + 2,
8 + wnd.y + (1 + pos - start) * font[0].size.y * 2, de->name, 0);
}
}
return (de == NULL);

Loading…
Cancel
Save