glimmer-dsl-swt 4.20.13.8 → 4.20.13.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +5 -5
- data/VERSION +1 -1
- data/docs/reference/GLIMMER_SAMPLES.md +24 -0
- data/docs/reference/GLIMMER_STYLE_GUIDE.md +2 -1
- data/glimmer-dsl-swt.gemspec +0 -0
- data/lib/glimmer/rake_task/scaffold.rb +14 -14
- data/lib/glimmer/swt/custom/code_text.rb +4 -4
- data/lib/glimmer/swt/custom/shape.rb +1 -1
- data/samples/elaborate/calculator.rb +2 -2
- data/samples/elaborate/contact_manager.rb +2 -2
- data/samples/elaborate/game_of_life.rb +111 -0
- data/samples/elaborate/game_of_life/model/cell.rb +72 -0
- data/samples/elaborate/game_of_life/model/grid.rb +97 -0
- data/samples/elaborate/klondike_solitaire.rb +30 -23
- data/samples/elaborate/klondike_solitaire/model/playing_card.rb +36 -0
- data/samples/elaborate/klondike_solitaire/view/empty_playing_card.rb +12 -4
- data/samples/elaborate/klondike_solitaire/view/foundation_pile.rb +4 -4
- data/samples/elaborate/klondike_solitaire/view/hidden_playing_card.rb +8 -1
- data/samples/elaborate/klondike_solitaire/view/playing_card.rb +3 -3
- data/samples/elaborate/klondike_solitaire/view/tableau.rb +4 -4
- data/samples/elaborate/login.rb +2 -2
- data/samples/elaborate/mandelbrot_fractal.rb +12 -12
- data/samples/elaborate/meta_sample.rb +2 -2
- data/samples/elaborate/metronome.rb +2 -2
- data/samples/elaborate/stock_ticker.rb +8 -8
- data/samples/elaborate/tetris.rb +4 -4
- data/samples/elaborate/tetris/view/bevel.rb +2 -2
- data/samples/elaborate/tetris/view/score_lane.rb +2 -2
- data/samples/elaborate/tic_tac_toe.rb +6 -6
- data/samples/elaborate/timer.rb +4 -4
- data/samples/elaborate/weather.rb +4 -4
- data/samples/hello/hello_button.rb +2 -2
- data/samples/hello/hello_c_combo.rb +2 -2
- data/samples/hello/hello_canvas.rb +4 -4
- data/samples/hello/hello_canvas_animation.rb +2 -2
- data/samples/hello/hello_canvas_data_binding.rb +2 -2
- data/samples/hello/hello_checkbox.rb +2 -2
- data/samples/hello/hello_checkbox_group.rb +2 -2
- data/samples/hello/hello_code_text.rb +2 -2
- data/samples/hello/hello_color_dialog.rb +2 -2
- data/samples/hello/hello_combo.rb +2 -2
- data/samples/hello/hello_computed.rb +14 -22
- data/samples/hello/hello_cool_bar.rb +2 -2
- data/samples/hello/hello_cursor.rb +2 -2
- data/samples/hello/hello_custom_shape.rb +2 -2
- data/samples/hello/hello_custom_shell.rb +2 -2
- data/samples/hello/hello_custom_widget.rb +4 -4
- data/samples/hello/hello_date_time.rb +2 -2
- data/samples/hello/hello_directory_dialog.rb +2 -2
- data/samples/hello/hello_file_dialog.rb +2 -2
- data/samples/hello/hello_font_dialog.rb +2 -2
- data/samples/hello/hello_group.rb +2 -2
- data/samples/hello/hello_list_multi_selection.rb +2 -2
- data/samples/hello/hello_list_single_selection.rb +2 -2
- data/samples/hello/hello_progress_bar.rb +2 -2
- data/samples/hello/hello_radio.rb +2 -2
- data/samples/hello/hello_radio_group.rb +2 -2
- data/samples/hello/hello_scale.rb +2 -2
- data/samples/hello/hello_spinner.rb +2 -2
- data/samples/hello/hello_table.rb +2 -2
- data/samples/hello/hello_text.rb +2 -2
- data/samples/hello/hello_tool_bar.rb +2 -2
- data/samples/hello/hello_tray_item.rb +2 -2
- data/samples/hello/hello_tree.rb +4 -4
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bec3c88dee81e6625c208ce0fe97f02984b27faa107bb5b1c0667612ada04cae
|
4
|
+
data.tar.gz: 4221c07f12ba4d2de558223a60546218a530c02cdb34e0d6c1a03b19b7a4ba6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c555e4e44ae1ca8933a35d2316bc8711d4888483b0f6ff3a90d372e7f25f3b66b9ac114239f5970e8f72f69ad2aa1358dc0833d96a8689c5d14b0fa6aba79ef
|
7
|
+
data.tar.gz: 363b079ba036a24e47a6919bc72d1dbaa4396586ae814ccb77cde3917b6ca917c5e5fe295dc17ff9339cfa9dfb526ee60e936af4e4d66f081901727017712f4e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
### 4.20.13.12
|
4
|
+
|
5
|
+
- 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
|
6
|
+
|
7
|
+
### 4.20.13.11
|
8
|
+
|
9
|
+
- Conway's Game of Life elaborate sample
|
10
|
+
|
11
|
+
### 4.20.13.10
|
12
|
+
|
13
|
+
- 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
|
14
|
+
|
15
|
+
### 4.20.13.9
|
16
|
+
|
17
|
+
- Update Klondike Solitaire to have playing card suit symbols and avoid clipping of cards on the boundaries
|
18
|
+
|
3
19
|
### 4.20.13.8
|
4
20
|
|
5
21
|
- Glimmer Klondike Solitaire elaborate sample
|
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.12
|
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.12 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.12
|
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.12'
|
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.12
|
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.12
|
@@ -61,7 +61,9 @@
|
|
61
61
|
- [Login](#login)
|
62
62
|
- [Tic Tac Toe](#tic-tac-toe)
|
63
63
|
- [Contact Manager](#contact-manager)
|
64
|
+
- [Game of Life](#game-of-life)
|
64
65
|
- [Glimmer Tetris](#glimmer-tetris)
|
66
|
+
- [Klondike Solitaire](#klondike-solitaire)
|
65
67
|
- [Mandelbrot Fractal](#mandelbrot-fractal)
|
66
68
|
- [Stock Ticker](#stock-ticker)
|
67
69
|
- [Metronome](#metronome)
|
@@ -1070,6 +1072,16 @@ Contact Manager - Edit Done
|
|
1070
1072
|
|
1071
1073
|
![Contact Manager](/images/glimmer-contact-manager-edit-done.png)
|
1072
1074
|
|
1075
|
+
#### Game of Life
|
1076
|
+
|
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.
|
1078
|
+
|
1079
|
+
Code:
|
1080
|
+
|
1081
|
+
[samples/elaborate/game_of_life.rb](/samples/elaborate/game_of_life.rb)
|
1082
|
+
|
1083
|
+
![Game of Life](/images/glimmer-game-of-life.gif)
|
1084
|
+
|
1073
1085
|
#### Glimmer Tetris
|
1074
1086
|
|
1075
1087
|
This sample demonstrates how to build an interactive animated game with MVC architecture, custom-shell/custom-widgets, multi-threading, asynchronous programming, data-binding, canvas shape graphic decorations, canvas shape icon image generation, and keyboard events/shortcuts.
|
@@ -1098,6 +1110,18 @@ Code:
|
|
1098
1110
|
|
1099
1111
|
![Tetris Help Menu](/images/glimmer-tetris-help-menu.png)
|
1100
1112
|
|
1113
|
+
#### Klondike Solitaire
|
1114
|
+
|
1115
|
+
This sample demonstrates how to build an interactive card game with MVC architecture, canvas, custom-shapes, data-binding, observers, and drag & drop.
|
1116
|
+
|
1117
|
+
Code:
|
1118
|
+
|
1119
|
+
[samples/elaborate/klondike_solitaire.rb](/samples/elaborate/klondike_solitaire.rb)
|
1120
|
+
|
1121
|
+
![Klondike Solitaire](/images/glimmer-klondike-solitaire.png)
|
1122
|
+
|
1123
|
+
![Klondike Solitaire Played](/images/glimmer-klondike-solitaire-played.png)
|
1124
|
+
|
1101
1125
|
#### Mandelbrot Fractal
|
1102
1126
|
|
1103
1127
|
This sample demonstrates how to render canvas graphics with multi-threaded processing taking advantage of all CPU cores and doing background processing of images.
|
@@ -10,6 +10,7 @@
|
|
10
10
|
- Widget listeners are always declared starting with `on_` prefix and affixing listener event method name afterwards in underscored lowercase form. Their multi-line blocks rely on the `do; end` style.
|
11
11
|
- Widget listeners are always followed by a block using curly braces (Only when declared in DSL. When invoked on widget object directly outside of GUI declarations, standard Ruby conventions apply)
|
12
12
|
- Data-binding is done via `bind` keyword, which always takes arguments wrapped in parentheses
|
13
|
-
- Custom widget `body
|
13
|
+
- Custom widget/shell/shape `body` blocks open and close with curly braces.
|
14
|
+
- Custom widget/shell/shape `before_body` and `after_body` blocks are declared as `do; end` blocks.
|
14
15
|
- Custom widgets receive additional keyword arguments called options, which come after the SWT styles.
|
15
16
|
- Pure logic multi-line blocks that do not constitute GUI DSL view elements (such as `Thread.new`, `loop`, `each` and `observe` blocks) rely on the `do; end` style to clearly separate logic code from view code.
|
data/glimmer-dsl-swt.gemspec
CHANGED
Binary file
|
@@ -607,7 +607,7 @@ module Glimmer
|
|
607
607
|
|
608
608
|
if %i[gem app desktopify].include?(shell_type)
|
609
609
|
custom_shell_file_content += <<-MULTI_LINE_STRING
|
610
|
-
before_body
|
610
|
+
before_body do
|
611
611
|
Display.app_name = '#{shell_type == :gem ? human_name(custom_shell_name) : human_name(namespace)}'
|
612
612
|
Display.app_version = VERSION
|
613
613
|
@display = display {
|
@@ -618,13 +618,13 @@ module Glimmer
|
|
618
618
|
#{shell_type == :desktopify ? 'display_about_dialog' : 'display_preferences_dialog'}
|
619
619
|
}
|
620
620
|
}
|
621
|
-
|
621
|
+
end
|
622
622
|
MULTI_LINE_STRING
|
623
623
|
else
|
624
624
|
custom_shell_file_content += <<-MULTI_LINE_STRING
|
625
|
-
# before_body
|
625
|
+
# before_body do
|
626
626
|
#
|
627
|
-
#
|
627
|
+
# end
|
628
628
|
MULTI_LINE_STRING
|
629
629
|
end
|
630
630
|
|
@@ -632,9 +632,9 @@ module Glimmer
|
|
632
632
|
|
633
633
|
## Use after_body block to setup observers for widgets in body
|
634
634
|
#
|
635
|
-
# after_body
|
635
|
+
# after_body do
|
636
636
|
#
|
637
|
-
#
|
637
|
+
# end
|
638
638
|
|
639
639
|
## Add widget content inside custom shell body
|
640
640
|
## Top-most widget must be a shell or another custom shell
|
@@ -767,15 +767,15 @@ end
|
|
767
767
|
## Use before_body block to pre-initialize variables to use in body
|
768
768
|
#
|
769
769
|
#
|
770
|
-
# before_body
|
770
|
+
# before_body do
|
771
771
|
#
|
772
|
-
#
|
772
|
+
# end
|
773
773
|
|
774
774
|
## Use after_body block to setup observers for widgets in body
|
775
775
|
#
|
776
|
-
# after_body
|
776
|
+
# after_body do
|
777
777
|
#
|
778
|
-
#
|
778
|
+
# end
|
779
779
|
|
780
780
|
## Add widget content under custom widget body
|
781
781
|
##
|
@@ -817,15 +817,15 @@ end
|
|
817
817
|
## Use before_body block to pre-initialize variables to use in body
|
818
818
|
#
|
819
819
|
#
|
820
|
-
# before_body
|
820
|
+
# before_body do
|
821
821
|
#
|
822
|
-
#
|
822
|
+
# end
|
823
823
|
|
824
824
|
## Use after_body block to setup observers for shapes in body
|
825
825
|
#
|
826
|
-
# after_body
|
826
|
+
# after_body do
|
827
827
|
#
|
828
|
-
#
|
828
|
+
# end
|
829
829
|
|
830
830
|
## Add shape content under custom shape body
|
831
831
|
#
|
@@ -121,7 +121,7 @@ module Glimmer
|
|
121
121
|
@line_numbers_styled_text_proxy.content(&block)
|
122
122
|
end
|
123
123
|
|
124
|
-
before_body
|
124
|
+
before_body do
|
125
125
|
require 'rouge'
|
126
126
|
require 'ext/rouge/themes/glimmer'
|
127
127
|
@swt_style = swt_style == 0 ? [:border, :multi, :v_scroll, :h_scroll] : swt_style
|
@@ -132,11 +132,11 @@ module Glimmer
|
|
132
132
|
@lines_width = lines[:width]
|
133
133
|
end
|
134
134
|
@dsl_mode = true
|
135
|
-
|
135
|
+
end
|
136
136
|
|
137
|
-
after_body
|
137
|
+
after_body do
|
138
138
|
@dsl_mode = nil
|
139
|
-
|
139
|
+
end
|
140
140
|
|
141
141
|
body {
|
142
142
|
if lines
|
@@ -713,7 +713,7 @@ module Glimmer
|
|
713
713
|
end
|
714
714
|
end
|
715
715
|
@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)}
|
716
|
+
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
717
|
Shape.dragging = false
|
718
718
|
Shape.dragged_shape.x = Shape.dragged_shape_original_x
|
719
719
|
Shape.dragged_shape.y = Shape.dragged_shape_original_y
|
@@ -15,7 +15,7 @@ class Calculator
|
|
15
15
|
|
16
16
|
attr_reader :presenter
|
17
17
|
|
18
|
-
before_body
|
18
|
+
before_body do
|
19
19
|
@presenter = Model::Presenter.new
|
20
20
|
|
21
21
|
Display.setAppName('Glimmer Calculator')
|
@@ -30,7 +30,7 @@ class Calculator
|
|
30
30
|
display_about_dialog
|
31
31
|
}
|
32
32
|
}
|
33
|
-
|
33
|
+
end
|
34
34
|
|
35
35
|
body {
|
36
36
|
shell {
|
@@ -26,10 +26,10 @@ require_relative "contact_manager/contact_manager_presenter"
|
|
26
26
|
class ContactManager
|
27
27
|
include Glimmer::UI::CustomShell
|
28
28
|
|
29
|
-
before_body
|
29
|
+
before_body do
|
30
30
|
@contact_manager_presenter = ContactManagerPresenter.new
|
31
31
|
@contact_manager_presenter.list
|
32
|
-
|
32
|
+
end
|
33
33
|
|
34
34
|
body {
|
35
35
|
shell {
|
@@ -0,0 +1,111 @@
|
|
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
|
+
|
24
|
+
require_relative 'game_of_life/model/grid'
|
25
|
+
|
26
|
+
class GameOfLife
|
27
|
+
include Glimmer::UI::CustomShell
|
28
|
+
|
29
|
+
WIDTH = 20
|
30
|
+
HEIGHT = 20
|
31
|
+
CELL_WIDTH = 25
|
32
|
+
CELL_HEIGHT = 25
|
33
|
+
|
34
|
+
before_body do
|
35
|
+
@grid = GameOfLife::Model::Grid.new(WIDTH, HEIGHT)
|
36
|
+
end
|
37
|
+
|
38
|
+
body {
|
39
|
+
shell {
|
40
|
+
row_layout :vertical
|
41
|
+
text "Conway's Game of Life (Glimmer Edition)"
|
42
|
+
|
43
|
+
canvas {
|
44
|
+
layout_data {
|
45
|
+
width WIDTH*CELL_WIDTH
|
46
|
+
height HEIGHT*CELL_HEIGHT
|
47
|
+
}
|
48
|
+
(0...HEIGHT).each do |row_index|
|
49
|
+
(0...WIDTH).each do |column_index|
|
50
|
+
rectangle(column_index*CELL_WIDTH, row_index*CELL_HEIGHT, CELL_WIDTH, CELL_HEIGHT) {
|
51
|
+
background <= [@grid.cell_rows[row_index][column_index], "alive", on_read: ->(a) {a ? :black : :white}]
|
52
|
+
|
53
|
+
on_mouse_down {
|
54
|
+
@grid.cell_rows[row_index][column_index].toggle_aliveness!
|
55
|
+
}
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
}
|
60
|
+
|
61
|
+
composite {
|
62
|
+
row_layout(:horizontal) {
|
63
|
+
margin_width 0
|
64
|
+
}
|
65
|
+
|
66
|
+
button {
|
67
|
+
text 'Step'
|
68
|
+
enabled <= [@grid, :playing, on_read: :! ]
|
69
|
+
|
70
|
+
on_widget_selected {
|
71
|
+
@grid.step!
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
button {
|
76
|
+
text 'Clear'
|
77
|
+
enabled <= [@grid, :playing, on_read: :! ]
|
78
|
+
|
79
|
+
on_widget_selected {
|
80
|
+
@grid.clear!
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
button {
|
85
|
+
text <= [@grid, :playing, on_read: ->(p) { p ? 'Stop' : 'Play' }]
|
86
|
+
|
87
|
+
on_widget_selected {
|
88
|
+
@grid.toggle_playback!
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
label {
|
93
|
+
text 'Slower'
|
94
|
+
}
|
95
|
+
|
96
|
+
scale {
|
97
|
+
minimum 1
|
98
|
+
maximum 100
|
99
|
+
selection <=> [@grid, :speed]
|
100
|
+
}
|
101
|
+
|
102
|
+
label {
|
103
|
+
text 'Faster'
|
104
|
+
}
|
105
|
+
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
GameOfLife.launch
|
@@ -0,0 +1,72 @@
|
|
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
|
+
class GameOfLife
|
23
|
+
module Model
|
24
|
+
class Cell
|
25
|
+
attr_reader :grid, :row_index, :column_index
|
26
|
+
attr_accessor :alive
|
27
|
+
alias alive? alive
|
28
|
+
|
29
|
+
def initialize(grid, row_index, column_index, alive=false)
|
30
|
+
@grid = grid
|
31
|
+
@row_index = row_index
|
32
|
+
@column_index = column_index
|
33
|
+
@alive = alive
|
34
|
+
end
|
35
|
+
|
36
|
+
def live!
|
37
|
+
self.alive = true
|
38
|
+
end
|
39
|
+
|
40
|
+
def die!
|
41
|
+
self.alive = false
|
42
|
+
end
|
43
|
+
|
44
|
+
def toggle_aliveness!
|
45
|
+
return if grid.playing?
|
46
|
+
dead ? live! : die!
|
47
|
+
end
|
48
|
+
|
49
|
+
def dead?
|
50
|
+
!alive?
|
51
|
+
end
|
52
|
+
alias dead dead?
|
53
|
+
|
54
|
+
# step into the next generation
|
55
|
+
def step!
|
56
|
+
self.alive = (alive? && alive_neighbor_count.between?(2, 3)) || (dead? && alive_neighbor_count == 3)
|
57
|
+
end
|
58
|
+
|
59
|
+
def alive_neighbor_count
|
60
|
+
[row_index - 1, 0].max.upto([row_index + 1, grid.row_count - 1].min).map do |current_row_index|
|
61
|
+
[column_index - 1, 0].max.upto([column_index + 1, grid.column_count - 1].min).map do |current_column_index|
|
62
|
+
if current_row_index == row_index && current_column_index == column_index
|
63
|
+
0
|
64
|
+
else
|
65
|
+
grid.previous_cell_rows[current_row_index][current_column_index].alive? ? 1 : 0
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end.flatten.reduce(:+)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|