Skip to content

Commit

Permalink
Remove sdl::create_rect in favour of just creating a rect
Browse files Browse the repository at this point in the history
  • Loading branch information
mesilliac committed Jul 1, 2022
1 parent aa60879 commit 8051d52
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ static surface load_image_sub_file(const image::locator& loc)
}

if(loc.get_loc().valid()) {
SDL_Rect srcrect = sdl::create_rect(
rect srcrect(
((tile_size * 3) / 4) * loc.get_loc().x,
tile_size * loc.get_loc().y + (tile_size / 2) * (loc.get_loc().x % 2),
tile_size,
Expand Down
11 changes: 0 additions & 11 deletions src/sdl/rect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ namespace sdl

constexpr const SDL_Rect empty_rect { 0, 0, 0, 0 };

/**
* Creates an SDL_Rect with the given dimensions.
*
* This is a simple wrapper in order to avoid the narrowing conversion warnings
* that occur when using aggregate initialization and non-int values.
*/
inline SDL_Rect create_rect(const int x, const int y, const int w, const int h)
{
return {x, y, w, h};
}

} // namespace sdl

bool operator==(const SDL_Rect& a, const SDL_Rect& b);
Expand Down
6 changes: 3 additions & 3 deletions src/units/drawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ void unit_drawer::draw_bar(const std::string& image, int xpos, int ypos,

const std::size_t skip_rows = bar_loc.h - height;

SDL_Rect top {0, 0, surf->w, bar_loc.y};
SDL_Rect bot = sdl::create_rect(0, bar_loc.y + skip_rows, surf->w, 0);
rect top{0, 0, surf->w, bar_loc.y};
rect bot(0, bar_loc.y + skip_rows, surf->w, 0);
bot.h = surf->w - bot.y;

// TODO: highdpi - fix. see above
Expand All @@ -456,7 +456,7 @@ void unit_drawer::draw_bar(const std::string& image, int xpos, int ypos,
if(unfilled < height && alpha >= floating_to_fixed_point(0.3)) {
const uint8_t r_alpha = std::min<unsigned>(fixed_point_multiply(alpha,255),255);
surface filled_surf(bar_loc.w, height - unfilled);
SDL_Rect filled_area = sdl::create_rect(0, 0, bar_loc.w, height-unfilled);
rect filled_area(0, 0, bar_loc.w, height-unfilled);
sdl::fill_surface_rect(filled_surf,&filled_area,SDL_MapRGBA(bar_surf->format,col.r,col.g,col.b, r_alpha));
dest = {xpos + bar_loc.x, ypos + bar_loc.y + int(unfilled),
filled_surf->w, filled_surf->h};
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,9 +1088,9 @@ SDL_Rect menu::get_item_rect_internal(std::size_t item) const
y = prev.y + prev.h;
}

SDL_Rect res = sdl::create_rect(loc.x, y, loc.w, get_item_height(item));
rect res(loc.x, y, loc.w, get_item_height(item));

const SDL_Rect& draw_area = video().draw_area();
const rect draw_area = video().draw_area();

if(res.x > draw_area.w) {
return sdl::empty_rect;
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/textbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ void textbox::draw_contents()
break;
}

SDL_Rect rect = sdl::create_rect(loc.x + startx
rect r(loc.x + startx
, loc.y + starty - src.y
, right - startx
, line_height_);

draw::fill(rect, 0, 0, 160, 140);
draw::fill(r, 0, 0, 160, 140);

starty += int(line_height_);
startx = 0;
Expand Down

0 comments on commit 8051d52

Please sign in to comment.