glimmer-dsl-swt 4.18.4.8 → 4.18.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +70 -0
  3. data/README.md +24 -11
  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 +353 -145
  8. data/docs/reference/GLIMMER_SAMPLES.md +207 -41
  9. data/glimmer-dsl-swt.gemspec +33 -15
  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 +13 -15
  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 +2 -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 +18 -3
  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 +9 -5
  29. data/lib/glimmer/dsl/swt/shape_expression.rb +1 -1
  30. data/lib/glimmer/dsl/swt/shell_expression.rb +5 -2
  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 +50 -2
  37. data/lib/glimmer/swt/custom/radio_group.rb +2 -1
  38. data/lib/glimmer/swt/custom/shape.rb +166 -34
  39. data/lib/glimmer/{dsl/swt/directory_dialog_expression.rb → swt/custom/shape/arc.rb} +15 -20
  40. data/lib/glimmer/swt/custom/shape/focus.rb +43 -0
  41. data/lib/glimmer/swt/custom/shape/image.rb +86 -0
  42. data/lib/glimmer/swt/custom/shape/line.rb +58 -0
  43. data/lib/glimmer/swt/custom/shape/oval.rb +43 -0
  44. data/lib/glimmer/swt/custom/shape/point.rb +52 -0
  45. data/lib/glimmer/swt/custom/shape/polygon.rb +73 -0
  46. data/lib/glimmer/swt/custom/shape/polyline.rb +73 -0
  47. data/lib/glimmer/swt/custom/shape/rectangle.rb +87 -0
  48. data/lib/glimmer/swt/custom/shape/text.rb +73 -0
  49. data/lib/glimmer/swt/date_time_proxy.rb +9 -3
  50. data/lib/glimmer/swt/dialog_proxy.rb +92 -0
  51. data/lib/glimmer/swt/display_proxy.rb +62 -2
  52. data/lib/glimmer/swt/expand_item_proxy.rb +18 -12
  53. data/lib/glimmer/swt/font_proxy.rb +13 -7
  54. data/lib/glimmer/swt/image_proxy.rb +16 -5
  55. data/lib/glimmer/swt/layout_data_proxy.rb +21 -15
  56. data/lib/glimmer/swt/layout_proxy.rb +19 -15
  57. data/lib/glimmer/swt/menu_proxy.rb +2 -2
  58. data/lib/glimmer/swt/message_box_proxy.rb +21 -7
  59. data/lib/glimmer/swt/properties.rb +3 -0
  60. data/lib/glimmer/swt/proxy_properties.rb +145 -0
  61. data/lib/glimmer/swt/scrolled_composite_proxy.rb +20 -7
  62. data/lib/glimmer/swt/shell_proxy.rb +96 -80
  63. data/lib/glimmer/swt/swt_proxy.rb +17 -0
  64. data/lib/glimmer/swt/tab_item_proxy.rb +6 -3
  65. data/lib/glimmer/swt/table_proxy.rb +32 -11
  66. data/lib/glimmer/swt/transform_proxy.rb +26 -38
  67. data/lib/glimmer/swt/tree_proxy.rb +11 -16
  68. data/lib/glimmer/swt/widget_listener_proxy.rb +6 -2
  69. data/lib/glimmer/swt/widget_proxy.rb +194 -137
  70. data/lib/glimmer/ui.rb +5 -0
  71. data/lib/glimmer/ui/custom_shell.rb +13 -7
  72. data/lib/glimmer/ui/custom_widget.rb +4 -5
  73. data/samples/elaborate/contact_manager.rb +7 -7
  74. data/samples/elaborate/login.rb +25 -21
  75. data/samples/elaborate/mandelbrot_fractal.rb +346 -39
  76. data/samples/elaborate/meta_sample.rb +1 -1
  77. data/samples/elaborate/tetris.rb +1 -0
  78. data/samples/elaborate/tic_tac_toe.rb +16 -14
  79. data/samples/elaborate/tic_tac_toe/board.rb +5 -5
  80. data/samples/elaborate/tic_tac_toe/cell.rb +5 -5
  81. data/samples/hello/hello_button.rb +7 -7
  82. data/samples/hello/hello_canvas.rb +145 -41
  83. data/samples/hello/hello_checkbox.rb +16 -14
  84. data/samples/hello/hello_checkbox_group.rb +11 -9
  85. data/samples/hello/hello_color_dialog.rb +66 -0
  86. data/samples/hello/hello_combo.rb +14 -12
  87. data/samples/hello/hello_computed.rb +7 -7
  88. data/samples/hello/hello_cursor.rb +58 -0
  89. data/samples/hello/hello_custom_shell.rb +17 -21
  90. data/samples/hello/hello_custom_widget.rb +4 -6
  91. data/samples/hello/hello_date_time.rb +14 -12
  92. data/samples/hello/hello_directory_dialog.rb +7 -7
  93. data/samples/hello/hello_expand_bar.rb +8 -8
  94. data/samples/hello/hello_file_dialog.rb +7 -7
  95. data/samples/hello/hello_font_dialog.rb +82 -0
  96. data/samples/hello/hello_group.rb +18 -16
  97. data/samples/hello/hello_list_multi_selection.rb +13 -11
  98. data/samples/hello/hello_list_single_selection.rb +13 -11
  99. data/samples/hello/hello_progress_bar.rb +125 -0
  100. data/samples/hello/hello_radio.rb +18 -16
  101. data/samples/hello/hello_radio_group.rb +14 -12
  102. data/samples/hello/hello_spinner.rb +7 -7
  103. data/samples/hello/hello_tab.rb +5 -5
  104. data/samples/hello/hello_table.rb +10 -5
  105. data/samples/hello/hello_tree.rb +485 -0
  106. metadata +30 -23
  107. data/lib/glimmer/swt/directory_dialog_proxy.rb +0 -65
  108. data/lib/glimmer/swt/file_dialog_proxy.rb +0 -66
@@ -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
+ # 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
44
39
  end
45
40
  end
46
41
  end
@@ -0,0 +1,43 @@
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 Focus < Shape
36
+ def parameter_names
37
+ [:x, :y, :width, :height]
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,86 @@
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 include?(x, y)
66
+ self_x = dest_x || self.x
67
+ self_y = dest_y || self.y
68
+ width = dest_width || image.bounds.width
69
+ height = dest_height || image.bounds.height
70
+ x.between?(self_x, self_x + width) && y.between?(self_y, self_y + height)
71
+ end
72
+
73
+ def move_by(x_delta, y_delta)
74
+ if dest_x
75
+ self.dest_x += x_delta
76
+ self.dest_y += y_delta
77
+ else
78
+ self.x += x_delta
79
+ self.y += y_delta
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,58 @@
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
+ def parameter_names
37
+ [:x1, :y1, :x2, :y2]
38
+ end
39
+
40
+ def include?(x, y)
41
+ # TODO must account for line width
42
+ distance1 = Math.sqrt((x - x1)**2 + (y - y1)**2)
43
+ distance2 = Math.sqrt((x2 - x)**2 + (y2 - y)**2)
44
+ distance = Math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
45
+ (distance1 + distance2).to_i == distance.to_i
46
+ end
47
+
48
+ def move_by(x_delta, y_delta)
49
+ self.x1 += x_delta
50
+ self.y1 += y_delta
51
+ self.x2 += x_delta
52
+ self.y2 += y_delta
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,43 @@
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
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,52 @@
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
+ 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)
42
+ end
43
+
44
+ def move_by(x_delta, y_delta)
45
+ self.x += x_delta
46
+ self.y += y_delta
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ 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 size
41
+ point_array.size / 2
42
+ end
43
+
44
+ def [](index)
45
+ index = 0 if index == size
46
+ org.eclipse.swt.graphics.Point.new(point_array[index * 2], point_array[index * 2 + 1])
47
+ end
48
+
49
+ def include?(x, y)
50
+ c = false
51
+ i = -1
52
+ j = self.size
53
+ while (i += 1) < (self.size + 1)
54
+ if ((self[i].y <= y && y < self[j].y) ||
55
+ (self[j].y <= y && y < self[i].y))
56
+ if (x < (self[j].x - self[i].x) * (y - self[i].y) /
57
+ (self[j].y - self[i].y) + self[i].x)
58
+ c = !c
59
+ end
60
+ j = i
61
+ end
62
+ end
63
+ c
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
@@ -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 Polyline < Shape
36
+ def parameter_names
37
+ [:point_array]
38
+ end
39
+
40
+ def size
41
+ point_array.size / 2
42
+ end
43
+
44
+ def [](index)
45
+ index = 0 if index == size
46
+ org.eclipse.swt.graphics.Point.new(point_array[index * 2], point_array[index * 2 + 1])
47
+ end
48
+
49
+ def include?(x, y)
50
+ c = false
51
+ i = -1
52
+ j = self.size
53
+ while (i += 1) < (self.size + 1)
54
+ if ((self[i].y <= y && y < self[j].y) ||
55
+ (self[j].y <= y && y < self[i].y))
56
+ if (x < (self[j].x - self[i].x) * (y - self[i].y) /
57
+ (self[j].y - self[i].y) + self[i].x)
58
+ c = !c
59
+ end
60
+ j = i
61
+ end
62
+ end
63
+ c
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