glimmer-dsl-opal 0.26.2 → 0.28.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ # Copyright (c) 2020-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/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Oval < Shape
33
+
34
+ def element
35
+ 'ellipse'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ x = @args[0]
42
+ y = @args[1]
43
+ width = @args[2]
44
+ height = @args[3]
45
+ rx = width / 2.0
46
+ ry = height / 2.0
47
+ cx = x + rx
48
+ cy = y + ry
49
+ @dom ||= xml {
50
+ ellipse(id: shape_id, class: shape_class, cx: cx, cy: cy, rx: rx, ry: ry)
51
+ }.to_s
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2020-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/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Point < Shape
33
+
34
+ def element
35
+ 'rect'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ rect(id: shape_id, class: shape_class, x: @args[0], y: @args[1], width: 1, height: 1)
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2020-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/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Polygon < Shape
33
+
34
+ def element
35
+ 'polygon'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ polygon(id: shape_id, class: shape_class, points: @args.map(&:to_s).join(' '))
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2020-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/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Polyline < Shape
33
+
34
+ def element
35
+ 'polyline'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ polyline(id: shape_id, class: shape_class, points: @args.map(&:to_s).join(' '))
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2020-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/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Rectangle < Shape
33
+
34
+ def element
35
+ 'rect'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ rect(id: shape_id, class: shape_class, x: @args[0], y: @args[1], width: @args[2], height: @args[3], rx: @args[4].to_f/2.0, ry: @args[5].to_f/2.0)
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,64 @@
1
+ # Copyright (c) 2020-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/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Text < Shape
33
+
34
+ def background=(value)
35
+ # TODO override background= to fill a rectangle containing text, matching its size
36
+ # For now, disable background when foreground is not set
37
+ super(value) unless foreground.nil?
38
+ end
39
+
40
+ def foreground=(value)
41
+ super(value)
42
+ self.background = value
43
+ end
44
+
45
+ def element
46
+ 'text'
47
+ end
48
+
49
+ def dom
50
+ shape_id = id
51
+ shape_class = name
52
+ @dom ||= xml {
53
+ tag(:_name => 'text', id: shape_id, class: shape_class, x: @args[1], y: @args[2]) {
54
+ @args[0]
55
+ }
56
+ }.to_s
57
+ end
58
+
59
+ end
60
+ String = Text
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,110 @@
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/property_owner'
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
+ require 'glimmer/swt/point'
29
+ require 'glimmer/swt/rectangle'
30
+
31
+ module Glimmer
32
+ module SWT
33
+ module Custom
34
+ # Represents a shape (graphics) to be drawn on a control/widget/canvas/display
35
+ # That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
36
+ class Shape < WidgetProxy
37
+ include PropertyOwner
38
+
39
+ class << self
40
+ def create(parent, keyword, args, &property_block)
41
+ potential_shape_class_name = keyword.to_s.camelcase(:upper).to_sym
42
+ if constants.include?(potential_shape_class_name)
43
+ const_get(potential_shape_class_name).new(parent, args, &property_block)
44
+ else
45
+ new(parent, args, &property_block)
46
+ end
47
+ end
48
+
49
+ def valid?(parent, keyword, args, &block)
50
+ return true if keyword.to_s == 'shape'
51
+ keywords.include?(keyword.to_s)
52
+ end
53
+
54
+ def keywords
55
+ constants.select do |constant|
56
+ constant_value = const_get(constant)
57
+ constant_value.respond_to?(:ancestors) && constant_value.ancestors.include?(Glimmer::SWT::Custom::Shape)
58
+ end.map {|constant| constant.to_s.underscore}
59
+ end
60
+
61
+ end
62
+
63
+ def background=(value)
64
+ value = ColorProxy.new(value) if value.is_a?(String)
65
+ @background = value
66
+ dom_element.css('fill', background.to_css) unless background.nil?
67
+ end
68
+
69
+ def foreground=(value)
70
+ value = ColorProxy.new(value) if value.is_a?(String)
71
+ @foreground = value
72
+ dom_element.css('stroke', foreground.to_css) unless foreground.nil?
73
+ dom_element.css('fill', 'transparent') if background.nil?
74
+ end
75
+
76
+ def attach(the_parent_dom_element)
77
+ the_parent_dom_element.html("#{the_parent_dom_element.html()}\n#{@dom}")
78
+ end
79
+
80
+ def element
81
+ 'g'
82
+ end
83
+
84
+ def dom
85
+ shape_id = id
86
+ shape_class = name
87
+ @dom ||= xml {
88
+ g(id: shape_id, class: shape_class) {
89
+ }
90
+ }.to_s
91
+ end
92
+
93
+ # TODO implement shape_at_location potentially with document.elementFromPoint(x, y);
94
+
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ end
102
+
103
+ require 'glimmer/swt/custom/shape/arc'
104
+ require 'glimmer/swt/custom/shape/line'
105
+ require 'glimmer/swt/custom/shape/oval'
106
+ require 'glimmer/swt/custom/shape/point'
107
+ require 'glimmer/swt/custom/shape/polygon'
108
+ require 'glimmer/swt/custom/shape/polyline'
109
+ require 'glimmer/swt/custom/shape/rectangle'
110
+ require 'glimmer/swt/custom/shape/text'
@@ -136,43 +136,6 @@ module Glimmer
136
136
  }
137
137
  },
138
138
  ],
139
- 'on_key_pressed' => {
140
- event: 'keydown',
141
- event_handler: -> (event_listener) {
142
- -> (event) {
143
- # TODO generalize this solution to all widgets that support key presses
144
- # TODO support event.location once DOM3 is supported by opal-jquery
145
- event.define_singleton_method(:keyCode) {event.which}
146
- event.define_singleton_method(:key_code, &event.method(:keyCode))
147
- event.define_singleton_method(:character) {event.which.chr}
148
- event.define_singleton_method(:stateMask) do
149
- state_mask = 0
150
- state_mask |= SWTProxy[:alt] if event.alt_key
151
- state_mask |= SWTProxy[:ctrl] if event.ctrl_key
152
- state_mask |= SWTProxy[:shift] if event.shift_key
153
- state_mask |= SWTProxy[:command] if event.meta_key
154
- state_mask
155
- end
156
- event.define_singleton_method(:state_mask, &event.method(:stateMask))
157
- doit = true
158
- event.define_singleton_method(:doit=) do |value|
159
- doit = value
160
- end
161
- event.define_singleton_method(:doit) { doit }
162
- event_listener.call(event)
163
-
164
- # TODO Fix doit false, it's not stopping input
165
- unless doit
166
- event.prevent
167
- event.prevent_default
168
- event.stop_propagation
169
- event.stop_immediate_propagation
170
- end
171
-
172
- doit
173
- }
174
- }
175
- },
176
139
  }
177
140
  end
178
141