cAbstractTextFigure Class Reference¶

API: cAbstractTextFigure Class Reference
API
cAbstractTextFigure Class Reference
Inheritance diagram for cAbstractTextFigure:
[legend]

Public Member Functions

Constructors, destructor, assignment.
Redefined cObject and cFigure member functions.
virtual cAbstractTextFiguredup () const override
virtual std::string str () const override
virtual void parse (cProperty *property) override
virtual void moveLocal (double dx, double dy) override
Geometry
virtual const PointgetPosition () const
virtual void setPosition (const Point &position)
virtual Anchor getAnchor () const
virtual void setAnchor (Anchor anchor)
virtual Alignment getAlignment () const
virtual void setAlignment (Alignment alignment)
virtual Rectangle getBounds () const
virtual Point getTextExtent () const
virtual double getFontAscent () const
Styling
virtual const ColorgetColor () const
virtual void setColor (const Color &color)
virtual double getOpacity () const
virtual void setOpacity (double opacity)
virtual bool getHalo () const
virtual void setHalo (bool enabled)
virtual const FontgetFont () const
virtual void setFont (Font font)
Input
virtual const char * getText () const
virtual void setText (const char *text)
Public Member Functions inherited from cFigure
 cFigure (const char *name=nullptr)
 cFigure (const cFigure &other)
virtual ~cFigure ()
cFigureoperator= (const cFigure &other)
virtual void forEachChild (cVisitor *v) override
int getId () const
virtual bool isVisible () const
virtual void setVisible (bool visible)
virtual const TransformgetTransform () const
virtual void setTransform (const Transform &transform)
virtual void resetTransform ()
virtual double getZIndex () const
virtual void setZIndex (double zIndex)
virtual double getEffectiveZIndex () const
virtual const char * getTooltip () const
virtual void setTooltip (const char *tooltip)
virtual cObjectgetAssociatedObject () const
virtual void setAssociatedObject (cObject *obj)
virtual const char * getTags () const
virtual void setTags (const char *tags)
virtual cFiguregetParentFigure () const
virtual cCanvasgetCanvas () const
virtual int getNumFigures () const
virtual cFiguregetFigure (int pos) const
virtual cFiguregetFigure (const char *name) const
virtual int findFigure (const char *name) const
virtual int findFigure (const cFigure *figure) const
virtual bool containsFigures () const
virtual cFigurefindFigureRecursively (const char *name) const
virtual cFiguregetFigureByPath (const char *path) const
virtual void addFigure (cFigure *figure)
virtual void addFigure (cFigure *figure, int pos)
virtual cFigureremoveFigure (cFigure *figure)
virtual cFigureremoveFigure (int pos)
virtual cFigureremoveFromParent ()
virtual bool isAbove (const cFigure *figure) const
virtual bool isBelow (const cFigure *figure) const
virtual void insertAbove (cFigure *referenceFigure)
virtual void insertBelow (cFigure *referenceFigure)
virtual void insertAfter (const cFigure *referenceFigure)
virtual void insertBefore (const cFigure *referenceFigure)
virtual void raiseAbove (cFigure *figure)
virtual void lowerBelow (cFigure *figure)
virtual void raiseToTop ()
virtual void lowerToBottom ()
virtual cFiguredupTree () const
virtual void move (double dx, double dy)
virtual void refreshDisplay ()
virtual const char * getRendererClassName () const =0
Public Member Functions inherited from cOwnedObject
 cOwnedObject ()
 cOwnedObject (const char *name, bool namepooling=true)
 cOwnedObject (const cOwnedObject &obj)
virtual ~cOwnedObject ()
cOwnedObjectoperator= (const cOwnedObject &o)
virtual void parsimPack (cCommBuffer *buffer) const override
virtual void parsimUnpack (cCommBuffer *buffer) override
virtual cObjectgetOwner () const override
virtual bool isOwnedObject () const override
Public Member Functions inherited from cNamedObject
 cNamedObject ()
 cNamedObject (const char *name, bool namepooling=true)
 cNamedObject (const cNamedObject &obj)
virtual ~cNamedObject ()
cNamedObjectoperator= (const cNamedObject &o)
virtual void setName (const char *s)
virtual const char * getName () const override
virtual void setNamePooling (bool b)
virtual bool getNamePooling ()
Public Member Functions inherited from cObject
 cObject ()
 cObject (const cObject &other)=default
virtual ~cObject ()
virtual const char * getClassName () const
bool isName (const char *s) const
virtual const char * getFullName () const
virtual std::string getFullPath () const
virtual std::string getClassAndFullName () const
virtual std::string getClassAndFullPath () const
const cObjectgetThisPtr () const
virtual std::ostream & printOn (std::ostream &os) const
virtual bool isSoftOwner () const
cObjectfindObject (const char *name, bool deep=true)
virtual cClassDescriptorgetDescriptor () const
void copyNotSupported () const

Protected Member Functions

virtual const char ** getAllowedPropertyKeys () const override
Protected Member Functions inherited from cObject
virtual void take (cOwnedObject *obj)
virtual void drop (cOwnedObject *obj)
void dropAndDelete (cOwnedObject *obj)

Additional Inherited Members

enum  FontStyle
 Font style constants: FONT_NONE, FONT_BOLD, etc. More...
enum  LineStyle
 Line style constants: LINE_SOLID, LINE_DOTTED, etc. More...
enum  CapStyle
 Line cap style constants: CAP_BUTT, CAP_SQUARE, etc. More...
enum  JoinStyle
 Line join style constants: JOIN_BEVEL, JOIN_MITER, etc. More...
enum  FillRule
 Fill rule constants: FILL_EVENODD, FILL_NONZERO. More...
enum  Arrowhead
 Arrowhead style constants: ARROW_NONE, ARROW_SIMPLE, etc. More...
enum  Interpolation
 Image interpolation mode constants: INTERPOLATION_NONE, INTERPOLATION_FAST, etc. More...
enum  Anchor
 Anchoring mode constants: ANCHOR_CENTER, ANCHOR_N, etc. More...
enum  Alignment
 Text alignment mode constants: ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER. More...
Static Public Member Functions inherited from cOwnedObject
static long getTotalObjectCount ()
static long getLiveObjectCount ()
static void resetObjectCounters ()
static cSoftOwnergetOwningContext ()

Description

Abstract base class for figures that display text. Text may be multi-line.

The location of the text on the canvas is determined jointly by the position and anchor properties. The anchor tells how to position the text relative to the positioning point. For example, if anchor is ANCHOR_CENTER then the text is centered on the point; if anchor is ANCHOR_N then the text will be drawn so that its top center is at the positioning point. The values ANCHOR_BASELINE_START, ANCHOR_BASELINE_MIDDLE, ANCHOR_BASELINE_END refer to the beginning, middle and end of the baseline of the (first line of the) text as anchor point. The chosen alignment mode does not affect this, the baseline anchor points always behave as if the first line spanned the entire width of the bounding box. Anchor defaults to ANCHOR_CENTER.

Other properties in this class define the font, color and opacity of the text.

Member Function Documentation

◆ getAllowedPropertyKeys()

virtual const char ** getAllowedPropertyKeys ( ) const
overrideprotectedvirtual

Returns the list of allowed keys in @figure properties with this figure type, in a nullptr-terminated array of const char* elements. This method is invoked e.g. from parse(), in order to be able to issue error messages for invalid keys in the property. Note that property keys starting with "x-" are already allowed by default. Custom figure classes usually need to override this method together with parse(); see the source code of the library classes for example implementations.

Reimplemented from cFigure.

Reimplemented in cLabelFigure.

References cFigure::cFigure().

◆ dup()

virtual cAbstractTextFigure * dup ( ) const
inlineoverridevirtual

Clones the figure, ignoring its child figures. (The copy will have no children.) To clone a figure together with its figure subtree, use dupTree().

Reimplemented from cFigure.

Reimplemented in cLabelFigure, and cTextFigure.

◆ str()

virtual std::string str ( ) const
overridevirtual

Returns a one-line string with the most characteristic data of the figure.

Reimplemented from cFigure.

◆ parse()

virtual void parse ( cProperty * property)
overridevirtual

This method is invoked by the simulation library to initialize the figure from a @figure NED property. Custom figure classes usually need to override this method (and call the super class' similar method in it).

Note: When overriding parse(), it is usually also necessary to override getAllowedPropertyKeys(), in order to allow new keys in the @figure property.

Reimplemented from cFigure.

Reimplemented in cLabelFigure.

◆ moveLocal()

virtual void moveLocal ( double dx,
double dy )
overridevirtual

Updates the position of the text, see getPosition().

Implements cFigure.

◆ getPosition()

virtual const Point & getPosition ( ) const
inlinevirtual

Returns the position of the text. The position and the anchoring mode jointly determine the placement of the text item; see the class description for details.

◆ setPosition()

virtual void setPosition ( const Point & position)
virtual

Sets the position of the text. The position and the anchoring mode jointly determine the placement of the text item; see the class description for details.

◆ getAnchor()

virtual Anchor getAnchor ( ) const
inlinevirtual

Returns the anchoring mode of the text. The position and the anchoring mode jointly determine the placement of the text item; see the class description for details.

◆ setAnchor()

virtual void setAnchor ( Anchor anchor)
virtual

Sets the anchoring mode of the text. The position and the anchoring mode jointly determine the placement of the text item; see the class description for details.

◆ getAlignment()

virtual Alignment getAlignment ( ) const
inlinevirtual

Returns the alignment mode of the text. This only has an effect on figures with multi-line text. Each line will be aligned within the figure bounding box according to this option. This does not affect the anchor points on the baseline; see the class description for details.

◆ setAlignment()

virtual void setAlignment ( Alignment alignment)
virtual

Sets the alignment mode of the text. This only has an effect on figures with multi-line text. Each line will be aligned within the figure bounding box according to this option. This does not affect the anchor points on the baseline; see the class description for details.

◆ getBounds()

virtual Rectangle getBounds ( ) const
virtual

Returns the bounding box of the text figure.

Caveat: Note that the figure itself only has a position and an anchor available for computing the bounding box, size (and for some cases ascent height) need to be supplied by the user interface of the simulation (cEnvir). The result depends on the details of font rendering and other factors, so the returned numbers and their accuracy may vary across user interfaces, operating systems or even installations. Cmdenv and other non-GUI environments may return completely made-up (but not entirely unrealistic) numbers.

See also
cEnvir::getTextExtent()
getTextExtent()
getFontAscent()

Reimplemented in cLabelFigure.

◆ getTextExtent()

virtual Point getTextExtent ( ) const
virtual

Returns the size of the text figure, not taking into account the anchor point, the position, or (in case of cLabelFigure) the angle.

Caveat: The result depends on the details of font rendering and other factors, so the returned numbers and their accuracy may vary across user interfaces, operating systems or even installations. Cmdenv and other non-GUI environments may return completely made-up (but not entirely unrealistic) numbers.

See also
cEnvir::getTextExtent()
getBounds()
getFontAscent()

◆ getFontAscent()

virtual double getFontAscent ( ) const
virtual

Returns the ascent of the font set on the text figure.

Caveat: The result depends on the details of font rendering and other factors, so the returned number and its accuracy may vary across user interfaces, operating systems or even installations. Cmdenv and other non-GUI environments may return a completely made-up (but not entirely unrealistic) number.

See also
cEnvir::getTextExtent()
getBounds()
getTextExtent()

◆ getColor()

virtual const Color & getColor ( ) const
inlinevirtual

Returns the text color.

◆ setColor()

virtual void setColor ( const Color & color)
virtual

Sets the text color. The default color is black.

◆ getOpacity()

virtual double getOpacity ( ) const
inlinevirtual

Returns the opacity of the figure, a number in the [0,1] interval.

◆ setOpacity()

virtual void setOpacity ( double opacity)
virtual

Sets the line opacity of the figure. The argument must be a number in the [0,1] interval. The default opacity is 1.0.

◆ getHalo()

virtual bool getHalo ( ) const
inlinevirtual

Returns true if a "halo" is displayed around the text.

◆ setHalo()

virtual void setHalo ( bool enabled)
virtual

Sets the flag that controls whether a partially transparent "halo" should be displayed around the text. The halo improves the readability of the text when it is displayed over a background that has similar color as the text, or when it overlaps with other text items. The default setting is false (no halo).

Note: In Qtenv, halo may be slow to render for text figures (cTextFigure) under some circumstances. There is no such penalty for label figures (cLabelFigure).

◆ getFont()

virtual const Font & getFont ( ) const
inlinevirtual

Returns the font used for the figure.

◆ setFont()

virtual void setFont ( Font font)
virtual

Sets the font to be used for the figure. The default font has no specific typeface or size set, allowing the UI to use its preferred font.

◆ getText()

virtual const char * getText ( ) const
inlinevirtual

Returns the text to be displayed.

◆ setText()

virtual void setText ( const char * text)
virtual

Sets the text to be displayed. The text may contain newline and tab characters ("\n", "\t") for formatting.