The Battle for Wesnoth  1.17.4+dev
Classes | Functions | Variables
sdl Namespace Reference

Classes

struct  exception
 
class  UserEvent
 
class  window
 The wrapper class for the SDL_Window class. More...
 

Functions

static std::string create_error (const std::string &operation, const bool use_sdl_error)
 
uint32_t get_mouse_state (int *x, int *y)
 A wrapper for SDL_GetMouseState that gives coordinates in draw space. More...
 
uint32_t get_mouse_button_mask ()
 Returns the current mouse button mask. More...
 
SDL_Point get_mouse_location ()
 Returns the currnet mouse location in draw space. More...
 
void update_input_dimensions (int draw_width, int draw_height, int input_width, int input_height)
 Update the cached drawing area and input area sizes. More...
 
void update_input_dimensions (SDL_Point draw_size, SDL_Point input_size)
 
bool point_in_rect (int x, int y, const SDL_Rect &rect)
 Tests whether a point is inside a rectangle. More...
 
bool point_in_rect (const point &point, const SDL_Rect &rect)
 
bool rects_overlap (const SDL_Rect &rect1, const SDL_Rect &rect2)
 Tests whether two rectangles overlap. More...
 
SDL_Rect intersect_rects (const SDL_Rect &rect1, const SDL_Rect &rect2)
 Calculates the intersection of two rectangles. More...
 
SDL_Rect union_rects (const SDL_Rect &rect1, const SDL_Rect &rect2)
 Calculates the union of two rectangles. More...
 
void draw_rectangle (const SDL_Rect &rect, const color_t &color)
 Draw a rectangle outline. More...
 
void fill_rectangle (const SDL_Rect &rect, const color_t &color)
 Draws a filled rectangle. More...
 
SDL_Rect create_rect (const int x, const int y, const int w, const int h)
 Creates an SDL_Rect with the given dimensions. More...
 
void fill_surface_rect (surface &dst, SDL_Rect *dst_rect, const uint32_t color)
 Fill a rectangle on a given surface. More...
 

Variables

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

Function Documentation

◆ create_error()

static std::string sdl::create_error ( const std::string &  operation,
const bool  use_sdl_error 
)
static

Definition at line 23 of file exception.cpp.

◆ create_rect()

SDL_Rect sdl::create_rect ( const int  x,
const int  y,
const int  w,
const int  h 
)
inline

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.

Definition at line 40 of file rect.hpp.

References draw_rectangle(), fill_rectangle(), intersect_rects(), point_in_rect(), rects_overlap(), union_rects(), and w.

Referenced by gui2::rect_bounded_shape::calculate_rects(), gui2::image_shape::draw(), unit_drawer::draw_bar(), gui::textbox::draw_contents(), display::draw_invalidated(), gui::menu::get_item_rect_internal(), image::load_image_sub_file(), gui2::vertical_scrollbar::on_positioner(), gui2::horizontal_scrollbar::on_positioner(), and gui2::slider::on_positioner().

◆ draw_rectangle()

void sdl::draw_rectangle ( const SDL_Rect &  rect,
const color_t color 
)

Draw a rectangle outline.

Parameters
rectThe dimensions of the rectangle.
colorThe color of the rectangle.

Definition at line 58 of file rect.cpp.

References color_t::a, color_t::b, color_t::g, CVideo::get_singleton(), CVideo::get_window(), and color_t::r.

Referenced by create_rect(), location_palette_item::draw_contents(), and gui2::widget::draw_debug_border().

◆ fill_rectangle()

void sdl::fill_rectangle ( const SDL_Rect &  rect,
const color_t color 
)

◆ fill_surface_rect()

void sdl::fill_surface_rect ( surface dst,
SDL_Rect *  dst_rect,
const uint32_t  color 
)
inline

Fill a rectangle on a given surface.

Alias for SDL_FillRect.

Parameters
dstThe surface to operate on.
dst_rectThe rectangle to fill.
colorColor of the rectangle.

Definition at line 115 of file rect.hpp.

References a, b, operator!=(), operator<<(), operator==(), and s.

Referenced by font::floating_label::create_texture(), unit_drawer::draw_bar(), display::draw_hex(), and image::getMinimap().

◆ get_mouse_button_mask()

uint32_t sdl::get_mouse_button_mask ( )

◆ get_mouse_location()

SDL_Point sdl::get_mouse_location ( )

Returns the currnet mouse location in draw space.

Definition at line 50 of file input.cpp.

References get_mouse_state(), and p.

Referenced by gui2::get_mouse_position().

◆ get_mouse_state()

uint32_t sdl::get_mouse_state ( int *  x,
int *  y 
)

◆ intersect_rects()

SDL_Rect sdl::intersect_rects ( const SDL_Rect &  rect1,
const SDL_Rect &  rect2 
)

Calculates the intersection of two rectangles.

Parameters
rect1One rectangle.
rect2Another rectangle
Returns
The intersection of rect1 and rect2, or empty_rect if they don't overlap.

Definition at line 40 of file rect.cpp.

References empty_rect.

Referenced by CVideo::clip_to_draw_area(), create_rect(), display::invalidate_visible_locations_in_rect(), gui2::dialogs::terrain_layers::pre_show(), CVideo::read_pixels(), surface_restorer::restore(), display::scroll(), gui2::scrollbar_container::set_visible_rectangle(), and gui2::widget::set_visible_rectangle().

◆ point_in_rect() [1/2]

bool sdl::point_in_rect ( int  x,
int  y,
const SDL_Rect &  rect 
)

◆ point_in_rect() [2/2]

bool sdl::point_in_rect ( const point point,
const SDL_Rect &  rect 
)

Definition at line 29 of file rect.cpp.

References point_in_rect(), point::x, and point::y.

◆ rects_overlap()

bool sdl::rects_overlap ( const SDL_Rect &  rect1,
const SDL_Rect &  rect2 
)

Tests whether two rectangles overlap.

Parameters
rect1One rectangle.
rect2Another rectangle.
Returns
True if rect1 and rect2 intersect, false if not. Touching borders don't overlap.

Definition at line 34 of file rect.cpp.

Referenced by tooltips::clear_tooltips(), create_rect(), display::draw_invalidated(), gui::widget::hidden(), gui2::listbox::list_item_clicked(), unit_drawer::redraw_unit(), halo::halo_impl::effect::render(), and display::render_image().

◆ union_rects()

SDL_Rect sdl::union_rects ( const SDL_Rect &  rect1,
const SDL_Rect &  rect2 
)

Calculates the union of two rectangles.

Note: "union" here doesn't mean the union of the sets of points of the two polygons, but rather the minimal rectangle that supersets both rectangles.

Parameters
rect1One rectangle.
rect2Another rectangle.
Returns
The union of rect1 and rect2.

Definition at line 50 of file rect.cpp.

Referenced by create_rect().

◆ update_input_dimensions() [1/2]

void sdl::update_input_dimensions ( int  draw_width,
int  draw_height,
int  input_width,
int  input_height 
)

Update the cached drawing area and input area sizes.

These correspond to the size of the drawing surface in pixels, and the size of the window in display coordinates.

This should be called every time the window is resized, or the pixel scale multiplier changes.

Parameters
draw_widthThe width of the drawing surface, in pixels
draw_heightThe height of the drawing surface, in pixels
input_widthThe width of the input surface, in display coordinates
input_heightThe height of the input surface, in display coordinates

Definition at line 57 of file input.cpp.

Referenced by sdl::window::full_screen(), sdl::window::maximize(), sdl::window::restore(), sdl::window::set_logical_size(), sdl::window::set_minimum_size(), sdl::window::set_size(), sdl::window::to_window(), CVideo::update_framebuffer(), and sdl::window::window().

◆ update_input_dimensions() [2/2]

void sdl::update_input_dimensions ( SDL_Point  draw_size,
SDL_Point  input_size 
)

Definition at line 67 of file input.cpp.

Variable Documentation

◆ empty_rect

constexpr const SDL_Rect sdl::empty_rect { 0, 0, 0, 0 }