Skip to content

Commit

Permalink
Fixed some bad drawing offsets and sizes when zoomed in
Browse files Browse the repository at this point in the history
This fixes HP/XP bar size (wasn't scaled to zoom) and placement, as well as crown/orb and main sprite placement.
  • Loading branch information
Vultraz committed Jul 9, 2017
1 parent 728d761 commit 725eac9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
20 changes: 9 additions & 11 deletions src/units/drawer.cpp
Expand Up @@ -272,8 +272,8 @@ void unit_drawer::redraw_unit(const unit & u) const

const texture::info unit_img_info = unit_img.get_info();

const int xoff = unit_img.null() ? hex_size_by_2 : (hex_size - unit_img_info.w) / 2;
const int yoff = unit_img.null() ? hex_size_by_2 : (hex_size - unit_img_info.h) / 2;
const int xoff = unit_img.null() ? hex_size_by_2 : (hex_size - (unit_img_info.w * zoom_factor)) / 2;
const int yoff = unit_img.null() ? hex_size_by_2 : (hex_size - (unit_img_info.h * zoom_factor)) / 2;

const image::locator partmoved_orb(
game_config::images::orb + "~RC(magenta>" + preferences::partial_color() + ")");
Expand Down Expand Up @@ -380,11 +380,6 @@ void unit_drawer::redraw_unit(const unit & u) const

void unit_drawer::draw_bar(int xpos, int ypos, size_t height, double filled, color_t col, fixed_t alpha) const
{
filled = utils::clamp<double>(filled, 0.0, 1.0);
height = static_cast<size_t>(height * zoom_factor);

const size_t unfilled = static_cast<size_t>(height * (1.0 - filled));

// Magic width number
static unsigned int bar_width = 4;

Expand All @@ -400,10 +395,13 @@ void unit_drawer::draw_bar(int xpos, int ypos, size_t height, double filled, col
// much to make it line up with the crowns as before. Should probably compensate for this better
// in the future.
SDL_Rect bar_rect;
bar_rect.x = xpos + 19;
bar_rect.y = ypos + 13;
bar_rect.w = bar_width;
bar_rect.h = height;
bar_rect.x = xpos + (19 * zoom_factor);
bar_rect.y = ypos + (13 * zoom_factor);
bar_rect.w = bar_width * zoom_factor;
bar_rect.h = height * zoom_factor;

filled = utils::clamp<double>(filled, 0.0, 1.0);
const size_t unfilled = static_cast<size_t>(bar_rect.h * (1.0 - filled));

// Filled area dimensions.
SDL_Rect fill_rect;
Expand Down
4 changes: 2 additions & 2 deletions src/units/frame.cpp
Expand Up @@ -541,8 +541,8 @@ void unit_frame::redraw(const int frame_time, bool on_start_time, bool in_scope_

const texture::info info = image.get_info();

int my_x = x + current_data.x - info.w / 2;
int my_y = y + current_data.y - info.h / 2;
int my_x = x + current_data.x - ((info.w / 2) * game_disp->get_zoom_factor());
int my_y = y + current_data.y - ((info.h / 2) * game_disp->get_zoom_factor());

if(facing_west) {
my_x -= current_data.directional_x;
Expand Down

0 comments on commit 725eac9

Please sign in to comment.