The Battle for Wesnoth  1.19.7+dev
Public Member Functions | List of all members
rect Struct Reference

An abstract description of a rectangle with integer coordinates. More...

#include <rect.hpp>

Inheritance diagram for rect:

Public Member Functions

constexpr rect ()
 Explicitly initialize rects to 0. More...
 
constexpr rect (const SDL_Rect &r)
 There's nothing extra when converting an SDL_Rect. More...
 
constexpr rect (int x, int y, int w, int h)
 Specify via (x, y, w, h). More...
 
constexpr rect (const point &pos, const point &size)
 Specify via top-left corner position and size. More...
 
constexpr point origin () const
 
constexpr point size () const
 
bool operator== (const rect &r) const
 
bool operator== (const SDL_Rect &r) const
 
constexpr rect operator* (int s) const
 
constexpr rectoperator*= (int s)
 
constexpr rect operator/ (int s) const
 
constexpr rectoperator/= (int s)
 
constexpr int area () const
 The area of this rectangle, in square pixels. More...
 
constexpr point center () const
 The center point of the rectangle, accounting for origin. More...
 
bool empty () const
 False if both w and h are > 0, true otherwise. More...
 
bool contains (int x, int y) const
 Whether the given point lies within the rectangle. More...
 
bool contains (const point &p) const
 
bool contains (const SDL_Rect &r) const
 Whether the given rectangle is completely contained by this one. More...
 
bool overlaps (const SDL_Rect &r) const
 Whether the given rectangle and this rectangle overlap. More...
 
rect minimal_cover (const SDL_Rect &r) const
 Calculates the minimal rectangle that completely contains both this rectangle and the given rectangle. More...
 
rectexpand_to_cover (const SDL_Rect &r)
 Minimally expand this rect to fully contain another. More...
 
rect intersect (const SDL_Rect &r) const
 Calculates the intersection of this rectangle and another; that is, the maximal rectangle that is contained by both. More...
 
void clip (const SDL_Rect &r)
 Clip this rectangle by the given rectangle. More...
 
void shift (const point &p)
 Shift the rectangle by the given relative position. More...
 
rect shifted_by (int x, int y) const
 Returns a new rectangle shifted by the given relative position. More...
 
rect shifted_by (const point &p) const
 
constexpr rect padded_by (int dx, int dy) const
 Returns a new rectangle with dx horizontal padding and dy vertical padding. More...
 
constexpr rect padded_by (int amount) const
 Returns a new rectangle with equal amount horizontal and vertical padding. More...
 
point point_at (double x, double y) const
 Returns the proper point that corresponds to the given [0.0, 1.0] coordinates. More...
 
rect subrect (const SDL_FPoint &top_left, const SDL_FPoint &bottom_right) const
 Returns the sub-rect bounded to the top left and bottom right by the given [0.0, 1.0] coordinates. More...
 

Detailed Description

An abstract description of a rectangle with integer coordinates.

This is a thin wrapper over SDL_Rect, furnished with utility functions.

As for SDL_Rect, member variables x, y, w and h are public.

Definition at line 46 of file rect.hpp.

Constructor & Destructor Documentation

◆ rect() [1/4]

constexpr rect::rect ( )
inlineconstexpr

Explicitly initialize rects to 0.

Definition at line 50 of file rect.hpp.

Referenced by intersect().

◆ rect() [2/4]

constexpr rect::rect ( const SDL_Rect &  r)
inlineconstexpr

There's nothing extra when converting an SDL_Rect.

Definition at line 53 of file rect.hpp.

◆ rect() [3/4]

constexpr rect::rect ( int  x,
int  y,
int  w,
int  h 
)
inlineconstexpr

Specify via (x, y, w, h).

Definition at line 56 of file rect.hpp.

◆ rect() [4/4]

constexpr rect::rect ( const point pos,
const point size 
)
inlineconstexpr

Specify via top-left corner position and size.

Definition at line 59 of file rect.hpp.

Member Function Documentation

◆ area()

constexpr int rect::area ( ) const
inlineconstexpr

◆ center()

constexpr point rect::center ( ) const
inlineconstexpr

The center point of the rectangle, accounting for origin.

Definition at line 104 of file rect.hpp.

References h, and w.

Referenced by game_display::float_label(), display::get_middle_location(), display::scroll_to_tiles(), and display::scroll_to_xy().

◆ clip()

void rect::clip ( const SDL_Rect &  r)

Clip this rectangle by the given rectangle.

This rectangle will be reduced to the intersection of both rectangles.

Definition at line 100 of file rect.cpp.

References intersect().

Referenced by gui2::window::expose(), video::read_pixels(), and display::scroll().

◆ contains() [1/3]

bool rect::contains ( const point p) const

Definition at line 59 of file rect.cpp.

◆ contains() [2/3]

bool rect::contains ( const SDL_Rect &  r) const

Whether the given rectangle is completely contained by this one.

Definition at line 64 of file rect.cpp.

References h, and w.

◆ contains() [3/3]

bool rect::contains ( int  x,
int  y 
) const

◆ empty()

bool rect::empty ( ) const

◆ expand_to_cover()

rect & rect::expand_to_cover ( const SDL_Rect &  r)

Minimally expand this rect to fully contain another.

Definition at line 85 of file rect.cpp.

Referenced by draw_manager::invalidate_region().

◆ intersect()

rect rect::intersect ( const SDL_Rect &  r) const

Calculates the intersection of this rectangle and another; that is, the maximal rectangle that is contained by both.

Definition at line 91 of file rect.cpp.

References rect().

Referenced by clip(), font::floating_label::draw(), display::draw_invalidated(), draw_manager::expose(), display::expose(), gui2::window::expose(), gui2::window::queue_rerender(), texture::set_src(), texture::set_src_raw(), and gui2::widget::set_visible_rectangle().

◆ minimal_cover()

rect rect::minimal_cover ( const SDL_Rect &  r) const

Calculates the minimal rectangle that completely contains both this rectangle and the given rectangle.

Definition at line 78 of file rect.cpp.

Referenced by draw_manager::expose(), and draw_manager::invalidate_region().

◆ operator*()

constexpr rect rect::operator* ( int  s) const
inlineconstexpr

Definition at line 72 of file rect.hpp.

References h, s, and w.

◆ operator*=()

constexpr rect& rect::operator*= ( int  s)
inlineconstexpr

Definition at line 77 of file rect.hpp.

References h, s, and w.

◆ operator/()

constexpr rect rect::operator/ ( int  s) const
inlineconstexpr

Definition at line 86 of file rect.hpp.

References h, s, and w.

◆ operator/=()

constexpr rect& rect::operator/= ( int  s)
inlineconstexpr

Definition at line 91 of file rect.hpp.

References h, s, and w.

◆ operator==() [1/2]

bool rect::operator== ( const rect r) const

Definition at line 38 of file rect.cpp.

◆ operator==() [2/2]

bool rect::operator== ( const SDL_Rect &  r) const

Definition at line 43 of file rect.cpp.

◆ origin()

constexpr point rect::origin ( ) const
inlineconstexpr

Definition at line 64 of file rect.hpp.

Referenced by display::hexes_under_rect(), video::to_output(), and video::update_framebuffer().

◆ overlaps()

bool rect::overlaps ( const SDL_Rect &  r) const

◆ padded_by() [1/2]

constexpr rect rect::padded_by ( int  amount) const
inlineconstexpr

Returns a new rectangle with equal amount horizontal and vertical padding.

Definition at line 162 of file rect.hpp.

References padded_by().

◆ padded_by() [2/2]

constexpr rect rect::padded_by ( int  dx,
int  dy 
) const
inlineconstexpr

Returns a new rectangle with dx horizontal padding and dy vertical padding.

Definition at line 156 of file rect.hpp.

References h, and w.

Referenced by display::draw_hex(), font::floating_label::get_bg_rect(), padded_by(), and display::scroll_to_tiles().

◆ point_at()

point rect::point_at ( double  x,
double  y 
) const

Returns the proper point that corresponds to the given [0.0, 1.0] coordinates.

Definition at line 124 of file rect.cpp.

References h, and w.

Referenced by subrect().

◆ shift()

void rect::shift ( const point p)

Shift the rectangle by the given relative position.

The point's X and Y coordinates will be added to the rectangle's.

Definition at line 105 of file rect.cpp.

Referenced by gui2::widget::draw_background(), gui2::widget::draw_children(), gui2::widget::draw_foreground(), gui2::window::expose(), gui2::window::queue_rerender(), and display::scroll().

◆ shifted_by() [1/2]

rect rect::shifted_by ( const point p) const

Definition at line 119 of file rect.cpp.

References shifted_by().

◆ shifted_by() [2/2]

rect rect::shifted_by ( int  x,
int  y 
) const

Returns a new rectangle shifted by the given relative position.

Definition at line 111 of file rect.cpp.

Referenced by unit_drawer::redraw_unit(), and shifted_by().

◆ size()

constexpr point rect::size ( ) const
inlineconstexpr

Definition at line 65 of file rect.hpp.

References h, and w.

Referenced by display::set_zoom(), config::splice_children(), video::to_output(), and video::update_framebuffer().

◆ subrect()

rect rect::subrect ( const SDL_FPoint &  top_left,
const SDL_FPoint &  bottom_right 
) const

Returns the sub-rect bounded to the top left and bottom right by the given [0.0, 1.0] coordinates.

Definition at line 132 of file rect.cpp.

References markup::br, and point_at().


The documentation for this struct was generated from the following files: