Wt: Wt::WPen Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Wt::WPen Class Reference
Painting system

A value class that defines the style for pen strokes. More...

`#include <Wt/WPen.h>`

Inheritance diagram for Wt::WPen:
[legend]

## Public Types
typedef PenStyle | Style
| Typedef for enum Wt::PenStyle.
typedef PenCapStyle | CapStyle
| Typedef for enum Wt::PenCapStyle.
typedef PenJoinStyle | JoinStyle
| Typedef for enum Wt::PenJoinStyle.

## Public Member Functions
| WPen ()
| Creates a black cosmetic pen.
| WPen (PenStyle style)
| Creates a black pen with a particular style.
| WPen (const WColor &color)
| Creates a solid pen of a particular color.
| WPen (StandardColor color)
| Creates a solid pen of a standard color.
| WPen (const WGradient &gradient)
| Creates a solid pen with a gradient color.
bool | operator== (const WPen &other) const
| Comparison operator.
bool | operator!= (const WPen &other) const
| Comparison operator.
void | setStyle (PenStyle style)
| Sets the pen style.
PenStyle | style () const
| Returns the pen style.
void | setCapStyle (PenCapStyle style)
| Sets the style for rendering line ends.
PenCapStyle | capStyle () const
| Returns the style for rendering line ends.
void | setJoinStyle (PenJoinStyle style)
| Sets the style for rendering line joins.
PenJoinStyle | joinStyle () const
| Returns the style for rendering line joins.
void | setWidth (const WLength &width)
| Sets the pen width.
const WLength & | width () const
| Returns the pen width.
void | setColor (const WColor &color)
| Sets the pen color.
const WColor & | color () const
| Returns the pen color.
void | setGradient (const WGradient &gradient)
| Sets the pen color as a gradient.
const WGradient & | gradient () const
| Returns the pen color gradient.
virtual std::string | jsValue () const override
| Returns a JavaScript representation of the value of this object.
Public Member Functions inherited from Wt::WJavaScriptExposableObject
bool | isJavaScriptBound () const
| Returns whether this object is JavaScript bound.
std::string | jsRef () const
| Returns a JavaScript reference to this object.

## Detailed Description

A value class that defines the style for pen strokes.

A pen defines the properties of how lines (that may surround shapes) are rendered.

A pen with width 0 is a cosmetic pen, and is always rendered as 1 pixel width, regardless of transformations. Otherwized, the pen width is modified by the transformation set on the painter.

### JavaScript exposability

A WPen is JavaScript exposable. If a WPen is JavaScript bound, it can be accessed in your custom JavaScript code through its handle's jsRef(). At the moment, only the color() property is exposed, e.g. a pen with the color WColor(10,20,30,255) will be represented in JavaScript as:

{
color: [10,20,30,255]
}
Wt::WPen::color
const WColor & color() const
Returns the pen color.
Definition WPen.h:200

Warning
  A WPen that is JavaScript exposed should be modified only through its handle. Any attempt at modifying it will cause an exception to be thrown.

See also
  WPainter::setPen(), WBrush, WPaintedWidget::createJSPen()

## Constructor & Destructor Documentation

## ◆ WPen() [1/5]

Wt::WPen::WPen | ( |  | ) |

Creates a black cosmetic pen.

Constructs a black solid pen of 0 width (i.e. cosmetic single pixel width), with PenCapStyle::Square line ends and PenJoinStyle::Bevel line join style.

## ◆ WPen() [2/5]

Wt::WPen::WPen | ( | PenStyle | style | ) |

Creates a black pen with a particular style.

Constructs a black pen of 0 width (i.e. cosmetic single pixel width), with PenCapStyle::Square line ends and PenJoinStyle::Bevel line join style.

The line style is set to `style`.

## ◆ WPen() [3/5]

Wt::WPen::WPen | ( | const WColor & | color | ) |

Creates a solid pen of a particular color.

Constructs a solid pen of 0 width (i.e. cosmetic single pixel width), with PenCapStyle::Square line ends and PenJoinStyle::Bevel line join style.

The pen color is set to `color`.

## ◆ WPen() [4/5]

Wt::WPen::WPen | ( | StandardColor | color | ) |

Creates a solid pen of a standard color.

Constructs a solid pen of 0 width (i.e. cosmetic single pixel width), with PenCapStyle::Square line ends and PenJoinStyle::Bevel line join style.

The pen color is set to `color`.

## ◆ WPen() [5/5]

Wt::WPen::WPen | ( | const WGradient & | gradient | ) |

Creates a solid pen with a gradient color.

Constructs a solid pen of 0 width (i.e. cosmetic single pixel width), with PenCapStyle::Square line ends and PenJoinStyle::Bevel line join style.

The pen's color is defined by the gradient `color`.

## Member Function Documentation

## ◆ capStyle()

PenCapStyle Wt::WPen::capStyle | ( |  | ) | const

Returns the style for rendering line ends.

See also
  setCapStyle(PenCapStyle)

## ◆ color()

const WColor & Wt::WPen::color | ( |  | ) | const

Returns the pen color.

See also
  setColor()

## ◆ gradient()

const WGradient & Wt::WPen::gradient | ( |  | ) | const

Returns the pen color gradient.

See also
  setGradient()

## ◆ joinStyle()

PenJoinStyle Wt::WPen::joinStyle | ( |  | ) | const

Returns the style for rendering line joins.

See also
  setJoinStyle(PenJoinStyle)

## ◆ jsValue()

virtual std::string Wt::WPen::jsValue | ( |  | ) | const
| overridevirtual

Returns a JavaScript representation of the value of this object.

Note
  The value returned will reflect the current server side value of the object. If this object is JavaScript bound, this value may not reflect the actual client side value. If you need access to the client side value, use jsRef() intead.

Implements Wt::WJavaScriptExposableObject.

## ◆ operator!=()

bool Wt::WPen::operator!= | ( | const WPen & | other | ) | const

Comparison operator.

Returns `true` if the pens are different.

## ◆ operator==()

bool Wt::WPen::operator== | ( | const WPen & | other | ) | const

Comparison operator.

Returns `true` if the pens are exactly the same.

## ◆ setCapStyle()

void Wt::WPen::setCapStyle | ( | PenCapStyle | style | ) |

Sets the style for rendering line ends.

The cap style configures how line ends are rendered.

Exceptions

  WException | if the pen is JavaScript bound

## ◆ setColor()

void Wt::WPen::setColor | ( | const WColor & | color | ) |

Sets the pen color.

Exceptions

  WException | if the pen is JavaScript bound

setGradient()

## ◆ setGradient()

void Wt::WPen::setGradient | ( | const WGradient & | gradient | ) |

Sets the pen color as a gradient.

Exceptions

  WException | if the pen is JavaScript bound

See also
  setColor()

## ◆ setJoinStyle()

void Wt::WPen::setJoinStyle | ( | PenJoinStyle | style | ) |

Sets the style for rendering line joins.

The join style configures how corners are rendered between different segments of a poly-line, rectange or painter path.

Exceptions

  WException | if the pen is JavaScript bound

## ◆ setStyle()

void Wt::WPen::setStyle | ( | PenStyle | style | ) |

Sets the pen style.

The pen style determines the pattern with which the pen is rendered.

Exceptions

  WException | if the pen is JavaScript bound

## ◆ setWidth()

void Wt::WPen::setWidth | ( | const WLength & | width | ) |

Sets the pen width.

A pen width `must` be specified using LengthUnit::Pixel units.

Exceptions

  WException | if the pen is JavaScript bound

## ◆ style()

PenStyle Wt::WPen::style | ( |  | ) | const

Returns the pen style.

See also
  setStyle(PenStyle)

## ◆ width()

const WLength & Wt::WPen::width | ( |  | ) | const

Returns the pen width.

See also
  setWidth(const WLength&)