glimmer-dsl-swt 4.20.13.11 → 4.20.13.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +5 -5
- data/VERSION +1 -1
- data/docs/reference/GLIMMER_SAMPLES.md +84 -2
- data/glimmer-dsl-swt.gemspec +0 -0
- data/lib/glimmer-dsl-swt.rb +1 -0
- data/lib/glimmer/swt/custom/drawable.rb +1 -0
- data/lib/glimmer/swt/custom/shape.rb +20 -1
- data/lib/glimmer/swt/custom/shape/arc.rb +2 -0
- data/lib/glimmer/swt/custom/shape/cubic.rb +1 -0
- data/lib/glimmer/swt/custom/shape/line.rb +1 -0
- data/lib/glimmer/swt/custom/shape/oval.rb +2 -0
- data/lib/glimmer/swt/custom/shape/path.rb +1 -5
- data/lib/glimmer/swt/custom/shape/point.rb +1 -0
- data/lib/glimmer/swt/custom/shape/polygon.rb +2 -0
- data/lib/glimmer/swt/custom/shape/polyline.rb +1 -0
- data/lib/glimmer/swt/custom/shape/rectangle.rb +1 -0
- data/samples/elaborate/battleship.rb +79 -0
- data/samples/elaborate/battleship/model/cell.rb +84 -0
- data/samples/elaborate/battleship/model/game.rb +143 -0
- data/samples/elaborate/battleship/model/grid.rb +54 -0
- data/samples/elaborate/battleship/model/ship.rb +114 -0
- data/samples/elaborate/battleship/model/ship_collection.rb +56 -0
- data/samples/elaborate/battleship/view/action_panel.rb +59 -0
- data/samples/elaborate/battleship/view/cell.rb +163 -0
- data/samples/elaborate/battleship/view/grid.rb +77 -0
- data/samples/elaborate/battleship/view/ship.rb +65 -0
- data/samples/elaborate/battleship/view/ship_collection.rb +49 -0
- data/samples/elaborate/connect4.rb +116 -0
- data/samples/elaborate/connect4/model/grid.rb +174 -0
- data/samples/elaborate/connect4/model/slot.rb +36 -0
- data/samples/elaborate/game_of_life/model/cell.rb +21 -0
- data/samples/elaborate/game_of_life/model/grid.rb +21 -0
- data/samples/elaborate/klondike_solitaire.rb +1 -1
- data/samples/elaborate/klondike_solitaire/view/column_pile.rb +0 -1
- data/samples/elaborate/klondike_solitaire/view/foundation_pile.rb +0 -2
- data/samples/elaborate/parking.rb +146 -0
- data/samples/elaborate/parking/model/parking_floor.rb +41 -0
- data/samples/elaborate/parking/model/parking_presenter.rb +42 -0
- data/samples/elaborate/parking/model/parking_spot.rb +46 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6f16ea275e3ce37889ed445d6cc3ab42bbcb7068eb1e57f51017d1625ac2582
|
4
|
+
data.tar.gz: d5dc4c387caa917f1c20db29cbf27c06148736b52bc7bd4cfb63d75854e866f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e9ab4f42471a424a335d5f39a395639601b88c4694eeb016f4d5b3b2449114eea07e3395058892b22b1c4e5b9b11c1e1b3e24a0fc7b687393cfb8218c548142
|
7
|
+
data.tar.gz: 472f326d596fbcb2e551549bb6bb6411839acb86437ad789e4ecc29841facbd2a27c32a696ac4c2a2c68d8b754517a35fff7570a05441c18db5033f1774c671b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
### 4.20.13.15
|
4
|
+
|
5
|
+
- Battleship elaborate sample
|
6
|
+
|
7
|
+
### 4.20.13.14
|
8
|
+
|
9
|
+
- Connect 4 elaborate sample
|
10
|
+
|
11
|
+
### 4.20.13.13
|
12
|
+
|
13
|
+
- Parking elaborate sample
|
14
|
+
- Support shape contain?/include? when a transform (e.g. rotation) is applied
|
15
|
+
|
16
|
+
### 4.20.13.12
|
17
|
+
|
18
|
+
- Fixed issue with dragged shapes having `drag_source true` not going back to original position when not dropped in a target if they were part of a composite shape
|
19
|
+
|
20
|
+
### 4.20.13.11
|
21
|
+
|
22
|
+
- Conway's Game of Life elaborate sample
|
23
|
+
|
3
24
|
### 4.20.13.10
|
4
25
|
|
5
26
|
- Update Glimmer Style Guide, scaffolding, and samples to have `before_body` and `after_body` in custom widgets/shells/shapes always take a `do; end` block since they contain logic not visuals
|
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.20.13.
|
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.20.13.15
|
2
2
|
## JRuby Desktop Development GUI Framework
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
|
4
4
|
[![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
|
@@ -15,7 +15,7 @@
|
|
15
15
|
[<img src="https://covers.oreillystatic.com/images/9780596519650/lrg.jpg" width=105 /><br />
|
16
16
|
Featured in JRuby Cookbook](http://shop.oreilly.com/product/9780596519650.do) and [Chalmers/Gothenburg University Software Engineering Master's Lecture Material](http://www.cse.chalmers.se/~bergert/slides/guest_lecture_DSLs.pdf)
|
17
17
|
|
18
|
-
[Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.13.
|
18
|
+
[Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.13.15 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
|
19
19
|
|
20
20
|
**Starting in version 4.20.0.0, [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) comes with the new [***Shine***](/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#shine) syntax** for highly intuitive and visually expressive View/Model Attribute Mapping, relying on `<=>` for bidirectional (two-way) data-binding and `<=` for unidirectional (one-way) data-binding, providing an alternative to the `bind` keyword (keep in mind that it is still a beta, so default back to `bind` whenever needed).
|
21
21
|
|
@@ -326,7 +326,7 @@ jgem install glimmer-dsl-swt
|
|
326
326
|
|
327
327
|
Or this command if you want a specific version:
|
328
328
|
```
|
329
|
-
jgem install glimmer-dsl-swt -v 4.20.13.
|
329
|
+
jgem install glimmer-dsl-swt -v 4.20.13.15
|
330
330
|
```
|
331
331
|
|
332
332
|
`jgem` is JRuby's version of `gem` command.
|
@@ -354,7 +354,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
|
|
354
354
|
|
355
355
|
Add the following to `Gemfile`:
|
356
356
|
```
|
357
|
-
gem 'glimmer-dsl-swt', '~> 4.20.13.
|
357
|
+
gem 'glimmer-dsl-swt', '~> 4.20.13.15'
|
358
358
|
```
|
359
359
|
|
360
360
|
And, then run:
|
@@ -375,7 +375,7 @@ glimmer
|
|
375
375
|
```
|
376
376
|
|
377
377
|
```
|
378
|
-
Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.13.
|
378
|
+
Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.13.15
|
379
379
|
|
380
380
|
Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
|
381
381
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.20.13.
|
1
|
+
4.20.13.15
|
@@ -60,11 +60,14 @@
|
|
60
60
|
- [User Profile](#user-profile)
|
61
61
|
- [Login](#login)
|
62
62
|
- [Tic Tac Toe](#tic-tac-toe)
|
63
|
+
- [Connect 4](#connect-4)
|
63
64
|
- [Contact Manager](#contact-manager)
|
64
65
|
- [Game of Life](#game-of-life)
|
65
66
|
- [Glimmer Tetris](#glimmer-tetris)
|
66
67
|
- [Klondike Solitaire](#klondike-solitaire)
|
68
|
+
- [Battleship](#battleship)
|
67
69
|
- [Mandelbrot Fractal](#mandelbrot-fractal)
|
70
|
+
- [Parking](#parking)
|
68
71
|
- [Stock Ticker](#stock-ticker)
|
69
72
|
- [Metronome](#metronome)
|
70
73
|
- [Weather](#weather)
|
@@ -72,6 +75,7 @@
|
|
72
75
|
- [Glimmer Calculator](#glimmer-calculator)
|
73
76
|
- [Gladiator](#gladiator)
|
74
77
|
- [Timer](#timer)
|
78
|
+
- [Glimmer Klondike Solitaire](#glimmer-klondike-solitaire)
|
75
79
|
- [License](#license)
|
76
80
|
|
77
81
|
## Samples
|
@@ -1044,6 +1048,34 @@ Code:
|
|
1044
1048
|
![Tic Tac Toe In Progress](/images/glimmer-tic-tac-toe-in-progress.png)
|
1045
1049
|
![Tic Tac Toe Game Over](/images/glimmer-tic-tac-toe-game-over.png)
|
1046
1050
|
|
1051
|
+
#### Connect 4
|
1052
|
+
|
1053
|
+
This sample demonstrates a widget/shape hybrid MVC application, including GUI layout and data-binding.
|
1054
|
+
|
1055
|
+
Code:
|
1056
|
+
|
1057
|
+
[samples/elaborate/connect4.rb](/samples/elaborate/connect4.rb)
|
1058
|
+
|
1059
|
+
Connect 4
|
1060
|
+
|
1061
|
+
![Connect 4](/images/glimmer-connect4.png)
|
1062
|
+
|
1063
|
+
Connect 4 - About To Drop
|
1064
|
+
|
1065
|
+
![Connect 4 About To Drop](/images/glimmer-connect4-about-to-drop.png)
|
1066
|
+
|
1067
|
+
Connect 4 - Dropped Coin
|
1068
|
+
|
1069
|
+
![Connect 4 Dropped Coin](/images/glimmer-connect4-dropped-coin.png)
|
1070
|
+
|
1071
|
+
Connect 4 - Player 1 Wins (keeps the coin about to drop visual cue)
|
1072
|
+
|
1073
|
+
![Connect 4 Player 1 Wins](/images/glimmer-connect4-player1-wins.png)
|
1074
|
+
|
1075
|
+
Connect 4 - Game Over Message Box
|
1076
|
+
|
1077
|
+
![Connect 4 Game Over Message Box](/images/glimmer-connect4-game-over-dialog.png)
|
1078
|
+
|
1047
1079
|
#### Contact Manager
|
1048
1080
|
|
1049
1081
|
This sample demonstrates table data-binding, sorting, filtering, GUI layout, MVP pattern, and test-driven development (has [specs](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/spec/samples/elaborate/contact_manager/contact_manager_presenter_spec.rb)).
|
@@ -1074,7 +1106,7 @@ Contact Manager - Edit Done
|
|
1074
1106
|
|
1075
1107
|
#### Game of Life
|
1076
1108
|
|
1077
|
-
This sample demonstrates how to build an interactive canvas-based visualization of Conway's Game of Life (test-first), taking advantage of data-binding and multi-threading.
|
1109
|
+
This sample demonstrates how to build an interactive canvas-based visualization of Conway's Game of Life ([test-first](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/spec/samples/elaborate/game_of_life/model/grid_spec.rb)), taking advantage of data-binding and multi-threading.
|
1078
1110
|
|
1079
1111
|
Code:
|
1080
1112
|
|
@@ -1112,7 +1144,7 @@ Code:
|
|
1112
1144
|
|
1113
1145
|
#### Klondike Solitaire
|
1114
1146
|
|
1115
|
-
This sample demonstrates how to build an interactive card game with MVC architecture, canvas, custom-shapes, data-binding, observers, and drag & drop.
|
1147
|
+
This sample demonstrates how to build an interactive card game with MVC architecture, canvas, custom-shapes, data-binding, observers, and canvas shape drag & drop.
|
1116
1148
|
|
1117
1149
|
Code:
|
1118
1150
|
|
@@ -1122,6 +1154,26 @@ Code:
|
|
1122
1154
|
|
1123
1155
|
![Klondike Solitaire Played](/images/glimmer-klondike-solitaire-played.png)
|
1124
1156
|
|
1157
|
+
Check out a souped up large-card-size packaged version of the game in the [Glimmer Klondike Solitaire](#glimmer-klondike-solitaire) external sample.
|
1158
|
+
|
1159
|
+
#### Battleship
|
1160
|
+
|
1161
|
+
This sample demonstrates how to build an interactive board game with A.I., MVC architecture, hybrid canvas widget/shape approach, custom-widgets, data-binding, observers, and widget drag & drop.
|
1162
|
+
|
1163
|
+
Code:
|
1164
|
+
|
1165
|
+
[samples/elaborate/battleship.rb](/samples/elaborate/battleship.rb)
|
1166
|
+
|
1167
|
+
![Battleship](/images/glimmer-battleship.png)
|
1168
|
+
|
1169
|
+
![Battleship Placement](/images/glimmer-battleship-placement.png)
|
1170
|
+
|
1171
|
+
![Battleship Ready for Battle](/images/glimmer-battleship-ready-for-battle.png)
|
1172
|
+
|
1173
|
+
![Battleship Won](/images/glimmer-battleship-won.png)
|
1174
|
+
|
1175
|
+
![Battleship Game Over](/images/glimmer-battleship-game-over.png)
|
1176
|
+
|
1125
1177
|
#### Mandelbrot Fractal
|
1126
1178
|
|
1127
1179
|
This sample demonstrates how to render canvas graphics with multi-threaded processing taking advantage of all CPU cores and doing background processing of images.
|
@@ -1148,6 +1200,28 @@ Code:
|
|
1148
1200
|
|
1149
1201
|
![Mandelbrot Fractal Help Menu](/images/glimmer-mandelbrot-menu-help.png)
|
1150
1202
|
|
1203
|
+
#### Parking
|
1204
|
+
|
1205
|
+
This sample demonstrates how to use method-based custom shapes and how to take advantage of transforms (e.g. rotation).
|
1206
|
+
|
1207
|
+
It enables booking a parking spot at the entrance of a building's parking, which in a real scenario would have prompted for payment too.
|
1208
|
+
|
1209
|
+
Code:
|
1210
|
+
|
1211
|
+
[samples/elaborate/parking.rb](/samples/elaborate/parking.rb)
|
1212
|
+
|
1213
|
+
Parking
|
1214
|
+
|
1215
|
+
![Parking](/images/glimmer-parking.png)
|
1216
|
+
|
1217
|
+
Parking Floor 4
|
1218
|
+
|
1219
|
+
![Parking Floor 4](/images/glimmer-parking-floor4.png)
|
1220
|
+
|
1221
|
+
Parking Booked
|
1222
|
+
|
1223
|
+
![Parking Booked](/images/glimmer-parking-booked.png)
|
1224
|
+
|
1151
1225
|
#### Stock Ticker
|
1152
1226
|
|
1153
1227
|
This sample demonstrates a Stock Ticker that generates random stock price data for 4 different stocks and provides 4 different tab views of the graphed data using the [Canvas Path DSL](/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#canvas-path-dsl). It leverages a thread that runs in the background and ticks the stocks to generate random new stock prices before amending the graphed paths with them.
|
@@ -1223,6 +1297,14 @@ Gladiator is a good demonstration of:
|
|
1223
1297
|
|
1224
1298
|
[<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer-cs-timer/master/glimmer-timer-screenshot.png" />](https://github.com/AndyObtiva/glimmer-cs-timer)
|
1225
1299
|
|
1300
|
+
#### Glimmer Klondike Solitaire
|
1301
|
+
|
1302
|
+
This is a souped up version of the Klondike Solitaire elaborate sample, which is built as an external application to enable packaging as a native executable installer. Enjoy!
|
1303
|
+
|
1304
|
+
[<img alt="Glimmer Klondike Solitaire Icon" src="https://raw.githubusercontent.com/AndyObtiva/glimmer_klondike_solitaire/master/package/linux/Glimmer%20Klondike%20Solitaire.png" height=40 /> Glimmer Klondike Solitaire](https://github.com/AndyObtiva/glimmer_klondike_solitaire)
|
1305
|
+
|
1306
|
+
![Glimmer Klondike Solitaire](https://raw.githubusercontent.com/AndyObtiva/glimmer_klondike_solitaire/master/images/glimmer-klondike-solitaire.png)
|
1307
|
+
|
1226
1308
|
## License
|
1227
1309
|
|
1228
1310
|
[MIT](LICENSE.txt)
|
data/glimmer-dsl-swt.gemspec
CHANGED
Binary file
|
data/lib/glimmer-dsl-swt.rb
CHANGED
@@ -62,6 +62,7 @@ module Glimmer
|
|
62
62
|
# 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)
|
63
63
|
shapes.dup.each {|s| s.dispose(dispose_images: dispose_images, dispose_patterns: dispose_patterns) } if requires_shape_disposal?
|
64
64
|
end
|
65
|
+
alias dispose_shapes clear_shapes
|
65
66
|
|
66
67
|
def paint_pixel_by_pixel(width = nil, height = nil, &each_pixel_color)
|
67
68
|
if @image_double_buffered
|
@@ -216,6 +216,7 @@ module Glimmer
|
|
216
216
|
# Subclasses (like polygon) may override to indicate if a point x,y coordinates falls inside the shape
|
217
217
|
# some shapes may choose to provide a fuzz factor to make usage of this method for mouse clicking more user friendly
|
218
218
|
def contain?(x, y)
|
219
|
+
x, y = inverse_transform_point(x, y)
|
219
220
|
# assume a rectangular filled shape by default (works for several shapes like image, text, and focus)
|
220
221
|
x.between?(self.absolute_x, self.absolute_x + calculated_width.to_f) && y.between?(self.absolute_y, self.absolute_y + calculated_height.to_f)
|
221
222
|
end
|
@@ -232,6 +233,24 @@ module Glimmer
|
|
232
233
|
included = include?(x, y)
|
233
234
|
included ||= expanded_shapes.reject {|shape| shape == except_child}.detect { |shape| shape.include?(x, y) }
|
234
235
|
end
|
236
|
+
|
237
|
+
# if there is a transform, invert it and apply on x, y point coordinates
|
238
|
+
def inverse_transform_point(x, y)
|
239
|
+
current_transform = (transform || parent_shape_containers.map(&:transform).first)&.first
|
240
|
+
if current_transform
|
241
|
+
transform_array = [1,2,3,4,5,6].to_java(:float)
|
242
|
+
current_transform.getElements(transform_array)
|
243
|
+
inverse_transform = TransformProxy.new(DisplayProxy.instance.swt_display, *transform_array.to_a)
|
244
|
+
inverse_transform_array = [1,2,3,4,5,6].to_java(:float)
|
245
|
+
inverse_transform.getElements(inverse_transform_array)
|
246
|
+
matrix = Matrix[[inverse_transform_array[0], inverse_transform_array[1]], [inverse_transform_array[2], inverse_transform_array[3]]]
|
247
|
+
result = matrix * Matrix.column_vector([x, y])
|
248
|
+
x, y = result.to_a.flatten
|
249
|
+
x += inverse_transform_array[5]
|
250
|
+
y += inverse_transform_array[4]
|
251
|
+
end
|
252
|
+
[x, y]
|
253
|
+
end
|
235
254
|
|
236
255
|
# Indicates if a shape's x, y, width, height differ from its bounds calculation (e.g. arc / polygon)
|
237
256
|
def irregular?
|
@@ -713,7 +732,7 @@ module Glimmer
|
|
713
732
|
end
|
714
733
|
end
|
715
734
|
@drawable_on_mouse_up = drawable.handle_observation_request('on_mouse_up') do |event|
|
716
|
-
if Shape.dragging && Shape.dragged_shape == self && !Shape.drop_shapes.detect {|shape| shape.include_with_children?(event.x, event.y)}
|
735
|
+
if Shape.dragging && Shape.dragged_shape == self && !Shape.drop_shapes.detect {|shape| shape.include_with_children?(event.x, event.y, except_child: Shape.dragged_shape)}
|
717
736
|
Shape.dragging = false
|
718
737
|
Shape.dragged_shape.x = Shape.dragged_shape_original_x
|
719
738
|
Shape.dragged_shape.y = Shape.dragged_shape_original_y
|
@@ -53,6 +53,7 @@ module Glimmer
|
|
53
53
|
|
54
54
|
# checks if shape contains the point denoted by x and y
|
55
55
|
def contain?(x, y)
|
56
|
+
x, y = inverse_transform_point(x, y)
|
56
57
|
geometry.contains(x, y)
|
57
58
|
end
|
58
59
|
|
@@ -60,6 +61,7 @@ module Glimmer
|
|
60
61
|
if filled?
|
61
62
|
contain?(x, y)
|
62
63
|
else
|
64
|
+
x, y = inverse_transform_point(x, y)
|
63
65
|
# give it some fuzz to allow a larger region around the drawn oval to accept including a point (helps with mouse clickability on a shape)
|
64
66
|
outer_shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, calculated_width + 3, calculated_height + 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
|
65
67
|
inner_shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, calculated_width - 3, calculated_height - 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
|
@@ -55,6 +55,7 @@ module Glimmer
|
|
55
55
|
|
56
56
|
# checks if drawn or filled rectangle includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge)
|
57
57
|
def include?(x, y, filled: nil)
|
58
|
+
x, y = inverse_transform_point(x, y)
|
58
59
|
filled = filled? if filled.nil?
|
59
60
|
makeshift_gc = org.eclipse.swt.graphics.GC.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
|
60
61
|
swt_path = org.eclipse.swt.graphics.Path.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
|
@@ -39,6 +39,7 @@ module Glimmer
|
|
39
39
|
|
40
40
|
# checks if shape contains the point denoted by x and y
|
41
41
|
def contain?(x, y)
|
42
|
+
x, y = inverse_transform_point(x, y)
|
42
43
|
shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x, self.absolute_y, calculated_width, calculated_height)
|
43
44
|
shape_geometry.contains(x, y)
|
44
45
|
end
|
@@ -48,6 +49,7 @@ module Glimmer
|
|
48
49
|
if filled?
|
49
50
|
contain?(x, y)
|
50
51
|
else
|
52
|
+
x, y = inverse_transform_point(x, y)
|
51
53
|
# give it some fuzz to allow a larger region around the drawn oval to accept including a point (helps with mouse clickability on a shape)
|
52
54
|
outer_shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x - 3, self.absolute_y - 3, calculated_width + 6, calculated_height + 6)
|
53
55
|
inner_shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x + 3, self.absolute_y + 3, calculated_width - 6, calculated_height - 6)
|
@@ -61,17 +61,13 @@ module Glimmer
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def contain?(x, y)
|
65
|
-
makeshift_gc = org.eclipse.swt.graphics.GC.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
|
66
|
-
@swt_path.contains(x.to_f, y.to_f, makeshift_gc, false)
|
67
|
-
end
|
68
|
-
|
69
64
|
def contain?(x, y)
|
70
65
|
include?(x, y, filled: true)
|
71
66
|
end
|
72
67
|
|
73
68
|
# checks if drawn or filled rectangle includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge)
|
74
69
|
def include?(x, y, filled: nil)
|
70
|
+
x, y = inverse_transform_point(x, y)
|
75
71
|
filled = filled? if filled.nil?
|
76
72
|
makeshift_gc = org.eclipse.swt.graphics.GC.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
|
77
73
|
@swt_path.contains(x.to_f, y.to_f, makeshift_gc, !filled)
|
@@ -49,6 +49,7 @@ module Glimmer
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def include?(x, y)
|
52
|
+
x, y = inverse_transform_point(x, y)
|
52
53
|
# give it some fuzz (helps makes mouse clicking easier)
|
53
54
|
x.to_i.between?(self.absolute_x.to_i - 2, self.absolute_x.to_i + 2) && y.to_i.between?(self.absolute_y.to_i - 2, self.absolute_y.to_i + 2)
|
54
55
|
end
|
@@ -152,6 +152,7 @@ module Glimmer
|
|
152
152
|
end
|
153
153
|
|
154
154
|
def contain?(x, y)
|
155
|
+
x, y = inverse_transform_point(x, y)
|
155
156
|
geometry.contains(x, y)
|
156
157
|
end
|
157
158
|
|
@@ -159,6 +160,7 @@ module Glimmer
|
|
159
160
|
if filled?
|
160
161
|
contain?(x, y)
|
161
162
|
else
|
163
|
+
x, y = inverse_transform_point(x, y)
|
162
164
|
comparison_lines = absolute_point_xy_array.zip(absolute_point_xy_array.rotate(1))
|
163
165
|
comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
|
164
166
|
end
|
@@ -130,6 +130,7 @@ module Glimmer
|
|
130
130
|
end
|
131
131
|
|
132
132
|
def include?(x, y)
|
133
|
+
x, y = inverse_transform_point(x, y)
|
133
134
|
comparison_lines = absolute_point_xy_array.zip(absolute_point_xy_array.rotate(1))
|
134
135
|
comparison_lines.pop # ignore last pair since you don't want to compare last point with first point
|
135
136
|
comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
|
@@ -85,6 +85,7 @@ module Glimmer
|
|
85
85
|
if filled?
|
86
86
|
contain?(x, y)
|
87
87
|
else
|
88
|
+
x, y = inverse_transform_point(x, y)
|
88
89
|
comparison_lines = absolute_point_xy_array.zip(absolute_point_xy_array.rotate(1))
|
89
90
|
comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
|
90
91
|
end
|
@@ -0,0 +1,79 @@
|
|
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-dsl-swt'
|
23
|
+
require 'facets/string/titlecase'
|
24
|
+
require 'facets/string/underscore'
|
25
|
+
|
26
|
+
require_relative 'battleship/model/game'
|
27
|
+
|
28
|
+
require_relative 'battleship/view/grid'
|
29
|
+
require_relative 'battleship/view/ship_collection'
|
30
|
+
require_relative 'battleship/view/action_panel'
|
31
|
+
|
32
|
+
class Battleship
|
33
|
+
include Glimmer::UI::CustomShell
|
34
|
+
|
35
|
+
COLOR_WATER = rgb(156, 211, 219)
|
36
|
+
COLOR_SHIP = :dark_gray
|
37
|
+
|
38
|
+
before_body do
|
39
|
+
@game = Model::Game.new
|
40
|
+
end
|
41
|
+
|
42
|
+
after_body do
|
43
|
+
observe(@game, :over) do |game_over_value|
|
44
|
+
if game_over_value
|
45
|
+
game_over_message = if game_over_value == :you
|
46
|
+
"Game over!\nYou Won!"
|
47
|
+
else
|
48
|
+
"Game over!\nYou Lost!"
|
49
|
+
end
|
50
|
+
|
51
|
+
message_box {
|
52
|
+
text 'Game Over!'
|
53
|
+
message game_over_message
|
54
|
+
}.open
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
body {
|
60
|
+
shell(:no_resize) {
|
61
|
+
grid_layout(2, false) {
|
62
|
+
horizontal_spacing 15
|
63
|
+
vertical_spacing 15
|
64
|
+
}
|
65
|
+
|
66
|
+
text 'Glimmer Battleship'
|
67
|
+
|
68
|
+
@enemy_grid = grid(game: @game, player: :enemy)
|
69
|
+
@enemy_ship_collection = ship_collection(game: @game, player: :enemy)
|
70
|
+
|
71
|
+
@player_grid = grid(game: @game, player: :you)
|
72
|
+
@player_ship_collection = ship_collection(game: @game, player: :you)
|
73
|
+
|
74
|
+
action_panel(game: @game)
|
75
|
+
}
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
Battleship.launch
|