std::vector<Menu*> Menu::last_menus;
Menu* Menu::current_ = 0;
+Font* Menu::default_font;
+Font* Menu::active_font;
+Font* Menu::deactive_font;
+Font* Menu::label_font;
+Font* Menu::field_font;
/* just displays a Yes/No text that can be used to confirm stuff */
bool SuperTux::confirm_dialog(Surface *background, std::string text)
{
//Surface* cap_screen = Surface::CaptureScreen();
-
+
Menu* dialog = new Menu;
dialog->additem(MN_DEACTIVE, text,0,0);
dialog->additem(MN_HL,"",0,0);
DrawingContext context;
while(true)
- {
- SDL_Event event;
-
- while (SDL_PollEvent(&event))
{
- dialog->event(event);
- }
+ SDL_Event event;
- if(background == NULL)
- context.draw_gradient(Color(200,240,220), Color(200,200,220), LAYER_BACKGROUND0);
- else
- context.draw_surface(background, Vector(0,0), LAYER_BACKGROUND0);
+ while (SDL_PollEvent(&event))
+ {
+ dialog->event(event);
+ }
- dialog->draw(context);
- dialog->action();
+ if(background == NULL)
+ context.draw_gradient(Color(200,240,220), Color(200,200,220), LAYER_BACKGROUND0);
+ else
+ context.draw_surface(background, Vector(0,0), LAYER_BACKGROUND0);
- switch (dialog->check())
- {
- case true:
- //delete cap_screen;
- Menu::set_current(0);
- delete dialog;
- return true;
- break;
- case false:
- //delete cap_screen;
- Menu::set_current(0);
- delete dialog;
- return false;
- break;
- default:
- break;
- }
+ dialog->draw(context);
+ dialog->action();
- mouse_cursor->draw(context);
- context.do_drawing();
- SDL_Delay(25);
- }
+ switch (dialog->check())
+ {
+ case true:
+ //delete cap_screen;
+ Menu::set_current(0);
+ delete dialog;
+ return true;
+ break;
+ case false:
+ //delete cap_screen;
+ Menu::set_current(0);
+ delete dialog;
+ return false;
+ break;
+ default:
+ break;
+ }
+
+ mouse_cursor->draw(context);
+ context.do_drawing();
+ SDL_Delay(25);
+ }
return false;
}
Menu::pop_current()
{
if (!last_menus.empty())
- {
- current_ = last_menus.back();
- current_->effect.start(500);
+ {
+ current_ = last_menus.back();
+ current_->effect.start(500);
- last_menus.pop_back();
- }
+ last_menus.pop_back();
+ }
else
- {
- current_ = 0;
- }
+ {
+ current_ = 0;
+ }
}
void
pnew_item->input[0] = '\0';
if(kind_ == MN_STRINGSELECT)
- {
- pnew_item->list = (string_list_type*) malloc(sizeof(string_list_type));
- string_list_init(pnew_item->list);
- }
+ {
+ pnew_item->list = (string_list_type*) malloc(sizeof(string_list_type));
+ string_list_init(pnew_item->list);
+ }
else
pnew_item->list = NULL;
MenuItem::change_text(const char *text_)
{
if (text_)
- {
- free(text);
- text = (char*) malloc(sizeof(char )*(strlen(text_)+1));
- strcpy(text, text_);
- }
+ {
+ free(text);
+ text = (char*) malloc(sizeof(char )*(strlen(text_)+1));
+ strcpy(text, text_);
+ }
}
void
MenuItem::change_input(const char *text_)
{
if(text)
- {
- free(input);
- input = (char*) malloc(sizeof(char )*(strlen(text_)+1));
- strcpy(input, text_);
- }
+ {
+ free(input);
+ input = (char*) malloc(sizeof(char )*(strlen(text_)+1));
+ strcpy(input, text_);
+ }
}
std::string MenuItem::get_input_with_symbol(bool active_item)
if(!active_item)
input_flickering = true;
else
- {
- if(input_flickering_timer.get_left() < 0)
{
- if(input_flickering)
- input_flickering = false;
- else
- input_flickering = true;
- input_flickering_timer.start(FLICK_CURSOR_TIME);
+ if(input_flickering_timer.get_left() < 0)
+ {
+ if(input_flickering)
+ input_flickering = false;
+ else
+ input_flickering = true;
+ input_flickering_timer.start(FLICK_CURSOR_TIME);
+ }
}
- }
char str[1024];
if(input_flickering)
void Menu::get_controlfield_key_into_input(MenuItem *item)
{
switch(*item->int_p)
- {
- case SDLK_UP:
- item->change_input(_("Up cursor"));
- break;
- case SDLK_DOWN:
- item->change_input(_("Down cursor"));
- break;
- case SDLK_LEFT:
- item->change_input(_("Left cursor"));
- break;
- case SDLK_RIGHT:
- item->change_input(_("Right cursor"));
- break;
- case SDLK_RETURN:
- item->change_input(_("Return"));
- break;
- case SDLK_SPACE:
- item->change_input(_("Space"));
- break;
- case SDLK_RSHIFT:
- item->change_input(_("Right Shift"));
- break;
- case SDLK_LSHIFT:
- item->change_input(_("Left Shift"));
- break;
- case SDLK_RCTRL:
- item->change_input(_("Right Control"));
- break;
- case SDLK_LCTRL:
- item->change_input(_("Left Control"));
- break;
- case SDLK_RALT:
- item->change_input(_("Right Alt"));
- break;
- case SDLK_LALT:
- item->change_input(_("Left Alt"));
- break;
- default:
{
- char tmp[64];
- snprintf(tmp, 64, "%d", *item->int_p);
- item->change_input(tmp);
+ case SDLK_UP:
+ item->change_input(_("Up cursor"));
+ break;
+ case SDLK_DOWN:
+ item->change_input(_("Down cursor"));
+ break;
+ case SDLK_LEFT:
+ item->change_input(_("Left cursor"));
+ break;
+ case SDLK_RIGHT:
+ item->change_input(_("Right cursor"));
+ break;
+ case SDLK_RETURN:
+ item->change_input(_("Return"));
+ break;
+ case SDLK_SPACE:
+ item->change_input(_("Space"));
+ break;
+ case SDLK_RSHIFT:
+ item->change_input(_("Right Shift"));
+ break;
+ case SDLK_LSHIFT:
+ item->change_input(_("Left Shift"));
+ break;
+ case SDLK_RCTRL:
+ item->change_input(_("Right Control"));
+ break;
+ case SDLK_LCTRL:
+ item->change_input(_("Left Control"));
+ break;
+ case SDLK_RALT:
+ item->change_input(_("Right Alt"));
+ break;
+ case SDLK_LALT:
+ item->change_input(_("Left Alt"));
+ break;
+ default:
+ {
+ char tmp[64];
+ snprintf(tmp, 64, "%d", *item->int_p);
+ item->change_input(tmp);
+ }
+ break;
}
- break;
- }
}
/* Set ControlField for joystick button */
Menu::~Menu()
{
if(item.size() != 0)
- {
- for(unsigned int i = 0; i < item.size(); ++i)
{
- free(item[i].text);
- free(item[i].input);
- string_list_free(item[i].list);
+ for(unsigned int i = 0; i < item.size(); ++i)
+ {
+ free(item[i].text);
+ free(item[i].input);
+ string_list_free(item[i].list);
+ }
}
- }
}
{
hit_item = -1;
if(item.size() != 0)
- {
- switch(menuaction)
{
- case MENU_ACTION_UP:
- if (active_item > 0)
- --active_item;
- else
- active_item = int(item.size())-1;
- break;
-
- case MENU_ACTION_DOWN:
- if(active_item < int(item.size())-1)
- ++active_item;
- else
- active_item = 0;
- break;
-
- case MENU_ACTION_LEFT:
- if(item[active_item].kind == MN_STRINGSELECT
- && item[active_item].list->num_items != 0)
- {
- if(item[active_item].list->active_item > 0)
- --item[active_item].list->active_item;
- else
- item[active_item].list->active_item = item[active_item].list->num_items-1;
- }
- break;
-
- case MENU_ACTION_RIGHT:
- if(item[active_item].kind == MN_STRINGSELECT
- && item[active_item].list->num_items != 0)
- {
- if(item[active_item].list->active_item < item[active_item].list->num_items-1)
- ++item[active_item].list->active_item;
- else
- item[active_item].list->active_item = 0;
- }
- break;
-
- case MENU_ACTION_HIT:
- {
- hit_item = active_item;
- switch (item[active_item].kind)
+ switch(menuaction)
{
- case MN_GOTO:
- if (item[active_item].target_menu != NULL)
- Menu::push_current(item[active_item].target_menu);
+ case MENU_ACTION_UP:
+ if (active_item > 0)
+ --active_item;
else
- puts("NULLL");
+ active_item = int(item.size())-1;
break;
- case MN_TOGGLE:
- item[active_item].toggled = !item[active_item].toggled;
+ case MENU_ACTION_DOWN:
+ if(active_item < int(item.size())-1)
+ ++active_item;
+ else
+ active_item = 0;
break;
- case MN_ACTION:
- Menu::set_current(0);
- item[active_item].toggled = true;
- break;
- case MN_TEXTFIELD:
- case MN_NUMFIELD:
- menuaction = MENU_ACTION_DOWN;
- action();
+ case MENU_ACTION_LEFT:
+ if(item[active_item].kind == MN_STRINGSELECT
+ && item[active_item].list->num_items != 0)
+ {
+ if(item[active_item].list->active_item > 0)
+ --item[active_item].list->active_item;
+ else
+ item[active_item].list->active_item = item[active_item].list->num_items-1;
+ }
break;
- case MN_BACK:
- Menu::pop_current();
- break;
- default:
+ case MENU_ACTION_RIGHT:
+ if(item[active_item].kind == MN_STRINGSELECT
+ && item[active_item].list->num_items != 0)
+ {
+ if(item[active_item].list->active_item < item[active_item].list->num_items-1)
+ ++item[active_item].list->active_item;
+ else
+ item[active_item].list->active_item = 0;
+ }
break;
- }
- }
- break;
-
- case MENU_ACTION_REMOVE:
- if(item[active_item].kind == MN_TEXTFIELD
- || item[active_item].kind == MN_NUMFIELD)
- {
- if(item[active_item].input != NULL)
- {
- int i = strlen(item[active_item].input);
- while(delete_character > 0) /* remove charactes */
+ case MENU_ACTION_HIT:
{
- item[active_item].input[i-1] = '\0';
- delete_character--;
+ hit_item = active_item;
+ switch (item[active_item].kind)
+ {
+ case MN_GOTO:
+ if (item[active_item].target_menu != NULL)
+ Menu::push_current(item[active_item].target_menu);
+ else
+ puts("NULLL");
+ break;
+
+ case MN_TOGGLE:
+ item[active_item].toggled = !item[active_item].toggled;
+ break;
+
+ case MN_ACTION:
+ Menu::set_current(0);
+ item[active_item].toggled = true;
+ break;
+ case MN_TEXTFIELD:
+ case MN_NUMFIELD:
+ menuaction = MENU_ACTION_DOWN;
+ action();
+ break;
+
+ case MN_BACK:
+ Menu::pop_current();
+ break;
+ default:
+ break;
+ }
}
- }
- }
- break;
+ break;
- case MENU_ACTION_INPUT:
- if(item[active_item].kind == MN_TEXTFIELD
- || (item[active_item].kind == MN_NUMFIELD && mn_input_char >= '0' && mn_input_char <= '9'))
- {
- if(item[active_item].input != NULL)
- {
- int i = strlen(item[active_item].input);
- item[active_item].input = (char*) realloc(item[active_item].input,sizeof(char)*(i + 2));
- item[active_item].input[i] = mn_input_char;
- item[active_item].input[i+1] = '\0';
- }
- else
- {
- item[active_item].input = (char*) malloc(2*sizeof(char));
- item[active_item].input[0] = mn_input_char;
- item[active_item].input[1] = '\0';
- }
- }
+ case MENU_ACTION_REMOVE:
+ if(item[active_item].kind == MN_TEXTFIELD
+ || item[active_item].kind == MN_NUMFIELD)
+ {
+ if(item[active_item].input != NULL)
+ {
+ int i = strlen(item[active_item].input);
+
+ while(delete_character > 0) /* remove charactes */
+ {
+ item[active_item].input[i-1] = '\0';
+ delete_character--;
+ }
+ }
+ }
+ break;
- case MENU_ACTION_NONE:
- break;
+ case MENU_ACTION_INPUT:
+ if(item[active_item].kind == MN_TEXTFIELD
+ || (item[active_item].kind == MN_NUMFIELD && mn_input_char >= '0' && mn_input_char <= '9'))
+ {
+ if(item[active_item].input != NULL)
+ {
+ int i = strlen(item[active_item].input);
+ item[active_item].input = (char*) realloc(item[active_item].input,sizeof(char)*(i + 2));
+ item[active_item].input[i] = mn_input_char;
+ item[active_item].input[i+1] = '\0';
+ }
+ else
+ {
+ item[active_item].input = (char*) malloc(2*sizeof(char));
+ item[active_item].input[0] = mn_input_char;
+ item[active_item].input[1] = '\0';
+ }
+ }
+
+ case MENU_ACTION_NONE:
+ break;
+ }
}
- }
MenuItem& new_item = item[active_item];
if(new_item.kind == MN_DEACTIVE
|| new_item.kind == MN_LABEL
|| new_item.kind == MN_HL)
- {
- // Skip the horzontal line item
- if (menuaction != MENU_ACTION_UP && menuaction != MENU_ACTION_DOWN)
- menuaction = MENU_ACTION_DOWN;
+ {
+ // Skip the horzontal line item
+ if (menuaction != MENU_ACTION_UP && menuaction != MENU_ACTION_DOWN)
+ menuaction = MENU_ACTION_DOWN;
- if (item.size() > 1)
- action();
- }
+ if (item.size() > 1)
+ action();
+ }
menuaction = MENU_ACTION_NONE;
void
Menu::draw_item(DrawingContext& context,
- int index, // Position of the current item in the menu
- int menu_width, int menu_height)
+ int index, // Position of the current item in the menu
+ int menu_width, int menu_height)
{
MenuItem& pitem = item[index];
effect_offset = (index % 2) ? effect_time : -effect_time;
}
- Font* text_font = white_text;
+ Font* text_font = default_font;
int x_pos = pos_x;
int y_pos = pos_y + 24*index - menu_height/2 + 12 + effect_offset;
int shadow_size = 2;
x_pos += 24 - menu_width/2 + (text_width + input_width + list_width)/2;
if(index == active_item)
- {
- shadow_size = 3;
- text_font = blue_text;
- }
-
- switch (pitem.kind)
- {
- case MN_DEACTIVE:
{
- context.draw_text_center(gray_text, pitem.text,
- Vector(0, y_pos - int(blue_text->get_height()/2)),
- LAYER_GUI);
- break;
+ shadow_size = 3;
+ text_font = active_font;
}
- case MN_HL:
- {
- // TODO
- int x = pos_x - menu_width/2;
- int y = y_pos - 12 - effect_offset;
- /* Draw a horizontal line with a little 3d effect */
- context.draw_filled_rect(Vector(x, y + 6),
- Vector(menu_width, 4), Color(150,200,255,225), LAYER_GUI);
- context.draw_filled_rect(Vector(x, y + 6),
- Vector(menu_width, 2), Color(255,255,255,255), LAYER_GUI);
- break;
- }
- case MN_LABEL:
- {
- context.draw_text_center(white_big_text,
- pitem.text, Vector(0, y_pos - int(white_big_text->get_height()/2)),
- LAYER_GUI);
- break;
- }
- case MN_TEXTFIELD:
- case MN_NUMFIELD:
- case MN_CONTROLFIELD_KB:
- case MN_CONTROLFIELD_JS:
+ switch (pitem.kind)
{
- int width = text_width + input_width + 5;
- int text_pos = screen->w/2 - width/2;
- int input_pos = text_pos + text_width + 10;
+ case MN_DEACTIVE:
+ {
+ context.draw_text_center(deactive_font, pitem.text,
+ Vector(0, y_pos - int(deactive_font->get_height()/2)),
+ LAYER_GUI);
+ break;
+ }
+
+ case MN_HL:
+ {
+ // TODO
+ int x = pos_x - menu_width/2;
+ int y = y_pos - 12 - effect_offset;
+ /* Draw a horizontal line with a little 3d effect */
+ context.draw_filled_rect(Vector(x, y + 6),
+ Vector(menu_width, 4), Color(150,200,255,225), LAYER_GUI);
+ context.draw_filled_rect(Vector(x, y + 6),
+ Vector(menu_width, 2), Color(255,255,255,255), LAYER_GUI);
+ break;
+ }
+ case MN_LABEL:
+ {
+ context.draw_text_center(label_font,
+ pitem.text, Vector(0, y_pos - int(label_font->get_height()/2)),
+ LAYER_GUI);
+ break;
+ }
+ case MN_TEXTFIELD:
+ case MN_NUMFIELD:
+ case MN_CONTROLFIELD_KB:
+ case MN_CONTROLFIELD_JS:
+ {
+ int width = text_width + input_width + 5;
+ int text_pos = screen->w/2 - width/2;
+ int input_pos = text_pos + text_width + 10;
- context.draw_filled_rect(
+ context.draw_filled_rect(
Vector(input_pos - 5, y_pos - 10),
Vector(input_width + 10, 20),
Color(255,255,255,255), LAYER_GUI-5);
- context.draw_filled_rect(
+ context.draw_filled_rect(
Vector(input_pos - 4, y_pos - 9),
Vector(input_width + 8, 18),
Color(0,0,0,128), LAYER_GUI-4);
- if(pitem.kind == MN_CONTROLFIELD_KB)
- get_controlfield_key_into_input(&pitem);
- else if (pitem.kind == MN_CONTROLFIELD_JS)
- get_controlfield_js_into_input(&pitem);
+ if(pitem.kind == MN_CONTROLFIELD_KB)
+ get_controlfield_key_into_input(&pitem);
+ else if (pitem.kind == MN_CONTROLFIELD_JS)
+ get_controlfield_js_into_input(&pitem);
- if(pitem.kind == MN_TEXTFIELD || pitem.kind == MN_NUMFIELD)
- {
- if(active_item == index)
- context.draw_text(gold_text,
- pitem.get_input_with_symbol(true),
- Vector(input_pos, y_pos - int(gold_text->get_height()/2)),
- LAYER_GUI);
+ if(pitem.kind == MN_TEXTFIELD || pitem.kind == MN_NUMFIELD)
+ {
+ if(active_item == index)
+ context.draw_text(field_font,
+ pitem.get_input_with_symbol(true),
+ Vector(input_pos, y_pos - int(field_font->get_height()/2)),
+ LAYER_GUI);
+ else
+ context.draw_text(field_font,
+ pitem.get_input_with_symbol(false),
+ Vector(input_pos, y_pos - int(field_font->get_height()/2)),
+ LAYER_GUI);
+ }
else
- context.draw_text(gold_text,
- pitem.get_input_with_symbol(false),
- Vector(input_pos, y_pos - int(gold_text->get_height()/2)),
- LAYER_GUI);
+ context.draw_text(field_font, pitem.input,
+ Vector(input_pos, y_pos - int(field_font->get_height()/2)),
+ LAYER_GUI);
+
+ context.draw_text(text_font, pitem.text,
+ Vector(text_pos, y_pos - int(text_font->get_height()/2)),
+ LAYER_GUI);
+ break;
}
- else
- context.draw_text(gold_text, pitem.input,
- Vector(input_pos, y_pos - int(gold_text->get_height()/2)),
- LAYER_GUI);
-
- context.draw_text(text_font, pitem.text,
- Vector(text_pos, y_pos - int(text_font->get_height()/2)),
- LAYER_GUI);
- break;
- }
- case MN_STRINGSELECT:
- {
- int list_pos_2 = list_width + 16;
- int list_pos = list_width/2;
- int text_pos = (text_width + 16)/2;
-
- /* Draw arrows */
- context.draw_surface(arrow_left,
- Vector(x_pos - list_pos + text_pos - 17, y_pos - 8),
- LAYER_GUI);
- context.draw_surface(arrow_right,
- Vector(x_pos - list_pos + text_pos - 1 + list_pos_2, y_pos - 8),
- LAYER_GUI);
-
- /* Draw input background */
- context.draw_filled_rect(
+ case MN_STRINGSELECT:
+ {
+ int list_pos_2 = list_width + 16;
+ int list_pos = list_width/2;
+ int text_pos = (text_width + 16)/2;
+
+ /* Draw arrows */
+ context.draw_surface(arrow_left,
+ Vector(x_pos - list_pos + text_pos - 17, y_pos - 8),
+ LAYER_GUI);
+ context.draw_surface(arrow_right,
+ Vector(x_pos - list_pos + text_pos - 1 + list_pos_2, y_pos - 8),
+ LAYER_GUI);
+
+ /* Draw input background */
+ context.draw_filled_rect(
Vector(x_pos - list_pos + text_pos - 1, y_pos - 10),
Vector(list_pos_2 + 2, 20),
Color(255,255,255,255), LAYER_GUI - 4);
- context.draw_filled_rect(
+ context.draw_filled_rect(
Vector(x_pos - list_pos + text_pos, y_pos - 9),
Vector(list_pos_2, 18),
Color(0,0,0,128), LAYER_GUI - 5);
- context.draw_text_center(text_font, string_list_active(pitem.list),
- Vector(text_pos, y_pos - int(text_font->get_height()/2)),
- LAYER_GUI);
- context.draw_text_center(text_font, pitem.text,
- Vector(list_pos_2/2, y_pos - int(text_font->get_height()/2)),
- LAYER_GUI);
- break;
- }
- case MN_BACK:
- {
+ context.draw_text_center(text_font, string_list_active(pitem.list),
+ Vector(text_pos, y_pos - int(text_font->get_height()/2)),
+ LAYER_GUI);
+ context.draw_text_center(text_font, pitem.text,
+ Vector(list_pos_2/2, y_pos - int(text_font->get_height()/2)),
+ LAYER_GUI);
+ break;
+ }
+ case MN_BACK:
+ {
+ context.draw_text_center(text_font, pitem.text,
+ Vector(0, y_pos - int(text_font->get_height()/2)),
+ LAYER_GUI);
+ context.draw_surface(back,
+ Vector(x_pos + text_width/2 + 16, y_pos - 8),
+ LAYER_GUI);
+ break;
+ }
+
+ case MN_TOGGLE:
+ {
+ context.draw_text_center(text_font, pitem.text,
+ Vector(0, y_pos - (text_font->get_height()/2)),
+ LAYER_GUI);
+
+ if(pitem.toggled)
+ context.draw_surface(checkbox_checked,
+ Vector(x_pos + (text_width+16)/2, y_pos - 8),
+ LAYER_GUI + 1);
+ else
+ context.draw_surface(checkbox,
+ Vector(x_pos + (text_width+16)/2, y_pos - 8),
+ LAYER_GUI + 1);
+ break;
+ }
+ case MN_ACTION:
context.draw_text_center(text_font, pitem.text,
- Vector(0, y_pos - int(text_font->get_height()/2)),
- LAYER_GUI);
- context.draw_surface(back,
- Vector(x_pos + text_width/2 + 16, y_pos - 8),
- LAYER_GUI);
+ Vector(0, y_pos - int(text_font->get_height()/2)),
+ LAYER_GUI);
break;
- }
- case MN_TOGGLE:
- {
+ case MN_GOTO:
context.draw_text_center(text_font, pitem.text,
- Vector(0, y_pos - (text_font->get_height()/2)),
- LAYER_GUI);
-
- if(pitem.toggled)
- context.draw_surface(checkbox_checked,
- Vector(x_pos + (text_width+16)/2, y_pos - 8),
- LAYER_GUI + 1);
- else
- context.draw_surface(checkbox,
- Vector(x_pos + (text_width+16)/2, y_pos - 8),
- LAYER_GUI + 1);
+ Vector(0, y_pos - int(text_font->get_height()/2)),
+ LAYER_GUI);
break;
}
- case MN_ACTION:
- context.draw_text_center(text_font, pitem.text,
- Vector(0, y_pos - int(text_font->get_height()/2)),
- LAYER_GUI);
- break;
-
- case MN_GOTO:
- context.draw_text_center(text_font, pitem.text,
- Vector(0, y_pos - int(text_font->get_height()/2)),
- LAYER_GUI);
- break;
- }
}
int Menu::get_width() const
-{
- /* The width of the menu has to be more than the width of the text
- with the most characters */
- int menu_width = 0;
- for(unsigned int i = 0; i < item.size(); ++i)
{
- int w = strlen(item[i].text) + (item[i].input ? strlen(item[i].input) + 1 : 0) + strlen(string_list_active(item[i].list));
- if( w > menu_width )
- {
- menu_width = w;
- if( item[i].kind == MN_TOGGLE)
- menu_width += 2;
- }
- }
+ /* The width of the menu has to be more than the width of the text
+ with the most characters */
+ int menu_width = 0;
+ for(unsigned int i = 0; i < item.size(); ++i)
+ {
+ int w = strlen(item[i].text) + (item[i].input ? strlen(item[i].input) + 1 : 0) + strlen(string_list_active(item[i].list));
+ if( w > menu_width )
+ {
+ menu_width = w;
+ if( item[i].kind == MN_TOGGLE)
+ menu_width += 2;
+ }
+ }
- return (menu_width * 16 + 24);
-}
+ return (menu_width * 16 + 24);
+ }
int Menu::get_height() const
-{
- return item.size() * 24;
-}
+ {
+ return item.size() * 24;
+ }
/* Draw the current menu. */
void
/* Draw a transparent background */
context.draw_filled_rect(
- Vector(pos_x - menu_width/2, pos_y - 24*item.size()/2 - 10),
- Vector(menu_width,menu_height + 20),
- Color(150,180,200,125), LAYER_GUI-10);
+ Vector(pos_x - menu_width/2, pos_y - 24*item.size()/2 - 10),
+ Vector(menu_width,menu_height + 20),
+ Color(150,180,200,125), LAYER_GUI-10);
for(unsigned int i = 0; i < item.size(); ++i)
- {
- draw_item(context, i, menu_width, menu_height);
- }
+ {
+ draw_item(context, i, menu_width, menu_height);
+ }
}
MenuItem&
Menu::get_item_by_id(int id)
{
for(std::vector<MenuItem>::iterator i = item.begin(); i != item.end(); ++i)
- {
- if(i->id == id)
- return *i;
- }
+ {
+ if(i->id == id)
+ return *i;
+ }
assert(false);
static MenuItem dummyitem;
}
}
break;
-
+
case SDL_JOYAXISMOTION:
if(event.jaxis.axis == joystick_keymap.y_axis)
{
case SDL_JOYBUTTONDOWN:
if (item[active_item].kind == MN_CONTROLFIELD_JS)
{
- // FIXME: This next line does nothing useable, right?
+ // FIXME: This next line does nothing useable, right?
// *item[active_item].int_p = key;
menuaction = MENU_ACTION_DOWN;
}
int y = event.motion.y;
if(x > pos_x - get_width()/2 &&
- x < pos_x + get_width()/2 &&
- y > pos_y - get_height()/2 &&
- y < pos_y + get_height()/2)
+ x < pos_x + get_width()/2 &&
+ y > pos_y - get_height()/2 &&
+ y < pos_y + get_height()/2)
{
menuaction = MENU_ACTION_HIT;
}
int y = event.motion.y;
if(x > pos_x - get_width()/2 &&
- x < pos_x + get_width()/2 &&
- y > pos_y - get_height()/2 &&
- y < pos_y + get_height()/2)
+ x < pos_x + get_width()/2 &&
+ y > pos_y - get_height()/2 &&
+ y < pos_y + get_height()/2)
{
active_item = (y - (pos_y - get_height()/2)) / 24;
mouse_cursor->set_state(MC_LINK);
#include "audio/sound_manager.h"
#include "app/setup.h"
#include "door.h"
+#include "gui/button.h"
Surface* img_waves[3];
Surface* img_water;
"/sounds/explosion.wav"
};
+
+Font* gold_text;
+Font* blue_text;
+Font* gray_text;
+Font* yellow_nums;
+Font* white_text;
+Font* white_small_text;
+Font* white_big_text;
+
/* Load graphics/sounds shared between all levels: */
void loadshared()
{
+
+ /* Load global images: */
+ gold_text = new Font(datadir + "/images/fonts/gold.png", Font::TEXT, 16,18);
+ blue_text = new Font(datadir + "/images/fonts/blue.png", Font::TEXT, 16,18,3);
+ white_text = new Font(datadir + "/images/fonts/white.png",
+ Font::TEXT, 16,18);
+ gray_text = new Font(datadir + "/images/fonts/gray.png",
+ Font::TEXT, 16,18);
+ white_small_text = new Font(datadir + "/images/fonts/white-small.png",
+ Font::TEXT, 8,9, 1);
+ white_big_text = new Font(datadir + "/images/fonts/white-big.png",
+ Font::TEXT, 20,22, 3);
+ yellow_nums = new Font(datadir + "/images/fonts/numbers.png",
+ Font::NUM, 32,32);
+
+ Menu::default_font = white_text;
+ Menu::active_font = blue_text;
+ Menu::deactive_font = gray_text;
+ Menu::label_font = white_big_text;
+ Menu::field_font = gold_text;
+
+ Button::info_font = white_small_text;
+
int i;
sprite_manager = new SpriteManager(datadir + "/supertux.strf");
char img_name[1024];
for (int i = 0; i < GROWING_FRAMES; i++)
- {
- sprintf(img_name, "%s/images/shared/tux-grow-left-%i.png", datadir.c_str(), i+1);
- growingtux_left[i] = new Surface(img_name, false);
+ {
+ sprintf(img_name, "%s/images/shared/tux-grow-left-%i.png", datadir.c_str(), i+1);
+ growingtux_left[i] = new Surface(img_name, false);
- sprintf(img_name, "%s/images/shared/tux-grow-right-%i.png", datadir.c_str(), i+1);
- growingtux_right[i] = new Surface(img_name, false);
- }
+ sprintf(img_name, "%s/images/shared/tux-grow-right-%i.png", datadir.c_str(), i+1);
+ growingtux_right[i] = new Surface(img_name, false);
+ }
smalltux.stand_left = sprite_manager->load("smalltux-stand-left");
smalltux.stand_right = sprite_manager->load("smalltux-stand-right");
img_water = new Surface(datadir + "/images/shared/water.png", false);
img_waves[0] = new Surface(datadir + "/images/shared/waves-0.png",
- true);
+ true);
img_waves[1] = new Surface(datadir + "/images/shared/waves-1.png",
- true);
+ true);
img_waves[2] = new Surface(datadir + "/images/shared/waves-2.png",
- true);
+ true);
/* Pole: */
img_pole = new Surface(datadir + "/images/shared/pole.png", true);
img_poletop = new Surface(datadir + "/images/shared/poletop.png",
- true);
+ true);
/* Flag: */
img_flag[0] = new Surface(datadir + "/images/shared/flag-0.png",
- true);
+ true);
img_flag[1] = new Surface(datadir + "/images/shared/flag-1.png",
- true);
+ true);
/* Cloud: */
img_cloud[0][0] = new Surface(datadir + "/images/shared/cloud-00.png",
- true);
+ true);
img_cloud[0][1] = new Surface(datadir + "/images/shared/cloud-01.png",
- true);
+ true);
img_cloud[0][2] = new Surface(datadir + "/images/shared/cloud-02.png",
- true);
+ true);
img_cloud[0][3] = new Surface(datadir + "/images/shared/cloud-03.png",
- true);
+ true);
img_cloud[1][0] = new Surface(datadir + "/images/shared/cloud-10.png",
- true);
+ true);
img_cloud[1][1] = new Surface(datadir + "/images/shared/cloud-11.png",
- true);
+ true);
img_cloud[1][2] = new Surface(datadir + "/images/shared/cloud-12.png",
- true);
+ true);
img_cloud[1][3] = new Surface(datadir + "/images/shared/cloud-13.png",
- true);
+ true);
/* Bad guys: */
door = sprite_manager->load("door");
for (int i = 0; i < DOOR_OPENING_FRAMES; i++)
{
- sprintf(img_name, "%s/images/shared/door-%i.png", datadir.c_str(), i+1);
- door_opening[i] = new Surface(img_name, false);
+ sprintf(img_name, "%s/images/shared/door-%i.png", datadir.c_str(), i+1);
+ door_opening[i] = new Surface(img_name, false);
}
/* Distros: */
img_distro[0] = new Surface(datadir + "/images/tilesets/coin1.png",
- true);
+ true);
img_distro[1] = new Surface(datadir + "/images/tilesets/coin2.png",
- true);
+ true);
img_distro[2] = new Surface(datadir + "/images/tilesets/coin3.png",
- true);
+ true);
img_distro[3] = new Surface(datadir + "/images/tilesets/coin2.png",
- true);
+ true);
/* Tux life: */
Send a mail to me: neoneurone@users.sf.net, if you have another opinion. :)
*/
for (i = 0; i < NUM_SOUNDS; i++)
- SoundManager::get()->add_sound(SoundManager::get()->load_sound(datadir + soundfilenames[i]),i);
+ SoundManager::get
+ ()->add_sound(SoundManager::get
+ ()->load_sound(datadir + soundfilenames[i]),i);
/* Herring song */
- herring_song = SoundManager::get()->load_music(datadir + "/music/SALCON.MOD");
- level_end_song = SoundManager::get()->load_music(datadir + "/music/leveldone.mod");
+ herring_song = SoundManager::get
+ ()->load_music(datadir + "/music/SALCON.MOD");
+ level_end_song = SoundManager::get
+ ()->load_music(datadir + "/music/leveldone.mod");
}
-
/* Free shared data: */
void unloadshared(void)
{
+ /* Free global images: */
+ delete gold_text;
+ delete white_text;
+ delete blue_text;
+ delete gray_text;
+ delete white_small_text;
+ delete white_big_text;
+ delete yellow_nums;
+
int i;
free_special_gfx();