Permalink
Browse files

Implemented arc and cap methods.

  • Loading branch information...
1 parent 2d4f27b commit 618f4e6a0520d3ba8609b293cb0c6b088776724b @ashbb committed Apr 17, 2012
Showing with 33 additions and 3 deletions.
  1. +1 −1 VERSION
  2. +1 −0 lib/purple_shoes.rb
  3. +31 −2 lib/shoes/app.rb
View
@@ -1 +1 @@
-0.0.134
+0.0.135
View
@@ -22,6 +22,7 @@ module Shoes
PAGE_UP PAGE_DOWN HOME END INSERT
F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15].each{|k| KEY_NAMES[eval("Swt::SWT::#{k}")] = k}
KEY_NAMES[Swt::SWT::CR] = "\n"
+ LINECAP = {curve: Swt::SWT::CAP_ROUND, rect: Swt::SWT::CAP_FLAT, project: Swt::SWT::CAP_SQUARE}
COLORS = {}
end
View
@@ -279,6 +279,7 @@ def shape args={}, &blk
args[:stroke] ||= stroke
args[:fill] ||= fill
args[:rotate] ||= rotate
+ args[:cap] = (LINECAP[args[:cap]] or cap)
args[:real], args[:app], args[:block] = :shape, self, blk
Shape.new(args).tap do |s|
pl = Swt::PaintListener.new
@@ -292,6 +293,7 @@ class << pl; self end.
gc = e.gc
Shoes.dps_reset s.dps, gc
gc.setAntialias Swt::SWT::ON
+ gc.setLineCap s.cap
sw, pat1, pat2 = s.strokewidth, s.stroke, s.fill
Shoes.set_rotate gc, *s.rotate do
if pat2
@@ -336,7 +338,9 @@ def oval *attrs, &blk
args[:stroke] ||= stroke
args[:fill] ||= fill
args[:rotate] ||= rotate
+ args[:cap] = (LINECAP[args[:cap]] or cap)
args[:real], args[:app] = :shape, self
+ args[:angle1] = false unless args[:angle1]
Oval.new(args).tap do |s|
pl = Swt::PaintListener.new
s.pl = pl
@@ -347,17 +351,20 @@ class << pl; self end.
gc = e.gc
Shoes.dps_reset s.dps, gc
gc.setAntialias Swt::SWT::ON
+ gc.setLineCap s.cap
sw, pat1, pat2 = s.strokewidth, s.stroke, s.fill
Shoes.set_rotate gc, *s.rotate do
if pat2
Shoes.set_pattern s, gc, pat2
- gc.fillOval s.left+sw, s.top+sw, s.width-sw*2, s.height-sw*2
+ s.angle1 ? gc.fillArc(s.left+sw, s.top+sw, s.width-sw*2, s.height-sw*2, s.angle1, s.angle2) :
+ gc.fillOval(s.left+sw, s.top+sw, s.width-sw*2, s.height-sw*2)
end
if pat1
Shoes.set_pattern s, gc, pat1, :Foreground
if sw > 0
gc.setLineWidth sw
- gc.drawOval s.left+sw/2, s.top+sw/2, s.width-sw, s.height-sw
+ s.angle1 ? gc.drawArc(s.left+sw/2, s.top+sw/2, s.width-sw, s.height-sw, s.angle1, s.angle2) :
+ gc.drawOval(s.left+sw/2, s.top+sw/2, s.width-sw, s.height-sw)
end
end
end
@@ -368,6 +375,13 @@ class << pl; self end.
clickable s, &blk
end
end
+
+ def arc l, t, w, h, a1, a2, args={}
+ a1 = a1 * 180 / Math::PI
+ a2 = -a2 * 180 / Math::PI
+ args.merge!({angle1: a1, angle2: a2})
+ oval l, t, w, h, args
+ end
def rect *attrs, &blk
args = attrs.last.class == Hash ? attrs.pop : {}
@@ -390,6 +404,7 @@ def rect *attrs, &blk
args[:stroke] ||= stroke
args[:fill] ||= fill
args[:rotate] ||= rotate
+ args[:cap] = (LINECAP[args[:cap]] or cap)
args[:real], args[:app] = :shape, self
Rect.new(args).tap do |s|
pl = Swt::PaintListener.new
@@ -401,6 +416,7 @@ class << pl; self end.
gc = e.gc
Shoes.dps_reset s.dps, gc
gc.setAntialias Swt::SWT::ON
+ gc.setLineCap s.cap
sw, pat1, pat2 = s.strokewidth, s.stroke, s.fill
Shoes.set_rotate gc, *s.rotate do
if pat2
@@ -458,6 +474,7 @@ def line *attrs, &blk
args[:stroke] ||= stroke
args[:rotate] ||= rotate
+ args[:cap] = (LINECAP[args[:cap]] or cap)
args[:real], args[:app] = :shape, self
Line.new(args).tap do |s|
pl = Swt::PaintListener.new
@@ -469,6 +486,7 @@ class << pl; self end.
gc = e.gc
Shoes.dps_reset s.dps, gc
gc.setAntialias Swt::SWT::ON
+ gc.setLineCap s.cap
sw, pat = s.strokewidth, s.stroke
Shoes.set_rotate gc, *s.rotate do
if pat
@@ -501,6 +519,7 @@ def star *attrs, &blk
args[:stroke] ||= stroke
args[:fill] ||= fill
args[:rotate] ||= rotate
+ args[:cap] = (LINECAP[args[:cap]] or cap)
args[:real], args[:app] = :shape, self
Star.new(args).tap do |s|
pl = Swt::PaintListener.new
@@ -512,6 +531,7 @@ class << pl; self end.
gc = e.gc
Shoes.dps_reset s.dps, gc
gc.setAntialias Swt::SWT::ON
+ gc.setLineCap s.cap
sw, pat1, pat2 = s.strokewidth, s.stroke, s.fill
outer, inner, points, left, top = s.outer, s.inner, s.points, s.left, s.top
polygon = []
@@ -735,5 +755,14 @@ def gray *attrs
g, a = attrs
g ? rgb(g*255, g*255, g*255, a) : rgb(128, 128, 128)[0..2]
end
+
+ def cap *line_cap
+ @line_cap = case line_cap.first
+ when :curve, :rect, :project
+ LINECAP[line_cap.first]
+ else
+ @line_cap ||= LINECAP[:rect]
+ end
+ end
end
end

0 comments on commit 618f4e6

Please sign in to comment.