glimmer-dsl-libui 0.2.12 → 0.2.13

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: 3aefaaeba868daf629c8ec07474b45a78f10c2dfb17ef5fc748b97dc3f00447c
4
- data.tar.gz: eccf64a897d80f36e99f738c4cf528715c666ad80a86fa2c6abdb75d340edd39
3
+ metadata.gz: d0d69180e099ba8e4ef76b6d862542fd84753baf128e07ea17ef145ee1a4e20d
4
+ data.tar.gz: 25a96db46d241e7e17ec45778bda264fc662c77fcf9323e4eb0917ace5cda6da
5
5
  SHA512:
6
- metadata.gz: 9bc9daeb504c2133ceadb0556ec29ff2264789c4d0c86a1958752106beed708912830692125c660579914d1cea67fe16827056add48f7d132ab67c9e814ab15e
7
- data.tar.gz: ce7a85691919adb938b1eb3de235ca5fed5a9bfa4b484f649dff1a5a03ee7a46cabcd25cb7c54da9d86a60e215495e0e075f82c647f6e5125e491aa617491ef6
6
+ metadata.gz: 5073abc3a7bec0ffafa7d7dccc90273c9d6fbb5533a15a74b083a25df0d7a8b3e0dd7536429b47ea1d8b863afb4e98ef6de63943593025b3a53df39a7d455eeb
7
+ data.tar.gz: 33c26144db9e702762afaa3866685851e620208b60515937bdaccf44d059056c2232a325fc43d629f8998965f35b60106f390677ff2400305f711b1860475f4b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.13
4
+
5
+ - Rename examples/color_the_circles.rb to examples/color_the_shapes.rb to fix/make compatible with Windows by rendering only Squares on Windows, but Squares and Circles on Mac/Linux
6
+ - Fix examples/basic_table_button.rb double-deletion issue on Windows via a temporary workaround (generating an extra empty row on Windows only)
7
+ - Fix examples/basic_table_checkbox.rb , examples/basic_table_checkbox_text.rb , and examples/basic_table_color.rb on Windows
8
+ - Fix examples/basic_table_progress_bar.rb crash due to an issue on Windows when switching from -1 to a positive value
9
+ - Fix examples/area_gallery.rb (all its versions) by disabling arc/circle on Windows where they don't work due to issue in libui
10
+ - Fix girb on Windows
11
+ - Removed redundant `table` on_change notification
12
+ - Fix issue with supplying a font without all its keys (e.g. missing `:weight`) to attributed `string` nested under `text`, tolerating missing font keys.
13
+ - Fix issue with examples/color_the_circles.rb when clicking outside the playing area causing this error:
14
+ ```
15
+ examples/color_the_circles.rb:82:in `block in color_circle': undefined method `include?' for nil:NilClass (NoMethodError)
16
+ from examples/color_the_circles.rb:81:in `each'
17
+ from examples/color_the_circles.rb:81:in `find'
18
+ from examples/color_the_circles.rb:81:in `color_circle'
19
+ from examples/color_the_circles.rb:212:in `block (4 levels) in launch'
20
+ ```
21
+
3
22
  ## 0.2.12
4
23
 
5
24
  - Upgrade to glimmer 2.4.0
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.12
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.13
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)
@@ -119,19 +119,21 @@ window('Area Gallery', 400, 400) {
119
119
  fill r: 202, g: 102, b: 204, a: 0.5
120
120
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
121
121
  }
122
- path { # declarative stable path
123
- arc(400, 220, 180, 90, 90, false)
124
-
125
- # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
126
- fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
127
- stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
128
- }
129
- path { # declarative stable path
130
- circle(200, 200, 90)
131
-
132
- fill r: 202, g: 102, b: 204, a: 0.5
133
- stroke r: 0, g: 0, b: 0, thickness: 2
134
- }
122
+ unless OS.windows?
123
+ path { # declarative stable path
124
+ arc(400, 220, 180, 90, 90, false)
125
+
126
+ # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
127
+ fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
128
+ stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
129
+ }
130
+ path { # declarative stable path
131
+ circle(200, 200, 90)
132
+
133
+ fill r: 202, g: 102, b: 204, a: 0.5
134
+ stroke r: 0, g: 0, b: 0, thickness: 2
135
+ }
136
+ end
135
137
  text(160, 40, 100) { # x, y, width
136
138
  string('Area Gallery') {
137
139
  font family: 'Times', size: 14
@@ -255,7 +257,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
255
257
  - [Basic Transform](#basic-transform)
256
258
  - [Login](#login)
257
259
  - [Timer](#timer)
258
- - [Color The Circles](#color-the-circles)
260
+ - [Color The Shapes](#color-the-shapes)
259
261
  - [Basic Draw Text](#basic-draw-text)
260
262
  - [Custom Draw Text](#custom-draw-text)
261
263
  - [Method-Based Custom Keyword](#method-based-custom-keyword)
@@ -346,7 +348,7 @@ gem install glimmer-dsl-libui
346
348
  Or install via Bundler `Gemfile`:
347
349
 
348
350
  ```ruby
349
- gem 'glimmer-dsl-libui', '~> 0.2.12'
351
+ gem 'glimmer-dsl-libui', '~> 0.2.13'
350
352
  ```
351
353
 
352
354
  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.
@@ -1013,6 +1015,10 @@ window('Method-Based Custom Keyword') {
1013
1015
  - There is no proper way to destroy `grid` children due to [libui](https://github.com/andlabs/libui) not offering any API for deleting them from `grid` (no `grid_delete` similar to `box_delete` for `horizontal_box` and `vertical_box`).
1014
1016
  - `table` `checkbox_column` and `checkbox_text_column` checkbox editing only works on Windows and Linux (not Mac) due to a current limitation in [libui](https://github.com/andlabs/ui/issues/357).
1015
1017
  - `text` `align` property seems not to work on the Mac ([libui](https://github.com/andlabs/libui) has an [issue](https://github.com/andlabs/libui/pull/407) about it)
1018
+ - `text` `string` `background` does not work on Windows due to an issue in [libui](https://github.com/andlabs/libui).
1019
+ - `arc` shape does not work on Windows due to an issue in [libui](https://github.com/andlabs/libui).
1020
+ - `table` controls on Windows intentionally get an extra empty row at the end because if any row were to be deleted for the first time, double-deletion happens due to an issue in [libui](https://github.com/andlabs/libui) on Windows.
1021
+ - `table` `progress_bar` column on Windows cannot be updated with a positive value if it started initially with `-1` (it ignores update to avoid crashing due to an issue in [libui](https://github.com/andlabs/libui) on Windows.
1016
1022
 
1017
1023
  ### Original API
1018
1024
 
@@ -3895,19 +3901,21 @@ window('Area Gallery', 400, 400) {
3895
3901
  fill r: 202, g: 102, b: 204, a: 0.5
3896
3902
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
3897
3903
  }
3898
- path { # declarative stable path
3899
- arc(400, 220, 180, 90, 90, false)
3900
-
3901
- # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
3902
- fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
3903
- stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
3904
- }
3905
- path { # declarative stable path
3906
- circle(200, 200, 90)
3907
-
3908
- fill r: 202, g: 102, b: 204, a: 0.5
3909
- stroke r: 0, g: 0, b: 0, thickness: 2
3910
- }
3904
+ unless OS.windows?
3905
+ path { # declarative stable path
3906
+ arc(400, 220, 180, 90, 90, false)
3907
+
3908
+ # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
3909
+ fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
3910
+ stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
3911
+ }
3912
+ path { # declarative stable path
3913
+ circle(200, 200, 90)
3914
+
3915
+ fill r: 202, g: 102, b: 204, a: 0.5
3916
+ stroke r: 0, g: 0, b: 0, thickness: 2
3917
+ }
3918
+ end
3911
3919
  text(160, 40, 100) { # x, y, width
3912
3920
  string('Area Gallery') {
3913
3921
  font family: 'Times', size: 14
@@ -4066,30 +4074,32 @@ window('Area Gallery', 400, 400) {
4066
4074
  fill r: 202, g: 102, b: 204, a: 0.5
4067
4075
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4068
4076
  }
4069
- path { # declarative stable path
4070
- arc {
4071
- x_center 400
4072
- y_center 220
4073
- radius 180
4074
- start_angle 90
4075
- sweep 90
4076
- is_negative false
4077
+ unless OS.windows?
4078
+ path { # declarative stable path
4079
+ arc {
4080
+ x_center 400
4081
+ y_center 220
4082
+ radius 180
4083
+ start_angle 90
4084
+ sweep 90
4085
+ is_negative false
4086
+ }
4087
+
4088
+ # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
4089
+ fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
4090
+ stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4077
4091
  }
4078
-
4079
- # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
4080
- fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
4081
- stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4082
- }
4083
- path { # declarative stable path
4084
- circle {
4085
- x_center 200
4086
- y_center 200
4087
- radius 90
4092
+ path { # declarative stable path
4093
+ circle {
4094
+ x_center 200
4095
+ y_center 200
4096
+ radius 90
4097
+ }
4098
+
4099
+ fill r: 202, g: 102, b: 204, a: 0.5
4100
+ stroke r: 0, g: 0, b: 0, thickness: 2
4088
4101
  }
4089
-
4090
- fill r: 202, g: 102, b: 204, a: 0.5
4091
- stroke r: 0, g: 0, b: 0, thickness: 2
4092
- }
4102
+ end
4093
4103
  text {
4094
4104
  x 160
4095
4105
  y 40
@@ -4201,19 +4211,21 @@ window('Area Gallery', 400, 400) {
4201
4211
  fill r: 202, g: 102, b: 204, a: 0.5
4202
4212
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4203
4213
  }
4204
- path { # a dynamic path is added semi-declaratively inside on_draw block
4205
- arc(400, 220, 180, 90, 90, false)
4206
-
4207
- # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
4208
- fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
4209
- stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4210
- }
4211
- path { # a dynamic path is added semi-declaratively inside on_draw block
4212
- circle(200, 200, 90)
4213
-
4214
- fill r: 202, g: 102, b: 204, a: 0.5
4215
- stroke r: 0, g: 0, b: 0, thickness: 2
4216
- }
4214
+ unless OS.windows?
4215
+ path { # a dynamic path is added semi-declaratively inside on_draw block
4216
+ arc(400, 220, 180, 90, 90, false)
4217
+
4218
+ # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
4219
+ fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
4220
+ stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4221
+ }
4222
+ path { # a dynamic path is added semi-declaratively inside on_draw block
4223
+ circle(200, 200, 90)
4224
+
4225
+ fill r: 202, g: 102, b: 204, a: 0.5
4226
+ stroke r: 0, g: 0, b: 0, thickness: 2
4227
+ }
4228
+ end
4217
4229
  text(160, 40, 100) { # x, y, width
4218
4230
  string('Area Gallery') {
4219
4231
  font family: 'Times', size: 14
@@ -4374,30 +4386,32 @@ window('Area Gallery', 400, 400) {
4374
4386
  fill r: 202, g: 102, b: 204, a: 0.5
4375
4387
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4376
4388
  }
4377
- path { # a dynamic path is added semi-declaratively inside on_draw block
4378
- arc {
4379
- x_center 400
4380
- y_center 220
4381
- radius 180
4382
- start_angle 90
4383
- sweep 90
4384
- is_negative false
4389
+ unless OS.windows?
4390
+ path { # a dynamic path is added semi-declaratively inside on_draw block
4391
+ arc {
4392
+ x_center 400
4393
+ y_center 220
4394
+ radius 180
4395
+ start_angle 90
4396
+ sweep 90
4397
+ is_negative false
4398
+ }
4399
+
4400
+ # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
4401
+ fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
4402
+ stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4385
4403
  }
4386
-
4387
- # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
4388
- fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
4389
- stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4390
- }
4391
- path { # a dynamic path is added semi-declaratively inside on_draw block
4392
- circle {
4393
- x_center 200
4394
- y_center 200
4395
- radius 90
4404
+ path { # a dynamic path is added semi-declaratively inside on_draw block
4405
+ circle {
4406
+ x_center 200
4407
+ y_center 200
4408
+ radius 90
4409
+ }
4410
+
4411
+ fill r: 202, g: 102, b: 204, a: 0.5
4412
+ stroke r: 0, g: 0, b: 0, thickness: 2
4396
4413
  }
4397
-
4398
- fill r: 202, g: 102, b: 204, a: 0.5
4399
- stroke r: 0, g: 0, b: 0, thickness: 2
4400
- }
4414
+ end
4401
4415
  text {
4402
4416
  x 160
4403
4417
  y 40
@@ -5100,70 +5114,74 @@ end
5100
5114
  Timer.new
5101
5115
  ```
5102
5116
 
5103
- ### Color The Circles
5117
+ ### Color The Shapes
5104
5118
 
5105
- [examples/color_the_circles.rb](examples/color_the_circles.rb)
5119
+ [examples/color_the_shapes.rb](examples/color_the_shapes.rb)
5106
5120
 
5107
5121
  Run with this command from the root of the project if you cloned the project:
5108
5122
 
5109
5123
  ```
5110
- ruby -r './lib/glimmer-dsl-libui' examples/color_the_circles.rb
5124
+ ruby -r './lib/glimmer-dsl-libui' examples/color_the_shapes.rb
5111
5125
  ```
5112
5126
 
5113
5127
  Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
5114
5128
 
5115
5129
  ```
5116
- ruby -r glimmer-dsl-libui -e "require 'examples/color_the_circles'"
5130
+ ruby -r glimmer-dsl-libui -e "require 'examples/color_the_shapes'"
5117
5131
  ```
5118
5132
 
5119
5133
  Mac
5120
5134
 
5121
- ![glimmer-dsl-libui-mac-color-the-circles.png](images/glimmer-dsl-libui-mac-color-the-circles.png)
5122
- ![glimmer-dsl-libui-mac-color-the-circles-lost.png](images/glimmer-dsl-libui-mac-color-the-circles-lost.png)
5123
- ![glimmer-dsl-libui-mac-color-the-circles-won.png](images/glimmer-dsl-libui-mac-color-the-circles-won.png)
5135
+ ![glimmer-dsl-libui-mac-color-the-shapes.png](images/glimmer-dsl-libui-mac-color-the-shapes.png)
5136
+ ![glimmer-dsl-libui-mac-color-the-shapes-lost.png](images/glimmer-dsl-libui-mac-color-the-shapes-lost.png)
5137
+ ![glimmer-dsl-libui-mac-color-the-shapes-won.png](images/glimmer-dsl-libui-mac-color-the-shapes-won.png)
5124
5138
 
5125
5139
  Linux
5126
5140
 
5127
- ![glimmer-dsl-libui-linux-color-the-circles.png](images/glimmer-dsl-libui-linux-color-the-circles.png)
5128
- ![glimmer-dsl-libui-linux-color-the-circles-lost.png](images/glimmer-dsl-libui-linux-color-the-circles-lost.png)
5129
- ![glimmer-dsl-libui-linux-color-the-circles-won.png](images/glimmer-dsl-libui-linux-color-the-circles-won.png)
5141
+ ![glimmer-dsl-libui-linux-color-the-shapes.png](images/glimmer-dsl-libui-linux-color-the-shapes.png)
5142
+ ![glimmer-dsl-libui-linux-color-the-shapes-lost.png](images/glimmer-dsl-libui-linux-color-the-shapes-lost.png)
5143
+ ![glimmer-dsl-libui-linux-color-the-shapes-won.png](images/glimmer-dsl-libui-linux-color-the-shapes-won.png)
5130
5144
 
5131
5145
  New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
5132
5146
 
5133
5147
  ```ruby
5134
5148
  require 'glimmer-dsl-libui'
5135
5149
 
5136
- class ColorTheCircles
5150
+ class ColorTheShapes
5137
5151
  include Glimmer
5138
5152
 
5139
5153
  WINDOW_WIDTH = 800
5140
5154
  WINDOW_HEIGHT = 600
5141
- CIRCLE_MIN_RADIUS = 15
5142
- CIRCLE_MAX_RADIUS = 50
5155
+ SHAPE_MIN_SIZE = 15
5156
+ SHAPE_MAX_SIZE = 100
5143
5157
  MARGIN_WIDTH = 55
5144
5158
  MARGIN_HEIGHT = 155
5145
5159
  TIME_MAX_EASY = 4
5146
5160
  TIME_MAX_MEDIUM = 3
5147
5161
  TIME_MAX_HARD = 2
5148
5162
  TIME_MAX_INSANE = 1
5163
+ SHAPES = ['square'] + (OS.windows? ? [] : ['circle'])
5149
5164
 
5150
5165
  attr_accessor :score
5151
5166
 
5152
5167
  def initialize
5153
- @circles_data = []
5168
+ @shapes_data = []
5154
5169
  @score = 0
5155
5170
  @time_max = TIME_MAX_HARD
5171
+ @game_over = false
5156
5172
  register_observers
5157
- setup_circle_factory
5173
+ setup_shape_factory
5158
5174
  end
5159
5175
 
5160
5176
  def register_observers
5161
5177
  observer = Glimmer::DataBinding::Observer.proc do |new_score|
5162
5178
  @score_label.text = new_score.to_s
5163
5179
  if new_score == -20
5180
+ @game_over = true
5164
5181
  msg_box('You Lost!', 'Sorry! Your score reached -20')
5165
5182
  restart_game
5166
5183
  elsif new_score == 0
5184
+ @game_over = true
5167
5185
  msg_box('You Won!', 'Congratulations! Your score reached 0')
5168
5186
  restart_game
5169
5187
  end
@@ -5171,13 +5189,15 @@ class ColorTheCircles
5171
5189
  observer.observe(self, :score) # automatically enhances self to become Glimmer::DataBinding::ObservableModel and notify observer on score attribute changes
5172
5190
  end
5173
5191
 
5174
- def setup_circle_factory
5192
+ def setup_shape_factory
5175
5193
  consumer = Proc.new do
5176
- if @circles_data.empty?
5177
- # start with 3 circles to make more challenging
5178
- add_circle until @circles_data.size > 3
5179
- else
5180
- add_circle
5194
+ unless @game_over
5195
+ if @shapes_data.empty?
5196
+ # start with 3 shapes to make more challenging
5197
+ add_shape until @shapes_data.size > 3
5198
+ else
5199
+ add_shape
5200
+ end
5181
5201
  end
5182
5202
  delay = rand * @time_max
5183
5203
  Glimmer::LibUI.timer(delay, repeat: false, &consumer)
@@ -5185,13 +5205,13 @@ class ColorTheCircles
5185
5205
  Glimmer::LibUI.queue_main(&consumer)
5186
5206
  end
5187
5207
 
5188
- def add_circle
5189
- circle_x_center = rand * (WINDOW_WIDTH - MARGIN_WIDTH - CIRCLE_MAX_RADIUS) + CIRCLE_MAX_RADIUS
5190
- circle_y_center = rand * (WINDOW_HEIGHT - MARGIN_HEIGHT - CIRCLE_MAX_RADIUS) + CIRCLE_MAX_RADIUS
5191
- circle_radius = rand * (CIRCLE_MAX_RADIUS - CIRCLE_MIN_RADIUS) + CIRCLE_MIN_RADIUS
5208
+ def add_shape
5209
+ shape_x = rand * (WINDOW_WIDTH - MARGIN_WIDTH - SHAPE_MAX_SIZE) + SHAPE_MAX_SIZE
5210
+ shape_y = rand * (WINDOW_HEIGHT - MARGIN_HEIGHT - SHAPE_MAX_SIZE) + SHAPE_MAX_SIZE
5211
+ shape_size = rand * (SHAPE_MAX_SIZE - SHAPE_MIN_SIZE) + SHAPE_MIN_SIZE
5192
5212
  stroke_color = Glimmer::LibUI.x11_colors.sample
5193
- @circles_data << {
5194
- args: [circle_x_center, circle_y_center, circle_radius],
5213
+ @shapes_data << {
5214
+ args: [shape_x, shape_y, shape_size],
5195
5215
  fill: nil,
5196
5216
  stroke: stroke_color
5197
5217
  }
@@ -5201,9 +5221,29 @@ class ColorTheCircles
5201
5221
 
5202
5222
  def restart_game
5203
5223
  @score = 0 # update variable directly to avoid notifying observers
5204
- @circles_data.clear
5224
+ @shapes_data.clear
5225
+ @game_over = false
5205
5226
  end
5206
5227
 
5228
+ def color_shape(x, y)
5229
+ clicked_shape_data = @shapes_data.find do |shape_data|
5230
+ shape_data[:fill].nil? && shape_data[:shape]&.include?(x, y)
5231
+ end
5232
+ if clicked_shape_data
5233
+ clicked_shape_data[:fill] = clicked_shape_data[:stroke]
5234
+ push_colored_shape_behind_uncolored_shapes(clicked_shape_data)
5235
+ @area.queue_redraw_all
5236
+ self.score += 1 # notifies score observers automatically of change
5237
+ end
5238
+ end
5239
+
5240
+ def push_colored_shape_behind_uncolored_shapes(colored_shape_data)
5241
+ removed_colored_shape_data = @shapes_data.delete(colored_shape_data)
5242
+ last_colored_shape_data = @shapes_data.select {|cd| cd[:fill]}.last
5243
+ last_colored_shape_data_index = @shapes_data.index(last_colored_shape_data) || -1
5244
+ @shapes_data.insert(last_colored_shape_data_index + 1, removed_colored_shape_data)
5245
+ end
5246
+
5207
5247
  def launch
5208
5248
  menu('Actions') {
5209
5249
  menu_item('Restart') {
@@ -5246,12 +5286,12 @@ class ColorTheCircles
5246
5286
  menu('Help') {
5247
5287
  menu_item('Instructions') {
5248
5288
  on_clicked do
5249
- msg_box('Instructions', "Score goes down as circles are added.\nIf it reaches -20, you lose!\n\nClick circles to color and score!\nOnce score reaches 0, you win!\n\nBeware of concealed light-colored circles!\nThey are revealed once darker circles intersect them.\n\nThere are four levels of difficulty.\nChange via difficulty menu if the game gets too tough.")
5289
+ msg_box('Instructions', "Score goes down as shapes are added.\nIf it reaches -20, you lose!\n\nClick shapes to color and score!\nOnce score reaches 0, you win!\n\nBeware of concealed light-colored shapes!\nThey are revealed once darker shapes intersect them.\n\nThere are four levels of difficulty.\nChange via difficulty menu if the game gets too tough.")
5250
5290
  end
5251
5291
  }
5252
5292
  }
5253
5293
 
5254
- window('Color The Circles', WINDOW_WIDTH, WINDOW_HEIGHT) {
5294
+ window('Color The Shapes', WINDOW_WIDTH, WINDOW_HEIGHT) {
5255
5295
  margined true
5256
5296
 
5257
5297
  grid {
@@ -5265,13 +5305,13 @@ class ColorTheCircles
5265
5305
  end
5266
5306
  }
5267
5307
 
5268
- label('Score goes down as circles are added. If it reaches -20, you lose!') {
5308
+ label('Score goes down as shapes are added. If it reaches -20, you lose!') {
5269
5309
  left 0
5270
5310
  top 1
5271
5311
  halign :center
5272
5312
  }
5273
5313
 
5274
- label('Click circles to color and score! Once score reaches 0, you win!') {
5314
+ label('Click shapes to color and score! Once score reaches 0, you win!') {
5275
5315
  left 0
5276
5316
  top 2
5277
5317
  halign :center
@@ -5291,51 +5331,41 @@ class ColorTheCircles
5291
5331
  }
5292
5332
  }
5293
5333
 
5294
- vertical_box {
5334
+ @area = area {
5295
5335
  left 0
5296
5336
  top 4
5297
5337
  hexpand true
5298
5338
  vexpand true
5299
5339
  halign :fill
5300
5340
  valign :fill
5301
-
5302
- @area = area {
5303
- on_draw do |area_draw_params|
5341
+
5342
+ on_draw do |area_draw_params|
5343
+ path {
5344
+ rectangle(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
5345
+
5346
+ fill :white
5347
+ }
5348
+
5349
+ @shapes_data.each do |shape_data|
5304
5350
  path {
5305
- rectangle(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
5306
-
5307
- fill :white
5351
+ shape_data[:shape] = send(SHAPES.sample, *shape_data[:args])
5352
+
5353
+ fill shape_data[:fill]
5354
+ stroke shape_data[:stroke]
5308
5355
  }
5309
-
5310
- @circles_data.each do |circle_data|
5311
- path {
5312
- circle_data[:circle] = circle(*circle_data[:args])
5313
-
5314
- fill circle_data[:fill]
5315
- stroke circle_data[:stroke]
5316
- }
5317
- end
5318
5356
  end
5319
-
5320
- on_mouse_down do |area_mouse_event|
5321
- clicked_circle_data = @circles_data.find do |circle_data|
5322
- circle_data[:fill].nil? && circle_data[:circle].include?(area_mouse_event[:x], area_mouse_event[:y])
5323
- end
5324
- if clicked_circle_data
5325
- clicked_circle_data[:fill] = clicked_circle_data[:stroke]
5326
- @area.queue_redraw_all
5327
- self.score += 1 # notifies score observers automatically of change
5328
- end
5329
- end
5330
- }
5357
+ end
5358
+
5359
+ on_mouse_down do |area_mouse_event|
5360
+ color_shape(area_mouse_event[:x], area_mouse_event[:y])
5361
+ end
5331
5362
  }
5332
-
5333
5363
  }
5334
5364
  }.show
5335
5365
  end
5336
5366
  end
5337
5367
 
5338
- ColorTheCircles.new.launch
5368
+ ColorTheShapes.new.launch
5339
5369
  ```
5340
5370
 
5341
5371
  ### Basic Draw Text
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.12
1
+ 0.2.13
data/bin/girb CHANGED
File without changes
data/bin/girb_runner.rb CHANGED
@@ -27,7 +27,7 @@ require_relative '../lib/glimmer-dsl-libui'
27
27
 
28
28
  include Glimmer
29
29
 
30
- GIRB_RUNNER_EXIT_FILE = "#{Etc.getpwuid.dir}/.girb_runner_exit"
30
+ GIRB_RUNNER_EXIT_FILE = "#{Dir.home}/.girb_runner_exit"
31
31
  FileUtils.rm_rf GIRB_RUNNER_EXIT_FILE
32
32
 
33
33
  @exit_method = method(:exit)
@@ -41,19 +41,21 @@ window('Area Gallery', 400, 400) {
41
41
  fill r: 202, g: 102, b: 204, a: 0.5
42
42
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
43
43
  }
44
- path { # declarative stable path
45
- arc(400, 220, 180, 90, 90, false)
46
-
47
- # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
48
- fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
49
- stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
50
- }
51
- path { # declarative stable path
52
- circle(200, 200, 90)
53
-
54
- fill r: 202, g: 102, b: 204, a: 0.5
55
- stroke r: 0, g: 0, b: 0, thickness: 2
56
- }
44
+ unless OS.windows?
45
+ path { # declarative stable path
46
+ arc(400, 220, 180, 90, 90, false)
47
+
48
+ # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
49
+ fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
50
+ stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
51
+ }
52
+ path { # declarative stable path
53
+ circle(200, 200, 90)
54
+
55
+ fill r: 202, g: 102, b: 204, a: 0.5
56
+ stroke r: 0, g: 0, b: 0, thickness: 2
57
+ }
58
+ end
57
59
  text(160, 40, 100) { # x, y, width
58
60
  string('Area Gallery') {
59
61
  font family: 'Times', size: 14
@@ -95,30 +95,32 @@ window('Area Gallery', 400, 400) {
95
95
  fill r: 202, g: 102, b: 204, a: 0.5
96
96
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
97
97
  }
98
- path { # declarative stable path
99
- arc {
100
- x_center 400
101
- y_center 220
102
- radius 180
103
- start_angle 90
104
- sweep 90
105
- is_negative false
98
+ unless OS.windows?
99
+ path { # declarative stable path
100
+ arc {
101
+ x_center 400
102
+ y_center 220
103
+ radius 180
104
+ start_angle 90
105
+ sweep 90
106
+ is_negative false
107
+ }
108
+
109
+ # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
110
+ fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
111
+ stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
106
112
  }
107
-
108
- # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
109
- fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
110
- stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
111
- }
112
- path { # declarative stable path
113
- circle {
114
- x_center 200
115
- y_center 200
116
- radius 90
113
+ path { # declarative stable path
114
+ circle {
115
+ x_center 200
116
+ y_center 200
117
+ radius 90
118
+ }
119
+
120
+ fill r: 202, g: 102, b: 204, a: 0.5
121
+ stroke r: 0, g: 0, b: 0, thickness: 2
117
122
  }
118
-
119
- fill r: 202, g: 102, b: 204, a: 0.5
120
- stroke r: 0, g: 0, b: 0, thickness: 2
121
- }
123
+ end
122
124
  text {
123
125
  x 160
124
126
  y 40
@@ -42,19 +42,21 @@ window('Area Gallery', 400, 400) {
42
42
  fill r: 202, g: 102, b: 204, a: 0.5
43
43
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
44
44
  }
45
- path { # a dynamic path is added semi-declaratively inside on_draw block
46
- arc(400, 220, 180, 90, 90, false)
47
-
48
- # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
49
- fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
50
- stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
51
- }
52
- path { # a dynamic path is added semi-declaratively inside on_draw block
53
- circle(200, 200, 90)
54
-
55
- fill r: 202, g: 102, b: 204, a: 0.5
56
- stroke r: 0, g: 0, b: 0, thickness: 2
57
- }
45
+ unless OS.windows?
46
+ path { # a dynamic path is added semi-declaratively inside on_draw block
47
+ arc(400, 220, 180, 90, 90, false)
48
+
49
+ # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
50
+ fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
51
+ stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
52
+ }
53
+ path { # a dynamic path is added semi-declaratively inside on_draw block
54
+ circle(200, 200, 90)
55
+
56
+ fill r: 202, g: 102, b: 204, a: 0.5
57
+ stroke r: 0, g: 0, b: 0, thickness: 2
58
+ }
59
+ end
58
60
  text(160, 40, 100) { # x, y, width
59
61
  string('Area Gallery') {
60
62
  font family: 'Times', size: 14
@@ -96,30 +96,32 @@ window('Area Gallery', 400, 400) {
96
96
  fill r: 202, g: 102, b: 204, a: 0.5
97
97
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
98
98
  }
99
- path { # a dynamic path is added semi-declaratively inside on_draw block
100
- arc {
101
- x_center 400
102
- y_center 220
103
- radius 180
104
- start_angle 90
105
- sweep 90
106
- is_negative false
99
+ unless OS.windows?
100
+ path { # a dynamic path is added semi-declaratively inside on_draw block
101
+ arc {
102
+ x_center 400
103
+ y_center 220
104
+ radius 180
105
+ start_angle 90
106
+ sweep 90
107
+ is_negative false
108
+ }
109
+
110
+ # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
111
+ fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
112
+ stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
107
113
  }
108
-
109
- # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
110
- fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
111
- stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
112
- }
113
- path { # a dynamic path is added semi-declaratively inside on_draw block
114
- circle {
115
- x_center 200
116
- y_center 200
117
- radius 90
114
+ path { # a dynamic path is added semi-declaratively inside on_draw block
115
+ circle {
116
+ x_center 200
117
+ y_center 200
118
+ radius 90
119
+ }
120
+
121
+ fill r: 202, g: 102, b: 204, a: 0.5
122
+ stroke r: 0, g: 0, b: 0, thickness: 2
118
123
  }
119
-
120
- fill r: 202, g: 102, b: 204, a: 0.5
121
- stroke r: 0, g: 0, b: 0, thickness: 2
122
- }
124
+ end
123
125
  text {
124
126
  x 160
125
127
  y 40
@@ -12,7 +12,7 @@ data = [
12
12
  %w[cow moo delete]
13
13
  ]
14
14
 
15
- window('Animal sounds', 300, 200) {
15
+ window('Animal sounds', 400, 200) {
16
16
  horizontal_box {
17
17
  table {
18
18
  text_column('Animal')
@@ -12,7 +12,7 @@ data = [
12
12
  ['cow', 'moo', true]
13
13
  ]
14
14
 
15
- window('Animal sounds', 300, 200) {
15
+ window('Animal sounds', 400, 200) {
16
16
  horizontal_box {
17
17
  table {
18
18
  text_column('Animal')
@@ -14,6 +14,7 @@ IMAGE_ROWS = []
14
14
  50.times do |i|
15
15
  url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
16
16
  puts "Processing Image: #{url}"
17
+ $stdout.flush # for Windows
17
18
  f = URI.open(url)
18
19
  canvas = ChunkyPNG::Canvas.from_io(f)
19
20
  f.close
@@ -14,6 +14,7 @@ IMAGE_ROWS = []
14
14
  5.times do |i|
15
15
  url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
16
16
  puts "Processing Image: #{url}"
17
+ $stdout.flush # for Windows
17
18
  f = URI.open(url)
18
19
  canvas = ChunkyPNG::Canvas.from_io(f)
19
20
  f.close
@@ -1,28 +1,29 @@
1
1
  require 'glimmer-dsl-libui'
2
2
 
3
- class ColorTheCircles
3
+ class ColorTheShapes
4
4
  include Glimmer
5
5
 
6
6
  WINDOW_WIDTH = 800
7
7
  WINDOW_HEIGHT = 600
8
- CIRCLE_MIN_RADIUS = 15
9
- CIRCLE_MAX_RADIUS = 50
8
+ SHAPE_MIN_SIZE = 15
9
+ SHAPE_MAX_SIZE = 100
10
10
  MARGIN_WIDTH = 55
11
11
  MARGIN_HEIGHT = 155
12
12
  TIME_MAX_EASY = 4
13
13
  TIME_MAX_MEDIUM = 3
14
14
  TIME_MAX_HARD = 2
15
15
  TIME_MAX_INSANE = 1
16
+ SHAPES = ['square'] + (OS.windows? ? [] : ['circle'])
16
17
 
17
18
  attr_accessor :score
18
19
 
19
20
  def initialize
20
- @circles_data = []
21
+ @shapes_data = []
21
22
  @score = 0
22
23
  @time_max = TIME_MAX_HARD
23
24
  @game_over = false
24
25
  register_observers
25
- setup_circle_factory
26
+ setup_shape_factory
26
27
  end
27
28
 
28
29
  def register_observers
@@ -41,14 +42,14 @@ class ColorTheCircles
41
42
  observer.observe(self, :score) # automatically enhances self to become Glimmer::DataBinding::ObservableModel and notify observer on score attribute changes
42
43
  end
43
44
 
44
- def setup_circle_factory
45
+ def setup_shape_factory
45
46
  consumer = Proc.new do
46
47
  unless @game_over
47
- if @circles_data.empty?
48
- # start with 3 circles to make more challenging
49
- add_circle until @circles_data.size > 3
48
+ if @shapes_data.empty?
49
+ # start with 3 shapes to make more challenging
50
+ add_shape until @shapes_data.size > 3
50
51
  else
51
- add_circle
52
+ add_shape
52
53
  end
53
54
  end
54
55
  delay = rand * @time_max
@@ -57,13 +58,13 @@ class ColorTheCircles
57
58
  Glimmer::LibUI.queue_main(&consumer)
58
59
  end
59
60
 
60
- def add_circle
61
- circle_x_center = rand * (WINDOW_WIDTH - MARGIN_WIDTH - CIRCLE_MAX_RADIUS) + CIRCLE_MAX_RADIUS
62
- circle_y_center = rand * (WINDOW_HEIGHT - MARGIN_HEIGHT - CIRCLE_MAX_RADIUS) + CIRCLE_MAX_RADIUS
63
- circle_radius = rand * (CIRCLE_MAX_RADIUS - CIRCLE_MIN_RADIUS) + CIRCLE_MIN_RADIUS
61
+ def add_shape
62
+ shape_x = rand * (WINDOW_WIDTH - MARGIN_WIDTH - SHAPE_MAX_SIZE) + SHAPE_MAX_SIZE
63
+ shape_y = rand * (WINDOW_HEIGHT - MARGIN_HEIGHT - SHAPE_MAX_SIZE) + SHAPE_MAX_SIZE
64
+ shape_size = rand * (SHAPE_MAX_SIZE - SHAPE_MIN_SIZE) + SHAPE_MIN_SIZE
64
65
  stroke_color = Glimmer::LibUI.x11_colors.sample
65
- @circles_data << {
66
- args: [circle_x_center, circle_y_center, circle_radius],
66
+ @shapes_data << {
67
+ args: [shape_x, shape_y, shape_size],
67
68
  fill: nil,
68
69
  stroke: stroke_color
69
70
  }
@@ -73,29 +74,29 @@ class ColorTheCircles
73
74
 
74
75
  def restart_game
75
76
  @score = 0 # update variable directly to avoid notifying observers
76
- @circles_data.clear
77
+ @shapes_data.clear
77
78
  @game_over = false
78
79
  end
79
80
 
80
- def color_circle(x, y)
81
- clicked_circle_data = @circles_data.find do |circle_data|
82
- circle_data[:fill].nil? && circle_data[:circle].include?(x, y)
81
+ def color_shape(x, y)
82
+ clicked_shape_data = @shapes_data.find do |shape_data|
83
+ shape_data[:fill].nil? && shape_data[:shape]&.include?(x, y)
83
84
  end
84
- if clicked_circle_data
85
- clicked_circle_data[:fill] = clicked_circle_data[:stroke]
86
- push_colored_circle_behind_uncolored_circles(clicked_circle_data)
85
+ if clicked_shape_data
86
+ clicked_shape_data[:fill] = clicked_shape_data[:stroke]
87
+ push_colored_shape_behind_uncolored_shapes(clicked_shape_data)
87
88
  @area.queue_redraw_all
88
89
  self.score += 1 # notifies score observers automatically of change
89
90
  end
90
91
  end
91
92
 
92
- def push_colored_circle_behind_uncolored_circles(colored_circle_data)
93
- removed_colored_circle_data = @circles_data.delete(colored_circle_data)
94
- last_colored_circle_data = @circles_data.select {|cd| cd[:fill]}.last
95
- last_colored_circle_data_index = @circles_data.index(last_colored_circle_data) || -1
96
- @circles_data.insert(last_colored_circle_data_index + 1, removed_colored_circle_data)
93
+ def push_colored_shape_behind_uncolored_shapes(colored_shape_data)
94
+ removed_colored_shape_data = @shapes_data.delete(colored_shape_data)
95
+ last_colored_shape_data = @shapes_data.select {|cd| cd[:fill]}.last
96
+ last_colored_shape_data_index = @shapes_data.index(last_colored_shape_data) || -1
97
+ @shapes_data.insert(last_colored_shape_data_index + 1, removed_colored_shape_data)
97
98
  end
98
-
99
+
99
100
  def launch
100
101
  menu('Actions') {
101
102
  menu_item('Restart') {
@@ -138,12 +139,12 @@ class ColorTheCircles
138
139
  menu('Help') {
139
140
  menu_item('Instructions') {
140
141
  on_clicked do
141
- msg_box('Instructions', "Score goes down as circles are added.\nIf it reaches -20, you lose!\n\nClick circles to color and score!\nOnce score reaches 0, you win!\n\nBeware of concealed light-colored circles!\nThey are revealed once darker circles intersect them.\n\nThere are four levels of difficulty.\nChange via difficulty menu if the game gets too tough.")
142
+ msg_box('Instructions', "Score goes down as shapes are added.\nIf it reaches -20, you lose!\n\nClick shapes to color and score!\nOnce score reaches 0, you win!\n\nBeware of concealed light-colored shapes!\nThey are revealed once darker shapes intersect them.\n\nThere are four levels of difficulty.\nChange via difficulty menu if the game gets too tough.")
142
143
  end
143
144
  }
144
145
  }
145
146
 
146
- window('Color The Circles', WINDOW_WIDTH, WINDOW_HEIGHT) {
147
+ window('Color The Shapes', WINDOW_WIDTH, WINDOW_HEIGHT) {
147
148
  margined true
148
149
 
149
150
  grid {
@@ -157,13 +158,13 @@ class ColorTheCircles
157
158
  end
158
159
  }
159
160
 
160
- label('Score goes down as circles are added. If it reaches -20, you lose!') {
161
+ label('Score goes down as shapes are added. If it reaches -20, you lose!') {
161
162
  left 0
162
163
  top 1
163
164
  halign :center
164
165
  }
165
166
 
166
- label('Click circles to color and score! Once score reaches 0, you win!') {
167
+ label('Click shapes to color and score! Once score reaches 0, you win!') {
167
168
  left 0
168
169
  top 2
169
170
  halign :center
@@ -190,26 +191,26 @@ class ColorTheCircles
190
191
  vexpand true
191
192
  halign :fill
192
193
  valign :fill
193
-
194
+
194
195
  on_draw do |area_draw_params|
195
196
  path {
196
197
  rectangle(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
197
-
198
+
198
199
  fill :white
199
200
  }
200
-
201
- @circles_data.each do |circle_data|
201
+
202
+ @shapes_data.each do |shape_data|
202
203
  path {
203
- circle_data[:circle] = circle(*circle_data[:args])
204
-
205
- fill circle_data[:fill]
206
- stroke circle_data[:stroke]
204
+ shape_data[:shape] = send(SHAPES.sample, *shape_data[:args])
205
+
206
+ fill shape_data[:fill]
207
+ stroke shape_data[:stroke]
207
208
  }
208
209
  end
209
210
  end
210
-
211
+
211
212
  on_mouse_down do |area_mouse_event|
212
- color_circle(area_mouse_event[:x], area_mouse_event[:y])
213
+ color_shape(area_mouse_event[:x], area_mouse_event[:y])
213
214
  end
214
215
  }
215
216
  }
@@ -217,4 +218,4 @@ class ColorTheCircles
217
218
  end
218
219
  end
219
220
 
220
- ColorTheCircles.new.launch
221
+ ColorTheShapes.new.launch
@@ -9,6 +9,7 @@ menu('File') {
9
9
  on_clicked do
10
10
  file = open_file
11
11
  puts file unless file.nil?
12
+ $stdout.flush # for Windows
12
13
  end
13
14
  }
14
15
 
@@ -16,6 +17,7 @@ menu('File') {
16
17
  on_clicked do
17
18
  file = save_file
18
19
  puts file unless file.nil?
20
+ $stdout.flush # for Windows
19
21
  end
20
22
  }
21
23
 
@@ -98,6 +100,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500) {
98
100
 
99
101
  on_changed do |s|
100
102
  puts "New Spinbox value: #{s.value}"
103
+ $stdout.flush # for Windows
101
104
  end
102
105
  }
103
106
 
@@ -107,6 +110,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500) {
107
110
  on_changed do |s|
108
111
  v = s.value
109
112
  puts "New Slider value: #{v}"
113
+ $stdout.flush # for Windows
110
114
  @progress_bar.value = v
111
115
  end
112
116
  }
@@ -125,6 +129,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500) {
125
129
 
126
130
  on_selected do |c|
127
131
  puts "New combobox selection: #{c.selected}"
132
+ $stdout.flush # for Windows
128
133
  end
129
134
  }
130
135
 
@@ -147,6 +152,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500) {
147
152
 
148
153
  on_changed do |e|
149
154
  puts "Current textbox data: '#{e.text}'"
155
+ $stdout.flush # for Windows
150
156
  end
151
157
  }
152
158
  }
@@ -48,6 +48,7 @@ class MetaExample
48
48
  f.each_line do |line|
49
49
  result << line
50
50
  puts line
51
+ $stdout.flush # for Windows
51
52
  end
52
53
  end
53
54
  msg_box('Error Running Example', result) if result.downcase.include?('error')
Binary file
@@ -151,16 +151,26 @@ module Glimmer
151
151
  end
152
152
  end
153
153
  unless font.nil?
154
- family_attribute = ::LibUI.new_family_attribute(font[:family])
155
- ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, family_attribute, @start, @start + @string.size)
156
- size_attribute = ::LibUI.new_size_attribute(font[:size])
157
- ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, size_attribute, @start, @start + @string.size)
158
- weight_attribute = ::LibUI.new_weight_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_weight, font[:weight]))
159
- ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, weight_attribute, @start, @start + @string.size)
160
- italic_attribute = ::LibUI.new_italic_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_italic, font[:italic]))
161
- ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, italic_attribute, @start, @start + @string.size)
162
- stretch_attribute = ::LibUI.new_stretch_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_stretch, font[:stretch]))
163
- ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, stretch_attribute, @start, @start + @string.size)
154
+ if font[:family]
155
+ family_attribute = ::LibUI.new_family_attribute(font[:family])
156
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, family_attribute, @start, @start + @string.size)
157
+ end
158
+ if font[:size]
159
+ size_attribute = ::LibUI.new_size_attribute(font[:size])
160
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, size_attribute, @start, @start + @string.size)
161
+ end
162
+ if font[:weight]
163
+ weight_attribute = ::LibUI.new_weight_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_weight, font[:weight]))
164
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, weight_attribute, @start, @start + @string.size)
165
+ end
166
+ if font[:italic]
167
+ italic_attribute = ::LibUI.new_italic_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_italic, font[:italic]))
168
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, italic_attribute, @start, @start + @string.size)
169
+ end
170
+ if font[:stretch]
171
+ stretch_attribute = ::LibUI.new_stretch_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_stretch, font[:stretch]))
172
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, stretch_attribute, @start, @start + @string.size)
173
+ end
164
174
  end
165
175
  unless open_type_features.nil?
166
176
  open_type_features_attribute = ::LibUI.new_features_attribute(open_type_features.libui)
@@ -84,7 +84,7 @@ module Glimmer
84
84
  @cell_rows = rows
85
85
  @cell_rows.tap do
86
86
  @last_cell_rows = array_deep_clone(@cell_rows)
87
- Glimmer::DataBinding::Observer.proc do
87
+ Glimmer::DataBinding::Observer.proc do |new_cell_rows|
88
88
  if @cell_rows.size < @last_cell_rows.size && @last_cell_rows.include_all?(*@cell_rows)
89
89
  @last_cell_rows.array_diff_indexes(@cell_rows).reverse.each do |row|
90
90
  ::LibUI.table_model_row_deleted(model, row)
@@ -103,6 +103,7 @@ module Glimmer
103
103
  end
104
104
  end
105
105
  end
106
+ @last_last_cell_rows = array_deep_clone(@last_cell_rows)
106
107
  @last_cell_rows = array_deep_clone(@cell_rows)
107
108
  end.observe(self, :cell_rows, recursive: true)
108
109
  end
@@ -112,7 +113,11 @@ module Glimmer
112
113
  alias set_cell_rows cell_rows
113
114
 
114
115
  def expanded_cell_rows
115
- cell_rows.map do |row|
116
+ expand(cell_rows)
117
+ end
118
+
119
+ def expand(cell_rows)
120
+ cell_rows.to_a.map do |row|
116
121
  row.flatten(1)
117
122
  end
118
123
  end
@@ -146,23 +151,39 @@ module Glimmer
146
151
  3
147
152
  end
148
153
  end
149
- @model_handler.NumRows = fiddle_closure_block_caller(4) { cell_rows.count }
154
+ @model_handler.NumRows = fiddle_closure_block_caller(4) do
155
+ # Note: there is a double-delete bug in Windows when performing table_model_row_deleted, which requires pre-adding and extra empty row
156
+ cell_rows.count + (OS.windows? ? 1 : 0)
157
+ end
150
158
  @model_handler.CellValue = fiddle_closure_block_caller(1, [1, 1, 4, 4]) do |_, _, row, column|
151
159
  the_cell_rows = expanded_cell_rows
152
160
  case @columns[column]
153
161
  when Column::TextColumnProxy, Column::ButtonColumnProxy, Column::TextColorColumnProxy, :text
154
162
  ::LibUI.new_table_value_string((expanded_cell_rows[row] && expanded_cell_rows[row][column]).to_s)
155
163
  when Column::ImageColumnProxy, Column::ImageTextColumnProxy, Column::ImageTextColorColumnProxy
156
- ::LibUI.new_table_value_image((expanded_cell_rows[row] && (expanded_cell_rows[row][column].respond_to?(:libui) ? expanded_cell_rows[row][column].libui : expanded_cell_rows[row][column])))
164
+ if OS.windows? && row == cell_rows.count
165
+ ::LibUI.new_table_value_image((expanded_cell_rows[row - 1] && (expanded_cell_rows[row - 1][column].respond_to?(:libui) ? expanded_cell_rows[row - 1][column].libui : expanded_cell_rows[row - 1][column])))
166
+ else
167
+ ::LibUI.new_table_value_image((expanded_cell_rows[row] && (expanded_cell_rows[row][column].respond_to?(:libui) ? expanded_cell_rows[row][column].libui : expanded_cell_rows[row][column])))
168
+ end
157
169
  when Column::CheckboxColumnProxy, Column::CheckboxTextColumnProxy, Column::CheckboxTextColorColumnProxy
158
- ::LibUI.new_table_value_int((expanded_cell_rows[row] && (expanded_cell_rows[row][column] == 1 || expanded_cell_rows[row][column].to_s.strip.downcase == 'true' ? 1 : 0)))
170
+ ::LibUI.new_table_value_int(((expanded_cell_rows[row] && (expanded_cell_rows[row][column] == 1 || expanded_cell_rows[row][column].to_s.strip.downcase == 'true' ? 1 : 0))) || 0)
159
171
  when Column::ProgressBarColumnProxy
160
- ::LibUI.new_table_value_int((expanded_cell_rows[row] && (expanded_cell_rows[row][column].to_i)))
172
+ value = (expanded_cell_rows[row] && expanded_cell_rows[row][column]).to_i
173
+ expanded_last_last_cell_rows = expand(@last_last_cell_rows)
174
+ old_value = (expanded_last_last_cell_rows[row] && expanded_last_last_cell_rows[row][column]).to_i
175
+ if OS.windows? && old_value == -1 && value >= 0
176
+ Glimmer::Config.logger.error('Switching a progress bar value from -1 to a positive value is not supported on Windows')
177
+ cell_rows[row][column] = -1
178
+ ::LibUI.new_table_value_int(old_value)
179
+ else
180
+ ::LibUI.new_table_value_int((expanded_cell_rows[row] && expanded_cell_rows[row][column]).to_i)
181
+ end
161
182
  when Column::BackgroundColorColumnProxy
162
- background_color = Glimmer::LibUI.interpret_color(expanded_cell_rows[row] && expanded_cell_rows[row][column])
183
+ background_color = Glimmer::LibUI.interpret_color(expanded_cell_rows[row] && expanded_cell_rows[row][column]) || {r: 255, g: 255, b: 255}
163
184
  ::LibUI.new_table_value_color(background_color[:r] / 255.0, background_color[:g] / 255.0, background_color[:b] / 255.0, background_color[:a] || 1.0)
164
185
  when :color
165
- color = Glimmer::LibUI.interpret_color(expanded_cell_rows[row] && expanded_cell_rows[row][column])
186
+ color = Glimmer::LibUI.interpret_color(expanded_cell_rows[row] && expanded_cell_rows[row][column]) || {r: 0, g: 0, b: 0}
166
187
  ::LibUI.new_table_value_color(color[:r] / 255.0, color[:g] / 255.0, color[:b] / 255.0, color[:a] || 1.0)
167
188
  end
168
189
  end
@@ -182,7 +203,6 @@ module Glimmer
182
203
  @cell_rows[row] ||= []
183
204
  @cell_rows[row][column] = ::LibUI.table_value_int(val).to_i == 1
184
205
  end
185
- on_changed.each {|listener| listener.call(row, :changed, @cell_rows[row])}
186
206
  on_edited.each {|listener| listener.call(row, @cell_rows[row])}
187
207
  end
188
208
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-16 00:00:00.000000000 Z
11
+ date: 2021-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -193,9 +193,9 @@ dependencies:
193
193
  description: Glimmer DSL for LibUI - Prerequisite-Free Ruby Desktop Development GUI
194
194
  Library (No need to pre-install any prerequisites. Just install the gem and have
195
195
  platform-independent native GUI that just works! Glimmer DSL for LibUI aims to provide
196
- declarative DSL syntax that visually maps to the GUI control hierarchy, convention
197
- over configuration via smart defaults and automation of low-level details, requiring
198
- the least amount of syntax possible to build GUI, and custom control support.)
196
+ declarative DSL syntax that visually maps to GUI control hierarchy, convention over
197
+ configuration via smart defaults, automation of low-level details, requiring the
198
+ least amount of syntax possible to build GUI, and custom control support.
199
199
  email: andy.am@gmail.com
200
200
  executables:
201
201
  - girb
@@ -233,7 +233,7 @@ files:
233
233
  - examples/basic_window.rb
234
234
  - examples/basic_window2.rb
235
235
  - examples/color_button.rb
236
- - examples/color_the_circles.rb
236
+ - examples/color_the_shapes.rb
237
237
  - examples/control_gallery.rb
238
238
  - examples/custom_draw_text.rb
239
239
  - examples/custom_draw_text2.rb