An abstract description of a rectangle with integer coordinates. More...
#include <rect.hpp>
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 rect & | operator*= (int s) |
constexpr rect | operator/ (int s) const |
constexpr rect & | operator/= (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... | |
rect & | expand_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... | |
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.
|
inlineconstexpr |
Explicitly initialize rects to 0.
Definition at line 50 of file rect.hpp.
Referenced by intersect().
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
The area of this rectangle, in square pixels.
Definition at line 101 of file rect.hpp.
Referenced by draw_manager::expose(), draw_manager::invalidate_region(), image::adjust_alpha_modification::operator()(), image::adjust_channels_modification::operator()(), and image::o_modification::operator()().
|
inlineconstexpr |
The center point of the rectangle, accounting for origin.
Definition at line 104 of file rect.hpp.
Referenced by game_display::float_label(), display::get_middle_location(), display::scroll_to_tiles(), and display::scroll_to_xy().
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().
bool rect::contains | ( | const SDL_Rect & | r | ) | const |
bool rect::contains | ( | int | x, |
int | y | ||
) | const |
Whether the given point lies within the rectangle.
Definition at line 53 of file rect.cpp.
References p.
Referenced by gui::scrollarea::handle_event(), gui::scrollbar::handle_event(), controller_base::handle_event(), display::hex_clicked_on(), location_palette_item::hit(), gui::tristate_button::hit(), gui::button::hit(), draw_manager::invalidate_region(), gui2::widget::is_at(), gui2::horizontal_scrollbar::on_positioner(), gui2::slider::on_positioner(), gui2::vertical_scrollbar::on_positioner(), gui::widget::process_tooltip_string(), events::mouse_handler::right_click_show_menu(), and display::tile_fully_on_screen().
bool rect::empty | ( | ) | const |
False if both w and h are > 0, true otherwise.
Definition at line 48 of file rect.cpp.
Referenced by font::floating_label::draw(), display::draw_minimap(), gui2::window::expose(), font::pango_draw_text(), playturn_network_adapter::read(), read_config(), display::recalculate_minimap(), display::render(), gui2::widget::set_visible_rectangle(), and replay::undo_cut().
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().
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().
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().
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
Definition at line 64 of file rect.hpp.
Referenced by display::hexes_under_rect(), video::to_output(), and video::update_framebuffer().
bool rect::overlaps | ( | const SDL_Rect & | r | ) | const |
Whether the given rectangle and this rectangle overlap.
Definition at line 73 of file rect.cpp.
Referenced by font::floating_label::draw(), display::draw_all_panels(), display::draw_invalidated(), display::draw_minimap(), display::expose(), gui::widget::expose(), gui::widget::hidden(), gui2::listbox::list_item_clicked(), unit_drawer::redraw_unit(), and halo::halo_impl::render().
|
inlineconstexpr |
Returns a new rectangle with equal amount horizontal and vertical padding.
Definition at line 162 of file rect.hpp.
References padded_by().
|
inlineconstexpr |
Returns a new rectangle with dx horizontal padding and dy vertical padding.
Definition at line 156 of file rect.hpp.
Referenced by display::draw_hex(), font::floating_label::get_bg_rect(), padded_by(), and display::scroll_to_tiles().
point rect::point_at | ( | double | x, |
double | y | ||
) | const |
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().
Definition at line 119 of file rect.cpp.
References shifted_by().
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().
|
inlineconstexpr |
Definition at line 65 of file rect.hpp.
Referenced by display::set_zoom(), config::splice_children(), video::to_output(), and video::update_framebuffer().
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().