glimmer-dsl-libui 0.2.20 → 0.2.24

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70f45c14b2e19345bb8ca1a16409260ef9835daf69053febcc6e28309a58618d
4
- data.tar.gz: 06e4d212588dff9195b6cc6df82bcca4f6c1fcc1f401abc5d174ef88aa20164a
3
+ metadata.gz: a9b4b92bdc276153bae236387b4813b62bc1b8b9f5b6779c59ffae9b1b47484f
4
+ data.tar.gz: 69efbe44dac5e3fec15ec31c261b469187a45d8acabf2d9754459f1bbfbc66d7
5
5
  SHA512:
6
- metadata.gz: 18a072c532d014a9849e96c6add0a7279200384c11478c99c2271e6f34cd30c2035d751f4644e8eb1f78f847497d1be0126c795efc32582ce22727c0b71ab029
7
- data.tar.gz: efe76c9b3c7439eb27b2b8c1159a5d133966b8282b130c983544bf60b1df41134267dbdc59a3b08e94d6491dffbe9e0a9d54a9afcad89701f68e3c17fbd6bcc4
6
+ metadata.gz: 39ef3e3f8db68098d52222ef7ffa3ed5f9d85e25199ed960d9945e2f92a13bd90cdfc860fcd5fd901a6b76d3899786ef9363fad131d7bc25880506b4355ef2dd
7
+ data.tar.gz: 0f92e07ed0e37bfc7e172b275d57853b26407b9f708554d586a4b6b97460485926217f364cad5cfdf3b016a37366acd51dbf440004709909f5d9cf924a8d7734
data/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.24
4
+
5
+ - Support hex colors as `String` with `'#'` prefix (e.g. '#ffaa92')
6
+
7
+ ## 0.2.23
8
+
9
+ - Improve examples/tetris.rb by having high score dialog pause the game if running and resume after closed
10
+ - Adjust Area Gallery example text size to 11 in Windows/Linux
11
+ - Fix `Glimmer::LibUI::timer {}` behavior so that the block return value will not affect repetition outcome if it is `Integer` (only Booleans affect it)
12
+ - Fix Tetris down button for Windows (it was going too fast before making tetrominos invisible before they hit the bottom)
13
+ - Fix Tetris double-downs (or multiple downs) happening after game over (it was firing an additional down timer after game over by mistake before)
14
+ - Fix Tetris by prechecking Turn Left on Up radio menu item since it is the one selected upon launch of the game
15
+ - Fix Tic-Tac-Toe text-size for Windows/Linux
16
+
17
+ ## 0.2.22
18
+
19
+ - examples/snake.rb implemented test-first
20
+
21
+ ## 0.2.21
22
+
23
+ - examples/tic_tac_toe.rb
24
+ - `Glimmer::LibUI::enum_names` provides all possible enum names to use with `Glimmer::LibUI::enum_symbols(enum_name)`
25
+ - Document all `Glimmer::LibUI` custom operations
26
+ - Fix issue with retrieving `Glimmer::LibUI::enum_symbols` for `:at` enum name
27
+
3
28
  ## 0.2.20
4
29
 
5
30
  - Improve examples/tetris.rb with menus, high score dialog, and options
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.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.2.24
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)
@@ -143,7 +143,7 @@ window('Area Gallery', 400, 400) {
143
143
  }
144
144
  text(161, 40, 100) { # x, y, width
145
145
  string('Area Gallery') {
146
- font family: 'Arial', size: 14
146
+ font family: 'Arial', size: (OS.mac? ? 14 : 11)
147
147
  color :black
148
148
  }
149
149
  }
@@ -218,9 +218,10 @@ NOTE: [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) is fe
218
218
  Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interested in:
219
219
  - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
220
220
  - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps)
221
+ - [glimmer-dsl-tk](https://github.com/AndyObtiva/glimmer-dsl-tk): Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library)
222
+ - [glimmer-dsl-gtk](https://github.com/AndyObtiva/glimmer-dsl-gtk): Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library)
221
223
  - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
222
224
  - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS
223
- - [glimmer-dsl-tk](https://github.com/AndyObtiva/glimmer-dsl-tk): Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library)
224
225
 
225
226
  ## Table of Contents
226
227
 
@@ -278,6 +279,8 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
278
279
  - [Custom Draw Text](#custom-draw-text)
279
280
  - [Method-Based Custom Keyword](#method-based-custom-keyword)
280
281
  - [Tetris](#tetris)
282
+ - [Tic Tac Toe](#tic-tac-toe)
283
+ - [Snake](#snake)
281
284
  - [Applications](#applications)
282
285
  - [Manga2PDF](#manga2pdf)
283
286
  - [Befunge98 GUI](#befunge98-gui)
@@ -370,7 +373,7 @@ gem install glimmer-dsl-libui
370
373
  Or install via Bundler `Gemfile`:
371
374
 
372
375
  ```ruby
373
- gem 'glimmer-dsl-libui', '~> 0.2.20'
376
+ gem 'glimmer-dsl-libui', '~> 0.2.24'
374
377
  ```
375
378
 
376
379
  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.
@@ -545,6 +548,35 @@ All operations that could normally be called on `LibUI` can also be called on `G
545
548
  - `Glimmer::LibUI::queue_main(&block)`: queues an operation to be run on the main event loop at the earliest opportunity possible
546
549
  - `Glimmer::LibUI::timer(time_in_seconds=0.1, repeat: true, &block)`: calls block after time_in_seconds has elapsed, repeating indefinitely unless repeat is `false` or an `Integer` for finite number of repeats. Block can return `false` or `true` to override next repetition.
547
550
 
551
+ There are additional useful `Glimmer::LibUI` operations that are not found in `LibUI`, which mostly help if you would like to do advanced lower level [LibUI](https://github.com/kojix2/LibUI) programming:
552
+ - `Glimmer::LibUI::integer_to_boolean(int, allow_nil: true)`
553
+ - `Glimmer::LibUI::boolean_to_integer(int, allow_nil: true)`
554
+ - `Glimmer::LibUI::degrees_to_radians(degrees)`
555
+ - `Glimmer::LibUI::interpret_color(value)`: interprets a color in any form like `String`, `Symbol`, or hex into an rgb `Hash` (including `0x1f3b5d`, `'0x1f3b5d'`, `'#1f3b5d'`, and 3-char hex-shorthand variations)
556
+ - `Glimmer::LibUI::hex_to_rgb(value)`: converts a hex color to an rgb `Hash` (including `0x1f3b5d`, `'0x1f3b5d'`, `'#1f3b5d'`, and 3-char hex-shorthand variations)
557
+ - `Glimmer::LibUI::enum_names`: provides all possible enum names to use with `Glimmer::LibUI::enum_symbols(enum_name)`
558
+ - `Glimmer::LibUI::enum_symbols(enum_name)`: returns all possible values for an enum. `enum_name` can be:
559
+ - `:draw_brush_type`: `[:solid, :linear_gradient, :radial_gradient, :image]`
560
+ - `:draw_line_cap`: `[:flat, :round, :square]`
561
+ - `:draw_line_join`: `[:miter, :round, :bevel]`
562
+ - `:draw_fill_mode`: `[:winding, :alternate]`
563
+ - `:attribute_type`: attributes for attributed `string`s: `[:family, :size, weight, :italic, :stretch, :color, :background, :underline, :underline_color, :features]`
564
+ - `:text_weight`: `[:minimum, :thin, :ultra_light, :light, :book, :normal, :medium, :semi_bold, :bold, :ultra_bold, :heavy, :ultra_heavy, :maximum]`
565
+ - `:text_italic`: `[:normal, :oblique, :italic]`
566
+ - `:text_stretch`: `[:ultra_condensed, :extra_condensed, :condensed, :semi_condensed, :normal, :semi_expanded, :expanded, :extra_expanded, :ultra_expanded]`
567
+ - `:underline`: `[:none, :single, :double, :suggestion, :color_custom, :color_spelling, :color_grammar, :color_auxiliary]`
568
+ - `:underline_color`: `[:custom, :spelling, :grammar, :auxiliary]`
569
+ - `:draw_text_align`: `[:left, :center, :right]`
570
+ - `:modifier`: `[:ctrl, :alt, :shift, :super]`
571
+ - `:ext_key`: `[:escape, :insert, :delete, :home, :end, :page_up, :page_down, :up, :down, :left, :right, :f1, :f2, :f3, :f4, :f5, :f6, :f7, :f8, :f9, :f10, :f11, :f12, :n0, :n1, :n2, :n3, :n4, :n5, :n6, :n7, :n8, :n9, :n_dot, :n_enter, :n_add, :n_subtract, :n_multiply, :n_divide]`
572
+ - `:at`: for inserting `grid` controls: `[:leading, :top, :trailing, :bottom]`
573
+ - `:align`: `[:fill, :start, :center, :end]`
574
+ - `:table_value_type`: `[:string, :image, :int, :color]`
575
+ - `:table_model_column`: `[:never_editable, :always_editable]`
576
+ - `Glimmer::LibUI::enum_symbol_to_value(enum_name, enum_symbol, default_symbol: nil, default_index: 0)`
577
+ - `Glimmer::LibUI::enum_value_to_symbol(enum_name, enum_value)`
578
+ - `Glimmer::LibUI::x11_colors`: returns all [X11 colors](https://en.wikipedia.org/wiki/X11_color_names): `[:alice_blue, :antique_white, :aqua, :aquamarine, :azure, :beige, :bisque, :rebecca_purple, :becca_purple, :blanched_almond, :blue, :blue_violet, :brown, :burly_wood, :burlywood, :cadet_blue, :carnation, :cayenne, :chartreuse, :chocolate, :coral, :cornflower_blue, :cornsilk, :crimson, :cyan, :dark_blue, :dark_cyan, :dark_golden_rod, :dark_goldenrod, :dark_gray, :dark_grey, :dark_green, :dark_khaki, :dark_magenta, :dark_olive_green, :darkolive_green, :dark_orange, :dark_orchid, :dark_red, :dark_salmon, :darksalmon, :dark_sea_green, :dark_slate_blue, :dark_slate_gray, :dark_slate_grey, :dark_turquoise, :dark_violet, :darkorange, :deep_pink, :deep_sky_blue, :dim_gray, :dim_grey, :dodger_blue, :feldspar, :fire_brick, :firebrick, :floral_white, :forest_green, :fuchsia, :gainsboro, :ghost_white, :gold, :golden_rod, :goldenrod, :gray, :grey, :gray10, :grey10, :gray20, :grey20, :gray30, :grey30, :gray40, :grey40, :gray50, :grey50, :gray60, :grey60, :gray70, :grey70, :gray80, :grey80, :gray90, :grey90, :green, :green_yellow, :honey_dew, :honeydew, :hot_pink, :indian_red, :indigo, :ivory, :khaki, :lavender, :lavender_blush, :lawn_green, :lemon_chiffon, :light_blue, :light_coral, :light_cyan, :light_golden_rod_yellow, :light_goldenrod_yellow, :light_gray, :light_grey, :light_green, :light_pink, :light_salmon, :lightsalmon, :light_sea_green, :light_sky_blue, :light_slate_blue, :light_slate_gray, :light_slate_grey, :light_steel_blue, :lightsteel_blue, :light_yellow, :lime, :lime_green, :linen, :magenta, :maroon, :medium_aqua_marine, :medium_aquamarine, :medium_blue, :medium_orchid, :medium_purple, :medium_sea_green, :medium_slate_blue, :medium_spring_green, :medium_turquoise, :medium_violet_red, :midnight_blue, :mint_cream, :misty_rose, :moccasin, :navajo_white, :navy, :old_lace, :olive, :olive_drab, :olivedrab, :orange, :orange_red, :orchid, :pale_golden_rod, :pale_goldenrod, :pale_green, :pale_turquoise, :pale_violet_red, :papaya_whip, :peach_puff, :peachpuff, :peru, :pink, :plum, :powder_blue, :purple, :red, :rosy_brown, :royal_blue, :saddle_brown, :salmon, :sandy_brown, :sea_green, :sea_shell, :seashell, :sienna, :silver, :sky_blue, :slate_blue, :slate_gray, :slate_grey, :snow, :spring_green, :steel_blue, :tan, :teal, :thistle, :tomato, :turquoise, :violet, :violet_red, :wheat, :white_smoke, :yellow, :yellow_green, :metallic, :white, :black, :gray_scale, :grey_scale]`
579
+
548
580
  ### Extra Dialogs
549
581
 
550
582
  - `open_file(window as Glimmer::LibUI::WindowProxy = ControlProxy::main_window_proxy)`: returns selected file (`String`) or `nil` if cancelled
@@ -869,11 +901,13 @@ transform m1
869
901
  # and then reuse m1 elsewhere too
870
902
  ```
871
903
 
904
+ You can set a `matrix`/`transform` on `area` directly to conveniently apply to all nested `path`s too.
905
+
872
906
  Note that `area`, `path`, and nested shapes are all truly declarative, meaning they do not care about the ordering of calls to `fill`, `stroke`, and `transform`. Furthermore, any transform that is applied is reversed at the end of the block, so you never have to worry about the ordering of `transform` calls among different paths. You simply set a transform on the `path`s that need it and it is guaranteed to be called before all its content is drawn, and then undone afterwards to avoid affecting later paths. Matrix `transform` can be set on an entire `area` too, applying to all nested `path`s.
873
907
 
874
- `fill` and `stroke` accept [X11](https://en.wikipedia.org/wiki/X11_color_names) color `Symbol`s/`String`s like `:skyblue` and `'sandybrown'` or 6-number hex or 3-number hex-shorthand (as `Integer` or `String` with or without `0x` prefix)
908
+ `fill` and `stroke` accept [X11](https://en.wikipedia.org/wiki/X11_color_names) color `Symbol`s/`String`s like `:skyblue` and `'sandybrown'` or 6-char hex or 3-char hex-shorthand (as `Integer` or `String` with or without `0x` prefix)
875
909
 
876
- Available [X11](https://en.wikipedia.org/wiki/X11_color_names) colors can be obtained through `Glimmer::LibUI.x11_colors` method.
910
+ Available [X11 colors](https://en.wikipedia.org/wiki/X11_color_names) can be obtained through `Glimmer::LibUI.x11_colors` method.
877
911
 
878
912
  Check [Basic Transform](#basic-transform) example for use of [X11](https://en.wikipedia.org/wiki/X11_color_names) colors.
879
913
 
@@ -964,7 +998,7 @@ window('area text drawing') {
964
998
  - All controls are protected from garbage collection until no longer needed (explicitly destroyed), so there is no need to worry about surprises.
965
999
  - All resources are freed automatically once no longer needed or left to garbage collection.
966
1000
  - When nesting an `area` directly underneath `window` (without a layout control like `vertical_box`), it is automatically reparented with `vertical_box` in between the `window` and `area` since it would not show up on Linux otherwise.
967
- - Colors may be passed in as a hash of `:r`, `:g`, `:b`, `:a`, or `:red`, `:green`, `:blue`, `:alpha`, or [X11](https://en.wikipedia.org/wiki/X11_color_names) color like `:skyblue`, or 6-number hex or 3-number hex (as `Integer` or `String` with or without `0x` prefix)
1001
+ - Colors may be passed in as a hash of `:r`, `:g`, `:b`, `:a`, or `:red`, `:green`, `:blue`, `:alpha`, or [X11](https://en.wikipedia.org/wiki/X11_color_names) color like `:skyblue`, or 6-char hex or 3-char hex (as `Integer` or `String` with or without `0x` prefix)
968
1002
  - Color alpha value defaults to `1.0` when not specified.
969
1003
 
970
1004
  ### Custom Keywords
@@ -1090,8 +1124,8 @@ window('Method-Based Custom Keyword') {
1090
1124
 
1091
1125
  To learn more about the [LibUI](https://github.com/kojix2/LibUI) API exposed through [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui):
1092
1126
  - Check out [LibUI ffi.rb](https://github.com/kojix2/LibUI/blob/main/lib/libui/ffi.rb)
1093
- - Check out the [libui C headers](https://github.com/andlabs/libui/blob/master/ui.h)
1094
- - Check out the [Go UI (Golang LibUI) documentation](https://pkg.go.dev/github.com/andlabs/ui) for an alternative well-documented [libui](https://github.com/andlabs/libui) reference.
1127
+ - Check out the [libui C Headers](https://github.com/andlabs/libui/blob/master/ui.h)
1128
+ - Check out the [Go UI (Golang LibUI) API Documentation](https://pkg.go.dev/github.com/andlabs/ui) for an alternative well-documented [libui](https://github.com/andlabs/libui) reference.
1095
1129
 
1096
1130
  ## Packaging
1097
1131
 
@@ -1191,7 +1225,7 @@ class MetaExample
1191
1225
 
1192
1226
  def run_example(example)
1193
1227
  Thread.new do
1194
- command = "ruby -r #{glimmer_dsl_libui_file} #{example} 2>&1"
1228
+ command = "#{RbConfig.ruby} -r #{glimmer_dsl_libui_file} #{example} 2>&1"
1195
1229
  result = ''
1196
1230
  IO.popen(command) do |f|
1197
1231
  sleep(0.0001) # yield to main thread
@@ -1728,11 +1762,11 @@ class TinyMidiPlayer
1728
1762
 
1729
1763
  UI.new_horizontal_box.tap do |hbox|
1730
1764
  UI.new_vertical_box.tap do |vbox|
1731
- UI.new_button('').tap do |button1|
1765
+ UI.new_button('â–¶').tap do |button1|
1732
1766
  UI.button_on_clicked(button1) { play_midi }
1733
1767
  UI.box_append(vbox, button1, 1)
1734
1768
  end
1735
- UI.new_button('').tap do |button2|
1769
+ UI.new_button('â– ').tap do |button2|
1736
1770
  UI.button_on_clicked(button2) { stop_midi }
1737
1771
  UI.box_append(vbox, button2, 1)
1738
1772
  end
@@ -1826,12 +1860,12 @@ class TinyMidiPlayer
1826
1860
  vertical_box {
1827
1861
  stretchy false
1828
1862
 
1829
- button('') {
1863
+ button('â–¶') {
1830
1864
  on_clicked do
1831
1865
  play_midi
1832
1866
  end
1833
1867
  }
1834
- button('') {
1868
+ button('â– ') {
1835
1869
  on_clicked do
1836
1870
  stop_midi
1837
1871
  end
@@ -4097,7 +4131,7 @@ window('Area Gallery', 400, 400) {
4097
4131
  }
4098
4132
  text(161, 40, 100) { # x, y, width
4099
4133
  string('Area Gallery') {
4100
- font family: 'Arial', size: 14
4134
+ font family: 'Arial', size: (OS.mac? ? 14 : 11)
4101
4135
  color :black
4102
4136
  }
4103
4137
  }
@@ -4307,7 +4341,7 @@ window('Area Gallery', 400, 400) {
4307
4341
  width 100
4308
4342
 
4309
4343
  string {
4310
- font family: 'Arial', size: 14
4344
+ font family: 'Arial', size: (OS.mac? ? 14 : 11)
4311
4345
  color :black
4312
4346
 
4313
4347
  'Area Gallery'
@@ -4420,7 +4454,7 @@ window('Area Gallery', 400, 400) {
4420
4454
  }
4421
4455
  text(161, 40, 100) { # x, y, width
4422
4456
  string('Area Gallery') {
4423
- font family: 'Arial', size: 14
4457
+ font family: 'Arial', size: (OS.mac? ? 14 : 11)
4424
4458
  color :black
4425
4459
  }
4426
4460
  }
@@ -4632,7 +4666,7 @@ window('Area Gallery', 400, 400) {
4632
4666
  width 100
4633
4667
 
4634
4668
  string {
4635
- font family: 'Arial', size: 14
4669
+ font family: 'Arial', size: (OS.mac? ? 14 : 11)
4636
4670
  color :black
4637
4671
 
4638
4672
  'Area Gallery'
@@ -6236,7 +6270,7 @@ window('Method-Based Custom Keyword') {
6236
6270
 
6237
6271
  ### Tetris
6238
6272
 
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.
6273
+ Glimmer Tetris utilizes many small areas to represent Tetromino blocks because this ensures smaller redraws per tetromino block color change, thus achieving higher performance than redrawing one large area on every little change.
6240
6274
 
6241
6275
  [examples/tetris.rb](examples/tetris.rb)
6242
6276
 
@@ -6260,6 +6294,22 @@ Mac
6260
6294
 
6261
6295
  ![glimmer-dsl-libui-mac-tetris-high-scores.png](images/glimmer-dsl-libui-mac-tetris-high-scores.png)
6262
6296
 
6297
+ Windows
6298
+
6299
+ ![glimmer-dsl-libui-windows-tetris.png](images/glimmer-dsl-libui-windows-tetris.png)
6300
+
6301
+ ![glimmer-dsl-libui-windows-tetris-game-over.png](images/glimmer-dsl-libui-windows-tetris-game-over.png)
6302
+
6303
+ ![glimmer-dsl-libui-windows-tetris-high-scores.png](images/glimmer-dsl-libui-windows-tetris-high-scores.png)
6304
+
6305
+ Linux
6306
+
6307
+ ![glimmer-dsl-libui-linux-tetris.png](images/glimmer-dsl-libui-linux-tetris.png)
6308
+
6309
+ ![glimmer-dsl-libui-linux-tetris-game-over.png](images/glimmer-dsl-libui-linux-tetris-game-over.png)
6310
+
6311
+ ![glimmer-dsl-libui-linux-tetris-high-scores.png](images/glimmer-dsl-libui-linux-tetris-high-scores.png)
6312
+
6263
6313
  New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
6264
6314
 
6265
6315
  ```ruby
@@ -6500,7 +6550,19 @@ class Tetris
6500
6550
  on_key_down do |key_event|
6501
6551
  case key_event
6502
6552
  in ext_key: :down
6503
- @game.down!
6553
+ if OS.windows?
6554
+ # rate limit downs in Windows as they go too fast when key is held
6555
+ @queued_downs ||= 0
6556
+ if @queued_downs < 2
6557
+ @queued_downs += 1
6558
+ Glimmer::LibUI.timer(0.01, repeat: false) do
6559
+ @game.down! if @queued_downs < 2
6560
+ @queued_downs -= 1
6561
+ end
6562
+ end
6563
+ else
6564
+ @game.down!
6565
+ end
6504
6566
  in key: ' '
6505
6567
  @game.down!(instant: true)
6506
6568
  in ext_key: :up
@@ -6584,8 +6646,11 @@ class Tetris
6584
6646
  end
6585
6647
 
6586
6648
  def start_moving_tetrominos_down
6587
- Glimmer::LibUI.timer(@game.delay) do
6588
- @game.down! if !@game.game_over? && !@game.paused?
6649
+ unless @tetrominos_start_moving_down
6650
+ @tetrominos_start_moving_down = true
6651
+ Glimmer::LibUI.timer(@game.delay) do
6652
+ @game.down! if !@game.game_over? && !@game.paused?
6653
+ end
6589
6654
  end
6590
6655
  end
6591
6656
 
@@ -6598,6 +6663,8 @@ class Tetris
6598
6663
 
6599
6664
  def show_high_scores
6600
6665
  Glimmer::LibUI.queue_main do
6666
+ game_paused = !!@game.paused
6667
+ @game.paused = true
6601
6668
  if @game.high_scores.empty?
6602
6669
  high_scores_string = "No games have been scored yet."
6603
6670
  else
@@ -6606,6 +6673,7 @@ class Tetris
6606
6673
  end.join("\n")
6607
6674
  end
6608
6675
  msg_box('High Scores', high_scores_string)
6676
+ @game.paused = game_paused
6609
6677
  end
6610
6678
  end
6611
6679
 
@@ -6619,6 +6687,273 @@ end
6619
6687
  Tetris.new.launch
6620
6688
  ```
6621
6689
 
6690
+ ### Tic Tac Toe
6691
+
6692
+ [examples/tic_tac_toe.rb](examples/tic_tac_toe.rb)
6693
+
6694
+ Run with this command from the root of the project if you cloned the project:
6695
+
6696
+ ```
6697
+ ruby -r './lib/glimmer-dsl-libui' examples/tic_tac_toe.rb
6698
+ ```
6699
+
6700
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
6701
+
6702
+ ```
6703
+ ruby -r glimmer-dsl-libui -e "require 'examples/tic_tac_toe'"
6704
+ ```
6705
+
6706
+ Mac
6707
+
6708
+ ![glimmer-dsl-libui-mac-tic-tac-toe.png](images/glimmer-dsl-libui-mac-tic-tac-toe.png)
6709
+
6710
+ ![glimmer-dsl-libui-mac-tic-tac-toe-player-o-wins.png](images/glimmer-dsl-libui-mac-tic-tac-toe-player-o-wins.png)
6711
+
6712
+ ![glimmer-dsl-libui-mac-tic-tac-toe-player-x-wins.png](images/glimmer-dsl-libui-mac-tic-tac-toe-player-x-wins.png)
6713
+
6714
+ ![glimmer-dsl-libui-mac-tic-tac-toe-draw.png](images/glimmer-dsl-libui-mac-tic-tac-toe-draw.png)
6715
+
6716
+ Windows
6717
+
6718
+ ![glimmer-dsl-libui-windows-tic-tac-toe.png](images/glimmer-dsl-libui-windows-tic-tac-toe.png)
6719
+
6720
+ ![glimmer-dsl-libui-windows-tic-tac-toe-player-o-wins.png](images/glimmer-dsl-libui-windows-tic-tac-toe-player-o-wins.png)
6721
+
6722
+ ![glimmer-dsl-libui-windows-tic-tac-toe-player-x-wins.png](images/glimmer-dsl-libui-windows-tic-tac-toe-player-x-wins.png)
6723
+
6724
+ ![glimmer-dsl-libui-windows-tic-tac-toe-draw.png](images/glimmer-dsl-libui-windows-tic-tac-toe-draw.png)
6725
+
6726
+ Linux
6727
+
6728
+ ![glimmer-dsl-libui-linux-tic-tac-toe.png](images/glimmer-dsl-libui-linux-tic-tac-toe.png)
6729
+
6730
+ ![glimmer-dsl-libui-linux-tic-tac-toe-player-o-wins.png](images/glimmer-dsl-libui-linux-tic-tac-toe-player-o-wins.png)
6731
+
6732
+ ![glimmer-dsl-libui-linux-tic-tac-toe-player-x-wins.png](images/glimmer-dsl-libui-linux-tic-tac-toe-player-x-wins.png)
6733
+
6734
+ ![glimmer-dsl-libui-linux-tic-tac-toe-draw.png](images/glimmer-dsl-libui-linux-tic-tac-toe-draw.png)
6735
+
6736
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
6737
+
6738
+ ```ruby
6739
+ require 'glimmer-dsl-libui'
6740
+
6741
+ require_relative "tic_tac_toe/board"
6742
+
6743
+ class TicTacToe
6744
+ include Glimmer
6745
+
6746
+ def initialize
6747
+ @tic_tac_toe_board = Board.new
6748
+ end
6749
+
6750
+ def launch
6751
+ create_gui
6752
+ register_observers
6753
+ @main_window.show
6754
+ end
6755
+
6756
+ def register_observers
6757
+ Glimmer::DataBinding::Observer.proc do |game_status|
6758
+ display_win_message if game_status == Board::WIN
6759
+ display_draw_message if game_status == Board::DRAW
6760
+ end.observe(@tic_tac_toe_board, :game_status)
6761
+
6762
+ 3.times.map do |row|
6763
+ 3.times.map do |column|
6764
+ Glimmer::DataBinding::Observer.proc do |sign|
6765
+ @cells[row][column].string = sign
6766
+ end.observe(@tic_tac_toe_board[row + 1, column + 1], :sign) # board model is 1-based
6767
+ end
6768
+ end
6769
+ end
6770
+
6771
+ def create_gui
6772
+ @main_window = window('Tic-Tac-Toe', 180, 180) {
6773
+ resizable false
6774
+
6775
+ @cells = []
6776
+ vertical_box {
6777
+ padded false
6778
+
6779
+ 3.times.map do |row|
6780
+ @cells << []
6781
+ horizontal_box {
6782
+ padded false
6783
+
6784
+ 3.times.map do |column|
6785
+ area {
6786
+ path {
6787
+ square(0, 0, 60)
6788
+
6789
+ stroke :black, thickness: 2
6790
+ }
6791
+ text(23, 19) {
6792
+ @cells[row] << string('') {
6793
+ font family: 'Arial', size: 20
6794
+ }
6795
+ }
6796
+ on_mouse_up do
6797
+ @tic_tac_toe_board.mark(row + 1, column + 1) # board model is 1-based
6798
+ end
6799
+ }
6800
+ end
6801
+ }
6802
+ end
6803
+ }
6804
+ }
6805
+ end
6806
+
6807
+ def display_win_message
6808
+ display_game_over_message("Player #{@tic_tac_toe_board.winning_sign} has won!")
6809
+ end
6810
+
6811
+ def display_draw_message
6812
+ display_game_over_message("Draw!")
6813
+ end
6814
+
6815
+ def display_game_over_message(message_text)
6816
+ Glimmer::LibUI.queue_main do
6817
+ msg_box('Game Over', message_text)
6818
+ @tic_tac_toe_board.reset!
6819
+ end
6820
+ end
6821
+ end
6822
+
6823
+ TicTacToe.new.launch
6824
+ ```
6825
+
6826
+ ### Snake
6827
+
6828
+ 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.
6829
+
6830
+ [examples/snake.rb](examples/snake.rb)
6831
+
6832
+ Run with this command from the root of the project if you cloned the project:
6833
+
6834
+ ```
6835
+ ruby -r './lib/glimmer-dsl-libui' examples/snake.rb
6836
+ ```
6837
+
6838
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
6839
+
6840
+ ```
6841
+ ruby -r glimmer-dsl-libui -e "require 'examples/snake'"
6842
+ ```
6843
+
6844
+ Mac
6845
+
6846
+ ![glimmer-dsl-libui-mac-snake.png](images/glimmer-dsl-libui-mac-snake.png)
6847
+
6848
+ ![glimmer-dsl-libui-mac-snake-game-over.png](images/glimmer-dsl-libui-mac-snake-game-over.png)
6849
+
6850
+ Windows
6851
+
6852
+ ![glimmer-dsl-libui-windows-snake.png](images/glimmer-dsl-libui-windows-snake.png)
6853
+
6854
+ ![glimmer-dsl-libui-windows-snake-game-over.png](images/glimmer-dsl-libui-windows-snake-game-over.png)
6855
+
6856
+ Linux
6857
+
6858
+ ![glimmer-dsl-libui-linux-snake.png](images/glimmer-dsl-libui-linux-snake.png)
6859
+
6860
+ ![glimmer-dsl-libui-linux-snake-game-over.png](images/glimmer-dsl-libui-linux-snake-game-over.png)
6861
+
6862
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
6863
+
6864
+ ```ruby
6865
+ require 'glimmer-dsl-libui'
6866
+ require 'glimmer/data_binding/observer'
6867
+
6868
+ require_relative 'snake/presenter/grid'
6869
+
6870
+ class Snake
6871
+ CELL_SIZE = 15
6872
+ SNAKE_MOVE_DELAY = 0.1
6873
+ include Glimmer
6874
+
6875
+ def initialize
6876
+ @game = Model::Game.new
6877
+ @grid = Presenter::Grid.new(@game)
6878
+ @game.start
6879
+ create_gui
6880
+ register_observers
6881
+ end
6882
+
6883
+ def launch
6884
+ @main_window.show
6885
+ end
6886
+
6887
+ def register_observers
6888
+ @game.height.times do |row|
6889
+ @game.width.times do |column|
6890
+ Glimmer::DataBinding::Observer.proc do |new_color|
6891
+ @cell_grid[row][column].fill = new_color
6892
+ end.observe(@grid.cells[row][column], :color)
6893
+ end
6894
+ end
6895
+
6896
+ Glimmer::DataBinding::Observer.proc do |game_over|
6897
+ Glimmer::LibUI.queue_main do
6898
+ if game_over
6899
+ msg_box('Game Over!', "Score: #{@game.score}")
6900
+ @game.start
6901
+ end
6902
+ end
6903
+ end.observe(@game, :over)
6904
+
6905
+ Glimmer::LibUI.timer(SNAKE_MOVE_DELAY) do
6906
+ unless @game.over?
6907
+ @game.snake.move
6908
+ @main_window.title = "Glimmer Snake (Score: #{@game.score})"
6909
+ end
6910
+ end
6911
+ end
6912
+
6913
+ def create_gui
6914
+ @cell_grid = []
6915
+ @main_window = window('Glimmer Snake', @game.width * CELL_SIZE, @game.height * CELL_SIZE) {
6916
+ resizable false
6917
+
6918
+ vertical_box {
6919
+ padded false
6920
+
6921
+ @game.height.times do |row|
6922
+ @cell_grid << []
6923
+ horizontal_box {
6924
+ padded false
6925
+
6926
+ @game.width.times do |column|
6927
+ area {
6928
+ @cell_grid.last << path {
6929
+ square(0, 0, CELL_SIZE)
6930
+
6931
+ fill Presenter::Cell::COLOR_CLEAR
6932
+ }
6933
+
6934
+ on_key_up do |area_key_event|
6935
+ orientation_and_key = [@game.snake.head.orientation, area_key_event[:ext_key]]
6936
+ case orientation_and_key
6937
+ in [:north, :right] | [:east, :down] | [:south, :left] | [:west, :up]
6938
+ @game.snake.turn_right
6939
+ in [:north, :left] | [:west, :down] | [:south, :right] | [:east, :up]
6940
+ @game.snake.turn_left
6941
+ else
6942
+ # No Op
6943
+ end
6944
+ end
6945
+ }
6946
+ end
6947
+ }
6948
+ end
6949
+ }
6950
+ }
6951
+ end
6952
+ end
6953
+
6954
+ Snake.new.launch
6955
+ ```
6956
+
6622
6957
  ## Applications
6623
6958
 
6624
6959
  Here are some applications built with [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui)
@@ -6649,9 +6984,10 @@ https://github.com/iraamaro/i3off-gtk-ruby
6649
6984
 
6650
6985
  ## Resources
6651
6986
 
6652
- - [libui C Library](https://github.com/andlabs/libui)
6653
- - [LibUI Ruby Bindings](https://github.com/kojix2/LibUI)
6654
6987
  - [Code Master Blog](https://andymaleh.blogspot.com/search/label/LibUI)
6988
+ - [LibUI Ruby Bindings](https://github.com/kojix2/LibUI)
6989
+ - [libui C Library](https://github.com/andlabs/libui)
6990
+ - [Go UI (Golang LibUI) API Documentation](https://pkg.go.dev/github.com/andlabs/ui)
6655
6991
 
6656
6992
  ## Help
6657
6993
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.20
1
+ 0.2.24
@@ -49,7 +49,7 @@ window('Area Gallery', 400, 400) {
49
49
  }
50
50
  text(161, 40, 100) { # x, y, width
51
51
  string('Area Gallery') {
52
- font family: 'Arial', size: 14
52
+ font family: 'Arial', size: (OS.mac? ? 14 : 11)
53
53
  color :black
54
54
  }
55
55
  }
@@ -149,7 +149,7 @@ window('Area Gallery', 400, 400) {
149
149
  width 100
150
150
 
151
151
  string {
152
- font family: 'Arial', size: 14
152
+ font family: 'Arial', size: (OS.mac? ? 14 : 11)
153
153
  color :black
154
154
 
155
155
  'Area Gallery'
@@ -50,7 +50,7 @@ window('Area Gallery', 400, 400) {
50
50
  }
51
51
  text(161, 40, 100) { # x, y, width
52
52
  string('Area Gallery') {
53
- font family: 'Arial', size: 14
53
+ font family: 'Arial', size: (OS.mac? ? 14 : 11)
54
54
  color :black
55
55
  }
56
56
  }
@@ -150,7 +150,7 @@ window('Area Gallery', 400, 400) {
150
150
  width 100
151
151
 
152
152
  string {
153
- font family: 'Arial', size: 14
153
+ font family: 'Arial', size: (OS.mac? ? 14 : 11)
154
154
  color :black
155
155
 
156
156
  'Area Gallery'
@@ -43,7 +43,7 @@ class MetaExample
43
43
 
44
44
  def run_example(example)
45
45
  Thread.new do
46
- command = "ruby -r #{glimmer_dsl_libui_file} #{example} 2>&1"
46
+ command = "#{RbConfig.ruby} -r #{glimmer_dsl_libui_file} #{example} 2>&1"
47
47
  result = ''
48
48
  IO.popen(command) do |f|
49
49
  sleep(0.0001) # yield to main thread