tbuilder_control::tbuilder_control(const config& cfg) : tbuilder_widget(cfg) , id(cfg["id"]) , definition(cfg["definition"]) , linked_group(cfg["linked_group"]) , label(cfg["label"].t_str()) , tooltip(cfg["tooltip"].t_str()) , help(cfg["help"].t_str()) , use_tooltip_on_label_overflow(true) #ifndef LOW_MEM , debug_border_mode(cfg["debug_border_mode"]) , debug_border_color(decode_color(cfg["debug_border_color"])) #endif { if(definition.empty()) { definition = "default"; } VALIDATE_WITH_DEV_MESSAGE(help.empty() || !tooltip.empty() , _("Found a widget with a helptip and without a tooltip.") , (formatter() << "id '" << id << "' label '" << label << "' helptip '" << help << "'.").str()); DBG_GUI_P << "Window builder: found control with id '" << id << "' and definition '" << definition << "'.\n"; }
void tcircle::draw(surface& canvas , const game_logic::map_formula_callable& variables) { /** * @todo formulas are now recalculated every draw cycle which is a bit * silly unless there has been a resize. So to optimize we should use an * extra flag or do the calculation in a separate routine. */ const unsigned x = x_(variables); const unsigned y = y_(variables); const unsigned radius = radius_(variables); DBG_GUI_D << "Circle: drawn at " << x << ',' << y << " radius " << radius << " canvas size " << canvas->w << ',' << canvas->h << ".\n"; VALIDATE_WITH_DEV_MESSAGE( static_cast<int>(x - radius) >= 0 , _("Circle doesn't fit on canvas.") , (formatter() << "x = " << x << ", radius = " << radius).str()); VALIDATE_WITH_DEV_MESSAGE( static_cast<int>(y - radius) >= 0 , _("Circle doesn't fit on canvas.") , (formatter() << "y = " << y << ", radius = " << radius).str()); VALIDATE_WITH_DEV_MESSAGE( static_cast<int>(x + radius) < canvas->w , _("Circle doesn't fit on canvas.") , (formatter() << "x = " << x << ", radius = " << radius << "', canvas width = " << canvas->w << ".").str()); VALIDATE_WITH_DEV_MESSAGE( static_cast<int>(y + radius) < canvas->h , _("Circle doesn't fit on canvas.") , (formatter() << "y = " << y << ", radius = " << radius << "', canvas height = " << canvas->h << ".").str()); // lock the surface surface_lock locker(canvas); draw_circle(canvas, color_, x, y, radius); }
builder_styled_widget::builder_styled_widget(const config& cfg) : builder_widget(cfg) , definition(cfg["definition"]) , label_string(cfg["label"].t_str()) , tooltip(cfg["tooltip"].t_str()) , help(cfg["help"].t_str()) , use_tooltip_on_label_overflow(true) , use_markup(cfg["use_markup"].to_bool(false)) { if(definition.empty()) { definition = "default"; } VALIDATE_WITH_DEV_MESSAGE( help.empty() || !tooltip.empty(), _("Found a widget with a helptip and without a tooltip."), formatter() << "id '" << id << "' label '" << label_string << "' helptip '" << help << "'."); DBG_GUI_P << "Window builder: found styled_widget with id '" << id << "' and definition '" << definition << "'.\n"; }
void timage::draw(surface& canvas , const game_logic::map_formula_callable& variables) { DBG_GUI_D << "Image: draw.\n"; /** * @todo formulas are now recalculated every draw cycle which is a bit * silly unless there has been a resize. So to optimize we should use an * extra flag or do the calculation in a separate routine. */ const std::string& name = image_name_(variables); if(name.empty()) { DBG_GUI_D << "Image: formula returned no value, will not be drawn.\n"; return; } /* * The locator might return a different surface for every call so we can't * cache the output, also not if no formula is used. */ surface tmp(image::get_image(image::locator(name))); if(!tmp) { ERR_GUI_D << "Image: '" << name << "' not found and won't be drawn.\n"; return; } image_.assign(make_neutral_surface(tmp)); assert(image_); src_clip_ = ::create_rect(0, 0, image_->w, image_->h); game_logic::map_formula_callable local_variables(variables); local_variables.add("image_original_width", variant(image_->w)); local_variables.add("image_original_height", variant(image_->h)); unsigned w = w_(local_variables); VALIDATE_WITH_DEV_MESSAGE( static_cast<int>(w) >= 0 , _("Image doesn't fit on canvas.") , (formatter() << "Image '" << name << "', w = " << static_cast<int>(w) << ".").str()); unsigned h = h_(local_variables); VALIDATE_WITH_DEV_MESSAGE( static_cast<int>(h) >= 0 , _("Image doesn't fit on canvas.") , (formatter() << "Image '" << name << "', h = " << static_cast<int>(h) << ".").str()); local_variables.add("image_width", variant(w ? w : image_->w)); local_variables.add("image_height", variant(h ? h : image_->h)); const unsigned x = x_(local_variables); VALIDATE_WITH_DEV_MESSAGE( static_cast<int>(x) >= 0 , _("Image doesn't fit on canvas.") , (formatter() << "Image '" << name << "', x = " << static_cast<int>(x) << ".").str()); const unsigned y = y_(local_variables); VALIDATE_WITH_DEV_MESSAGE( static_cast<int>(y) >= 0 , _("Image doesn't fit on canvas.") , (formatter() << "Image '" << name << "', y = " << static_cast<int>(y) << ".").str()); // Copy the data to local variables to avoid overwriting the originals. SDL_Rect src_clip = src_clip_; SDL_Rect dst_clip = ::create_rect(x, y, 0, 0); surface surf; // Test whether we need to scale and do the scaling if needed. if(w || h) { bool done = false; bool stretch_image = (resize_mode_ == stretch) && (!!w ^ !!h); if(!w) { if(stretch_image) { DBG_GUI_D << "Image: vertical stretch from " << image_->w << ',' << image_->h << " to a height of " << h << ".\n"; surf = stretch_surface_vertical(image_, h, false); done = true; } w = image_->w; } if(!h) { if(stretch_image) { DBG_GUI_D << "Image: horizontal stretch from " << image_->w << ',' << image_->h << " to a width of " << w << ".\n"; surf = stretch_surface_horizontal(image_, w, false); done = true; } h = image_->h; } if(!done) { if(resize_mode_ == tile) { DBG_GUI_D << "Image: tiling from " << image_->w << ',' << image_->h << " to " << w << ',' << h << ".\n"; const int columns = (w + image_->w - 1) / image_->w; const int rows = (h + image_->h - 1) / image_->h; surf = create_neutral_surface(w, h); for(int x = 0; x < columns; ++x) { for(int y = 0; y < rows; ++y) { const SDL_Rect dest = ::create_rect( x * image_->w , y * image_->h , 0 , 0); blit_surface(image_, NULL, surf, &dest); } } } else { if(resize_mode_ == stretch) { ERR_GUI_D << "Image: failed to stretch image, " "fall back to scaling.\n"; } DBG_GUI_D << "Image: scaling from " << image_->w << ',' << image_->h << " to " << w << ',' << h << ".\n"; surf = scale_surface(image_, w, h, false); } } src_clip.w = w; src_clip.h = h; } else { surf = image_; } if(vertical_mirror_(local_variables)) { surf = flip_surface(surf, false); } blit_surface(surf, &src_clip, canvas, &dst_clip); }