User Guide
Ruby Component
The first two inputs are the same as for the isVisible method. The pen input defines the pen that the path would be drawn with. The point is
then tested to see if it would lie on the drawn path. Obviously the wider the pen, the more likely this is. The return value is either true or false.
Text
You can draw text to a View using the drawString method. However, before we talk about this you're going to need to know about two other
drawing classes.
The Font Class
The Font class defines the typeface you'll use for drawing your text. You need to supply the name of the typeface (this must be a font that is
installed on your system), the size of font (in grid squares) and the style.
The style can be any combination of “normal”, “bold”, “italic”, “underline” and “strikeout”. For example, “bolditalic” or “strikeout-underline”. You
can have spaces in the strings or use hyphens or other symbols – as long as the key words are present then FlowBotics Studio will pick
them up. You can also use an integer in the range 0-15 to specify style combinations as a bitmask. The bits are 1 = bold, 2= italic, 4 =
underline and 8 = strikeout. So by adding these together 1+4+8 = 13 is the same as “bold-underline-strikeout”.
Here's an example of how to create a font:
font = Font.new “Arial”,1.2,”normal”
The StringFormat Class
The StringFormat class defines how text is placed relative to its location or bounding rectangle. There are 3 attributes to consider. Alignment
determines how the text aligns horizontally. There are 3 options: near (left), center (middle) or far (right).
Line Alignment determines how the text aligns vertically. There are 3 options here too: near (top), center (middle) or far (bottom).
Finally Flags allows you to specify combinations of more detailed options. The flags input is an integer that should be a bitwise combination
of the options you want. There are quite a number of options so to avoid cluttering things here we've listed them in full at the end of the next
section.
Here's an example on how you might create a StringFormat object:
sf = StringFormat.new
sf.setAlignment “center”
sf.setLineAlignment “far”
sf.setFlags 4128
Drawing the Text
Now let's return to the drawString method. This is defined as follows:
drawString text, font, stringFormat, location, brush
The location can be a point (an array of two values) or a rectangle ( [x,y,width,height]).If the location is a point then all drawing will be
referenced to that point. If the location is a rectangle then the text will be drawn inside that rectangle.
122 of 212