glimmer-dsl-swt 4.18.4.10 → 4.18.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +71 -0
  3. data/README.md +14 -5
  4. data/VERSION +1 -1
  5. data/bin/glimmer +3 -3
  6. data/docs/reference/GLIMMER_CONFIGURATION.md +7 -3
  7. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +451 -112
  8. data/docs/reference/GLIMMER_SAMPLES.md +76 -3
  9. data/glimmer-dsl-swt.gemspec +23 -13
  10. data/lib/ext/glimmer/config.rb +3 -7
  11. data/lib/glimmer/data_binding/list_selection_binding.rb +13 -7
  12. data/lib/glimmer/data_binding/table_items_binding.rb +22 -17
  13. data/lib/glimmer/data_binding/tree_items_binding.rb +19 -15
  14. data/lib/glimmer/data_binding/widget_binding.rb +12 -27
  15. data/lib/glimmer/dsl/swt/{file_dialog_expression.rb → auto_exec_expression.rb} +6 -18
  16. data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +9 -6
  17. data/lib/glimmer/dsl/swt/color_expression.rb +1 -1
  18. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +16 -14
  19. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +4 -1
  20. data/lib/glimmer/dsl/swt/data_binding_expression.rb +1 -2
  21. data/lib/glimmer/dsl/swt/dialog_expression.rb +18 -9
  22. data/lib/glimmer/dsl/swt/dsl.rb +1 -0
  23. data/lib/glimmer/dsl/swt/exec_expression.rb +1 -1
  24. data/lib/glimmer/dsl/swt/font_expression.rb +1 -1
  25. data/lib/glimmer/dsl/swt/image_expression.rb +16 -2
  26. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +11 -8
  27. data/lib/glimmer/dsl/swt/pixel_expression.rb +1 -1
  28. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +8 -5
  29. data/lib/glimmer/dsl/swt/shape_expression.rb +2 -2
  30. data/lib/glimmer/dsl/swt/shell_expression.rb +1 -1
  31. data/lib/glimmer/dsl/swt/widget_expression.rb +8 -4
  32. data/lib/glimmer/launcher.rb +3 -0
  33. data/lib/glimmer/rake_task/scaffold.rb +3 -0
  34. data/lib/glimmer/swt/color_proxy.rb +1 -1
  35. data/lib/glimmer/swt/custom/code_text.rb +33 -11
  36. data/lib/glimmer/swt/custom/drawable.rb +57 -1
  37. data/lib/glimmer/swt/custom/shape.rb +332 -48
  38. data/lib/glimmer/swt/custom/shape/arc.rb +60 -0
  39. data/lib/glimmer/{dsl/swt/directory_dialog_expression.rb → swt/custom/shape/focus.rb} +15 -20
  40. data/lib/glimmer/swt/custom/shape/image.rb +112 -0
  41. data/lib/glimmer/swt/custom/shape/line.rb +111 -0
  42. data/lib/glimmer/swt/custom/shape/oval.rb +61 -0
  43. data/lib/glimmer/swt/custom/shape/point.rb +49 -0
  44. data/lib/glimmer/swt/custom/shape/polygon.rb +114 -0
  45. data/lib/glimmer/swt/custom/shape/polyline.rb +115 -0
  46. data/lib/glimmer/swt/custom/shape/rectangle.rb +105 -0
  47. data/lib/glimmer/swt/custom/shape/text.rb +85 -0
  48. data/lib/glimmer/swt/date_time_proxy.rb +9 -3
  49. data/lib/glimmer/swt/dialog_proxy.rb +92 -0
  50. data/lib/glimmer/swt/display_proxy.rb +62 -2
  51. data/lib/glimmer/swt/expand_item_proxy.rb +18 -12
  52. data/lib/glimmer/swt/font_proxy.rb +13 -7
  53. data/lib/glimmer/swt/image_proxy.rb +15 -4
  54. data/lib/glimmer/swt/layout_data_proxy.rb +21 -15
  55. data/lib/glimmer/swt/layout_proxy.rb +19 -15
  56. data/lib/glimmer/swt/menu_proxy.rb +2 -2
  57. data/lib/glimmer/swt/message_box_proxy.rb +21 -7
  58. data/lib/glimmer/swt/properties.rb +3 -0
  59. data/lib/glimmer/swt/proxy_properties.rb +145 -0
  60. data/lib/glimmer/swt/scrolled_composite_proxy.rb +6 -2
  61. data/lib/glimmer/swt/shell_proxy.rb +94 -80
  62. data/lib/glimmer/swt/swt_proxy.rb +16 -0
  63. data/lib/glimmer/swt/tab_item_proxy.rb +5 -3
  64. data/lib/glimmer/swt/table_proxy.rb +32 -11
  65. data/lib/glimmer/swt/transform_proxy.rb +39 -35
  66. data/lib/glimmer/swt/tree_proxy.rb +11 -16
  67. data/lib/glimmer/swt/widget_listener_proxy.rb +6 -2
  68. data/lib/glimmer/swt/widget_proxy.rb +193 -138
  69. data/lib/glimmer/ui.rb +5 -0
  70. data/lib/glimmer/ui/custom_shell.rb +11 -5
  71. data/lib/glimmer/ui/custom_widget.rb +4 -5
  72. data/samples/elaborate/contact_manager.rb +9 -7
  73. data/samples/elaborate/login.rb +27 -21
  74. data/samples/elaborate/mandelbrot_fractal.rb +20 -25
  75. data/samples/elaborate/meta_sample.rb +2 -1
  76. data/samples/elaborate/tetris.rb +3 -1
  77. data/samples/elaborate/tic_tac_toe.rb +18 -14
  78. data/samples/elaborate/tic_tac_toe/board.rb +5 -5
  79. data/samples/elaborate/tic_tac_toe/cell.rb +5 -5
  80. data/samples/elaborate/user_profile.rb +10 -8
  81. data/samples/hello/hello_browser.rb +2 -0
  82. data/samples/hello/hello_button.rb +9 -7
  83. data/samples/hello/hello_canvas.rb +144 -40
  84. data/samples/hello/hello_canvas_animation.rb +2 -0
  85. data/samples/hello/hello_canvas_transform.rb +2 -0
  86. data/samples/hello/hello_checkbox.rb +18 -14
  87. data/samples/hello/hello_checkbox_group.rb +13 -9
  88. data/samples/hello/hello_code_text.rb +2 -0
  89. data/samples/hello/hello_color_dialog.rb +68 -0
  90. data/samples/hello/hello_combo.rb +16 -12
  91. data/samples/hello/hello_computed.rb +9 -7
  92. data/samples/hello/hello_cursor.rb +4 -1
  93. data/samples/hello/hello_custom_shell.rb +18 -21
  94. data/samples/hello/hello_custom_widget.rb +6 -6
  95. data/samples/hello/hello_date_time.rb +16 -12
  96. data/samples/hello/hello_dialog.rb +2 -0
  97. data/samples/hello/hello_directory_dialog.rb +9 -7
  98. data/samples/hello/hello_drag_and_drop.rb +5 -3
  99. data/samples/hello/hello_expand_bar.rb +10 -8
  100. data/samples/hello/hello_file_dialog.rb +9 -7
  101. data/samples/hello/hello_font_dialog.rb +84 -0
  102. data/samples/hello/hello_group.rb +20 -16
  103. data/samples/hello/hello_link.rb +2 -0
  104. data/samples/hello/hello_list_multi_selection.rb +15 -11
  105. data/samples/hello/hello_list_single_selection.rb +15 -11
  106. data/samples/hello/hello_menu_bar.rb +2 -0
  107. data/samples/hello/hello_message_box.rb +2 -0
  108. data/samples/hello/hello_pop_up_context_menu.rb +2 -0
  109. data/samples/hello/hello_progress_bar.rb +5 -5
  110. data/samples/hello/hello_radio.rb +20 -16
  111. data/samples/hello/hello_radio_group.rb +16 -12
  112. data/samples/hello/hello_sash_form.rb +2 -0
  113. data/samples/hello/hello_spinner.rb +9 -7
  114. data/samples/hello/hello_styled_text.rb +19 -17
  115. data/samples/hello/hello_tab.rb +7 -5
  116. data/samples/hello/hello_table.rb +12 -5
  117. data/samples/hello/hello_tree.rb +485 -0
  118. data/samples/hello/hello_world.rb +2 -0
  119. metadata +21 -22
  120. data/lib/glimmer/swt/directory_dialog_proxy.rb +0 -65
  121. 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.absolute_x, self.absolute_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.absolute_x, self.absolute_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.absolute_x, self.absolute_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/dsl/static_expression'
23
- require 'glimmer/dsl/parent_expression'
24
- require 'glimmer/dsl/top_level_expression'
25
- require 'glimmer/swt/directory_dialog_proxy'
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 DSL
29
- module SWT
30
- class DirectoryDialogExpression < StaticExpression
31
- include TopLevelExpression
32
- include ParentExpression
33
-
34
- include_package 'org.eclipse.swt.widgets'
35
-
36
- def can_interpret?(parent, keyword, *args, &block)
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,112 @@
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 default_x?
82
+ super ||
83
+ current_parameter_name?('dest_x') && (dest_x.nil? || dest_x.to_s == 'default')
84
+ end
85
+
86
+ def default_y?
87
+ super ||
88
+ current_parameter_name?('dest_y') && (dest_y.nil? || dest_y.to_s == 'default')
89
+ end
90
+
91
+ def move_by(x_delta, y_delta)
92
+ if default_x?
93
+ self.x_delta += x_delta
94
+ elsif dest_x
95
+ self.dest_x += x_delta
96
+ else
97
+ self.x += x_delta
98
+ end
99
+
100
+ if default_y?
101
+ self.y_delta += y_delta
102
+ elsif dest_y
103
+ self.dest_y += y_delta
104
+ else
105
+ self.y += y_delta
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,111 @@
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 location_parameter_names
50
+ parameter_names
51
+ end
52
+
53
+ # Logical x coordinate. Always assumes the first point in the line to be the x coordinate.
54
+ def x
55
+ x1
56
+ end
57
+
58
+ # Logical y coordinate. Always assumes the first point in the line to be the y coordinate.
59
+ def y
60
+ y1
61
+ end
62
+
63
+ def absolute_x1
64
+ if parent.is_a?(Shape)
65
+ parent.absolute_x + x1
66
+ else
67
+ x1
68
+ end
69
+ end
70
+
71
+ def absolute_y1
72
+ if parent.is_a?(Shape)
73
+ parent.absolute_y + y1
74
+ else
75
+ y1
76
+ end
77
+ end
78
+
79
+ def absolute_x2
80
+ if parent.is_a?(Shape)
81
+ parent.absolute_x + x2
82
+ else
83
+ x2
84
+ end
85
+ end
86
+
87
+ def absolute_y2
88
+ if parent.is_a?(Shape)
89
+ parent.absolute_y + y1
90
+ else
91
+ y2
92
+ end
93
+ end
94
+
95
+ def include?(x, y)
96
+ # TODO must account for line width
97
+ Line.include?(absolute_x1, absolute_y1, absolute_x2, absolute_y2, x, y)
98
+ end
99
+ alias contain? include?
100
+
101
+ def move_by(x_delta, y_delta)
102
+ self.x1 += x_delta
103
+ self.y1 += y_delta
104
+ self.x2 += x_delta
105
+ self.y2 += y_delta
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ 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.absolute_x, self.absolute_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.absolute_x - 3, self.absolute_y - 3, width + 6, height + 6)
53
+ inner_shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x + 3, self.absolute_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,49 @@
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.absolute_x.to_i - 2, self.absolute_x.to_i + 2) && y.to_i.between?(self.absolute_y.to_i - 2, self.absolute_y.to_i + 2)
43
+ end
44
+ alias contain? include?
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,114 @@
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 location_parameter_names
41
+ parameter_names
42
+ end
43
+
44
+ def point_count
45
+ point_array.count / 2
46
+ end
47
+
48
+ def [](index)
49
+ index = 0 if index == point_count
50
+ org.eclipse.swt.graphics.Point.new(point_array[index * 2], point_array[index * 2 + 1])
51
+ end
52
+
53
+ def x_array
54
+ point_array.each_with_index.select {|pair| pair.last.even?}.map(&:first)
55
+ end
56
+
57
+ def y_array
58
+ point_array.each_with_index.select {|pair| pair.last.odd?}.map(&:first)
59
+ end
60
+
61
+ def point_xy_array
62
+ x_array.zip(y_array)
63
+ end
64
+
65
+ # Logical x coordinate. Always assumes the first point in the polygon to be the x coordinate.
66
+ def x
67
+ x_array.first
68
+ end
69
+
70
+ # Logical y coordinate. Always assumes the first point in the polygon to be the y coordinate.
71
+ def y
72
+ y_array.first
73
+ end
74
+
75
+ def absolute_point_array
76
+ if parent.is_a?(Shape)
77
+ point_array.each_with_index.map do |coordinate, i|
78
+ if i.even?
79
+ parent.absolute_x + coordinate
80
+ else
81
+ parent.absolute_y + coordinate
82
+ end
83
+ end
84
+ else
85
+ point_array
86
+ end
87
+ end
88
+
89
+ def absolute_x_array
90
+ absolute_point_array.each_with_index.select {|pair| pair.last.even?}.map(&:first)
91
+ end
92
+
93
+ def absolute_y_array
94
+ absolute_point_array.each_with_index.select {|pair| pair.last.odd?}.map(&:first)
95
+ end
96
+
97
+ def absolute_point_xy_array
98
+ absolute_x_array.zip(absolute_y_array)
99
+ end
100
+
101
+ def include?(x, y)
102
+ shape_geometry = java.awt.Polygon.new(absolute_x_array.to_java(:int), absolute_y_array.to_java(:int), point_count)
103
+ shape_geometry.contains(x, y)
104
+ end
105
+ alias contain? include? # TODO make include do an outer/inner check of edge detection only
106
+
107
+ def move_by(x_delta, y_delta)
108
+ self.point_array = point_array.each_with_index.map {|coordinate, i| i.even? ? coordinate + x_delta : coordinate + y_delta}
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end