glimmer-dsl-libui 0.4.21 → 0.4.22
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 +6 -0
- data/README.md +65 -29
- data/VERSION +1 -1
- data/examples/tetris/model/game.rb +25 -23
- data/examples/tetris.rb +50 -19
- data/glimmer-dsl-libui.gemspec +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cc2ebc159948cf7110cdc9113b219809789a6b73c5412435364998c5633afe26
|
|
4
|
+
data.tar.gz: f6f988f09d76f8cbe72bc76fc2440c426def14ecbd4405270d70d05012d4d183
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f9d5a3a2232050cc372235a7e97d47ab26fdf5a39c87e1d77614e029b938c9d745f2ba01caf4d26158f0c2334035db63e5226fd6e1d9cf61df656a293c81c3b6
|
|
7
|
+
data.tar.gz: 77ff5efbc0945a2be47f0e2241025c6a9eb83e122c42581cb704c3a540d1d7ac6cd224d6a25b58e6894ccee852b32f3ba65daedaab6b27d53a4808bda163ed2a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 0.4.22
|
|
4
|
+
|
|
5
|
+
- examples/tetris.rb "Show Next Block Preview" menu item under "View" menu
|
|
6
|
+
- examples/tetris.rb "Speed" menu
|
|
7
|
+
- Fix issue with examples/tetris.rb not accelerating upon level ups
|
|
8
|
+
|
|
3
9
|
## 0.4.21
|
|
4
10
|
|
|
5
11
|
- Pause via spacebar in examples/snake.rb (all versions)
|
data/README.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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 LibUI 0.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 LibUI 0.4.22
|
|
2
2
|
## Prerequisite-Free Ruby Desktop Development GUI Library
|
|
3
3
|
[](http://badge.fury.io/rb/glimmer-dsl-libui)
|
|
4
4
|
[](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
5
5
|
|
|
6
|
-
[
|
|
6
|
+
[**(Fukuoka Ruby Award Competition 2022 Special Award Winner)**](http://www.digitalfukuoka.jp/topics/187?locale=ja)
|
|
7
|
+
|
|
8
|
+
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [LibUI](https://github.com/kojix2/LibUI) is a prerequisite-free [MRI Ruby](https://www.ruby-lang.org) desktop development GUI (Graphical User Interface) library. No need to pre-install any prerequisites. Just install the [gem](https://rubygems.org/gems/glimmer-dsl-libui) and have platform-independent native GUI that just works!
|
|
7
9
|
|
|
8
10
|
Mac | Windows | Linux
|
|
9
11
|
----|---------|------
|
|
@@ -330,13 +332,19 @@ Mac | Windows | Linux
|
|
|
330
332
|
|
|
331
333
|
NOTE: [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) is 100% feature-complete and in beta mode (though the C [libui](https://github.com/andlabs/libui) is still mid-alpha). Please help make better by contributing, adopting for small or low risk projects, and providing feedback. The more feedback and issues you report the better.
|
|
332
334
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
-
|
|
338
|
-
-
|
|
339
|
-
|
|
335
|
+
**[Glimmer](https://rubygems.org/gems/glimmer) DSL Comparison Table:**
|
|
336
|
+
DSL | Platforms | Native? | Vector Graphics? | Pros | Cons | Prereqs
|
|
337
|
+
----|-----------|---------|------------------|------|------|--------
|
|
338
|
+
[Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)](https://github.com/AndyObtiva/glimmer-dsl-swt) | Mac / Windows / Linux | Yes | Yes (Canvas Shape DSL) | Very Mature / Scaffolding / Native Executable Packaging / Custom Widgets | Slow JRuby Startup Time / Heavy Memory Footprint | Java / JRuby
|
|
339
|
+
[Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps)](https://github.com/AndyObtiva/glimmer-dsl-opal) | All Web Browsers | No | Yes (Canvas Shape DSL) | Simpler than All JavaScript Technologies / Auto-Webify Desktop Apps | Setup Process / Only Rails 5 Support for Now | Rails
|
|
340
|
+
[Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-libui) | Mac / Windows / Linux | Yes | Yes (Area API) | Fast Startup Time / Light Memory Footprint | LibUI is an Incomplete Mid-Alpha Only | None Other Than MRI Ruby
|
|
341
|
+
[Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-tk) | Mac / Windows / Linux | Some Native-Themed Widgets (Not Truly Native) | Yes (Canvas) | Fast Startup Time / Light Memory Footprint | Widgets Do Not Look Truly Native, Espcially on Linux | ActiveTcl / MRI Ruby
|
|
342
|
+
[Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-gtk) | Mac / Windows / Linux | Only on Linux | Yes (Cairo) | Complete Access to GNOME Features on Linux (Forte) | Not Native on Mac and Windows | None Other Than MRI Ruby on Linux / Brew Packages on Mac / MSYS & MING Toolchains on Windows / MRI Ruby
|
|
343
|
+
[Glimmer DSL for FX (FOX Toolkit Ruby Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-fx) | Mac (requires XQuartz) / Windows / Linux | No | Yes (Canvas) | No Prerequisites on Windows (Forte Since Binaries Are Included Out of The Box) | Widgets Do Not Look Native / Mac Usage Obtrusively Starts XQuartz | None Other Than MRI Ruby on Windows / XQuarts on Mac / MRI Ruby
|
|
344
|
+
[Glimmer DSL for JFX (JRuby JavaFX Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-jfx) | Mac / Windows / Linux | No | Yes (javafx.scene.shape and javafx.scene.canvas) | Rich in Custom Widgets | Slow JRuby Startup Time / Heavy Memory Footprint / Widgets Do Not Look Native | Java / JRuby / JavaFX SDK
|
|
345
|
+
[Glimmer DSL for Swing (JRuby Swing Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-swing) | Mac / Windows / Linux | No | Yes (Java2D) | Very Mature | Slow JRuby Startup Time / Heavy Memory Footprint / Widgets Do Not Look Native | Java / JRuby
|
|
346
|
+
[Glimmer DSL for XML (& HTML)](https://github.com/AndyObtiva/glimmer-dsl-xml) | All Web Browsers | No | Yes (SVG) | Programmable / Lighter-weight Than Actual XML | XML Elements Are Sometimes Not Well-Named (Many Types of Input) | None
|
|
347
|
+
[Glimmer DSL for CSS](https://github.com/AndyObtiva/glimmer-dsl-css) | All Web Browsers | No | Yes | Programmable | CSS Is Over-Engineered / Too Many Features To Learn | None
|
|
340
348
|
|
|
341
349
|
## Table of Contents
|
|
342
350
|
|
|
@@ -511,7 +519,7 @@ gem install glimmer-dsl-libui
|
|
|
511
519
|
Or install via Bundler `Gemfile`:
|
|
512
520
|
|
|
513
521
|
```ruby
|
|
514
|
-
gem 'glimmer-dsl-libui', '~> 0.4.
|
|
522
|
+
gem 'glimmer-dsl-libui', '~> 0.4.22'
|
|
515
523
|
```
|
|
516
524
|
|
|
517
525
|
Test that installation worked by running the [Meta-Example](#examples):
|
|
@@ -581,13 +589,14 @@ w.set_title 'aloha'
|
|
|
581
589
|
puts w.title # => aloha
|
|
582
590
|
```
|
|
583
591
|
|
|
584
|
-
Controls are wrapped as Ruby proxy objects, having a `#libui` method to obtain the wrapped [LibUI](https://github.com/kojix2/LibUI) Fiddle pointer object. Ruby proxy objects rely on composition (via [Proxy Design Pattern](https://en.wikipedia.org/wiki/Proxy_pattern)) instead of inheritance to shield consumers from having to deal with lower-level details unless absolutely needed.
|
|
592
|
+
Controls are wrapped as Ruby proxy objects, having a `#libui` method to obtain the wrapped [LibUI](https://github.com/kojix2/LibUI) Fiddle pointer object. Ruby proxy objects rely on composition (via [Proxy Design Pattern](https://en.wikipedia.org/wiki/Proxy_pattern)) instead of inheritance to shield consumers from having to deal with lower-level details unless absolutely needed. That said, you can invoke any [LibUI operation](#libui-operations) on the Glimmer proxy object directly and it gets proxied automatically to the wrapped Fiddle pointer object (e.g. `window_proxy.title` gets proxied to `LibUI.window_title(window_proxy.libui).to_s` automatically), so you rarely have to refer to the wrapped `#libui` Fiddle pointer object directly.
|
|
585
593
|
|
|
586
594
|
Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
|
|
587
595
|
|
|
588
596
|
```ruby
|
|
589
597
|
w = window('hello world') # => #<Glimmer::LibUI::WindowProxy:0x00007fde4ea39fb0
|
|
590
598
|
w.libui # => #<Fiddle::Pointer:0x00007fde53997980 ptr=0x00007fde51352a60 size=0 free=0x0000000000000000>
|
|
599
|
+
w.title == LibUI.window_title(w.libui).to_s # => true
|
|
591
600
|
```
|
|
592
601
|
|
|
593
602
|
### Supported Keywords
|
|
@@ -9313,6 +9322,8 @@ TinyMidiPlayer.new
|
|
|
9313
9322
|
|
|
9314
9323
|
Snake provides an example of building a desktop application [test-first](/spec/examples/snake/model/game_spec.rb) following the MVP ([Model](/examples/snake/model/game.rb) / [View](/examples/snake.rb) / [Presenter](/examples/snake/presenter/grid.rb)) architectural pattern.
|
|
9315
9324
|
|
|
9325
|
+
Use arrows to move and spacebar to pause/resume.
|
|
9326
|
+
|
|
9316
9327
|
[examples/snake.rb](examples/snake.rb)
|
|
9317
9328
|
|
|
9318
9329
|
Run with this command from the root of the project if you cloned the project:
|
|
@@ -9553,7 +9564,7 @@ ruby -r glimmer-dsl-libui -e "require 'examples/tetris'"
|
|
|
9553
9564
|
|
|
9554
9565
|
Mac | Windows | Linux
|
|
9555
9566
|
----|---------|------
|
|
9556
|
-

|
|
9567
|
+
 |  | 
|
|
9557
9568
|
|
|
9558
9569
|
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
|
9559
9570
|
|
|
@@ -9631,18 +9642,31 @@ class Tetris
|
|
|
9631
9642
|
|
|
9632
9643
|
Model::Game::PREVIEW_PLAYFIELD_HEIGHT.times do |row|
|
|
9633
9644
|
Model::Game::PREVIEW_PLAYFIELD_WIDTH.times do |column|
|
|
9634
|
-
|
|
9645
|
+
preview_updater = proc do
|
|
9635
9646
|
Glimmer::LibUI.queue_main do
|
|
9647
|
+
new_color = @game.preview_playfield[row][column].color
|
|
9636
9648
|
color = Glimmer::LibUI.interpret_color(new_color)
|
|
9637
9649
|
block = @preview_playfield_blocks[row][column]
|
|
9638
|
-
|
|
9639
|
-
|
|
9640
|
-
|
|
9641
|
-
|
|
9642
|
-
|
|
9643
|
-
|
|
9650
|
+
if @game.show_preview_tetromino?
|
|
9651
|
+
block[:background_square].fill = color
|
|
9652
|
+
block[:top_bevel_edge].fill = {r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT}
|
|
9653
|
+
block[:right_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
|
|
9654
|
+
block[:bottom_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
|
|
9655
|
+
block[:left_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
|
|
9656
|
+
block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : color
|
|
9657
|
+
else
|
|
9658
|
+
transparent_color = {r: 255, g: 255, b: 255, a: 0}
|
|
9659
|
+
block[:background_square].fill = transparent_color
|
|
9660
|
+
block[:top_bevel_edge].fill = transparent_color
|
|
9661
|
+
block[:right_bevel_edge].fill = transparent_color
|
|
9662
|
+
block[:bottom_bevel_edge].fill = transparent_color
|
|
9663
|
+
block[:left_bevel_edge].fill = transparent_color
|
|
9664
|
+
block[:border_square].stroke = transparent_color
|
|
9665
|
+
end
|
|
9644
9666
|
end
|
|
9645
9667
|
end
|
|
9668
|
+
observe(@game.preview_playfield[row][column], :color, &preview_updater)
|
|
9669
|
+
observe(@game, :show_preview_tetromino, &preview_updater)
|
|
9646
9670
|
end
|
|
9647
9671
|
end
|
|
9648
9672
|
|
|
@@ -9690,6 +9714,12 @@ class Tetris
|
|
|
9690
9714
|
}
|
|
9691
9715
|
|
|
9692
9716
|
menu('View') {
|
|
9717
|
+
check_menu_item('Show Next Block Preview') {
|
|
9718
|
+
checked <=> [@game, :show_preview_tetromino]
|
|
9719
|
+
}
|
|
9720
|
+
|
|
9721
|
+
separator_menu_item
|
|
9722
|
+
|
|
9693
9723
|
menu_item('Show High Scores') {
|
|
9694
9724
|
on_clicked do
|
|
9695
9725
|
show_high_scores
|
|
@@ -9701,18 +9731,20 @@ class Tetris
|
|
|
9701
9731
|
@game.clear_high_scores!
|
|
9702
9732
|
}
|
|
9703
9733
|
}
|
|
9734
|
+
|
|
9735
|
+
separator_menu_item
|
|
9704
9736
|
}
|
|
9705
9737
|
|
|
9706
9738
|
menu('Options') {
|
|
9707
|
-
radio_menu_item('Instant Down on Up Arrow') {
|
|
9739
|
+
radio_menu_item('Instant Down on Up Arrow') {
|
|
9708
9740
|
checked <=> [@game, :instant_down_on_up]
|
|
9709
9741
|
}
|
|
9710
9742
|
|
|
9711
|
-
radio_menu_item('Rotate Right on Up Arrow') {
|
|
9743
|
+
radio_menu_item('Rotate Right on Up Arrow') {
|
|
9712
9744
|
checked <=> [@game, :rotate_right_on_up]
|
|
9713
9745
|
}
|
|
9714
9746
|
|
|
9715
|
-
radio_menu_item('Rotate Left on Up Arrow') {
|
|
9747
|
+
radio_menu_item('Rotate Left on Up Arrow') {
|
|
9716
9748
|
checked <=> [@game, :rotate_left_on_up]
|
|
9717
9749
|
}
|
|
9718
9750
|
}
|
|
@@ -9759,7 +9791,7 @@ class Tetris
|
|
|
9759
9791
|
block = {}
|
|
9760
9792
|
bevel_pixel_size = 0.16 * block_size.to_f
|
|
9761
9793
|
color = Glimmer::LibUI.interpret_color(Model::Block::COLOR_CLEAR)
|
|
9762
|
-
area {
|
|
9794
|
+
block[:area] = area {
|
|
9763
9795
|
block[:background_square] = square(0, 0, block_size) {
|
|
9764
9796
|
fill color
|
|
9765
9797
|
}
|
|
@@ -9835,12 +9867,6 @@ class Tetris
|
|
|
9835
9867
|
|
|
9836
9868
|
def score_board(block_size: , &extra_content)
|
|
9837
9869
|
vertical_box {
|
|
9838
|
-
horizontal_box {
|
|
9839
|
-
label # filler
|
|
9840
|
-
@preview_playfield_blocks = playfield(playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: block_size)
|
|
9841
|
-
label # filler
|
|
9842
|
-
}
|
|
9843
|
-
|
|
9844
9870
|
horizontal_box {
|
|
9845
9871
|
label # filler
|
|
9846
9872
|
grid {
|
|
@@ -9881,6 +9907,12 @@ class Tetris
|
|
|
9881
9907
|
}
|
|
9882
9908
|
label # filler
|
|
9883
9909
|
}
|
|
9910
|
+
|
|
9911
|
+
horizontal_box {
|
|
9912
|
+
label # filler
|
|
9913
|
+
@preview_playfield_blocks = playfield(playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: block_size)
|
|
9914
|
+
label # filler
|
|
9915
|
+
}
|
|
9884
9916
|
|
|
9885
9917
|
extra_content&.call
|
|
9886
9918
|
}
|
|
@@ -10430,6 +10462,10 @@ https://github.com/AndyObtiva/befunge98/tree/gui
|
|
|
10430
10462
|
|
|
10431
10463
|
https://github.com/iraamaro/i3off-gtk-ruby
|
|
10432
10464
|
|
|
10465
|
+
### Chess
|
|
10466
|
+
|
|
10467
|
+
https://github.com/mikeweber/chess
|
|
10468
|
+
|
|
10433
10469
|
## Process
|
|
10434
10470
|
|
|
10435
10471
|
[Glimmer Process](https://github.com/AndyObtiva/glimmer/blob/master/PROCESS.md)
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.4.
|
|
1
|
+
0.4.22
|
|
@@ -36,21 +36,27 @@ class Tetris
|
|
|
36
36
|
PREVIEW_PLAYFIELD_WIDTH = 4
|
|
37
37
|
PREVIEW_PLAYFIELD_HEIGHT = 2
|
|
38
38
|
SCORE_MULTIPLIER = {1 => 40, 2 => 100, 3 => 300, 4 => 1200}
|
|
39
|
+
UP_ARROW_ACTIONS = %i[instant_down rotate_right rotate_left]
|
|
40
|
+
SPEEDS = %i[snail sloth turtle rabbit gorilla bear horse gazelle cheetah falcon]
|
|
41
|
+
SPEED_INITIAL_DELAYS = SPEEDS.each_with_index.inject({}) {|hash, speed_index_pair| hash.merge(speed_index_pair.first => 1.1 - speed_index_pair.last*(0.1)) }
|
|
39
42
|
|
|
40
43
|
attr_reader :playfield_width, :playfield_height
|
|
41
|
-
attr_accessor :game_over, :paused, :preview_tetromino, :lines, :score, :level, :high_scores, :beeping, :added_high_score, :show_high_scores, :up_arrow_action
|
|
44
|
+
attr_accessor :game_over, :paused, :preview_tetromino, :lines, :score, :level, :high_scores, :beeping, :added_high_score, :show_high_scores, :up_arrow_action, :show_preview_tetromino, :initial_delay
|
|
42
45
|
alias game_over? game_over
|
|
43
46
|
alias paused? paused
|
|
44
47
|
alias beeping? beeping
|
|
45
48
|
alias added_high_score? added_high_score
|
|
49
|
+
alias show_preview_tetromino? show_preview_tetromino
|
|
46
50
|
|
|
47
51
|
def initialize(playfield_width = PLAYFIELD_WIDTH, playfield_height = PLAYFIELD_HEIGHT)
|
|
52
|
+
@initial_delay = SPEED_INITIAL_DELAYS[:snail]
|
|
48
53
|
@playfield_width = playfield_width
|
|
49
54
|
@playfield_height = playfield_height
|
|
50
55
|
@high_scores = []
|
|
51
56
|
@show_high_scores = false
|
|
52
57
|
@beeping = true
|
|
53
58
|
@up_arrow_action = :rotate_left
|
|
59
|
+
@show_preview_tetromino = true
|
|
54
60
|
load_high_scores!
|
|
55
61
|
end
|
|
56
62
|
|
|
@@ -200,35 +206,31 @@ class Tetris
|
|
|
200
206
|
end
|
|
201
207
|
|
|
202
208
|
def delay
|
|
203
|
-
[
|
|
209
|
+
[@initial_delay - (level.to_i * 0.1), 0.001].max
|
|
204
210
|
end
|
|
205
211
|
|
|
206
212
|
def beep
|
|
207
213
|
@beeper&.call if beeping
|
|
208
214
|
end
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
def rotate_right_on_up=(value)
|
|
219
|
-
self.up_arrow_action = :rotate_right if value
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
def rotate_right_on_up
|
|
223
|
-
self.up_arrow_action == :rotate_right
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
def rotate_left_on_up=(value)
|
|
227
|
-
self.up_arrow_action = :rotate_left if value
|
|
215
|
+
|
|
216
|
+
SPEED_INITIAL_DELAYS.each do |speed, speed_initial_day|
|
|
217
|
+
define_method("speed_#{speed}=") do |is_true|
|
|
218
|
+
self.initial_delay = speed_initial_day if is_true
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
define_method("speed_#{speed}") do
|
|
222
|
+
self.initial_delay == speed_initial_day
|
|
223
|
+
end
|
|
228
224
|
end
|
|
229
225
|
|
|
230
|
-
|
|
231
|
-
|
|
226
|
+
UP_ARROW_ACTIONS.each do |up_arrow_action_symbol|
|
|
227
|
+
define_method("#{up_arrow_action_symbol}_on_up=") do |is_true|
|
|
228
|
+
self.up_arrow_action = up_arrow_action_symbol if is_true
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
define_method("#{up_arrow_action_symbol}_on_up") do
|
|
232
|
+
self.up_arrow_action == up_arrow_action_symbol
|
|
233
|
+
end
|
|
232
234
|
end
|
|
233
235
|
|
|
234
236
|
def reset_tetrominoes
|
data/examples/tetris.rb
CHANGED
|
@@ -5,7 +5,7 @@ require_relative 'tetris/model/game'
|
|
|
5
5
|
class Tetris
|
|
6
6
|
include Glimmer
|
|
7
7
|
|
|
8
|
-
BLOCK_SIZE = 25
|
|
8
|
+
BLOCK_SIZE = OS.linux? ? 28 : 25
|
|
9
9
|
BEVEL_CONSTANT = 20
|
|
10
10
|
COLOR_GRAY = {r: 192, g: 192, b: 192}
|
|
11
11
|
|
|
@@ -71,18 +71,31 @@ class Tetris
|
|
|
71
71
|
|
|
72
72
|
Model::Game::PREVIEW_PLAYFIELD_HEIGHT.times do |row|
|
|
73
73
|
Model::Game::PREVIEW_PLAYFIELD_WIDTH.times do |column|
|
|
74
|
-
|
|
74
|
+
preview_updater = proc do
|
|
75
75
|
Glimmer::LibUI.queue_main do
|
|
76
|
+
new_color = @game.preview_playfield[row][column].color
|
|
76
77
|
color = Glimmer::LibUI.interpret_color(new_color)
|
|
77
78
|
block = @preview_playfield_blocks[row][column]
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
if @game.show_preview_tetromino?
|
|
80
|
+
block[:background_square].fill = color
|
|
81
|
+
block[:top_bevel_edge].fill = {r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT}
|
|
82
|
+
block[:right_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
|
|
83
|
+
block[:bottom_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
|
|
84
|
+
block[:left_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
|
|
85
|
+
block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : color
|
|
86
|
+
else
|
|
87
|
+
transparent_color = {r: 255, g: 255, b: 255, a: 0}
|
|
88
|
+
block[:background_square].fill = transparent_color
|
|
89
|
+
block[:top_bevel_edge].fill = transparent_color
|
|
90
|
+
block[:right_bevel_edge].fill = transparent_color
|
|
91
|
+
block[:bottom_bevel_edge].fill = transparent_color
|
|
92
|
+
block[:left_bevel_edge].fill = transparent_color
|
|
93
|
+
block[:border_square].stroke = transparent_color
|
|
94
|
+
end
|
|
84
95
|
end
|
|
85
96
|
end
|
|
97
|
+
observe(@game.preview_playfield[row][column], :color, &preview_updater)
|
|
98
|
+
observe(@game, :show_preview_tetromino, &preview_updater)
|
|
86
99
|
end
|
|
87
100
|
end
|
|
88
101
|
|
|
@@ -130,6 +143,12 @@ class Tetris
|
|
|
130
143
|
}
|
|
131
144
|
|
|
132
145
|
menu('View') {
|
|
146
|
+
check_menu_item('Show Next Block Preview') {
|
|
147
|
+
checked <=> [@game, :show_preview_tetromino]
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
separator_menu_item
|
|
151
|
+
|
|
133
152
|
menu_item('Show High Scores') {
|
|
134
153
|
on_clicked do
|
|
135
154
|
show_high_scores
|
|
@@ -141,18 +160,28 @@ class Tetris
|
|
|
141
160
|
@game.clear_high_scores!
|
|
142
161
|
}
|
|
143
162
|
}
|
|
163
|
+
|
|
164
|
+
separator_menu_item
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
menu('Speed') {
|
|
168
|
+
Model::Game::SPEEDS.each do |speed|
|
|
169
|
+
radio_menu_item(speed.to_s.capitalize) {
|
|
170
|
+
checked <=> [@game, "speed_#{speed}"]
|
|
171
|
+
}
|
|
172
|
+
end
|
|
144
173
|
}
|
|
145
174
|
|
|
146
175
|
menu('Options') {
|
|
147
|
-
radio_menu_item('Instant Down on Up Arrow') {
|
|
176
|
+
radio_menu_item('Instant Down on Up Arrow') {
|
|
148
177
|
checked <=> [@game, :instant_down_on_up]
|
|
149
178
|
}
|
|
150
179
|
|
|
151
|
-
radio_menu_item('Rotate Right on Up Arrow') {
|
|
180
|
+
radio_menu_item('Rotate Right on Up Arrow') {
|
|
152
181
|
checked <=> [@game, :rotate_right_on_up]
|
|
153
182
|
}
|
|
154
183
|
|
|
155
|
-
radio_menu_item('Rotate Left on Up Arrow') {
|
|
184
|
+
radio_menu_item('Rotate Left on Up Arrow') {
|
|
156
185
|
checked <=> [@game, :rotate_left_on_up]
|
|
157
186
|
}
|
|
158
187
|
}
|
|
@@ -199,7 +228,7 @@ class Tetris
|
|
|
199
228
|
block = {}
|
|
200
229
|
bevel_pixel_size = 0.16 * block_size.to_f
|
|
201
230
|
color = Glimmer::LibUI.interpret_color(Model::Block::COLOR_CLEAR)
|
|
202
|
-
area {
|
|
231
|
+
block[:area] = area {
|
|
203
232
|
block[:background_square] = square(0, 0, block_size) {
|
|
204
233
|
fill color
|
|
205
234
|
}
|
|
@@ -275,12 +304,6 @@ class Tetris
|
|
|
275
304
|
|
|
276
305
|
def score_board(block_size: , &extra_content)
|
|
277
306
|
vertical_box {
|
|
278
|
-
horizontal_box {
|
|
279
|
-
label # filler
|
|
280
|
-
@preview_playfield_blocks = playfield(playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: block_size)
|
|
281
|
-
label # filler
|
|
282
|
-
}
|
|
283
|
-
|
|
284
307
|
horizontal_box {
|
|
285
308
|
label # filler
|
|
286
309
|
grid {
|
|
@@ -321,6 +344,12 @@ class Tetris
|
|
|
321
344
|
}
|
|
322
345
|
label # filler
|
|
323
346
|
}
|
|
347
|
+
|
|
348
|
+
horizontal_box {
|
|
349
|
+
label # filler
|
|
350
|
+
@preview_playfield_blocks = playfield(playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: block_size)
|
|
351
|
+
label # filler
|
|
352
|
+
}
|
|
324
353
|
|
|
325
354
|
extra_content&.call
|
|
326
355
|
}
|
|
@@ -329,9 +358,11 @@ class Tetris
|
|
|
329
358
|
def start_moving_tetrominos_down
|
|
330
359
|
unless @tetrominos_start_moving_down
|
|
331
360
|
@tetrominos_start_moving_down = true
|
|
332
|
-
|
|
361
|
+
tetromino_move = proc do
|
|
333
362
|
@game.down! if !@game.game_over? && !@game.paused?
|
|
363
|
+
Glimmer::LibUI.timer(@game.delay, repeat: false, &tetromino_move)
|
|
334
364
|
end
|
|
365
|
+
Glimmer::LibUI.timer(@game.delay, repeat: false, &tetromino_move)
|
|
335
366
|
end
|
|
336
367
|
end
|
|
337
368
|
|
data/glimmer-dsl-libui.gemspec
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: glimmer-dsl-libui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.22
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andy Maleh
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-02-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: glimmer
|