You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.1 KiB
78 lines
2.1 KiB
/* $Id: menulabels.c,v 1.4 2004/02/07 15:03:25 stpohle Exp $
|
|
* Menuhandling: labels */
|
|
|
|
#include "basic.h"
|
|
#include "bomberclone.h"
|
|
#include "menu.h"
|
|
#include "menugui.h"
|
|
|
|
|
|
/* draw the menuitem label
|
|
* menuitem->pos.[x|y] - Position inside the menu
|
|
* pos.w - Fontsize
|
|
* label - Text of the label
|
|
*/
|
|
void menu_draw_label (_menuitem *mi) {
|
|
int dx, dy;
|
|
|
|
if (mi->type != MENU_label)
|
|
return;
|
|
|
|
if (mi->pos.x == -1)
|
|
dx = (menu.oldscreenpos.w - 2*menu.images[0]->w - (strlen (mi->label) * font[mi->pos.w].size.x)) / 2;
|
|
else
|
|
dx = mi->pos.x;
|
|
if (mi->pos.y == -1)
|
|
dy = (menu.oldscreenpos.h - 2*menu.images[0]->h - font[mi->pos.w].size.y) / 2;
|
|
else
|
|
dy = mi->pos.y;
|
|
|
|
font_gfxdraw (menu.oldscreenpos.x + menu.images[0]->w + dx, menu.oldscreenpos.y + menu.images[0]->h + dy, mi->label, mi->pos.w, mi->pos.h, 10000);
|
|
};
|
|
|
|
|
|
void menu_create_label (char *name, int x, int y, int fontsize, int fontcolor) {
|
|
int i = menu_getlastitem(menu.items);
|
|
|
|
if (i == -1) { /* first entry in the itemslist */
|
|
menu.items = &menuitems[0];
|
|
i = 0;
|
|
}
|
|
else if (i >= MENU_MAXENTRYS) { /* max items reached, ignore new item */
|
|
d_fatal ("menu_create_label: MENU_MAXENTRYS reached. Item Ignored\n");
|
|
return;
|
|
}
|
|
else { /* add new item to the list */
|
|
menuitems[i].next = &menuitems[i+1];
|
|
i++;
|
|
}
|
|
|
|
menuitems[i].pos.x = x;
|
|
menuitems[i].pos.y = y;
|
|
menuitems[i].pos.w = fontsize;
|
|
menuitems[i].pos.h = fontcolor;
|
|
menuitems[i].type = MENU_label;
|
|
strncpy (menuitems[i].label, name, MENU_TITLELEN);
|
|
};
|
|
|
|
|
|
/* this will wrap a text into more labels */
|
|
void menu_create_text (char *name, int x, int y, int maxlen, int maxlines, int fontcolor, char *fmt,...) {
|
|
char text[1024];
|
|
char out[1024];
|
|
char *lineptr[maxlines+1];
|
|
int linecnt, maxchar, i;
|
|
va_list args;
|
|
|
|
/* read the whole text and convert it to a normal char text */
|
|
memset (text, 0, sizeof (text));
|
|
memset (out, 0, sizeof (out));
|
|
va_start (args, fmt);
|
|
vsprintf (text, fmt, args);
|
|
va_end (args);
|
|
|
|
menu_formattext (text, out, lineptr, &linecnt, &maxchar, maxlen, maxlines);
|
|
for (i = 0; (i <= linecnt && i < maxlines); i++)
|
|
menu_create_label (lineptr[i], x, y + i * font[0].size.y, 0, fontcolor);
|
|
};
|