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); }