lib/shoes/swt/star.rb in shoes-swt-4.0.0.pre2 vs lib/shoes/swt/star.rb in shoes-swt-4.0.0.pre3
- old
+ new
@@ -29,21 +29,43 @@
end
def draw(gc)
gc.drawPolygon make_polygon(@obj)
end
-
+
def make_polygon(obj)
outer, inner, points, left, top = obj.outer, obj.inner, obj.points,
obj.element_left, obj.element_top
- polygon = []
- polygon << left << (top + outer)
- (1..points*2).each do |i|
- angle = i * ::Math::PI / points
- r = (i % 2 == 0) ? outer : inner
- polygon << (left + r * ::Math.sin(angle)) << (top + r * ::Math.cos(angle))
+ @polygon = []
+ add_edge(left, top + outer)
+ (1..points * 2).each do |i|
+ make_edge(i, left, top, outer, inner, points)
end
- polygon
+
+ translate_to_proper_start(obj)
+
+ @polygon
+ end
+
+ def add_edge(start, finish)
+ @polygon << start << finish
+ end
+
+ def make_edge(i, left, top, outer, inner, points)
+ r = (i % 2 == 0) ? outer : inner
+ angle = i * ::Math::PI / points
+ add_edge(left + r * ::Math.sin(angle),
+ top + r * ::Math.cos(angle))
+ end
+
+ # Prior logic centers start on left/top, so translate to where we
+ # really want to start.
+ def translate_to_proper_start(obj)
+ return if obj.dsl.style[:center]
+
+ @polygon.map! do |x|
+ x + obj.element_width / 2
+ end
end
end
end
end
end