glimmer-dsl-libui 0.2.19 → 0.2.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +115 -17
- data/VERSION +1 -1
- data/examples/tetris/model/game.rb +2 -0
- data/examples/tetris.rb +105 -13
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/libui/control_proxy/window_proxy.rb +40 -1
- 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: 70f45c14b2e19345bb8ca1a16409260ef9835daf69053febcc6e28309a58618d
|
4
|
+
data.tar.gz: 06e4d212588dff9195b6cc6df82bcca4f6c1fcc1f401abc5d174ef88aa20164a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18a072c532d014a9849e96c6add0a7279200384c11478c99c2271e6f34cd30c2035d751f4644e8eb1f78f847497d1be0126c795efc32582ce22727c0b71ab029
|
7
|
+
data.tar.gz: efe76c9b3c7439eb27b2b8c1159a5d133966b8282b130c983544bf60b1df41134267dbdc59a3b08e94d6491dffbe9e0a9d54a9afcad89701f68e3c17fbd6bcc4
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.2.20
|
4
|
+
|
5
|
+
- Improve examples/tetris.rb with menus, high score dialog, and options
|
6
|
+
- Prevent examples/tetris.rb `window` from being resized
|
7
|
+
- Support `window` `resizable` property (`resizable false` means one cannot resize `window`)
|
8
|
+
- Support calling `window.content_size = [x, y]` as an alternative to `window.set_content_size(x, y)`
|
9
|
+
- Fix issue with hooking `on_content_size_changed` listener to `window`
|
10
|
+
- Fix issue with using `window` `content_size` property getter
|
11
|
+
|
3
12
|
## 0.2.19
|
4
13
|
|
5
14
|
- Improve examples/tetris.rb with a score board (indicating next Tetromino, score, level, and lines)
|
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 LibUI 0.2.
|
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.2.20
|
2
2
|
## Prerequisite-Free Ruby Desktop Development GUI Library
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-libui.svg)](http://badge.fury.io/rb/glimmer-dsl-libui)
|
4
4
|
[![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
@@ -370,7 +370,7 @@ gem install glimmer-dsl-libui
|
|
370
370
|
Or install via Bundler `Gemfile`:
|
371
371
|
|
372
372
|
```ruby
|
373
|
-
gem 'glimmer-dsl-libui', '~> 0.2.
|
373
|
+
gem 'glimmer-dsl-libui', '~> 0.2.20'
|
374
374
|
```
|
375
375
|
|
376
376
|
Add `require 'glimmer-dsl-libui'` at the top, and then `include Glimmer` into the top-level main object for testing or into an actual class for serious usage.
|
@@ -456,6 +456,7 @@ Keyword(Args) | Properties | Listeners
|
|
456
456
|
`checkbox_column(name as String)` | `editable` (Boolean) | None
|
457
457
|
`checkbox_text_column(name as String)` | `editable` (Boolean), `editable_checkbox` (Boolean), `editable_text` (Boolean) | None
|
458
458
|
`checkbox_text_color_column(name as String)` | `editable` (Boolean), `editable_checkbox` (Boolean), `editable_text` (Boolean) | None
|
459
|
+
`check_menu_item(text as String)` | `checked` (Boolean) | `on_clicked`
|
459
460
|
`combobox` | `items` (`Array` of `String`), `selected` (`Integer`) | `on_selected`
|
460
461
|
`color_button` | `color` (Array of `red` as `Float`, `green` as `Float`, `blue` as `Float`, `alpha` as `Float`), `red` as `Float`, `green` as `Float`, `blue` as `Float`, `alpha` as `Float` | `on_changed`
|
461
462
|
`date_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`, `mday` as `Integer`, `mon` as `Integer`, `year` as `Integer`, `wday` as `Integer`, `yday` as `Integer`, `dst` as Boolean) | `on_changed`
|
@@ -478,7 +479,7 @@ Keyword(Args) | Properties | Listeners
|
|
478
479
|
`line(x as Numeric, y as Numeric)` | `x` (`Numeric`), `y` (`Numeric`) | None
|
479
480
|
`matrix(m11 = nil as Numeric, m12 = nil as Numeric, m21 = nil as Numeric, m22 = nil as Numeric, m31 = nil as Numeric, m32 = nil as Numeric)` | `m11` (`Numeric`), `m12` (`Numeric`), `m21` (`Numeric`), `m22` (`Numeric`), `m31` (`Numeric`), `m32` (`Numeric`) | None
|
480
481
|
`menu(text as String)` | None | None
|
481
|
-
`menu_item(text as String)` |
|
482
|
+
`menu_item(text as String)` | None | `on_clicked`
|
482
483
|
`message_box` (alias for `msg_box`; see for arguments) | None | None
|
483
484
|
`message_box_error` (alias for `msg_box_error`; see for arguments) | None | None
|
484
485
|
`multiline_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
|
@@ -497,6 +498,7 @@ Keyword(Args) | Properties | Listeners
|
|
497
498
|
`radio_buttons` | `selected` (`Integer`) | `on_selected`
|
498
499
|
`rectangle(x as Numeric, y as Numeric, width as Numeric, height as Numeric)` | `x` (`Numeric`), `y` (`Numeric`), `width` (`Numeric`), `height` (`Numeric`) | None
|
499
500
|
`search_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
|
501
|
+
`separator_menu_item` | None | None
|
500
502
|
`slider(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
|
501
503
|
`spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
|
502
504
|
`square(x as Numeric, y as Numeric, length as Numeric)` | `x` (`Numeric`), `y` (`Numeric`), `length` (`Numeric`) | None
|
@@ -510,7 +512,7 @@ Keyword(Args) | Properties | Listeners
|
|
510
512
|
`time_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`) | `on_changed`
|
511
513
|
`vertical_box` | `padded` (Boolean) | None
|
512
514
|
`vertical_separator` | None | None
|
513
|
-
`window(title as String, width as Integer, height as Integer, has_menubar as Boolean)` | `borderless` (Boolean), `content_size` (width `Numeric`, height `Numeric`), `fullscreen` (Boolean), `margined` (Boolean), `title` (`String`) | `on_closing`, `on_content_size_changed`, `on_destroy`
|
515
|
+
`window(title as String, width as Integer, height as Integer, has_menubar as Boolean)` | `borderless` (Boolean), `content_size` (width `Numeric`, height `Numeric`), `fullscreen` (Boolean), `margined` (Boolean), `title` (`String`), `resizable` (Boolean) | `on_closing`, `on_content_size_changed`, `on_destroy`
|
514
516
|
|
515
517
|
### Common Control Properties
|
516
518
|
- `enabled` (Boolean)
|
@@ -6234,6 +6236,8 @@ window('Method-Based Custom Keyword') {
|
|
6234
6236
|
|
6235
6237
|
### Tetris
|
6236
6238
|
|
6239
|
+
Glimmer Tetris utilizes many small areas to represent Tetromino blocks because this ensures smaller redraws per tetromino block color change, thus higher performance than having one area that gets redrawn on every little change.
|
6240
|
+
|
6237
6241
|
[examples/tetris.rb](examples/tetris.rb)
|
6238
6242
|
|
6239
6243
|
Run with this command from the root of the project if you cloned the project:
|
@@ -6254,6 +6258,8 @@ Mac
|
|
6254
6258
|
|
6255
6259
|
![glimmer-dsl-libui-mac-tetris-game-over.png](images/glimmer-dsl-libui-mac-tetris-game-over.png)
|
6256
6260
|
|
6261
|
+
![glimmer-dsl-libui-mac-tetris-high-scores.png](images/glimmer-dsl-libui-mac-tetris-high-scores.png)
|
6262
|
+
|
6257
6263
|
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
6258
6264
|
|
6259
6265
|
```ruby
|
@@ -6268,8 +6274,6 @@ class Tetris
|
|
6268
6274
|
BEVEL_CONSTANT = 20
|
6269
6275
|
COLOR_GRAY = {r: 192, g: 192, b: 192}
|
6270
6276
|
|
6271
|
-
attr_reader :game
|
6272
|
-
|
6273
6277
|
def initialize
|
6274
6278
|
@game = Model::Game.new
|
6275
6279
|
end
|
@@ -6282,8 +6286,11 @@ class Tetris
|
|
6282
6286
|
end
|
6283
6287
|
|
6284
6288
|
def create_gui
|
6289
|
+
menu_bar
|
6290
|
+
|
6285
6291
|
@main_window = window('Glimmer Tetris') {
|
6286
6292
|
content_size Model::Game::PLAYFIELD_WIDTH * BLOCK_SIZE, Model::Game::PLAYFIELD_HEIGHT * BLOCK_SIZE + 98
|
6293
|
+
resizable false
|
6287
6294
|
|
6288
6295
|
vertical_box {
|
6289
6296
|
label { # filler
|
@@ -6302,8 +6309,10 @@ class Tetris
|
|
6302
6309
|
def register_observers
|
6303
6310
|
Glimmer::DataBinding::Observer.proc do |game_over|
|
6304
6311
|
if game_over
|
6312
|
+
@pause_menu_item.enabled = false
|
6305
6313
|
show_game_over_dialog
|
6306
6314
|
else
|
6315
|
+
@pause_menu_item.enabled = true
|
6307
6316
|
start_moving_tetrominos_down
|
6308
6317
|
end
|
6309
6318
|
end.observe(@game, :game_over)
|
@@ -6361,6 +6370,76 @@ class Tetris
|
|
6361
6370
|
end.observe(@game, :level)
|
6362
6371
|
end
|
6363
6372
|
|
6373
|
+
def menu_bar
|
6374
|
+
menu('Game') {
|
6375
|
+
@pause_menu_item = check_menu_item('Pause') {
|
6376
|
+
enabled false
|
6377
|
+
|
6378
|
+
on_clicked do
|
6379
|
+
@game.paused = @pause_menu_item.checked?
|
6380
|
+
end
|
6381
|
+
}
|
6382
|
+
menu_item('Restart') {
|
6383
|
+
on_clicked do
|
6384
|
+
@game.restart!
|
6385
|
+
end
|
6386
|
+
}
|
6387
|
+
separator_menu_item
|
6388
|
+
menu_item('Exit') {
|
6389
|
+
on_clicked do
|
6390
|
+
exit(0)
|
6391
|
+
end
|
6392
|
+
}
|
6393
|
+
quit_menu_item if OS.mac?
|
6394
|
+
}
|
6395
|
+
|
6396
|
+
menu('View') {
|
6397
|
+
menu_item('Show High Scores') {
|
6398
|
+
on_clicked do
|
6399
|
+
show_high_scores
|
6400
|
+
end
|
6401
|
+
}
|
6402
|
+
menu_item('Clear High Scores') {
|
6403
|
+
on_clicked {
|
6404
|
+
@game.clear_high_scores!
|
6405
|
+
}
|
6406
|
+
}
|
6407
|
+
}
|
6408
|
+
|
6409
|
+
menu('Options') {
|
6410
|
+
radio_menu_item('Instant Down on Up Arrow') {
|
6411
|
+
on_clicked do
|
6412
|
+
@game.instant_down_on_up = true
|
6413
|
+
end
|
6414
|
+
}
|
6415
|
+
radio_menu_item('Rotate Right on Up Arrow') {
|
6416
|
+
on_clicked do
|
6417
|
+
@game.rotate_right_on_up = true
|
6418
|
+
end
|
6419
|
+
}
|
6420
|
+
radio_menu_item('Rotate Left on Up Arrow') {
|
6421
|
+
on_clicked do
|
6422
|
+
@game.rotate_left_on_up = true
|
6423
|
+
end
|
6424
|
+
}
|
6425
|
+
}
|
6426
|
+
|
6427
|
+
menu('Help') {
|
6428
|
+
if OS.mac?
|
6429
|
+
about_menu_item {
|
6430
|
+
on_clicked do
|
6431
|
+
show_about_dialog
|
6432
|
+
end
|
6433
|
+
}
|
6434
|
+
end
|
6435
|
+
menu_item('About') {
|
6436
|
+
on_clicked do
|
6437
|
+
show_about_dialog
|
6438
|
+
end
|
6439
|
+
}
|
6440
|
+
}
|
6441
|
+
end
|
6442
|
+
|
6364
6443
|
def playfield(playfield_width: , playfield_height: , block_size: , &extra_content)
|
6365
6444
|
blocks = []
|
6366
6445
|
vertical_box {
|
@@ -6421,26 +6500,26 @@ class Tetris
|
|
6421
6500
|
on_key_down do |key_event|
|
6422
6501
|
case key_event
|
6423
6502
|
in ext_key: :down
|
6424
|
-
game.down!
|
6503
|
+
@game.down!
|
6425
6504
|
in key: ' '
|
6426
|
-
game.down!(instant: true)
|
6505
|
+
@game.down!(instant: true)
|
6427
6506
|
in ext_key: :up
|
6428
|
-
case game.up_arrow_action
|
6507
|
+
case @game.up_arrow_action
|
6429
6508
|
when :instant_down
|
6430
|
-
game.down!(instant: true)
|
6509
|
+
@game.down!(instant: true)
|
6431
6510
|
when :rotate_right
|
6432
|
-
game.rotate!(:right)
|
6511
|
+
@game.rotate!(:right)
|
6433
6512
|
when :rotate_left
|
6434
|
-
game.rotate!(:left)
|
6513
|
+
@game.rotate!(:left)
|
6435
6514
|
end
|
6436
6515
|
in ext_key: :left
|
6437
|
-
game.left!
|
6516
|
+
@game.left!
|
6438
6517
|
in ext_key: :right
|
6439
|
-
game.right!
|
6518
|
+
@game.right!
|
6440
6519
|
in modifier: :shift
|
6441
|
-
game.rotate!(:right)
|
6520
|
+
@game.rotate!(:right)
|
6442
6521
|
in modifier: :control
|
6443
|
-
game.rotate!(:left)
|
6522
|
+
@game.rotate!(:left)
|
6444
6523
|
else
|
6445
6524
|
# Do Nothing
|
6446
6525
|
end
|
@@ -6512,10 +6591,29 @@ class Tetris
|
|
6512
6591
|
|
6513
6592
|
def show_game_over_dialog
|
6514
6593
|
Glimmer::LibUI.queue_main do
|
6515
|
-
msg_box('Game Over', "Score: #{@game.high_scores.first.score}\nLines: #{@game.high_scores.first.lines}\nLevel: #{@game.high_scores.first.level}")
|
6594
|
+
msg_box('Game Over!', "Score: #{@game.high_scores.first.score}\nLines: #{@game.high_scores.first.lines}\nLevel: #{@game.high_scores.first.level}")
|
6516
6595
|
@game.restart!
|
6517
6596
|
end
|
6518
6597
|
end
|
6598
|
+
|
6599
|
+
def show_high_scores
|
6600
|
+
Glimmer::LibUI.queue_main do
|
6601
|
+
if @game.high_scores.empty?
|
6602
|
+
high_scores_string = "No games have been scored yet."
|
6603
|
+
else
|
6604
|
+
high_scores_string = @game.high_scores.map do |high_score|
|
6605
|
+
"#{high_score.name} | Score: #{high_score.score} | Lines: #{high_score.lines} | Level: #{high_score.level}"
|
6606
|
+
end.join("\n")
|
6607
|
+
end
|
6608
|
+
msg_box('High Scores', high_scores_string)
|
6609
|
+
end
|
6610
|
+
end
|
6611
|
+
|
6612
|
+
def show_about_dialog
|
6613
|
+
Glimmer::LibUI.queue_main do
|
6614
|
+
msg_box('About', 'Glimmer Tetris - Glimmer DSL for LibUI Example - Copyright (c) 2021 Andy Maleh')
|
6615
|
+
end
|
6616
|
+
end
|
6519
6617
|
end
|
6520
6618
|
|
6521
6619
|
Tetris.new.launch
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.20
|
@@ -85,11 +85,13 @@ class Tetris
|
|
85
85
|
|
86
86
|
def clear_high_scores!
|
87
87
|
high_scores.clear
|
88
|
+
save_high_scores!
|
88
89
|
end
|
89
90
|
|
90
91
|
def add_high_score!
|
91
92
|
self.added_high_score = true
|
92
93
|
high_scores.prepend(PastGame.new("Player #{high_scores.count + 1}", score, lines, level))
|
94
|
+
save_high_scores!
|
93
95
|
end
|
94
96
|
|
95
97
|
def save_high_scores!
|
data/examples/tetris.rb
CHANGED
@@ -9,8 +9,6 @@ class Tetris
|
|
9
9
|
BEVEL_CONSTANT = 20
|
10
10
|
COLOR_GRAY = {r: 192, g: 192, b: 192}
|
11
11
|
|
12
|
-
attr_reader :game
|
13
|
-
|
14
12
|
def initialize
|
15
13
|
@game = Model::Game.new
|
16
14
|
end
|
@@ -23,8 +21,11 @@ class Tetris
|
|
23
21
|
end
|
24
22
|
|
25
23
|
def create_gui
|
24
|
+
menu_bar
|
25
|
+
|
26
26
|
@main_window = window('Glimmer Tetris') {
|
27
27
|
content_size Model::Game::PLAYFIELD_WIDTH * BLOCK_SIZE, Model::Game::PLAYFIELD_HEIGHT * BLOCK_SIZE + 98
|
28
|
+
resizable false
|
28
29
|
|
29
30
|
vertical_box {
|
30
31
|
label { # filler
|
@@ -43,8 +44,10 @@ class Tetris
|
|
43
44
|
def register_observers
|
44
45
|
Glimmer::DataBinding::Observer.proc do |game_over|
|
45
46
|
if game_over
|
47
|
+
@pause_menu_item.enabled = false
|
46
48
|
show_game_over_dialog
|
47
49
|
else
|
50
|
+
@pause_menu_item.enabled = true
|
48
51
|
start_moving_tetrominos_down
|
49
52
|
end
|
50
53
|
end.observe(@game, :game_over)
|
@@ -102,6 +105,76 @@ class Tetris
|
|
102
105
|
end.observe(@game, :level)
|
103
106
|
end
|
104
107
|
|
108
|
+
def menu_bar
|
109
|
+
menu('Game') {
|
110
|
+
@pause_menu_item = check_menu_item('Pause') {
|
111
|
+
enabled false
|
112
|
+
|
113
|
+
on_clicked do
|
114
|
+
@game.paused = @pause_menu_item.checked?
|
115
|
+
end
|
116
|
+
}
|
117
|
+
menu_item('Restart') {
|
118
|
+
on_clicked do
|
119
|
+
@game.restart!
|
120
|
+
end
|
121
|
+
}
|
122
|
+
separator_menu_item
|
123
|
+
menu_item('Exit') {
|
124
|
+
on_clicked do
|
125
|
+
exit(0)
|
126
|
+
end
|
127
|
+
}
|
128
|
+
quit_menu_item if OS.mac?
|
129
|
+
}
|
130
|
+
|
131
|
+
menu('View') {
|
132
|
+
menu_item('Show High Scores') {
|
133
|
+
on_clicked do
|
134
|
+
show_high_scores
|
135
|
+
end
|
136
|
+
}
|
137
|
+
menu_item('Clear High Scores') {
|
138
|
+
on_clicked {
|
139
|
+
@game.clear_high_scores!
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
menu('Options') {
|
145
|
+
radio_menu_item('Instant Down on Up Arrow') {
|
146
|
+
on_clicked do
|
147
|
+
@game.instant_down_on_up = true
|
148
|
+
end
|
149
|
+
}
|
150
|
+
radio_menu_item('Rotate Right on Up Arrow') {
|
151
|
+
on_clicked do
|
152
|
+
@game.rotate_right_on_up = true
|
153
|
+
end
|
154
|
+
}
|
155
|
+
radio_menu_item('Rotate Left on Up Arrow') {
|
156
|
+
on_clicked do
|
157
|
+
@game.rotate_left_on_up = true
|
158
|
+
end
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
menu('Help') {
|
163
|
+
if OS.mac?
|
164
|
+
about_menu_item {
|
165
|
+
on_clicked do
|
166
|
+
show_about_dialog
|
167
|
+
end
|
168
|
+
}
|
169
|
+
end
|
170
|
+
menu_item('About') {
|
171
|
+
on_clicked do
|
172
|
+
show_about_dialog
|
173
|
+
end
|
174
|
+
}
|
175
|
+
}
|
176
|
+
end
|
177
|
+
|
105
178
|
def playfield(playfield_width: , playfield_height: , block_size: , &extra_content)
|
106
179
|
blocks = []
|
107
180
|
vertical_box {
|
@@ -162,26 +235,26 @@ class Tetris
|
|
162
235
|
on_key_down do |key_event|
|
163
236
|
case key_event
|
164
237
|
in ext_key: :down
|
165
|
-
game.down!
|
238
|
+
@game.down!
|
166
239
|
in key: ' '
|
167
|
-
game.down!(instant: true)
|
240
|
+
@game.down!(instant: true)
|
168
241
|
in ext_key: :up
|
169
|
-
case game.up_arrow_action
|
242
|
+
case @game.up_arrow_action
|
170
243
|
when :instant_down
|
171
|
-
game.down!(instant: true)
|
244
|
+
@game.down!(instant: true)
|
172
245
|
when :rotate_right
|
173
|
-
game.rotate!(:right)
|
246
|
+
@game.rotate!(:right)
|
174
247
|
when :rotate_left
|
175
|
-
game.rotate!(:left)
|
248
|
+
@game.rotate!(:left)
|
176
249
|
end
|
177
250
|
in ext_key: :left
|
178
|
-
game.left!
|
251
|
+
@game.left!
|
179
252
|
in ext_key: :right
|
180
|
-
game.right!
|
253
|
+
@game.right!
|
181
254
|
in modifier: :shift
|
182
|
-
game.rotate!(:right)
|
255
|
+
@game.rotate!(:right)
|
183
256
|
in modifier: :control
|
184
|
-
game.rotate!(:left)
|
257
|
+
@game.rotate!(:left)
|
185
258
|
else
|
186
259
|
# Do Nothing
|
187
260
|
end
|
@@ -253,10 +326,29 @@ class Tetris
|
|
253
326
|
|
254
327
|
def show_game_over_dialog
|
255
328
|
Glimmer::LibUI.queue_main do
|
256
|
-
msg_box('Game Over', "Score: #{@game.high_scores.first.score}\nLines: #{@game.high_scores.first.lines}\nLevel: #{@game.high_scores.first.level}")
|
329
|
+
msg_box('Game Over!', "Score: #{@game.high_scores.first.score}\nLines: #{@game.high_scores.first.lines}\nLevel: #{@game.high_scores.first.level}")
|
257
330
|
@game.restart!
|
258
331
|
end
|
259
332
|
end
|
333
|
+
|
334
|
+
def show_high_scores
|
335
|
+
Glimmer::LibUI.queue_main do
|
336
|
+
if @game.high_scores.empty?
|
337
|
+
high_scores_string = "No games have been scored yet."
|
338
|
+
else
|
339
|
+
high_scores_string = @game.high_scores.map do |high_score|
|
340
|
+
"#{high_score.name} | Score: #{high_score.score} | Lines: #{high_score.lines} | Level: #{high_score.level}"
|
341
|
+
end.join("\n")
|
342
|
+
end
|
343
|
+
msg_box('High Scores', high_scores_string)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
def show_about_dialog
|
348
|
+
Glimmer::LibUI.queue_main do
|
349
|
+
msg_box('About', 'Glimmer Tetris - Glimmer DSL for LibUI Example - Copyright (c) 2021 Andy Maleh')
|
350
|
+
end
|
351
|
+
end
|
260
352
|
end
|
261
353
|
|
262
354
|
Tetris.new.launch
|
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
@@ -78,6 +78,7 @@ module Glimmer
|
|
78
78
|
when 'on_destroy'
|
79
79
|
on_destroy(&listener)
|
80
80
|
else
|
81
|
+
default_behavior_listener = nil
|
81
82
|
if listener_name == 'on_closing'
|
82
83
|
default_behavior_listener = Proc.new do
|
83
84
|
return_value = listener.call(self)
|
@@ -90,9 +91,45 @@ module Glimmer
|
|
90
91
|
end
|
91
92
|
end
|
92
93
|
end
|
93
|
-
super(listener_name, &default_behavior_listener)
|
94
|
+
super(listener_name, &(default_behavior_listener || listener))
|
94
95
|
end
|
95
96
|
end
|
97
|
+
|
98
|
+
def content_size(*args)
|
99
|
+
if args.empty?
|
100
|
+
width = Fiddle::Pointer.malloc(8)
|
101
|
+
height = Fiddle::Pointer.malloc(8)
|
102
|
+
::LibUI.window_content_size(@libui, width, height)
|
103
|
+
width = width[0, 8].unpack1('i')
|
104
|
+
height = height[0, 8].unpack1('i')
|
105
|
+
[width, height]
|
106
|
+
else
|
107
|
+
args = args.first if args.size == 1 && args.first.is_a?(Array)
|
108
|
+
super
|
109
|
+
@width = args[0]
|
110
|
+
@height = args[1]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
alias content_size= content_size
|
114
|
+
alias set_content_size content_size
|
115
|
+
|
116
|
+
def resizable(value = nil)
|
117
|
+
if value.nil?
|
118
|
+
@resizable = true if @resizable.nil?
|
119
|
+
@resizable
|
120
|
+
else
|
121
|
+
@resizable = value
|
122
|
+
if !@resizable && !@resizable_listener_registered
|
123
|
+
handle_listener('on_content_size_changed') do
|
124
|
+
set_content_size(@width, @height) unless @resizable
|
125
|
+
end
|
126
|
+
@resizable_listener_registered = true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
alias resizable? resizable
|
131
|
+
alias resizable= resizable
|
132
|
+
alias set_resizable resizable
|
96
133
|
|
97
134
|
private
|
98
135
|
|
@@ -107,6 +144,8 @@ module Glimmer
|
|
107
144
|
construction_args[2] = DEFAULT_HEIGHT if construction_args.size == 2
|
108
145
|
construction_args[3] = DEFAULT_HAS_MENUBAR if construction_args.size == 3
|
109
146
|
construction_args[3] = Glimmer::LibUI.boolean_to_integer(construction_args[3]) if construction_args.size == 4 && (construction_args[3].is_a?(TrueClass) || construction_args[3].is_a?(FalseClass))
|
147
|
+
@width = construction_args[1]
|
148
|
+
@height = construction_args[2]
|
110
149
|
@libui = ControlProxy.new_control(@keyword, construction_args)
|
111
150
|
@libui.tap do
|
112
151
|
handle_listener('on_closing') do
|