glimmer-dsl-libui 0.2.18 → 0.2.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c52fe6bf6dd2ed5494e9bc372628d340379cfdbfd8e2d19617c4813324e47a91
4
- data.tar.gz: d713e9293141c0c7d74d0be00319126fccad50c7aea6d787fe1cb1774b8547a6
3
+ metadata.gz: 0ff67ac5c365f692b3bd884c0b0cfaacfe0fcecc9eb26b18ade0cd8f52c78c06
4
+ data.tar.gz: 705fda986670a9e196c0f520d9322058f0cbdbb83b7317e3ca55eb34937aff0c
5
5
  SHA512:
6
- metadata.gz: d10eb3c9fff91f1a6881189b6ae17735986aff25f256eefc9c88ab1f4b8c11a20837ebf10f9735d02dc86418ba9471032bb2992e9f74e72fd9a446ff9116359d
7
- data.tar.gz: 7706f38cf41de97fd1a740ecaf150f0852d1974872e3dd95e0006df03927d081add8d06b342fb0c7b966c79c0134c1d591cfdff499bf5d951470fb7701a131b5
6
+ metadata.gz: c4ed363d60a4998baba5e3d6fdba60fde484e6d77d997051c3a7c9fdd5ab852ee5f9ee96de35d74f631b09a7bbb375adda967c915aee4f896facfc40375ef6da
7
+ data.tar.gz: 9c8d0080d025effa2e074cc140f532d6a9f5e3a1726dc1230a8dc7519316d1fbc6d947edee39ab3cbc8889cef10a221089b89b6f70fbbb8c76872a34332565ce
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.19
4
+
5
+ - Improve examples/tetris.rb with a score board (indicating next Tetromino, score, level, and lines)
6
+ - Add instant down action to examples/tetris.rb upon hitting the space button
7
+
3
8
  ## 0.2.18
4
9
 
5
10
  - Support `polygon` (closed figure of lines), `polyline` (open figure of lines), and `polybezier` (open figure of beziers) shape keywords to use under `path`
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.18
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.19
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.18'
373
+ gem 'glimmer-dsl-libui', '~> 0.2.19'
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.
@@ -446,7 +446,7 @@ These are all the supported keywords. Note that some keywords do not represent c
446
446
  Keyword(Args) | Properties | Listeners
447
447
  ------------- | ---------- | ---------
448
448
  `about_menu_item` | None | `on_clicked`
449
- `area` | None | `on_draw(area_draw_params)`, `on_mouse_event(area_mouse_event)`, `on_mouse_down(area_mouse_event)`, `on_mouse_up(area_mouse_event)`, `on_mouse_drag_started(area_mouse_event)`, `on_mouse_dragged(area_mouse_event)`, `on_mouse_dropped(area_mouse_event)`, `on_mouse_entered`, `on_mouse_exited`, `on_key_event(area_key_event)`, `on_key_down(area_key_event)`, `on_key_up(area_key_event)`
449
+ `area` | `auto_draw_enabled` | `on_draw(area_draw_params)`, `on_mouse_event(area_mouse_event)`, `on_mouse_down(area_mouse_event)`, `on_mouse_up(area_mouse_event)`, `on_mouse_drag_started(area_mouse_event)`, `on_mouse_dragged(area_mouse_event)`, `on_mouse_dropped(area_mouse_event)`, `on_mouse_entered`, `on_mouse_exited`, `on_key_event(area_key_event)`, `on_key_down(area_key_event)`, `on_key_up(area_key_event)`
450
450
  `arc(x_center as Numeric, y_center as Numeric, radius as Numeric, start_angle as Numeric, sweep as Numeric, is_negative as Boolean)` | `x_center` (`Numeric`), `y_center` (`Numeric`), `radius` (`Numeric`), `start_angle` (`Numeric`), `sweep` (`Numeric`), `is_negative` (Boolean) | None
451
451
  `background_color_column(name as String)` | None | None
452
452
  `bezier(c1_x as Numeric, c1_y as Numeric, c2_x as Numeric, c2_y as Numeric, end_x as Numeric, end_y as Numeric)` | `c1_x` (`Numeric`), `c1_y` (`Numeric`), `c2_x` (`Numeric`), `c2_y` (`Numeric`), `end_x` (`Numeric`), `end_y` (`Numeric`) | None
@@ -6252,6 +6252,8 @@ Mac
6252
6252
 
6253
6253
  ![glimmer-dsl-libui-mac-tetris.png](images/glimmer-dsl-libui-mac-tetris.png)
6254
6254
 
6255
+ ![glimmer-dsl-libui-mac-tetris-game-over.png](images/glimmer-dsl-libui-mac-tetris-game-over.png)
6256
+
6255
6257
  New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
6256
6258
 
6257
6259
  ```ruby
@@ -6270,18 +6272,30 @@ class Tetris
6270
6272
 
6271
6273
  def initialize
6272
6274
  @game = Model::Game.new
6273
- create_gui
6274
- register_observers
6275
6275
  end
6276
6276
 
6277
6277
  def launch
6278
+ create_gui
6279
+ register_observers
6278
6280
  @game.start!
6279
6281
  @main_window.show
6280
6282
  end
6281
6283
 
6282
6284
  def create_gui
6283
- @main_window = window('Glimmer Tetris', Model::Game::PLAYFIELD_WIDTH * BLOCK_SIZE, Model::Game::PLAYFIELD_HEIGHT * BLOCK_SIZE) {
6284
- playfield(playfield_width: Model::Game::PLAYFIELD_WIDTH, playfield_height: Model::Game::PLAYFIELD_HEIGHT, block_size: BLOCK_SIZE)
6285
+ @main_window = window('Glimmer Tetris') {
6286
+ content_size Model::Game::PLAYFIELD_WIDTH * BLOCK_SIZE, Model::Game::PLAYFIELD_HEIGHT * BLOCK_SIZE + 98
6287
+
6288
+ vertical_box {
6289
+ label { # filler
6290
+ stretchy false
6291
+ }
6292
+
6293
+ score_board(block_size: BLOCK_SIZE) {
6294
+ stretchy false
6295
+ }
6296
+
6297
+ @playfield_blocks = playfield(playfield_width: Model::Game::PLAYFIELD_WIDTH, playfield_height: Model::Game::PLAYFIELD_HEIGHT, block_size: BLOCK_SIZE)
6298
+ }
6285
6299
  }
6286
6300
  end
6287
6301
 
@@ -6295,11 +6309,11 @@ class Tetris
6295
6309
  end.observe(@game, :game_over)
6296
6310
 
6297
6311
  Model::Game::PLAYFIELD_HEIGHT.times do |row|
6298
- Model::Game::PLAYFIELD_HEIGHT.times do |column|
6312
+ Model::Game::PLAYFIELD_WIDTH.times do |column|
6299
6313
  Glimmer::DataBinding::Observer.proc do |new_color|
6300
6314
  Glimmer::LibUI.queue_main do
6301
6315
  color = Glimmer::LibUI.interpret_color(new_color)
6302
- block = @blocks[row][column]
6316
+ block = @playfield_blocks[row][column]
6303
6317
  block[:background_square].fill = color
6304
6318
  block[:top_bevel_edge].fill = {r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT}
6305
6319
  block[:right_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
@@ -6310,27 +6324,65 @@ class Tetris
6310
6324
  end.observe(@game.playfield[row][column], :color)
6311
6325
  end
6312
6326
  end
6327
+
6328
+ Model::Game::PREVIEW_PLAYFIELD_HEIGHT.times do |row|
6329
+ Model::Game::PREVIEW_PLAYFIELD_WIDTH.times do |column|
6330
+ Glimmer::DataBinding::Observer.proc do |new_color|
6331
+ Glimmer::LibUI.queue_main do
6332
+ color = Glimmer::LibUI.interpret_color(new_color)
6333
+ block = @preview_playfield_blocks[row][column]
6334
+ block[:background_square].fill = color
6335
+ block[:top_bevel_edge].fill = {r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT}
6336
+ block[:right_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
6337
+ block[:bottom_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
6338
+ block[:left_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
6339
+ block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : color
6340
+ end
6341
+ end.observe(@game.preview_playfield[row][column], :color)
6342
+ end
6343
+ end
6344
+
6345
+ Glimmer::DataBinding::Observer.proc do |new_score|
6346
+ Glimmer::LibUI.queue_main do
6347
+ @score_label.text = new_score.to_s
6348
+ end
6349
+ end.observe(@game, :score)
6350
+
6351
+ Glimmer::DataBinding::Observer.proc do |new_lines|
6352
+ Glimmer::LibUI.queue_main do
6353
+ @lines_label.text = new_lines.to_s
6354
+ end
6355
+ end.observe(@game, :lines)
6356
+
6357
+ Glimmer::DataBinding::Observer.proc do |new_level|
6358
+ Glimmer::LibUI.queue_main do
6359
+ @level_label.text = new_level.to_s
6360
+ end
6361
+ end.observe(@game, :level)
6313
6362
  end
6314
6363
 
6315
- def playfield(playfield_width: , playfield_height: , block_size: )
6316
- @blocks = []
6364
+ def playfield(playfield_width: , playfield_height: , block_size: , &extra_content)
6365
+ blocks = []
6317
6366
  vertical_box {
6318
6367
  padded false
6319
6368
 
6320
6369
  playfield_height.times.map do |row|
6321
- @blocks << []
6370
+ blocks << []
6322
6371
  horizontal_box {
6323
6372
  padded false
6324
6373
 
6325
6374
  playfield_width.times.map do |column|
6326
- @blocks.last << block(row: row, column: column, block_size: block_size)
6375
+ blocks.last << block(row: row, column: column, block_size: block_size)
6327
6376
  end
6328
6377
  }
6329
6378
  end
6379
+
6380
+ extra_content&.call
6330
6381
  }
6382
+ blocks
6331
6383
  end
6332
6384
 
6333
- def block(row: , column: , block_size: )
6385
+ def block(row: , column: , block_size: , &extra_content)
6334
6386
  block = {}
6335
6387
  bevel_pixel_size = 0.16 * block_size.to_f
6336
6388
  color = Glimmer::LibUI.interpret_color(Model::Block::COLOR_CLEAR)
@@ -6370,6 +6422,8 @@ class Tetris
6370
6422
  case key_event
6371
6423
  in ext_key: :down
6372
6424
  game.down!
6425
+ in key: ' '
6426
+ game.down!(instant: true)
6373
6427
  in ext_key: :up
6374
6428
  case game.up_arrow_action
6375
6429
  when :instant_down
@@ -6391,10 +6445,65 @@ class Tetris
6391
6445
  # Do Nothing
6392
6446
  end
6393
6447
  end
6448
+
6449
+ extra_content&.call
6394
6450
  }
6395
6451
  block
6396
6452
  end
6397
6453
 
6454
+ def score_board(block_size: , &extra_content)
6455
+ vertical_box {
6456
+ horizontal_box {
6457
+ label # filler
6458
+ @preview_playfield_blocks = playfield(playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: block_size)
6459
+ label # filler
6460
+ }
6461
+
6462
+ horizontal_box {
6463
+ label # filler
6464
+ grid {
6465
+ stretchy false
6466
+
6467
+ label('Score') {
6468
+ left 0
6469
+ top 0
6470
+ halign :fill
6471
+ }
6472
+ @score_label = label {
6473
+ left 0
6474
+ top 1
6475
+ halign :center
6476
+ }
6477
+
6478
+ label('Lines') {
6479
+ left 1
6480
+ top 0
6481
+ halign :fill
6482
+ }
6483
+ @lines_label = label {
6484
+ left 1
6485
+ top 1
6486
+ halign :center
6487
+ }
6488
+
6489
+ label('Level') {
6490
+ left 2
6491
+ top 0
6492
+ halign :fill
6493
+ }
6494
+ @level_label = label {
6495
+ left 2
6496
+ top 1
6497
+ halign :center
6498
+ }
6499
+ }
6500
+ label # filler
6501
+ }
6502
+
6503
+ extra_content&.call
6504
+ }
6505
+ end
6506
+
6398
6507
  def start_moving_tetrominos_down
6399
6508
  Glimmer::LibUI.timer(@game.delay) do
6400
6509
  @game.down! if !@game.game_over? && !@game.paused?
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.18
1
+ 0.2.19
data/examples/tetris.rb CHANGED
@@ -13,18 +13,30 @@ class Tetris
13
13
 
14
14
  def initialize
15
15
  @game = Model::Game.new
16
- create_gui
17
- register_observers
18
16
  end
19
17
 
20
18
  def launch
19
+ create_gui
20
+ register_observers
21
21
  @game.start!
22
22
  @main_window.show
23
23
  end
24
24
 
25
25
  def create_gui
26
- @main_window = window('Glimmer Tetris', Model::Game::PLAYFIELD_WIDTH * BLOCK_SIZE, Model::Game::PLAYFIELD_HEIGHT * BLOCK_SIZE) {
27
- playfield(playfield_width: Model::Game::PLAYFIELD_WIDTH, playfield_height: Model::Game::PLAYFIELD_HEIGHT, block_size: BLOCK_SIZE)
26
+ @main_window = window('Glimmer Tetris') {
27
+ content_size Model::Game::PLAYFIELD_WIDTH * BLOCK_SIZE, Model::Game::PLAYFIELD_HEIGHT * BLOCK_SIZE + 98
28
+
29
+ vertical_box {
30
+ label { # filler
31
+ stretchy false
32
+ }
33
+
34
+ score_board(block_size: BLOCK_SIZE) {
35
+ stretchy false
36
+ }
37
+
38
+ @playfield_blocks = playfield(playfield_width: Model::Game::PLAYFIELD_WIDTH, playfield_height: Model::Game::PLAYFIELD_HEIGHT, block_size: BLOCK_SIZE)
39
+ }
28
40
  }
29
41
  end
30
42
 
@@ -38,11 +50,11 @@ class Tetris
38
50
  end.observe(@game, :game_over)
39
51
 
40
52
  Model::Game::PLAYFIELD_HEIGHT.times do |row|
41
- Model::Game::PLAYFIELD_HEIGHT.times do |column|
53
+ Model::Game::PLAYFIELD_WIDTH.times do |column|
42
54
  Glimmer::DataBinding::Observer.proc do |new_color|
43
55
  Glimmer::LibUI.queue_main do
44
56
  color = Glimmer::LibUI.interpret_color(new_color)
45
- block = @blocks[row][column]
57
+ block = @playfield_blocks[row][column]
46
58
  block[:background_square].fill = color
47
59
  block[:top_bevel_edge].fill = {r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT}
48
60
  block[:right_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
@@ -53,27 +65,65 @@ class Tetris
53
65
  end.observe(@game.playfield[row][column], :color)
54
66
  end
55
67
  end
68
+
69
+ Model::Game::PREVIEW_PLAYFIELD_HEIGHT.times do |row|
70
+ Model::Game::PREVIEW_PLAYFIELD_WIDTH.times do |column|
71
+ Glimmer::DataBinding::Observer.proc do |new_color|
72
+ Glimmer::LibUI.queue_main do
73
+ color = Glimmer::LibUI.interpret_color(new_color)
74
+ block = @preview_playfield_blocks[row][column]
75
+ block[:background_square].fill = color
76
+ block[:top_bevel_edge].fill = {r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT}
77
+ block[:right_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
78
+ block[:bottom_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
79
+ block[:left_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
80
+ block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : color
81
+ end
82
+ end.observe(@game.preview_playfield[row][column], :color)
83
+ end
84
+ end
85
+
86
+ Glimmer::DataBinding::Observer.proc do |new_score|
87
+ Glimmer::LibUI.queue_main do
88
+ @score_label.text = new_score.to_s
89
+ end
90
+ end.observe(@game, :score)
91
+
92
+ Glimmer::DataBinding::Observer.proc do |new_lines|
93
+ Glimmer::LibUI.queue_main do
94
+ @lines_label.text = new_lines.to_s
95
+ end
96
+ end.observe(@game, :lines)
97
+
98
+ Glimmer::DataBinding::Observer.proc do |new_level|
99
+ Glimmer::LibUI.queue_main do
100
+ @level_label.text = new_level.to_s
101
+ end
102
+ end.observe(@game, :level)
56
103
  end
57
104
 
58
- def playfield(playfield_width: , playfield_height: , block_size: )
59
- @blocks = []
105
+ def playfield(playfield_width: , playfield_height: , block_size: , &extra_content)
106
+ blocks = []
60
107
  vertical_box {
61
108
  padded false
62
109
 
63
110
  playfield_height.times.map do |row|
64
- @blocks << []
111
+ blocks << []
65
112
  horizontal_box {
66
113
  padded false
67
114
 
68
115
  playfield_width.times.map do |column|
69
- @blocks.last << block(row: row, column: column, block_size: block_size)
116
+ blocks.last << block(row: row, column: column, block_size: block_size)
70
117
  end
71
118
  }
72
119
  end
120
+
121
+ extra_content&.call
73
122
  }
123
+ blocks
74
124
  end
75
125
 
76
- def block(row: , column: , block_size: )
126
+ def block(row: , column: , block_size: , &extra_content)
77
127
  block = {}
78
128
  bevel_pixel_size = 0.16 * block_size.to_f
79
129
  color = Glimmer::LibUI.interpret_color(Model::Block::COLOR_CLEAR)
@@ -113,6 +163,8 @@ class Tetris
113
163
  case key_event
114
164
  in ext_key: :down
115
165
  game.down!
166
+ in key: ' '
167
+ game.down!(instant: true)
116
168
  in ext_key: :up
117
169
  case game.up_arrow_action
118
170
  when :instant_down
@@ -134,10 +186,65 @@ class Tetris
134
186
  # Do Nothing
135
187
  end
136
188
  end
189
+
190
+ extra_content&.call
137
191
  }
138
192
  block
139
193
  end
140
194
 
195
+ def score_board(block_size: , &extra_content)
196
+ vertical_box {
197
+ horizontal_box {
198
+ label # filler
199
+ @preview_playfield_blocks = playfield(playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: block_size)
200
+ label # filler
201
+ }
202
+
203
+ horizontal_box {
204
+ label # filler
205
+ grid {
206
+ stretchy false
207
+
208
+ label('Score') {
209
+ left 0
210
+ top 0
211
+ halign :fill
212
+ }
213
+ @score_label = label {
214
+ left 0
215
+ top 1
216
+ halign :center
217
+ }
218
+
219
+ label('Lines') {
220
+ left 1
221
+ top 0
222
+ halign :fill
223
+ }
224
+ @lines_label = label {
225
+ left 1
226
+ top 1
227
+ halign :center
228
+ }
229
+
230
+ label('Level') {
231
+ left 2
232
+ top 0
233
+ halign :fill
234
+ }
235
+ @level_label = label {
236
+ left 2
237
+ top 1
238
+ halign :center
239
+ }
240
+ }
241
+ label # filler
242
+ }
243
+
244
+ extra_content&.call
245
+ }
246
+ end
247
+
141
248
  def start_moving_tetrominos_down
142
249
  Glimmer::LibUI.timer(@game.delay) do
143
250
  @game.down! if !@game.game_over? && !@game.paused?
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh