Some small rendering fixes.
* halo background draw fixed * tiled images clip correctly * new interface/setter for reducing clipping area.
This commit is contained in:
parent
0baa83666e
commit
f183978071
5 changed files with 37 additions and 10 deletions
|
@ -281,8 +281,10 @@ void draw::flipped(const texture& tex, bool flip_h, bool flip_v)
|
|||
void draw::tiled(const texture& tex, const SDL_Rect& dst, bool centered,
|
||||
bool mirrored)
|
||||
{
|
||||
// TODO: highdpi - should this draw at full res? Or game res? For now it's using game res to ensure consistency of the result.
|
||||
// TODO: highdpi - does this ever need to clip the source texture? It doesn't seem so
|
||||
// TODO: highdpi - should this draw at full res? Or game res? For now it's using game res. To draw in higher res, width and height would have to be specified.
|
||||
|
||||
// Reduce clip to dst.
|
||||
auto clipper = CVideo::get_singleton().reduce_clip(dst);
|
||||
|
||||
const int xoff = centered ? (dst.w - tex.w()) / 2 : 0;
|
||||
const int yoff = centered ? (dst.h - tex.h()) / 2 : 0;
|
||||
|
|
|
@ -157,17 +157,24 @@ void rectangle_shape::draw(
|
|||
{
|
||||
const auto rects = calculate_rects(portion_to_draw, variables);
|
||||
if(rects.empty) {
|
||||
DBG_GUI_D << "Rectangle: nothing to draw" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
const color_t fill_color = fill_color_(variables);
|
||||
const color_t border_color = border_color_(variables);
|
||||
SDL_Rect r = rects.unclipped_around_viewport;
|
||||
r.x += draw_location.x;
|
||||
r.y += draw_location.y;
|
||||
|
||||
DBG_GUI_D << "Rectangle: draw at " << r
|
||||
<< " with bounds " << portion_to_draw << std::endl;
|
||||
|
||||
// Fill the background, if applicable
|
||||
if(!fill_color.null()) {
|
||||
DBG_GUI_D << "fill " << fill_color << std::endl;
|
||||
draw::set_color(fill_color);
|
||||
auto area = rects.unclipped_around_viewport;
|
||||
area.x += draw_location.x;
|
||||
area.y += draw_location.y;
|
||||
SDL_Rect area = r;
|
||||
area.x += border_thickness_;
|
||||
area.y += border_thickness_;
|
||||
area.w -= 2 * border_thickness_;
|
||||
|
@ -177,11 +184,11 @@ void rectangle_shape::draw(
|
|||
}
|
||||
|
||||
// Draw the border
|
||||
draw::set_color(border_color_(variables));
|
||||
draw::set_color(border_color);
|
||||
DBG_GUI_D << "border thickness " << border_thickness_
|
||||
<< ", colour " << border_color << std::endl;
|
||||
for(int i = 0; i < border_thickness_; ++i) {
|
||||
auto dimensions = rects.unclipped_around_viewport;
|
||||
dimensions.x += draw_location.x;
|
||||
dimensions.y += draw_location.y;
|
||||
SDL_Rect dimensions = r;
|
||||
dimensions.x += i;
|
||||
dimensions.y += i;
|
||||
dimensions.w -= 2 * i;
|
||||
|
|
|
@ -248,7 +248,7 @@ bool halo_impl::effect::render()
|
|||
|
||||
void halo_impl::effect::unrender()
|
||||
{
|
||||
if (tex_ || buffer_) {
|
||||
if (!tex_ || !buffer_) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -534,6 +534,16 @@ CVideo::clip_setter CVideo::set_clip(const SDL_Rect& clip)
|
|||
return CVideo::clip_setter(*this, clip);
|
||||
}
|
||||
|
||||
CVideo::clip_setter CVideo::reduce_clip(const SDL_Rect& clip)
|
||||
{
|
||||
SDL_Rect c = get_clip();
|
||||
if (c == sdl::empty_rect) {
|
||||
return CVideo::clip_setter(*this, clip);
|
||||
} else {
|
||||
return CVideo::clip_setter(*this, sdl::intersect_rects(clip, c));
|
||||
}
|
||||
}
|
||||
|
||||
void CVideo::force_clip(const SDL_Rect& clip)
|
||||
{
|
||||
// Set the clipping area both on the drawing surface,
|
||||
|
|
|
@ -415,6 +415,14 @@ public:
|
|||
*/
|
||||
clip_setter set_clip(const SDL_Rect& clip);
|
||||
|
||||
/**
|
||||
* Set the clipping area to the intersection of the current clipping
|
||||
* area and the given rectangle.
|
||||
*
|
||||
* Otherwise acts as set_clip().
|
||||
*/
|
||||
clip_setter reduce_clip(const SDL_Rect& clip);
|
||||
|
||||
/**
|
||||
* Set the clipping area, without any provided way of setting it back.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue