circular button

637 views
Skip to first unread message

jcy29

unread,
Oct 12, 2011, 10:16:22 AM10/12/11
to Kivy users support
I recently saw an answer about the circular button in kivy:

>You must differenciate the Widget graphics and Widget bounding box.
>The bounding box of the widget will be always expressed as a rectangle (pos
+ size)
> So you can draw anything inside the bounding box (recommanded), like you can
> draw a circle, or even custom shape using image with transparency.
> Then you have the collision with the widget: it's handled by the method
> collide_point(). You can overload it and implement a custom collisiion
> function using Vector.distance() for a circle, or even use Image.read_pixel
> (if Image(keep_data=True)) and check alpha part of the color. And you'll
> have your result: drawing a custom shape button with adapted collision to
> the shape.

But I did not quite understand what you said about drawing bounding
box of widgets. If you do not mind, could you give me a short example
please?Thank you in advance

Mathieu Virbel

unread,
Oct 16, 2011, 6:18:16 AM10/16/11
to kivy-...@googlegroups.com
Hi,

Every widget in Kivy have its own position and size. This is what we
call the bounding box. (Google it if you don't know about it.)
All widgets have a collision function. You can give a (x, y), it will
return True/False if the coordinate is inside the bounding box or not.

Now, depending the widget, you'll have graphics instructions attached
to it. The graphics use the pos/size of the widget.
The graphics don't change anything to the collide function.
Graphics can draw outside the bounding box.

So if you want to have a collision function that match your graphics,
you must adapt it too.

Now, try to re-read the response to understand the proposed solution.

Regards,

Mathieu


2011/10/12 jcy29 <jeanclaude....@gmail.com>:

Reply all
Reply to author
Forward
0 new messages