wPlot2D version: 0.1.0
A lightweight C++ library for clear and customizable 2D scientific plots.
Loading...
Searching...
No Matches
wEngine::LineDrawer Class Reference

Utility class for rendering thick lines and polylines with style support. More...

#include <wLineDrawer.hpp>

Static Public Member Functions

static float drawLine (sf::RenderWindow &window, const sf::Vector2f &point1, const sf::Vector2f &point2, const sf::Color &color, float thickness, LineStyleComponent::LineStyle style=LineStyleComponent::LineStyle::Solid, float dashLength=20.0f, float gapLength=5.0f, float patternOffset=0.0f)
 Draws a single thick line segment between two points.
static void drawPolylineRound (sf::RenderWindow &window, const std::vector< sf::Vector2f > &points, const sf::Color &color, float thickness, LineStyleComponent::LineStyle style=LineStyleComponent::LineStyle::Solid, float dashLength=20.0f, float gapLength=5.0f, unsigned int arcResolution=12)
 Draws a polyline (sequence of connected line segments) with optional round joins.

Detailed Description

Utility class for rendering thick lines and polylines with style support.

The LineDrawer provides static methods to draw line segments and polylines with configurable thickness, color, and style (Solid, Dashed, Dotted).

Features:

  • Thick line rendering via quads (two triangles per segment).
  • Support for dashed and dotted patterns using configurable dash/gap lengths.
  • Dash/dot continuity across multiple connected segments using a shared pattern offset.
  • Optional round joins at corners of polylines (applied only when style == Solid).

Usage:

  • Use drawLine( ) to render a single thick segment.
  • Use drawPolylineRound( ) to render a sequence of connected points with optional round joins.
  • To maintain consistent dash/dot alignment across segments, pass the returned patternOffset from drawLine( ) into the next segment.
Warning
Round joins are currently only applied for Solid style. For dashed or dotted lines, joins would produce inconsistent results and are therefore omitted.
See also
LineStyleComponent for configuring line style options.
Author
Wilfried Koch

Member Function Documentation

◆ drawLine()

float wEngine::LineDrawer::drawLine ( sf::RenderWindow & window,
const sf::Vector2f & point1,
const sf::Vector2f & point2,
const sf::Color & color,
float thickness,
LineStyleComponent::LineStyle style = LineStyleComponent::LineStyle::Solid,
float dashLength = 20.0f,
float gapLength = 5.0f,
float patternOffset = 0.0f )
static

Draws a single thick line segment between two points.

Style behavior:

  • Solid: Renders a single quad covering the full segment.
  • Dashed: Repeats a dash/gap pattern along the segment.
  • Dotted: Places successive dots along the segment, using thickness as dot length.

Pattern control:

  • dashLength sets the visible length of each dash (Dashed style).
  • gapLength sets the empty space between dashes or dots.
  • thickness is reused as the dot length if style == Dotted.
  • patternOffset maintains pattern alignment between consecutive calls.
Parameters
windowRender target.
point1First endpoint of the line.
point2Second endpoint of the line.
colorLine color.
thicknessLine thickness in pixels.
styleLine style (Solid, Dashed, Dotted).
dashLengthDash length (used if style == Dashed).
gapLengthGap length between dashes or dots.
patternOffsetInitial offset within the dash/dot pattern.
Returns
Updated pattern offset after this segment (pass to next segment for continuity).

◆ drawPolylineRound()

void wEngine::LineDrawer::drawPolylineRound ( sf::RenderWindow & window,
const std::vector< sf::Vector2f > & points,
const sf::Color & color,
float thickness,
LineStyleComponent::LineStyle style = LineStyleComponent::LineStyle::Solid,
float dashLength = 20.0f,
float gapLength = 5.0f,
unsigned int arcResolution = 12 )
static

Draws a polyline (sequence of connected line segments) with optional round joins.

  • Each segment [p1, p2] is rendered using drawLine( ), with pattern continuity preserved.
  • If style == Solid and a next segment exists: a circular arc is approximated using triangles to smooth the corner at [p2].
Parameters
windowRender target.
pointsList of polyline points (must contain at least 2).
colorPolyline color.
thicknessLine thickness in pixels.
styleLine style (Solid, Dashed, Dotted).
dashLengthDash length (used if style == Dashed).
gapLengthGap length between dashes or dots.
arcResolutionNumber of triangles used to approximate each round join (higher = smoother).
Note
For Dashed or Dotted styles, round joins are skipped.

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