Reference » Window classes » MWindow » drawText

Elgrint::MWindow::drawText(MString,MRect,MTextJustifications) method

Declaration (see MWindow.h):

void drawText(const MString& text, const MRect& bBox, MTextJustifications tj = tjDefault);


Draws the specified text at the coordinates specified by bBox.


Name Type Def value Description
text MString

The text to draw.

Details: The string can include line-breaks and tab characters. Each tab character is replaced with 4 spaces before drawing the string.

bBox MRect

The bounding box for the text.

Details: If bBox.p1() is an invalid MPoint (see MRect::p1), then nothing is drawn. Otherwise, bBox.p1() is transformed according to the latest setDrawTransform.
If bBox.size is an invalid MSize (see MRect::size), then the text is "unbounded", otherwise it is "bounded" by the bBox rect. If the text is bounded, then it is clipped by bBox, i.e. parts of the text that are outside of the box become invisible. If that happens, an ellipsis ("...") is used to inform the user that part of the text is not shown. Of course, the text is also clipped by the window/screen boundaries, in which case the ellipsis is not displayed. If the text is unbounded (bBox.size() is invalid), then bBox.size() is an anchor point (see tj), and the text is clipped only by the window/screen boundaries (no ellipsis). A valid bBox.size() is transformed according to the latest setDrawTransform.


  • The z and d components are reserved for the future support of 3D drawing

tj MTextJustifications tjDefault

Justifies the text. i.e. adjusts its alignment relatively to bBox.

Details: The tj parameter affects the position of the painted text relatively to bBox.
If text is bounded (i.e. bBox.size() is valid), then tj defines the alignment of the text within bBox. For example, if tj contains tjLeft and does not contain tjRight, then the text is "pressed" against the left boundary of bBox.
If text is unbounded (i.e. bBox.size() is invalid), then tj specifies the location of the text relatively to "anchor point" bBox.p1() (the top-left corner of bBox). For example, if tj contains tjLeft and does not contain tjRight, the text appears on the left side of that anchor point.
If text is bounded and tj includes tjWrapped, then the text is wrapped inside bBox at word boundaries (or character boundaries if a word is too long to fit the box). Without tjWrapped the text is not wrapped but clipped by the vertical boundaries of bBox. If the text is unbounded, then tjWrapped is ignored.
See MTextJustifications for more details and examples.


The font and color of the text are determined by the latest setDrawTextSettings.


Let us know

Please Contact us to report any errors on this page, or to suggest any improvements.

Miranor Home | About Miranor | About Elgrint | Create account | Login | Account settings | Contact Us | Privacy Policy | Site map

© Copyright 2014 by Miranor. All rights reserved. By using this site you agree to the Terms of Use.

Page last updated on August 10th, 2014.