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.
bomberclone/src/menubools.c

61 lines
1.9 KiB

/* $Id: menubools.c,v 1.1 2003/12/24 02:42:05 stpohle Exp $
* Menuhandling: bools */
#include "basic.h"
#include "bomberclone.h"
#include "menu.h"
#include "menugui.h"
/* create a bool only in the menudatas.. darf all this only when menu_loop
* is called */
void menu_create_bool (char *name, int x, int y, int w, int *data, int id) {
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_button: MENU_MAXENTRYS reached. Item Ignored\n");
return;
}
else { /* add new item to the list */
menuitems[i].next = &menuitems[i+1];
i++;
}
menuitems[i].type = MENU_bool;
menuitems[i].pos.w = (1 + (int)((w - menu.buttonimages[0][0]->w - menu.buttonimages[0][2]->w) / menu.buttonimages[0][1]->w)) * menu.buttonimages[0][1]->w + menu.buttonimages[0][0]->w + menu.buttonimages[0][2]->w;
if (x != -1)
menuitems[i].pos.x = x;
else
menuitems[i].pos.x = (menu.oldscreenpos.w - 2 * menu.images[0]->w - menuitems[i].pos.w) / 2;
menuitems[i].pos.y = y;
menuitems[i].state = 0;
menuitems[i].id = id;
menuitems[i].ptrdata = (char *)data;
strncpy (menuitems[i].label, name, MENU_TITLELEN);
};
/* handle the event on the button
* Return: 1 - if the button was pressed (With Enter) */
int menu_event_bool (_menuitem *mi, SDL_Event *event) {
switch (event->type) {
case (SDL_KEYDOWN): /* key was pressed */
if (event->key.keysym.sym == SDLK_LEFT || event->key.keysym.sym == SDLK_UP)
menu_focus_prev ();
else if (event->key.keysym.sym == SDLK_RIGHT || event->key.keysym.sym == SDLK_DOWN)
menu_focus_next ();
else if (event->key.keysym.sym == SDLK_RETURN || event->key.keysym.sym == SDLK_LCTRL || event->key.keysym.sym == SDLK_RCTRL) {
*(int *)mi->ptrdata = !(*(int *)mi->ptrdata);
menu_draw_bool (mi);
}
break;
}
return 0;
};