glimmer-dsl-swt 4.18.5.3 → 4.18.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -0
- data/README.md +8 -10
- data/VERSION +1 -1
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +57 -13
- data/docs/reference/GLIMMER_PACKAGING_AND_DISTRIBUTION.md +2 -0
- data/docs/reference/GLIMMER_SAMPLES.md +32 -0
- data/glimmer-dsl-swt.gemspec +10 -3
- data/lib/glimmer/swt/color_proxy.rb +1 -1
- data/lib/glimmer/swt/custom/shape.rb +319 -76
- data/lib/glimmer/swt/custom/shape/arc.rb +22 -4
- data/lib/glimmer/swt/custom/shape/cubic.rb +118 -0
- data/lib/glimmer/swt/custom/shape/image.rb +4 -4
- data/lib/glimmer/swt/custom/shape/line.rb +80 -6
- data/lib/glimmer/swt/custom/shape/oval.rb +3 -3
- data/lib/glimmer/swt/custom/shape/path.rb +227 -0
- data/lib/glimmer/swt/custom/shape/path_segment.rb +133 -0
- data/lib/glimmer/swt/custom/shape/point.rb +41 -0
- data/lib/glimmer/swt/custom/shape/polygon.rb +63 -14
- data/lib/glimmer/swt/custom/shape/polyline.rb +41 -10
- data/lib/glimmer/swt/custom/shape/quad.rb +114 -0
- data/lib/glimmer/swt/custom/shape/rectangle.rb +3 -2
- data/lib/glimmer/swt/custom/shape/text.rb +2 -4
- data/lib/glimmer/swt/dialog_proxy.rb +4 -0
- data/lib/glimmer/swt/proxy_properties.rb +1 -1
- data/samples/elaborate/mandelbrot_fractal.rb +1 -1
- data/samples/elaborate/stock_ticker.rb +220 -0
- data/samples/hello/hello_canvas.rb +38 -21
- data/samples/hello/hello_canvas_data_binding.rb +193 -0
- data/samples/hello/hello_canvas_path.rb +120 -0
- metadata +9 -2
@@ -37,10 +37,23 @@ module Glimmer
|
|
37
37
|
[:x, :y, :width, :height, :start_angle, :arc_angle]
|
38
38
|
end
|
39
39
|
|
40
|
+
def bounds
|
41
|
+
shape_bounds = geometry.getBounds2D
|
42
|
+
org.eclipse.swt.graphics.Rectangle.new(shape_bounds.x, shape_bounds.y, shape_bounds.width, shape_bounds.height)
|
43
|
+
end
|
44
|
+
|
45
|
+
def size
|
46
|
+
shape_bounds = geometry.getBounds2D
|
47
|
+
org.eclipse.swt.graphics.Point.new(shape_bounds.width, shape_bounds.height)
|
48
|
+
end
|
49
|
+
|
50
|
+
def geometry
|
51
|
+
java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, calculated_width, calculated_height, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
|
52
|
+
end
|
53
|
+
|
40
54
|
# checks if shape contains the point denoted by x and y
|
41
55
|
def contain?(x, y)
|
42
|
-
|
43
|
-
shape_geometry.contains(x, y)
|
56
|
+
geometry.contains(x, y)
|
44
57
|
end
|
45
58
|
|
46
59
|
def include?(x, y)
|
@@ -48,11 +61,16 @@ module Glimmer
|
|
48
61
|
contain?(x, y)
|
49
62
|
else
|
50
63
|
# give it some fuzz to allow a larger region around the drawn oval to accept including a point (helps with mouse clickability on a shape)
|
51
|
-
outer_shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y,
|
52
|
-
inner_shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y,
|
64
|
+
outer_shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, calculated_width + 3, calculated_height + 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
|
65
|
+
inner_shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, calculated_width - 3, calculated_height - 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
|
53
66
|
outer_shape_geometry.contains(x, y) && !inner_shape_geometry.contains(x, y)
|
54
67
|
end
|
55
68
|
end
|
69
|
+
|
70
|
+
def irregular?
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
56
74
|
end
|
57
75
|
end
|
58
76
|
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# Copyright (c) 2007-2021 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer/swt/custom/shape'
|
23
|
+
require 'glimmer/swt/custom/shape/path'
|
24
|
+
require 'glimmer/swt/custom/shape/path_segment'
|
25
|
+
require 'glimmer/swt/swt_proxy'
|
26
|
+
require 'glimmer/swt/display_proxy'
|
27
|
+
require 'glimmer/swt/color_proxy'
|
28
|
+
require 'glimmer/swt/font_proxy'
|
29
|
+
require 'glimmer/swt/transform_proxy'
|
30
|
+
|
31
|
+
module Glimmer
|
32
|
+
module SWT
|
33
|
+
module Custom
|
34
|
+
# Represents a shape (graphics) to be drawn on a control/widget/canvas/display
|
35
|
+
# That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
|
36
|
+
class Shape
|
37
|
+
class Cubic < Path
|
38
|
+
def parameter_names
|
39
|
+
[:point_array]
|
40
|
+
end
|
41
|
+
|
42
|
+
def geometry
|
43
|
+
the_point_array = point_array
|
44
|
+
if the_point_array != @geometry_point_array
|
45
|
+
@geometry_point_array = the_point_array
|
46
|
+
@geometry = Java::JavaAwtGeom::Path2D::Double.new
|
47
|
+
add_to_geometry(@geometry)
|
48
|
+
end
|
49
|
+
@geometry
|
50
|
+
end
|
51
|
+
|
52
|
+
def contain?(x, y)
|
53
|
+
include?(x, y, filled: true)
|
54
|
+
end
|
55
|
+
|
56
|
+
# checks if drawn or filled rectangle includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge)
|
57
|
+
def include?(x, y, filled: nil)
|
58
|
+
filled = filled? if filled.nil?
|
59
|
+
makeshift_gc = org.eclipse.swt.graphics.GC.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
|
60
|
+
swt_path = org.eclipse.swt.graphics.Path.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
|
61
|
+
the_path_segment_args = path_segment_args.dup
|
62
|
+
if previous_point_connected?
|
63
|
+
the_previous_path_segment = previous_path_segment
|
64
|
+
swt_path.moveTo(the_previous_path_segment.x, the_previous_path_segment.y)
|
65
|
+
else
|
66
|
+
swt_path.moveTo(the_path_segment_args.shift, the_path_segment_args.shift)
|
67
|
+
end
|
68
|
+
swt_path.curveTo(*the_path_segment_args)
|
69
|
+
swt_path.contains(x.to_f, y.to_f, makeshift_gc, !filled)
|
70
|
+
ensure
|
71
|
+
swt_path.dispose
|
72
|
+
end
|
73
|
+
|
74
|
+
def move_by(x_delta, y_delta)
|
75
|
+
the_point_array = @args.compact
|
76
|
+
the_point_array = the_point_array.first if the_point_array.first.is_a?(Array)
|
77
|
+
self.point_array = the_point_array.each_with_index.map {|coordinate, i| i.even? ? coordinate + x_delta : coordinate + y_delta}
|
78
|
+
end
|
79
|
+
|
80
|
+
def path_segment_method_name
|
81
|
+
'cubicTo'
|
82
|
+
end
|
83
|
+
|
84
|
+
def path_segment_args
|
85
|
+
# TODO make args auto-infer control points if previous_point_connected is true or if there is only a point_array with 1 point
|
86
|
+
@args.to_a
|
87
|
+
end
|
88
|
+
|
89
|
+
def default_path_segment_arg_count
|
90
|
+
8
|
91
|
+
end
|
92
|
+
|
93
|
+
def default_connected_path_segment_arg_count
|
94
|
+
6
|
95
|
+
end
|
96
|
+
|
97
|
+
def path_segment_geometry_method_name
|
98
|
+
'curveTo'
|
99
|
+
end
|
100
|
+
|
101
|
+
def previous_point_connected?
|
102
|
+
@args.compact.count == 6 && !first_path_segment?
|
103
|
+
end
|
104
|
+
|
105
|
+
def eql?(other)
|
106
|
+
other.is_a?(Cubic) && point_array == (other && other.respond_to?(:point_array) && other.point_array)
|
107
|
+
end
|
108
|
+
alias == eql?
|
109
|
+
|
110
|
+
def hash
|
111
|
+
point_array.hash
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -80,17 +80,17 @@ module Glimmer
|
|
80
80
|
|
81
81
|
def default_x?
|
82
82
|
super ||
|
83
|
-
current_parameter_name?(
|
83
|
+
current_parameter_name?(:dest_x) && (dest_x.nil? || dest_x.to_s == 'default')
|
84
84
|
end
|
85
85
|
|
86
86
|
def default_y?
|
87
87
|
super ||
|
88
|
-
current_parameter_name?(
|
88
|
+
current_parameter_name?(:dest_y) && (dest_y.nil? || dest_y.to_s == 'default')
|
89
89
|
end
|
90
90
|
|
91
91
|
def move_by(x_delta, y_delta)
|
92
92
|
if default_x?
|
93
|
-
self.
|
93
|
+
self.default_x_delta += x_delta
|
94
94
|
elsif dest_x
|
95
95
|
self.dest_x += x_delta
|
96
96
|
else
|
@@ -98,7 +98,7 @@ module Glimmer
|
|
98
98
|
end
|
99
99
|
|
100
100
|
if default_y?
|
101
|
-
self.
|
101
|
+
self.default_y_delta += y_delta
|
102
102
|
elsif dest_y
|
103
103
|
self.dest_y += y_delta
|
104
104
|
else
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# Copyright (c) 2007-2021 Andy Maleh
|
2
|
+
# Copyright (c) 2007-2021 Andy Maleh
|
2
3
|
#
|
3
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
5
|
# a copy of this software and associated documentation files (the
|
@@ -20,6 +21,7 @@
|
|
20
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
22
|
|
22
23
|
require 'glimmer/swt/custom/shape'
|
24
|
+
require 'glimmer/swt/custom/shape/path_segment'
|
23
25
|
require 'glimmer/swt/swt_proxy'
|
24
26
|
require 'glimmer/swt/display_proxy'
|
25
27
|
require 'glimmer/swt/color_proxy'
|
@@ -33,6 +35,8 @@ module Glimmer
|
|
33
35
|
# That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
|
34
36
|
class Shape
|
35
37
|
class Line < Shape
|
38
|
+
include PathSegment
|
39
|
+
|
36
40
|
class << self
|
37
41
|
def include?(x1, y1, x2, y2, x, y)
|
38
42
|
distance1 = Math.sqrt((x - x1)**2 + (y - y1)**2)
|
@@ -50,14 +54,40 @@ module Glimmer
|
|
50
54
|
parameter_names
|
51
55
|
end
|
52
56
|
|
53
|
-
|
57
|
+
def bounds
|
58
|
+
shape_bounds = geometry.getBounds2D
|
59
|
+
org.eclipse.swt.graphics.Rectangle.new(shape_bounds.x, shape_bounds.y, shape_bounds.width, shape_bounds.height)
|
60
|
+
end
|
61
|
+
|
62
|
+
def size
|
63
|
+
shape_bounds = geometry.getBounds2D
|
64
|
+
org.eclipse.swt.graphics.Point.new(shape_bounds.width, shape_bounds.height)
|
65
|
+
end
|
66
|
+
|
67
|
+
def geometry
|
68
|
+
java.awt.geom.Line2D::Double.new(absolute_x1, absolute_y1, absolute_x2, absolute_y2)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Logical x coordinate relative to parent
|
54
72
|
def x
|
55
|
-
|
73
|
+
x_value = bounds.x
|
74
|
+
x_value -= parent.absolute_x if parent.is_a?(Shape)
|
75
|
+
x_value
|
56
76
|
end
|
57
77
|
|
58
|
-
# Logical y coordinate
|
78
|
+
# Logical y coordinate relative to parent
|
59
79
|
def y
|
60
|
-
|
80
|
+
y_value = bounds.y
|
81
|
+
y_value -= parent.absolute_y if parent.is_a?(Shape)
|
82
|
+
y_value
|
83
|
+
end
|
84
|
+
|
85
|
+
def width
|
86
|
+
size.x
|
87
|
+
end
|
88
|
+
|
89
|
+
def height
|
90
|
+
size.y
|
61
91
|
end
|
62
92
|
|
63
93
|
def absolute_x1
|
@@ -78,7 +108,7 @@ module Glimmer
|
|
78
108
|
|
79
109
|
def absolute_x2
|
80
110
|
if parent.is_a?(Shape)
|
81
|
-
parent.absolute_x + x2
|
111
|
+
parent.absolute_x + x2.to_f
|
82
112
|
else
|
83
113
|
x2
|
84
114
|
end
|
@@ -86,7 +116,7 @@ module Glimmer
|
|
86
116
|
|
87
117
|
def absolute_y2
|
88
118
|
if parent.is_a?(Shape)
|
89
|
-
parent.absolute_y +
|
119
|
+
parent.absolute_y + y2.to_f
|
90
120
|
else
|
91
121
|
y2
|
92
122
|
end
|
@@ -104,6 +134,50 @@ module Glimmer
|
|
104
134
|
self.x2 += x_delta
|
105
135
|
self.y2 += y_delta
|
106
136
|
end
|
137
|
+
|
138
|
+
def irregular?
|
139
|
+
true
|
140
|
+
end
|
141
|
+
|
142
|
+
def path_segment_method_name
|
143
|
+
'lineTo'
|
144
|
+
end
|
145
|
+
|
146
|
+
def path_segment_args
|
147
|
+
# TODO make args auto-infer first point if previous_point_connected is true or if there is only x1,y1 or x2,y2 (but not both), or if there is an x, y, or if there is a point_array with 1 point
|
148
|
+
@args
|
149
|
+
end
|
150
|
+
|
151
|
+
def default_path_segment_arg_count
|
152
|
+
4
|
153
|
+
end
|
154
|
+
|
155
|
+
def default_connected_path_segment_arg_count
|
156
|
+
2
|
157
|
+
end
|
158
|
+
|
159
|
+
def path_segment_geometry_args
|
160
|
+
# TODO make args auto-infer first point if previous_point_connected is true or if there is only x1,y1 or x2,y2 (but not both), or if there is an x, y, or if there is a point_array with 1 point
|
161
|
+
@args
|
162
|
+
end
|
163
|
+
|
164
|
+
def previous_point_connected?
|
165
|
+
@args.compact.count == 2 && !first_path_segment?
|
166
|
+
end
|
167
|
+
|
168
|
+
def eql?(other)
|
169
|
+
other.is_a?(Line) &&
|
170
|
+
x1 == (other && other.respond_to?(:x1) && other.x1) &&
|
171
|
+
y1 == (other && other.respond_to?(:y1) && other.y1) &&
|
172
|
+
x2 == (other && other.respond_to?(:x2) && other.x2) &&
|
173
|
+
y2 == (other && other.respond_to?(:y2) && other.y2)
|
174
|
+
end
|
175
|
+
alias == eql?
|
176
|
+
|
177
|
+
def hash
|
178
|
+
[x1, y1, x2, y2].hash
|
179
|
+
end
|
180
|
+
|
107
181
|
end
|
108
182
|
end
|
109
183
|
end
|
@@ -39,7 +39,7 @@ module Glimmer
|
|
39
39
|
|
40
40
|
# checks if shape contains the point denoted by x and y
|
41
41
|
def contain?(x, y)
|
42
|
-
shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x, self.absolute_y,
|
42
|
+
shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x, self.absolute_y, calculated_width, calculated_height)
|
43
43
|
shape_geometry.contains(x, y)
|
44
44
|
end
|
45
45
|
|
@@ -49,8 +49,8 @@ module Glimmer
|
|
49
49
|
contain?(x, y)
|
50
50
|
else
|
51
51
|
# give it some fuzz to allow a larger region around the drawn oval to accept including a point (helps with mouse clickability on a shape)
|
52
|
-
outer_shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x - 3, self.absolute_y - 3,
|
53
|
-
inner_shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x + 3, self.absolute_y + 3,
|
52
|
+
outer_shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x - 3, self.absolute_y - 3, calculated_width + 6, calculated_height + 6)
|
53
|
+
inner_shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x + 3, self.absolute_y + 3, calculated_width - 6, calculated_height - 6)
|
54
54
|
outer_shape_geometry.contains(x, y) && !inner_shape_geometry.contains(x, y)
|
55
55
|
end
|
56
56
|
end
|
@@ -0,0 +1,227 @@
|
|
1
|
+
# Copyright (c) 2007-2021 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer/swt/custom/shape'
|
23
|
+
require 'glimmer/swt/custom/shape/path_segment'
|
24
|
+
require 'glimmer/swt/swt_proxy'
|
25
|
+
require 'glimmer/swt/display_proxy'
|
26
|
+
require 'glimmer/swt/color_proxy'
|
27
|
+
require 'glimmer/swt/font_proxy'
|
28
|
+
require 'glimmer/swt/display_proxy'
|
29
|
+
|
30
|
+
module Glimmer
|
31
|
+
module SWT
|
32
|
+
module Custom
|
33
|
+
class Shape
|
34
|
+
# Represents a path to be drawn on a control/widget/canvas/display
|
35
|
+
# That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
|
36
|
+
# swt_path is not guaranteed to have any object in it till after rendering
|
37
|
+
class Path < Shape
|
38
|
+
include PathSegment # a path may behave as a path segment in another path
|
39
|
+
|
40
|
+
attr_reader :swt_path, :path_segments
|
41
|
+
attr_accessor :calculated_path_args
|
42
|
+
|
43
|
+
def initialize(parent, keyword, *args, &property_block)
|
44
|
+
super
|
45
|
+
@path_segments = []
|
46
|
+
@uncalculated_path_segments = []
|
47
|
+
end
|
48
|
+
|
49
|
+
def parameter_names
|
50
|
+
[:swt_path]
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_shape(shape)
|
54
|
+
if shape.is_a?(PathSegment)
|
55
|
+
@path_segments << shape
|
56
|
+
@uncalculated_path_segments << shape
|
57
|
+
else
|
58
|
+
super
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def contain?(x, y)
|
63
|
+
makeshift_gc = org.eclipse.swt.graphics.GC.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
|
64
|
+
@swt_path.contains(x.to_f, y.to_f, makeshift_gc, false)
|
65
|
+
end
|
66
|
+
|
67
|
+
def contain?(x, y)
|
68
|
+
include?(x, y, filled: true)
|
69
|
+
end
|
70
|
+
|
71
|
+
# checks if drawn or filled rectangle includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge)
|
72
|
+
def include?(x, y, filled: nil)
|
73
|
+
filled = filled? if filled.nil?
|
74
|
+
makeshift_gc = org.eclipse.swt.graphics.GC.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
|
75
|
+
@swt_path.contains(x.to_f, y.to_f, makeshift_gc, !filled)
|
76
|
+
end
|
77
|
+
|
78
|
+
def irregular?
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
def post_dispose_content(path_segment)
|
83
|
+
@path_segments.delete(path_segment)
|
84
|
+
@uncalculated_path_segments = @path_segments.dup
|
85
|
+
@swt_path&.dispose
|
86
|
+
@swt_path = nil
|
87
|
+
@args = []
|
88
|
+
calculated_args_changed!(children: false)
|
89
|
+
end
|
90
|
+
|
91
|
+
def clear
|
92
|
+
@path_segments.each { |path_segments| path_segments.class == Path && path_segments.dispose }
|
93
|
+
@path_segments.clear
|
94
|
+
@uncalculated_path_segments = @path_segments.dup
|
95
|
+
@swt_path&.dispose
|
96
|
+
@swt_path = nil
|
97
|
+
@args = []
|
98
|
+
calculated_args_changed!(children: false)
|
99
|
+
end
|
100
|
+
|
101
|
+
def dispose
|
102
|
+
clear if self.class == Path
|
103
|
+
super if parent.is_a?(Drawable)
|
104
|
+
end
|
105
|
+
|
106
|
+
def calculated_args_changed!(children: true)
|
107
|
+
super
|
108
|
+
end
|
109
|
+
|
110
|
+
def calculated_args
|
111
|
+
new_swt_path = @swt_path.nil? || !@calculated_paint_args || !@calculated_path_args
|
112
|
+
if new_swt_path
|
113
|
+
@swt_path&.dispose
|
114
|
+
@swt_path = org.eclipse.swt.graphics.Path.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
|
115
|
+
@uncalculated_path_segments = @path_segments.dup
|
116
|
+
end
|
117
|
+
# TODO recreate @swt_path only if one of the children get disposed (must notify parent on dispose)
|
118
|
+
@args = [@swt_path]
|
119
|
+
@uncalculated_path_segments.each do |path_segment|
|
120
|
+
path_segment.add_to_swt_path(@swt_path)
|
121
|
+
@uncalculated_path_segments.delete(path_segment)
|
122
|
+
end
|
123
|
+
@calculated_path_args = true
|
124
|
+
if new_swt_path
|
125
|
+
@path_calculated_args = super
|
126
|
+
else
|
127
|
+
@path_calculated_args
|
128
|
+
end
|
129
|
+
rescue => e
|
130
|
+
Glimmer::Config.logger.error {e.full_message}
|
131
|
+
@args
|
132
|
+
end
|
133
|
+
|
134
|
+
def move_by(x_delta, y_delta)
|
135
|
+
@path_segments.each {|path_segment| path_segment.move_by(x_delta, y_delta)}
|
136
|
+
end
|
137
|
+
|
138
|
+
def bounds
|
139
|
+
if @path_segments != @bounds_path_segments
|
140
|
+
@bounds_path_segments = @path_segments
|
141
|
+
shape_bounds = geometry.getBounds2D
|
142
|
+
@bounds = org.eclipse.swt.graphics.Rectangle.new(shape_bounds.x, shape_bounds.y, shape_bounds.width, shape_bounds.height)
|
143
|
+
end
|
144
|
+
@bounds
|
145
|
+
end
|
146
|
+
|
147
|
+
def size
|
148
|
+
if @path_segments != @size_path_segments
|
149
|
+
@size_path_segments = @path_segments
|
150
|
+
shape_bounds = geometry.getBounds2D
|
151
|
+
@size = org.eclipse.swt.graphics.Point.new(shape_bounds.width, shape_bounds.height)
|
152
|
+
end
|
153
|
+
@size
|
154
|
+
end
|
155
|
+
|
156
|
+
# Logical x coordinate relative to parent
|
157
|
+
def x
|
158
|
+
x_value = bounds.x
|
159
|
+
x_value -= parent.absolute_x if parent.is_a?(Shape)
|
160
|
+
x_value
|
161
|
+
end
|
162
|
+
|
163
|
+
# Logical y coordinate relative to parent
|
164
|
+
def y
|
165
|
+
y_value = bounds.y
|
166
|
+
y_value -= parent.absolute_y if parent.is_a?(Shape)
|
167
|
+
y_value
|
168
|
+
end
|
169
|
+
|
170
|
+
def width
|
171
|
+
size.x
|
172
|
+
end
|
173
|
+
|
174
|
+
def height
|
175
|
+
size.y
|
176
|
+
end
|
177
|
+
|
178
|
+
def geometry
|
179
|
+
if @path_segments != @geometry_path_segments
|
180
|
+
@geometry_path_segments = @path_segments
|
181
|
+
@geometry = Java::JavaAwtGeom::Path2D::Double.new
|
182
|
+
@path_segments.each do |path_segment|
|
183
|
+
path_segment.add_to_geometry(@geometry)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
@geometry
|
187
|
+
end
|
188
|
+
|
189
|
+
def path_segment_method_name
|
190
|
+
'addPath'
|
191
|
+
end
|
192
|
+
|
193
|
+
def path_segment_args
|
194
|
+
@args
|
195
|
+
end
|
196
|
+
|
197
|
+
def path_segment_geometry_method_name
|
198
|
+
if self.class == Path
|
199
|
+
'append'
|
200
|
+
else
|
201
|
+
super
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def path_segment_geometry_args
|
206
|
+
if self.class == Path
|
207
|
+
# TODO consider supporting connected true instead of false (2nd arg)
|
208
|
+
[geometry, false]
|
209
|
+
else
|
210
|
+
super
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def eql?(other)
|
215
|
+
(other.class == Path) && geometry.equals(other && other.respond_to?(:geometry) && other.geometry)
|
216
|
+
end
|
217
|
+
alias == eql?
|
218
|
+
|
219
|
+
def hash
|
220
|
+
geometry.hashCode
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|