The Battle for Wesnoth  1.15.12+dev
Public Member Functions | Private Attributes | List of all members
gui2::line_shape Class Reference

Definition of a line. More...

#include <canvas_private.hpp>

Inheritance diagram for gui2::line_shape:

Public Member Functions

 line_shape (const config &cfg)
 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 Attributes

typed_formula< unsigned > x1_
 The start x coordinate of the line. More...
 
typed_formula< unsigned > y1_
 The start y coordinate of the line. More...
 
typed_formula< unsigned > x2_
 The end x coordinate of the line. More...
 
typed_formula< unsigned > y2_
 The end y coordinate of the line. More...
 
typed_formula< color_tcolor_
 The color of the line. More...
 
unsigned thickness_
 The thickness of the line. More...
 

Detailed Description

Definition of a line.

When drawing a line it doesn't get blended on the surface but replaces the pixels instead. A blitting flag might be added later if needed.

Keys:

Key Type Default Description
x1 f_unsigned0 The x coordinate of the startpoint.
y1 f_unsigned0 The y coordinate of the startpoint.
x2 f_unsigned0 The x coordinate of the endpoint.
y2 f_unsigned0 The y coordinate of the endpoint.
color color "" The color of the line.
thickness unsigned 0 The thickness of the line; if 0 nothing is drawn.
debug string "" Debug message to show upon creation this message is not stored.

Variables:

Key Type Description
width unsigned The width of the canvas.
height unsigned The height of the canvas.
text t_string The text to render on the widget.
text_maximum_width unsigned The maximum width available for the text on the widget.
text_maximum_heightunsigned The maximum height available for the text on the widget.
text_wrap_mode int When the text doesn't fit in the available width there are several ways to fix that. This variable holds the best method. (NOTE this is a 'hidden' variable meant to copy state from a widget to its canvas so there's no reason to use this variable and thus its values are not listed and might change without further notice.)
text_alignment h_align The way the text is aligned inside the canvas.

The size variables are copied to the window and will be determined at runtime. This is needed since the main window can be resized and the dialog needs to resize accordingly. The following variables are available:

Key Type Description
screen_width unsignedThe usable width of the Wesnoth main window.
screen_height unsignedThe usable height of the Wesnoth main window.
gamemapx_offsetunsignedThe distance between left edge of the screen and the game map.
gamemap_width unsignedThe usable width of the Wesnoth gamemap, if no gamemap shown it's the same value as screen_width.
gamemap_height unsignedThe usable height of the Wesnoth gamemap, if no gamemap shown it's the same value as screen_height.
mouse_x unsignedThe x coordinate of the mouse pointer.
mouse_y unsignedThe y coordinate of the mouse pointer.
window_width unsignedThe window width. This value has two meanings during the layout phase. This only applies if automatic placement is not enabled. - When set to 0 it should return the wanted maximum width. If no maximum is wanted it should be set to the '"(screen_width)"'. - When not equal to 0 its value is the best width for the window. When the size should remain unchanged it should be set to '"(window_width)"'.
window_height unsignedThe window height. This value has two meanings during the layout phase. This only applies if automatic placement is not enabled. - When set to 0 it should return the wanted maximum height. If no maximum is wanted it should be set to the '"(screen_height)"'. - When not equal to 0 its value is the best height for the window. When the size should remain unchanged it should be set to '"(window_height)"'.

Note when drawing the valid coordinates are:

Drawing outside this area will result in unpredictable results including crashing. (That should be fixed, when encountered.)

Definition at line 70 of file canvas_private.hpp.

Constructor & Destructor Documentation

◆ line_shape()

gui2::line_shape::line_shape ( const config cfg)
explicit

Constructor.

Parameters
cfgThe config object to define the line.

Definition at line 207 of file canvas.cpp.

References DBG_GUI_P, and debug.

Member Function Documentation

◆ draw()

void gui2::line_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 222 of file canvas.cpp.

References color_, DBG_GUI_D, x1_, x2_, y1_, and y2_.

Member Data Documentation

◆ color_

typed_formula<color_t> gui2::line_shape::color_
private

The color of the line.

Definition at line 91 of file canvas_private.hpp.

Referenced by draw().

◆ thickness_

unsigned gui2::line_shape::thickness_
private

The thickness of the line.

if the value is odd the x and y are the middle of the line. if the value is even the x and y are the middle of a line with width - 1. (0 is special case, does nothing.)

Definition at line 100 of file canvas_private.hpp.

◆ x1_

typed_formula<unsigned> gui2::line_shape::x1_
private

The start x coordinate of the line.

Definition at line 85 of file canvas_private.hpp.

Referenced by draw().

◆ x2_

typed_formula<unsigned> gui2::line_shape::x2_
private

The end x coordinate of the line.

Definition at line 85 of file canvas_private.hpp.

Referenced by draw().

◆ y1_

typed_formula<unsigned> gui2::line_shape::y1_
private

The start y coordinate of the line.

Definition at line 85 of file canvas_private.hpp.

Referenced by draw().

◆ y2_

typed_formula<unsigned> gui2::line_shape::y2_
private

The end y coordinate of the line.

Definition at line 85 of file canvas_private.hpp.

Referenced by draw().


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