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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -0
- data/LICENSE.txt +20 -20
- data/README.md +43 -5058
- data/RUBY_VERSION +1 -1
- data/VERSION +1 -1
- data/bin/girb +31 -31
- data/bin/girb_runner.rb +34 -34
- data/bin/glimmer +26 -26
- data/docs/reference/GLIMMER_COMMAND.md +591 -0
- data/docs/reference/GLIMMER_CONFIGURATION.md +183 -0
- data/docs/reference/GLIMMER_GIRB.md +30 -0
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +3367 -0
- data/docs/reference/GLIMMER_PACKAGING_AND_DISTRIBUTION.md +202 -0
- data/docs/reference/GLIMMER_SAMPLES.md +755 -0
- data/docs/reference/GLIMMER_STYLE_GUIDE.md +14 -0
- data/glimmer-dsl-swt.gemspec +22 -7
- data/lib/ext/glimmer.rb +41 -41
- data/lib/ext/glimmer/config.rb +167 -167
- data/lib/ext/rouge/themes/glimmer.rb +29 -29
- data/lib/glimmer-dsl-swt.rb +44 -44
- data/lib/glimmer/Rakefile +26 -26
- data/lib/glimmer/data_binding/list_selection_binding.rb +72 -72
- data/lib/glimmer/data_binding/observable_widget.rb +38 -38
- data/lib/glimmer/data_binding/shine.rb +44 -44
- data/lib/glimmer/data_binding/table_items_binding.rb +89 -89
- data/lib/glimmer/data_binding/tree_items_binding.rb +108 -108
- data/lib/glimmer/data_binding/widget_binding.rb +73 -73
- data/lib/glimmer/dsl/swt/animation_expression.rb +43 -43
- data/lib/glimmer/dsl/swt/async_exec_expression.rb +35 -35
- data/lib/glimmer/dsl/swt/bind_expression.rb +58 -58
- data/lib/glimmer/dsl/swt/block_property_expression.rb +41 -41
- data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +61 -61
- data/lib/glimmer/dsl/swt/color_expression.rb +40 -40
- data/lib/glimmer/dsl/swt/column_properties_expression.rb +45 -45
- data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +67 -67
- data/lib/glimmer/dsl/swt/cursor_expression.rb +44 -44
- data/lib/glimmer/dsl/swt/custom_widget_expression.rb +63 -63
- data/lib/glimmer/dsl/swt/data_binding_expression.rb +55 -55
- data/lib/glimmer/dsl/swt/dialog_expression.rb +48 -48
- data/lib/glimmer/dsl/swt/directory_dialog_expression.rb +48 -48
- data/lib/glimmer/dsl/swt/display_expression.rb +40 -40
- data/lib/glimmer/dsl/swt/dnd_expression.rb +46 -46
- data/lib/glimmer/dsl/swt/dsl.rb +63 -63
- data/lib/glimmer/dsl/swt/exec_expression.rb +55 -55
- data/lib/glimmer/dsl/swt/expand_item_expression.rb +60 -60
- data/lib/glimmer/dsl/swt/file_dialog_expression.rb +48 -48
- data/lib/glimmer/dsl/swt/font_expression.rb +49 -49
- data/lib/glimmer/dsl/swt/image_expression.rb +54 -50
- data/lib/glimmer/dsl/swt/layout_data_expression.rb +46 -46
- data/lib/glimmer/dsl/swt/layout_expression.rb +50 -50
- data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +65 -65
- data/lib/glimmer/dsl/swt/menu_bar_expression.rb +54 -54
- data/lib/glimmer/dsl/swt/menu_expression.rb +53 -53
- data/lib/glimmer/dsl/swt/message_box_expression.rb +54 -54
- data/lib/glimmer/dsl/swt/multiply_expression.rb +53 -53
- data/lib/glimmer/dsl/swt/observe_expression.rb +56 -53
- data/lib/glimmer/dsl/swt/pixel_expression.rb +38 -0
- data/lib/glimmer/dsl/swt/property_expression.rb +46 -46
- data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +62 -61
- data/lib/glimmer/dsl/swt/rgb_expression.rb +33 -33
- data/lib/glimmer/dsl/swt/rgba_expression.rb +33 -33
- data/lib/glimmer/dsl/swt/shape_expression.rb +54 -54
- data/lib/glimmer/dsl/swt/shell_expression.rb +46 -46
- data/lib/glimmer/dsl/swt/swt_expression.rb +46 -46
- data/lib/glimmer/dsl/swt/sync_exec_expression.rb +36 -36
- data/lib/glimmer/dsl/swt/tab_item_expression.rb +54 -54
- data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +52 -52
- data/lib/glimmer/dsl/swt/transform_expression.rb +55 -55
- data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +52 -52
- data/lib/glimmer/dsl/swt/tree_properties_expression.rb +47 -47
- data/lib/glimmer/dsl/swt/widget_expression.rb +67 -66
- data/lib/glimmer/dsl/swt/widget_listener_expression.rb +53 -53
- data/lib/glimmer/rake_task.rb +220 -220
- data/lib/glimmer/rake_task/list.rb +97 -97
- data/lib/glimmer/rake_task/package.rb +139 -139
- data/lib/glimmer/rake_task/scaffold.rb +765 -765
- data/lib/glimmer/swt/color_proxy.rb +108 -107
- data/lib/glimmer/swt/cursor_proxy.rb +66 -66
- data/lib/glimmer/swt/custom/animation.rb +245 -243
- data/lib/glimmer/swt/custom/checkbox_group.rb +181 -181
- data/lib/glimmer/swt/custom/code_text.rb +1 -0
- data/lib/glimmer/swt/custom/drawable.rb +97 -49
- data/lib/glimmer/swt/custom/radio_group.rb +177 -176
- data/lib/glimmer/swt/custom/shape.rb +332 -297
- data/lib/glimmer/swt/date_time_proxy.rb +85 -85
- data/lib/glimmer/swt/directory_dialog_proxy.rb +65 -65
- data/lib/glimmer/swt/display_proxy.rb +167 -166
- data/lib/glimmer/swt/dnd_proxy.rb +51 -51
- data/lib/glimmer/swt/expand_item_proxy.rb +97 -97
- data/lib/glimmer/swt/file_dialog_proxy.rb +66 -66
- data/lib/glimmer/swt/font_proxy.rb +94 -94
- data/lib/glimmer/swt/image_proxy.rb +195 -184
- data/lib/glimmer/swt/layout_data_proxy.rb +105 -105
- data/lib/glimmer/swt/layout_proxy.rb +112 -112
- data/lib/glimmer/swt/menu_proxy.rb +126 -126
- data/lib/glimmer/swt/message_box_proxy.rb +89 -89
- data/lib/glimmer/swt/packages.rb +37 -37
- data/lib/glimmer/swt/properties.rb +74 -49
- data/lib/glimmer/swt/sash_form_proxy.rb +53 -53
- data/lib/glimmer/swt/scrolled_composite_proxy.rb +46 -37
- data/lib/glimmer/swt/style_constantizable.rb +157 -157
- data/lib/glimmer/swt/styled_text_proxy.rb +38 -38
- data/lib/glimmer/swt/swt_proxy.rb +59 -59
- data/lib/glimmer/swt/tab_item_proxy.rb +92 -91
- data/lib/glimmer/swt/table_column_proxy.rb +57 -57
- data/lib/glimmer/swt/transform_proxy.rb +109 -109
- data/lib/glimmer/swt/tree_proxy.rb +145 -145
- data/lib/glimmer/swt/widget_listener_proxy.rb +64 -64
- data/lib/glimmer/swt/widget_proxy.rb +977 -957
- data/lib/glimmer/ui/custom_shell.rb +82 -82
- data/lib/glimmer/ui/custom_widget.rb +332 -315
- data/lib/glimmer/util/proc_tracker.rb +39 -39
- data/samples/elaborate/contact_manager.rb +142 -142
- data/samples/elaborate/contact_manager/contact.rb +32 -32
- data/samples/elaborate/contact_manager/contact_manager_presenter.rb +47 -47
- data/samples/elaborate/contact_manager/contact_repository.rb +169 -169
- data/samples/elaborate/login.rb +123 -123
- data/samples/elaborate/mandelbrot_fractal.rb +354 -0
- data/samples/elaborate/tetris.rb +5 -18
- data/samples/elaborate/tetris/model/block.rb +48 -48
- data/samples/elaborate/tetris/model/past_game.rb +39 -39
- data/samples/elaborate/tetris/view/block.rb +1 -1
- data/samples/elaborate/tetris/view/playfield.rb +1 -1
- data/samples/elaborate/tic_tac_toe.rb +76 -76
- data/samples/elaborate/tic_tac_toe/board.rb +145 -145
- data/samples/elaborate/tic_tac_toe/cell.rb +48 -48
- data/samples/elaborate/user_profile.rb +76 -76
- data/samples/hello/hello_browser.rb +31 -31
- data/samples/hello/hello_button.rb +46 -46
- data/samples/hello/hello_canvas.rb +64 -64
- data/samples/hello/hello_canvas_animation.rb +1 -1
- data/samples/hello/hello_checkbox.rb +85 -85
- data/samples/hello/hello_checkbox_group.rb +71 -71
- data/samples/hello/hello_code_text.rb +104 -104
- data/samples/hello/hello_combo.rb +63 -63
- data/samples/hello/hello_computed.rb +96 -96
- data/samples/hello/hello_computed/contact.rb +42 -42
- data/samples/hello/hello_cursor.rb +57 -0
- data/samples/hello/hello_custom_shell.rb +155 -155
- data/samples/hello/hello_custom_widget.rb +86 -86
- data/samples/hello/hello_date_time.rb +63 -63
- data/samples/hello/hello_dialog.rb +78 -78
- data/samples/hello/hello_directory_dialog.rb +60 -60
- data/samples/hello/hello_drag_and_drop.rb +50 -50
- data/samples/hello/hello_expand_bar.rb +110 -110
- data/samples/hello/hello_file_dialog.rb +60 -60
- data/samples/hello/hello_group.rb +104 -104
- data/samples/hello/hello_link.rb +80 -80
- data/samples/hello/hello_list_multi_selection.rb +74 -74
- data/samples/hello/hello_list_single_selection.rb +59 -59
- data/samples/hello/hello_menu_bar.rb +241 -241
- data/samples/hello/hello_message_box.rb +37 -37
- data/samples/hello/hello_pop_up_context_menu.rb +84 -84
- data/samples/hello/hello_radio.rb +108 -108
- data/samples/hello/hello_radio_group.rb +87 -87
- data/samples/hello/hello_sash_form.rb +137 -137
- data/samples/hello/hello_spinner.rb +69 -69
- data/samples/hello/hello_styled_text.rb +138 -138
- data/samples/hello/hello_tab.rb +50 -50
- data/samples/hello/hello_table.rb +1 -1
- data/samples/hello/hello_table/baseball_park.png +0 -0
- data/samples/hello/hello_world.rb +29 -29
- 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)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
@
|
142
|
-
@
|
143
|
-
@
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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,
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
gradient = '
|
70
|
-
round = '
|
71
|
-
gc_instance_method_name_prefix = !['polyline', 'point', 'image', 'focus'].include?(keyword) && (method_arg_options[:fill] || method_arg_options[:gradient]) ? '
|
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
|
95
|
-
|
96
|
-
def initialize(parent, keyword, *args, &property_block)
|
97
|
-
@parent = parent
|
98
|
-
@name = keyword
|
99
|
-
@
|
100
|
-
@
|
101
|
-
@args = args
|
102
|
-
@properties = {}
|
103
|
-
@
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
148
|
-
if args.first.is_a?(
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
args
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
args[
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
args
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
args
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
@
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
@
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
@
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
@
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
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
|