bkgd = NULL;
}
-void Button::change_icon(std::string icon_file, int mw, int mh)
+void Button::change_icon(std::string icon_file, int /*mw*/, int /*mh*/)
{
char filename[1024];
{
/* Check for menu-events, if the menu is shown */
if(show_menu)
- menu_event(event);
+ current_menu->event(event);
switch(event.type)
{
while(SDL_PollEvent(&event))
if(event.type == SDL_KEYDOWN)
- menu_event(event);
+ current_menu->event(event);
switch (highscore_menu->check())
{
le_set_defaults();
le_current_level->load_gfx();
le_world.activate_bad_guys();
- menu_item_change_input(&subset_new_menu->item[2],"");
+ subset_new_menu->item[2].change_input("");
show_menu = true;
break;
}
char str[80];
int i;
- menu_item_change_input(&level_settings_menu->item[2], le_current_level->name.c_str());
+ level_settings_menu->item[2].change_input(le_current_level->name.c_str());
sprintf(str,"%d",le_current_level->width);
string_list_copy(level_settings_menu->item[3].list, dsubdirs("images/themes", "solid0.png"));
if((i = string_list_find(level_settings_menu->item[5].list,le_current_level->bkgd_image.c_str())) != -1)
level_settings_menu->item[5].list->active_item = i;
- menu_item_change_input(&level_settings_menu->item[6], str);
+ level_settings_menu->item[6].change_input(str);
sprintf(str,"%d",le_current_level->time_left);
- menu_item_change_input(&level_settings_menu->item[7], str);
+ level_settings_menu->item[7].change_input(str);
sprintf(str,"%2.0f",le_current_level->gravity);
- menu_item_change_input(&level_settings_menu->item[8], str);
+ level_settings_menu->item[8].change_input(str);
sprintf(str,"%d",le_current_level->bkgd_red);
- menu_item_change_input(&level_settings_menu->item[9], str);
+ level_settings_menu->item[9].change_input(str);
sprintf(str,"%d",le_current_level->bkgd_green);
- menu_item_change_input(&level_settings_menu->item[10], str);
+ level_settings_menu->item[10].change_input(str);
sprintf(str,"%d",le_current_level->bkgd_blue);
- menu_item_change_input(&level_settings_menu->item[11], str);
+ level_settings_menu->item[11].change_input(str);
}
void update_subset_settings_menu()
{
- menu_item_change_input(&subset_settings_menu->item[2], le_level_subset.title.c_str());
- menu_item_change_input(&subset_settings_menu->item[3], le_level_subset.description.c_str());
+ subset_settings_menu->item[2].change_input(le_level_subset.title.c_str());
+ subset_settings_menu->item[3].change_input(le_level_subset.description.c_str());
}
void apply_level_settings_menu()
while(SDL_PollEvent(&event))
{
if(show_menu)
- menu_event(event);
+ current_menu->event(event);
else
mouse_cursor->set_state(MC_NORMAL);
}
/* Return a pointer to a new menu item */
-menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu)
+MenuItem*
+MenuItem::create(MenuItemKind kind_, char *text_, int init_toggle_, Menu* target_menu_)
{
- menu_item_type *pnew_item = (menu_item_type*) malloc(sizeof(menu_item_type));
- pnew_item->kind = kind;
- pnew_item->text = (char*) malloc(sizeof(char) * (strlen(text) + 1));
- strcpy(pnew_item->text,text);
- if(kind == MN_TOGGLE)
- pnew_item->toggled = init_toggle;
+ MenuItem *pnew_item = new MenuItem;
+
+ pnew_item->kind = kind_;
+ pnew_item->text = (char*) malloc(sizeof(char) * (strlen(text_) + 1));
+ strcpy(pnew_item->text, text_);
+
+ if(kind_ == MN_TOGGLE)
+ pnew_item->toggled = init_toggle_;
else
pnew_item->toggled = false;
- pnew_item->target_menu = target_menu;
+
+ pnew_item->target_menu = target_menu_;
pnew_item->input = (char*) malloc(sizeof(char));
pnew_item->input[0] = '\0';
- if(kind == MN_STRINGSELECT)
+
+ if(kind_ == MN_STRINGSELECT)
{
pnew_item->list = (string_list_type*) malloc(sizeof(string_list_type));
string_list_init(pnew_item->list);
return pnew_item;
}
-void menu_item_change_text(menu_item_type* pmenu_item,const char *text)
+void
+MenuItem::change_text(const char *text_)
{
- if(text)
+ if (text_)
{
- free(pmenu_item->text);
- pmenu_item->text = (char*) malloc(sizeof(char )*(strlen(text)+1));
- strcpy(pmenu_item->text,text);
+ free(text);
+ text = (char*) malloc(sizeof(char )*(strlen(text_)+1));
+ strcpy(text, text_);
}
}
-void menu_item_change_input(menu_item_type* pmenu_item,const char *text)
+
+void
+MenuItem::change_input(const char *text_)
{
if(text)
{
- free(pmenu_item->input);
- pmenu_item->input = (char*) malloc(sizeof(char )*(strlen(text)+1));
- strcpy(pmenu_item->input,text);
+ free(input);
+ input = (char*) malloc(sizeof(char )*(strlen(text_)+1));
+ strcpy(input, text_);
}
}
}
void
-Menu::additem(MenuItemKind kind, char *text, int toggle, Menu* menu)
+Menu::additem(MenuItemKind kind_, char *text_, int toggle_, Menu* menu_)
{
- additem(menu_item_create(kind, text, toggle, menu));
+ additem(MenuItem::create(kind_, text_, toggle_, menu_));
}
/* Add an item to a menu */
void
-Menu::additem(menu_item_type* pmenu_item)
+Menu::additem(MenuItem* pmenu_item)
{
++num_items;
- item = (menu_item_type*)realloc(item, sizeof(menu_item_type) * num_items);
- memcpy(&item[num_items-1],pmenu_item,sizeof(menu_item_type));
+ item = (MenuItem*)realloc(item, sizeof(MenuItem) * num_items);
+ memcpy(&item[num_items-1], pmenu_item, sizeof(MenuItem));
free(pmenu_item);
}
}
}
- menu_item_type& new_item = item[active_item];
+ MenuItem& new_item = item[active_item];
if(new_item.kind == MN_DEACTIVE
|| new_item.kind == MN_LABEL
|| new_item.kind == MN_HL)
int menu_width,
int menu_height)
{
- int font_width = 16;
-
- const menu_item_type& pitem = item[index];
+ const MenuItem& pitem = item[index];
+ int font_width = 16;
int effect_offset = 0;
{
int effect_time = 0;
}
/* Check for menu event */
-void menu_event(SDL_Event& event)
+void
+Menu::event(SDL_Event& event)
{
SDLKey key;
switch(event.type)
menu_change = true;
break;
case SDLK_SPACE:
- if(current_menu->item[current_menu->active_item].kind == MN_TEXTFIELD)
+ if(item[active_item].kind == MN_TEXTFIELD)
{
menuaction = MENU_ACTION_INPUT;
menu_change = true;
case SDL_MOUSEBUTTONDOWN:
x = event.motion.x;
y = event.motion.y;
- if(x > current_menu->pos_x - current_menu->width()/2 &&
- x < current_menu->pos_x + current_menu->width()/2 &&
- y > current_menu->pos_y - current_menu->height()/2 &&
- y < current_menu->pos_y + current_menu->height()/2)
+ if(x > pos_x - width()/2 &&
+ x < pos_x + width()/2 &&
+ y > pos_y - height()/2 &&
+ y < pos_y + height()/2)
{
menuaction = MENU_ACTION_HIT;
}
case SDL_MOUSEMOTION:
x = event.motion.x;
y = event.motion.y;
- if(x > current_menu->pos_x - current_menu->width()/2 &&
- x < current_menu->pos_x + current_menu->width()/2 &&
- y > current_menu->pos_y - current_menu->height()/2 &&
- y < current_menu->pos_y + current_menu->height()/2)
+ if(x > pos_x - width()/2 &&
+ x < pos_x + width()/2 &&
+ y > pos_y - height()/2 &&
+ y < pos_y + height()/2)
{
- current_menu->active_item = (y - (current_menu->pos_y - current_menu->height()/2)) / 24;
+ active_item = (y - (pos_y - height()/2)) / 24;
menu_change = true;
mouse_cursor->set_state(MC_LINK);
}
class Menu;
-struct menu_item_type
- {
- MenuItemKind kind;
- int toggled;
- char *text;
- char *input;
- string_list_type* list;
- Menu* target_menu;
-};
+class MenuItem
+{
+public:
+ MenuItemKind kind;
+ int toggled;
+ char *text;
+ char *input;
+ string_list_type* list;
+ Menu* target_menu;
-menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu);
-void menu_item_change_text (menu_item_type* pmenu_item, const char *text);
-void menu_item_change_input(menu_item_type* pmenu_item, const char *text);
+ void change_text (const char *text);
+ void change_input(const char *text);
+
+ static MenuItem* create(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu);
+};
class Menu
{
-friend void menu_event(SDL_Event& event);
-
private:
// position of the menu (ie. center of the menu, not top/left)
int pos_x;
Timer effect;
int arrange_left;
int active_item;
- menu_item_type *item;
+ MenuItem* item;
static void set_current(Menu* pmenu);
Menu();
~Menu();
- void additem(menu_item_type* pmenu_item);
+ void additem(MenuItem* pmenu_item);
void additem(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu);
void action ();
void draw ();
void draw_item(int index, int menu_width, int menu_height);
void set_pos(int x, int y, float rw = 0, float rh = 0);
+
+ /* Check for a menu event */
+ void event(SDL_Event& event);
};
extern MenuAction menuaction;
extern bool show_menu;
extern bool menu_change;
-extern texture_type checkbox, checkbox_checked, back, arrow_left, arrow_right;
+
+extern texture_type checkbox;
+extern texture_type checkbox_checked;
+extern texture_type back;
+extern texture_type arrow_left;
+extern texture_type arrow_right;
extern Menu* contrib_menu;
extern Menu* main_menu;
/* "Calculate" and draw the menu */
void menu_process_current(void);
-/* Check for a menu event */
-void menu_event(SDL_Event& event);
-
#endif /*SUPERTUX_MENU_H*/
/* Local Variables: */
pmenu->item[i].kind = MN_ACTION;
else
pmenu->item[i].kind = MN_ACTION;
- menu_item_change_text(&pmenu->item[i], tmp.c_str());
+ pmenu->item[i].change_text(tmp.c_str());
}
}
while (SDL_PollEvent(&event))
{
- menu_event(event);
+ current_menu->event(event);
if (event.type == SDL_QUIT)
{
done = true;