glimmer-dsl-libui 0.4.20 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +144 -55
  5. data/VERSION +1 -1
  6. data/bin/girb_runner.rb +1 -1
  7. data/examples/area_based_custom_controls.rb +7 -3
  8. data/examples/color_the_circles.rb +1 -1
  9. data/examples/snake/model/game.rb +18 -1
  10. data/examples/snake.rb +6 -2
  11. data/examples/snake2.rb +6 -2
  12. data/examples/tetris/model/block.rb +1 -1
  13. data/examples/tetris/model/game.rb +26 -24
  14. data/examples/tetris/model/past_game.rb +1 -1
  15. data/examples/tetris/model/tetromino.rb +1 -1
  16. data/examples/tetris.rb +51 -20
  17. data/examples/tic_tac_toe/board.rb +1 -1
  18. data/examples/tic_tac_toe/cell.rb +1 -1
  19. data/glimmer-dsl-libui.gemspec +0 -0
  20. data/lib/glimmer/dsl/libui/bind_expression.rb +1 -1
  21. data/lib/glimmer/dsl/libui/control_expression.rb +1 -1
  22. data/lib/glimmer/dsl/libui/data_binding_expression.rb +1 -1
  23. data/lib/glimmer/dsl/libui/dsl.rb +1 -1
  24. data/lib/glimmer/dsl/libui/file_expression.rb +1 -1
  25. data/lib/glimmer/dsl/libui/listener_expression.rb +1 -1
  26. data/lib/glimmer/dsl/libui/observe_expression.rb +1 -1
  27. data/lib/glimmer/dsl/libui/open_file_expression.rb +1 -1
  28. data/lib/glimmer/dsl/libui/operation_expression.rb +1 -1
  29. data/lib/glimmer/dsl/libui/property_expression.rb +1 -1
  30. data/lib/glimmer/dsl/libui/save_file_expression.rb +1 -1
  31. data/lib/glimmer/dsl/libui/shape_expression.rb +1 -1
  32. data/lib/glimmer/dsl/libui/shine_data_binding_expression.rb +1 -1
  33. data/lib/glimmer/dsl/libui/string_expression.rb +1 -1
  34. data/lib/glimmer/dsl/libui/tab_item_expression.rb +1 -1
  35. data/lib/glimmer/fiddle_consumer.rb +1 -1
  36. data/lib/glimmer/libui/attributed_string.rb +1 -1
  37. data/lib/glimmer/libui/control_proxy/area_proxy/scrolling_area_proxy.rb +1 -1
  38. data/lib/glimmer/libui/control_proxy/area_proxy.rb +1 -1
  39. data/lib/glimmer/libui/control_proxy/box/horizontal_box_proxy.rb +1 -1
  40. data/lib/glimmer/libui/control_proxy/box/vertical_box_proxy.rb +1 -1
  41. data/lib/glimmer/libui/control_proxy/box.rb +1 -1
  42. data/lib/glimmer/libui/control_proxy/button_proxy.rb +1 -1
  43. data/lib/glimmer/libui/control_proxy/checkbox_proxy.rb +1 -1
  44. data/lib/glimmer/libui/control_proxy/color_button_proxy.rb +1 -1
  45. data/lib/glimmer/libui/control_proxy/column/background_color_column_proxy.rb +1 -1
  46. data/lib/glimmer/libui/control_proxy/column/button_column_proxy.rb +1 -1
  47. data/lib/glimmer/libui/control_proxy/column/checkbox_column_proxy.rb +1 -1
  48. data/lib/glimmer/libui/control_proxy/column/checkbox_text_color_column_proxy.rb +1 -1
  49. data/lib/glimmer/libui/control_proxy/column/checkbox_text_column_proxy.rb +1 -1
  50. data/lib/glimmer/libui/control_proxy/column/image_column_proxy.rb +1 -1
  51. data/lib/glimmer/libui/control_proxy/column/image_text_color_column_proxy.rb +1 -1
  52. data/lib/glimmer/libui/control_proxy/column/image_text_column_proxy.rb +1 -1
  53. data/lib/glimmer/libui/control_proxy/column/progress_bar_column_proxy.rb +1 -1
  54. data/lib/glimmer/libui/control_proxy/column/text_color_column_proxy.rb +1 -1
  55. data/lib/glimmer/libui/control_proxy/column/text_column_proxy.rb +1 -1
  56. data/lib/glimmer/libui/control_proxy/column.rb +1 -1
  57. data/lib/glimmer/libui/control_proxy/combobox_proxy.rb +1 -1
  58. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy/date_picker_proxy.rb +1 -1
  59. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy/time_picker_proxy.rb +1 -1
  60. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy.rb +1 -1
  61. data/lib/glimmer/libui/control_proxy/dual_column.rb +1 -1
  62. data/lib/glimmer/libui/control_proxy/editable_column.rb +1 -1
  63. data/lib/glimmer/libui/control_proxy/editable_combobox_proxy.rb +1 -1
  64. data/lib/glimmer/libui/control_proxy/enableable_column.rb +1 -1
  65. data/lib/glimmer/libui/control_proxy/entry_proxy/password_entry_proxy.rb +1 -1
  66. data/lib/glimmer/libui/control_proxy/entry_proxy/search_entry_proxy.rb +1 -1
  67. data/lib/glimmer/libui/control_proxy/entry_proxy.rb +1 -1
  68. data/lib/glimmer/libui/control_proxy/font_button_proxy.rb +1 -1
  69. data/lib/glimmer/libui/control_proxy/form_proxy.rb +1 -1
  70. data/lib/glimmer/libui/control_proxy/grid_proxy.rb +1 -1
  71. data/lib/glimmer/libui/control_proxy/group_proxy.rb +1 -1
  72. data/lib/glimmer/libui/control_proxy/image_part_proxy.rb +1 -1
  73. data/lib/glimmer/libui/control_proxy/image_proxy.rb +1 -1
  74. data/lib/glimmer/libui/control_proxy/label_proxy.rb +1 -1
  75. data/lib/glimmer/libui/control_proxy/matrix_proxy.rb +1 -1
  76. data/lib/glimmer/libui/control_proxy/menu_item_proxy/about_menu_item_proxy.rb +1 -1
  77. data/lib/glimmer/libui/control_proxy/menu_item_proxy/check_menu_item_proxy.rb +1 -1
  78. data/lib/glimmer/libui/control_proxy/menu_item_proxy/preferences_menu_item_proxy.rb +1 -1
  79. data/lib/glimmer/libui/control_proxy/menu_item_proxy/quit_menu_item_proxy.rb +1 -1
  80. data/lib/glimmer/libui/control_proxy/menu_item_proxy/radio_menu_item_proxy.rb +1 -1
  81. data/lib/glimmer/libui/control_proxy/menu_item_proxy/separator_menu_item_proxy.rb +1 -1
  82. data/lib/glimmer/libui/control_proxy/menu_item_proxy.rb +1 -1
  83. data/lib/glimmer/libui/control_proxy/menu_proxy.rb +1 -1
  84. data/lib/glimmer/libui/control_proxy/message_box/msg_box_error_proxy.rb +1 -1
  85. data/lib/glimmer/libui/control_proxy/message_box/msg_box_proxy.rb +1 -1
  86. data/lib/glimmer/libui/control_proxy/message_box.rb +1 -1
  87. data/lib/glimmer/libui/control_proxy/multiline_entry_proxy/non_wrapping_multiline_entry_proxy.rb +1 -1
  88. data/lib/glimmer/libui/control_proxy/multiline_entry_proxy.rb +1 -1
  89. data/lib/glimmer/libui/control_proxy/open_type_features_proxy.rb +1 -1
  90. data/lib/glimmer/libui/control_proxy/open_type_tag_proxy.rb +1 -1
  91. data/lib/glimmer/libui/control_proxy/path_proxy.rb +1 -1
  92. data/lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb +1 -1
  93. data/lib/glimmer/libui/control_proxy/slider_proxy.rb +1 -1
  94. data/lib/glimmer/libui/control_proxy/spinbox_proxy.rb +1 -1
  95. data/lib/glimmer/libui/control_proxy/tab_item_proxy.rb +1 -1
  96. data/lib/glimmer/libui/control_proxy/table_proxy.rb +1 -1
  97. data/lib/glimmer/libui/control_proxy/text_proxy.rb +1 -1
  98. data/lib/glimmer/libui/control_proxy/transformable.rb +1 -1
  99. data/lib/glimmer/libui/control_proxy/triple_column.rb +1 -1
  100. data/lib/glimmer/libui/control_proxy/window_proxy.rb +1 -1
  101. data/lib/glimmer/libui/control_proxy.rb +1 -1
  102. data/lib/glimmer/libui/data_bindable.rb +1 -1
  103. data/lib/glimmer/libui/parent.rb +1 -1
  104. data/lib/glimmer/libui/shape/arc.rb +18 -1
  105. data/lib/glimmer/libui/shape/bezier.rb +1 -1
  106. data/lib/glimmer/libui/shape/circle.rb +8 -3
  107. data/lib/glimmer/libui/shape/figure.rb +1 -1
  108. data/lib/glimmer/libui/shape/line.rb +1 -1
  109. data/lib/glimmer/libui/shape/polybezier.rb +1 -1
  110. data/lib/glimmer/libui/shape/polygon.rb +1 -1
  111. data/lib/glimmer/libui/shape/polyline.rb +1 -1
  112. data/lib/glimmer/libui/shape/rectangle.rb +8 -3
  113. data/lib/glimmer/libui/shape/square.rb +10 -3
  114. data/lib/glimmer/libui/shape.rb +41 -1
  115. data/lib/glimmer/libui.rb +1 -1
  116. data/lib/glimmer-dsl-libui.rb +2 -1
  117. metadata +27 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 594b6127dd134d82d6f91dd4856aadb841ecceb04a8e9b34741d940212956997
4
- data.tar.gz: efe2aa6e53ea80b58c1a1a12351c67e476e5ec3170aba680573d2f963680ccba
3
+ metadata.gz: 04aa1c93edebb982ee709366ff59b81a93a7dc79b8263ae17852f1d8302a3017
4
+ data.tar.gz: ca30e790f8c93262de84920fbd0a22c584eab485d5fc4467f3ac9d52310a4410
5
5
  SHA512:
6
- metadata.gz: 8d21fba0daf5a73da1b7d31aac00d492508d92ceda522751a3908b7b3c794368286e7d971aa525322a08d91f48e11b71ad9c838393de65e12c4fc5f8133b5e6f
7
- data.tar.gz: 2e448728ad41a976a169e5913e941cad523c5f897849ccacc82eb9d1ae2c75e002b8c9c5a933b9642d2845d263ed252a2e4826e29a0d18467b5e6bae63b51f8e
6
+ metadata.gz: 4c553da5930af45532c1b9ea8cb11c48d29d0b24a6229c7abeb28854c71d4e2e3cc933f2bc8a5231c8fe5debc7e424a03b316b56a805c68a235d25605ef7ff2c
7
+ data.tar.gz: a06cf47acaa964bfd73d5385082c4949ef9b76e0a54db230d29d961626367880e13e8e00cf63e3b78e40bb1cdafec29ea589e40b934ecc08268e768a5a2b48ac
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.5.1
4
+
5
+ - Upgrade to libui 0.0.14
6
+ - Alter `Shape#contain?` to support `outline: ` and `distance_tolerance: ` options as per perfect-shape gem
7
+ - Support `arc` `bounding_box` (minx, miny, width, height), `contain?` method (checking if shape contains point inside) and `include?` method (checking on outline if stroked and inside if filled?)
8
+ - Support `circle` `bounding_box` (minx, miny, width, height), `contain?` method (checking if shape contains point inside) and `include?` method (checking on outline if stroked and inside if filled?)
9
+
10
+ ## 0.5.0
11
+
12
+ - Upgrade to glimmer 2.6.0
13
+ - Support `rectangle` `bounding_box` (minx, miny, width, height), `contain?` method (checking if shape contains point inside) and `include?` method (checking on outline if stroked and inside if filled?)
14
+ - Support `square` `bounding_box` (minx, miny, width, height), `contain?` method (checking if shape contains point inside) and `include?` method (checking on outline if stroked and inside if filled?)
15
+
16
+ ## 0.4.22
17
+
18
+ - examples/tetris.rb "Show Next Block Preview" menu item under "View" menu
19
+ - examples/tetris.rb "Speed" menu
20
+ - Fix issue with examples/tetris.rb not accelerating upon level ups
21
+
22
+ ## 0.4.21
23
+
24
+ - Pause via spacebar in examples/snake.rb (all versions)
25
+ - Upgrade to glimmer 2.5.5
26
+
3
27
  ## 0.4.20
4
28
 
5
29
  - New examples/area_based_custom_controls.rb
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2021 Andy Maleh
1
+ Copyright (c) 2021-2022 Andy Maleh
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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.20
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.5.1
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)
5
5
 
6
- [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [LibUI](https://github.com/kojix2/LibUI) is a prerequisite-free Ruby 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!
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
  ----|---------|------
@@ -22,6 +24,8 @@ The main trade-off in using [Glimmer DSL for LibUI](https://rubygems.org/gems/gl
22
24
  - [Far Future Plan] Scaffolding for new custom controls, apps, and gems
23
25
  - [Far Future Plan] Native-Executable packaging on Mac, Windows, and Linux.
24
26
 
27
+ Note that currently, [LibUI](https://github.com/kojix2/LibUI) only includes x86_64 binaries out of the box, but there are plans to include ARM64/AARCH64 binaries too in the future.
28
+
25
29
  Hello, World!
26
30
 
27
31
  ```ruby
@@ -320,19 +324,27 @@ Mac | Windows | Linux
320
324
 
321
325
  [Check Out Many More Examples Over Here!](#examples)
322
326
 
323
- Mac | Windows | Linux
324
- ----|---------|------
325
- ![glimmer-dsl-libui-mac-tetris.png](images/glimmer-dsl-libui-mac-tetris.png) | ![glimmer-dsl-libui-windows-tetris.png](images/glimmer-dsl-libui-windows-tetris.png) | ![glimmer-dsl-libui-linux-tetris.png](images/glimmer-dsl-libui-linux-tetris.png)
327
+ ![glimmer-dsl-libui-mac-snake.gif](images/glimmer-dsl-libui-mac-snake.gif)
328
+
329
+ ![glimmer-dsl-libui-mac-color-the-circles.gif](images/glimmer-dsl-libui-mac-color-the-circles.gif)
326
330
 
327
- 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.
331
+ ![glimmer-dsl-libui-mac-tetris.gif](images/glimmer-dsl-libui-mac-tetris.gif)
328
332
 
329
- Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interested in:
330
- - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
331
- - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps)
332
- - [glimmer-dsl-tk](https://github.com/AndyObtiva/glimmer-dsl-tk): Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library)
333
- - [glimmer-dsl-gtk](https://github.com/AndyObtiva/glimmer-dsl-gtk): Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library)
334
- - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
335
- - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS
333
+ NOTE: [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) is 100% feature-complete with regards to covering the C [libui](https://github.com/andlabs/libui) library API and in beta mode (though the C [libui](https://github.com/andlabs/libui) is still mid-alpha, which is why [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) cannot be declared v1.0.0 yet). 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.
334
+
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
336
348
 
337
349
  ## Table of Contents
338
350
 
@@ -507,7 +519,7 @@ gem install glimmer-dsl-libui
507
519
  Or install via Bundler `Gemfile`:
508
520
 
509
521
  ```ruby
510
- gem 'glimmer-dsl-libui', '~> 0.4.20'
522
+ gem 'glimmer-dsl-libui', '~> 0.5.1'
511
523
  ```
512
524
 
513
525
  Test that installation worked by running the [Meta-Example](#examples):
@@ -577,13 +589,14 @@ w.set_title 'aloha'
577
589
  puts w.title # => aloha
578
590
  ```
579
591
 
580
- 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.
581
593
 
582
594
  Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
583
595
 
584
596
  ```ruby
585
597
  w = window('hello world') # => #<Glimmer::LibUI::WindowProxy:0x00007fde4ea39fb0
586
598
  w.libui # => #<Fiddle::Pointer:0x00007fde53997980 ptr=0x00007fde51352a60 size=0 free=0x0000000000000000>
599
+ w.title == LibUI.window_title(w.libui).to_s # => true
587
600
  ```
588
601
 
589
602
  ### Supported Keywords
@@ -995,15 +1008,49 @@ To draw `text` in an `area`, you simply nest a `text(x, y, width)` control direc
995
1008
  Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
996
1009
 
997
1010
  ```ruby
1011
+ require 'glimmer-dsl-libui'
1012
+
1013
+ include Glimmer
1014
+
998
1015
  window('area text drawing') {
999
1016
  area {
1000
1017
  text {
1001
1018
  default_font family: 'Helvetica', size: 12, weight: :normal, italic: :normal, stretch: :normal
1002
1019
 
1020
+ string('This ') {
1021
+ font size: 20, weight: :bold, italic: :normal, stretch: :normal
1022
+ color r: 128, g: 0, b: 0, a: 1
1023
+ }
1024
+
1025
+ string('is ') {
1026
+ font size: 20, weight: :bold, italic: :normal, stretch: :normal
1027
+ color r: 0, g: 128, b: 0, a: 1
1028
+ }
1029
+
1030
+ string('a ') {
1031
+ font size: 20, weight: :bold, italic: :normal, stretch: :normal
1032
+ color r: 0, g: 0, b: 128, a: 1
1033
+ }
1034
+
1035
+ string('short ') {
1036
+ font size: 20, weight: :bold, italic: :italic, stretch: :normal
1037
+ color r: 128, g: 128, b: 0, a: 1
1038
+ }
1039
+
1040
+ string('attributed ') {
1041
+ font size: 20, weight: :bold, italic: :normal, stretch: :normal
1042
+ color r: 0, g: 128, b: 128, a: 1
1043
+ }
1044
+
1045
+ string("string \n\n") {
1046
+ font size: 20, weight: :bold, italic: :normal, stretch: :normal
1047
+ color r: 128, g: 0, b: 128, a: 1
1048
+ }
1049
+
1003
1050
  string {
1004
1051
  font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
1005
- color r: 230, g: 100, b: 50, a: 0.5
1006
- background r: 230, g: 200, b: 250, a: 0.8
1052
+ color r: 0, g: 128, b: 255, a: 1
1053
+ background r: 255, g: 255, b: 0, a: 0.5
1007
1054
  underline :single
1008
1055
  underline_color :spelling
1009
1056
  open_type_features {
@@ -1016,13 +1063,14 @@ window('area text drawing') {
1016
1063
  "attributed string\n" \
1017
1064
  "spanning multiple lines\n\n"
1018
1065
  }
1019
-
1020
- string('This is a short unattributed string')
1021
1066
  }
1022
1067
  }
1023
1068
  }.show
1024
1069
  ```
1025
1070
 
1071
+ ![glimmer-dsl-libui-mac-area-text-drawing.png](/images/glimmer-dsl-libui-mac-area-text-drawing.png)
1072
+
1073
+
1026
1074
  You may checkout [examples/basic_draw_text.rb](#basic-draw-text) and [examples/custom_draw_text.rb](#custom-draw-text) for examples of using `text` inside `area`.
1027
1075
 
1028
1076
  Mac | Windows | Linux
@@ -1840,6 +1888,8 @@ For Mac, consider [Platypus](https://github.com/sveinbjornt/Platypus) (builds a
1840
1888
 
1841
1889
  For Linux, simply package your app as a [Ruby Gem](https://guides.rubygems.org/what-is-a-gem/) and [build rpm package from Ruby Gem](https://www.redpill-linpro.com/sysadvent/2015/12/07/building-rpms-from-gems.html) or [build deb package from Ruby Gem](https://openpreservation.org/blogs/building-debian-package-ruby-program/).
1842
1890
 
1891
+ Also, there is a promising project called [ruby-packer](https://github.com/pmq20/ruby-packer) that supports all platforms.
1892
+
1843
1893
  ## Glimmer Style Guide
1844
1894
 
1845
1895
  **1 - Control arguments are always wrapped by parentheses.**
@@ -5483,7 +5533,7 @@ class ColorTheCircles
5483
5533
 
5484
5534
  def color_circle(x, y)
5485
5535
  clicked_circle_data = @circles_data.find do |circle_data|
5486
- circle_data[:fill].nil? && circle_data[:circle]&.include?(x, y)
5536
+ circle_data[:fill].nil? && circle_data[:circle]&.contain?(x, y)
5487
5537
  end
5488
5538
  if clicked_circle_data
5489
5539
  clicked_circle_data[:fill] = clicked_circle_data[:stroke]
@@ -8642,14 +8692,14 @@ class AreaBasedCustomControls
8642
8692
  def initialize
8643
8693
  self.label_width = 335
8644
8694
  self.label_height = 50
8645
- self.label_font_descriptor = {family: OS.linux? ? 'Bitstream Vera Sans Mono' : 'Courier New', size: 16, weight: :bold, italic: :italic}
8695
+ self.label_font_descriptor = {family: OS.linux? ? 'Monospace Bold Italic' : 'Courier New', size: 16, weight: :bold, italic: :italic}
8646
8696
  self.label_text_color = :red
8647
8697
  self.label_background_fill = :yellow
8648
8698
  self.label_border_stroke = :limegreen
8649
8699
 
8650
- self.button_width = 130
8700
+ self.button_width = 150
8651
8701
  self.button_height = 50
8652
- self.button_font_descriptor = {family: OS.linux? ? 'Bitstream Vera Sans Mono' : 'Courier New', size: 36, weight: :bold, italic: :italic}
8702
+ self.button_font_descriptor = {family: OS.linux? ? 'Monospace Bold Italic' : 'Courier New', size: 36, weight: OS.linux? ? :normal : :bold, italic: :italic}
8653
8703
  self.button_text_color = :green
8654
8704
  self.button_background_fill = :yellow
8655
8705
  self.button_border_stroke = :limegreen
@@ -8657,7 +8707,7 @@ class AreaBasedCustomControls
8657
8707
 
8658
8708
  def rebuild_text_label
8659
8709
  @text_label.destroy
8660
- @text_label_vertical_box.content { # re-open vertical box content and shove in a new button
8710
+ @text_label_vertical_box.content { # re-open vertical box content and shove in a new label
8661
8711
  @text_label = text_label('This is a text label.',
8662
8712
  width: label_width, height: label_height, font_descriptor: label_font_descriptor,
8663
8713
  background_fill: label_background_fill, text_color: label_text_color, border_stroke: label_border_stroke,
@@ -8687,8 +8737,8 @@ class AreaBasedCustomControls
8687
8737
  tab_item('Text Label') {
8688
8738
  @text_label_vertical_box = vertical_box {
8689
8739
  vertical_box {
8690
- text_label('Text Label Construction Form:', width: 250, height: 30, font_descriptor: {size: 16, weight: :bold}, text_x: 0, text_y: 0)
8691
-
8740
+ text_label('Text Label Form:', width: 385, height: 30, background_fill: OS.windows? ? :white : {a: 0}, border_stroke: OS.windows? ? :white : {a: 0}, font_descriptor: {size: 16, weight: :bold}, text_x: 0, text_y: OS.windows? ? 0 : 5)
8741
+
8692
8742
  horizontal_box {
8693
8743
  label('Width')
8694
8744
  spinbox(1, 1000) {
@@ -8756,7 +8806,7 @@ class AreaBasedCustomControls
8756
8806
  tab_item('Push Button') {
8757
8807
  @push_button_vertical_box = vertical_box {
8758
8808
  vertical_box {
8759
- text_label('Push Button Construction Form:', width: 250, height: 30, font_descriptor: {size: 16, weight: :bold}, text_x: 0, text_y: 0)
8809
+ text_label('Push Button Form:', width: 385, height: 30, background_fill: OS.windows? ? :white : {a: 0}, border_stroke: OS.windows? ? :white : {a: 0}, font_descriptor: {size: 16, weight: :bold}, text_x: 0, text_y: OS.windows? ? 0 : 5)
8760
8810
 
8761
8811
  horizontal_box {
8762
8812
  label('Width')
@@ -8835,6 +8885,10 @@ class AreaBasedCustomControls
8835
8885
  # background_fill can accept a single color or gradient stops just as per `fill` property in README.
8836
8886
  # border_stroke is transparent by default.
8837
8887
  # border_stroke can accept thickness and dashes in addition to color just as per `stroke` property in README.
8888
+ # text_x and text_y are the offset of the label text in relation to its top-left corner.
8889
+ # When text_x, text_y are left nil, the text is automatically centered in the label area.
8890
+ # Sometimes, the centering calculation is not perfect due to using a custom font, so
8891
+ # in that case, pass in text_x, and text_y manually.
8838
8892
  def text_label(label_text,
8839
8893
  width: 80, height: 30, font_descriptor: {},
8840
8894
  background_fill: {a: 0}, text_color: :black, border_stroke: {a: 0},
@@ -8848,8 +8902,8 @@ class AreaBasedCustomControls
8848
8902
  stroke border_stroke
8849
8903
  }
8850
8904
 
8851
- text_height = (font_descriptor[:size] || 12) * 0.75
8852
- text_width = (text_height * label_text.size) * 0.75
8905
+ text_height = (font_descriptor[:size] || 12) * (OS.mac? ? 0.75 : 1.35)
8906
+ text_width = (text_height * label_text.size) * (OS.mac? ? 0.75 : 0.60)
8853
8907
  text_x ||= (width - text_width) / 2.0
8854
8908
  text_y ||= (height - 4 - text_height) / 2.0
8855
8909
  text(text_x, text_y, width) {
@@ -8869,10 +8923,10 @@ class AreaBasedCustomControls
8869
8923
  # background_fill can accept a single color or gradient stops just as per `fill` property in README.
8870
8924
  # border_stroke is black by default.
8871
8925
  # border_stroke can accept thickness and dashes in addition to color just as per `stroke` property in README.
8872
- # text_x and text_y are the offset of the button text in releation to its top-left corner
8926
+ # text_x and text_y are the offset of the button text in relation to its top-left corner.
8873
8927
  # When text_x, text_y are left nil, the text is automatically centered in the button area.
8874
8928
  # Sometimes, the centering calculation is not perfect due to using a custom font, so
8875
- # in that case, pass in text_x, and text_y manually
8929
+ # in that case, pass in text_x, and text_y manually.
8876
8930
  #
8877
8931
  # reuses the text_label custom control
8878
8932
  def push_button(button_text,
@@ -9305,6 +9359,8 @@ TinyMidiPlayer.new
9305
9359
 
9306
9360
  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.
9307
9361
 
9362
+ Use arrows to move and spacebar to pause/resume.
9363
+
9308
9364
  [examples/snake.rb](examples/snake.rb)
9309
9365
 
9310
9366
  Run with this command from the root of the project if you cloned the project:
@@ -9360,7 +9416,7 @@ class Snake
9360
9416
  end
9361
9417
 
9362
9418
  Glimmer::LibUI.timer(SNAKE_MOVE_DELAY) do
9363
- unless @game.over?
9419
+ unless @game.paused? || @game.over?
9364
9420
  process_queued_keypress
9365
9421
  @game.snake.move
9366
9422
  end
@@ -9401,7 +9457,11 @@ class Snake
9401
9457
  }
9402
9458
 
9403
9459
  on_key_up do |area_key_event|
9404
- @keypress_queue << area_key_event[:ext_key]
9460
+ if area_key_event[:key] == ' '
9461
+ @game.toggle_pause
9462
+ else
9463
+ @keypress_queue << area_key_event[:ext_key]
9464
+ end
9405
9465
  end
9406
9466
  }
9407
9467
  end
@@ -9460,7 +9520,7 @@ class Snake
9460
9520
  end
9461
9521
 
9462
9522
  Glimmer::LibUI.timer(SNAKE_MOVE_DELAY) do
9463
- unless @game.over?
9523
+ unless @game.paused? || @game.over?
9464
9524
  process_queued_keypress
9465
9525
  @game.snake.move
9466
9526
  end
@@ -9503,7 +9563,11 @@ class Snake
9503
9563
  }
9504
9564
 
9505
9565
  on_key_up do |area_key_event|
9506
- @keypress_queue << area_key_event[:ext_key]
9566
+ if area_key_event[:key] == ' '
9567
+ @game.toggle_pause
9568
+ else
9569
+ @keypress_queue << area_key_event[:ext_key]
9570
+ end
9507
9571
  end
9508
9572
  }
9509
9573
  end
@@ -9537,7 +9601,7 @@ ruby -r glimmer-dsl-libui -e "require 'examples/tetris'"
9537
9601
 
9538
9602
  Mac | Windows | Linux
9539
9603
  ----|---------|------
9540
- ![glimmer-dsl-libui-mac-tetris.png](images/glimmer-dsl-libui-mac-tetris.png) ![glimmer-dsl-libui-mac-tetris-game-over.png](images/glimmer-dsl-libui-mac-tetris-game-over.png) ![glimmer-dsl-libui-mac-tetris-high-scores.png](images/glimmer-dsl-libui-mac-tetris-high-scores.png) | ![glimmer-dsl-libui-windows-tetris.png](images/glimmer-dsl-libui-windows-tetris.png) ![glimmer-dsl-libui-windows-tetris-game-over.png](images/glimmer-dsl-libui-windows-tetris-game-over.png) ![glimmer-dsl-libui-windows-tetris-high-scores.png](images/glimmer-dsl-libui-windows-tetris-high-scores.png) | ![glimmer-dsl-libui-linux-tetris.png](images/glimmer-dsl-libui-linux-tetris.png) ![glimmer-dsl-libui-linux-tetris-game-over.png](images/glimmer-dsl-libui-linux-tetris-game-over.png) ![glimmer-dsl-libui-linux-tetris-high-scores.png](images/glimmer-dsl-libui-linux-tetris-high-scores.png)
9604
+ ![glimmer-dsl-libui-mac-tetris.png](images/glimmer-dsl-libui-mac-tetris.png) | ![glimmer-dsl-libui-windows-tetris.png](images/glimmer-dsl-libui-windows-tetris.png) | ![glimmer-dsl-libui-linux-tetris.png](images/glimmer-dsl-libui-linux-tetris.png)
9541
9605
 
9542
9606
  New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
9543
9607
 
@@ -9615,18 +9679,31 @@ class Tetris
9615
9679
 
9616
9680
  Model::Game::PREVIEW_PLAYFIELD_HEIGHT.times do |row|
9617
9681
  Model::Game::PREVIEW_PLAYFIELD_WIDTH.times do |column|
9618
- observe(@game.preview_playfield[row][column], :color) do |new_color|
9682
+ preview_updater = proc do
9619
9683
  Glimmer::LibUI.queue_main do
9684
+ new_color = @game.preview_playfield[row][column].color
9620
9685
  color = Glimmer::LibUI.interpret_color(new_color)
9621
9686
  block = @preview_playfield_blocks[row][column]
9622
- block[:background_square].fill = color
9623
- block[:top_bevel_edge].fill = {r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT}
9624
- block[:right_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
9625
- block[:bottom_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
9626
- block[:left_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
9627
- block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : color
9687
+ if @game.show_preview_tetromino?
9688
+ block[:background_square].fill = color
9689
+ block[:top_bevel_edge].fill = {r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT}
9690
+ block[:right_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
9691
+ block[:bottom_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
9692
+ block[:left_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
9693
+ block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : color
9694
+ else
9695
+ transparent_color = {r: 255, g: 255, b: 255, a: 0}
9696
+ block[:background_square].fill = transparent_color
9697
+ block[:top_bevel_edge].fill = transparent_color
9698
+ block[:right_bevel_edge].fill = transparent_color
9699
+ block[:bottom_bevel_edge].fill = transparent_color
9700
+ block[:left_bevel_edge].fill = transparent_color
9701
+ block[:border_square].stroke = transparent_color
9702
+ end
9628
9703
  end
9629
9704
  end
9705
+ observe(@game.preview_playfield[row][column], :color, &preview_updater)
9706
+ observe(@game, :show_preview_tetromino, &preview_updater)
9630
9707
  end
9631
9708
  end
9632
9709
 
@@ -9674,6 +9751,12 @@ class Tetris
9674
9751
  }
9675
9752
 
9676
9753
  menu('View') {
9754
+ check_menu_item('Show Next Block Preview') {
9755
+ checked <=> [@game, :show_preview_tetromino]
9756
+ }
9757
+
9758
+ separator_menu_item
9759
+
9677
9760
  menu_item('Show High Scores') {
9678
9761
  on_clicked do
9679
9762
  show_high_scores
@@ -9685,18 +9768,20 @@ class Tetris
9685
9768
  @game.clear_high_scores!
9686
9769
  }
9687
9770
  }
9771
+
9772
+ separator_menu_item
9688
9773
  }
9689
9774
 
9690
9775
  menu('Options') {
9691
- radio_menu_item('Instant Down on Up Arrow') { |r|
9776
+ radio_menu_item('Instant Down on Up Arrow') {
9692
9777
  checked <=> [@game, :instant_down_on_up]
9693
9778
  }
9694
9779
 
9695
- radio_menu_item('Rotate Right on Up Arrow') { |r|
9780
+ radio_menu_item('Rotate Right on Up Arrow') {
9696
9781
  checked <=> [@game, :rotate_right_on_up]
9697
9782
  }
9698
9783
 
9699
- radio_menu_item('Rotate Left on Up Arrow') { |r|
9784
+ radio_menu_item('Rotate Left on Up Arrow') {
9700
9785
  checked <=> [@game, :rotate_left_on_up]
9701
9786
  }
9702
9787
  }
@@ -9743,7 +9828,7 @@ class Tetris
9743
9828
  block = {}
9744
9829
  bevel_pixel_size = 0.16 * block_size.to_f
9745
9830
  color = Glimmer::LibUI.interpret_color(Model::Block::COLOR_CLEAR)
9746
- area {
9831
+ block[:area] = area {
9747
9832
  block[:background_square] = square(0, 0, block_size) {
9748
9833
  fill color
9749
9834
  }
@@ -9819,12 +9904,6 @@ class Tetris
9819
9904
 
9820
9905
  def score_board(block_size: , &extra_content)
9821
9906
  vertical_box {
9822
- horizontal_box {
9823
- label # filler
9824
- @preview_playfield_blocks = playfield(playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: block_size)
9825
- label # filler
9826
- }
9827
-
9828
9907
  horizontal_box {
9829
9908
  label # filler
9830
9909
  grid {
@@ -9865,6 +9944,12 @@ class Tetris
9865
9944
  }
9866
9945
  label # filler
9867
9946
  }
9947
+
9948
+ horizontal_box {
9949
+ label # filler
9950
+ @preview_playfield_blocks = playfield(playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: block_size)
9951
+ label # filler
9952
+ }
9868
9953
 
9869
9954
  extra_content&.call
9870
9955
  }
@@ -9904,7 +9989,7 @@ class Tetris
9904
9989
 
9905
9990
  def show_about_dialog
9906
9991
  Glimmer::LibUI.queue_main do
9907
- msg_box('About', 'Glimmer Tetris - Glimmer DSL for LibUI Example - Copyright (c) 2021 Andy Maleh')
9992
+ msg_box('About', 'Glimmer Tetris - Glimmer DSL for LibUI Example - Copyright (c) 2021-2022 Andy Maleh')
9908
9993
  end
9909
9994
  end
9910
9995
  end
@@ -10414,6 +10499,10 @@ https://github.com/AndyObtiva/befunge98/tree/gui
10414
10499
 
10415
10500
  https://github.com/iraamaro/i3off-gtk-ruby
10416
10501
 
10502
+ ### Chess
10503
+
10504
+ https://github.com/mikeweber/chess
10505
+
10417
10506
  ## Process
10418
10507
 
10419
10508
  [Glimmer Process](https://github.com/AndyObtiva/glimmer/blob/master/PROCESS.md)
@@ -10473,7 +10562,7 @@ Note that the latest development sometimes takes place in the [development](http
10473
10562
 
10474
10563
  [MIT](LICENSE.txt)
10475
10564
 
10476
- Copyright (c) 2021 Andy Maleh
10565
+ Copyright (c) 2021-2022 Andy Maleh
10477
10566
 
10478
10567
  --
10479
10568
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.20
1
+ 0.5.1
data/bin/girb_runner.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020-2021 Andy Maleh
1
+ # Copyright (c) 2021-2022 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -28,7 +28,7 @@ class AreaBasedCustomControls
28
28
 
29
29
  def rebuild_text_label
30
30
  @text_label.destroy
31
- @text_label_vertical_box.content { # re-open vertical box content and shove in a new button
31
+ @text_label_vertical_box.content { # re-open vertical box content and shove in a new label
32
32
  @text_label = text_label('This is a text label.',
33
33
  width: label_width, height: label_height, font_descriptor: label_font_descriptor,
34
34
  background_fill: label_background_fill, text_color: label_text_color, border_stroke: label_border_stroke,
@@ -206,6 +206,10 @@ class AreaBasedCustomControls
206
206
  # background_fill can accept a single color or gradient stops just as per `fill` property in README.
207
207
  # border_stroke is transparent by default.
208
208
  # border_stroke can accept thickness and dashes in addition to color just as per `stroke` property in README.
209
+ # text_x and text_y are the offset of the label text in relation to its top-left corner.
210
+ # When text_x, text_y are left nil, the text is automatically centered in the label area.
211
+ # Sometimes, the centering calculation is not perfect due to using a custom font, so
212
+ # in that case, pass in text_x, and text_y manually.
209
213
  def text_label(label_text,
210
214
  width: 80, height: 30, font_descriptor: {},
211
215
  background_fill: {a: 0}, text_color: :black, border_stroke: {a: 0},
@@ -240,10 +244,10 @@ class AreaBasedCustomControls
240
244
  # background_fill can accept a single color or gradient stops just as per `fill` property in README.
241
245
  # border_stroke is black by default.
242
246
  # border_stroke can accept thickness and dashes in addition to color just as per `stroke` property in README.
243
- # text_x and text_y are the offset of the button text in releation to its top-left corner
247
+ # text_x and text_y are the offset of the button text in relation to its top-left corner.
244
248
  # When text_x, text_y are left nil, the text is automatically centered in the button area.
245
249
  # Sometimes, the centering calculation is not perfect due to using a custom font, so
246
- # in that case, pass in text_x, and text_y manually
250
+ # in that case, pass in text_x, and text_y manually.
247
251
  #
248
252
  # reuses the text_label custom control
249
253
  def push_button(button_text,
@@ -81,7 +81,7 @@ class ColorTheCircles
81
81
 
82
82
  def color_circle(x, y)
83
83
  clicked_circle_data = @circles_data.find do |circle_data|
84
- circle_data[:fill].nil? && circle_data[:circle]&.include?(x, y)
84
+ circle_data[:fill].nil? && circle_data[:circle]&.contain?(x, y)
85
85
  end
86
86
  if clicked_circle_data
87
87
  clicked_circle_data[:fill] = clicked_circle_data[:stroke]
@@ -11,8 +11,9 @@ class Snake
11
11
  FILE_HIGH_SCORE = File.expand_path(File.join(Dir.home, '.glimmer-snake'))
12
12
 
13
13
  attr_reader :width, :height
14
- attr_accessor :snake, :apple, :over, :score, :high_score
14
+ attr_accessor :snake, :apple, :over, :score, :high_score, :paused
15
15
  alias over? over
16
+ alias paused? paused
16
17
 
17
18
  def initialize(width = WIDTH_DEFAULT, height = HEIGHT_DEFAULT)
18
19
  @width = width
@@ -42,6 +43,22 @@ class Snake
42
43
  self.apple.generate
43
44
  end
44
45
 
46
+ def pause
47
+ self.paused = true
48
+ end
49
+
50
+ def resume
51
+ self.paused = false
52
+ end
53
+
54
+ def toggle_pause
55
+ unless paused?
56
+ pause
57
+ else
58
+ resume
59
+ end
60
+ end
61
+
45
62
  # inspect is overridden to prevent printing very long stack traces
46
63
  def inspect
47
64
  "#{super[0, 75]}... >"
data/examples/snake.rb CHANGED
@@ -32,7 +32,7 @@ class Snake
32
32
  end
33
33
 
34
34
  Glimmer::LibUI.timer(SNAKE_MOVE_DELAY) do
35
- unless @game.over?
35
+ unless @game.paused? || @game.over?
36
36
  process_queued_keypress
37
37
  @game.snake.move
38
38
  end
@@ -73,7 +73,11 @@ class Snake
73
73
  }
74
74
 
75
75
  on_key_up do |area_key_event|
76
- @keypress_queue << area_key_event[:ext_key]
76
+ if area_key_event[:key] == ' '
77
+ @game.toggle_pause
78
+ else
79
+ @keypress_queue << area_key_event[:ext_key]
80
+ end
77
81
  end
78
82
  }
79
83
  end
data/examples/snake2.rb CHANGED
@@ -40,7 +40,7 @@ class Snake
40
40
  end
41
41
 
42
42
  Glimmer::LibUI.timer(SNAKE_MOVE_DELAY) do
43
- unless @game.over?
43
+ unless @game.paused? || @game.over?
44
44
  process_queued_keypress
45
45
  @game.snake.move
46
46
  end
@@ -83,7 +83,11 @@ class Snake
83
83
  }
84
84
 
85
85
  on_key_up do |area_key_event|
86
- @keypress_queue << area_key_event[:ext_key]
86
+ if area_key_event[:key] == ' '
87
+ @game.toggle_pause
88
+ else
89
+ @keypress_queue << area_key_event[:ext_key]
90
+ end
87
91
  end
88
92
  }
89
93
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2007-2021 Andy Maleh
1
+ # Copyright (c) 2021-2022 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the