glimmer-dsl-swt 4.18.4.9 → 4.18.5.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 +73 -0
- data/README.md +14 -5
- data/VERSION +1 -1
- data/bin/glimmer +3 -3
- data/docs/reference/GLIMMER_CONFIGURATION.md +7 -3
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +464 -149
- data/docs/reference/GLIMMER_SAMPLES.md +91 -4
- data/glimmer-dsl-swt.gemspec +24 -13
- data/lib/ext/glimmer/config.rb +3 -7
- data/lib/glimmer/data_binding/list_selection_binding.rb +13 -7
- data/lib/glimmer/data_binding/table_items_binding.rb +22 -17
- data/lib/glimmer/data_binding/tree_items_binding.rb +19 -15
- data/lib/glimmer/data_binding/widget_binding.rb +13 -15
- data/lib/glimmer/dsl/swt/{file_dialog_expression.rb → auto_exec_expression.rb} +6 -18
- data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +9 -6
- data/lib/glimmer/dsl/swt/color_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +16 -14
- data/lib/glimmer/dsl/swt/custom_widget_expression.rb +4 -1
- data/lib/glimmer/dsl/swt/data_binding_expression.rb +2 -2
- data/lib/glimmer/dsl/swt/dialog_expression.rb +18 -9
- data/lib/glimmer/dsl/swt/dsl.rb +1 -0
- data/lib/glimmer/dsl/swt/exec_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/font_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/image_expression.rb +16 -2
- data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +11 -8
- data/lib/glimmer/dsl/swt/pixel_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +8 -5
- data/lib/glimmer/dsl/swt/shape_expression.rb +2 -2
- data/lib/glimmer/dsl/swt/shell_expression.rb +5 -2
- data/lib/glimmer/dsl/swt/widget_expression.rb +8 -4
- data/lib/glimmer/launcher.rb +3 -0
- data/lib/glimmer/rake_task/scaffold.rb +3 -0
- data/lib/glimmer/swt/color_proxy.rb +1 -1
- data/lib/glimmer/swt/custom/code_text.rb +33 -11
- data/lib/glimmer/swt/custom/drawable.rb +55 -0
- data/lib/glimmer/swt/custom/shape.rb +187 -43
- data/lib/glimmer/swt/custom/shape/arc.rb +60 -0
- data/lib/glimmer/{dsl/swt/directory_dialog_expression.rb → swt/custom/shape/focus.rb} +15 -20
- data/lib/glimmer/swt/custom/shape/image.rb +99 -0
- data/lib/glimmer/swt/custom/shape/line.rb +65 -0
- data/lib/glimmer/swt/custom/shape/oval.rb +61 -0
- data/lib/glimmer/swt/custom/shape/point.rb +54 -0
- data/lib/glimmer/swt/custom/shape/polygon.rb +73 -0
- data/lib/glimmer/swt/custom/shape/polyline.rb +74 -0
- data/lib/glimmer/swt/custom/shape/rectangle.rb +101 -0
- data/lib/glimmer/swt/custom/shape/text.rb +85 -0
- data/lib/glimmer/swt/date_time_proxy.rb +9 -3
- data/lib/glimmer/swt/dialog_proxy.rb +92 -0
- data/lib/glimmer/swt/display_proxy.rb +62 -2
- data/lib/glimmer/swt/expand_item_proxy.rb +18 -12
- data/lib/glimmer/swt/font_proxy.rb +13 -7
- data/lib/glimmer/swt/image_proxy.rb +15 -4
- data/lib/glimmer/swt/layout_data_proxy.rb +21 -15
- data/lib/glimmer/swt/layout_proxy.rb +19 -15
- data/lib/glimmer/swt/menu_proxy.rb +2 -2
- data/lib/glimmer/swt/message_box_proxy.rb +21 -7
- data/lib/glimmer/swt/properties.rb +3 -0
- data/lib/glimmer/swt/proxy_properties.rb +145 -0
- data/lib/glimmer/swt/scrolled_composite_proxy.rb +6 -2
- data/lib/glimmer/swt/shell_proxy.rb +96 -80
- data/lib/glimmer/swt/swt_proxy.rb +17 -0
- data/lib/glimmer/swt/tab_item_proxy.rb +5 -3
- data/lib/glimmer/swt/table_proxy.rb +32 -11
- data/lib/glimmer/swt/transform_proxy.rb +39 -35
- data/lib/glimmer/swt/tree_proxy.rb +11 -16
- data/lib/glimmer/swt/widget_listener_proxy.rb +6 -2
- data/lib/glimmer/swt/widget_proxy.rb +192 -141
- data/lib/glimmer/ui.rb +5 -0
- data/lib/glimmer/ui/custom_shell.rb +13 -7
- data/lib/glimmer/ui/custom_widget.rb +4 -5
- data/samples/elaborate/contact_manager.rb +7 -7
- data/samples/elaborate/login.rb +25 -21
- data/samples/elaborate/mandelbrot_fractal.rb +87 -31
- data/samples/elaborate/meta_sample.rb +1 -1
- data/samples/elaborate/tetris.rb +1 -0
- data/samples/elaborate/tic_tac_toe.rb +16 -14
- data/samples/elaborate/tic_tac_toe/board.rb +5 -5
- data/samples/elaborate/tic_tac_toe/cell.rb +5 -5
- data/samples/hello/hello_button.rb +7 -7
- data/samples/hello/hello_canvas.rb +143 -41
- data/samples/hello/hello_checkbox.rb +16 -14
- data/samples/hello/hello_checkbox_group.rb +11 -9
- data/samples/hello/hello_color_dialog.rb +66 -0
- data/samples/hello/hello_combo.rb +14 -12
- data/samples/hello/hello_computed.rb +7 -7
- data/samples/hello/hello_cursor.rb +2 -1
- data/samples/hello/hello_custom_shell.rb +17 -21
- data/samples/hello/hello_custom_widget.rb +4 -6
- data/samples/hello/hello_date_time.rb +14 -12
- data/samples/hello/hello_directory_dialog.rb +7 -7
- data/samples/hello/hello_expand_bar.rb +8 -8
- data/samples/hello/hello_file_dialog.rb +7 -7
- data/samples/hello/hello_font_dialog.rb +82 -0
- data/samples/hello/hello_group.rb +18 -16
- data/samples/hello/hello_list_multi_selection.rb +13 -11
- data/samples/hello/hello_list_single_selection.rb +13 -11
- data/samples/hello/hello_progress_bar.rb +125 -0
- data/samples/hello/hello_radio.rb +18 -16
- data/samples/hello/hello_radio_group.rb +14 -12
- data/samples/hello/hello_spinner.rb +7 -7
- data/samples/hello/hello_tab.rb +5 -5
- data/samples/hello/hello_table.rb +10 -5
- data/samples/hello/hello_tree.rb +485 -0
- metadata +22 -22
- data/lib/glimmer/swt/directory_dialog_proxy.rb +0 -65
- data/lib/glimmer/swt/file_dialog_proxy.rb +0 -66
@@ -0,0 +1,60 @@
|
|
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/swt_proxy'
|
24
|
+
require 'glimmer/swt/display_proxy'
|
25
|
+
require 'glimmer/swt/color_proxy'
|
26
|
+
require 'glimmer/swt/font_proxy'
|
27
|
+
require 'glimmer/swt/transform_proxy'
|
28
|
+
|
29
|
+
module Glimmer
|
30
|
+
module SWT
|
31
|
+
module Custom
|
32
|
+
# Represents a shape (graphics) to be drawn on a control/widget/canvas/display
|
33
|
+
# That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
|
34
|
+
class Shape
|
35
|
+
class Arc < Shape
|
36
|
+
def parameter_names
|
37
|
+
[:x, :y, :width, :height, :start_angle, :arc_angle]
|
38
|
+
end
|
39
|
+
|
40
|
+
# checks if shape contains the point denoted by x and y
|
41
|
+
def contain?(x, y)
|
42
|
+
shape_geometry = java.awt.geom.Arc2D::Double.new(self.x, self.y, width, height, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
|
43
|
+
shape_geometry.contains(x, y)
|
44
|
+
end
|
45
|
+
|
46
|
+
def include?(x, y)
|
47
|
+
if filled?
|
48
|
+
contain?(x, y)
|
49
|
+
else
|
50
|
+
# 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.x, self.y, width + 3, height + 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
|
52
|
+
inner_shape_geometry = java.awt.geom.Arc2D::Double.new(self.x, self.y, width - 3, height - 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
|
53
|
+
outer_shape_geometry.contains(x, y) && !inner_shape_geometry.contains(x, y)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -19,28 +19,23 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
|
-
require 'glimmer/
|
23
|
-
require 'glimmer/
|
24
|
-
require 'glimmer/
|
25
|
-
require 'glimmer/swt/
|
22
|
+
require 'glimmer/swt/custom/shape'
|
23
|
+
require 'glimmer/swt/swt_proxy'
|
24
|
+
require 'glimmer/swt/display_proxy'
|
25
|
+
require 'glimmer/swt/color_proxy'
|
26
|
+
require 'glimmer/swt/font_proxy'
|
27
|
+
require 'glimmer/swt/transform_proxy'
|
26
28
|
|
27
29
|
module Glimmer
|
28
|
-
module
|
29
|
-
module
|
30
|
-
class
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
keyword == 'directory_dialog' and
|
38
|
-
(parent.nil? or parent.is_a?(Shell) or parent.is_a?(Glimmer::SWT::ShellProxy))
|
39
|
-
end
|
40
|
-
|
41
|
-
def interpret(parent, keyword, *args, &block)
|
42
|
-
args = [parent] + args unless parent.nil?
|
43
|
-
Glimmer::SWT::DirectoryDialogProxy.send(:new, *args)
|
30
|
+
module SWT
|
31
|
+
module Custom
|
32
|
+
class Shape
|
33
|
+
# Represents a focus shape to be drawn on a control/widget/canvas/display
|
34
|
+
# Helps highlight focus on another selected shape
|
35
|
+
class Focus < Shape
|
36
|
+
def parameter_names
|
37
|
+
[:x, :y, :width, :height]
|
38
|
+
end
|
44
39
|
end
|
45
40
|
end
|
46
41
|
end
|
@@ -0,0 +1,99 @@
|
|
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/swt_proxy'
|
24
|
+
require 'glimmer/swt/display_proxy'
|
25
|
+
require 'glimmer/swt/color_proxy'
|
26
|
+
require 'glimmer/swt/font_proxy'
|
27
|
+
require 'glimmer/swt/transform_proxy'
|
28
|
+
|
29
|
+
module Glimmer
|
30
|
+
module SWT
|
31
|
+
module Custom
|
32
|
+
# Represents a shape (graphics) to be drawn on a control/widget/canvas/display
|
33
|
+
# That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
|
34
|
+
class Shape
|
35
|
+
class Image < Shape
|
36
|
+
def parameter_names
|
37
|
+
if @args.to_a.size > 3
|
38
|
+
image_part_parameter_names
|
39
|
+
else
|
40
|
+
image_whole_parameter_names
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def possible_parameter_names
|
45
|
+
(image_part_parameter_names + image_whole_parameter_names).uniq
|
46
|
+
end
|
47
|
+
|
48
|
+
def image_part_parameter_names
|
49
|
+
[:image, :src_x, :src_y, :src_width, :src_height, :dest_x, :dest_y, :dest_width, :dest_height]
|
50
|
+
end
|
51
|
+
|
52
|
+
def image_whole_parameter_names
|
53
|
+
[:image, :x, :y]
|
54
|
+
end
|
55
|
+
|
56
|
+
def parameter_index(attribute_name)
|
57
|
+
####TODO refactor and improve this method through meta-programming (and share across other shapes)
|
58
|
+
if image_part_parameter_names.map(&:to_s).include?(attribute_name.to_s)
|
59
|
+
image_part_parameter_names.map(&:to_s).index(attribute_name.to_s)
|
60
|
+
elsif image_whole_parameter_names.map(&:to_s).include?(attribute_name.to_s)
|
61
|
+
image_whole_parameter_names.map(&:to_s).index(attribute_name.to_s)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def x
|
66
|
+
dest_x || get_attribute('x')
|
67
|
+
end
|
68
|
+
|
69
|
+
def y
|
70
|
+
dest_y || get_attribute('y')
|
71
|
+
end
|
72
|
+
|
73
|
+
def width
|
74
|
+
dest_width || image.bounds.width
|
75
|
+
end
|
76
|
+
|
77
|
+
def height
|
78
|
+
dest_height || image.bounds.height
|
79
|
+
end
|
80
|
+
|
81
|
+
def include?(x, y)
|
82
|
+
x.between?(self.x, self.x + width) && y.between?(self.y, self.y + height)
|
83
|
+
end
|
84
|
+
alias contain? include?
|
85
|
+
|
86
|
+
def move_by(x_delta, y_delta)
|
87
|
+
if dest_x
|
88
|
+
self.dest_x += x_delta
|
89
|
+
self.dest_y += y_delta
|
90
|
+
else
|
91
|
+
self.x += x_delta
|
92
|
+
self.y += y_delta
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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/swt_proxy'
|
24
|
+
require 'glimmer/swt/display_proxy'
|
25
|
+
require 'glimmer/swt/color_proxy'
|
26
|
+
require 'glimmer/swt/font_proxy'
|
27
|
+
require 'glimmer/swt/transform_proxy'
|
28
|
+
|
29
|
+
module Glimmer
|
30
|
+
module SWT
|
31
|
+
module Custom
|
32
|
+
# Represents a shape (graphics) to be drawn on a control/widget/canvas/display
|
33
|
+
# That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
|
34
|
+
class Shape
|
35
|
+
class Line < Shape
|
36
|
+
class << self
|
37
|
+
def include?(x1, y1, x2, y2, x, y)
|
38
|
+
distance1 = Math.sqrt((x - x1)**2 + (y - y1)**2)
|
39
|
+
distance2 = Math.sqrt((x2 - x)**2 + (y2 - y)**2)
|
40
|
+
distance = Math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
|
41
|
+
(distance1 + distance2).to_i == distance.to_i
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def parameter_names
|
46
|
+
[:x1, :y1, :x2, :y2]
|
47
|
+
end
|
48
|
+
|
49
|
+
def include?(x, y)
|
50
|
+
# TODO must account for line width
|
51
|
+
Line.include?(x1, y1, x2, y2, x, y)
|
52
|
+
end
|
53
|
+
alias contain? include?
|
54
|
+
|
55
|
+
def move_by(x_delta, y_delta)
|
56
|
+
self.x1 += x_delta
|
57
|
+
self.y1 += y_delta
|
58
|
+
self.x2 += x_delta
|
59
|
+
self.y2 += y_delta
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,61 @@
|
|
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/swt_proxy'
|
24
|
+
require 'glimmer/swt/display_proxy'
|
25
|
+
require 'glimmer/swt/color_proxy'
|
26
|
+
require 'glimmer/swt/font_proxy'
|
27
|
+
require 'glimmer/swt/transform_proxy'
|
28
|
+
|
29
|
+
module Glimmer
|
30
|
+
module SWT
|
31
|
+
module Custom
|
32
|
+
# Represents a shape (graphics) to be drawn on a control/widget/canvas/display
|
33
|
+
# That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
|
34
|
+
class Shape
|
35
|
+
class Oval < Shape
|
36
|
+
def parameter_names
|
37
|
+
[:x, :y, :width, :height]
|
38
|
+
end
|
39
|
+
|
40
|
+
# checks if shape contains the point denoted by x and y
|
41
|
+
def contain?(x, y)
|
42
|
+
shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.x, self.y, width, height)
|
43
|
+
shape_geometry.contains(x, y)
|
44
|
+
end
|
45
|
+
|
46
|
+
# checks if drawn or filled oval includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge)
|
47
|
+
def include?(x, y)
|
48
|
+
if filled?
|
49
|
+
contain?(x, y)
|
50
|
+
else
|
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.x - 3, self.y - 3, width + 6, height + 6)
|
53
|
+
inner_shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.x + 3, self.y + 3, width - 6, height - 6)
|
54
|
+
outer_shape_geometry.contains(x, y) && !inner_shape_geometry.contains(x, y)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,54 @@
|
|
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/swt_proxy'
|
24
|
+
require 'glimmer/swt/display_proxy'
|
25
|
+
require 'glimmer/swt/color_proxy'
|
26
|
+
require 'glimmer/swt/font_proxy'
|
27
|
+
require 'glimmer/swt/transform_proxy'
|
28
|
+
|
29
|
+
module Glimmer
|
30
|
+
module SWT
|
31
|
+
module Custom
|
32
|
+
# Represents a shape (graphics) to be drawn on a control/widget/canvas/display
|
33
|
+
# That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
|
34
|
+
class Shape
|
35
|
+
class Point < Shape
|
36
|
+
def parameter_names
|
37
|
+
[:x, :y]
|
38
|
+
end
|
39
|
+
|
40
|
+
def include?(x, y)
|
41
|
+
# give it some fuzz (helps makes mouse clicking easier)
|
42
|
+
x.to_i.between?(self.x.to_i - 2, self.x.to_i + 2) && y.to_i.between?(self.y.to_i - 2, self.y.to_i + 2)
|
43
|
+
end
|
44
|
+
alias contain? include?
|
45
|
+
|
46
|
+
def move_by(x_delta, y_delta)
|
47
|
+
self.x += x_delta
|
48
|
+
self.y += y_delta
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,73 @@
|
|
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/swt_proxy'
|
24
|
+
require 'glimmer/swt/display_proxy'
|
25
|
+
require 'glimmer/swt/color_proxy'
|
26
|
+
require 'glimmer/swt/font_proxy'
|
27
|
+
require 'glimmer/swt/transform_proxy'
|
28
|
+
|
29
|
+
module Glimmer
|
30
|
+
module SWT
|
31
|
+
module Custom
|
32
|
+
# Represents a shape (graphics) to be drawn on a control/widget/canvas/display
|
33
|
+
# That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
|
34
|
+
class Shape
|
35
|
+
class Polygon < Shape
|
36
|
+
def parameter_names
|
37
|
+
[:point_array]
|
38
|
+
end
|
39
|
+
|
40
|
+
def point_count
|
41
|
+
point_array.count / 2
|
42
|
+
end
|
43
|
+
|
44
|
+
def [](index)
|
45
|
+
index = 0 if index == point_count
|
46
|
+
org.eclipse.swt.graphics.Point.new(point_array[index * 2], point_array[index * 2 + 1])
|
47
|
+
end
|
48
|
+
|
49
|
+
def x_array
|
50
|
+
point_array.each_with_index.select {|pair| pair.last.even?}.map(&:first)
|
51
|
+
end
|
52
|
+
|
53
|
+
def y_array
|
54
|
+
point_array.each_with_index.select {|pair| pair.last.odd?}.map(&:first)
|
55
|
+
end
|
56
|
+
|
57
|
+
def point_xy_array
|
58
|
+
x_array.zip(y_array)
|
59
|
+
end
|
60
|
+
|
61
|
+
def include?(x, y)
|
62
|
+
shape_geometry = java.awt.Polygon.new(x_array.to_java(:int), y_array.to_java(:int), point_count)
|
63
|
+
shape_geometry.contains(x, y)
|
64
|
+
end
|
65
|
+
|
66
|
+
def move_by(x_delta, y_delta)
|
67
|
+
self.point_array = point_array.each_with_index.map {|coordinate, i| i.even? ? coordinate + x_delta : coordinate + y_delta}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|