X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbutton.cpp;h=f144bb3317f791c3e776ae0d480627d56c96b2b4;hb=4b985b51e7d2da923d53a61bb5038d11978e9cda;hp=27697c90236f049068c07cf3eb2619d57c2b30ef;hpb=b8c83bae1b0cd0367b6e3ac8c4c28e077eb1b594;p=supertux.git diff --git a/src/button.cpp b/src/button.cpp index 27697c902..f144bb331 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -21,18 +21,21 @@ #include #include #include "setup.h" -#include "screen.h" +#include "screen/screen.h" +#include "screen/drawing_context.h" #include "globals.h" #include "button.h" #include "camera.h" Timer Button::popup_timer; -Button::Button(std::string icon_file, std::string ninfo, SDLKey nshortcut, int x, int y, int mw, int mh) +Button::Button(Surface* button_image, const std::string& ninfo, + SDLKey nshortcut, int x, int y, int mw, int mh) { popup_timer.init(false); - add_icon(icon_file,mw,mh); + if(button_image) + icon.push_back(button_image); info = ninfo; @@ -45,10 +48,29 @@ Button::Button(std::string icon_file, std::string ninfo, SDLKey nshortcut, int x tag = -1; state = BUTTON_NONE; show_info = false; - drawable = NULL; } -void Button::add_icon(std::string icon_file, int mw, int mh) +Button::Button(const std::string& imagefilename, const std::string& ninfo, + SDLKey nshortcut, int x, int y, int mw, int mh) +{ + popup_timer.init(false); + + add_icon(imagefilename, mw, mh); + + info = ninfo; + + shortcut = nshortcut; + + rect.x = x; + rect.y = y; + rect.w = icon[0]->w; + rect.h = icon[0]->h; + tag = -1; + state = BUTTON_NONE; + show_info = false; +} + +void Button::add_icon(const std::string& icon_file, int mw, int mh) { char filename[1024]; @@ -73,7 +95,7 @@ void Button::add_icon(std::string icon_file, int mw, int mh) } -void Button::draw() +void Button::draw(DrawingContext& context) { if(state == BUTTON_HOVER) if(!popup_timer.check()) @@ -83,27 +105,27 @@ void Button::draw() fillrect(rect.x+1,rect.y+1,rect.w-2,rect.h-2,175,175,175,200); for(std::vector::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); @@ -116,7 +138,9 @@ Button::~Button() for(std::vector::iterator it = icon.begin(); it != icon.end(); ++it) delete (*it); icon.clear(); - delete drawable; + // FIXME TODO XXX: commenting this out fixes the leveleditor quit crash + // probably should be deleted somehow, though + //delete drawable; } void Button::event(SDL_Event &event) @@ -244,7 +268,7 @@ ButtonPanel::~ButtonPanel() item.clear(); } -void ButtonPanel::draw() +void ButtonPanel::draw(DrawingContext& context) { if(hidden == false) @@ -252,7 +276,7 @@ void ButtonPanel::draw() fillrect(rect.x,rect.y,rect.w,rect.h,100,100,100,200); for(std::vector::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); @@ -298,5 +322,3 @@ void ButtonPanel::highlight_last(bool b) { hlast = b; } - -