class Display
Display and Display-derived classes render Value into the specified rectangular area. References to Displays are used in many widgets as attributes affecting the rendering of widget Values. Default implementation uses StdDisplay to perform all actions (see below for StdDisplay description).
Visual style constants are used as "style" parameter bit flags of rendering methods and provide additional information about required visual appearance:
CURSOR Gui element is current ("has cursor").
FOCUS Gui element has focus.
SELECT Gui element is selected.
READONLY Gui element is read-only.
virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
This virtual method is used to paint rectangle content according to specified Value. Note that it is OK for derived class to understand just Value types it was designed for (and crash otherwise) - it is client code responsibility to use the correct Display.
|
ink |
Suggested foreground color. |
|
paper |
Suggested background color. |
virtual void PaintBackground(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
This virtual method is used to paint areas of GUI element that are outside of rectangle specified in Paint method, but should have color related somewhat to current Display class - usually this color is the same as background painted in Paint. (Note that Paint method must clear the background separately, although base Display class is defined to use PaintBackground for this task).
|
ink |
Suggested foreground color. |
|
paper |
Suggested background color. |
virtual Size GetStdSize(const Value& q) const
Should return standard size for given value and Display. E.g. if Display is rendering Images, it should return the Size of the Image in pixels. Base Display returns the size of textual representation of the Value.
|
Return value |
Size of Value for Display. |
virtual Size RatioSize(const Value& q, int cx, int cy) const
Returns size for defined value keeping the aspect ratio.
|
cx |
Required width. If zero, it should be computed to keep aspect ratio with cy. |
|
cy |
Required height. If zero, it should be computed to keep aspect ratio with cx. |
|
Return value |
Size of Value for Display. |
struct AttrText
Simple helper class convertible to the Value. StdDisplay, StdRightDisplay and StdCenterDisplay detect whether Value passed in is of AttrText type and handle it differently by adopting non-null attributes for the text painted.
WString text
Text to be displayed.
Font font
Font of text.
Color ink
Text color.
Color paper
Background color
AttrText& Ink(Color c)
Sets the text color.
AttrText& Paper(Color c)
Sets the paper color.
AttrText& SetFont(Font f)
Sets the font.
AttrText & Align(int a)
Sets the text horizontal alignment. Approved values are ALIGN_LEFT, ALIGN_CENTER and ALIGN_RIGHT.
AttrText & Left()
Aligns the text left.
AttrText & Center()
Aligns the text to the center.
AttrText & Right()
Aligns the text right.
operator Value() const
|
Return value |
AttrText as raw Value. |
AttrText(const char *text)
Constructs AttrText, assigning the text attribute and all other attributes to zero.
AttrText(const wchar *text)
Constructs AttrText, assigning the text attribute and all other attributes to zero.
AttrText(const WString& text)
Constructs AttrText, assigning the text attribute and all other attributes to zero.
Standard Displays
Standard Displays are implemented as "functional globals" - functions returning constant reference to single global Display instance.
|
Display name
|
Description
|
StdDisplay
|
Standard Display. Displays Value as text, unless it is AttrText (see above).
|
StdRightDisplay
|
Standard Display. Displays Value as right-aligned text, unless it is AttrText (see above).
|
StdCenterDisplay
|
Standard Display. Displays Value as centered text, unless it is AttrText (see above).
|
ColorDisplay
|
Displays Color (required) - simply paints background using the Value passed in.
|
SizeTextDisplay
|
Similar to StdDisplay, but stretches the text size to fill whole display area.
|
ImageDisplay
|
Displays Image passed in as Value, aligns it to the top-left corner.
|
FittedImageDisplay
|
Displays Image scaled to fit the rectangle.
|
CenteredImageDisplay
|
Displays Image centered in the rectangle.
|
CenteredHighlightImageDisplay
|
Displays Image centered in the rectangle with 1 pixel wide white border.
|
DrawingDisplay
|
Displays Drawing scaled to fit the rectangle.
|
|
|
class PaintRect : private Moveable<PaintRect>
PaintRect is a simple helper class that combines Value and a reference to the Display to provide "visual content" of rectangle. It is Moveable.
void Paint(Draw& w, const Rect& r, Color ink = SColorText, Color paper = SColorPaper, dword style = 0) const
Invokes Paint of contained Display for contained Value.
|
ink |
Suggested foreground color. |
|
paper |
Suggested background color. |
void Paint(Draw& w, int x, int y, int cx, int cy, Color ink = SColorText, Color paper = SColorPaper, dword style = 0) const
Invokes contained Display with contained Value.
|
x, y, cx, cy |
Target rectangle (left, top, width, height). |
|
ink |
Suggested foreground color. |
|
paper |
Suggested background color. |
Size GetStdSize() const
Invokes GetStdSize of contained Display for contained Value.
|
Return value |
Preferred Size of Value. |
Size RatioSize(int cx, int cy) const
Invokes RatioSize of contained Display for contained Value.
|
cx |
Required width. If zero, it should be computed to keep aspect ratio with cy. |
|
cy |
Required height. If zero, it should be computed to keep aspect ratio with cx. |
|
Return value |
Size of Value for Display. |
Size RatioSize(Size sz) const
Equivalent to RatioSize(sz.cx, sz.cy).
void SetDisplay(const Display& d)
Sets the Display.
void SetValue(const Value& v)
Sets the Value.
void Set(const Display& d, const Value& v)
Sets the Display and the Value.
void Clear()
Removes the Display - subsequent calls to Paint act as "no operation", calls to GetStdSize and RatioSize return Size(0, 0).
const Value& GetValue() const
Returns the Value.
const Display& GetDisplay() const
Returns the Display.
operator bool() const
|
Return value |
true if Display is set. |
PaintRect()
Constructs empty PaintRect, with no Display assigned.
PaintRect(const Display& display)
Constructs PaintRect with specified Display.
PaintRect(const Display& display, const Value& val)
Constructs PaintRext with specified Display and Value.
|