The Battle for Wesnoth  1.17.0-dev
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
gui2::image_shape Class Reference

Keys:

Key Type DefaultDescription
x f_unsigned 0 The x coordinate of the top left corner.
More...

#include <canvas_private.hpp>

Inheritance diagram for gui2::image_shape:

Public Member Functions

 image_shape (const config &cfg, wfl::action_function_symbol_table &functions)
 Constructor. More...
 
void draw (surface &canvas, SDL_Renderer *renderer, const SDL_Rect &viewport, wfl::map_formula_callable &variables) override
 Draws the canvas. More...
 
- Public Member Functions inherited from gui2::canvas::shape
 shape (const config &cfg)
 
virtual ~shape ()
 
bool immutable () const
 

Private Types

enum  resize_mode {
  resize_mode::scale, resize_mode::scale_sharp, resize_mode::stretch, resize_mode::tile,
  resize_mode::tile_center
}
 Determines the way an image will be resized. More...
 

Private Member Functions

resize_mode get_resize_mode (const std::string &resize_mode)
 Converts a string to a resize mode. More...
 

Static Private Member Functions

static void dimension_validation (unsigned value, const std::string &name, const std::string &key)
 

Private Attributes

typed_formula< unsigned > x_
 The x coordinate of the image. More...
 
typed_formula< unsigned > y_
 The y coordinate of the image. More...
 
typed_formula< unsigned > w_
 The width of the image. More...
 
typed_formula< unsigned > h_
 The height of the image. More...
 
SDL_Rect src_clip_
 Contains the size of the image. More...
 
surface image_
 The image is cached in this surface. More...
 
typed_formula< std::string > image_name_
 Name of the image. More...
 
resize_mode resize_mode_
 The resize mode for an image. More...
 
typed_formula< bool > vertical_mirror_
 Mirror the image over the vertical axis. More...
 
wfl::formula actions_formula_
 

Detailed Description

Keys:

Key Type DefaultDescription
x f_unsigned 0 The x coordinate of the top left corner.

y | f_unsigned |0 |The y coordinate of the top left corner. w | f_unsigned |0 |The width of the image, if not zero the image will be scaled to the desired width. h | f_unsigned |0 |The height of the image, if not zero the image will be scaled to the desired height. resize_mode | resize_mode|scale |Determines how an image is scaled to fit the wanted size. vertical_mirror | f_bool |false |Mirror the image over the vertical axis. name | string |"" |The name of the image. debug | string |"" |Debug message to show upon creation this message is not stored.

Variables:

Key Type Description
image_width unsigned The width of the image, either the requested width or the natural width of the image. This value can be used to set the x (or y) value of the image. (This means x and y are evaluated after the width and height.)
image_height unsigned The height of the image, either the requested height or the natural height of the image. This value can be used to set the y (or x) value of the image. (This means x and y are evaluated after the width and height.)
image_original_width unsigned The width of the image as stored on disk, can be used to set x or w (also y and h can be set).
image_original_heightunsigned The height of the image as stored on disk, can be used to set y or h (also x and y can be set).

Also the general variables are available, see line_shape

Definition at line 344 of file canvas_private.hpp.

Member Enumeration Documentation

◆ resize_mode

enum gui2::image_shape::resize_mode
strongprivate

Determines the way an image will be resized.

If the image is smaller is needed it needs to resized, how is determined by the value of this enum.

Enumerator
scale 
scale_sharp 
stretch 
tile 
tile_center 

Definition at line 386 of file canvas_private.hpp.

Constructor & Destructor Documentation

◆ image_shape()

gui2::image_shape::image_shape ( const config cfg,
wfl::action_function_symbol_table functions 
)

Constructor.

Parameters
cfgThe config object to define the image.
functionsWFL functions to execute.

Definition at line 488 of file canvas.cpp.

References DBG_GUI_P, and debug.

Member Function Documentation

◆ dimension_validation()

void gui2::image_shape::dimension_validation ( unsigned  value,
const std::string &  name,
const std::string &  key 
)
staticprivate

Definition at line 507 of file canvas.cpp.

References _(), and VALIDATE_WITH_DEV_MESSAGE.

Referenced by draw().

◆ draw()

void gui2::image_shape::draw ( surface canvas,
SDL_Renderer *  renderer,
const SDL_Rect &  view_bounds,
wfl::map_formula_callable variables 
)
overridevirtual

Draws the canvas.

Parameters
canvasThe resulting image will be blitted upon this canvas.
rendererThe SDL_Renderer to use.
view_boundsPart of the shape to render - this is the location of canvas within the coordinates of the shape.
variablesThe canvas can have formulas in it's definition, this parameter contains the values for these formulas.
Todo:
formulas are now recalculated every draw cycle which is a bit silly unless there has been a resize. So to optimize we should use an extra flag or do the calculation in a separate routine.

Implements gui2::canvas::shape.

Definition at line 516 of file canvas.cpp.

References actions_formula_, wfl::map_formula_callable::add(), blit_surface(), sdl::create_rect(), DBG_GUI_D, dimension_validation(), ERR_GUI_D, wfl::formula::evaluate(), wfl::formula_callable::fake_ptr(), flip_surface(), gui2::image::get_image(), h, h_, image_, image_name_, resize_mode_, scale_sharp, scale_surface_legacy(), scale_surface_sharp(), src_clip_, stretch, stretch_surface_horizontal(), stretch_surface_vertical(), tile, tile_center, tile_surface(), vertical_mirror_, w, w_, x_, and y_.

◆ get_resize_mode()

image_shape::resize_mode gui2::image_shape::get_resize_mode ( const std::string &  resize_mode)
private

Converts a string to a resize mode.

Definition at line 655 of file canvas.cpp.

References ERR_GUI_E, scale, scale_sharp, stretch, tile, and tile_center.

Member Data Documentation

◆ actions_formula_

wfl::formula gui2::image_shape::actions_formula_
private

Definition at line 404 of file canvas_private.hpp.

Referenced by draw().

◆ h_

typed_formula<unsigned> gui2::image_shape::h_
private

The height of the image.

Definition at line 360 of file canvas_private.hpp.

Referenced by draw().

◆ image_

surface gui2::image_shape::image_
private

The image is cached in this surface.

Definition at line 369 of file canvas_private.hpp.

Referenced by draw().

◆ image_name_

typed_formula<std::string> gui2::image_shape::image_name_
private

Name of the image.

This value is only used when the image name is a formula. If it isn't a formula the image will be loaded in the constructor. If it's a formula it will be loaded every draw cycles. This allows 'changing' images.

Definition at line 378 of file canvas_private.hpp.

Referenced by draw().

◆ resize_mode_

resize_mode gui2::image_shape::resize_mode_
private

The resize mode for an image.

Definition at line 398 of file canvas_private.hpp.

Referenced by draw().

◆ src_clip_

SDL_Rect gui2::image_shape::src_clip_
private

Contains the size of the image.

Definition at line 366 of file canvas_private.hpp.

Referenced by draw().

◆ vertical_mirror_

typed_formula<bool> gui2::image_shape::vertical_mirror_
private

Mirror the image over the vertical axis.

Definition at line 401 of file canvas_private.hpp.

Referenced by draw().

◆ w_

typed_formula<unsigned> gui2::image_shape::w_
private

The width of the image.

Definition at line 360 of file canvas_private.hpp.

Referenced by draw().

◆ x_

typed_formula<unsigned> gui2::image_shape::x_
private

The x coordinate of the image.

Definition at line 360 of file canvas_private.hpp.

Referenced by draw().

◆ y_

typed_formula<unsigned> gui2::image_shape::y_
private

The y coordinate of the image.

Definition at line 360 of file canvas_private.hpp.

Referenced by draw().


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