The Battle for Wesnoth  1.19.0-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 (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_unsigned 0 The x coordinate of the startpoint.
y1 f_unsigned 0 The y coordinate of the startpoint.
x2 f_unsigned 0 The x coordinate of the endpoint.
y2 f_unsigned 0 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_height unsigned 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 unsigned The usable width of the Wesnoth main window.
screen_height unsigned The usable height of the Wesnoth main window.
gamemapx_offset unsigned The distance between left edge of the screen and the game map.
gamemap_width unsigned The usable width of the Wesnoth gamemap, if no gamemap shown it's the same value as screen_width.
gamemap_height unsigned The usable height of the Wesnoth gamemap, if no gamemap shown it's the same value as screen_height.
mouse_x unsigned The x coordinate of the mouse pointer.
mouse_y unsigned The y coordinate of the mouse pointer.
window_width unsigned The 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 unsigned The 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 71 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 47 of file canvas.cpp.

References DBG_GUI_P, and debug.

Member Function Documentation

◆ draw()

void gui2::line_shape::draw ( wfl::map_formula_callable variables)
overridevirtual

Draws the canvas.

Parameters
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 62 of file canvas.cpp.

References color_, DBG_GUI_D, draw::line(), 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 90 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 99 of file canvas_private.hpp.

◆ x1_

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

The start x coordinate of the line.

Definition at line 84 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 86 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 87 of file canvas_private.hpp.

Referenced by draw().


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