Skip to content

Commit

Permalink
adjust some of the editor images code for terrain overlays
Browse files Browse the repository at this point in the history
the adjustments just make it use the more standard SDL utils fcns
for making a transparent (neutral) surface, and they avoid floating
point operations when scaling images

we also fix a bug caused by using "sdl_blit" instead of
"blit_surface", which caused the terrain overlay not to show up
  • Loading branch information
cbeck88 committed Nov 14, 2014
1 parent 6ad819d commit b309afd
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/editor/action/mouse/mouse_action.cpp
Expand Up @@ -155,38 +155,42 @@ void mouse_action::set_terrain_mouse_overlay(editor_display& disp, const t_trans
}

// Create a transparent surface of the right size.
surface image = create_compatible_surface(image_fg, image_fg->w, image_fg->h);
sdl::fill_rect(image,NULL,SDL_MapRGBA(image->format,0,0,0, 0));
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 Uint8 alpha = 196;
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;
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 = sdl::create_rect(offset, quarter_size, 0, 0);
sdl_blit ( image_fg, NULL, image, &rcDestLeft );
blit_surface ( image_fg, NULL, 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);
sdl_blit ( image_bg, NULL, image, &rcDestRight );
blit_surface ( image_bg, NULL, image, &rcDestRight );

//apply mask so the overlay is contained within the mouseover hex
image = mask_surface(image, image::get_hexmask());

// Add the alpha factor and scale the image
image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);
// 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);
Expand Down

0 comments on commit b309afd

Please sign in to comment.