lib/wx/shapes/arrows/circle_arrow.rb in wxruby3-shapes-0.9.0.pre.beta.3 vs lib/wx/shapes/arrows/circle_arrow.rb in wxruby3-shapes-0.9.5
- old
+ new
@@ -1,38 +1,49 @@
# Wx::SF::CircleArrow - circle arrow class
# Copyright (c) M.J.N. Corino, The Netherlands
-require 'wx/shapes/arrows/solid_arrow'
+require 'wx/shapes/arrows/filled_arrow'
module Wx::SF
- class CircleArrow < SolidArrow
+ # Class extends the Wx::FilledArrow class and encapsulates
+ # circle arrow shapes.
+ class CircleArrow < FilledArrow
# Default circle radius.
- RADIUS = 4
+ RADIUS = 6
- property :radius
-
# Constructor
# @param [Wx::SF::Shape] parent parent shape
def initialize(parent=nil)
super
- @radius = 4
+ scale
end
- # Get or set the circle radius
- attr_accessor :radius
+ # Get the circle radius
+ def get_radius
+ (RADIUS * @ratio).to_i
+ end
+ alias :radius :get_radius
+ def scale
+ @ratio = 1 + (pen_width / 2) * 0.5
+ end
+ protected :scale
+
# Draw arrow shape at the end of a virtual line.
# @param [Wx::RealPoint] from Start of the virtual line
# @param [Wx::RealPoint] to End of the virtual line
# @param [Wx::DC] dc Device context for drawing
def draw(from, to, dc)
- dc.with_pen(@pen) do |dc|
- dc.with_brush(@fill) do |dc|
- dc.draw_circle(to.to_point, @radius)
+ r = radius
+ centre, cp = translate_arrow([Wx::RealPoint.new(r, 0), Wx::RealPoint.new(2*r, 0)], from, to)
+ dc.with_pen(pen) do |dc|
+ dc.with_brush(fill) do |dc|
+ dc.draw_circle(centre, r)
end
end
+ cp
end
end
end