DrawObjects

From Dabo Wiki
Jump to: navigation, search

Dabo supports the drawing of basic shapes on any of its UI surfaces. This is done by calling one of several drawing primitives:

obj = self.drawCircle(x, y, radius)
obj = self.drawRectangle(x, y, width, height)
obj = self.drawLine(x1, y1, x2, y2)
obj = self.drawPolygon(points)

All of these methods return an object reference that can later be used to modify the drawing's appearance. Each method can also take additional parameters that control how the shape is drawn. They are (with their default values):

  • penColor ("black") - determines the color of the lines drawn
  • penWidth (1) - width in pixels of the lines. When this is zero or None, no lines are drawn for the perimiter of the shape.
  • fillColor (None) - Color used to fill the interior of the shape. When this is None, the shape is transparent.
  • lineStyle (solid) - can be one of solid, dot, dash or dotdash. Affects the way the perimiter lines of the shape are drawn.
  • persist (True) - does the shape remain drawn? When False, any Paint events can draw over or even erase the shape; also, the return value is None instead of an object reference.

Besides shapes, Dabo suports drawing of bitmaps by calling:

obj = self.drawBitmap(bmp)

This method also returns an object reference that can later be used to modify the drawing's appearance. It can also take additional parameters that control how the shape is drawn. They are (with their default values):

  • x (0) - the x position of the top left corner.
  • y (0) - the y position of the top left corner.
  • persist (True) - does the shape remain drawn? When False, any Paint events can draw over or even erase the shape; also, the return value is None instead of an object reference.

You can also draw text objects at any angle and in any font by calling:

obj = self.drawText(text, x, y)

Like the other methods, this returns a reference to an object you can then manipulate to change the text's appearance. There are several other parameters you can pass that affect the text:

  • angle (0) - angle the text is drawn at. Default is zero (i.e., flat).
  • fontFace (None) - font face used for the text. Default is system-dependent.
  • fontSize (None) - size in points used for the text. Default is system-dependent.
  • fontBold (False) - weight the text is drawn with.
  • fontItalic (False) - controls whether the text is drawn in italic style.
  • fontUnderline (False) - controls whether the text is drawn with an underline
  • foreColor (Black) - color of the text.
  • backColor (None) - background color of the text.

You can also draw gradients that vary continuously from one color to another either horizontally or vertically. The syntax is:

obj = self.drawGradient(orientation, color1=None, color2=None)

Obviously, if you don't specify the colors, nothing will get drawn. You can specify orientation in several ways, as long as the first letter is H or V in either upper or lower case. The default size of the gradient is the entire control; you can change that by specifying any of the following optional parameters:

  • x (0) - x-offset for the left side of the gradient
  • y (0) - y-offset for the top side of the gradient
  • width (None) - width of the drawn gradient. Defaults to the width of the control minus the x-offset.
  • height (None) - height of the drawn gradient. Defaults to the width of the control minus the y-offset.

So now that you've drawn a shape and have a reference to that shape, what can you do with it? Well, every shape supports these methods:

  • bringToFront()
  • sendToBack()
  • moveUp(levels=1)
  • moveDown(levels=1)

These should be self-explanatory. Shapes are drawn in the order they are called, and if they overlap, the later shape draws over any earlier shapes. If you decide that you want to change that order, you can call these methods.


Draw objects also have several properties. Not all will be relevant for all shapes (e.g., Radius only applies to circles). Here are the properties for draw objects:

  • Angle - Angle at which text is drawn
  • BackColor - Background color for the text objects
  • FillColor - Background color for the shape
  • FontBold - Determines if text is drawn in Bold style
  • FontFace - Face used for text objects
  • FontItalic - Determines if text is drawn in Italic style
  • FontSize - Size in points for text objects
  • ForeColor - Color that the text is drawn with.
  • GradientColor1 - Left/Top color for gradient fills
  • GradientColor2 - Right/Bottom color for gradient fills
  • Height - The height of the shape (rectangles)
  • LineStyle - Line style (solid, dash, dot, dot-dash) drawn
  • Orientation - Either Horizontal or Vertical. Determines how gradients are drawn.
  • PenColor - ForeColor of the shape's lines
  • PenWidth - Width of the shape's lines in pixels
  • Points - Tuple of (x,y) pairs defining a polygon
  • Radius - The radius of the shape (circles)
  • Shape - Type of shape to draw (circle, rectangle, polygon, line). Although it is possible to change this, the results may be unpredictable.
  • Transparent - Determines whether bitmaps are drawn transparently.
  • Visible - Controls whether the shape is drawn.
  • Width - The width of the shape (rectangles)
  • Xpos - For circles, the x position of the center. For rectangles, the x position of the top left corner.
  • Ypos - For circles, the y position of the center. For rectangles, the y position of the top left corner.