Cairo context and persistence?

拥有回忆 提交于 2019-12-06 02:22:15
ptomato

Cairo drawings don't persist at all. (It's best not to think of them as "objects" -- it's not like a canvas library where you can move them around or transform them after you've drawn them.) You have to do all drawing in the expose handler, or it will, as you have found out, disappear whenever the window is redrawn.

The cairo context doesn't persist because of double buffering: see the note in the C documentation, which unfortunately I couldn't find anywhere in the PyGTK documentation.

In the above code, you should generate the coordinates and color of your random line in the keypress handler and save them in an array. Then in the expose handler, draw each line in the array in order.

tm_lv

while you have to create context on every run, you can achieve the persistence you are looking for by disabling the double buffering of the widget.

here's an example using hamster graphics library that just does that:

https://github.com/projecthamster/experiments/blob/master/many_lines.py

Many flavors of persistence to discuss:

Drawings on some surfaces don't persist: GUI surfaces. You should redraw them in the expose callback.

PyCairo objects shouldn't be treated as persistent objects, only as an interface to functions of the Cairo library in C.

The contents (paths and fills) of Cairo contexts don't persist beyond a stroke() or fill() operation.

A context for a GUI surface doesn't persist between expose events (because of double buffering?) (I don't know whether a context persists for other surfaces i.e. devices.) So you can't use a cairo context to store the attributes of a viewport (a window onto a document i.e. model in user coordinates.)

Visual persistence is the tendency of the human eye to see light after it has ceased. Ghosts and flicker are its symptoms in animation or video. Disabling double buffering lets you see things as they are drawn, that is, enabling animation within one expose event ( the simulation of the symptoms of visual persistence.) Disabling double buffering doesn't make a context on a GUI surface persistent between expose events.

The persistence of memory is the ur real persistence, or should I say surreal.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!