glimmer-dsl-swt 4.18.4.7 → 4.18.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +3 -3
- data/VERSION +1 -1
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +117 -27
- data/glimmer-dsl-swt.gemspec +2 -2
- data/lib/glimmer/dsl/swt/image_expression.rb +3 -0
- data/lib/glimmer/swt/color_proxy.rb +4 -3
- data/lib/glimmer/swt/custom/animation.rb +1 -0
- data/lib/glimmer/swt/custom/drawable.rb +35 -3
- data/lib/glimmer/swt/custom/shape.rb +47 -21
- data/lib/glimmer/swt/image_proxy.rb +17 -6
- data/lib/glimmer/swt/widget_proxy.rb +1 -0
- data/samples/elaborate/mandelbrot_fractal.rb +1 -1
- data/samples/hello/hello_table.rb +1 -1
- data/samples/hello/hello_table/baseball_park.png +0 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89ea3be1af753358a8beaffbf28c8dfd6602eae3903b01a884e6999f0dbf6cfb
|
4
|
+
data.tar.gz: 672422abf1637420ac51706373824ac821682eab77afe86b91e22b21f1e00eb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b502b353aa06f6b26e39487859ae8f4d9f8ee47d74a4a97a224b14dfa8b18acba6d8e48b6a66ee518a8075cd90a6303f1864726a22812edf98515f6a2754aa2
|
7
|
+
data.tar.gz: a5926f825b0247d4b521bfa2f857d1b1f88d731dba9651690960cf7c516ef2a1c5aca9c6cce86878162358fb416a0913b3ba945b0589be19f78f94454848d0b5
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
### 4.18.4.8
|
4
|
+
|
5
|
+
- Make `image` a top-level expression keyword
|
6
|
+
- Default placing image on Canvas at coordinates 0, 0 if they are not specified (e.g. canvas {image some_image})
|
7
|
+
- Support passing in color args directly to the `pixel` keyword as an rgb value array without using the `color`/`rgb` keyword, to improve performance for large pixel counts
|
8
|
+
- Support Image Double Buffering by nesting an `image` built from shapes within a `canvas`
|
9
|
+
- Shrink image of baseball background for Hello, Table! Sample to reduce the glimmer-dsl-swt gem size (recently bloated)
|
10
|
+
- Fix issue with closing a canvas shell with pixel graphics freezing temporarily for a long time while disposing shapes
|
11
|
+
- Fix issue with disposing `image` having shapes
|
12
|
+
|
3
13
|
### 4.18.4.7
|
4
14
|
|
5
15
|
- Fixed issue with Tetris breaking with the latest Canvas Shape/Animation DSL performance optimizations
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.18.4.
|
1
|
+
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.18.4.8
|
2
2
|
## JRuby Desktop Development GUI Framework
|
3
3
|
[](http://badge.fury.io/rb/glimmer-dsl-swt)
|
4
4
|
[](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
|
@@ -342,7 +342,7 @@ jgem install glimmer-dsl-swt
|
|
342
342
|
|
343
343
|
Or this command if you want a specific version:
|
344
344
|
```
|
345
|
-
jgem install glimmer-dsl-swt -v 4.18.4.
|
345
|
+
jgem install glimmer-dsl-swt -v 4.18.4.8
|
346
346
|
```
|
347
347
|
|
348
348
|
`jgem` is JRuby's version of `gem` command.
|
@@ -360,7 +360,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
|
|
360
360
|
|
361
361
|
Add the following to `Gemfile`:
|
362
362
|
```
|
363
|
-
gem 'glimmer-dsl-swt', '~> 4.18.4.
|
363
|
+
gem 'glimmer-dsl-swt', '~> 4.18.4.8'
|
364
364
|
```
|
365
365
|
|
366
366
|
And, then run:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.18.4.
|
1
|
+
4.18.4.8
|
@@ -1289,7 +1289,7 @@ This is accomplished via the Shape DSL a sub-DSL of the Glimmer GUI DSL, which m
|
|
1289
1289
|
Shape keywords and their args (including defaults) are listed below (they basically match method names and arguments on [org.eclipse.swt.graphics.GC](https://help.eclipse.org/2020-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/graphics/GC.html) minus the `draw` or `fill` prefix in downcase):
|
1290
1290
|
- `arc(x, y, width, height, startAngle, arcAngle, fill: false)` arc is part of a circle within an oval area, denoted by start angle (degrees) and end angle (degrees)
|
1291
1291
|
- `focus(x, y, width, height)` this is just like rectangle but its foreground color is always that of the OS widget focus color (useful when capturing user interaction via a shape)
|
1292
|
-
- `image(image, x, y)` [image](#image)
|
1292
|
+
- `image(image, x = 0, y = 0)` sets [image](#image), which could be an [org.eclipse.swt.graphics.Image](https://help.eclipse.org/2020-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/graphics/Image.html) object or just a file path string
|
1293
1293
|
- `line(x1, y1, x2, y2)` line
|
1294
1294
|
- `oval(x, y, width, height, fill: false)` oval if width does not match heigh and circle if width matches height. Can be optionally filled.
|
1295
1295
|
- `point(x, y)` point
|
@@ -1369,37 +1369,15 @@ Screenshot:
|
|
1369
1369
|
|
1370
1370
|
Learn more at the [Hello, Canvas! Sample](#hello-canvas).
|
1371
1371
|
|
1372
|
-
|
1373
|
-
|
1374
|
-
**(Early Alpha Feature)**
|
1372
|
+
If you ever have special needs or optimizations, you could always default to direct SWT painting via [org.eclipse.swt.graphics.GC](https://help.eclipse.org/2020-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/graphics/GC.html) instead. Learn more at the [SWT Graphics Guide](https://www.eclipse.org/articles/Article-SWT-graphics/SWT_graphics.html) and [SWT Image Guide](https://www.eclipse.org/articles/Article-SWT-images/graphics-resources.html#Saving%20Images).
|
1375
1373
|
|
1376
|
-
|
1377
|
-
|
1378
|
-
Example (you may copy/paste in [`girb`](GLIMMER_GIRB.md)):
|
1374
|
+
Example of manually doing the same things as in the previous example without relying on the declarative Glimmer Shape DSL (you may copy/paste in [`girb`](GLIMMER_GIRB.md)):
|
1379
1375
|
|
1380
1376
|
```ruby
|
1381
|
-
|
1382
|
-
minimum_size 250, 265
|
1383
|
-
|
1384
|
-
canvas {
|
1385
|
-
250.times {|y|
|
1386
|
-
250.times {|x|
|
1387
|
-
pixel(x, y, foreground: color(y%255, x%255, (x+y)%255).swt_color)
|
1388
|
-
}
|
1389
|
-
}
|
1390
|
-
}
|
1391
|
-
}.open
|
1392
|
-
```
|
1393
|
-
|
1394
|
-
Remember that you could always default to direct [SWT GC Usage]([org.eclipse.swt.graphics.GC](https://help.eclipse.org/2020-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/graphics/GC.html) too for even faster performance (when rarely needed). Learn more at the [SWT Graphics Guide](https://www.eclipse.org/articles/Article-SWT-graphics/SWT_graphics.html) and [SWT Image Guide](https://www.eclipse.org/articles/Article-SWT-images/graphics-resources.html#Saving%20Images).
|
1395
|
-
|
1396
|
-
Example of manually doing the same things as in the Canvas Shape DSL example without relying on the declarative Glimmer Shape DSL:
|
1377
|
+
include Glimmer
|
1397
1378
|
|
1398
|
-
```ruby
|
1399
1379
|
image_object = image(File.expand_path('./icons/scaffold_app.png'), width: 100)
|
1400
1380
|
|
1401
|
-
include Glimmer
|
1402
|
-
|
1403
1381
|
shell {
|
1404
1382
|
text 'Canvas Manual Example'
|
1405
1383
|
minimum_size 320, 400
|
@@ -1431,6 +1409,118 @@ shell {
|
|
1431
1409
|
}.open
|
1432
1410
|
```
|
1433
1411
|
|
1412
|
+
#### Pixel Graphics
|
1413
|
+
|
1414
|
+
**(Early Alpha Feature)**
|
1415
|
+
|
1416
|
+
If you need to paint pixel graphics, use the optimized `pixel` keyword alternative to `point`, which takes foreground as a hash argument and bypasses the [Glimmer DSL Engine chain of responsibility](https://github.com/AndyObtiva/glimmer#dsl-engine), thus rendering faster when having very large pixel counts.
|
1417
|
+
|
1418
|
+
Example (you may copy/paste in [`girb`](GLIMMER_GIRB.md)):
|
1419
|
+
|
1420
|
+
```ruby
|
1421
|
+
include Glimmer
|
1422
|
+
|
1423
|
+
shell {
|
1424
|
+
minimum_size 250, 265
|
1425
|
+
text 'Pixel Graphics Example'
|
1426
|
+
|
1427
|
+
canvas {
|
1428
|
+
250.times {|y|
|
1429
|
+
250.times {|x|
|
1430
|
+
pixel(x, y, foreground: [y%255, x%255, (x+y)%255])
|
1431
|
+
}
|
1432
|
+
}
|
1433
|
+
}
|
1434
|
+
}.open
|
1435
|
+
```
|
1436
|
+
|
1437
|
+
Result:
|
1438
|
+
|
1439
|
+

|
1440
|
+
|
1441
|
+
Remember that you could always default to direct SWT painting via [org.eclipse.swt.graphics.GC](https://help.eclipse.org/2020-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/graphics/GC.html) too for even faster performance when needed in rare circumstances. Learn more at the [SWT Graphics Guide](https://www.eclipse.org/articles/Article-SWT-graphics/SWT_graphics.html) and [SWT Image Guide](https://www.eclipse.org/articles/Article-SWT-images/graphics-resources.html#Saving%20Images).
|
1442
|
+
|
1443
|
+
Example of manually doing the same things as in the previous example without relying on the declarative Glimmer Shape DSL (you may copy/paste in [`girb`](GLIMMER_GIRB.md)):
|
1444
|
+
|
1445
|
+
```ruby
|
1446
|
+
include Glimmer
|
1447
|
+
|
1448
|
+
shell {
|
1449
|
+
minimum_size 250, 265
|
1450
|
+
text 'Pixel Graphics Example'
|
1451
|
+
|
1452
|
+
canvas {
|
1453
|
+
on_paint_control { |paint_event|
|
1454
|
+
gc = paint_event.gc
|
1455
|
+
250.times {|y|
|
1456
|
+
250.times {|x|
|
1457
|
+
gc.foreground = Color.new(y%255, x%255, (x+y)%255)
|
1458
|
+
gc.draw_point(x, y)
|
1459
|
+
}
|
1460
|
+
}
|
1461
|
+
}
|
1462
|
+
}
|
1463
|
+
}.open
|
1464
|
+
```
|
1465
|
+
|
1466
|
+
The only downside with the approach above is that it repaints all pixels on repaints to the window (e.g. during window resize). To get around that, we can rely on a technique called **Image Double-Buffering**. That is to buffer the graphics on an Image first and then set it on the Canvas so that resizes of the shell dont cause a repaint of all the pixels. Additionally, this gives us the added benefit of being able to use the image as a Shell icon via its `image` property.
|
1467
|
+
|
1468
|
+
Example (you may copy/paste in [`girb`](GLIMMER_GIRB.md)):
|
1469
|
+
|
1470
|
+
```ruby
|
1471
|
+
include Glimmer
|
1472
|
+
|
1473
|
+
@the_image = image(250, 250)
|
1474
|
+
gc = org.eclipse.swt.graphics.GC.new(@the_image)
|
1475
|
+
250.times {|y|
|
1476
|
+
250.times {|x|
|
1477
|
+
gc.foreground = Color.new(y%255, x%255, (x+y)%255)
|
1478
|
+
gc.draw_point(x, y)
|
1479
|
+
}
|
1480
|
+
}
|
1481
|
+
|
1482
|
+
shell {
|
1483
|
+
minimum_size 250, 265
|
1484
|
+
text 'Pixel Graphics Example'
|
1485
|
+
image @the_image
|
1486
|
+
|
1487
|
+
canvas {
|
1488
|
+
image @the_image
|
1489
|
+
}
|
1490
|
+
}.open
|
1491
|
+
```
|
1492
|
+
|
1493
|
+
If you need a transparent background for the image, replace the image construction line with the following:
|
1494
|
+
|
1495
|
+
```ruby
|
1496
|
+
@the_image = image(250, 250)
|
1497
|
+
@the_image.image_data.alpha = 0
|
1498
|
+
@the_image = image(@the_image.image_data)
|
1499
|
+
```
|
1500
|
+
|
1501
|
+
That way, wherever you don't draw a point, you get transparency (seeing what is behind the image).
|
1502
|
+
|
1503
|
+
If you don't need a `shell` image icon and `pixel` performance is enough, you can automatically apply **Image Double-Buffering** with the `:image_double_buffered` SWT style (custom Glimmer style not available in SWT itself)
|
1504
|
+
|
1505
|
+
Example (you may copy/paste in [`girb`](GLIMMER_GIRB.md)):
|
1506
|
+
|
1507
|
+
```ruby
|
1508
|
+
include Glimmer
|
1509
|
+
|
1510
|
+
shell {
|
1511
|
+
minimum_size 250, 265
|
1512
|
+
text 'Pixel Graphics Example'
|
1513
|
+
|
1514
|
+
canvas(:image_double_buffered) {
|
1515
|
+
250.times {|y|
|
1516
|
+
250.times {|x|
|
1517
|
+
pixel(x, y, foreground: [y%255, x%255, (x+y)%255])
|
1518
|
+
}
|
1519
|
+
}
|
1520
|
+
}
|
1521
|
+
}.open
|
1522
|
+
```
|
1523
|
+
|
1434
1524
|
#### Shapes inside a Widget
|
1435
1525
|
|
1436
1526
|
Keep in mind that the Shape DSL can be used inside any widget, not just `canvas`. Unlike shapes on a `canvas`, which are standalone graphics, when included in a widget, which already has its own look and feel, shapes are used as a decorative add-on that complements its look by getting painted on top of it. For example, shapes were used to decorate `composite` blocks in the [Tetris](#tetris) sample to have a more bevel look. In summary, Shapes can be used in a hybrid approach (shapes inside a widget), not just standalone in a `canvas`.
|
@@ -1597,7 +1687,7 @@ shell {
|
|
1597
1687
|
|
1598
1688
|
#### Top-Level Transform Fluent Interface
|
1599
1689
|
|
1600
|
-
When using a transform at the top-level (outside of shell), you get a fluent interface to faciliate manual
|
1690
|
+
When using a transform at the top-level (outside of shell), you get a fluent interface to faciliate manual construction and use.
|
1601
1691
|
|
1602
1692
|
Example:
|
1603
1693
|
|
data/glimmer-dsl-swt.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: glimmer-dsl-swt 4.18.4.
|
5
|
+
# stub: glimmer-dsl-swt 4.18.4.8 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "glimmer-dsl-swt".freeze
|
9
|
-
s.version = "4.18.4.
|
9
|
+
s.version = "4.18.4.8"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
@@ -20,7 +20,9 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/dsl/expression'
|
23
|
+
require 'glimmer/dsl/top_level_expression'
|
23
24
|
require 'glimmer/swt/image_proxy'
|
25
|
+
require 'glimmer/swt/widget_proxy'
|
24
26
|
|
25
27
|
module Glimmer
|
26
28
|
module DSL
|
@@ -28,6 +30,7 @@ module Glimmer
|
|
28
30
|
# image expression
|
29
31
|
# Note: Cannot be a static expression because it clashes with image property expression
|
30
32
|
class ImageExpression < Expression
|
33
|
+
include TopLevelExpression
|
31
34
|
include ParentExpression
|
32
35
|
|
33
36
|
def can_interpret?(parent, keyword, *args, &block)
|
@@ -59,8 +59,10 @@ module Glimmer
|
|
59
59
|
# rgba is 4 arguments representing Red, Green, Blue, and Alpha numeric values
|
60
60
|
#
|
61
61
|
def initialize(*args)
|
62
|
+
@options = args.last.is_a?(Hash) ? args.pop : {}
|
62
63
|
@args = args
|
63
|
-
|
64
|
+
@args = @args.first if @args.first.is_a?(Array)
|
65
|
+
ensure_arg_values_within_valid_bounds unless @options[:ensure_bounds] == false
|
64
66
|
end
|
65
67
|
|
66
68
|
def swt_color
|
@@ -75,8 +77,7 @@ module Glimmer
|
|
75
77
|
@swt_color = @args.first
|
76
78
|
end
|
77
79
|
when 3..4
|
78
|
-
|
79
|
-
@swt_color = Color.new(*[red, green, blue, alpha].compact)
|
80
|
+
@swt_color = Color.new(*@args)
|
80
81
|
end
|
81
82
|
end
|
82
83
|
@swt_color
|
@@ -24,12 +24,31 @@ module Glimmer
|
|
24
24
|
module Custom
|
25
25
|
# Represents SWT drawable controls (widgets like canvas) and display
|
26
26
|
module Drawable
|
27
|
+
attr_accessor :requires_shape_disposal, :image_double_buffered
|
28
|
+
alias requires_shape_disposal? requires_shape_disposal
|
29
|
+
alias image_double_buffered? image_double_buffered
|
30
|
+
|
31
|
+
include_package 'org.eclipse.swt.graphics'
|
32
|
+
|
27
33
|
def shapes
|
28
34
|
@shapes ||= []
|
29
35
|
end
|
30
36
|
|
37
|
+
def image_buffered_shapes
|
38
|
+
@image_buffered_shapes ||= []
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_shape(shape)
|
42
|
+
if !@image_double_buffered || shape.args.first == @image_proxy_buffer
|
43
|
+
shapes << shape
|
44
|
+
else
|
45
|
+
image_buffered_shapes << shape
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
31
49
|
def clear_shapes
|
32
|
-
shapes
|
50
|
+
# Optimize further by having a collection of disposable_shapes independent of shapes, which is much smaller and only has shapes that require disposal (shapes with patterns or image)
|
51
|
+
shapes.dup.each(&:dispose) if requires_shape_disposal?
|
33
52
|
end
|
34
53
|
|
35
54
|
def deregister_shape_painting
|
@@ -40,8 +59,21 @@ module Glimmer
|
|
40
59
|
# TODO consider performance optimization relating to order of shape rendering (affecting only further shapes not previous ones)
|
41
60
|
if @paint_listener_proxy.nil?
|
42
61
|
shape_painter = lambda do |paint_event|
|
43
|
-
|
44
|
-
|
62
|
+
shape_painting_work = lambda do |paint_event|
|
63
|
+
paintable_shapes = @image_double_buffered ? image_buffered_shapes : shapes
|
64
|
+
paintable_shapes.each do |shape|
|
65
|
+
shape.paint(paint_event)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
if @image_double_buffered
|
69
|
+
if @image_proxy_buffer.nil?
|
70
|
+
swt_image = Image.new(DisplayProxy.instance.swt_display, bounds.width, bounds.height)
|
71
|
+
@image_proxy_buffer = ImageProxy.new(swt_image: swt_image)
|
72
|
+
shape_painting_work.call(@image_proxy_buffer)
|
73
|
+
end
|
74
|
+
@image_proxy_buffer.shape(self).paint(paint_event)
|
75
|
+
else
|
76
|
+
shape_painting_work.call(paint_event)
|
45
77
|
end
|
46
78
|
end
|
47
79
|
|
@@ -103,7 +103,7 @@ module Glimmer
|
|
103
103
|
@options.reject {|key, value| %w[fill gradient round].include?(key.to_s)}.each do |property, property_args|
|
104
104
|
@properties[property] = property_args
|
105
105
|
end
|
106
|
-
@parent.
|
106
|
+
@parent.add_shape(self)
|
107
107
|
post_add_content if property_block.nil?
|
108
108
|
end
|
109
109
|
|
@@ -134,7 +134,7 @@ module Glimmer
|
|
134
134
|
def post_add_content
|
135
135
|
unless @content_added
|
136
136
|
amend_method_name_options_based_on_properties!
|
137
|
-
@parent.setup_shape_painting
|
137
|
+
@parent.setup_shape_painting unless @parent.is_a?(ImageProxy)
|
138
138
|
@content_added = true
|
139
139
|
end
|
140
140
|
end
|
@@ -142,7 +142,10 @@ module Glimmer
|
|
142
142
|
def apply_property_arg_conversions(method_name, property, args)
|
143
143
|
args = args.dup
|
144
144
|
the_java_method = org.eclipse.swt.graphics.GC.java_class.declared_instance_methods.detect {|m| m.name == method_name}
|
145
|
-
if
|
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)
|
146
149
|
if the_java_method.parameter_types.first == Color.java_class
|
147
150
|
args[0] = ColorProxy.new(args[0])
|
148
151
|
end
|
@@ -163,6 +166,7 @@ module Glimmer
|
|
163
166
|
args[0] = args[0].swt_transform
|
164
167
|
end
|
165
168
|
if ['setBackgroundPattern', 'setForegroundPattern'].include?(method_name.to_s)
|
169
|
+
@parent.requires_shape_disposal = true
|
166
170
|
args.each_with_index do |arg, i|
|
167
171
|
if arg.is_a?(Symbol) || arg.is_a?(String)
|
168
172
|
args[i] = ColorProxy.new(arg).swt_color
|
@@ -192,11 +196,18 @@ module Glimmer
|
|
192
196
|
elsif (@name.include?('text') || @name.include?('String')) && !@properties.keys.map(&:to_s).include?('background') && @args.size == 3
|
193
197
|
@args << true
|
194
198
|
end
|
195
|
-
if @name.include?('image')
|
196
|
-
@
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
200
211
|
end
|
201
212
|
end
|
202
213
|
|
@@ -276,20 +287,35 @@ module Glimmer
|
|
276
287
|
end
|
277
288
|
|
278
289
|
def calculate_paint_args!
|
279
|
-
unless @
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
290
|
+
unless @calculated_paint_args
|
291
|
+
if @name == 'point'
|
292
|
+
# optimized performance calculation for pixel points
|
293
|
+
if !@properties[:foreground].is_a?(Color)
|
294
|
+
if @properties[:foreground].is_a?(Array)
|
295
|
+
@properties[:foreground] = ColorProxy.new(@properties[:foreground], ensure_bounds: false)
|
296
|
+
end
|
297
|
+
if @properties[:foreground].is_a?(Symbol) || @properties[:foreground].is_a?(String)
|
298
|
+
@properties[:foreground] = ColorProxy.new(@properties[:foreground], ensure_bounds: false)
|
299
|
+
end
|
300
|
+
if @properties[:foreground].is_a?(ColorProxy)
|
301
|
+
@properties[:foreground] = @properties[:foreground].swt_color
|
302
|
+
end
|
303
|
+
end
|
304
|
+
else
|
305
|
+
@properties['background'] = [@parent.background] if fill? && !has_some_background?
|
306
|
+
@properties['foreground'] = [@parent.foreground] if @parent.respond_to?(:foreground) && draw? && !has_some_foreground?
|
307
|
+
@properties['font'] = [@parent.font] if @parent.respond_to?(:font) && draw? && !@properties.keys.map(&:to_s).include?('font')
|
308
|
+
@properties['transform'] = [nil] if @parent.respond_to?(:transform) && !@properties.keys.map(&:to_s).include?('transform')
|
309
|
+
@properties.each do |property, args|
|
310
|
+
method_name = attribute_setter(property)
|
311
|
+
converted_args = apply_property_arg_conversions(method_name, property, args)
|
312
|
+
@properties[property] = converted_args
|
313
|
+
end
|
314
|
+
apply_shape_arg_conversions!
|
315
|
+
apply_shape_arg_defaults!
|
316
|
+
tolerate_shape_extra_args!
|
317
|
+
@calculated_paint_args = true
|
288
318
|
end
|
289
|
-
apply_shape_arg_conversions!
|
290
|
-
apply_shape_arg_defaults!
|
291
|
-
tolerate_shape_extra_args!
|
292
|
-
@calculated_paint_args = true
|
293
319
|
end
|
294
320
|
end
|
295
321
|
|
@@ -32,7 +32,7 @@ module Glimmer
|
|
32
32
|
class ImageProxy
|
33
33
|
include Custom::Drawable
|
34
34
|
include Properties
|
35
|
-
|
35
|
+
|
36
36
|
class << self
|
37
37
|
def create(*args)
|
38
38
|
if args.size == 1 && args.first.is_a?(ImageProxy)
|
@@ -53,6 +53,7 @@ module Glimmer
|
|
53
53
|
# Takes the same args as the SWT Image class
|
54
54
|
# Alternatively, takes a file path string or a uri:classloader file path string (generated by JRuby when invoking `File.expand_path` inside a JAR file)
|
55
55
|
# and returns an image object.
|
56
|
+
# Last but not least, it could serve as a parent for nesting shapes underneath to build an image with the Canvas Shape DSL
|
56
57
|
def initialize(*args, &content)
|
57
58
|
@args = args
|
58
59
|
@parent_proxy = nil
|
@@ -62,7 +63,7 @@ module Glimmer
|
|
62
63
|
end
|
63
64
|
options = @args.last.is_a?(Hash) ? @args.delete_at(-1) : {}
|
64
65
|
options[:swt_image] = @args.first if @args.size == 1 && @args.first.is_a?(Image)
|
65
|
-
@file_path = @args.first if @args.
|
66
|
+
@file_path = @args.first if @args.first.is_a?(String)
|
66
67
|
@args = @args.first if @args.size == 1 && @args.first.is_a?(Array)
|
67
68
|
if options&.keys&.include?(:swt_image)
|
68
69
|
@swt_image = options[:swt_image]
|
@@ -78,23 +79,33 @@ module Glimmer
|
|
78
79
|
height = (@image_data.height.to_f / @image_data.width.to_f)*width.to_f if !width.nil? && height.nil?
|
79
80
|
width = (@image_data.width.to_f / @image_data.height.to_f)*height.to_f if !height.nil? && width.nil?
|
80
81
|
scale_to(width, height) unless width.nil? || height.nil?
|
81
|
-
|
82
|
+
elsif !@args.first.is_a?(ImageProxy) && !@args.first.is_a?(Image)
|
82
83
|
@args.prepend(DisplayProxy.instance.swt_display) unless @args.first.is_a?(Display)
|
83
84
|
@swt_image = Image.new(*@args)
|
84
85
|
@original_image_data = @image_data = @swt_image.image_data
|
85
86
|
end
|
86
|
-
@swt_image.singleton_class.alias_method(:dispose_without_glimmer, :dispose)
|
87
87
|
proxy = self
|
88
88
|
# TODO consider adding a get_data/set_data method to conform with other SWT widgets
|
89
89
|
@swt_image.singleton_class.define_method(:dispose) do
|
90
90
|
proxy.clear_shapes
|
91
|
-
|
91
|
+
super
|
92
92
|
end
|
93
93
|
post_add_content if content.nil?
|
94
94
|
end
|
95
95
|
|
96
96
|
def post_add_content
|
97
|
-
|
97
|
+
if shapes.any?
|
98
|
+
setup_shape_painting
|
99
|
+
end
|
100
|
+
if @parent.respond_to?('image=')
|
101
|
+
@parent&.image = swt_image
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def shape(parent_proxy = nil, args = nil)
|
106
|
+
parent_proxy ||= @parent_proxy
|
107
|
+
args ||= [self] # TODO consider passing args if available
|
108
|
+
@shape ||= Glimmer::SWT::Custom::Shape.new(parent_proxy, 'image', *args)
|
98
109
|
end
|
99
110
|
|
100
111
|
def input_stream
|
@@ -149,6 +149,7 @@ module Glimmer
|
|
149
149
|
#
|
150
150
|
# Styles is a comma separate list of symbols representing SWT styles in lower case
|
151
151
|
def initialize(*init_args, swt_widget: nil)
|
152
|
+
@image_double_buffered = !!(init_args&.last&.include?(:image_double_buffered) && init_args&.last&.delete(:image_double_buffered))
|
152
153
|
if swt_widget.nil?
|
153
154
|
underscored_widget_name, parent, args = init_args
|
154
155
|
@parent_proxy = parent
|
@@ -192,7 +192,7 @@ class HelloTable
|
|
192
192
|
layout_data :center, :center, true, false
|
193
193
|
|
194
194
|
text 'BASEBALL PLAYOFF SCHEDULE'
|
195
|
-
background :transparent
|
195
|
+
background :transparent if OS.windows?
|
196
196
|
foreground rgb(94, 107, 103)
|
197
197
|
font name: 'Optima', height: 38, style: :bold
|
198
198
|
}
|
Binary file
|