- Kivy:Interactive Applications and Games in Python(Second Edition)
- Roberto Ulloa
- 460字
- 2021-07-16 14:07:28
Understanding the canvas
Before studying the examples of this chapter, it is important to recapitulate the following particularities related to the graphics display:
- The coordinate space refers to the place in which we draw, which is not restricted to the windows size
- A
Canvas
object is a set of instructions to draw in the coordinate space, not the place we draw in - All
Widget
objects contain their ownCanvas
(canvases, which we will see later) but all of them share the same coordinate space, the one in theApp
object.
For example, if we add a rotation instruction to a specific Canvas
instance (for example, the canvas of a button), then this will also affect all the subsequent graphics instructions that are going to display graphics in the coordinate space. It doesn't matter if the graphics belong to canvases of different widgets; they all share the same coordinate space.
Therefore, we need to learn techniques to leave the coordinate space context in its original state after modifying it with graphics instructions.
Tip
All the graphics instructions added to different Canvas
objects, which at the same time belong to different Widget
objects, affect the same coordinate space. It is our task to make sure that the coordinate space is in its original state after modifying it with the graphics instructions.
Another important concept that we need to extend is the one of the Widget
. We already know that widgets are the blocks that allow us to build interfaces.
Note
A Widget
is also a place marker (with its position and size), but not necessarily a placeholder. The instructions of the canvas of a widget are not restricted to the specific area of the widget but to the whole coordinate space.
This directly adds to the previous problem of sharing a coordinate space. Not only do we need to control the fact that we share a coordinate space, but also, we have no restrictions on where to draw. On one hand, this makes Kivy very efficient and gives us a lot of flexibility. On the other hand, this seems to be a lot to control. Fortunately, Kivy provides the necessary tools to easily work around the problem.
The next section will present the available graphics instructions that can be added to the canvas in order to draw basic shapes. After this, we will explore graphic instructions that change the coordinate space context and exemplify the problems of sharing the coordinate space. The final section concentrates on illustrating the acquired knowledge inside the Comic Creator, where we learn the most common techniques to master the use of the canvas considering its particularities. By the end of this chapter, we will be in complete control of the graphics that are displayed on the screen.
- Unreal Engine Physics Essentials
- OpenDaylight Cookbook
- Python王者歸來
- Mastering LibGDX Game Development
- Magento 1.8 Development Cookbook
- PhoneGap Mobile Application Development Cookbook
- 網絡爬蟲原理與實踐:基于C#語言
- Cybersecurity Attacks:Red Team Strategies
- Android群英傳
- JBoss:Developer's Guide
- Delphi開發典型模塊大全(修訂版)
- Clojure Polymorphism
- Practical Maya Programming with Python
- Python物理建模初學者指南(第2版)
- SFML Game Development