glimmer-dsl-swt 4.18.4.4 → 4.18.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/LICENSE.txt +20 -20
  4. data/README.md +43 -5058
  5. data/RUBY_VERSION +1 -1
  6. data/VERSION +1 -1
  7. data/bin/girb +31 -31
  8. data/bin/girb_runner.rb +34 -34
  9. data/bin/glimmer +26 -26
  10. data/docs/reference/GLIMMER_COMMAND.md +591 -0
  11. data/docs/reference/GLIMMER_CONFIGURATION.md +183 -0
  12. data/docs/reference/GLIMMER_GIRB.md +30 -0
  13. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +3367 -0
  14. data/docs/reference/GLIMMER_PACKAGING_AND_DISTRIBUTION.md +202 -0
  15. data/docs/reference/GLIMMER_SAMPLES.md +755 -0
  16. data/docs/reference/GLIMMER_STYLE_GUIDE.md +14 -0
  17. data/glimmer-dsl-swt.gemspec +22 -7
  18. data/lib/ext/glimmer.rb +41 -41
  19. data/lib/ext/glimmer/config.rb +167 -167
  20. data/lib/ext/rouge/themes/glimmer.rb +29 -29
  21. data/lib/glimmer-dsl-swt.rb +44 -44
  22. data/lib/glimmer/Rakefile +26 -26
  23. data/lib/glimmer/data_binding/list_selection_binding.rb +72 -72
  24. data/lib/glimmer/data_binding/observable_widget.rb +38 -38
  25. data/lib/glimmer/data_binding/shine.rb +44 -44
  26. data/lib/glimmer/data_binding/table_items_binding.rb +89 -89
  27. data/lib/glimmer/data_binding/tree_items_binding.rb +108 -108
  28. data/lib/glimmer/data_binding/widget_binding.rb +73 -73
  29. data/lib/glimmer/dsl/swt/animation_expression.rb +43 -43
  30. data/lib/glimmer/dsl/swt/async_exec_expression.rb +35 -35
  31. data/lib/glimmer/dsl/swt/bind_expression.rb +58 -58
  32. data/lib/glimmer/dsl/swt/block_property_expression.rb +41 -41
  33. data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +61 -61
  34. data/lib/glimmer/dsl/swt/color_expression.rb +40 -40
  35. data/lib/glimmer/dsl/swt/column_properties_expression.rb +45 -45
  36. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +67 -67
  37. data/lib/glimmer/dsl/swt/cursor_expression.rb +44 -44
  38. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +63 -63
  39. data/lib/glimmer/dsl/swt/data_binding_expression.rb +55 -55
  40. data/lib/glimmer/dsl/swt/dialog_expression.rb +48 -48
  41. data/lib/glimmer/dsl/swt/directory_dialog_expression.rb +48 -48
  42. data/lib/glimmer/dsl/swt/display_expression.rb +40 -40
  43. data/lib/glimmer/dsl/swt/dnd_expression.rb +46 -46
  44. data/lib/glimmer/dsl/swt/dsl.rb +63 -63
  45. data/lib/glimmer/dsl/swt/exec_expression.rb +55 -55
  46. data/lib/glimmer/dsl/swt/expand_item_expression.rb +60 -60
  47. data/lib/glimmer/dsl/swt/file_dialog_expression.rb +48 -48
  48. data/lib/glimmer/dsl/swt/font_expression.rb +49 -49
  49. data/lib/glimmer/dsl/swt/image_expression.rb +54 -50
  50. data/lib/glimmer/dsl/swt/layout_data_expression.rb +46 -46
  51. data/lib/glimmer/dsl/swt/layout_expression.rb +50 -50
  52. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +65 -65
  53. data/lib/glimmer/dsl/swt/menu_bar_expression.rb +54 -54
  54. data/lib/glimmer/dsl/swt/menu_expression.rb +53 -53
  55. data/lib/glimmer/dsl/swt/message_box_expression.rb +54 -54
  56. data/lib/glimmer/dsl/swt/multiply_expression.rb +53 -53
  57. data/lib/glimmer/dsl/swt/observe_expression.rb +56 -53
  58. data/lib/glimmer/dsl/swt/pixel_expression.rb +38 -0
  59. data/lib/glimmer/dsl/swt/property_expression.rb +46 -46
  60. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +62 -61
  61. data/lib/glimmer/dsl/swt/rgb_expression.rb +33 -33
  62. data/lib/glimmer/dsl/swt/rgba_expression.rb +33 -33
  63. data/lib/glimmer/dsl/swt/shape_expression.rb +54 -54
  64. data/lib/glimmer/dsl/swt/shell_expression.rb +46 -46
  65. data/lib/glimmer/dsl/swt/swt_expression.rb +46 -46
  66. data/lib/glimmer/dsl/swt/sync_exec_expression.rb +36 -36
  67. data/lib/glimmer/dsl/swt/tab_item_expression.rb +54 -54
  68. data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +52 -52
  69. data/lib/glimmer/dsl/swt/transform_expression.rb +55 -55
  70. data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +52 -52
  71. data/lib/glimmer/dsl/swt/tree_properties_expression.rb +47 -47
  72. data/lib/glimmer/dsl/swt/widget_expression.rb +67 -66
  73. data/lib/glimmer/dsl/swt/widget_listener_expression.rb +53 -53
  74. data/lib/glimmer/rake_task.rb +220 -220
  75. data/lib/glimmer/rake_task/list.rb +97 -97
  76. data/lib/glimmer/rake_task/package.rb +139 -139
  77. data/lib/glimmer/rake_task/scaffold.rb +765 -765
  78. data/lib/glimmer/swt/color_proxy.rb +108 -107
  79. data/lib/glimmer/swt/cursor_proxy.rb +66 -66
  80. data/lib/glimmer/swt/custom/animation.rb +245 -243
  81. data/lib/glimmer/swt/custom/checkbox_group.rb +181 -181
  82. data/lib/glimmer/swt/custom/code_text.rb +1 -0
  83. data/lib/glimmer/swt/custom/drawable.rb +97 -49
  84. data/lib/glimmer/swt/custom/radio_group.rb +177 -176
  85. data/lib/glimmer/swt/custom/shape.rb +332 -297
  86. data/lib/glimmer/swt/date_time_proxy.rb +85 -85
  87. data/lib/glimmer/swt/directory_dialog_proxy.rb +65 -65
  88. data/lib/glimmer/swt/display_proxy.rb +167 -166
  89. data/lib/glimmer/swt/dnd_proxy.rb +51 -51
  90. data/lib/glimmer/swt/expand_item_proxy.rb +97 -97
  91. data/lib/glimmer/swt/file_dialog_proxy.rb +66 -66
  92. data/lib/glimmer/swt/font_proxy.rb +94 -94
  93. data/lib/glimmer/swt/image_proxy.rb +195 -184
  94. data/lib/glimmer/swt/layout_data_proxy.rb +105 -105
  95. data/lib/glimmer/swt/layout_proxy.rb +112 -112
  96. data/lib/glimmer/swt/menu_proxy.rb +126 -126
  97. data/lib/glimmer/swt/message_box_proxy.rb +89 -89
  98. data/lib/glimmer/swt/packages.rb +37 -37
  99. data/lib/glimmer/swt/properties.rb +74 -49
  100. data/lib/glimmer/swt/sash_form_proxy.rb +53 -53
  101. data/lib/glimmer/swt/scrolled_composite_proxy.rb +46 -37
  102. data/lib/glimmer/swt/style_constantizable.rb +157 -157
  103. data/lib/glimmer/swt/styled_text_proxy.rb +38 -38
  104. data/lib/glimmer/swt/swt_proxy.rb +59 -59
  105. data/lib/glimmer/swt/tab_item_proxy.rb +92 -91
  106. data/lib/glimmer/swt/table_column_proxy.rb +57 -57
  107. data/lib/glimmer/swt/transform_proxy.rb +109 -109
  108. data/lib/glimmer/swt/tree_proxy.rb +145 -145
  109. data/lib/glimmer/swt/widget_listener_proxy.rb +64 -64
  110. data/lib/glimmer/swt/widget_proxy.rb +977 -957
  111. data/lib/glimmer/ui/custom_shell.rb +82 -82
  112. data/lib/glimmer/ui/custom_widget.rb +332 -315
  113. data/lib/glimmer/util/proc_tracker.rb +39 -39
  114. data/samples/elaborate/contact_manager.rb +142 -142
  115. data/samples/elaborate/contact_manager/contact.rb +32 -32
  116. data/samples/elaborate/contact_manager/contact_manager_presenter.rb +47 -47
  117. data/samples/elaborate/contact_manager/contact_repository.rb +169 -169
  118. data/samples/elaborate/login.rb +123 -123
  119. data/samples/elaborate/mandelbrot_fractal.rb +354 -0
  120. data/samples/elaborate/tetris.rb +5 -18
  121. data/samples/elaborate/tetris/model/block.rb +48 -48
  122. data/samples/elaborate/tetris/model/past_game.rb +39 -39
  123. data/samples/elaborate/tetris/view/block.rb +1 -1
  124. data/samples/elaborate/tetris/view/playfield.rb +1 -1
  125. data/samples/elaborate/tic_tac_toe.rb +76 -76
  126. data/samples/elaborate/tic_tac_toe/board.rb +145 -145
  127. data/samples/elaborate/tic_tac_toe/cell.rb +48 -48
  128. data/samples/elaborate/user_profile.rb +76 -76
  129. data/samples/hello/hello_browser.rb +31 -31
  130. data/samples/hello/hello_button.rb +46 -46
  131. data/samples/hello/hello_canvas.rb +64 -64
  132. data/samples/hello/hello_canvas_animation.rb +1 -1
  133. data/samples/hello/hello_checkbox.rb +85 -85
  134. data/samples/hello/hello_checkbox_group.rb +71 -71
  135. data/samples/hello/hello_code_text.rb +104 -104
  136. data/samples/hello/hello_combo.rb +63 -63
  137. data/samples/hello/hello_computed.rb +96 -96
  138. data/samples/hello/hello_computed/contact.rb +42 -42
  139. data/samples/hello/hello_cursor.rb +57 -0
  140. data/samples/hello/hello_custom_shell.rb +155 -155
  141. data/samples/hello/hello_custom_widget.rb +86 -86
  142. data/samples/hello/hello_date_time.rb +63 -63
  143. data/samples/hello/hello_dialog.rb +78 -78
  144. data/samples/hello/hello_directory_dialog.rb +60 -60
  145. data/samples/hello/hello_drag_and_drop.rb +50 -50
  146. data/samples/hello/hello_expand_bar.rb +110 -110
  147. data/samples/hello/hello_file_dialog.rb +60 -60
  148. data/samples/hello/hello_group.rb +104 -104
  149. data/samples/hello/hello_link.rb +80 -80
  150. data/samples/hello/hello_list_multi_selection.rb +74 -74
  151. data/samples/hello/hello_list_single_selection.rb +59 -59
  152. data/samples/hello/hello_menu_bar.rb +241 -241
  153. data/samples/hello/hello_message_box.rb +37 -37
  154. data/samples/hello/hello_pop_up_context_menu.rb +84 -84
  155. data/samples/hello/hello_radio.rb +108 -108
  156. data/samples/hello/hello_radio_group.rb +87 -87
  157. data/samples/hello/hello_sash_form.rb +137 -137
  158. data/samples/hello/hello_spinner.rb +69 -69
  159. data/samples/hello/hello_styled_text.rb +138 -138
  160. data/samples/hello/hello_tab.rb +50 -50
  161. data/samples/hello/hello_table.rb +1 -1
  162. data/samples/hello/hello_table/baseball_park.png +0 -0
  163. data/samples/hello/hello_world.rb +29 -29
  164. metadata +19 -4
@@ -1,176 +1,177 @@
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/ui/custom_widget'
23
-
24
- module Glimmer
25
- module SWT
26
- module Custom
27
- # A custom widget rendering a group of radios generated via data-binding
28
- class RadioGroup
29
- include Glimmer::UI::CustomWidget
30
-
31
- body {
32
- composite # just an empty composite to hold radios upon data-binding `selection`
33
- }
34
-
35
- def items=(text_array)
36
- selection_value = selection
37
- @items = Array[*text_array]
38
- build_radios
39
- end
40
-
41
- def items
42
- @items || []
43
- end
44
-
45
- def selection=(text)
46
- radios.count.times do |index|
47
- radio = radios[index]
48
- item = items[index]
49
- radio.selection = item == text
50
- end
51
- end
52
-
53
- def selection
54
- selection_value = labels[selection_index]&.text unless selection_index == -1
55
- selection_value.to_s
56
- end
57
-
58
- def selection_index=(index)
59
- self.selection=(items[index])
60
- end
61
- alias select selection_index=
62
-
63
- def selection_index
64
- radios.index(radios.detect(&:selection)) || -1
65
- end
66
-
67
- def radios
68
- @radios ||= []
69
- end
70
-
71
- def labels
72
- @labels ||= []
73
- end
74
-
75
- def can_handle_observation_request?(observation_request)
76
- radios.first&.can_handle_observation_request?(observation_request) || super(observation_request)
77
- end
78
-
79
- def handle_observation_request(observation_request, &block)
80
- observation_requests << [observation_request, block]
81
- delegate_observation_request_to_radios(observation_request, &block)
82
- super
83
- end
84
-
85
- def delegate_observation_request_to_radios(observation_request, &block)
86
- if observation_request != 'on_widget_disposed'
87
- radios.count.times do |index|
88
- radio = radios[index]
89
- label = labels[index]
90
- if observation_request == 'on_widget_selected'
91
- radio_block = lambda do |event|
92
- if event.widget.selection || selection_index == -1
93
- event.widget = self.swt_widget
94
- block.call(event)
95
- end
96
- end
97
- label_block = lambda do |event|
98
- self.selection_index = index
99
- block.call(event)
100
- end
101
- radio.handle_observation_request(observation_request, &radio_block) if radio.can_handle_observation_request?(observation_request)
102
- label.handle_observation_request('on_mouse_up', &label_block)
103
- else
104
- listener_block = lambda do |event|
105
- event.widget = self.swt_widget
106
- block.call(event)
107
- end
108
- radio.handle_observation_request(observation_request, &listener_block) if radio.can_handle_observation_request?(observation_request)
109
- label.handle_observation_request(observation_request, &listener_block) if label.can_handle_observation_request?(observation_request)
110
- end
111
- end
112
- end
113
- end
114
-
115
- def observation_requests
116
- @observation_requests ||= Set.new
117
- end
118
-
119
- def has_attribute?(attribute_name, *args)
120
- (@composites.to_a + @radios.to_a + @labels.to_a).map do |widget_proxy|
121
- return true if widget_proxy.has_attribute?(attribute_name, *args)
122
- end
123
- super
124
- end
125
-
126
- def set_attribute(attribute_name, *args)
127
- excluded_attributes = ['selection']
128
- unless excluded_attributes.include?(attribute_name.to_s)
129
- (@composites.to_a + @radios.to_a + @labels.to_a).each do |widget_proxy|
130
- widget_proxy.set_attribute(attribute_name, *args) if widget_proxy.has_attribute?(attribute_name, *args)
131
- end
132
- end
133
- super
134
- end
135
-
136
- private
137
-
138
- def build_radios
139
- current_selection = selection
140
- @composites.to_a.each(&:dispose)
141
- @radios = []
142
- @labels = []
143
- @composites = []
144
- items.each do |item|
145
- body_root.content {
146
- @composites << composite {
147
- grid_layout(2, false) {
148
- margin_width 0
149
- margin_height 0
150
- horizontal_spacing 0
151
- vertical_spacing 0
152
- }
153
- radios << radio { |radio_proxy|
154
- on_widget_selected {
155
- self.selection = items[radios.index(radio_proxy)]
156
- }
157
- }
158
- labels << label { |label_proxy|
159
- layout_data :fill, :center, true, false
160
- text item
161
- on_mouse_up {
162
- self.selection = label_proxy.text
163
- }
164
- }
165
- }
166
- }
167
- end
168
- observation_requests.to_a.each do |observation_request, block|
169
- delegate_observation_request_to_radios(observation_request, &block)
170
- end
171
- self.selection = current_selection
172
- end
173
- end
174
- end
175
- end
176
- end
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/ui/custom_widget'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ module Custom
27
+ # A custom widget rendering a group of radios generated via data-binding
28
+ class RadioGroup
29
+ include Glimmer::UI::CustomWidget
30
+
31
+ body {
32
+ composite # just an empty composite to hold radios upon data-binding `selection`
33
+ }
34
+
35
+ def items=(text_array)
36
+ selection_value = selection
37
+ @items = Array[*text_array]
38
+ build_radios
39
+ end
40
+
41
+ def items
42
+ @items || []
43
+ end
44
+
45
+ def selection=(text)
46
+ radios.count.times do |index|
47
+ radio = radios[index]
48
+ item = items[index]
49
+ radio.selection = item == text
50
+ end
51
+ end
52
+
53
+ def selection
54
+ selection_value = labels[selection_index]&.text unless selection_index == -1
55
+ selection_value.to_s
56
+ end
57
+
58
+ def selection_index=(index)
59
+ self.selection=(items[index])
60
+ end
61
+ alias select selection_index=
62
+
63
+ def selection_index
64
+ radios.index(radios.detect(&:selection)) || -1
65
+ end
66
+
67
+ def radios
68
+ @radios ||= []
69
+ end
70
+
71
+ def labels
72
+ @labels ||= []
73
+ end
74
+
75
+ def can_handle_observation_request?(observation_request)
76
+ radios.first&.can_handle_observation_request?(observation_request) or
77
+ super(observation_request)
78
+ end
79
+
80
+ def handle_observation_request(observation_request, &block)
81
+ observation_requests << [observation_request, block]
82
+ delegate_observation_request_to_radios(observation_request, &block)
83
+ super
84
+ end
85
+
86
+ def delegate_observation_request_to_radios(observation_request, &block)
87
+ if observation_request != 'on_widget_disposed'
88
+ radios.count.times do |index|
89
+ radio = radios[index]
90
+ label = labels[index]
91
+ if observation_request == 'on_widget_selected'
92
+ radio_block = lambda do |event|
93
+ if event.widget.selection || selection_index == -1
94
+ event.widget = self.swt_widget
95
+ block.call(event)
96
+ end
97
+ end
98
+ label_block = lambda do |event|
99
+ self.selection_index = index
100
+ block.call(event)
101
+ end
102
+ radio.handle_observation_request(observation_request, &radio_block) if radio.can_handle_observation_request?(observation_request)
103
+ label.handle_observation_request('on_mouse_up', &label_block)
104
+ else
105
+ listener_block = lambda do |event|
106
+ event.widget = self.swt_widget
107
+ block.call(event)
108
+ end
109
+ radio.handle_observation_request(observation_request, &listener_block) if radio.can_handle_observation_request?(observation_request)
110
+ label.handle_observation_request(observation_request, &listener_block) if label.can_handle_observation_request?(observation_request)
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ def observation_requests
117
+ @observation_requests ||= Set.new
118
+ end
119
+
120
+ def has_attribute?(attribute_name, *args)
121
+ (@composites.to_a + @radios.to_a + @labels.to_a).map do |widget_proxy|
122
+ return true if widget_proxy.has_attribute?(attribute_name, *args)
123
+ end
124
+ super
125
+ end
126
+
127
+ def set_attribute(attribute_name, *args)
128
+ excluded_attributes = ['selection']
129
+ unless excluded_attributes.include?(attribute_name.to_s)
130
+ (@composites.to_a + @radios.to_a + @labels.to_a).each do |widget_proxy|
131
+ widget_proxy.set_attribute(attribute_name, *args) if widget_proxy.has_attribute?(attribute_name, *args)
132
+ end
133
+ end
134
+ super
135
+ end
136
+
137
+ private
138
+
139
+ def build_radios
140
+ current_selection = selection
141
+ @composites.to_a.each(&:dispose)
142
+ @radios = []
143
+ @labels = []
144
+ @composites = []
145
+ items.each do |item|
146
+ body_root.content {
147
+ @composites << composite {
148
+ grid_layout(2, false) {
149
+ margin_width 0
150
+ margin_height 0
151
+ horizontal_spacing 0
152
+ vertical_spacing 0
153
+ }
154
+ radios << radio { |radio_proxy|
155
+ on_widget_selected {
156
+ self.selection = items[radios.index(radio_proxy)]
157
+ }
158
+ }
159
+ labels << label { |label_proxy|
160
+ layout_data :fill, :center, true, false
161
+ text item
162
+ on_mouse_up {
163
+ self.selection = label_proxy.text
164
+ }
165
+ }
166
+ }
167
+ }
168
+ end
169
+ observation_requests.to_a.each do |observation_request, block|
170
+ delegate_observation_request_to_radios(observation_request, &block)
171
+ end
172
+ self.selection = current_selection
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
@@ -1,297 +1,332 @@
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/properties'
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
- include Packages
36
- include Properties
37
- # TODO support textExtent sized shapes nested within text/string
38
- # TODO support a Pattern DSL for methods that take Pattern arguments
39
-
40
- class << self
41
- def valid?(parent, keyword, *args, &block)
42
- gc_instance_methods.include?(method_name(keyword, args))
43
- end
44
-
45
- def gc_instance_methods
46
- @gc_instance_methods ||= org.eclipse.swt.graphics.GC.instance_methods.map(&:to_s)
47
- end
48
-
49
- def keywords
50
- @keywords ||= gc_instance_methods.select do |method_name|
51
- !method_name.end_with?('=') && (method_name.start_with?('draw_') || method_name.start_with?('fill_'))
52
- end.reject do |method_name|
53
- gc_instance_methods.include?("#{method_name}=") || gc_instance_methods.include?("set_#{method_name}")
54
- end.map do |method_name|
55
- method_name.gsub(/(draw|fill|gradient|round)_/, '')
56
- end.uniq.compact.to_a
57
- end
58
-
59
- def arg_options(args, extract: false)
60
- arg_options_method = extract ? :pop : :last
61
- options = args.send(arg_options_method) if args.last.is_a?(Hash)
62
- options.nil? ? {} : options.symbolize_keys
63
- end
64
-
65
- def method_name(keyword, args)
66
- method_arg_options = arg_options(args)
67
- unless flyweight_method_names.keys.include?([keyword, method_arg_options])
68
- keyword = keyword.to_s
69
- gradient = 'gradient_' if method_arg_options[:gradient]
70
- round = 'round_' if method_arg_options[:round]
71
- gc_instance_method_name_prefix = !['polyline', 'point', 'image', 'focus'].include?(keyword) && (method_arg_options[:fill] || method_arg_options[:gradient]) ? 'fill_' : 'draw_'
72
- flyweight_method_names[[keyword, method_arg_options]] = "#{gc_instance_method_name_prefix}#{gradient}#{round}#{keyword}"
73
- end
74
- flyweight_method_names[[keyword, method_arg_options]]
75
- end
76
-
77
- def flyweight_method_names
78
- @flyweight_method_names ||= {}
79
- end
80
-
81
- def pattern(*args)
82
- found_pattern = flyweigh_patterns[args]
83
- if found_pattern.nil? || found_pattern.is_disposed
84
- found_pattern = flyweigh_patterns[args] = org.eclipse.swt.graphics.Pattern.new(*args)
85
- end
86
- found_pattern
87
- end
88
-
89
- def flyweigh_patterns
90
- @flyweigh_patterns ||= {}
91
- end
92
- end
93
-
94
- attr_reader :parent, :name, :args, :options, :paint_listener_proxy
95
-
96
- def initialize(parent, keyword, *args, &property_block)
97
- @parent = parent
98
- @name = keyword
99
- @method_name = self.class.method_name(keyword, args)
100
- @options = self.class.arg_options(args, extract: true)
101
- @args = args
102
- @properties = {}
103
- @parent.shapes << self
104
- post_add_content if property_block.nil?
105
- end
106
-
107
- def draw?
108
- !fill?
109
- end
110
-
111
- def fill?
112
- @options[:fill]
113
- end
114
-
115
- def gradient?
116
- @options[:gradient]
117
- end
118
-
119
- def round?
120
- @options[:round]
121
- end
122
-
123
- def has_some_background?
124
- @properties.keys.map(&:to_s).include?('background') || @properties.keys.map(&:to_s).include?('background_pattern')
125
- end
126
-
127
- def has_some_foreground?
128
- @properties.keys.map(&:to_s).include?('foreground') || @properties.keys.map(&:to_s).include?('foreground_pattern')
129
- end
130
-
131
- def post_add_content
132
- amend_method_name_options_based_on_properties
133
- setup_painting
134
- @content_added = true
135
- end
136
-
137
- def apply_property_arg_conversions(method_name, property, args)
138
- args = args.dup
139
- the_java_method = org.eclipse.swt.graphics.GC.java_class.declared_instance_methods.detect {|m| m.name == method_name}
140
- if (args.first.is_a?(Symbol) || args.first.is_a?(String))
141
- if the_java_method.parameter_types.first == Color.java_class
142
- args[0] = ColorProxy.new(args[0])
143
- end
144
- if the_java_method.parameter_types.first == Java::int.java_class
145
- args[0] = SWTProxy.constant(args[0])
146
- end
147
- end
148
- if args.first.is_a?(ColorProxy)
149
- args[0] = args[0].swt_color
150
- end
151
- if args.first.is_a?(Hash) && the_java_method.parameter_types.first == Font.java_class
152
- args[0] = FontProxy.new(args[0])
153
- end
154
- if args.first.is_a?(FontProxy)
155
- args[0] = args[0].swt_font
156
- end
157
- if args.first.is_a?(TransformProxy)
158
- args[0] = args[0].swt_transform
159
- end
160
- if ['setBackgroundPattern', 'setForegroundPattern'].include?(method_name.to_s)
161
- args.each_with_index do |arg, i|
162
- if arg.is_a?(Symbol) || arg.is_a?(String)
163
- args[i] = ColorProxy.new(arg).swt_color
164
- elsif arg.is_a?(ColorProxy)
165
- args[i] = arg.swt_color
166
- end
167
- end
168
- new_args = [DisplayProxy.instance.swt_display] + args
169
- args[0] = pattern(*new_args, type: method_name.to_s.match(/set(.+)Pattern/)[1])
170
- args[1..-1] = []
171
- end
172
- args
173
- end
174
-
175
- def apply_shape_arg_conversions(method_name, args)
176
- if args.size > 1 && (method_name.include?('polygon') || method_name.include?('polyline'))
177
- args[0] = args.dup
178
- args[1..-1] = []
179
- end
180
- end
181
-
182
- def apply_shape_arg_defaults(method_name, args)
183
- if method_name.include?('round_rectangle') && args.size.between?(4, 5)
184
- (6 - args.size).times {args << 60}
185
- elsif method_name.include?('rectangle') && gradient? && args.size == 4
186
- args << true
187
- elsif (method_name.include?('text') || method_name.include?('string')) && !@properties.keys.map(&:to_s).include?('background') && args.size == 3
188
- args << true
189
- end
190
- if method_name.include?('image') && args.first.is_a?(String)
191
- args[0] = ImageProxy.new(args[0])
192
- end
193
- if method_name.include?('image') && args.first.is_a?(ImageProxy)
194
- @image = args[0] = args[0].swt_image
195
- end
196
- end
197
-
198
- # Tolerates shape extra args added by user by mistake
199
- # (e.g. happens when switching from round rectangle to a standard one without removing all extra args)
200
- def tolerate_shape_extra_args(method_name, args)
201
- the_java_method_arg_count = org.eclipse.swt.graphics.GC.java_class.declared_instance_methods.select do |m|
202
- m.name == method_name.camelcase(:lower)
203
- end.map(&:parameter_types).map(&:size).max
204
- if args.size > the_java_method_arg_count
205
- args[the_java_method_arg_count..-1] = []
206
- end
207
- end
208
-
209
- def amend_method_name_options_based_on_properties
210
- if has_some_background? && !has_some_foreground?
211
- @options[:fill] = true
212
- elsif !has_some_background? && has_some_foreground?
213
- @options[:fill] = false
214
- elsif @name == 'rectangle' && has_some_background? && has_some_foreground?
215
- @options[:fill] = true
216
- @options[:gradient] = true
217
- end
218
- if @name == 'rectangle' && @args.size > 4 && @args.last.is_a?(Numeric)
219
- @options[:round] = true
220
- end
221
- @method_name = self.class.method_name(@name, @args + [@options])
222
- end
223
-
224
- def has_attribute?(attribute_name, *args)
225
- self.class.gc_instance_methods.include?(attribute_setter(attribute_name))
226
- end
227
-
228
- def set_attribute(attribute_name, *args)
229
- @properties[attribute_name] = args
230
- if @content_added && !@parent.is_disposed
231
- @parent.resetup_shape_painting
232
- @parent.redraw
233
- end
234
- end
235
-
236
- def get_attribute(attribute_name)
237
- @properties.symbolize_keys[attribute_name.to_s.to_sym]
238
- end
239
-
240
- def pattern(*args, type: nil)
241
- instance_variable_name = "@#{type}_pattern"
242
- the_pattern = instance_variable_get(instance_variable_name)
243
- if the_pattern.nil?
244
- the_pattern = self.class.pattern(*args)
245
- end
246
- the_pattern
247
- end
248
-
249
- def dispose
250
- paint_listener_proxy&.unregister
251
- @background_pattern&.dispose
252
- @background_pattern = nil
253
- @foreground_pattern&.dispose
254
- @foreground_pattern = nil
255
- @image&.dispose
256
- @image = nil
257
- @parent.shapes.delete(self)
258
- end
259
-
260
- def setup_painting
261
- # TODO consider moving this method to parent (making the logic polymorphic)
262
- return if @parent.is_disposed
263
- if parent.respond_to?(:swt_display)
264
- @paint_listener_proxy = @parent.on_swt_paint(&method(:paint))
265
- elsif parent.respond_to?(:swt_image)
266
- paint(parent) # treat parent as paint event since you don't do repaints with images, it's a one time deal.
267
- elsif parent.respond_to?(:swt_widget)
268
- @paint_listener_proxy = @parent.on_paint_control(&method(:paint))
269
- end
270
- end
271
-
272
- def paint(paint_event)
273
- @properties['background'] = [@parent.background] if fill? && !has_some_background?
274
- @properties['foreground'] = [@parent.foreground] if @parent.respond_to?(:foreground) && draw? && !has_some_foreground?
275
- @properties['font'] = [@parent.font] if @parent.respond_to?(:font) && draw? && !@properties.keys.map(&:to_s).include?('font')
276
- @properties['transform'] = [nil] if @parent.respond_to?(:transform) && !@properties.keys.map(&:to_s).include?('transform')
277
- @properties.each do |property, args|
278
- method_name = attribute_setter(property)
279
- converted_args = apply_property_arg_conversions(method_name, property, args)
280
- paint_event.gc.send(method_name, *converted_args)
281
- if property == 'transform' && args.first.is_a?(TransformProxy)
282
- args.first.swt_transform.dispose
283
- end
284
- end
285
- apply_shape_arg_conversions(@method_name, @args)
286
- apply_shape_arg_defaults(@method_name, @args)
287
- tolerate_shape_extra_args(@method_name, @args)
288
- paint_event.gc.send(@method_name, *@args)
289
- end
290
-
291
- end
292
-
293
- end
294
-
295
- end
296
-
297
- end
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/properties'
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
+ include Packages
36
+ include Properties
37
+ # TODO support textExtent sized shapes nested within text/string
38
+ # TODO support a Pattern DSL for methods that take Pattern arguments
39
+
40
+ class << self
41
+ def valid?(parent, keyword, *args, &block)
42
+ gc_instance_methods.include?(method_name(keyword, arg_options(args)))
43
+ end
44
+
45
+ def gc_instance_methods
46
+ @gc_instance_methods ||= org.eclipse.swt.graphics.GC.instance_methods.map(&:to_s)
47
+ end
48
+
49
+ def keywords
50
+ @keywords ||= gc_instance_methods.select do |method_name|
51
+ !method_name.end_with?('=') && (method_name.start_with?('draw_') || method_name.start_with?('fill_'))
52
+ end.reject do |method_name|
53
+ gc_instance_methods.include?("#{method_name}=") || gc_instance_methods.include?("set_#{method_name}")
54
+ end.map do |method_name|
55
+ method_name.gsub(/(draw|fill|gradient|round)_/, '')
56
+ end.uniq.compact.to_a
57
+ end
58
+
59
+ def arg_options(args, extract: false)
60
+ arg_options_method = extract ? :pop : :last
61
+ options = args.send(arg_options_method) if args.last.is_a?(Hash)
62
+ options.nil? ? {} : options.symbolize_keys
63
+ end
64
+
65
+ def method_name(keyword, method_arg_options)
66
+ keyword = keyword.to_s
67
+ method_arg_options = method_arg_options.select {|key, value| %w[fill gradient round].include?(key.to_s)}
68
+ unless flyweight_method_names.keys.include?([keyword, method_arg_options])
69
+ gradient = 'Gradient' if method_arg_options[:gradient]
70
+ round = 'Round' if method_arg_options[:round]
71
+ gc_instance_method_name_prefix = !['polyline', 'point', 'image', 'focus'].include?(keyword) && (method_arg_options[:fill] || method_arg_options[:gradient]) ? 'fill' : 'draw'
72
+ flyweight_method_names[[keyword, method_arg_options]] = "#{gc_instance_method_name_prefix}#{gradient}#{round}#{keyword.capitalize}"
73
+ end
74
+ flyweight_method_names[[keyword, method_arg_options]]
75
+ end
76
+
77
+ def flyweight_method_names
78
+ @flyweight_method_names ||= {}
79
+ end
80
+
81
+ def pattern(*args)
82
+ found_pattern = flyweigh_patterns[args]
83
+ if found_pattern.nil? || found_pattern.is_disposed
84
+ found_pattern = flyweigh_patterns[args] = org.eclipse.swt.graphics.Pattern.new(*args)
85
+ end
86
+ found_pattern
87
+ end
88
+
89
+ def flyweigh_patterns
90
+ @flyweigh_patterns ||= {}
91
+ end
92
+ end
93
+
94
+ attr_reader :parent, :name, :args, :options
95
+
96
+ def initialize(parent, keyword, *args, &property_block)
97
+ @parent = parent
98
+ @name = keyword
99
+ @options = self.class.arg_options(args, extract: true)
100
+ @method_name = self.class.method_name(keyword, @options)
101
+ @args = args
102
+ @properties = {}
103
+ @options.reject {|key, value| %w[fill gradient round].include?(key.to_s)}.each do |property, property_args|
104
+ @properties[property] = property_args
105
+ end
106
+ @parent.add_shape(self)
107
+ post_add_content if property_block.nil?
108
+ end
109
+
110
+ def draw?
111
+ !fill?
112
+ end
113
+
114
+ def fill?
115
+ @options[:fill]
116
+ end
117
+
118
+ def gradient?
119
+ @options[:gradient]
120
+ end
121
+
122
+ def round?
123
+ @options[:round]
124
+ end
125
+
126
+ def has_some_background?
127
+ @properties.keys.map(&:to_s).include?('background') || @properties.keys.map(&:to_s).include?('background_pattern')
128
+ end
129
+
130
+ def has_some_foreground?
131
+ @properties.keys.map(&:to_s).include?('foreground') || @properties.keys.map(&:to_s).include?('foreground_pattern')
132
+ end
133
+
134
+ def post_add_content
135
+ unless @content_added
136
+ amend_method_name_options_based_on_properties!
137
+ @parent.setup_shape_painting unless @parent.is_a?(ImageProxy)
138
+ @content_added = true
139
+ end
140
+ end
141
+
142
+ def apply_property_arg_conversions(method_name, property, args)
143
+ args = args.dup
144
+ the_java_method = org.eclipse.swt.graphics.GC.java_class.declared_instance_methods.detect {|m| m.name == method_name}
145
+ if ['setBackground', 'setForeground'].include?(method_name.to_s) && args.first.is_a?(Array)
146
+ args[0] = ColorProxy.new(args[0])
147
+ end
148
+ if args.first.is_a?(Symbol) || args.first.is_a?(String)
149
+ if the_java_method.parameter_types.first == Color.java_class
150
+ args[0] = ColorProxy.new(args[0])
151
+ end
152
+ if the_java_method.parameter_types.first == Java::int.java_class
153
+ args[0] = SWTProxy.constant(args[0])
154
+ end
155
+ end
156
+ if args.first.is_a?(ColorProxy)
157
+ args[0] = args[0].swt_color
158
+ end
159
+ if args.first.is_a?(Hash) && the_java_method.parameter_types.first == Font.java_class
160
+ args[0] = FontProxy.new(args[0])
161
+ end
162
+ if args.first.is_a?(FontProxy)
163
+ args[0] = args[0].swt_font
164
+ end
165
+ if args.first.is_a?(TransformProxy)
166
+ args[0] = args[0].swt_transform
167
+ end
168
+ if ['setBackgroundPattern', 'setForegroundPattern'].include?(method_name.to_s)
169
+ @parent.requires_shape_disposal = true
170
+ args.each_with_index do |arg, i|
171
+ if arg.is_a?(Symbol) || arg.is_a?(String)
172
+ args[i] = ColorProxy.new(arg).swt_color
173
+ elsif arg.is_a?(ColorProxy)
174
+ args[i] = arg.swt_color
175
+ end
176
+ end
177
+ new_args = [DisplayProxy.instance.swt_display] + args
178
+ args[0] = pattern(*new_args, type: method_name.to_s.match(/set(.+)Pattern/)[1])
179
+ args[1..-1] = []
180
+ end
181
+ args
182
+ end
183
+
184
+ def apply_shape_arg_conversions!
185
+ if @args.size > 1 && (['polygon', 'polyline'].include?(@name))
186
+ @args[0] = @args.dup
187
+ @args[1..-1] = []
188
+ end
189
+ end
190
+
191
+ def apply_shape_arg_defaults!
192
+ if @name.include?('rectangle') && round? && @args.size.between?(4, 5)
193
+ (6 - @args.size).times {@args << 60}
194
+ elsif @name.include?('rectangle') && gradient? && @args.size == 4
195
+ @args << true
196
+ elsif (@name.include?('text') || @name.include?('String')) && !@properties.keys.map(&:to_s).include?('background') && @args.size == 3
197
+ @args << true
198
+ end
199
+ if @name.include?('image')
200
+ @parent.requires_shape_disposal = true
201
+ if @args.size == 1
202
+ @args[1] = 0
203
+ @args[2] = 0
204
+ end
205
+ if @args.first.is_a?(String)
206
+ @args[0] = ImageProxy.new(@args[0])
207
+ end
208
+ if @args.first.is_a?(ImageProxy)
209
+ @image = @args[0] = @args[0].swt_image
210
+ end
211
+ end
212
+ end
213
+
214
+ # Tolerates shape extra args added by user by mistake
215
+ # (e.g. happens when switching from round rectangle to a standard one without removing all extra args)
216
+ def tolerate_shape_extra_args!
217
+ the_java_method_arg_count = org.eclipse.swt.graphics.GC.java_class.declared_instance_methods.select do |m|
218
+ m.name == @method_name.camelcase(:lower)
219
+ end.map(&:parameter_types).map(&:size).max
220
+ if @args.size > the_java_method_arg_count
221
+ @args[the_java_method_arg_count..-1] = []
222
+ end
223
+ end
224
+
225
+ def amend_method_name_options_based_on_properties!
226
+ return if @name == 'point'
227
+ if has_some_background? && !has_some_foreground?
228
+ @options[:fill] = true
229
+ elsif !has_some_background? && has_some_foreground?
230
+ @options[:fill] = false
231
+ elsif @name == 'rectangle' && has_some_background? && has_some_foreground?
232
+ @options[:fill] = true
233
+ @options[:gradient] = true
234
+ end
235
+ if @name == 'rectangle' && @args.size > 4 && @args.last.is_a?(Numeric)
236
+ @options[:round] = true
237
+ end
238
+ @method_name = self.class.method_name(@name, @options)
239
+ end
240
+
241
+ def has_attribute?(attribute_name, *args)
242
+ self.class.gc_instance_methods.include?(attribute_setter(attribute_name))
243
+ end
244
+
245
+ def set_attribute(attribute_name, *args)
246
+ @properties[attribute_name] = args
247
+ if @content_added && !@parent.is_disposed
248
+ @calculated_paint_args = false
249
+ @parent.redraw
250
+ end
251
+ end
252
+
253
+ def get_attribute(attribute_name)
254
+ @properties.symbolize_keys[attribute_name.to_s.to_sym]
255
+ end
256
+
257
+ def pattern(*args, type: nil)
258
+ instance_variable_name = "@#{type}_pattern"
259
+ the_pattern = instance_variable_get(instance_variable_name)
260
+ if the_pattern.nil?
261
+ the_pattern = self.class.pattern(*args)
262
+ end
263
+ the_pattern
264
+ end
265
+
266
+ def dispose(dispose_images: true, dispose_patterns: true)
267
+ if dispose_patterns
268
+ @background_pattern&.dispose
269
+ @background_pattern = nil
270
+ @foreground_pattern&.dispose
271
+ @foreground_pattern = nil
272
+ end
273
+ if dispose_images
274
+ @image&.dispose
275
+ @image = nil
276
+ end
277
+ @parent.shapes.delete(self)
278
+ end
279
+
280
+ def paint(paint_event)
281
+ calculate_paint_args!
282
+ @properties.each do |property, args|
283
+ method_name = attribute_setter(property)
284
+ # TODO consider optimization of not setting a background/foreground/font if it didn't change from last shape
285
+ paint_event.gc.send(method_name, *args)
286
+ if property == 'transform' && args.first.is_a?(TransformProxy)
287
+ args.first.swt_transform.dispose
288
+ end
289
+ end
290
+ paint_event.gc.send(@method_name, *@args)
291
+ end
292
+
293
+ def calculate_paint_args!
294
+ unless @calculated_paint_args
295
+ if @name == 'point'
296
+ # optimized performance calculation for pixel points
297
+ if !@properties[:foreground].is_a?(Color)
298
+ if @properties[:foreground].is_a?(Array)
299
+ @properties[:foreground] = ColorProxy.new(@properties[:foreground], ensure_bounds: false)
300
+ end
301
+ if @properties[:foreground].is_a?(Symbol) || @properties[:foreground].is_a?(String)
302
+ @properties[:foreground] = ColorProxy.new(@properties[:foreground], ensure_bounds: false)
303
+ end
304
+ if @properties[:foreground].is_a?(ColorProxy)
305
+ @properties[:foreground] = @properties[:foreground].swt_color
306
+ end
307
+ end
308
+ else
309
+ @properties['background'] = [@parent.background] if fill? && !has_some_background?
310
+ @properties['foreground'] = [@parent.foreground] if @parent.respond_to?(:foreground) && draw? && !has_some_foreground?
311
+ @properties['font'] = [@parent.font] if @parent.respond_to?(:font) && draw? && !@properties.keys.map(&:to_s).include?('font')
312
+ @properties['transform'] = [nil] if @parent.respond_to?(:transform) && !@properties.keys.map(&:to_s).include?('transform')
313
+ @properties.each do |property, args|
314
+ method_name = attribute_setter(property)
315
+ converted_args = apply_property_arg_conversions(method_name, property, args)
316
+ @properties[property] = converted_args
317
+ end
318
+ apply_shape_arg_conversions!
319
+ apply_shape_arg_defaults!
320
+ tolerate_shape_extra_args!
321
+ @calculated_paint_args = true
322
+ end
323
+ end
324
+ end
325
+
326
+ end
327
+
328
+ end
329
+
330
+ end
331
+
332
+ end