Object
A View is a special temporary object which is passed to the draw method of a RubyEdit instance. The draw method then fills the View with graphics and text; and it is then passed to the Windows GDI+ system for drawing to the screen. You would never create a new View object in your own code - you must use the View objects that are created automatically whenever an MGUI component needs to be redrawn.
Note that you should not try to store a View object in an instance variable. They are intended to remain in scope only for the duration of a single redraw.
You may, however, pass a View object as an argument to other methods that you call from within a draw method. This allows a screen drawing routine to be divided into smaller sub-routines for easier code management.
When drawing items into a View, all dimensions and sizes use the FlowStone 'grid' co-ordinate space. Position [0.0, 0.0] represents the top left corner of the view. X axis values increase from left to right, and Y axis value from top to bottom.
Dimensions use the current 'grid' size - as seen on the 'graph paper' background of the FlowStone workspace. By default, each grid is eight pixels across, though this can be changed in the FlowStone options menu dialogue, and will also be scaled if you zoom the view.
Dimensions are always given as Float values so that you can draw more precisely (e.g. by default, 0.125 would represent a single pixel.)
The order in which you call the various drawing methods determines the 'z-order' of the rendered graphics. The first item drawn will be the 'background' item, with subsequent graphics layered on top.
When drawing GUI objects to a View, you will always specify an instrument. An instrument can be any of the following items unless otherwise stated in the method description...
Pen -> Draws only an outline. For solid shapes and GraphicsPaths, drawing with a Pen leaves the interior of the shape unfilled (i.e. transparent).
Brush -> Fills the shape with a single solid color.
LinearGradientBrush -> Fills the shape will a gradual 'cross-fade' between two or more colours.
PathGradientBrush -> Fills the shape with a gradient that follows the contours of the shape.
HatchBrush -> Fills the shape with a simple two-colour texture.
TextureBrush -> Fills the shape with a texture derived from a Bitmap.
Note that it is rather tricky to describe the effects of GUI method calls in a text document such as this! The official FlowStone UserGuide includes many screenshots and diagrams which explain these method calls much better!
The combineClip method works much like setClip, but allows a new section of the view to be merged with any clipping area that already exists. See the setClip method for details of the area, points and GraphicsPath ways of setting a clip.
The option argument determines how the new section of view will be combined with the exisiting clipping. It is a short String descriptor that can take any one of the following values...
replace -> The old clip is discarded and replaced.
intersect -> Clip the area shared by the old and new clip.
union -> Add the two clip areas together.
xor -> Remove areas that the new and old clip share.
exclude -> Remove the new area from the old.
complement -> Remove the old area from the new.
# File GUI_Classes.rb, line 908 def combineClip #DUMMY end
Returns the current size of a single 'grid' unit of the View's co-ordinate space, measured in pixels. This is not affected by the current zoom level, and is fixed at the value set in the FlowStone options menu. (8 pixels by default).
Contrast with the gridStep method, which does change with the zoom level.
# File GUI_Classes.rb, line 493 def defaultGridStep #DUMMY end
Draws a chord of an ellipse or circle using the given pen. (i.e. a small section of an ellipse or circle's outline).
The area argument specifies the position and size of the whole ellipse before it is 'sliced' into a segment. This should be an Array containing four float values...
[x-position, y-position, width, height]
The section of the ellipse to draw is given by the remaining two arguments...
start_angle Measured in degrees, clock-wise from the x-axis.
sweep-angle Measured in degrees, clock-wise from the start angle.
# File GUI_Classes.rb, line 656 def drawArc #DUMMY end
Draws a series of Bezier curves that pass through a series of points, and also have 'control points' that describe the amount of curvature.
The series of points is given as a Array. Each Array item should be a two-element array giving the [x, y] position of a point...
The first point is the start point of the curve.
From then on, every third point is a point through which the curve passes.
Each 'pass-through' point is separated by two 'control points'
Bezier curves are too complex to describe in full here, please refer to the user guide (p.155) and the many on-line resources that are available.
# File GUI_Classes.rb, line 707 def drawBeziers #DUMMY end
Draws a Bitmap to the view. Note that this method always draws the whole bitmap, to draw only a section of the bitmap, use the drawBitmapSection method.
The arguments are as follows...
position An Array of Float values. If the Array has only two items, they are taken as the X and Y position of the top left corner. If there are four elements, they are the X and Y position followed by a width and height; the bitmap will then be stretched to fit the area.
alpha (optional) Specifies the transparency of the bitmap, from zero (totally transparent) to 255 (totally opaque).
rotation (optional) Rotates the bitmap by the given value, measured in degrees.
origin A two element array giving the X and Y position around which to rotate the bitmap. It is rotated around its centre point if this is not given.
Note that, if you specify a rotation or the bitmap must be resized, the calculations for this are done for every single redraw - which costs a lot of CPU! Thus, if your application allows it, it is better to use Bitmaps that are already the correct size - or use an 'animation strip' for rotations.
You can also use the setInterpolationMode method to decide what algorithm is used when resizing or rotating a Bitmap, so that you can trade quality for CPU load.
See also drawBitmapSection, setInterpolationMode, getInterpolationMode
# File GUI_Classes.rb, line 798 def drawBitmap #DUMMY end
Draws a rectangular section of a Bitmap to the view. All arguments are the same as for drawBitmap, except for the source argument, which is an Array of four floats giving the X-position, Y-position, width and height of the section to draw - these are measured in pixels, NOT grid units.
See also drawBitmap, setInterpolationMode, getInterpolationMode
# File GUI_Classes.rb, line 816 def drawBitmapSection #DUMMY end
Draws a closed curved shape that passes through a series of points representing its outline.
See the notes in the class description above, and the notes for each instrument class, for details of how different instruments will render the shape.
The series of points is given as a Array. Each Array item should be a two-element array giving the [x, y] position of a point through which the shape's outline will pass.
[ [x1, y1], [x2, y2], [x3, y3], ... ]
If the Float tension is given, it determines how smoothly the curve bends around the given points. A value of zero will simply draw straight lines between the points. Higher values will give a more rounded shape. If not given, the default setting of 0.5 is used, which generally gives a nice smooth shape without extending too far away from the screen area that the points define.
# File GUI_Classes.rb, line 625 def drawClosedCurve #DUMMY end
Draws a curve which passes through a series of points.
The series of points is given as a Array. Each Array item should be a two-element array giving the [x, y] position of a point through which the curve will pass.
[ [x1, y1], [x2, y2], [x3, y3], ... ]
The first point in the Array will be the start position of the curve, and the last point will be the end - start and end are not joined together to form a closed shape that can be filled.
If the Float tension is given, it determines how smoothly the curve bends around the given points. A value of zero will simply draw straight lines between the points. Higher values will give a more rounded shape. If not given, the default setting of 0.5 is used, which generally gives a nice smooth shape without extending too far away from the screen area that the points define.
If segments is given, it should be an Array containing two Integers - giving the indexes of two points from the points Array. Only this section of the curve will then be drawn. This allows only a short section of the curve to be drawn such that it still 'flows' along the smooth path that the whole point Array defines.
# File GUI_Classes.rb, line 688 def drawCurve #DUMMY end
Draws an ellipse onto the view.
See the notes in the class description above, and the notes for each instrument class, for details of how different instruments will render the shape.
The area argument specifies the position and size of the ellipse, and should be an Array containing four float values...
[x-position, y-position, width, height]
This describes a rectangular 'box' into which the ellipse is fitted, with its major and minor axes aligned with the drawing axes. If the given area is square (width == height), a circle is drawn
# File GUI_Classes.rb, line 535 def drawEllipse #DUMMY end
Draws a straight line between two points using the given Pen.
Each point is given as a two element Array...
[x-position, y-position]
# File GUI_Classes.rb, line 637 def drawLine #DUMMY end
Draws a series of lines that join a sequence of points on the view - rather like a 'dot-to-dot' picture book.
The series of points is given as a Array. Each Array item should be a two-element array giving the [x, y] position of a point to be joined by straight lines.
[ [x1, y1], [x2, y2], [x3, y3], ... ]
The first point in the Array will be the start position of the lines, and the last point will be the end - start and end are not joined together to form a closed shape that can be filled.
# File GUI_Classes.rb, line 725 def drawLines #DUMMY end
Draws a GraphicsPath object to the view.
See the notes in the class description above, and the notes for each instrument class, for details of how different instruments will render the shape.
# File GUI_Classes.rb, line 759 def drawPath #DUMMY end
Draws a segment of an ellipse or circle onto the view.
See the notes in the class description above, and the notes for each instrument class, for details of how different instruments will render the shape.
The area argument specifies the position and size of the whole ellipse before it is 'sliced' into a segment. This should be an Array containing four float values...
[x-position, y-position, width, height]
The section of the ellipse to draw is given by the remaining two arguments...
start_angle Measured in degrees, clock-wise from the x-axis.
sweep-angle Measured in degrees, clock-wise from the start angle.
# File GUI_Classes.rb, line 580 def drawPie #DUMMY end
Draws a polygon from a series of points representing its outline. Points are always joined by straight sides.
See the notes in the class description above, and the notes for each instrument class, for details of how different instruments will render the shape.
The series of points is given as a Array. Each Array item should be a two-element array giving the [x, y] position of a corner of the polygon...
[ [x1, y1], [x2, y2], [x3, y3], ... ]
# File GUI_Classes.rb, line 598 def drawPolygon #DUMMY end
Draws a rectangle onto the view.
See the notes in the class description above, and the notes for each instrument class, for details of how different instruments will render the shape.
The area argument specifies the position and size of the rectangle, and should be an Array containing four float values...
[x-position, y-position, width, height]
The rectangle will always be aligned with the drawing axes, it cannot be rotated.
# File GUI_Classes.rb, line 513 def drawRectangle #DUMMY end
Draws an Rectangle onto the view that has all four corners rounded.
See the notes in the class description above, and the notes for each instrument class, for details of how different instruments will render the shape.
The area argument specifies the position and size of the rectangle, and should be an Array containing four float values...
[x-position, y-position, width, height]
The corner argument specifies the roundness of all four corners. It is actually the diameter (not radius!) of a circle that would give the same curvature. Note that some very weird, distorted shapes will result if the corner size is larger than the length of the rectangle's sides!
# File GUI_Classes.rb, line 558 def drawRoundRect #DUMMY end
Draws a string of text (which may be multi-line) to the view.
The Font object will determine what character font and text size will be used. The StringFormat determines how the text will be arranged within the area of screen that is defined by the area argument. The area should be an Array containing four float values...
[x-position, y-position, width, height]
And finally, the given Brush will set the colour of the drawn text.
Note that, depending on the attributes of the StringFormat object, the text may extend outside of the given area. If this is the case, the setClip method may be used to mask out any parts of the text that should be hidden.
# File GUI_Classes.rb, line 746 def drawString #DUMMY end
call-seq
getInterpolationMode -> Integer
Returns the interpolation mode currently being used by the View.
See also getInterpolationMode, drawBitmap, drawBitmapSection
# File GUI_Classes.rb, line 980 def getInterpolationMode #DUMMY end
Returns the current size of a single 'grid' unit of the View's co-ordinate space, measured in pixels. This will change depending on the current level that you are zoomed into the display. At the normal zoom level, it will be the default grid size (8 pixels unless you have changed this in the options menu)
Contrast with defaultGridStep, which is not affected by the zoom level.
# File GUI_Classes.rb, line 479 def gridStep #DUMMY end
Returns the height of the View, measured in 'grid' units.
# File GUI_Classes.rb, line 834 def height #DUMMY end
Measures the View area that will be occupied by the given String when drawn using the given Font and StringFormat. The String may contain multiple lines.
Location should be an Array giving the position where the text would be drawn. It may contain two or four elements...
[x_position, y_position] #=> Top left corner of the text [x_pos, y_pos, width, height] #=> An area in which to fit the text
If an area is given, the measured size cannot be larger than this area. A common practice it to set the width to the width of the area to draw into, but set the height to an arbitrary, very large, size. You can then measure the height of the text when word-wrapped to the given width.
The return value is a Hash containing several items of data. The Hash keys are Strings, as follows...
bounds -> A four element array giving the area into which the text will fit -> as Floats measured in 'grid' units.
width -> Width of the text. A Float measured in 'grid' units.
height -> Height of the text. A Float measured in 'grid' units.
chars -> How many characters of the String will fit inside the area.
lines -> How many lines of the String will fit inside the area.
For example:
# Measure some text data = view.measureText("Hello", my_font, my_format, [0.0, 0.0, 100.0, 100.0]) # How wide was it? watch data["width"] #=> 3.25 # How many characters will fit watch data["chars"] #=> 5
# File GUI_Classes.rb, line 1020 def measureText #DUMMY end
If the setClip or combineClip methods have been used to define only a section of the view that can be drawn to, calling resetClip will remove the clipping so that the whole view can be drawn to again.
Note that resetClip is called automatically in between redraws, so that each new call to the draw method begins with an unclipped view.
See also setClip, combineClip
# File GUI_Classes.rb, line 882 def resetClip #DUMMY end
Set clip is used to ensure that the View's drawing methods can only draw on a limited portion of the View. This does not affect any graphics that have already been drawn to the view - but once set, pixels outside the given area cannot be changed until the resetClip or combineClip method makes them available again.
If an area is given, it defines a rectangular area of the view that may be drawn on. It should be an Array containing four float values...
[x-position, y-position, width, height]
If an Array of points is given...
[ [x1, y1], [x2, y2], [x3, y3], ... ]
...the clipped area will be a polygon where the points represent its vertices (corners).
If a GraphicsPath is given, the clipped area will take the shape that the GraphicsPath defines.
Note that the effects of setClip only last for the current redraw. The clipping is reset before the screen is redrawn again.
See also resetClip, combineClip
# File GUI_Classes.rb, line 866 def setClip #DUMMY end
If a Bitmap is drawn to a View with rotation or re-sizing, interpolation is used to ensure that the resulting image does not show nasty artefacts. Several forms of interpolation are available so that you can trade the smoothness of the image with the CPU time taken to do the resizing or rotation. The mode is set by giving either an Integer index or a short String descriptor from the following list...
0 or "off"
1 or "low"
2 or "high"
3 or "bilinear"
4 or "bicubic"
5 or "nearest"
6 or "hqbilinear"
7 or "hqbicubic"
See also getInterpolationMode, drawBitmap, drawBitmapSection
# File GUI_Classes.rb, line 969 def setInterpolationMode #DUMMY end
By default, all graphics are smoothed (anti-aliased). For lines which align with the X and Y axes, this can sometimes lead to a little blurring, though it makes curves look much smoother.
The setSmoothingMode method allows anti-aliasing to be turned on or off. To turn smoothing off, pass either integer zero, or the String "off". To turn smoothing on, pass either integer one, or the String "on".
# File GUI_Classes.rb, line 923 def setSmoothingMode #DUMMY end
By default, FlowStone tries to display text that looks as smooth as possible by anti-aliasing it. However, this may not always look good for very small text sizes, or when the font is not a 'TrueType' font. Calling this method allows you to change the way that text is rendered to suit those occasions where the default settings don't look so good. The single argument is a short String descriptor chosen from the following list...
off -> No smoothing is applied.
singleBitPerPixelGridFit -> Unsmoothed, but tries to align with pixels.
singleBitPerPixel -> Unsmoothed, no alignment
antiAliasGridFit -> Smoothed, attempts to align with pixels.
antiAlias -> Smoothed, no alignment.
clearTypeGridFit -> Windows 'Clear Type' method.
# File GUI_Classes.rb, line 944 def setTextRenderingHint #DUMMY end
Returns the width of the View, measured in 'grid' units.
# File GUI_Classes.rb, line 825 def width #DUMMY end
Generated with the Darkfish Rdoc Generator 2.