2012-03-16 14:42:35 +00:00
|
|
|
Drawing
|
2012-03-23 16:05:08 +00:00
|
|
|
-------
|
2012-04-04 19:38:00 +00:00
|
|
|
.. container:: title
|
2012-03-16 14:42:35 +00:00
|
|
|
|
2012-04-04 19:38:00 +00:00
|
|
|
Graphics Instructions, Canvas
|
2012-04-04 10:04:52 +00:00
|
|
|
|
2012-07-08 09:36:49 +00:00
|
|
|
Each widget has a canvas, i.e. a place to draw on. The canvas is a group of instructions that should be executed
|
|
|
|
whenever there is a change to the widget's graphics representation.
|
|
|
|
You can add two types of instructions to the canvas, *context* instructions and *vertex* instructions.
|
|
|
|
You can add instructions either from Python or from kv (the preferred way).
|
|
|
|
If you add them from kv, 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
|
|
|
|
2012-04-18 19:12:50 +00:00
|
|
|
In both cases the canvas of the MyWidget is re-drawn whenever the ``position`` or the ``size`` of the widget changes.
|
2012-04-04 10:04:52 +00:00
|
|
|
|
2012-07-08 09:36:49 +00:00
|
|
|
You can use **canvas.before** or **canvas.after** . This allows you to separate your instructions based on when you want them to happen.
|
2012-04-04 10:04:52 +00:00
|
|
|
|
2012-07-08 09:36:49 +00:00
|
|
|
For an in-depth look at how Kivy's graphics are handled, look `here. <http://kivy.org/docs/api-kivy.graphics.html>`_
|