2012-03-16 14:42:35 +00:00
|
|
|
Drawing
|
2012-03-23 16:05:08 +00:00
|
|
|
-------
|
2012-04-04 10:04:52 +00:00
|
|
|
|
2013-04-30 21:16:06 +00:00
|
|
|
Each widget has a canvas, i.e. a place to draw on. The canvas is a group of
|
2014-03-10 21:39:26 +00:00
|
|
|
drawing instructions that should be executed whenever there is a change to the
|
|
|
|
widget's graphical representation.
|
|
|
|
|
2013-04-30 21:16:06 +00:00
|
|
|
You can add two types of instructions to the canvas: *context* instructions and
|
2014-03-10 21:39:26 +00:00
|
|
|
*vertex* instructions. You can add instructions either from Python code or from
|
|
|
|
the kv file (the preferred way).
|
2013-04-30 21:16:06 +00:00
|
|
|
If you add them via the kv file, the advantage is that they are automatically
|
|
|
|
updated when any property they depend on changes. In Python, you need to do
|
|
|
|
this yourself.
|
2012-04-04 10:04:52 +00:00
|
|
|
|
2012-04-18 19:12:50 +00:00
|
|
|
.. image:: ../images/gs-drawing.png
|
2012-04-04 10:04:52 +00:00
|
|
|
|
2013-04-30 21:16:06 +00:00
|
|
|
In both cases, the canvas of `MyWidget` is re-drawn whenever the ``position``
|
|
|
|
or the ``size`` of the widget changes.
|
2012-04-04 10:04:52 +00:00
|
|
|
|
2014-03-13 01:24:43 +00:00
|
|
|
You can use the
|
2014-03-13 03:31:20 +00:00
|
|
|
:attr:`canvas.before <kivy.graphics.Canvas.before>` or
|
|
|
|
:attr:`canvas.after <kivy.graphics.Canvas.after>` groups to separate
|
2014-03-10 21:39:26 +00:00
|
|
|
your instructions based on when you want them to be executed.
|
2012-04-04 10:04:52 +00:00
|
|
|
|
2013-04-30 21:16:06 +00:00
|
|
|
For an in-depth look at how Kivy's graphics are handled, look
|
|
|
|
:mod:`here <kivy.graphics>`.
|