removed title from main menu
[supertux.git] / src / menu.cpp
index a534fa6..f8bfbf1 100644 (file)
 #include "high_scores.h"
 
 /* (global) menu variables */
-int menuaction;
-int show_menu;
-int menu_change;
+MenuAction menuaction = MENU_ACTION_NONE;
+bool show_menu;
+bool menu_change;
 texture_type checkbox, checkbox_checked, back, arrow_left, arrow_right;
 
-menu_type main_menu, game_menu, options_menu, highscore_menu, load_game_menu, save_game_menu;
-menu_type* current_menu, * last_menu;
+Menu* main_menu      = 0;
+Menu* game_menu      = 0;
+Menu* options_menu   = 0;
+Menu* options_controls_menu   = 0;
+Menu* highscore_menu = 0;
+Menu* load_game_menu = 0;
+Menu* save_game_menu = 0;
+
+Menu* current_menu = 0;
 
 /* input implementation variables */
 int delete_character;
 char mn_input_char;
 
 /* Set the current menu */
-void menu_set_current(menu_type* pmenu)
+void
+Menu::set_current(Menu* pmenu)
 {
   if(pmenu != current_menu)
     {
-      menu_change = YES;
-      last_menu = current_menu;
+      menu_change  = true;
+      Menu* tmp = current_menu;
       current_menu = pmenu;
+      if(tmp)
+        if(tmp->last_menu != pmenu)
+          current_menu->last_menu = tmp;
+
       timer_start(&pmenu->effect, 500);
     }
 }
 
 /* Return a pointer to a new menu item */
-menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, void* target_menu)
+menu_item_type* menu_item_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;
@@ -65,7 +77,7 @@ menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle,
   if(kind == MN_TOGGLE)
     pnew_item->toggled = init_toggle;
   else
-    pnew_item->toggled = NO;
+    pnew_item->toggled = false;
   pnew_item->target_menu = target_menu;
   pnew_item->input = (char*) malloc(sizeof(char));
   pnew_item->input[0] = '\0';
@@ -99,158 +111,205 @@ void menu_item_change_input(menu_item_type* pmenu_item,const  char *text)
 }
 
 /* Free a menu and all its items */
-void menu_free(menu_type* pmenu)
+Menu::~Menu()
 {
-  int i;
-  if(pmenu->num_items != 0 && pmenu->item != NULL)
+  if(num_items != 0 && item != NULL)
     {
-      for(i = 0; i < pmenu->num_items; ++i)
+      for(int i = 0; i < num_items; ++i)
         {
-          free(pmenu->item[i].text);
-          free(pmenu->item[i].input);
-          string_list_free(pmenu->item[i].list);
+          free(item[i].text);
+          free(item[i].input);
+          string_list_free(item[i].list);
         }
-      free(pmenu->item);
+      free(item);
     }
 }
 
-/* Initialize a menu */
-void menu_init(menu_type* pmenu)
+Menu::Menu()
 {
-  pmenu->arrange_left = 0;
-  pmenu->num_items = 0;
-  pmenu->active_item = 0;
-  pmenu->item = NULL;
-  timer_init(&pmenu->effect,NO);
+  pos_x        = screen->w/2;
+  pos_y        = screen->h/2;
+  last_menu    = 0;
+  arrange_left = 0;
+  num_items    = 0;
+  active_item  = 0;
+  last_menu    = 0;
+  item         = NULL;
+  timer_init(&effect,false);
+}
+
+void Menu::set_pos(int x, int y, float rw, float rh)
+{
+ pos_x = x + (int)((float)width() * rw);
+ pos_y = y + (int)((float)height() * rh);
+}
+
+void
+Menu::additem(MenuItemKind kind, char *text, int toggle, Menu* menu)
+{
+  additem(menu_item_create(kind, text, toggle, menu));
 }
 
 /* Add an item to a menu */
-void menu_additem(menu_type* pmenu, menu_item_type* pmenu_item)
+void
+Menu::additem(menu_item_type* pmenu_item)
 {
-  ++pmenu->num_items;
-  pmenu->item = (menu_item_type*) realloc(pmenu->item, sizeof(menu_item_type) * pmenu->num_items);
-  memcpy(&pmenu->item[pmenu->num_items-1],pmenu_item,sizeof(menu_item_type));
+  ++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));
   free(pmenu_item);
 }
 
 /* Process actions done on the menu */
-void menu_action(menu_type* pmenu)
+void
+Menu::action()
 {
-  int i;
-
-  if(pmenu->num_items != 0 && pmenu->item != NULL)
+  if(num_items != 0 && item != NULL)
     {
       switch(menuaction)
         {
-        case MN_UP:
-          if(pmenu->active_item > 0)
-            --pmenu->active_item;
+        case MENU_ACTION_UP:
+          if (active_item > 0)
+            --active_item;
           else
-            pmenu->active_item = pmenu->num_items-1;
+            active_item = num_items-1;
           break;
-        case MN_DOWN:
-          if(pmenu->active_item < pmenu->num_items-1)
-            ++pmenu->active_item;
+
+        case MENU_ACTION_DOWN:
+          if(active_item < num_items-1)
+            ++active_item;
           else
-            pmenu->active_item = 0;
+            active_item = 0;
           break;
-        case MN_LEFT:
-          if(pmenu->item[pmenu->active_item].kind == MN_STRINGSELECT && pmenu->item[pmenu->active_item].list->num_items != 0)
+
+        case MENU_ACTION_LEFT:
+          if(item[active_item].kind == MN_STRINGSELECT
+              && item[active_item].list->num_items != 0)
             {
-              if(pmenu->item[pmenu->active_item].list->active_item > 0)
-                --pmenu->item[pmenu->active_item].list->active_item;
+              if(item[active_item].list->active_item > 0)
+                --item[active_item].list->active_item;
               else
-                pmenu->item[pmenu->active_item].list->active_item = pmenu->item[pmenu->active_item].list->num_items-1;
+                item[active_item].list->active_item = item[active_item].list->num_items-1;
             }
           break;
-        case MN_RIGHT:
-          if(pmenu->item[pmenu->active_item].kind == MN_STRINGSELECT && pmenu->item[pmenu->active_item].list->num_items != 0)
+
+        case MENU_ACTION_RIGHT:
+          if(item[active_item].kind == MN_STRINGSELECT
+              && item[active_item].list->num_items != 0)
             {
-              if(pmenu->item[pmenu->active_item].list->active_item < pmenu->item[pmenu->active_item].list->num_items-1)
-                ++pmenu->item[pmenu->active_item].list->active_item;
+              if(item[active_item].list->active_item < item[active_item].list->num_items-1)
+                ++item[active_item].list->active_item;
               else
-                pmenu->item[pmenu->active_item].list->active_item = 0;
+                item[active_item].list->active_item = 0;
             }
           break;
-        case MN_HIT:
-          if(pmenu->item[pmenu->active_item].kind == MN_GOTO && pmenu->item[pmenu->active_item].target_menu != NULL)
-            menu_set_current((menu_type*)pmenu->item[pmenu->active_item].target_menu);
-          else if(pmenu->item[pmenu->active_item].kind == MN_TOGGLE)
-            {
-              pmenu->item[pmenu->active_item].toggled = !pmenu->item[pmenu->active_item].toggled;
-              menu_change = YES;
-            }
-          else if(pmenu->item[pmenu->active_item].kind == MN_ACTION || pmenu->item[pmenu->active_item].kind == MN_TEXTFIELD || pmenu->item[pmenu->active_item].kind == MN_NUMFIELD)
-            {
-              pmenu->item[pmenu->active_item].toggled = YES;
-            }
-          else if(pmenu->item[pmenu->active_item].kind == MN_BACK)
-            {
-              if(last_menu != NULL)
-                menu_set_current(last_menu);
-            }
+
+        case MENU_ACTION_HIT:
+          {
+            switch (item[active_item].kind)
+              {
+              case MN_GOTO:
+                if (item[active_item].target_menu != NULL)
+                  Menu::set_current(item[active_item].target_menu);
+                else
+                  puts("NULLL");
+                break;
+
+              case MN_TOGGLE:
+                item[active_item].toggled = !item[active_item].toggled;
+                menu_change = true;
+                break;
+
+              case MN_ACTION:
+              case MN_TEXTFIELD:
+              case MN_NUMFIELD:
+              case MN_CONTROLFIELD:
+                item[active_item].toggled = true;
+                break;
+
+              case MN_BACK:
+                if(last_menu != NULL)
+                  Menu::set_current(last_menu);
+                break;
+              default:
+                break;
+              }
+          }
           break;
-        case MN_REMOVE:
-          if(pmenu->item[pmenu->active_item].kind == MN_TEXTFIELD || pmenu->item[pmenu->active_item].kind == MN_NUMFIELD)
+
+        case MENU_ACTION_REMOVE:
+          if(item[active_item].kind == MN_TEXTFIELD
+              || item[active_item].kind == MN_NUMFIELD)
             {
-              if(pmenu->item[pmenu->active_item].input != NULL)
+              if(item[active_item].input != NULL)
                 {
-                  i = strlen(pmenu->item[pmenu->active_item].input);
+                  int i = strlen(item[active_item].input);
 
                   while(delete_character > 0)  /* remove charactes */
                     {
-                      pmenu->item[pmenu->active_item].input[i-1] = '\0';
+                      item[active_item].input[i-1] = '\0';
                       delete_character--;
                     }
                 }
             }
           break;
-        case MN_INPUT:
-          if(pmenu->item[pmenu->active_item].kind == MN_TEXTFIELD || (pmenu->item[pmenu->active_item].kind == MN_NUMFIELD && mn_input_char >= '0' && mn_input_char <= '9'))
+
+        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(pmenu->item[pmenu->active_item].input != NULL)
+              if(item[active_item].input != NULL)
                 {
-                  i = strlen(pmenu->item[pmenu->active_item].input);
-                  pmenu->item[pmenu->active_item].input = (char*) realloc(pmenu->item[pmenu->active_item].input,sizeof(char)*(i + 2));
-                  pmenu->item[pmenu->active_item].input[i] = mn_input_char;
-                  pmenu->item[pmenu->active_item].input[i+1] = '\0';
+                  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
                 {
-                  pmenu->item[pmenu->active_item].input = (char*) malloc(2*sizeof(char));
-                  pmenu->item[pmenu->active_item].input[0] = mn_input_char;
-                  pmenu->item[pmenu->active_item].input[1] = '\0';
+                  item[active_item].input = (char*) malloc(2*sizeof(char));
+                  item[active_item].input[0] = mn_input_char;
+                  item[active_item].input[1] = '\0';
                 }
             }
           break;
+
+        case MENU_ACTION_NONE:
+          break;
         }
     }
 
-  if(pmenu->item[pmenu->active_item].kind == MN_DEACTIVE || pmenu->item[pmenu->active_item].kind == MN_LABEL || pmenu->item[pmenu->active_item].kind == MN_HL)
+  menu_item_type& new_item = item[active_item];
+  if(new_item.kind == MN_DEACTIVE
+      || new_item.kind == MN_LABEL
+      || new_item.kind == MN_HL)
     {
-      if(menuaction != MN_UP && menuaction != MN_DOWN)
-        menuaction = MN_DOWN;
+      // Skip the horzontal line item
+      if(menuaction != MENU_ACTION_UP && menuaction != MENU_ACTION_DOWN)
+        menuaction = MENU_ACTION_DOWN;
 
-      if(pmenu->num_items > 1)
-        menu_action(pmenu);
+      if(num_items > 1)
+        action();
     }
-
 }
 
-/* Check, if the value of the active menu item has changed. */
-int menu_check(menu_type* pmenu)
+int
+Menu::check()
 {
-  if(pmenu->num_items != 0 && pmenu->item != NULL)
+  if(num_items != 0 && item != NULL)
     {
-      if((pmenu->item[pmenu->active_item].kind == MN_ACTION || pmenu->item[pmenu->active_item].kind == MN_TEXTFIELD || pmenu->item[pmenu->active_item].kind == MN_NUMFIELD) && pmenu->item[pmenu->active_item].toggled == YES)
+      if((item[active_item].kind == MN_ACTION
+          || item[active_item].kind == MN_TEXTFIELD
+          || item[active_item].kind == MN_NUMFIELD)
+          && item[active_item].toggled)
         {
-          pmenu->item[pmenu->active_item].toggled = NO;
+          item[active_item].toggled = false;
           show_menu = 0;
-          return pmenu->active_item;
+          return active_item;
         }
-      else if(pmenu->item[pmenu->active_item].kind == MN_TOGGLE || pmenu->item[pmenu->active_item].kind == MN_GOTO)
+      else if(item[active_item].kind == MN_TOGGLE || item[active_item].kind == MN_GOTO)
         {
-          return pmenu->active_item;
+          return active_item;
         }
       else
         return -1;
@@ -259,41 +318,36 @@ int menu_check(menu_type* pmenu)
     return -1;
 }
 
-void menu_draw_item(menu_type* pmenu, 
-                    int index, // Position of the current item in the menu
-                    int menu_width, 
-                    int menu_height)
+void
+Menu::draw_item(int index, // Position of the current item in the menu
+                int menu_width,
+                int menu_height)
 {
   int font_width  = 16;
 
-  const menu_item_type& pitem =  pmenu->item[index];
+  const menu_item_type& pitem =  item[index];
 
-  int x_pos = 0;
-  if(pmenu->arrange_left == YES)
-    x_pos = 24 - menu_width/2
-      + (font_width * (strlen(pitem.text) 
-               + strlen(pitem.input)
-               + strlen(string_list_active(pitem.list))))/2;
-      
   int effect_offset = 0;
   {
     int effect_time = 0;
-    if(timer_check(&pmenu->effect))
-      effect_time = timer_get_left(&pmenu->effect) / 4;
+    if(timer_check(&effect))
+      effect_time = timer_get_left(&effect) / 4;
 
     effect_offset = (index % 2) ? effect_time : -effect_time;
   }
 
-  int raw_y_pos  = 24*index - menu_height/2; 
-  int top        = raw_y_pos + effect_offset;
-  int bottom     = top + 10; // bottom of the menu item 
-
-  int start_x    = screen->w/2 + x_pos;
-  int cen_y_10_f = screen->h/2 + bottom;
-
+  int x_pos       = pos_x;
+  int y_pos       = pos_y + 24*index - menu_height/2 + 12 + effect_offset;
   int shadow_size = 2;
+  int text_width  = strlen(pitem.text) * font_width;
+  int input_width = strlen(pitem.input) * font_width;
+  int list_width  = strlen(string_list_active(pitem.list)) * font_width;
   text_type* text_font = &white_text;
-  if(index == pmenu->active_item)
+
+  if (arrange_left)
+    x_pos += 24 - menu_width/2 + (text_width + input_width + list_width)/2;
+
+  if(index == active_item)
     {
       shadow_size = 3;
       text_font = &blue_text;
@@ -303,260 +357,302 @@ void menu_draw_item(menu_type* pmenu,
     {
     case MN_DEACTIVE:
       {
-        text_drawf(&black_text, pitem.text, 
-                   x_pos, bottom,
-                   A_HMIDDLE, A_VMIDDLE, 2);
+        text_draw_align(&black_text, pitem.text,
+                        x_pos, y_pos,
+                        A_HMIDDLE, A_VMIDDLE, 2);
         break;
       }
 
     case MN_HL:
       {
-        int x = screen->w/2 - menu_width/2; 
-        int y = screen->h/2 + raw_y_pos;
+        int x = pos_x - menu_width/2;
+        int y = y_pos - 12 - effect_offset;
         /* Draw a horizontal line with a little 3d effect */
         fillrect(x, y + 6,
                  menu_width, 4,
-                 210,50,50,225);
-        fillrect(x, y + 10 + 6, 
+                 150,200,255,225);
+        fillrect(x, y + 6,
                  menu_width, 2,
-                 0,0,0,255);
+                 255,255,255,255);
         break;
       }
     case MN_LABEL:
       {
-        text_drawf(&white_big_text, pitem.text, 
-                   x_pos, bottom,
-                   A_HMIDDLE, A_VMIDDLE, 2);
+        text_draw_align(&white_big_text, pitem.text,
+                        x_pos, y_pos,
+                        A_HMIDDLE, A_VMIDDLE, 2);
         break;
       }
     case MN_TEXTFIELD:
     case MN_NUMFIELD:
+    case MN_CONTROLFIELD:
       {
-        int input_pos = (strlen(pitem.input)*font_width)/2;
-        int text_pos  = (strlen(pitem.text)+1)*font_width/2;
+        int input_pos = input_width/2;
+        int text_pos  = (text_width + font_width)/2;
 
-        fillrect(start_x - input_pos + text_pos - 1, cen_y_10_f - 10,
-                 (strlen(pitem.input)+1)*font_width + 2, 20,
+        fillrect(x_pos - input_pos + text_pos - 1, y_pos - 10,
+                 input_width + font_width + 2, 20,
                  255,255,255,255);
-        fillrect(start_x - input_pos + text_pos, cen_y_10_f - 9,
-                 (strlen(pitem.input)+1)*font_width, 18,
+        fillrect(x_pos - input_pos + text_pos, y_pos - 9,
+                 input_width + font_width, 18,
                  0,0,0,128);
 
-        text_drawf(&gold_text, pitem.input,
-                   x_pos + text_pos, bottom, 
-                   A_HMIDDLE, A_VMIDDLE, 2);
+        text_draw_align(&gold_text, pitem.input,
+                        x_pos + text_pos, y_pos,
+                        A_HMIDDLE, A_VMIDDLE, 2);
 
-        text_drawf(text_font, pitem.text, 
-                   x_pos - (((strlen(pitem.input)+1) * font_width)/2), bottom,
-                   A_HMIDDLE, A_VMIDDLE, shadow_size);
+        text_draw_align(text_font, pitem.text,
+                        x_pos - (input_width + font_width)/2, y_pos,
+                        A_HMIDDLE, A_VMIDDLE, shadow_size);
         break;
       }
     case MN_STRINGSELECT:
       {
-        int list_pos_2 = (strlen(string_list_active(pitem.list))+1)*font_width;
-        int list_pos   = (strlen(string_list_active(pitem.list))*font_width)/2;
-        int text_pos   = ((strlen(pitem.text) + 1)*font_width)/2;
+        int list_pos_2 = list_width + font_width;
+        int list_pos   = list_width/2;
+        int text_pos   = (text_width + font_width)/2;
 
         /* Draw arrows */
-        texture_draw(&arrow_left,  start_x - list_pos + text_pos - 17, cen_y_10_f - 8);
-        texture_draw(&arrow_right, start_x - list_pos + text_pos - 1 + list_pos_2, cen_y_10_f - 8);
+        texture_draw(&arrow_left,  x_pos - list_pos + text_pos - 17, y_pos - 8);
+        texture_draw(&arrow_right, x_pos - list_pos + text_pos - 1 + list_pos_2, y_pos - 8);
 
         /* Draw input background */
-        fillrect(start_x - list_pos + text_pos - 1, cen_y_10_f - 10,
+        fillrect(x_pos - list_pos + text_pos - 1, y_pos - 10,
                  list_pos_2 + 2, 20,
                  255,255,255,255);
-        fillrect(start_x - list_pos + text_pos, cen_y_10_f - 9,
+        fillrect(x_pos - list_pos + text_pos, y_pos - 9,
                  list_pos_2, 18,
                  0,0,0,128);
 
-        text_drawf(&gold_text, string_list_active(pitem.list), 
-                   x_pos + text_pos, bottom,
-                   A_HMIDDLE, A_VMIDDLE,2);
+        text_draw_align(&gold_text, string_list_active(pitem.list),
+                        x_pos + text_pos, y_pos,
+                        A_HMIDDLE, A_VMIDDLE,2);
 
-        text_drawf(text_font, pitem.text,
-                   x_pos - list_pos_2/2, bottom,
-                   A_HMIDDLE, A_VMIDDLE, shadow_size);
+        text_draw_align(text_font, pitem.text,
+                        x_pos - list_pos_2/2, y_pos,
+                        A_HMIDDLE, A_VMIDDLE, shadow_size);
         break;
       }
     case MN_BACK:
       {
-        texture_draw(&back, start_x + (strlen(pitem.text) * font_width)/2  + font_width, cen_y_10_f - 8);
+        text_draw_align(text_font, pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size);
+        texture_draw(&back, x_pos + text_width/2  + font_width, y_pos - 8);
         break;
       }
 
     case MN_TOGGLE:
       {
-        if(pitem.toggled == YES)
-          texture_draw(&checkbox_checked, start_x + (strlen(pitem.text) * font_width)/2 + font_width, cen_y_10_f - 8);
+        text_draw_align(text_font, pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size);
+
+        if(pitem.toggled)
+          texture_draw(&checkbox_checked,
+                       x_pos + (text_width+font_width)/2,
+                       y_pos - 8);
         else
-          texture_draw(&checkbox, start_x + (strlen(pitem.text) * font_width)/2 + font_width, cen_y_10_f - 8);
+          texture_draw(&checkbox,
+                       x_pos + (text_width+font_width)/2,
+                       y_pos - 8);
         break;
       }
     case MN_ACTION:
+      text_draw_align(text_font, pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size);
       break;
 
     case MN_GOTO:
-      break;
-    }
-
-  switch (pitem.kind)
-    {
-    case MN_ACTION:
-    case MN_GOTO:
-    case MN_TOGGLE:
-    case MN_BACK:
-      text_drawf(text_font, pitem.text, x_pos, bottom, A_HMIDDLE, A_VMIDDLE, shadow_size);
-      break;
-    case MN_DEACTIVE:
-    case MN_TEXTFIELD:
-    case MN_NUMFIELD:
-    case MN_STRINGSELECT:
-    case MN_LABEL:
-    case MN_HL:
+      text_draw_align(text_font, pitem.text, x_pos, y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size);
       break;
     }
 }
 
-/* Draw the current menu. */
-void menu_draw(menu_type* pmenu)
+int Menu::width()
 {
-  int y;
-  int menu_height;
-  int menu_width;
-  
-  /* The width of the menu has to be more than the width of the text with the most characters */
-  menu_width = 0;
-  for(int i = 0; i < pmenu->num_items; ++i)
+  /* The width of the menu has to be more than the width of the text
+     with the most characters */
+  int menu_width = 0;
+  for(int i = 0; i < num_items; ++i)
     {
-      y = strlen(pmenu->item[i].text) + (pmenu->item[i].input ? strlen(pmenu->item[i].input) + 1 : 0) + strlen(string_list_active(pmenu->item[i].list));
-      if( y > menu_width )
+      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 = y;
-          if( pmenu->item[i].kind == MN_TOGGLE)
+          menu_width = w;
+          if( item[i].kind == MN_TOGGLE)
             menu_width += 2;
         }
     }
 
-  menu_width  = menu_width * 16 + 48;
-  menu_height = (pmenu->num_items) * 24;
+  return (menu_width * 16 + 48);
+}
+
+int Menu::height()
+{
+  return ((num_items) * 24);
+}
+
+/* Draw the current menu. */
+void
+Menu::draw()
+{
+  int menu_height = height();
+  int menu_width = width();
 
-  int center_x = screen->w/2;
   /* Draw a transparent background */
-  fillrect(center_x - menu_width/2,screen->h/2-(((pmenu->num_items)*24)/2),menu_width,menu_height,150,150,150,100);
+  fillrect(pos_x - menu_width/2,
+           pos_y - 24*num_items/2,
+           menu_width,menu_height,
+           150,180,200,100);
 
-  for(int i = 0; i < pmenu->num_items; ++i)
+  for(int i = 0; i < num_items; ++i)
     {
-      menu_draw_item(pmenu, i, menu_width, menu_height);
+      draw_item(i, menu_width, menu_height);
     }
 }
 
 /* Reset/Set global defaults */
 void menu_reset(void)
 {
-  menu_change = NO;
-  show_menu = NO;
-  menuaction = -1;
+  menu_change  = false;
+  show_menu    = false;
+  menuaction   = MENU_ACTION_NONE;
   current_menu = NULL;
-  last_menu = NULL;
 
   delete_character = 0;
-  mn_input_char = '\0';
+  mn_input_char    = '\0';
 }
 
 /* --- MENU --- */
 /* Draw the current menu and execute the (menu)events */
 void menu_process_current(void)
 {
-  menu_change = NO;
+  menu_change = false;
 
   if(current_menu != NULL)
     {
-      menu_action(current_menu);
-      menu_draw(current_menu);
+      current_menu->action();
+      current_menu->draw();
     }
 
-  menuaction = -1;
+  menuaction = MENU_ACTION_NONE;
 }
 
 /* Check for menu event */
-void menu_event(SDL_keysym* keysym)
+void menu_event(SDL_Event& event)
 {
-  SDLKey key = keysym->sym;
-  SDLMod keymod;
-  char ch[2];
-  keymod = SDL_GetModState();
-
-  /* If the current unicode character is an ASCII character,
-     assign it to ch. */
-  if ( (keysym->unicode & 0xFF80) == 0 )
+  SDLKey key;
+  switch(event.type)
     {
-      ch[0] = keysym->unicode & 0x7F;
-      ch[1] = '\0';
-    }
-  else
-    {
-      /* An International Character. */
-    }
+    case SDL_KEYDOWN:
+      key = event.key.keysym.sym;
+      SDLMod keymod;
+      char ch[2];
+      keymod = SDL_GetModState();
+      int x,y;
+
+      /* If the current unicode character is an ASCII character,
+         assign it to ch. */
+      if ( (event.key.keysym.unicode & 0xFF80) == 0 )
+        {
+          ch[0] = event.key.keysym.unicode & 0x7F;
+          ch[1] = '\0';
+        }
+      else
+        {
+          /* An International Character. */
+        }
 
-  switch(key)
-    {
-    case SDLK_UP:              /* Menu Up */
-      menuaction = MN_UP;
-      menu_change = YES;
-      break;
-    case SDLK_DOWN:            /* Menu Down */
-      menuaction = MN_DOWN;
-      menu_change = YES;
-      break;
-    case SDLK_LEFT:            /* Menu Up */
-      menuaction = MN_LEFT;
-      menu_change = YES;
-      break;
-    case SDLK_RIGHT:           /* Menu Down */
-      menuaction = MN_RIGHT;
-      menu_change = YES;
-      break;
-    case SDLK_SPACE:
-      if(current_menu->item[current_menu->active_item].kind == MN_TEXTFIELD)
-      {
-      menuaction = MN_INPUT;
-      menu_change = YES;
-      mn_input_char = ' ';
+      switch(key)
+        {
+        case SDLK_UP:          /* Menu Up */
+          menuaction = MENU_ACTION_UP;
+          menu_change = true;
+          break;
+        case SDLK_DOWN:                /* Menu Down */
+          menuaction = MENU_ACTION_DOWN;
+          menu_change = true;
+          break;
+        case SDLK_LEFT:                /* Menu Up */
+          menuaction = MENU_ACTION_LEFT;
+          menu_change = true;
+          break;
+        case SDLK_RIGHT:               /* Menu Down */
+          menuaction = MENU_ACTION_RIGHT;
+          menu_change = true;
+          break;
+        case SDLK_SPACE:
+          if(current_menu->item[current_menu->active_item].kind == MN_TEXTFIELD)
+            {
+              menuaction = MENU_ACTION_INPUT;
+              menu_change = true;
+              mn_input_char = ' ';
+              break;
+            }
+        case SDLK_RETURN: /* Menu Hit */
+          menuaction = MENU_ACTION_HIT;
+          menu_change = true;
+          break;
+        case SDLK_DELETE:
+        case SDLK_BACKSPACE:
+          menuaction = MENU_ACTION_REMOVE;
+          menu_change = true;
+          delete_character++;
+          break;
+        default:
+          if( (key >= SDLK_0 && key <= SDLK_9) || (key >= SDLK_a && key <= SDLK_z) || (key >= SDLK_SPACE && key <= SDLK_SLASH))
+            {
+              menuaction = MENU_ACTION_INPUT;
+              menu_change = true;
+              mn_input_char = *ch;
+            }
+          else
+            {
+              mn_input_char = '\0';
+            }
+          break;
+        }
       break;
-      }
-    case SDLK_RETURN: /* Menu Hit */
-      menuaction = MN_HIT;
-      menu_change = YES;
+    case  SDL_JOYAXISMOTION:
+      if(event.jaxis.axis == JOY_Y)
+        {
+          if (event.jaxis.value > 1024)
+            menuaction = MENU_ACTION_DOWN;
+          else if (event.jaxis.value < -1024)
+            menuaction = MENU_ACTION_UP;
+        }
       break;
-    case SDLK_DELETE:
-    case SDLK_BACKSPACE:
-      menuaction = MN_REMOVE;
-      menu_change = YES;
-      delete_character++;
+    case  SDL_JOYBUTTONDOWN:
+      menuaction = MENU_ACTION_HIT;
       break;
-    default:
-      if( (key >= SDLK_0 && key <= SDLK_9) || (key >= SDLK_a && key <= SDLK_z) || (key >= SDLK_SPACE && key <= SDLK_SLASH))
+    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)
         {
-          menuaction = MN_INPUT;
-          menu_change = YES;
-          mn_input_char = *ch;
+          menuaction = MENU_ACTION_HIT;
         }
-      else
+      break;
+    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)
         {
-          mn_input_char = '\0';
+          current_menu->active_item = (y - (current_menu->pos_y - current_menu->height()/2)) / 24;
+          menu_change = true;
+         mouse_cursor->set_state(MC_LINK);
         }
+       else
+       {
+         mouse_cursor->set_state(MC_NORMAL);
+       }
+      break;
+    default:
       break;
     }
-
-
-  /* FIXME: NO JOYSTICK SUPPORT */
-  /*#ifdef JOY_YES
-  else if (event.type == SDL_JOYBUTTONDOWN)
-   {
-      Joystick button: Continue:
-
-     done = 1;
-   }
-  #endif*/
 }
 
+
+// EOF //