[cppcheck] Part 1: Performance
[supertux.git] / src / supertux / info_box.cpp
index 323bbfc..46c4da9 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "supertux/info_box.hpp"
 
-#include "supertux/main.hpp"
+#include "supertux/globals.hpp"
 #include "supertux/info_box_line.hpp"
 #include "util/log.hpp"
 #include "video/drawing_context.hpp"
 
 InfoBox::InfoBox(const std::string& text) :
   firstline(0),
-  lines(),
+  // Split text string lines into a vector
+  lines(InfoBoxLine::split(text, 400)),
   images(),
   arrow_scrollup(),
   arrow_scrolldown()
 {
-  // Split text string lines into a vector
-  lines = InfoBoxLine::split(text, 400);
-
   try
   {
     // get the arrow sprites
-    arrow_scrollup   = new Surface("images/engine/menu/scroll-up.png");
-    arrow_scrolldown = new Surface("images/engine/menu/scroll-down.png");
+    arrow_scrollup   = Surface::create("images/engine/menu/scroll-up.png");
+    arrow_scrolldown = Surface::create("images/engine/menu/scroll-down.png");
   }
   catch (std::exception& e)
   {
     log_warning << "Could not load scrolling images: " << e.what() << std::endl;
-    arrow_scrollup = 0;
-    arrow_scrolldown = 0;
+    arrow_scrollup.reset();
+    arrow_scrolldown.reset();
   }
 }
 
 InfoBox::~InfoBox()
 {
   for(std::vector<InfoBoxLine*>::iterator i = lines.begin();
-      i != lines.end(); i++)
+      i != lines.end(); ++i)
     delete *i;
-
-  delete arrow_scrollup;
-  delete arrow_scrolldown;
 }
 
 void
@@ -75,18 +70,18 @@ InfoBox::draw(DrawingContext& context)
       break;
     }
 
-    lines[i]->draw(context, Rect(x1, y, x1+width, y), LAYER_GUI);
+    lines[i]->draw(context, Rectf(x1, y, x1+width, y), LAYER_GUI);
     y += lines[i]->get_height();
   }
 
   {
     // draw the scrolling arrows
-    if (arrow_scrollup && firstline > 0)
+    if (arrow_scrollup.get() && firstline > 0)
       context.draw_surface(arrow_scrollup,
                            Vector( x1 + width  - arrow_scrollup->get_width(),  // top-right corner of box
                                    y1), LAYER_GUI);
 
-    if (arrow_scrolldown && linesLeft && firstline < lines.size()-1)
+    if (arrow_scrolldown.get() && linesLeft && firstline < lines.size()-1)
       context.draw_surface(arrow_scrolldown,
                            Vector( x1 + width  - arrow_scrolldown->get_width(),  // bottom-light corner of box
                                    y1 + height - arrow_scrolldown->get_height()),