void mouse_action::set_terrain_mouse_overlay(editor_display& disp, const t_translation::t_terrain & fg, const t_translation::t_terrain & bg) { surface image_fg(image::get_image(disp.get_map().get_terrain_info(fg).editor_image())); surface image_bg(image::get_image(disp.get_map().get_terrain_info(bg).editor_image())); if (image_fg == nullptr || image_bg == nullptr) { ERR_ED << "Missing terrain icon" << std::endl; disp.set_mouseover_hex_overlay(nullptr); return; } // Create a transparent surface of the right size. surface image = create_neutral_surface(image_fg->w, image_fg->h); // For efficiency the size of the tile is cached. // We assume all tiles are of the same size. // The zoom factor can change, so it's not cached. // NOTE: when zooming and not moving the mouse, there are glitches. // Since the optimal alpha factor is unknown, it has to be calculated // on the fly, and caching the surfaces makes no sense yet. static const fixed_t alpha = 196; static const int size = image_fg->w; static const int half_size = size / 2; static const int quarter_size = size / 4; static const int offset = 2; static const int new_size = half_size - 2; // Blit left side image_fg = scale_surface(image_fg, new_size, new_size); SDL_Rect rcDestLeft = sdl::create_rect(offset, quarter_size, 0, 0); blit_surface ( image_fg, nullptr, image, &rcDestLeft ); // Blit right side image_bg = scale_surface(image_bg, new_size, new_size); SDL_Rect rcDestRight = sdl::create_rect(half_size, quarter_size, 0, 0); blit_surface ( image_bg, nullptr, image, &rcDestRight ); //apply mask so the overlay is contained within the mouseover hex image = mask_surface(image, image::get_hexmask()); // Add the alpha factor image = adjust_surface_alpha(image, alpha); // scale the image const int zoom = disp.hex_size(); if (zoom != game_config::tile_size) { image = scale_surface(image, zoom, zoom); } // Set as mouseover disp.set_mouseover_hex_overlay(image); }
void mouse_action::set_terrain_mouse_overlay(editor_display& disp, t_translation::t_terrain fg, t_translation::t_terrain bg) { surface image_fg(image::get_image("terrain/" + disp.get_map().get_terrain_info(fg).editor_image() + ".png")); surface image_bg(image::get_image("terrain/" + disp.get_map().get_terrain_info(bg).editor_image() + ".png")); if (image_fg == NULL || image_bg == NULL) { ERR_ED << "Missing terrain icon\n"; disp.set_mouseover_hex_overlay(NULL); return; } // Create a transparent surface of the right size. surface image = create_compatible_surface(image_fg, image_fg->w, image_fg->h); SDL_FillRect(image,NULL,SDL_MapRGBA(image->format,0,0,0, 0)); // For efficiency the size of the tile is cached. // We assume all tiles are of the same size. // The zoom factor can change, so it's not cached. // NOTE: when zooming and not moving the mouse, there are glitches. // Since the optimal alpha factor is unknown, it has to be calculated // on the fly, and caching the surfaces makes no sense yet. static const Uint8 alpha = 196; static const int size = image_fg->w; static const int half_size = size / 2; static const int quarter_size = size / 4; static const int offset = 2; static const int new_size = half_size - 2; const int zoom = static_cast<int>(size * disp.get_zoom_factor()); // Blit left side image_fg = scale_surface(image_fg, new_size, new_size); SDL_Rect rcDestLeft = { offset, quarter_size, 0, 0 }; SDL_BlitSurface ( image_fg, NULL, image, &rcDestLeft ); // Blit left side image_bg = scale_surface(image_bg, new_size, new_size); SDL_Rect rcDestRight = { half_size, quarter_size, 0, 0 }; SDL_BlitSurface ( image_bg, NULL, image, &rcDestRight ); //apply mask so the overlay is contained within the mouseover hex surface mask(image::get_image("terrain/alphamask.png")); image = mask_surface(image, mask); // Add the alpha factor and scale the image image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom); // Set as mouseover disp.set_mouseover_hex_overlay(image); }
void terrain_palette::draw_item(const t_translation::t_terrain& terrain, surface& image, std::stringstream& tooltip_text) { const t_translation::t_terrain base_terrain = map().get_terrain_info(terrain).default_base(); //Draw default base for overlay terrains if(base_terrain != t_translation::NONE_TERRAIN) { const std::string base_filename = map().get_terrain_info(base_terrain).editor_image(); surface base_image(image::get_image(base_filename)); if(base_image == nullptr) { tooltip_text << "BASE IMAGE NOT FOUND\n"; ERR_ED << "image for terrain : '" << base_filename << "' not found" << std::endl; base_image = image::get_image(game_config::images::missing); if (base_image == nullptr) { ERR_ED << "Placeholder image not found" << std::endl; return; } } if(base_image->w != item_size_ || base_image->h != item_size_) { base_image.assign(scale_surface(base_image, item_size_, item_size_)); } } const std::string filename = map().get_terrain_info(terrain).editor_image(); image = image::get_image(filename); if(image == nullptr) { tooltip_text << "IMAGE NOT FOUND\n"; ERR_ED << "image for terrain: '" << filename << "' not found" << std::endl; image = image::get_image(game_config::images::missing); if (image == nullptr) { ERR_ED << "Placeholder image not found" << std::endl; return; } } if(image->w != item_size_ || image->h != item_size_) { image.assign(scale_surface(image, item_size_, item_size_)); } tooltip_text << map().get_terrain_editor_string(terrain); if (gui_.get_draw_terrain_codes()) { tooltip_text << " " + utils::unicode_em_dash + " " << terrain; } }
floating_image::render_input floating_image::get_render_input(double xscale, double yscale, SDL_Rect& dst_rect) const { render_input ri = { {0,0,0,0}, file_.empty() ? nullptr : image::get_image(file_) }; if(!ri.image.null()) { if(autoscaled_) { ri.image = scale_surface( ri.image, static_cast<int>(ri.image->w * xscale), static_cast<int>(ri.image->h * yscale) ); } ri.rect.x = static_cast<int>(x_*xscale) + dst_rect.x; ri.rect.y = static_cast<int>(y_*yscale) + dst_rect.y; ri.rect.w = ri.image->w; ri.rect.h = ri.image->h; if(centered_) { ri.rect.x -= ri.rect.w / 2; ri.rect.y -= ri.rect.h / 2; } } return ri; }
void item_palette::draw_item(const overlay& item, surface& image, std::stringstream& tooltip_text) { std::stringstream filename; filename << item.image; if(item.image.empty()) { filename << item.halo; } image = image::get_image(filename.str()); if(image == nullptr) { tooltip_text << "IMAGE NOT FOUND\n"; ERR_ED << "image for item type: '" << filename.str() << "' not found" << std::endl; image = image::get_image(game_config::images::missing); if(image == nullptr) { ERR_ED << "Placeholder image not found" << std::endl; return; } } if(image->w != item_size_ || image->h != item_size_) { image.assign(scale_surface(image, item_size_, item_size_)); } tooltip_text << item.name; }
/* @brief Draw an image at the given offset. * * @param cr A cairo context for drawing to the screen. * @param file The image to be drawn. * @return The advance in the x direction. */ static uint32_t draw_image(cairo_t *cr, const char *file, offset_t offset) { wordexp_t expanded_file; if (wordexp(file, &expanded_file, 0)) { fprintf(stderr, "Error expanding file %s\n", file); } else { file = expanded_file.we_wordv[0]; } if (access(file, F_OK) == -1) { fprintf(stderr, "Cannot open image file %s\n", file); return 0; } cairo_surface_t *img; img = cairo_image_surface_create_from_png(file); int w = cairo_image_surface_get_width(img); int h = cairo_image_surface_get_height(img); int neww = (int)(((float)(settings.height) * ((float)(w) / (float)(h))) + 0.49999999); img = scale_surface (img, w, h, neww, settings.height); h = settings.height; w = neww; /* Attempt to center the image if it is not the height of the line. */ int image_offset = (h - settings.height) / 2; cairo_set_source_surface(cr, img, offset.x, offset.image_y - h + image_offset); cairo_mask_surface(cr, img, offset.x, offset.image_y - h + image_offset); return w; }
/* Load a file image in the window. */ static void load_file () { if (background_data->background_cr) { cairo_surface_t *surface = cairo_image_surface_create_from_png (background_data->background_image); cairo_t *cr = cairo_create (surface); gtk_window_set_opacity (GTK_WINDOW (background_data->background_window), 1.0); gint new_height = 0; gint new_width = 0; new_height = gdk_window_get_height (gtk_widget_get_window (background_data->background_window)); new_width = gdk_window_get_width (gtk_widget_get_window (background_data->background_window)); cairo_surface_t *scaled_surface = scale_surface (surface, new_width, new_height ); cairo_surface_destroy (surface); cairo_destroy (cr); cairo_set_source_surface (background_data->background_cr, scaled_surface, 0.0, 0.0); cairo_paint (background_data->background_cr); cairo_stroke (background_data->background_cr); cairo_surface_destroy (scaled_surface); #ifndef _WIN32 gtk_widget_input_shape_combine_region (background_data->background_window, NULL); #endif } }
surface campaign::create_image_surface(const SDL_Rect& image_rect) { surface temp_image( image::get_image(image::locator(image_label_))); return scale_surface(temp_image, image_rect.w, image_rect.h); }
void unit_palette::draw_item(SDL_Rect& dstrect, const unit_type& u, std::stringstream& tooltip_text) { surface screen = gui_.video().getSurface(); const std::string filename = u.image(); surface image(image::get_image(filename)); if(image == NULL) { tooltip_text << "IMAGE NOT FOUND\n"; ERR_ED << "image for terrain: '" << filename << "' not found\n"; image = image::get_image(game_config::images::missing); if (image == NULL) { ERR_ED << "Placeholder image not found\n"; return; } } if(image->w != item_size_ || image->h != item_size_) { image.assign(scale_surface(image, item_size_, item_size_)); } sdl_blit(image, NULL, screen, &dstrect); tooltip_text << u.type_name(); }
surface scale_function::operator()(const surface& src) const { const int old_w = src->w; const int old_h = src->h; int w = w_; int h = h_; if(w <= 0) { if(w < 0) { ERR_DP << "width of SCALE is negative - resetting to original width\n"; } w = old_w; } if(h <= 0) { if(h < 0) { ERR_DP << "height of SCALE is negative - resetting to original height\n"; } h = old_h; } return( (w != old_w || h != old_h) ? scale_surface(src, w, h) : src ); }
void part_ui::render_story_box_borders(SDL_Rect& update_area) { const part::BLOCK_LOCATION tbl = p_.story_text_location(); if(has_background_) { surface border_top = NULL; surface border_bottom = NULL; if(tbl == part::BLOCK_BOTTOM || tbl == part::BLOCK_MIDDLE) { border_top = image::get_image(storybox_top_border_path); } if(tbl == part::BLOCK_TOP || tbl == part::BLOCK_MIDDLE) { border_bottom = image::get_image(storybox_bottom_border_path); } // // If one of those are null at this point, it means that either we // don't need that border pic, or it is missing (in such case get_image() // would report). // if(border_top.null() != true) { if((border_top = scale_surface(border_top, screen_area().w, border_top->h)).null()) { WARN_NG << "storyscreen got a null top border surface after rescaling\n"; } else { update_area.y -= border_top->h; update_area.h += border_top->h; blur_area(video_, update_area.y, border_top->h); video_.blit_surface(0, update_area.y, border_top); } } if(border_bottom.null() != true) { if((border_bottom = scale_surface(border_bottom, screen_area().w, border_bottom->h)).null()) { WARN_NG << "storyscreen got a null bottom border surface after rescaling\n"; } else { blur_area(video_, update_area.h, border_bottom->h); video_.blit_surface(0, update_area.y+update_area.h, border_bottom); update_area.h += border_bottom->h; } } } }
static cairo_surface_t * get_surface_from_pixbuf (GdkPixbuf *pixbuf, MetaImageFillType fill_type, gdouble width, gdouble height, gboolean vertical_stripes, gboolean horizontal_stripes) { gdouble pixbuf_width; gdouble pixbuf_height; cairo_surface_t *surface; cairo_content_t content; cairo_surface_t *copy; cairo_t *cr; pixbuf_width = gdk_pixbuf_get_width (pixbuf); pixbuf_height = gdk_pixbuf_get_height (pixbuf); surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL); if (pixbuf_width == width && pixbuf_height == height) { return surface; } if (fill_type != META_IMAGE_FILL_TILE) { cairo_surface_t *scaled; scaled = scale_surface (surface, pixbuf_width, pixbuf_height, width, height, vertical_stripes, horizontal_stripes); cairo_surface_destroy (surface); surface = scaled; } content = CAIRO_CONTENT_COLOR_ALPHA; width = ceil (width); height = ceil (height); copy = cairo_surface_create_similar (surface, content, width, height); cr = cairo_create (copy); cairo_set_source_surface (cr, surface, 0, 0); if (fill_type == META_IMAGE_FILL_TILE || vertical_stripes || horizontal_stripes) { cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT); } cairo_paint (cr); cairo_destroy (cr); cairo_surface_destroy (surface); return copy; }
button::button(CVideo& video, const std::string& label, button::TYPE type, std::string button_image_name, SPACE_CONSUMPTION spacing, const bool auto_join) : widget(video, auto_join), type_(type), label_(label), image_(NULL), pressedImage_(NULL), activeImage_(NULL), pressedActiveImage_(NULL), button_(true), state_(NORMAL), pressed_(false), spacing_(spacing), base_height_(0), base_width_(0) { if(button_image_name.empty() && type == TYPE_PRESS) { button_image_name = "button"; } else if(button_image_name.empty() && type == TYPE_CHECK) { button_image_name = "checkbox"; } const std::string button_image_file = "buttons/" + button_image_name + ".png"; surface button_image(image::get_image(button_image_file)); surface pressed_image(image::get_image("buttons/" + button_image_name + "-pressed.png")); surface active_image(image::get_image("buttons/" + button_image_name + "-active.png")); surface pressed_active_image; if (pressed_image.null()) pressed_image.assign(button_image); if (active_image.null()) active_image.assign(button_image); if (type == TYPE_CHECK) { pressed_active_image.assign(image::get_image("buttons/" + button_image_name + "-active-pressed.png")); if (pressed_active_image.null()) pressed_active_image.assign(pressed_image); } if (button_image.null()) { ERR_DP << "error initializing button!\n"; throw error(); } base_height_ = button_image->h; base_width_ = button_image->w; if (type_ != TYPE_IMAGE){ set_label(label); } if(type == TYPE_PRESS) { image_.assign(scale_surface(button_image,location().w,location().h)); pressedImage_.assign(scale_surface(pressed_image,location().w,location().h)); activeImage_.assign(scale_surface(active_image,location().w,location().h)); } else { image_.assign(scale_surface(button_image,button_image->w,button_image->h)); pressedImage_.assign(scale_surface(pressed_image,button_image->w,button_image->h)); activeImage_.assign(scale_surface(active_image,button_image->w,button_image->h)); if (type == TYPE_CHECK) pressedActiveImage_.assign(scale_surface(pressed_active_image, button_image->w, button_image->h)); } if (type_ == TYPE_IMAGE){ calculate_size(); } }
surface light_modification::operator()(const surface& src) const { if(src == NULL) { return NULL; } //light_surface wants a neutral surface having same dimensions surface nsurf; if(surf_->w != src->w || surf_->h != src->h) nsurf = scale_surface(surf_, src->w, src->h, false); else nsurf = make_neutral_surface(surf_); return light_surface(src, nsurf);; }
void mouse_action_starting_position::set_mouse_overlay(editor_display& disp) { surface image = image::get_image("editor/tool-overlay-starting-position.png"); Uint8 alpha = 196; int size = image->w; int zoom = static_cast<int>(size * disp.get_zoom_factor()); // Add the alpha factor and scale the image image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom); disp.set_mouseover_hex_overlay(image); }
void dialog_frame::draw_border() { if(have_border_ == false) { return; } surface top_image(scale_surface(top_, dim_.interior.w, top_->h)); if(top_image != NULL) { video_.blit_surface(dim_.interior.x, dim_.exterior.y, top_image); } surface bot_image(scale_surface(bot_, dim_.interior.w, bot_->h)); if(bot_image != NULL) { video_.blit_surface(dim_.interior.x, dim_.interior.y + dim_.interior.h, bot_image); } surface left_image(scale_surface(left_, left_->w, dim_.interior.h)); if(left_image != NULL) { video_.blit_surface(dim_.exterior.x, dim_.interior.y, left_image); } surface right_image(scale_surface(right_, right_->w, dim_.interior.h)); if(right_image != NULL) { video_.blit_surface(dim_.interior.x + dim_.interior.w, dim_.interior.y, right_image); } update_rect(dim_.exterior); if(top_left_ == NULL || bot_left_ == NULL || top_right_ == NULL || bot_right_ == NULL) { return; } video_.blit_surface(dim_.interior.x - left_->w, dim_.interior.y - top_->h, top_left_); video_.blit_surface(dim_.interior.x - left_->w, dim_.interior.y + dim_.interior.h + bot_->h - bot_left_->h, bot_left_); video_.blit_surface(dim_.interior.x + dim_.interior.w + right_->w - top_right_->w, dim_.interior.y - top_->h, top_right_); video_.blit_surface(dim_.interior.x + dim_.interior.w + right_->w - bot_right_->w, dim_.interior.y + dim_.interior.h + bot_->h - bot_right_->h, bot_right_); }
floating_image::render_input floating_image::get_render_input(double xscale, double yscale, SDL_Rect& dst_rect) const { #ifdef SDL_GPU render_input ri = { {0,0,0,0}, file_.empty() ? sdl::timage() : image::get_texture(file_) }; if(!ri.image.null()) { if(autoscaled_) { ri.image.set_scale(xscale, yscale); } ri.rect.x = static_cast<int>(x_*xscale) + dst_rect.x; ri.rect.y = static_cast<int>(y_*yscale) + dst_rect.y; ri.rect.w = ri.image.width(); ri.rect.h = ri.image.height(); if(centered_) { ri.rect.x -= ri.rect.w / 2; ri.rect.y -= ri.rect.h / 2; } } return ri; #else render_input ri = { {0,0,0,0}, file_.empty() ? nullptr : image::get_image(file_) }; if(!ri.image.null()) { if(autoscaled_) { ri.image = scale_surface( ri.image, static_cast<int>(ri.image->w * xscale), static_cast<int>(ri.image->h * yscale) ); } ri.rect.x = static_cast<int>(x_*xscale) + dst_rect.x; ri.rect.y = static_cast<int>(y_*yscale) + dst_rect.y; ri.rect.w = ri.image->w; ri.rect.h = ri.image->h; if(centered_) { ri.rect.x -= ri.rect.w / 2; ri.rect.y -= ri.rect.h / 2; } } return ri; #endif }
static void scale(surface& surf, const std::string& parameters) { unsigned width, height; const int count = sscanf(parameters.c_str(), "%u,%u", &width, &height); if(count != 2) { std::cerr << "Error: Arguments to scale »" << parameters << "« are not compatible.\n"; throw texit(EXIT_FAILURE); } surf = scale_surface(surf, width, height); }
void mouse_action_select::set_mouse_overlay(editor_display& disp) { surface image; if (has_shift_modifier()) { image = image::get_image("editor/tool-overlay-select-wand.png"); } else { image = image::get_image("editor/tool-overlay-select-brush.png"); } Uint8 alpha = 196; int size = image->w; int zoom = static_cast<int>(size * disp.get_zoom_factor()); // Add the alpha factor and scale the image image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom); disp.set_mouseover_hex_overlay(image); }
void tcontrol::set_surface(const surface& surf, int w, int h) { size_t count = canvas_.size(); surfs_.clear(); surfs_.resize(count); if (!surf || !count) { return; } surface normal = scale_surface(surf, w, h); for (size_t n = 0; n < count; n ++) { surfs_[n] = normal; } set_dirty(); }
void menu::imgsel_style::draw_row_bg(menu& menu_ref, const size_t row_index, const SDL_Rect& rect, ROW_TYPE type) { if(type == SELECTED_ROW && has_background_ && !load_failed_) { if(bg_cache_.width != rect.w || bg_cache_.height != rect.h) { //draw scaled background image //scale image each time (to prevent loss of quality) bg_cache_.surf = scale_surface(img_map_["background"], rect.w, rect.h); bg_cache_.width = rect.w; bg_cache_.height = rect.h; } SDL_Rect clip = rect; menu_ref.video().blit_surface(rect.x,rect.y,bg_cache_.surf,nullptr,&clip); } else { style::draw_row_bg(menu_ref, row_index, rect, type); } }
void mouse_action_unit::set_unit_mouse_overlay(editor_display& disp, const unit_type& u) { std::stringstream filename; filename << u.image() << "~RC(" << u.flag_rgb() << '>' << team::get_side_color_index(disp.viewing_side()) << ')'; surface image(image::get_image(filename.str())); Uint8 alpha = 196; //TODO don't hardcode int size = 72; //int size = image->w; int zoom = static_cast<int>(size * disp.get_zoom_factor()); // Add the alpha factor and scale the image image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom); disp.set_mouseover_hex_overlay(image); }
void mouse_action_village::set_mouse_overlay(editor_display& disp) { surface image60 = image::get_image("icons/action/editor-tool-village_60.png"); //TODO avoid hardcoded hex field size surface image = create_neutral_surface(72,72); SDL_Rect r = sdl::create_rect(6, 6, 0, 0); blit_surface(image60, NULL, image, &r); Uint8 alpha = 196; int size = image->w; int zoom = static_cast<int>(size * disp.get_zoom_factor()); // Add the alpha factor and scale the image image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom); disp.set_mouseover_hex_overlay(image); }
surface menu::style::get_item_image(const image::locator& img_loc) const { surface surf = image::get_image(img_loc); if(!surf.null()) { int scale = 100; if(max_img_w_ > 0 && surf->w > max_img_w_) { scale = (max_img_w_ * 100) / surf->w; } if(max_img_h_ > 0 && surf->h > max_img_h_) { scale = std::min<int>(scale, ((max_img_h_ * 100) / surf->h)); } if(scale != 100) { return scale_surface(surf, (scale * surf->w)/100, (scale * surf->h)/100); } } return surf; }
void part_ui::prepare_background() { // Build background surface if(p_.background().empty() != true) { background_.assign( image::get_image(p_.background()) ); } has_background_ = !background_.null(); if(background_.null() || background_->w * background_-> h == 0) { background_.assign( create_neutral_surface(video_.getx(), video_.gety()) ); } const double xscale = 1.0 * video_.getx() / background_->w; const double yscale = 1.0 * video_.gety() / background_->h; scale_factor_ = p_.scale_background() ? std::min<double>(xscale,yscale) : 1.0; background_ = scale_surface(background_, static_cast<int>(background_->w*scale_factor_), static_cast<int>(background_->h*scale_factor_)); ASSERT_LOG(background_.null() == false, "Oops: storyscreen part background got NULL"); }
surface scale_modification::operator()(const surface& src) const { const int old_w = src->w; const int old_h = src->h; int w = w_; int h = h_; if(w <= 0) { if(w < 0) { ERR_DP << "width of SCALE is negative - resetting to original width" << std::endl; } w = old_w; } if(h <= 0) { if(h < 0) { ERR_DP << "height of SCALE is negative - resetting to original height" << std::endl; } h = old_h; } return scale_surface(src, w, h); }
void unit_palette::draw_item(const unit_type& u, surface& image, std::stringstream& tooltip_text) { std::stringstream filename; filename << u.image() << "~RC(" << u.flag_rgb() << '>' << team::get_side_color_id(gui_.viewing_side()) << ')'; image = image::get_image(filename.str()); if(image == nullptr) { tooltip_text << "IMAGE NOT FOUND\n"; ERR_ED << "image for unit type: '" << filename.str() << "' not found" << std::endl; image = image::get_image(game_config::images::missing); if(image == nullptr) { ERR_ED << "Placeholder image not found" << std::endl; return; } } if(image->w != item_size_ || image->h != item_size_) { image.assign(scale_surface(image, item_size_, item_size_)); } tooltip_text << u.type_name(); }
void part_ui::render_story_box_borders(SDL_Rect& update_area) { #ifdef SDL_GPU const part::BLOCK_LOCATION tbl = p_.story_text_location(); if(has_background_) { sdl::timage border_top; sdl::timage border_bottom; if(tbl == part::BLOCK_BOTTOM || tbl == part::BLOCK_MIDDLE) { border_top = image::get_texture(storybox_top_border_path); } if(tbl == part::BLOCK_TOP || tbl == part::BLOCK_MIDDLE) { border_bottom = image::get_texture(storybox_bottom_border_path); } // // If one of those are null at this point, it means that either we // don't need that border pic, or it is missing (in such case get_image() // would report). // if(border_top.null() != true) { const float xscale = float(screen_area().w) / border_top.base_width(); border_top.set_hscale(xscale); //TODO: blurring video_.draw_texture(border_top, 0, update_area.y - border_top.base_height()); } if(border_bottom.null() != true) { const float xscale = float(screen_area().w) / border_bottom.base_width(); border_bottom.set_hscale(xscale); //TODO: blurring video_.draw_texture(border_bottom, 0, update_area.y - border_top.base_height()); } } #else const part::BLOCK_LOCATION tbl = p_.story_text_location(); if(has_background_) { surface border_top = NULL; surface border_bottom = NULL; if(tbl == part::BLOCK_BOTTOM || tbl == part::BLOCK_MIDDLE) { border_top = image::get_image(storybox_top_border_path); } if(tbl == part::BLOCK_TOP || tbl == part::BLOCK_MIDDLE) { border_bottom = image::get_image(storybox_bottom_border_path); } // // If one of those are null at this point, it means that either we // don't need that border pic, or it is missing (in such case get_image() // would report). // if(border_top.null() != true) { if((border_top = scale_surface(border_top, screen_area().w, border_top->h)).null()) { WARN_NG << "storyscreen got a null top border surface after rescaling" << std::endl; } else { update_area.y -= border_top->h; update_area.h += border_top->h; blur_area(video_, update_area.y, border_top->h); video_.blit_surface(0, update_area.y, border_top); } } if(border_bottom.null() != true) { if((border_bottom = scale_surface(border_bottom, screen_area().w, border_bottom->h)).null()) { WARN_NG << "storyscreen got a null bottom border surface after rescaling" << std::endl; } else { blur_area(video_, update_area.h, border_bottom->h); video_.blit_surface(0, update_area.y+update_area.h, border_bottom); update_area.h += border_bottom->h; } } } #endif }
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); }
void button::load_images() { std::string size_postfix; switch (location().h) { case 25: size_postfix = "_25"; break; case 30: size_postfix = "_30"; break; case 60: size_postfix = "_60"; break; default: break; } surface button_image(image::get_image(button_image_name_ + ".png" + button_image_path_suffix_)); surface pressed_image(image::get_image(button_image_name_ + "-pressed.png"+ button_image_path_suffix_)); surface active_image(image::get_image(button_image_name_ + "-active.png"+ button_image_path_suffix_)); surface disabled_image; if (file_exists(game_config::path + "/images/" + button_image_name_ + "-disabled.png"+ button_image_path_suffix_)) disabled_image.assign((image::get_image(button_image_name_ + "-disabled.png"+ button_image_path_suffix_))); surface pressed_disabled_image, pressed_active_image, touched_image; if (!button_overlay_image_name_.empty()) { overlayImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + ".png"+ button_image_path_suffix_)); overlayPressedImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-pressed.png"+ button_image_path_suffix_)); if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_)) overlayActiveImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_)); if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_)) overlayDisabledImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_)); if (overlayDisabledImage_.null()) overlayDisabledImage_ = image::get_image(button_overlay_image_name_ + size_postfix + ".png~GS()" + button_image_path_suffix_); if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_)) overlayPressedDisabledImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_)); if (overlayPressedDisabledImage_.null()) overlayPressedDisabledImage_ = image::get_image(button_overlay_image_name_ + size_postfix + "-pressed.png~GS()"+ button_image_path_suffix_); } else { overlayImage_.assign(NULL); } if (disabled_image == NULL) { disabled_image = image::get_image(button_image_name_ + ".png~GS()" + button_image_path_suffix_); } if (pressed_image.null()) pressed_image.assign(button_image); if (active_image.null()) active_image.assign(button_image); if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) { touched_image.assign(image::get_image(button_image_name_ + "-touched.png"+ button_image_path_suffix_)); if (touched_image.null()) touched_image.assign(pressed_image); pressed_active_image.assign(image::get_image(button_image_name_ + "-active-pressed.png"+ button_image_path_suffix_)); if (pressed_active_image.null()) pressed_active_image.assign(pressed_image); if (file_exists(game_config::path + "/images/" + button_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_)) pressed_disabled_image.assign(image::get_image(button_image_name_ + "-disabled-pressed.png"+ button_image_path_suffix_)); if (pressed_disabled_image.null()) pressed_disabled_image = image::get_image(button_image_name_ + "-pressed.png~GS()"+ button_image_path_suffix_); } if (button_image.null()) { ERR_DP << "error initializing button!\n"; throw error(); } base_height_ = button_image->h; base_width_ = button_image->w; if (type_ != TYPE_IMAGE) { set_label(label_); } if(type_ == TYPE_PRESS || type_ == TYPE_TURBO) { image_.assign(scale_surface(button_image,location().w,location().h)); pressedImage_.assign(scale_surface(pressed_image,location().w,location().h)); activeImage_.assign(scale_surface(active_image,location().w,location().h)); disabledImage_.assign(scale_surface(disabled_image,location().w,location().h)); } else { image_.assign(scale_surface(button_image,button_image->w,button_image->h)); activeImage_.assign(scale_surface(active_image,button_image->w,button_image->h)); disabledImage_.assign(scale_surface(disabled_image,button_image->w,button_image->h)); pressedImage_.assign(scale_surface(pressed_image,button_image->w,button_image->h)); if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) { pressedDisabledImage_.assign(scale_surface(pressed_disabled_image,button_image->w,button_image->h)); pressedActiveImage_.assign(scale_surface(pressed_active_image, button_image->w, button_image->h)); touchedImage_.assign(scale_surface(touched_image, button_image->w, button_image->h)); } } if (type_ == TYPE_IMAGE){ calculate_size(); } }