The Battle for Wesnoth  1.17.10+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 pos () 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...
 
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...
 

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 ( )
inline

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)
inline

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 
)
inline

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

Definition at line 56 of file rect.hpp.

References w.

◆ rect() [4/4]

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

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
inline

The area of this rectangle, in square pixels.

Definition at line 101 of file rect.hpp.

References utils::contains(), h, operator<<(), p, and w.

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

◆ 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 101 of file rect.cpp.

References intersect().

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

◆ contains() [1/3]

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

◆ contains() [2/3]

bool rect::contains ( const point p) const

Definition at line 60 of file rect.cpp.

◆ contains() [3/3]

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

Whether the given rectangle is completely contained by this one.

Definition at line 65 of file rect.cpp.

References h, and w.

◆ 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 86 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 92 of file rect.cpp.

References rect().

Referenced by clip(), font::floating_label::draw(), display::draw_invalidated(), gui2::window::expose(), display::expose(), texture::set_src(), texture::set_src_raw(), gui2::scrollbar_container::set_visible_rectangle(), 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 79 of file rect.cpp.

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

◆ operator*()

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

Definition at line 72 of file rect.hpp.

References h, s, and w.

◆ operator*=()

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

Definition at line 77 of file rect.hpp.

References h, s, and w.

◆ operator/()

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

Definition at line 86 of file rect.hpp.

References h, s, and w.

◆ operator/=()

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

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 39 of file rect.cpp.

◆ operator==() [2/2]

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

Definition at line 44 of file rect.cpp.

◆ overlaps()

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

◆ pos()

constexpr point rect::pos ( ) const
inline

Definition at line 64 of file rect.hpp.

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

◆ 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 106 of file rect.cpp.

◆ size()

constexpr point rect::size ( ) const
inline

Definition at line 65 of file rect.hpp.

References h, operator==(), and w.

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


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