- did some C++ifying. let's try to follow suit :)
[supertux.git] / src / button.cpp
index 15b2be1..1cfbc72 100644 (file)
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //  02111-1307, USA.
 
-#include <string.h>
-#include <stdlib.h>
+#include <cstring>
+#include <cstdlib>
+
 #include "setup.h"
 #include "screen/screen.h"
+#include "screen/drawing_context.h"
 #include "globals.h"
 #include "button.h"
 #include "camera.h"
 
-// TODO
-#if 0
-
 Timer Button::popup_timer;
 
 Button::Button(Surface* button_image, const std::string& ninfo,
@@ -50,7 +49,6 @@ Button::Button(Surface* button_image, const std::string& ninfo,
   tag = -1;
   state = BUTTON_NONE;
   show_info = false;
-  drawable = NULL;
 }
 
 Button::Button(const std::string& imagefilename, const std::string& ninfo,
@@ -71,7 +69,6 @@ Button::Button(const std::string& imagefilename, const std::string& ninfo,
   tag = -1;
   state = BUTTON_NONE;
   show_info = false;
-  drawable = NULL;
 }
 
 void Button::add_icon(const std::string& icon_file, int mw, int mh)
@@ -99,7 +96,7 @@ void Button::add_icon(const std::string& icon_file, int mw, int mh)
 
 }
 
-void Button::draw()
+void Button::draw(DrawingContext& context)
 {
   if(state == BUTTON_HOVER)
     if(!popup_timer.check())
@@ -109,27 +106,27 @@ void Button::draw()
   fillrect(rect.x+1,rect.y+1,rect.w-2,rect.h-2,175,175,175,200);
 
   for(std::vector<Surface*>::iterator it = icon.begin(); it != icon.end(); ++it)
-    (*it)->draw(rect.x,rect.y);
+    context.draw_surface(*it, Vector(rect.x,rect.y), LAYER_GUI);
 
-  if(drawable)
+/*  if(drawable)
   {
     Camera viewport;
     viewport.set_translation(Vector(rect.x, rect.y));
     drawable->draw(viewport, 0);
-  }
+  }*/
 
   if(show_info)
   {
     char str[80];
     int i = -32;
 
-    if(0 > rect.x - (int)strlen(info.c_str()) * white_small_text->w)
-      i = rect.w + strlen(info.c_str()) * white_small_text->w;
+    if(0 > rect.x - white_small_text->get_text_width(info))
+      i = rect.w + (int)white_small_text->get_text_width(info);
 
     if(!info.empty())
-      white_small_text->draw(info.c_str(), i + rect.x - strlen(info.c_str()) * white_small_text->w, rect.y, 1);
+      context.draw_text(white_small_text, info, Vector(i + rect.x - white_small_text->get_text_width(info), rect.y), LAYER_GUI);
     sprintf(str,"(%s)", SDL_GetKeyName(shortcut));
-    white_small_text->draw(str, i + rect.x - strlen(str) * white_small_text->w, rect.y + white_small_text->h+2, 1);
+    context.draw_text(white_small_text, str, Vector(i + rect.x -  white_small_text->get_text_width(str), rect.y + white_small_text->get_height()+2), LAYER_GUI);
   }
   if(state == BUTTON_PRESSED || state == BUTTON_DEACTIVE)
     fillrect(rect.x,rect.y,rect.w,rect.h,75,75,75,200);
@@ -272,7 +269,7 @@ ButtonPanel::~ButtonPanel()
   item.clear();
 }
 
-void ButtonPanel::draw()
+void ButtonPanel::draw(DrawingContext& context)
 {
 
   if(hidden == false)
@@ -280,7 +277,7 @@ void ButtonPanel::draw()
     fillrect(rect.x,rect.y,rect.w,rect.h,100,100,100,200);
     for(std::vector<Button*>::iterator it = item.begin(); it != item.end(); ++it)
     {
-      (*it)->draw();
+      (*it)->draw(context);
       if(hlast && it == last_clicked)
       {
         fillrect((*it)->get_pos().x,(*it)->get_pos().y,(*it)->get_pos().w,(*it)->get_pos().h,100,100,100,128);
@@ -326,6 +323,3 @@ void ButtonPanel::highlight_last(bool b)
 {
   hlast = b;
 }
-#endif
-
-