Added a function to draw text on center of screen for comodity.
[supertux.git] / lib / gui / menu.cpp
index ddddbb7..862b613 100644 (file)
@@ -531,9 +531,9 @@ Menu::draw_item(DrawingContext& context,
     {
     case MN_DEACTIVE:
       {
-        context.draw_text_center(deactive_font, pitem.text,
-                                 Vector(0, y_pos - int(deactive_font->get_height()/2)),
-                                 LAYER_GUI);
+        context.draw_text(deactive_font, pitem.text,
+                          Vector(screen->w/2, y_pos - int(deactive_font->get_height()/2)),
+                          CENTER_ALLIGN, LAYER_GUI);
         break;
       }
 
@@ -551,9 +551,9 @@ Menu::draw_item(DrawingContext& context,
       }
     case MN_LABEL:
       {
-        context.draw_text_center(label_font,
-                                 pitem.text, Vector(0, y_pos - int(label_font->get_height()/2)),
-                                 LAYER_GUI);
+        context.draw_text(label_font, pitem.text,
+                          Vector(screen->w/2, y_pos - int(label_font->get_height()/2)),
+                          CENTER_ALLIGN, LAYER_GUI);
         break;
       }
     case MN_TEXTFIELD:
@@ -585,21 +585,21 @@ Menu::draw_item(DrawingContext& context,
               context.draw_text(field_font,
                                 pitem.get_input_with_symbol(true),
                                 Vector(input_pos, y_pos - int(field_font->get_height()/2)),
-                                LAYER_GUI);
+                                LEFT_ALLIGN, 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);
+                                LEFT_ALLIGN, LAYER_GUI);
           }
         else
           context.draw_text(field_font, pitem.input,
                             Vector(input_pos, y_pos - int(field_font->get_height()/2)),
-                            LAYER_GUI);
+                            LEFT_ALLIGN, LAYER_GUI);
 
         context.draw_text(text_font, pitem.text,
                           Vector(text_pos, y_pos - int(text_font->get_height()/2)),
-                          LAYER_GUI);
+                          LEFT_ALLIGN, LAYER_GUI);
         break;
       }
     case MN_STRINGSELECT:
@@ -626,19 +626,19 @@ Menu::draw_item(DrawingContext& context,
           Vector(list_pos_2, 18),
           Color(0,0,0,128), LAYER_GUI - 5);
 
-        context.draw_text_center(text_font, (*pitem.list.second),
-                                 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);
+        context.draw_text(text_font, (*pitem.list.second),
+                                 Vector(screen->w/2 + text_pos, y_pos - int(text_font->get_height()/2)),
+                                 CENTER_ALLIGN, LAYER_GUI);
+        context.draw_text(text_font, pitem.text,
+                                 Vector(screen->w/2  + list_pos_2/2, y_pos - int(text_font->get_height()/2)),
+                                 CENTER_ALLIGN, 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_text(text_font, pitem.text,
+                          Vector(screen->w/2, y_pos - int(text_font->get_height()/2)),
+                          CENTER_ALLIGN, LAYER_GUI);
         context.draw_surface(back,
                              Vector(x_pos + text_width/2  + 16, y_pos - 8),
                              LAYER_GUI);
@@ -647,9 +647,9 @@ Menu::draw_item(DrawingContext& context,
 
     case MN_TOGGLE:
       {
-        context.draw_text_center(text_font, pitem.text,
-                                 Vector(0, y_pos - (text_font->get_height()/2)),
-                                 LAYER_GUI);
+        context.draw_text(text_font, pitem.text,
+                          Vector(screen->w/2, y_pos - (text_font->get_height()/2)),
+                          CENTER_ALLIGN, LAYER_GUI);
 
         if(pitem.toggled)
           context.draw_surface(checkbox_checked,
@@ -662,15 +662,15 @@ Menu::draw_item(DrawingContext& context,
         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_text(text_font, pitem.text,
+                        Vector(screen->w/2, y_pos - int(text_font->get_height()/2)),
+                        CENTER_ALLIGN, 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);
+      context.draw_text(text_font, pitem.text,
+                        Vector(screen->w/2, y_pos - int(text_font->get_height()/2)),
+                        CENTER_ALLIGN, LAYER_GUI);
       break;
     }
 }
@@ -846,6 +846,13 @@ Menu::event(SDL_Event& event)
             joystick_timer.stop();
         }
       break;
+    case SDL_JOYHATMOTION:
+      if(event.jhat.value & SDL_HAT_UP) {
+          menuaction = MENU_ACTION_UP;
+      } else if(event.jhat.value & SDL_HAT_DOWN) {
+          menuaction = MENU_ACTION_DOWN;
+      }
+      break;
     case  SDL_JOYBUTTONDOWN:
       if (item.size() > 0 && item[active_item].kind == MN_CONTROLFIELD_JS)
         {