-
Notifications
You must be signed in to change notification settings - Fork 30
Home
ofxTextSuite provides a number of text functions for re-use.
ofxTextBlock is a text wrapping manager that provides the following features:
- Text wrapping:
- Horiztonal Wrapping
- Area wrap and resize (fit to area)
- Force number of lines of wrap
- Text drawing alignment:
- Left
- Right
- Center
- Justified
- Independent word colouring. E.g. each word can be a different colour.
- Word level access to text.
`void init(string fontLocation, float fontSize);`
e.g. In setup(): `myText.init(“frabk.ttf”, 80);` `void setText(string _inputText);` e.g. In update(): `myText.setText(“The rain in spain rains mainly on the plain.”)``int wrapTextX(float lineWidth);`
`linewidth` is the number of pixels wide to wrap to. This will use the default font size specified during ofxTextBlock.init for it’s calculations. `ofxTextBlock.scale` will be set to `1.0f`; Returns the number of lines it formed.
`void wrapTextArea(float rWidth, float rHeight);`
This function will wrap and resize the text block to `rWidth` and `rHeight`, scaling the text to the largest possible size it can. The function sets the float value of `ofxTextBlock.scale` and then uses it during drawing.
`bool wrapTextForceLines(int linesN);`
This evenly spreads the text over a number of lines: `linesN`. `ofxTextBlock.scale` will be set to `1.0f`;
`void draw(float x, float y);`
Draws the text block left aligned, with the upper left point of the text block at coordinates `x, y`.
`void drawLeft(float x, float y);`
Draws the text block left aligned, with the upper left point of the text block at coordinates `x, y`.
`void drawRight(float x, float y);`
Draws the text block right aligned, with the upper right point of the text block at coordinates `x, y`.
`void drawCenter(float x, float y);`
Draws the text block center aligned, with the upper center point of the text block at coordinates `x, y`.
`void drawJustified(float x, float y, float boxWidth);`
Draws the text block justified, with the upper left point of the text block at coordinates `x, y` and the width of text area specified by `boxWidth`.
`void setLineHeight(float lineHeight);`
Sets the line height with which to render the text. `lineHeight` is specified PRE scaling and hence is proportional to the font size specified in `ofxTextBlock.init`.
`void setColor(int r, int g, int b, int a);`
Sets the color of all words in the text block. Individual word colors can be changed by accessing the `words` vector directly.
`float getWidth();`
Returns the width of the text block, taking into consideration scale.
`float getHeight();`
Returns the height of the text block, taking into consideration scale.
`void forceScale(float _scale);`
Force scale can manually be used after a wrap function to force the text block to a different scale.