wxruby3-shapes 0.9.0.pre.beta.3 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/INSTALL.md +5 -7
- data/README.md +38 -6
- data/assets/logo.svg +339 -0
- data/assets/logo.xpm +60 -0
- data/assets/screenshot.png +0 -0
- data/assets/social.png +0 -0
- data/bin/wx-shapes +1 -1
- data/lib/wx/shapes/arrow_base.rb +4 -11
- data/lib/wx/shapes/arrows/circle_arrow.rb +22 -11
- data/lib/wx/shapes/arrows/circle_prong_arrow.rb +48 -0
- data/lib/wx/shapes/arrows/cross_bar_arrow.rb +57 -0
- data/lib/wx/shapes/arrows/cross_bar_circle_arrow.rb +56 -0
- data/lib/wx/shapes/arrows/cross_bar_prong_arrow.rb +49 -0
- data/lib/wx/shapes/arrows/crossed_circle.rb +46 -0
- data/lib/wx/shapes/arrows/cup_arrow.rb +65 -0
- data/lib/wx/shapes/arrows/diamond_arrow.rb +8 -13
- data/lib/wx/shapes/arrows/double_cross_bar_arrow.rb +27 -0
- data/lib/wx/shapes/arrows/filled_arrow.rb +60 -0
- data/lib/wx/shapes/arrows/line_arrow.rb +67 -0
- data/lib/wx/shapes/arrows/open_arrow.rb +22 -23
- data/lib/wx/shapes/arrows/prong_arrow.rb +42 -0
- data/lib/wx/shapes/arrows/solid_arrow.rb +21 -35
- data/lib/wx/shapes/arrows/square_arrow.rb +37 -0
- data/lib/wx/shapes/auto_layout.rb +2 -2
- data/lib/wx/shapes/base.rb +1 -1
- data/lib/wx/shapes/canvas_history.rb +20 -0
- data/lib/wx/shapes/connection_point.rb +10 -6
- data/lib/wx/shapes/diagram.rb +98 -78
- data/lib/wx/shapes/events.rb +8 -8
- data/lib/wx/shapes/printout.rb +3 -16
- data/lib/wx/shapes/serializable.rb +2 -436
- data/lib/wx/shapes/serialize/wx.rb +30 -18
- data/lib/wx/shapes/shape.rb +211 -168
- data/lib/wx/shapes/shape_canvas.rb +728 -267
- data/lib/wx/shapes/shape_data_object.rb +99 -18
- data/lib/wx/shapes/shape_handle.rb +18 -11
- data/lib/wx/shapes/shape_list.rb +34 -67
- data/lib/wx/shapes/shapes/bitmap_shape.rb +23 -24
- data/lib/wx/shapes/shapes/box_shape.rb +389 -0
- data/lib/wx/shapes/shapes/circle_shape.rb +19 -22
- data/lib/wx/shapes/shapes/control_shape.rb +77 -41
- data/lib/wx/shapes/shapes/curve_shape.rb +38 -31
- data/lib/wx/shapes/shapes/diamond_shape.rb +7 -17
- data/lib/wx/shapes/shapes/edit_text_shape.rb +6 -9
- data/lib/wx/shapes/shapes/ellipse_shape.rb +12 -15
- data/lib/wx/shapes/shapes/flex_grid_shape.rb +58 -33
- data/lib/wx/shapes/shapes/grid_shape.rb +259 -161
- data/lib/wx/shapes/shapes/line_shape.rb +155 -161
- data/lib/wx/shapes/shapes/manager_shape.rb +77 -0
- data/lib/wx/shapes/shapes/multi_sel_rect.rb +8 -8
- data/lib/wx/shapes/shapes/ortho_shape.rb +31 -36
- data/lib/wx/shapes/shapes/polygon_shape.rb +23 -29
- data/lib/wx/shapes/shapes/rect_shape.rb +95 -53
- data/lib/wx/shapes/shapes/round_ortho_shape.rb +6 -8
- data/lib/wx/shapes/shapes/round_rect_shape.rb +20 -24
- data/lib/wx/shapes/shapes/square_shape.rb +14 -17
- data/lib/wx/shapes/shapes/text_shape.rb +95 -53
- data/lib/wx/shapes/version.rb +1 -1
- data/lib/wx/shapes/wx.rb +16 -7
- data/lib/wx/wx-shapes/cmd/test.rb +1 -1
- data/samples/demo/arrows.json +1 -0
- data/samples/demo/arrows.yaml +793 -0
- data/samples/demo/art/HBox.xpm +22 -0
- data/samples/demo/art/VBox.xpm +22 -0
- data/samples/demo/art/logo.xpm +60 -0
- data/samples/demo/class.json +1 -0
- data/samples/demo/class.yaml +5631 -0
- data/samples/demo/demo.rb +301 -91
- data/samples/demo/dialogs.rb +1405 -0
- data/samples/demo/erd.json +1 -0
- data/samples/demo/erd.yaml +4072 -0
- data/samples/demo/frame_canvas.rb +409 -33
- data/samples/sample1/art/logo.xpm +60 -0
- data/samples/sample1/sample.rb +11 -11
- data/samples/sample2/art/logo.xpm +60 -0
- data/samples/sample2/sample.rb +2 -2
- data/samples/sample2/sample_shape.rb +15 -15
- data/samples/sample3/art/logo.xpm +60 -0
- data/samples/sample3/sample.rb +3 -3
- data/samples/sample4/art/logo.xpm +60 -0
- data/samples/sample4/sample.rb +2 -2
- data/tests/lib/wxapp_runner.rb +4 -0
- data/tests/serializer_tests.rb +8 -441
- data/tests/test_grid_shapes.rb +2 -2
- data/tests/test_serialize_xml.rb +17 -0
- data/tests/test_serialize_yaml.rb +2 -2
- metadata +78 -28
- data/lib/wx/shapes/serialize/core.rb +0 -40
- data/lib/wx/shapes/serialize/id.rb +0 -82
- data/lib/wx/shapes/serializer/json.rb +0 -258
- data/lib/wx/shapes/serializer/yaml.rb +0 -125
- data/samples/demo/art/sample.xpm +0 -251
- data/samples/sample1/art/sample.xpm +0 -251
- data/samples/sample2/art/sample.xpm +0 -251
- data/samples/sample3/art/sample.xpm +0 -251
- data/samples/sample4/art/sample.xpm +0 -251
@@ -0,0 +1,57 @@
|
|
1
|
+
# Wx::SF::CrossBarArrow - crossbar arrow class
|
2
|
+
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
|
+
|
4
|
+
require 'wx/shapes/arrows/line_arrow'
|
5
|
+
|
6
|
+
module Wx::SF
|
7
|
+
|
8
|
+
# Class extends the Wx::LineArrow class and encapsulates
|
9
|
+
# arrow shape consisting of single crossbar before the end of the
|
10
|
+
# parent line shape.
|
11
|
+
class CrossBarArrow < LineArrow
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def arrow(ratio)
|
15
|
+
x = ratio*6; y = ratio*6
|
16
|
+
[[Wx::RealPoint.new(x,y), Wx::RealPoint.new(x, -y), Wx::RealPoint.new(x, 0)]]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Constructor
|
21
|
+
# @param [Wx::SF::Shape] parent parent shape
|
22
|
+
def initialize(parent=nil)
|
23
|
+
super(parent)
|
24
|
+
scale
|
25
|
+
end
|
26
|
+
|
27
|
+
def lines
|
28
|
+
@lines ||= CrossBarArrow.arrow(@ratio)
|
29
|
+
end
|
30
|
+
private :lines
|
31
|
+
|
32
|
+
def scale
|
33
|
+
@lines = nil
|
34
|
+
@ratio = 1 + (pen_width / 2) * 0.5
|
35
|
+
end
|
36
|
+
protected :scale
|
37
|
+
|
38
|
+
# Draw arrow shape at the end of a virtual line.
|
39
|
+
# @param [Wx::RealPoint] from Start of the virtual line
|
40
|
+
# @param [Wx::RealPoint] to End of the virtual line
|
41
|
+
# @param [Wx::DC] dc Device context for drawing
|
42
|
+
# @return [Wx::Point] translated connection point for arrow
|
43
|
+
def draw(from, to, dc)
|
44
|
+
bar_cp = nil
|
45
|
+
dc.with_pen(pen) do |dc|
|
46
|
+
lines.each do |line|
|
47
|
+
bar_from, bar_to, bar_cp = translate_arrow(line, from, to)
|
48
|
+
dc.draw_line(bar_from, bar_to)
|
49
|
+
end
|
50
|
+
dc.draw_line(bar_cp, to.to_point)
|
51
|
+
end
|
52
|
+
bar_cp
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Wx::SF::CrossBarCircleArrow - crossbar with circle arrow class
|
2
|
+
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
|
+
|
4
|
+
require 'wx/shapes/arrows/circle_arrow'
|
5
|
+
|
6
|
+
module Wx::SF
|
7
|
+
|
8
|
+
# Class extends the Wx::CircleArrow class and encapsulates
|
9
|
+
# circle arrow shapes with a crossbar.
|
10
|
+
class CrossBarCircleArrow < CircleArrow
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def arrow(ratio)
|
14
|
+
x = ratio*6; y = ratio*6
|
15
|
+
[Wx::RealPoint.new(x,y), Wx::RealPoint.new(x, -y), Wx::RealPoint.new(x, 0)]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Default circle radius.
|
20
|
+
RADIUS = 4
|
21
|
+
|
22
|
+
# Constructor
|
23
|
+
# @param [Wx::SF::Shape] parent parent shape
|
24
|
+
def initialize(parent=nil)
|
25
|
+
super
|
26
|
+
scale
|
27
|
+
end
|
28
|
+
|
29
|
+
def line
|
30
|
+
@line ||= CrossBarCircleArrow.arrow(@ratio)
|
31
|
+
end
|
32
|
+
private :line
|
33
|
+
|
34
|
+
def scale
|
35
|
+
@line = nil
|
36
|
+
super
|
37
|
+
end
|
38
|
+
protected :scale
|
39
|
+
|
40
|
+
# Draw arrow shape at the end of a virtual line.
|
41
|
+
# @param [Wx::RealPoint] from Start of the virtual line
|
42
|
+
# @param [Wx::RealPoint] to End of the virtual line
|
43
|
+
# @param [Wx::DC] dc Device context for drawing
|
44
|
+
def draw(from, to, dc)
|
45
|
+
dc.with_pen(pen) do |dc|
|
46
|
+
bar_from, bar_to, bar_mid = translate_arrow(line, from, to)
|
47
|
+
dc.draw_line(bar_from, bar_to)
|
48
|
+
dc.draw_line(bar_mid, to.to_point)
|
49
|
+
to = bar_mid
|
50
|
+
end
|
51
|
+
super(from, to, dc)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Wx::SF::CrossBarProngArrow - crossbar with prong arrow class
|
2
|
+
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
|
+
|
4
|
+
require 'wx/shapes/arrows/prong_arrow'
|
5
|
+
|
6
|
+
module Wx::SF
|
7
|
+
|
8
|
+
# Class extends the Wx::ProngArrow class and encapsulates
|
9
|
+
# arrow shape consisting of single two lines bisecting before the end of the
|
10
|
+
# parent line shape with a crossbar at the intersection point.
|
11
|
+
class CrossBarProngArrow < ProngArrow
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def arrow(ratio)
|
15
|
+
x = ratio*6; y = ratio*6
|
16
|
+
[Wx::RealPoint.new(0,y), Wx::RealPoint.new(0, -y), Wx::RealPoint.new(0, 0)]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def line
|
21
|
+
@line ||= CrossBarProngArrow.arrow(@ratio)
|
22
|
+
end
|
23
|
+
private :line
|
24
|
+
|
25
|
+
def scale
|
26
|
+
@line = nil
|
27
|
+
super
|
28
|
+
end
|
29
|
+
protected :scale
|
30
|
+
|
31
|
+
# Draw arrow shape at the end of a virtual line.
|
32
|
+
# @param [Wx::RealPoint] from Start of the virtual line
|
33
|
+
# @param [Wx::RealPoint] to End of the virtual line
|
34
|
+
# @param [Wx::DC] dc Device context for drawing
|
35
|
+
# @return [Wx::Point] translated connection point for arrow
|
36
|
+
def draw(from, to, dc)
|
37
|
+
to = super
|
38
|
+
dc.with_pen(pen) do |dc|
|
39
|
+
bar_from, bar_to, bar_mid = translate_arrow(line, from, to)
|
40
|
+
dc.draw_line(bar_from, bar_to)
|
41
|
+
dc.draw_line(bar_mid, to.to_point)
|
42
|
+
to = bar_mid
|
43
|
+
end
|
44
|
+
to
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Wx::SF::CrossedCircleArrow - circle with cross arrow class
|
2
|
+
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
|
+
|
4
|
+
require 'wx/shapes/arrows/circle_arrow'
|
5
|
+
|
6
|
+
module Wx::SF
|
7
|
+
|
8
|
+
# Class extends the Wx::CircleArrow class and encapsulates
|
9
|
+
# arrow shape consisting a crossed circle.
|
10
|
+
class CrossedCircleArrow < CircleArrow
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def crossbar(radius)
|
14
|
+
[Wx::RealPoint.new(radius,radius), Wx::RealPoint.new(radius, -radius)]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def crossbar
|
19
|
+
@crossbar ||= CrossedCircleArrow.crossbar(radius)
|
20
|
+
end
|
21
|
+
private :crossbar
|
22
|
+
|
23
|
+
def scale
|
24
|
+
@crossbar = nil
|
25
|
+
super
|
26
|
+
end
|
27
|
+
protected :scale
|
28
|
+
|
29
|
+
# Draw arrow shape at the end of a virtual line.
|
30
|
+
# @param [Wx::RealPoint] from Start of the virtual line
|
31
|
+
# @param [Wx::RealPoint] to End of the virtual line
|
32
|
+
# @param [Wx::DC] dc Device context for drawing
|
33
|
+
# @return [Wx::Point] translated connection point for arrow
|
34
|
+
def draw(from, to, dc)
|
35
|
+
cp = super
|
36
|
+
cb = translate_arrow(crossbar, from, to)
|
37
|
+
dc.with_pen(pen) do |dc|
|
38
|
+
dc.draw_line(cb[0], cb[1])
|
39
|
+
dc.draw_line(cp, to.to_point)
|
40
|
+
end
|
41
|
+
cp
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Wx::SF::SquareArrow - square arrow class
|
2
|
+
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
|
+
|
4
|
+
require 'wx/shapes/arrows/line_arrow'
|
5
|
+
|
6
|
+
module Wx::SF
|
7
|
+
|
8
|
+
# Class extends the Wx::SolidArrow class and encapsulates
|
9
|
+
# cup arrow shapes.
|
10
|
+
class CupArrow < LineArrow
|
11
|
+
|
12
|
+
# Default arc radius size
|
13
|
+
RADIUS = 7
|
14
|
+
|
15
|
+
class << self
|
16
|
+
|
17
|
+
def arrow(radius)
|
18
|
+
[Wx::RealPoint.new(0, radius), Wx::RealPoint.new(0, -radius), Wx::RealPoint.new(0, 0), Wx::RealPoint.new(radius, 0)]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
# Constructor
|
24
|
+
# @param [Wx::SF::Shape] parent parent shape
|
25
|
+
def initialize(parent=nil)
|
26
|
+
super
|
27
|
+
scale
|
28
|
+
end
|
29
|
+
|
30
|
+
# Get the circle radius
|
31
|
+
def get_radius
|
32
|
+
(RADIUS * @ratio).to_i
|
33
|
+
end
|
34
|
+
alias :radius :get_radius
|
35
|
+
|
36
|
+
def coords
|
37
|
+
@coords ||= CupArrow.arrow(get_radius)
|
38
|
+
end
|
39
|
+
protected :coords
|
40
|
+
|
41
|
+
def scale
|
42
|
+
@coords = nil
|
43
|
+
@ratio = 1 + (pen_width / 2) * 0.5
|
44
|
+
end
|
45
|
+
protected :scale
|
46
|
+
|
47
|
+
# Draw arrow shape at the end of a virtual line.
|
48
|
+
# @param [Wx::RealPoint] from Start of the virtual line
|
49
|
+
# @param [Wx::RealPoint] to End of the virtual line
|
50
|
+
# @param [Wx::DC] dc Device context for drawing
|
51
|
+
# @return [Wx::Point] translated connection point for arrow
|
52
|
+
def draw(from, to, dc)
|
53
|
+
rarrow = translate_arrow(coords, from, to)
|
54
|
+
cp = rarrow.pop
|
55
|
+
dc.with_pen(pen) do |dc|
|
56
|
+
dc.with_brush(Wx::TRANSPARENT_BRUSH) do |dc|
|
57
|
+
dc.draw_arc(*rarrow)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
cp
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -5,28 +5,23 @@ require 'wx/shapes/arrows/solid_arrow'
|
|
5
5
|
|
6
6
|
module Wx::SF
|
7
7
|
|
8
|
+
# Class extends the Wx::SolidArrow class and encapsulates
|
9
|
+
# solid diamond arrow shapes.
|
8
10
|
class DiamondArrow < SolidArrow
|
9
11
|
|
10
12
|
class << self
|
11
13
|
|
12
|
-
def
|
13
|
-
|
14
|
+
def arrow(ratio)
|
15
|
+
x = ratio*10; y = ratio*5
|
16
|
+
[Wx::RealPoint.new(0,0), Wx::RealPoint.new(x, y), Wx::RealPoint.new(2*x,0), Wx::RealPoint.new(x,-y), Wx::RealPoint.new(2*x,0)]
|
14
17
|
end
|
15
18
|
|
16
19
|
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
# @param [Wx::RealPoint] to End of the virtual line
|
21
|
-
# @param [Wx::DC] dc Device context for drawing
|
22
|
-
def draw(from, to, dc)
|
23
|
-
rarrow = translate_arrow(DiamondArrow.diamond_arrow, from, to)
|
24
|
-
dc.with_pen(@pen) do |dc|
|
25
|
-
dc.with_brush(@fill) do |dc|
|
26
|
-
dc.draw_polygon(rarrow)
|
27
|
-
end
|
28
|
-
end
|
21
|
+
def vertices
|
22
|
+
@vertices ||= DiamondArrow.arrow(@ratio)
|
29
23
|
end
|
24
|
+
protected :vertices
|
30
25
|
|
31
26
|
end
|
32
27
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Wx::SF::DoubleCrossBarArrow - double crossbar arrow class
|
2
|
+
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
|
+
|
4
|
+
require 'wx/shapes/arrows/cross_bar_arrow'
|
5
|
+
|
6
|
+
module Wx::SF
|
7
|
+
|
8
|
+
# Class extends the Wx::CrossBarArrow class and encapsulates
|
9
|
+
# arrow shape consisting of double crossbar before the end of the
|
10
|
+
# parent line shape.
|
11
|
+
class DoubleCrossBarArrow < CrossBarArrow
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def arrow(ratio)
|
15
|
+
x = ratio*7; y = ratio*6
|
16
|
+
[[Wx::RealPoint.new(2+x/2,y), Wx::RealPoint.new(2+x/2, -y)],[Wx::RealPoint.new(2+x,y), Wx::RealPoint.new(2+x, -y), Wx::RealPoint.new(2+x, 0)]]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def lines
|
21
|
+
@lines ||= DoubleCrossBarArrow.arrow(@ratio)
|
22
|
+
end
|
23
|
+
private :lines
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Wx::SF::FilledArrow - closed line drawn arrow class
|
2
|
+
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
|
+
|
4
|
+
require 'wx/shapes/arrows/line_arrow'
|
5
|
+
|
6
|
+
module Wx::SF
|
7
|
+
|
8
|
+
# Class extends the Wx::LineArrow class and encapsulates
|
9
|
+
# enclosed and filled arrow shapes.
|
10
|
+
class FilledArrow < LineArrow
|
11
|
+
|
12
|
+
module DEFAULT
|
13
|
+
class << self
|
14
|
+
def fill; @fill ||= Wx::WHITE_BRUSH.dup; end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
property fill: :serialize_arrow_fill
|
19
|
+
|
20
|
+
# Constructor
|
21
|
+
# @param [Wx::SF::Shape] parent parent shape
|
22
|
+
def initialize(parent=nil)
|
23
|
+
super
|
24
|
+
@fill = DEFAULT.fill
|
25
|
+
end
|
26
|
+
|
27
|
+
# Get arrow fill brush
|
28
|
+
# @return [Wx::Brush]
|
29
|
+
def get_fill
|
30
|
+
@fill || (@diagram&.shape_canvas ? @diagram.shape_canvas.arrow_fill : DEFAULT.fill)
|
31
|
+
end
|
32
|
+
alias :fill :get_fill
|
33
|
+
|
34
|
+
# Set arrow fill brush
|
35
|
+
# @overload set_fill(brush)
|
36
|
+
# @param [Wx::Brush] brush
|
37
|
+
# @overload set_fill(color, style=Wx::BrushStyle::BRUSHSTYLE_SOLID)
|
38
|
+
# @param [Wx::Colour,Symbol,String] color brush color
|
39
|
+
# @param [Wx::BrushStyle] style
|
40
|
+
# @overload set_fill(stipple_bitmap)
|
41
|
+
# @param [Wx::Bitmap] stipple_bitmap
|
42
|
+
def set_fill(brush)
|
43
|
+
@fill = if args.size == 1 && Wx::Brush === args.first
|
44
|
+
args.first
|
45
|
+
else
|
46
|
+
Wx::Brush.new(*args)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
alias :fill= :set_fill
|
50
|
+
|
51
|
+
# (de-)serialize only
|
52
|
+
def serialize_arrow_fill(*val)
|
53
|
+
@fill = val.first unless val.empty?
|
54
|
+
@fill
|
55
|
+
end
|
56
|
+
private :serialize_arrow_fill
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Wx::SF::LineArrow - line drawn arrow base class
|
2
|
+
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
|
+
|
4
|
+
require 'wx/shapes/arrow_base'
|
5
|
+
|
6
|
+
module Wx::SF
|
7
|
+
|
8
|
+
# Class extends the Wx::ArrowBase class and encapsulates
|
9
|
+
# line drawn arrow shapes.
|
10
|
+
# The shapes are automatically scaled based on the line width used.
|
11
|
+
class LineArrow < ArrowBase
|
12
|
+
|
13
|
+
property pen: :serialize_pen
|
14
|
+
|
15
|
+
# Constructor
|
16
|
+
# @param [Wx::SF::Shape] parent parent shape
|
17
|
+
def initialize(parent=nil)
|
18
|
+
super
|
19
|
+
@pen = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get arrow border pen
|
23
|
+
# @return [Wx::Pen,nil]
|
24
|
+
def get_pen
|
25
|
+
@pen || @parent_shape&.line_pen
|
26
|
+
end
|
27
|
+
alias :pen :get_pen
|
28
|
+
|
29
|
+
# Set arrow border pen (when nil restore the default).
|
30
|
+
# @param [Wx::Pen,nil] pen
|
31
|
+
def set_pen(pen)
|
32
|
+
@pen = pen
|
33
|
+
scale
|
34
|
+
end
|
35
|
+
alias :pen= :set_pen
|
36
|
+
|
37
|
+
# Return current pen width.
|
38
|
+
# @return [Integer]
|
39
|
+
def get_pen_width
|
40
|
+
get_pen&.width || 1
|
41
|
+
end
|
42
|
+
alias :pen_width :get_pen_width
|
43
|
+
|
44
|
+
# Set a parent of the arrow shape.
|
45
|
+
# @param [Wx::SF::Shape] parent parent shape
|
46
|
+
def set_parent_shape(parent)
|
47
|
+
super
|
48
|
+
scale
|
49
|
+
end
|
50
|
+
alias :parent_shape= :set_parent_shape
|
51
|
+
|
52
|
+
# Scale the arrow.
|
53
|
+
# Does nothing by default.
|
54
|
+
def scale
|
55
|
+
# noop
|
56
|
+
end
|
57
|
+
protected :scale
|
58
|
+
|
59
|
+
def serialize_pen(*arg)
|
60
|
+
@pen = arg.shift unless arg.empty?
|
61
|
+
@pen
|
62
|
+
end
|
63
|
+
private :serialize_pen
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -1,54 +1,53 @@
|
|
1
1
|
# Wx::SF::OpenArrow - open arrow class
|
2
2
|
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
3
|
|
4
|
-
require 'wx/shapes/
|
4
|
+
require 'wx/shapes/arrows/line_arrow'
|
5
5
|
|
6
6
|
module Wx::SF
|
7
7
|
|
8
|
-
# Class extends the
|
8
|
+
# Class extends the Wx::LineArrow class and encapsulates
|
9
9
|
# arrow shape consisting of single two lines leading from the end of the
|
10
10
|
# parent line shape.
|
11
|
-
class OpenArrow <
|
11
|
+
class OpenArrow < LineArrow
|
12
12
|
|
13
13
|
class << self
|
14
|
-
def
|
15
|
-
|
14
|
+
def arrow(ratio)
|
15
|
+
x = ratio*11; y = ratio*5
|
16
|
+
[Wx::RealPoint.new(0,0), Wx::RealPoint.new(x, y), Wx::RealPoint.new(x,-y), Wx::RealPoint.new(x, 0)]
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
property :arrow_pen
|
20
|
-
|
21
20
|
# Constructor
|
22
21
|
# @param [Wx::SF::Shape] parent parent shape
|
23
22
|
def initialize(parent=nil)
|
24
|
-
super
|
25
|
-
|
23
|
+
super(parent)
|
24
|
+
scale
|
26
25
|
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
def get_arrow_pen
|
31
|
-
@pen
|
27
|
+
def vertices
|
28
|
+
@vertices ||= OpenArrow.arrow(@ratio)
|
32
29
|
end
|
33
|
-
|
30
|
+
private :vertices
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@pen = pen
|
32
|
+
def scale
|
33
|
+
@vertices = nil
|
34
|
+
@ratio = 1 + (pen_width / 2) * 0.5
|
39
35
|
end
|
40
|
-
|
36
|
+
protected :scale
|
41
37
|
|
42
38
|
# Draw arrow shape at the end of a virtual line.
|
43
39
|
# @param [Wx::RealPoint] from Start of the virtual line
|
44
40
|
# @param [Wx::RealPoint] to End of the virtual line
|
45
41
|
# @param [Wx::DC] dc Device context for drawing
|
42
|
+
# @return [Wx::Point] translated connection point for arrow
|
46
43
|
def draw(from, to, dc)
|
47
|
-
|
48
|
-
dc.with_pen(
|
49
|
-
dc.draw_line(
|
50
|
-
dc.draw_line(
|
44
|
+
tip, wing1, wing2, cp = translate_arrow(vertices, from, to)
|
45
|
+
dc.with_pen(pen) do |dc|
|
46
|
+
dc.draw_line(tip, wing1)
|
47
|
+
dc.draw_line(tip, wing2)
|
48
|
+
dc.draw_line(tip, cp)
|
51
49
|
end
|
50
|
+
cp
|
52
51
|
end
|
53
52
|
|
54
53
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Wx::SF::ProngArrow - prong arrow class
|
2
|
+
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
|
+
|
4
|
+
require 'wx/shapes/arrows/open_arrow'
|
5
|
+
|
6
|
+
module Wx::SF
|
7
|
+
|
8
|
+
# Class extends the Wx::OpenArrow class and encapsulates
|
9
|
+
# arrow shape consisting of single two lines bisecting before the end of the
|
10
|
+
# parent line shape.
|
11
|
+
class ProngArrow < OpenArrow
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def arrow(ratio)
|
15
|
+
x = ratio*11; y = ratio*5
|
16
|
+
[Wx::RealPoint.new(x,0), Wx::RealPoint.new(0, y), Wx::RealPoint.new(0,-y), Wx::RealPoint.new(0, 0)]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def vertices
|
21
|
+
@vertices ||= ProngArrow.arrow(@ratio)
|
22
|
+
end
|
23
|
+
private :vertices
|
24
|
+
|
25
|
+
# Draw arrow shape at the end of a virtual line.
|
26
|
+
# @param [Wx::RealPoint] from Start of the virtual line
|
27
|
+
# @param [Wx::RealPoint] to End of the virtual line
|
28
|
+
# @param [Wx::DC] dc Device context for drawing
|
29
|
+
# @return [Wx::Point] translated connection point for arrow
|
30
|
+
def draw(from, to, dc)
|
31
|
+
cp, wing1, wing2, tip = translate_arrow(vertices, from, to)
|
32
|
+
dc.with_pen(pen) do |dc|
|
33
|
+
dc.draw_line(cp, wing1)
|
34
|
+
dc.draw_line(cp, wing2)
|
35
|
+
dc.draw_line(cp, tip)
|
36
|
+
end
|
37
|
+
cp
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -1,67 +1,53 @@
|
|
1
1
|
# Wx::SF::SolidArrow - solid arrow class
|
2
2
|
# Copyright (c) M.J.N. Corino, The Netherlands
|
3
3
|
|
4
|
-
require 'wx/shapes/
|
4
|
+
require 'wx/shapes/arrows/filled_arrow'
|
5
5
|
|
6
6
|
module Wx::SF
|
7
7
|
|
8
|
-
class
|
8
|
+
# Class extends the Wx::FilledArrow class and encapsulates
|
9
|
+
# solid arrow shapes.
|
10
|
+
class SolidArrow < FilledArrow
|
9
11
|
|
10
12
|
class << self
|
11
|
-
def
|
12
|
-
|
13
|
+
def arrow(ratio)
|
14
|
+
x = ratio*11; y = ratio*5
|
15
|
+
[Wx::RealPoint.new(0,0), Wx::RealPoint.new(x, y), Wx::RealPoint.new(x,-y), Wx::RealPoint.new(x,0)]
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
|
-
property :arrow_fill, :arrow_pen
|
17
|
-
|
18
19
|
# Constructor
|
19
20
|
# @param [Wx::SF::Shape] parent parent shape
|
20
21
|
def initialize(parent=nil)
|
21
22
|
super
|
22
|
-
|
23
|
-
@pen = DEFAULT::BORDER
|
24
|
-
end
|
25
|
-
|
26
|
-
# Get arrow fill brush
|
27
|
-
# @return [Wx::Brush]
|
28
|
-
def get_arrow_fill
|
29
|
-
@fill
|
30
|
-
end
|
31
|
-
alias :arrow_fill :get_arrow_fill
|
32
|
-
|
33
|
-
# Set arrow fill brush
|
34
|
-
# @param [Wx::Brush] brush
|
35
|
-
def set_arrow_fill(brush)
|
36
|
-
@fill = brush
|
23
|
+
scale
|
37
24
|
end
|
38
|
-
alias :arrow_fill= :set_arrow_fill
|
39
25
|
|
40
|
-
|
41
|
-
|
42
|
-
def get_arrow_pen
|
43
|
-
@pen
|
26
|
+
def vertices
|
27
|
+
@vertices ||= SolidArrow.arrow(@ratio)
|
44
28
|
end
|
45
|
-
|
29
|
+
protected :vertices
|
46
30
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
@pen = pen
|
31
|
+
def scale
|
32
|
+
@vertices = nil
|
33
|
+
@ratio = 1 + (pen_width / 2) * 0.5
|
51
34
|
end
|
52
|
-
|
35
|
+
protected :scale
|
53
36
|
|
54
37
|
# Draw arrow shape at the end of a virtual line.
|
55
38
|
# @param [Wx::RealPoint] from Start of the virtual line
|
56
39
|
# @param [Wx::RealPoint] to End of the virtual line
|
57
40
|
# @param [Wx::DC] dc Device context for drawing
|
41
|
+
# @return [Wx::Point] translated connection point for arrow
|
58
42
|
def draw(from, to, dc)
|
59
|
-
rarrow = translate_arrow(
|
60
|
-
|
61
|
-
|
43
|
+
rarrow = translate_arrow(vertices, from, to)
|
44
|
+
cp = rarrow.pop # get connection point
|
45
|
+
dc.with_pen(pen) do |dc|
|
46
|
+
dc.with_brush(fill) do |dc|
|
62
47
|
dc.draw_polygon(rarrow)
|
63
48
|
end
|
64
49
|
end
|
50
|
+
cp
|
65
51
|
end
|
66
52
|
|
67
53
|
end
|