Changed behavior of centered text drawing and added right allignment, as well.
authorRicardo Cruz <rick2@aeiou.pt>
Thu, 16 Sep 2004 15:04:18 +0000 (15:04 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Thu, 16 Sep 2004 15:04:18 +0000 (15:04 +0000)
Added a new allignment argument for draw_text(). draw_text_center() is draw_text() with CENTER_ALLIGN in point Vector(screen->w/2, ...).

SVN-Revision: 1927

13 files changed:
lib/gui/button.cpp
lib/gui/menu.cpp
lib/video/drawing_context.cpp
lib/video/drawing_context.h
lib/video/font.cpp
lib/video/font.h
src/gameloop.cpp
src/gameobjs.cpp
src/high_scores.cpp
src/leveleditor.cpp
src/statistics.cpp
src/title.cpp
src/worldmap.cpp

index 7b02985..170e003 100644 (file)
@@ -126,9 +126,9 @@ void Button::draw(DrawingContext& context)
         i = rect.w + (int)info_font->get_text_width(info);
 
       if(!info.empty())
         i = rect.w + (int)info_font->get_text_width(info);
 
       if(!info.empty())
-        context.draw_text(info_font, info, Vector(i + rect.x - info_font->get_text_width(info), rect.y), LAYER_GUI);
+        context.draw_text(info_font, info, Vector(i + rect.x - info_font->get_text_width(info), rect.y), LEFT_ALLIGN, LAYER_GUI);
       sprintf(str,"(%s)", SDL_GetKeyName(shortcut));
       sprintf(str,"(%s)", SDL_GetKeyName(shortcut));
-      context.draw_text(info_font, str, Vector(i + rect.x -  info_font->get_text_width(str), rect.y + info_font->get_height()+2), LAYER_GUI);
+      context.draw_text(info_font, str, Vector(i + rect.x -  info_font->get_text_width(str), rect.y + info_font->get_height()+2), LEFT_ALLIGN, LAYER_GUI);
     }
   if(state == BUTTON_PRESSED || state == BUTTON_DEACTIVE)
     fillrect(rect.x,rect.y,rect.w,rect.h,75,75,75,200);
     }
   if(state == BUTTON_PRESSED || state == BUTTON_DEACTIVE)
     fillrect(rect.x,rect.y,rect.w,rect.h,75,75,75,200);
index fcd60a4..862b613 100644 (file)
@@ -531,9 +531,9 @@ Menu::draw_item(DrawingContext& context,
     {
     case MN_DEACTIVE:
       {
     {
     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;
       }
 
         break;
       }
 
@@ -551,9 +551,9 @@ Menu::draw_item(DrawingContext& context,
       }
     case MN_LABEL:
       {
       }
     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:
         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)),
               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)),
             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)),
           }
         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)),
 
         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:
         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);
 
           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:
       {
         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);
         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:
       {
 
     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,
 
         if(pitem.toggled)
           context.draw_surface(checkbox_checked,
@@ -662,15 +662,15 @@ Menu::draw_item(DrawingContext& context,
         break;
       }
     case MN_ACTION:
         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:
       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;
     }
 }
       break;
     }
 }
index 0019ff5..693191c 100644 (file)
@@ -78,7 +78,8 @@ DrawingContext::draw_surface_part(const Surface* surface, const Vector& source,
 
 void
 DrawingContext::draw_text(Font* font, const std::string& text,
 
 void
 DrawingContext::draw_text(Font* font, const std::string& text,
-    const Vector& position, int layer, Uint32 drawing_effect, int alpha)
+    const Vector& position, int allignment, int layer,
+    Uint32 drawing_effect, int alpha)
 {
   DrawingRequest request;
 
 {
   DrawingRequest request;
 
@@ -90,28 +91,7 @@ DrawingContext::draw_text(Font* font, const std::string& text,
   TextRequest* textrequest = new TextRequest;
   textrequest->font = font;
   textrequest->text = text;
   TextRequest* textrequest = new TextRequest;
   textrequest->font = font;
   textrequest->text = text;
-  textrequest->center = false;
-  textrequest->alpha = alpha;
-  request.request_data = textrequest;
-
-  drawingrequests.push_back(request);
-}
-
-void
-DrawingContext::draw_text_center(Font* font, const std::string& text,
-    const Vector& position, int layer, Uint32 drawing_effect, int alpha)
-{
-  DrawingRequest request;
-
-  request.type = TEXT;
-  request.layer = layer;
-  request.pos = transform.apply(position);
-  request.drawing_effect = drawing_effect;
-
-  TextRequest* textrequest = new TextRequest;
-  textrequest->font = font;
-  textrequest->text = text;
-  textrequest->center = true;
+  textrequest->allignment = allignment;
   textrequest->alpha = alpha;
   request.request_data = textrequest;
 
   textrequest->alpha = alpha;
   request.request_data = textrequest;
 
@@ -219,10 +199,7 @@ DrawingContext::draw_text(DrawingRequest& request)
 {
   TextRequest* textrequest = (TextRequest*) request.request_data;
 
 {
   TextRequest* textrequest = (TextRequest*) request.request_data;
 
-  if(textrequest->center)
-    textrequest->font->draw_center(textrequest->text, request.pos, request.drawing_effect, textrequest->alpha);
-  else
-    textrequest->font->draw(textrequest->text, request.pos, request.drawing_effect, textrequest->alpha);
+  textrequest->font->draw(textrequest->text, request.pos, textrequest->allignment, request.drawing_effect, textrequest->alpha);
 
   delete textrequest;
 }
 
   delete textrequest;
 }
index c52e40f..be8cdfd 100644 (file)
@@ -67,10 +67,8 @@ namespace SuperTux
                              Uint32 drawing_effect = NONE_EFFECT);
       /// Draws a text.
       void draw_text(Font* font, const std::string& text, const Vector& position,
                              Uint32 drawing_effect = NONE_EFFECT);
       /// Draws a text.
       void draw_text(Font* font, const std::string& text, const Vector& position,
-                     int layer, Uint32 drawing_effect = NONE_EFFECT, int alpha = 255);
-      /// Draws aligned text.
-      void draw_text_center(Font* font, const std::string& text,
-                            const Vector& position, int layer, Uint32 drawing_effect = NONE_EFFECT, int alpha = 255);
+                     int allignment, int layer,
+                     Uint32 drawing_effect = NONE_EFFECT, int alpha = 255);
       /// Draws a color gradient onto the whole screen */
       void draw_gradient(Color from, Color to, int layer);
       /// Fills a rectangle.
       /// Draws a color gradient onto the whole screen */
       void draw_gradient(Color from, Color to, int layer);
       /// Fills a rectangle.
@@ -129,7 +127,7 @@ namespace SuperTux
         {
           Font* font;
           std::string text;
         {
           Font* font;
           std::string text;
-          bool center;
+          int allignment;
           int alpha;
         };
 
           int alpha;
         };
 
index f132ec6..95d60f7 100644 (file)
@@ -114,38 +114,34 @@ Font::get_height() const
 }
 
 void
 }
 
 void
-Font::draw(const std::string& text, const Vector& pos, Uint32 drawing_effect, int alpha)
+Font::draw(const std::string& text, const Vector& pos_, int allignment, Uint32 drawing_effect, int alpha)
 {
 {
-  if(shadowsize > 0)
-    draw_chars(shadow_chars, text, pos + Vector(shadowsize, shadowsize),
-               drawing_effect, alpha);
-
-  draw_chars(chars, text, pos, drawing_effect, alpha);
-}
-
-void
-Font::draw_center(const std::string& text, const Vector& pos, Uint32 drawing_effect, int alpha)
-{
-  /* Cut lines changes into seperate strings, needed to support centering text
-     with break lines.
+  // calculate X positions based on the allignment type
+  Vector pos = Vector(pos_);
+  if(allignment == CENTER_ALLIGN)
+    pos.x -= get_text_width(text) / 2;
+  else if(allignment == RIGHT_ALLIGN)
+    pos.x -= get_text_width(text);
+
+  /* Cut lines changes into seperate strings, needed to support center/right text
+     allignments with break lines.
      Feel free to replace this hack with a more elegant solution
   */
   char temp[1024];
   unsigned int i, l, y;
   i = y = 0;
      Feel free to replace this hack with a more elegant solution
   */
   char temp[1024];
   unsigned int i, l, y;
   i = y = 0;
+
   while(true)
     {
     l = text.find("\n", i);
     if(l == std::string::npos)
       {
       temp[text.copy(temp, text.size() - i, i)] = '\0';
   while(true)
     {
     l = text.find("\n", i);
     if(l == std::string::npos)
       {
       temp[text.copy(temp, text.size() - i, i)] = '\0';
-      draw(temp, Vector(screen->w/2 - get_text_width(temp)/2 + pos.x, pos.y + y),
-           drawing_effect, alpha);
+      draw_text(temp, pos + Vector(0,y), drawing_effect, alpha);
       break;
       }
     temp[text.copy(temp, l - i, i)] = '\0';
       break;
       }
     temp[text.copy(temp, l - i, i)] = '\0';
-    draw(temp, Vector(screen->w/2 - get_text_width(temp)/2 + pos.x, pos.y + y),
-         drawing_effect, alpha);
+    draw_text(temp, pos + Vector(0,y), drawing_effect, alpha);
 
     i = l+1;
     y += h + 2;
 
     i = l+1;
     y += h + 2;
@@ -153,6 +149,16 @@ Font::draw_center(const std::string& text, const Vector& pos, Uint32 drawing_eff
 }
 
 void
 }
 
 void
+Font::draw_text(const std::string& text, const Vector& pos, Uint32 drawing_effect, int alpha)
+{
+  if(shadowsize > 0)
+    draw_chars(shadow_chars, text, pos + Vector(shadowsize, shadowsize),
+               drawing_effect, alpha);
+
+  draw_chars(chars, text, pos, drawing_effect, alpha);
+}
+
+void
 Font::draw_chars(Surface* pchars, const std::string& text, const Vector& pos,
                  Uint32 drawing_effect, int alpha)
 {
 Font::draw_chars(Surface* pchars, const std::string& text, const Vector& pos,
                  Uint32 drawing_effect, int alpha)
 {
@@ -303,9 +309,9 @@ void SuperTux::display_text_file(const std::string& file, float scroll_speed, Fo
           default: font = reference_font; break;
         }
 
           default: font = reference_font; break;
         }
 
-        context.draw_text_center(font,
+        context.draw_text(font,
             names[i].substr(1, names[i].size()-1),
             names[i].substr(1, names[i].size()-1),
-            Vector(0, screen->h + y - scroll), LAYER_FOREGROUND1);
+            Vector(screen->w/2, screen->h + y - scroll), CENTER_ALLIGN, LAYER_FOREGROUND1);
         y += font->get_height() + ITEMS_SPACE;
       }
 
         y += font->get_height() + ITEMS_SPACE;
       }
 
index 3d1b9fc..2a5067a 100644 (file)
 namespace SuperTux
   {
 
 namespace SuperTux
   {
 
+  enum {
+    LEFT_ALLIGN,
+    CENTER_ALLIGN,
+    RIGHT_ALLIGN
+    };
+
   /// Font
   class Font
     {
   /// Font
   class Font
     {
@@ -60,13 +66,18 @@ namespace SuperTux
       /// returns the height of the font.
       float get_height() const;
 
       /// returns the height of the font.
       float get_height() const;
 
+      /** Draws the given text to the screen. Also needs the position.
+       * Type of alignment, drawing effect and alpha are optional. */
+      void draw(const std::string& text, const Vector& pos,
+                int allignment = LEFT_ALLIGN,
+                Uint32 drawing_effect = NONE_EFFECT, int alpha = 255);
+
     private:
       friend class DrawingContext;
 
     private:
       friend class DrawingContext;
 
-      void draw(const std::string& text, const Vector& pos,
-                Uint32 drawing_effect = NONE_EFFECT, int alpha = 255);
-      void draw_center(const std::string& text, const Vector& pos,
+      void draw_text(const std::string& text, const Vector& pos,
                 Uint32 drawing_effect = NONE_EFFECT, int alpha = 255);
                 Uint32 drawing_effect = NONE_EFFECT, int alpha = 255);
+
       void draw_chars(Surface* pchars, const std::string& text,
                       const Vector& position, Uint32 drawing_effect, int alpha);
 
       void draw_chars(Surface* pchars, const std::string& text,
                       const Vector& position, Uint32 drawing_effect, int alpha);
 
index 849202b..0ccf68d 100644 (file)
@@ -175,23 +175,23 @@ GameSession::levelintro(void)
   DrawingContext context;
   currentsector->background->draw(context);
 
   DrawingContext context;
   currentsector->background->draw(context);
 
-  context.draw_text_center(gold_text, level->get_name(), Vector(0, 220),
-      LAYER_FOREGROUND1);
+  context.draw_text(gold_text, level->get_name(), Vector(screen->w/2, 160),
+      CENTER_ALLIGN, LAYER_FOREGROUND1);
 
   sprintf(str, "TUX x %d", player_status.lives);
 
   sprintf(str, "TUX x %d", player_status.lives);
-  context.draw_text_center(white_text, str, Vector(0, 240),
-      LAYER_FOREGROUND1);
+  context.draw_text(white_text, str, Vector(screen->w/2, 210),
+      CENTER_ALLIGN, LAYER_FOREGROUND1);
 
   if(level->get_author().size())
 
   if(level->get_author().size())
-    context.draw_text_center(white_small_text,
+    context.draw_text(white_small_text,
       std::string(_("by ")) + level->get_author(), 
       std::string(_("by ")) + level->get_author(), 
-      Vector(0, 360), LAYER_FOREGROUND1);
+      Vector(screen->w/2, 350), CENTER_ALLIGN, LAYER_FOREGROUND1);
 
 
   if(flip_level)
 
 
   if(flip_level)
-    context.draw_text_center(white_text,
+    context.draw_text(white_text,
       _("Level Vertically Flipped!"),
       _("Level Vertically Flipped!"),
-      Vector(0, 310), LAYER_FOREGROUND1);
+      Vector(screen->w/2, 310), CENTER_ALLIGN, LAYER_FOREGROUND1);
 
   if(best_level_statistics != NULL)
     best_level_statistics->draw_message_info(context, _("Best Level Statistics"));
 
   if(best_level_statistics != NULL)
     best_level_statistics->draw_message_info(context, _("Best Level Statistics"));
@@ -357,7 +357,7 @@ GameSession::process_events()
                               tux.base.x, tux.base.y);
                           context->draw_text(white_text, buf,
                               Vector(0, screen->h - white_text->get_height()),
                               tux.base.x, tux.base.y);
                           context->draw_text(white_text, buf,
                               Vector(0, screen->h - white_text->get_height()),
-                              LAYER_FOREGROUND1);
+                              LEFT_ALLIGN, LAYER_FOREGROUND1);
                           context->do_drawing();
                           SDL_Delay(1000);
                         }
                           context->do_drawing();
                           SDL_Delay(1000);
                         }
@@ -630,8 +630,8 @@ GameSession::draw()
       context->draw_filled_rect(
           Vector(0,0), Vector(screen->w, screen->h),
           Color(rand() % 50, rand() % 50, rand() % 50, 128), LAYER_FOREGROUND1);
       context->draw_filled_rect(
           Vector(0,0), Vector(screen->w, screen->h),
           Color(rand() % 50, rand() % 50, rand() % 50, 128), LAYER_FOREGROUND1);
-      context->draw_text_center(blue_text, _("PAUSE - Press 'P' To Play"),
-          Vector(0, 230), LAYER_FOREGROUND1+2);
+      context->draw_text(blue_text, _("PAUSE - Press 'P' To Play"),
+          Vector(screen->w/2, 230), CENTER_ALLIGN, LAYER_FOREGROUND1+2);
 
       char str1[60];
       char str2[124];
 
       char str1[60];
       char str2[124];
@@ -640,10 +640,10 @@ GameSession::draw()
 
       context->draw_text(blue_text, str1,
           Vector((screen->w - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2, 340),
 
       context->draw_text(blue_text, str1,
           Vector((screen->w - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2, 340),
-          LAYER_FOREGROUND1+2);
+          LEFT_ALLIGN, LAYER_FOREGROUND1+2);
       context->draw_text(white_text, str2,
           Vector(((screen->w - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2)+blue_text->get_text_width(str1), 340),
       context->draw_text(white_text, str2,
           Vector(((screen->w - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2)+blue_text->get_text_width(str1), 340),
-          LAYER_FOREGROUND1+2);
+          LEFT_ALLIGN, LAYER_FOREGROUND1+2);
     }
 
   if(Menu::current())
     }
 
   if(Menu::current())
@@ -810,38 +810,38 @@ GameSession::drawstatus(DrawingContext& context)
   char str[60];
   
   snprintf(str, 60, " %d", global_stats.get_points(SCORE_STAT));
   char str[60];
   
   snprintf(str, 60, " %d", global_stats.get_points(SCORE_STAT));
-  context.draw_text(white_text, _("SCORE"), Vector(0, 0), LAYER_FOREGROUND1);
-  context.draw_text(gold_text, str, Vector(96, 0), LAYER_FOREGROUND1);
+  context.draw_text(white_text, _("SCORE"), Vector(0, 0), LEFT_ALLIGN, LAYER_FOREGROUND1);
+  context.draw_text(gold_text, str, Vector(96, 0), LEFT_ALLIGN, LAYER_FOREGROUND1);
 
   if(st_gl_mode == ST_GL_TEST)
     {
       context.draw_text(white_text, _("Press ESC To Return"), Vector(0,20),
 
   if(st_gl_mode == ST_GL_TEST)
     {
       context.draw_text(white_text, _("Press ESC To Return"), Vector(0,20),
-          LAYER_FOREGROUND1);
+          LEFT_ALLIGN, LAYER_FOREGROUND1);
     }
 
   if(!time_left.check()) {
     }
 
   if(!time_left.check()) {
-    context.draw_text_center(white_text, _("TIME's UP"), Vector(0, 0),
-        LAYER_FOREGROUND1);
+    context.draw_text(white_text, _("TIME's UP"), Vector(screen->w/2, 0),
+        CENTER_ALLIGN, LAYER_FOREGROUND1);
   } else if (time_left.get_left() > TIME_WARNING || (global_frame_counter % 10) < 5) {
     sprintf(str, " %d", time_left.get_left() / 1000 );
   } else if (time_left.get_left() > TIME_WARNING || (global_frame_counter % 10) < 5) {
     sprintf(str, " %d", time_left.get_left() / 1000 );
-    context.draw_text_center(white_text, _("TIME"),
-        Vector(0, 0), LAYER_FOREGROUND1);
-    context.draw_text_center(gold_text, str,
-        Vector(4*16, 0), LAYER_FOREGROUND1);
+    context.draw_text(white_text, _("TIME"),
+        Vector(screen->w/2, 0), CENTER_ALLIGN, LAYER_FOREGROUND1);
+    context.draw_text(gold_text, str,
+        Vector(screen->w/2 + 4*16, 0), CENTER_ALLIGN, LAYER_FOREGROUND1);
   }
 
   sprintf(str, " %d", player_status.distros);
   context.draw_text(white_text, _("COINS"),
       Vector(screen->w - white_text->get_text_width(_("COINS"))-white_text->get_text_width("   99"), 0),
   }
 
   sprintf(str, " %d", player_status.distros);
   context.draw_text(white_text, _("COINS"),
       Vector(screen->w - white_text->get_text_width(_("COINS"))-white_text->get_text_width("   99"), 0),
-        LAYER_FOREGROUND1);
+        LEFT_ALLIGN, LAYER_FOREGROUND1);
   context.draw_text(gold_text, str,
   context.draw_text(gold_text, str,
-      Vector(screen->w - gold_text->get_text_width(" 99"), 0),LAYER_FOREGROUND1);
+      Vector(screen->w - gold_text->get_text_width(" 99"), 0),LEFT_ALLIGN, LAYER_FOREGROUND1);
 
   if (player_status.lives >= 5)
     {
       sprintf(str, "%dx", player_status.lives);
       float x = screen->w - gold_text->get_text_width(str) - tux_life->w;
 
   if (player_status.lives >= 5)
     {
       sprintf(str, "%dx", player_status.lives);
       float x = screen->w - gold_text->get_text_width(str) - tux_life->w;
-      context.draw_text(gold_text, str, Vector(x, 20), LAYER_FOREGROUND1);
+      context.draw_text(gold_text, str, Vector(x, 20), LEFT_ALLIGN, LAYER_FOREGROUND1);
       context.draw_surface(tux_life, Vector(screen->w - 16, 20),
           LAYER_FOREGROUND1);
     }
       context.draw_surface(tux_life, Vector(screen->w - 16, 20),
           LAYER_FOREGROUND1);
     }
@@ -855,16 +855,16 @@ GameSession::drawstatus(DrawingContext& context)
 
   context.draw_text(white_text, _("LIVES"),
       Vector(screen->w - white_text->get_text_width(_("LIVES")) - white_text->get_text_width("   99"), 20),
 
   context.draw_text(white_text, _("LIVES"),
       Vector(screen->w - white_text->get_text_width(_("LIVES")) - white_text->get_text_width("   99"), 20),
-      LAYER_FOREGROUND1);
+      LEFT_ALLIGN, LAYER_FOREGROUND1);
 
   if(show_fps)
     {
       sprintf(str, "%2.1f", fps_fps);
       context.draw_text(white_text, "FPS", 
           Vector(screen->w - white_text->get_text_width("FPS     "), 40),
 
   if(show_fps)
     {
       sprintf(str, "%2.1f", fps_fps);
       context.draw_text(white_text, "FPS", 
           Vector(screen->w - white_text->get_text_width("FPS     "), 40),
-          LAYER_FOREGROUND1);
+          LEFT_ALLIGN, LAYER_FOREGROUND1);
       context.draw_text(gold_text, str,
       context.draw_text(gold_text, str,
-          Vector(screen->w-4*16, 40), LAYER_FOREGROUND1);
+          Vector(screen->w-4*16, 40), LEFT_ALLIGN, LAYER_FOREGROUND1);
     }
 }
 
     }
 }
 
@@ -876,14 +876,14 @@ GameSession::drawresultscreen(void)
   DrawingContext context;
   currentsector->background->draw(context);  
 
   DrawingContext context;
   currentsector->background->draw(context);  
 
-  context.draw_text_center(blue_text, _("Result:"), Vector(0, 200),
-      LAYER_FOREGROUND1);
+  context.draw_text(blue_text, _("Result:"), Vector(screen->w/2, 200),
+      CENTER_ALLIGN, LAYER_FOREGROUND1);
 
   sprintf(str, _("SCORE: %d"), global_stats.get_points(SCORE_STAT));
 
   sprintf(str, _("SCORE: %d"), global_stats.get_points(SCORE_STAT));
-  context.draw_text_center(gold_text, str, Vector(0, 224), LAYER_FOREGROUND1);
+  context.draw_text(gold_text, str, Vector(screen->w/2, 224), CENTER_ALLIGN, LAYER_FOREGROUND1);
 
   sprintf(str, _("COINS: %d"), player_status.distros);
 
   sprintf(str, _("COINS: %d"), player_status.distros);
-  context.draw_text_center(gold_text, str, Vector(0, 256), LAYER_FOREGROUND1);
+  context.draw_text(gold_text, str, Vector(screen->w/2, 256), CENTER_ALLIGN, LAYER_FOREGROUND1);
 
   context.do_drawing();
   
 
   context.do_drawing();
   
@@ -940,8 +940,8 @@ bool process_load_game_menu()
       fadeout(256);
 
       DrawingContext context;
       fadeout(256);
 
       DrawingContext context;
-      context.draw_text_center(white_text, "Loading...",
-                               Vector(0, screen->h/2), LAYER_FOREGROUND1);
+      context.draw_text(white_text, "Loading...",
+                        Vector(screen->w/2, screen->h/2), CENTER_ALLIGN, LAYER_FOREGROUND1);
       context.do_drawing();
 
       WorldMapNS::WorldMap worldmap;
       context.do_drawing();
 
       WorldMapNS::WorldMap worldmap;
index 39d4eb6..4ede2c7 100644 (file)
@@ -133,7 +133,7 @@ FloatingScore::action(float elapsed_time)
 void
 FloatingScore::draw(DrawingContext& context)
 {
 void
 FloatingScore::draw(DrawingContext& context)
 {
-  context.draw_text(gold_text, str, position, LAYER_OBJECTS);
+  context.draw_text(gold_text, str, position, LEFT_ALLIGN, LAYER_OBJECTS);
 }
 
 /* Trampoline */
 }
 
 /* Trampoline */
index 1685e4b..674e8df 100644 (file)
@@ -102,12 +102,12 @@ void save_hs(int score)
     {
       context.draw_surface(bkgd, Vector(0, 0), LAYER_BACKGROUND0);
 
     {
       context.draw_surface(bkgd, Vector(0, 0), LAYER_BACKGROUND0);
 
-      context.draw_text_center(blue_text, "Congratulations", 
-          Vector(0, 130), LAYER_FOREGROUND1);
+      context.draw_text(blue_text, "Congratulations", 
+          Vector(screen->w/2, 130), CENTER_ALLIGN, LAYER_FOREGROUND1);
       context.draw_text(blue_text, "Your score:", Vector(150, 180),
       context.draw_text(blue_text, "Your score:", Vector(150, 180),
-          LAYER_FOREGROUND1);
+          LEFT_ALLIGN, LAYER_FOREGROUND1);
       sprintf(str, "%d", hs_score);
       sprintf(str, "%d", hs_score);
-      context.draw_text(yellow_nums, str, Vector(250, 170), LAYER_FOREGROUND1);
+      context.draw_text(yellow_nums, str, Vector(250, 170), LEFT_ALLIGN, LAYER_FOREGROUND1);
 
       Menu::current()->draw(context);
       Menu::current()->action();
 
       Menu::current()->draw(context);
       Menu::current()->action();
index ddc0e08..7be8284 100644 (file)
@@ -827,20 +827,20 @@ void LevelEditor::drawinterface(DrawingContext &context)
     }
 
     sprintf(str, "%d/%d", le_levelnb, le_level_subset->get_num_levels());
     }
 
     sprintf(str, "%d/%d", le_levelnb, le_level_subset->get_num_levels());
-    context.draw_text(white_text, str, Vector((le_level_subset->get_num_levels() < 10) ? -10 : 0, 16), LAYER_GUI);
+    context.draw_text(white_text, str, Vector((le_level_subset->get_num_levels() < 10) ? -10 : 0, 16), LEFT_ALLIGN, LAYER_GUI);
 
     if(!le_help_shown)
 
     if(!le_help_shown)
-      context.draw_text(white_small_text, "F1 for Help", Vector(10, 430), LAYER_GUI);
+      context.draw_text(white_small_text, "F1 for Help", Vector(10, 430), LEFT_ALLIGN, LAYER_GUI);
 
     if(display_level_info.check())
 
     if(display_level_info.check())
-      context.draw_text_center(white_text, le_level->name.c_str(), Vector(0, 0), LAYER_GUI);
+      context.draw_text(white_text, le_level->name.c_str(), Vector(screen->w/2, 0), CENTER_ALLIGN, LAYER_GUI);
   }
   else
   {
     if(!Menu::current())
   }
   else
   {
     if(!Menu::current())
-      context.draw_text(white_small_text, "No Level Subset loaded - Press ESC and choose one in the menu", Vector(10, 430), LAYER_GUI);
+      context.draw_text(white_small_text, "No Level Subset loaded - Press ESC and choose one in the menu", Vector(10, 430), LEFT_ALLIGN, LAYER_GUI);
     else
     else
-      context.draw_text(white_small_text, "No Level Subset loaded", Vector(10, 430), LAYER_GUI);
+      context.draw_text(white_small_text, "No Level Subset loaded", Vector(10, 430), LEFT_ALLIGN, LAYER_GUI);
   }
 
 }
   }
 
 }
@@ -1782,13 +1782,13 @@ void LevelEditor::showhelp()
     context.draw_gradient(Color(0,0,0), Color(255,255,255), LAYER_BACKGROUND0);
     drawinterface(context);
 
     context.draw_gradient(Color(0,0,0), Color(255,255,255), LAYER_BACKGROUND0);
     drawinterface(context);
 
-    context.draw_text_center(blue_text, "- Help -", Vector(0, 30), LAYER_GUI);
+    context.draw_text(blue_text, "- Help -", Vector(screen->w/2, 30), CENTER_ALLIGN, LAYER_GUI);
 
     for(unsigned int t = 0; t < sizeof(text[i])/sizeof(char *); t++)
 
     for(unsigned int t = 0; t < sizeof(text[i])/sizeof(char *); t++)
-      context.draw_text(white_text, text[i][t], Vector(5, 80+(t*white_text->get_height())), LAYER_GUI);
+      context.draw_text(white_text, text[i][t], Vector(5, 80+(t*white_text->get_height())), LEFT_ALLIGN, LAYER_GUI);
 
     sprintf(str,"Press any key to continue - Page %d/%d?", i, static_cast<int>(sizeof(text)));
 
     sprintf(str,"Press any key to continue - Page %d/%d?", i, static_cast<int>(sizeof(text)));
-    context.draw_text(gold_text, str, Vector(0, 0), LAYER_GUI);
+    context.draw_text(gold_text, str, Vector(0, 0), LEFT_ALLIGN, LAYER_GUI);
 
     context.do_drawing();
 
 
     context.do_drawing();
 
index 79db1a1..79c3083 100644 (file)
@@ -22,6 +22,7 @@
 #include "statistics.h"
 #include "video/drawing_context.h"
 #include "app/gettext.h"
 #include "statistics.h"
 #include "video/drawing_context.h"
 #include "app/gettext.h"
+#include "app/globals.h"
 #include "resources.h"
 
 Statistics global_stats;
 #include "resources.h"
 
 Statistics global_stats;
@@ -108,10 +109,10 @@ Statistics::draw_worldmap_info(DrawingContext& context)
 
   char str[128];
 
 
   char str[128];
 
-  context.draw_text(white_small_text, _("Level Statistics"), Vector(550, 490), LAYER_GUI);
+  context.draw_text(white_small_text, _("Level Statistics"), Vector(550, 490), LEFT_ALLIGN, LAYER_GUI);
 
   sprintf(str, _("Max score: %d"), stats[SCORE_STAT]);
 
   sprintf(str, _("Max score: %d"), stats[SCORE_STAT]);
-  context.draw_text(white_small_text, str, Vector(560, 506), LAYER_GUI);
+  context.draw_text(white_small_text, str, Vector(560, 506), LEFT_ALLIGN, LAYER_GUI);
 
   if(display_stat == BADGUYS_SQUISHED_STAT)
     sprintf(str, _("Max fragging: %d"), stats[BADGUYS_SQUISHED_STAT]);
 
   if(display_stat == BADGUYS_SQUISHED_STAT)
     sprintf(str, _("Max fragging: %d"), stats[BADGUYS_SQUISHED_STAT]);
@@ -122,7 +123,7 @@ Statistics::draw_worldmap_info(DrawingContext& context)
   else// if(display_stat == JUMPS_STAT)
     sprintf(str, _("Min jumps: %d"), stats[JUMPS_STAT]);
 
   else// if(display_stat == JUMPS_STAT)
     sprintf(str, _("Min jumps: %d"), stats[JUMPS_STAT]);
 
-  context.draw_text(white_small_text, str, Vector(560, 522), LAYER_GUI, NONE_EFFECT, alpha);
+  context.draw_text(white_small_text, str, Vector(560, 522), LAYER_GUI, LEFT_ALLIGN, NONE_EFFECT, alpha);
 }
 
 void
 }
 
 void
@@ -131,7 +132,7 @@ Statistics::draw_message_info(DrawingContext& context, std::string title)
   if(stats[SCORE_STAT] == -1)  // not initialized yet
     return;
 
   if(stats[SCORE_STAT] == -1)  // not initialized yet
     return;
 
-  context.draw_text_center(gold_text, title, Vector(0, 400), LAYER_GUI);
+  context.draw_text(gold_text, title, Vector(screen->w/2, 400), CENTER_ALLIGN, LAYER_GUI);
 
   char str[128];
   for(int i = 0; i < NUM_STATS; i++)
 
   char str[128];
   for(int i = 0; i < NUM_STATS; i++)
@@ -147,7 +148,7 @@ Statistics::draw_message_info(DrawingContext& context, std::string title)
     else// if(i == JUMPS_STAT)
       sprintf(str, _("Min jumps: %d"), stats[JUMPS_STAT]);
 
     else// if(i == JUMPS_STAT)
       sprintf(str, _("Min jumps: %d"), stats[JUMPS_STAT]);
 
-    context.draw_text_center(white_text, str, Vector(0, 430 + i*22), LAYER_GUI);
+    context.draw_text(white_text, str, Vector(screen->w/2, 430 + i*22), CENTER_ALLIGN, LAYER_GUI);
     }
 }
 
     }
 }
 
index 1131b5c..69fdb79 100644 (file)
@@ -328,12 +328,12 @@ void title(void)
         context.draw_surface(logo, Vector(screen->w/2 - logo->w/2, 30),
             LAYER_FOREGROUND1+1);
 
         context.draw_surface(logo, Vector(screen->w/2 - logo->w/2, 30),
             LAYER_FOREGROUND1+1);
 
-      context.draw_text(white_small_text, " SuperTux " VERSION "\n", Vector(0, screen->h - 70), LAYER_FOREGROUND1);
+      context.draw_text(white_small_text, " SuperTux " VERSION "\n", Vector(0, screen->h - 70), LEFT_ALLIGN, LAYER_FOREGROUND1);
       context.draw_text(white_small_text,
         _("Copyright (c) 2003 SuperTux Devel Team\n"
           "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n"
           "are welcome to redistribute it under certain conditions; see the file COPYING\n"
       context.draw_text(white_small_text,
         _("Copyright (c) 2003 SuperTux Devel Team\n"
           "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n"
           "are welcome to redistribute it under certain conditions; see the file COPYING\n"
-          "for details.\n"), Vector(0, screen->h - 70 + white_small_text->get_height()), LAYER_FOREGROUND1);
+          "for details.\n"), Vector(0, screen->h - 70 + white_small_text->get_height()), LEFT_ALLIGN, LAYER_FOREGROUND1);
 
       /* Don't draw menu, if quit is true */
       Menu* menu = Menu::current();
 
       /* Don't draw menu, if quit is true */
       Menu* menu = Menu::current();
index 5c09101..72e9edb 100644 (file)
@@ -906,16 +906,12 @@ WorldMap::update(float delta)
                   context.draw_gradient(Color (200,240,220), Color(200,200,220),
                       LAYER_BACKGROUND0);
 
                   context.draw_gradient(Color (200,240,220), Color(200,200,220),
                       LAYER_BACKGROUND0);
 
-                  context.draw_text_center(blue_text, _("GAMEOVER"), 
-                      Vector(0, 200), LAYER_FOREGROUND1);
-
-//                  sprintf(str, _("SCORE: %d"), total_stats.get_points(SCORE_STAT));
-//                  context.draw_text_center(gold_text, str,
-//                      Vector(0, 230), LAYER_FOREGROUND1);
+                  context.draw_text(blue_text, _("GAMEOVER"), 
+                      Vector(screen->w/2, 200), CENTER_ALLIGN, LAYER_FOREGROUND1);
 
                   sprintf(str, _("COINS: %d"), player_status.distros);
 
                   sprintf(str, _("COINS: %d"), player_status.distros);
-                  context.draw_text_center(gold_text, str,
-                      Vector(0, screen->w - 32), LAYER_FOREGROUND1);
+                  context.draw_text(gold_text, str,
+                      Vector(screen->w/2, screen->w - 32), CENTER_ALLIGN, LAYER_FOREGROUND1);
 
                   total_stats.draw_message_info(context, _("Total Statistics"));
 
 
                   total_stats.draw_message_info(context, _("Total Statistics"));
 
@@ -1068,23 +1064,23 @@ WorldMap::draw_status(DrawingContext& context)
   char str[80];
   sprintf(str, " %d", total_stats.get_points(SCORE_STAT));
 
   char str[80];
   sprintf(str, " %d", total_stats.get_points(SCORE_STAT));
 
-  context.draw_text(white_text, _("SCORE"), Vector(0, 0), LAYER_FOREGROUND1);
-  context.draw_text(gold_text, str, Vector(96, 0), LAYER_FOREGROUND1);
+  context.draw_text(white_text, _("SCORE"), Vector(0, 0), LEFT_ALLIGN, LAYER_FOREGROUND1);
+  context.draw_text(gold_text, str, Vector(96, 0), LEFT_ALLIGN, LAYER_FOREGROUND1);
 
   sprintf(str, "%d", player_status.distros);
   context.draw_text(white_text, _("COINS"), Vector(screen->w/2 - 16*5, 0),
 
   sprintf(str, "%d", player_status.distros);
   context.draw_text(white_text, _("COINS"), Vector(screen->w/2 - 16*5, 0),
-      LAYER_FOREGROUND1);
+      LEFT_ALLIGN, LAYER_FOREGROUND1);
   context.draw_text(gold_text, str, Vector(screen->w/2 + (16*5)/2, 0),
   context.draw_text(gold_text, str, Vector(screen->w/2 + (16*5)/2, 0),
-        LAYER_FOREGROUND1);
+        LEFT_ALLIGN, LAYER_FOREGROUND1);
 
   if (player_status.lives >= 5)
     {
       sprintf(str, "%dx", player_status.lives);
       context.draw_text(gold_text, str, 
           Vector(screen->w - gold_text->get_text_width(str) - tux_life->w, 0),
 
   if (player_status.lives >= 5)
     {
       sprintf(str, "%dx", player_status.lives);
       context.draw_text(gold_text, str, 
           Vector(screen->w - gold_text->get_text_width(str) - tux_life->w, 0),
-          LAYER_FOREGROUND1);
+          LEFT_ALLIGN, LAYER_FOREGROUND1);
       context.draw_surface(tux_life, Vector(screen->w -
       context.draw_surface(tux_life, Vector(screen->w -
-            gold_text->get_text_width("9"), 0), LAYER_FOREGROUND1);
+            gold_text->get_text_width("9"), 0), LEFT_ALLIGN, LAYER_FOREGROUND1);
     }
   else
     {
     }
   else
     {
@@ -1095,7 +1091,7 @@ WorldMap::draw_status(DrawingContext& context)
     }
   context.draw_text(white_text, _("LIVES"),
       Vector(screen->w - white_text->get_text_width(_("LIVES")) - white_text->get_text_width("   99"), 0),
     }
   context.draw_text(white_text, _("LIVES"),
       Vector(screen->w - white_text->get_text_width(_("LIVES")) - white_text->get_text_width("   99"), 0),
-      LAYER_FOREGROUND1);
+      LEFT_ALLIGN, LAYER_FOREGROUND1);
 
   if (!tux->is_moving())
     {
 
   if (!tux->is_moving())
     {
@@ -1109,27 +1105,27 @@ WorldMap::draw_status(DrawingContext& context)
                 if(i->title == "")
                   get_level_title(*i);
 
                 if(i->title == "")
                   get_level_title(*i);
 
-                context.draw_text_center(white_text, i->title, 
-                    Vector(0, screen->h - white_text->get_height() - 30),
-                    LAYER_FOREGROUND1);
+                context.draw_text(white_text, i->title, 
+                    Vector(screen->w/2, screen->h - white_text->get_height() - 30),
+                    CENTER_ALLIGN, LAYER_FOREGROUND1);
 
                 i->statistics.draw_worldmap_info(context);
                 }
 
               /* Display an in-map message in the map, if any as been selected */
               if(!i->map_message.empty() && !i->passive_message)
 
                 i->statistics.draw_worldmap_info(context);
                 }
 
               /* Display an in-map message in the map, if any as been selected */
               if(!i->map_message.empty() && !i->passive_message)
-                context.draw_text_center(gold_text, i->map_message, 
-                    Vector(0, screen->h - white_text->get_height() - 60),
-                    LAYER_FOREGROUND1);
+                context.draw_text(gold_text, i->map_message, 
+                    Vector(screen->w/2, screen->h - white_text->get_height() - 60),
+                    CENTER_ALLIGN, LAYER_FOREGROUND1);
               break;
             }
         }
     }
   /* Display a passive message in the map, if needed */
   if(passive_message_timer.check())
               break;
             }
         }
     }
   /* Display a passive message in the map, if needed */
   if(passive_message_timer.check())
-    context.draw_text_center(gold_text, passive_message, 
-            Vector(0, screen->h - white_text->get_height() - 60),
-            LAYER_FOREGROUND1);
+    context.draw_text(gold_text, passive_message, 
+            Vector(screen->w/2, screen->h - white_text->get_height() - 60),
+            CENTER_ALLIGN, LAYER_FOREGROUND1);
 }
 
 void
 }
 
 void