1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
""" A moveable circle shape. """
from traits.api import Float
from enable.primitives.shape import Shape
class Circle(Shape):
""" A moveable circle shape. """
# The radius of the circle.
radius = Float
# 'CoordinateBox' interface.
#---------------------------
def _bounds_changed(self):
""" Static trait change handler. """
w, h = self.bounds
self.radius = min(w, h) / 2.0
# 'Component' interface.
#-----------------------
def is_in(self, x, y):
""" Return True if a point is considered to be 'in' the component. """
return self._distance_between(self.center, (x, y)) <= self.radius
# Protected 'Component' interface.
#---------------------------------
def _draw_mainlayer(self, gc, view_bounds=None, mode='default'):
""" Draw the component. """
with gc:
gc.set_fill_color(self._get_fill_color(self.event_state))
x, y = self.position
gc.arc(x + self.radius, y + self.radius, self.radius, 0,
2*3.14159, False)
gc.fill_path()
# Draw the shape's text.
self._draw_text(gc)
return
# 'Circle' interface.
#--------------------
def _radius_changed(self):
""" Static trait change handler. """
diameter = self.radius * 2
self.bounds = [diameter, diameter]
|