Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site













SourceForge.net Logo

Label routines

 

LabelBase.h contains functions and simple helper classes used to implement Ctrls with text, images and accelerator keys.

Generally, format of text used by LabelBase facilities is either simple multi-line or QTF:

If first character of text is '\1', text is QTF (starting with next character).

If first character is NOT '\1', text is simple multi-line text with '\n' used as line separator.

In both cases, '&' or '\b' are used as access-key flags. If '&' should be the part of text, it must be escaped as "&&". This format is formally named "SmartText".

Note also that U++ normally distributes access-keys automatically. Providing access-key is thus usually unnecessary.

 

 

String DeAmp(const char *s)

This routine escapes all occurrences of '&' character in source string with "&&" string to avoid using it as access-key flag.

s

Input string.

Return value

Escaped string.

 


 

Size GetSmartTextSize(const char *text, Font font = StdFont(), int cx = INT_MAX)

Returns the minimal size of SmartText. If text is multi-paragraph QTF text, width of text is the width of widest paragraph without doing any line breaks (paragraphs are formatted for infinite width).

w

Draw.

text

SmartText string.

font

Font for non-QTF text.

Return value

Size of SmartText.

 


 

int GetSmartTextHeight(const char *s, int cx, Font font = StdFont())

Returns the height of given SmartText for given width. QTF paragraphs are formatted for this width.

w

Draw.

s

SmartText string.

cx

Required width.

font

Font for non-QTF text.

Return value

Height of SmartText.

 


 

void DrawSmartText(Draw& w, int x, int y, int cx, const char *text, Font font = StdFont(), Color ink = DefaultInk, int accesskey = 0)

Paints SmartText to target Draw.

w

Draw.

x, y

Position.

cx

Required width.

text

SmartText.

font

Font for non-QTF SmartText.

ink

Text color for non-QTF SmartText.

accesskey

Access-key - first corresponding character will be painted with underline.

 


 

byte ExtractAccessKey(const char *s, String& label)

Scans input string for access-key.

s

Input string.

label

Output string - with access-key removed.

Return value

Access-key.

 


 

bool CompareAccessKey(byte accesskey, dword key)

Compares access key to U++ event key value as received by Key virtual method.

accesskey

Access-key.

key

U++ event key value.

Return value

True if values match.

 


 

byte ChooseAccessKey(const char *s, dword used)

Scans input string for suitable access-key.

s

Input string.

used

Bit-set of already used access-keys. Bit-mask of specific access-key is defined by Ctrl::AccessKeyBit class method.

Return value

Access-key or 0 if no suitable access-key found.

 

 

 

 

DrawLabel

 

struct DrawLabel

This structure in fact just encapsulates generic label painting routine that otherwise would have way too much parameters.

 

 

Constructor Detail

 

DrawLabel()

Default constructor. Default values are documented in attributes descriptions.

 

 

Public Member List

 

Size GetSize(int txtcx = INT_MAX) const

Returns the size of label based on current set of attributes. txtcx specifies the maximum width of text.

 


 

Size Paint(Draw& w, const Rect& r, bool visibleaccesskey = trueconst

Paints the label in given rectangle.

w

Draw.

r

Rectangle.

visibleacckey

Access-keys should be graphically highlighted (underlined).

Return value

Size of label.

 


 

Size Paint(Draw& w, int x, int y, int cx, int cy, bool visibleaccesskey = trueconst

Paints the label in given rectangle.

w

Draw.

x, y, cx, cy

Position and size of rectangle.

visibleacckey

Access-keys should be graphically highlighted (underlined).

Return value

Size of label.

 


 

bool push

Label should be painted as "pushed" (means paint offset one pixel right and down). Default is false.

 


 

bool focus

Label should be painted as "with input focus" (light blue rectangle is drawn around label). Default is false.

 


 

bool disabled

Label should be painted as "disable" (affects the way how images and text are painted, disabled mean they are gray).

 


 

PaintRect paintrect

This paintrect is painted behind the label text. If label text is empty, size of text area is determined as paintrect.GetSize().

 


 

Image limg

Left image.

 


 

Color lcolor

Color of left monochromatic image. Null means that the image is color.

 


 

int lspc

Space between left image and text. If Null, image is placed at left edge of Label.

 


 

String text

Text of label.

 


 

Font font

Font used to paint non-QTF text.

 


 

Color ink

Color used to paint non-QTF text.

 


 

Image rimg

Right image.

 


 

Color rcolor

Color of monochromatic right image. Null means that the image is color.

 


 

int rspc

Space between the right image and text. If Null, image is placed at the right size of Label.

 


 

int align

Horizontal alignment. Can be ALIGN_LEFT, ALIGN_RIGHT or ALIGN_CENTER.

 


 

int valign

Vertical alignment. Can be ALIGN_TOP, ALIGN_BOTTOM or ALIGN_CENTER.

 


 

bool nowrap

When true (default false), now text wrapping is performed.

 


 

int accesskey

Access-key.

 

 

 

 

LabelBase

 

class LabelBase

This class encapsulates basic DrawLabel struct into form suitable to play a role of base class of GUI elements.

 

 

Public Method List

 

virtual void LabelUpdate()

This virtual method is called each time when any of attributes changes.

 


 

LabelBase& SetLeftImage(const Image& bmp1, int spc = 0)

Sets the left image.

bmp1

Image.

spc

Space between left image and text. If Null, image is placed at left size of Label.

Return value

*this for chaining.

 


 

LabelBase& SetPaintRect(const PaintRect& pr)

Sets PaintRect to be drawn behind or instead of label text.

pr

PaintRect

Return value

*this for chaining.

 


 

LabelBase& SetText(const char *text)

Sets text of the label.

text

Text.

Return value

*this for chaining.

 


 

LabelBase& SetFont(Font font)

Sets font of non-QTF text.

font

Font.

Return value

*this for chaining.

 


 

LabelBase& SetInk(Color color)

Sets the color of non-QTF text .

color

Color.

Return value

*this for chaining.

 


 

LabelBase& SetRightImage(const Image& bmp2, int spc = 0)

Sets the right image.

bmp2

Image.

spc

Space between left image and text. If Null, image is placed at left size of Label.

Return value

*this for chaining.

 


 

LabelBase& SetAlign(int align)

Sets horizontal alignment.

align

One of ALIGN_LEFT, ALIGN_RIGHT or ALIGN_CENTER.

Return value

*this for chaining.

 


 

LabelBase& AlignLeft()

Same as SetAlign(ALIGN_LEFT).

 


 

LabelBase& AlignCenter()

Same as SetAlign(ALIGN_CENTER).

 


 

LabelBase& AlignRight()

Same as SetAlign(ALIGN_RIGHT).

 


 

LabelBase& SetVAlign(int align)

Sets vertical alignment.

align

One of ALIGN_TOP, ALIGN_BOTTOM or ALIGN_CENTER.

Return value

*this for chaining.

 


 

LabelBase& AlignTop()

Same as SetVAlign(ALIGN_TOP).

 


 

LabelBase& AlignVCenter()

Same as SetVAlign(ALIGN_CENTER).

 


 

LabelBase& AlignBottom()

Same as SetVAlign(ALIGN_BOTTOM).

 


 

LabelBase& NoWrap(bool b = true)

When active (default false), now text wrapping is performed.

 


 

LabelBase& SetImage(const Image& bmp, int spc = 0)

Same as SetLeftImage(bmp, spc).

 


 

int GetAlign() const

Return value

Current horizontal alignment.

 


 

int GetVAlign() const

Return value

Current vertical alignment.

 


 

PaintRect GetPaintRect() const

Return value

Current PaintRect.

 


 

String GetText() const

Return value

Current label text.

 


 

Font GetFont() const

Return value

Current font.

 


 

Color GetInk() const

Return value

Current text color.

 


 

Size PaintLabel(Draw& w, const Rect& r, bool disabled = false, bool push = false, bool focus = false, bool vak = true)

Paints label in the given rectangle.

w

Draw.

r

Rectangle.

disabled

Disable flag.

push

Push flag.

focus

Focus flag.

vak

If true, accelerator should be highlighted.

Return value

Size of label.

 


 

Size PaintLabel(Draw& w, int x, int y, int cx, int cy, bool disabled = false, bool push = false, bool focus = false, bool vak = true)

Paints label in the given rectangle.

w

Draw.

x, y, cx, cy

Rectangle.

disabled

Disable flag.

push

Push flag.

focus

Focus flag.

vak

If true, accelerator should be highlighted.

Return value

Size of label.

 


 

Size GetLabelSize() const

Return value

Size of label.

 

 

Last edit by cxl on 12/02/2017. Do you want to contribute?. T++