blob: 90d51119c3775470e05314dd96ffac11bf20a5aa [file] [log] [blame]
Guido van Rossum7df0c161991-01-23 13:41:31 +00001# A CSplit is a Clock-shaped split: the children are grouped in a circle.
2# The numbering is a little different from a real clock: the 12 o'clock
3# position is called 0, not 12. This is a little easier since Python
4# usually counts from zero. (BTW, there needn't be exactly 12 children.)
5
6
7from math import pi, sin, cos
8from Split import Split
9
Guido van Rossumce084481991-12-26 13:06:29 +000010class CSplit(Split):
Guido van Rossum7df0c161991-01-23 13:41:31 +000011 #
Guido van Rossum89a78691992-12-14 12:57:56 +000012 def getminsize(self, m, (width, height)):
Guido van Rossum7df0c161991-01-23 13:41:31 +000013 # Since things look best if the children are spaced evenly
14 # along the circle (and often all children have the same
15 # size anyway) we compute the max child size and assume
16 # this is each child's size.
Guido van Rossum7df0c161991-01-23 13:41:31 +000017 for child in self.children:
Guido van Rossumca197b51991-08-16 13:05:37 +000018 wi, he = child.getminsize(m, (0, 0))
Guido van Rossum7df0c161991-01-23 13:41:31 +000019 width = max(width, wi)
20 height = max(height, he)
21 # In approximation, the diameter of the circle we need is
22 # (diameter of box) * (#children) / pi.
23 # We approximate pi by 3 (so we slightly overestimate
24 # our minimal size requirements -- not so bad).
25 # Because the boxes stick out of the circle we add the
26 # box size to each dimension.
27 # Because we really deal with ellipses, do everything
28 # separate in each dimension.
29 n = len(self.children)
30 return width + (width*n + 2)/3, height + (height*n + 2)/3
31 #
32 def getbounds(self):
33 return self.bounds
34 #
35 def setbounds(self, bounds):
36 self.bounds = bounds
37 # Place the children. This involves some math.
38 # Compute center positions for children as if they were
39 # ellipses with a diameter about 1/N times the
40 # circumference of the big ellipse.
41 # (There is some rounding involved to make it look
42 # reasonable for small and large N alike.)
43 # XXX One day Python will have automatic conversions...
44 n = len(self.children)
45 fn = float(n)
Guido van Rossumbdfcfcc1992-01-01 19:35:13 +000046 if n == 0: return
Guido van Rossum7df0c161991-01-23 13:41:31 +000047 (left, top), (right, bottom) = bounds
48 width, height = right-left, bottom-top
49 child_width, child_height = width*3/(n+4), height*3/(n+4)
50 half_width, half_height = \
51 float(width-child_width)/2.0, \
52 float(height-child_height)/2.0
53 center_h, center_v = center = (left+right)/2, (top+bottom)/2
54 fch, fcv = float(center_h), float(center_v)
55 alpha = 2.0 * pi / fn
56 for i in range(n):
57 child = self.children[i]
58 fi = float(i)
59 fh, fv = \
60 fch + half_width*sin(fi*alpha), \
61 fcv - half_height*cos(fi*alpha)
62 left, top = \
63 int(fh) - child_width/2, \
64 int(fv) - child_height/2
65 right, bottom = \
66 left + child_width, \
67 top + child_height
Guido van Rossum89a78691992-12-14 12:57:56 +000068 child.setbounds(((left, top), (right, bottom)))
Guido van Rossum7df0c161991-01-23 13:41:31 +000069 #