glimmer-dsl-libui 0.2.17 → 0.2.18

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: d6e095fec39866bb2bfe5b9d1295a642dfaea6d8014c0fe99e56d038435a4589
4
- data.tar.gz: c884e58ae378f0a453f0f40ec5e5f61f96b786894eeabf74d954c3fd58329d41
3
+ metadata.gz: c52fe6bf6dd2ed5494e9bc372628d340379cfdbfd8e2d19617c4813324e47a91
4
+ data.tar.gz: d713e9293141c0c7d74d0be00319126fccad50c7aea6d787fe1cb1774b8547a6
5
5
  SHA512:
6
- metadata.gz: b4148815da2f069acc297de2b882277cb0026ff2cb9f8175a78e0d8b54cabaec6afc03db5a3be1b8abca89ba3b29727c5b9b0aa3f3b659ae4e36838074eaed9c
7
- data.tar.gz: 255e3885c541a8bb73a5887ef21e1ec2dcbd8a288c07973cf7c3ae6e17dd31121fa784fc2e8af0a8b5c0ed974831e59ca752f3617a1821c6ec73e0faf6489b8e
6
+ metadata.gz: d10eb3c9fff91f1a6881189b6ae17735986aff25f256eefc9c88ab1f4b8c11a20837ebf10f9735d02dc86418ba9471032bb2992e9f74e72fd9a446ff9116359d
7
+ data.tar.gz: 7706f38cf41de97fd1a740ecaf150f0852d1974872e3dd95e0006df03927d081add8d06b342fb0c7b966c79c0134c1d591cfdff499bf5d951470fb7701a131b5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.18
4
+
5
+ - Support `polygon` (closed figure of lines), `polyline` (open figure of lines), and `polybezier` (open figure of beziers) shape keywords to use under `path`
6
+ - Improve examples/tetris.rb with bevel block 3D look and restarting upon game over
7
+ - Update examples/area_gallery.rb to add uses of `polygon`, `polyline`, and `polybezier`
8
+ - Refactor examples/histogram.rb to utilize new `polygon` and `polyline` keywords
9
+ - Support `area` `request_auto_redraw`, `pause_auto_redraw`, and `resume_auto_redraw`, operations, and `auto_redraw_enabled` property.
10
+
3
11
  ## 0.2.17
4
12
 
5
13
  - Tetris example - basic version with simple color squares
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.17
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for LibUI 0.2.18
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)
@@ -112,31 +112,24 @@ window('Area Gallery', 400, 400) {
112
112
  fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
113
113
  }
114
114
  path { # declarative stable path
115
- figure(100, 100) {
116
- line(100, 400)
117
- line(400, 100)
118
- line(400, 400)
119
-
120
- closed true
121
- }
122
-
115
+ polygon(100, 100, 100, 400, 400, 100, 400, 400)
116
+
123
117
  fill r: 202, g: 102, b: 104, a: 0.5
124
118
  stroke r: 0, g: 0, b: 0
125
119
  }
126
120
  path { # declarative stable path
127
- figure(0, 0) {
128
- bezier(200, 100, 100, 200, 400, 100)
129
- bezier(300, 100, 100, 300, 100, 400)
130
- bezier(100, 300, 300, 100, 400, 400)
131
-
132
- closed true
133
- }
121
+ polybezier(0, 0, 200, 100, 100, 200, 400, 100, 300, 100, 100, 300, 100, 400, 100, 300, 300, 100, 400, 400)
134
122
 
135
123
  fill r: 202, g: 102, b: 204, a: 0.5
136
124
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
137
125
  }
138
126
  path { # declarative stable path
139
- arc(400, 220, 180, 90, 90, false)
127
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
128
+
129
+ stroke r: 0, g: 0, b: 0, thickness: 2
130
+ }
131
+ path { # declarative stable path
132
+ arc(404, 216, 190, 90, 90, false)
140
133
 
141
134
  # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
142
135
  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}]
@@ -148,9 +141,9 @@ window('Area Gallery', 400, 400) {
148
141
  fill r: 202, g: 102, b: 204, a: 0.5
149
142
  stroke r: 0, g: 0, b: 0, thickness: 2
150
143
  }
151
- text(160, 40, 100) { # x, y, width
144
+ text(161, 40, 100) { # x, y, width
152
145
  string('Area Gallery') {
153
- font family: 'Times', size: 14
146
+ font family: 'Arial', size: 14
154
147
  color :black
155
148
  }
156
149
  }
@@ -377,7 +370,7 @@ gem install glimmer-dsl-libui
377
370
  Or install via Bundler `Gemfile`:
378
371
 
379
372
  ```ruby
380
- gem 'glimmer-dsl-libui', '~> 0.2.17'
373
+ gem 'glimmer-dsl-libui', '~> 0.2.18'
381
374
  ```
382
375
 
383
376
  Add `require 'glimmer-dsl-libui'` at the top, and then `include Glimmer` into the top-level main object for testing or into an actual class for serious usage.
@@ -494,6 +487,9 @@ Keyword(Args) | Properties | Listeners
494
487
  `non_wrapping_multiline_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
495
488
  `password_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
496
489
  `path(draw_fill_mode = :winding)` | `fill` (`Hash` of `:r` as `0`-`255`, `:g` as `0`-`255`, `:b` as `0`-`255`, `:a` as `0.0`-`1.0`, hex, or [X11](https://en.wikipedia.org/wiki/X11_color_names) color), `stroke` (`Hash` of `:r` as `0`-`255`, `:g` as `0`-`255`, `:b` as `0`-`255`, `:a` as `0.0`-`1.0`, hex, or [X11](https://en.wikipedia.org/wiki/X11_color_names) color), `:cap` as (`:round`, `:square`, `:flat`), `:join` as (`:miter`, `:round`, `:bevel`), `:thickness` as `Numeric`, `:miter_limit` as `Numeric`, `:dashes` as `Array` of `Numeric` ) | None
490
+ `polygon(point_array as Array of Arrays of Numeric or Array of Numeric)` | `point_array` (`Array of Arrays of Numeric or Array of Numeric`) | None
491
+ `polyline(point_array as Array of Arrays of Numeric or Array of Numeric)` | `point_array` (`Array of Arrays of Numeric or Array of Numeric`) | None
492
+ `polybezier(point_array as Array of Arrays of Numeric or Array of Numeric)` | `point_array` (`Array of Arrays of Numeric or Array of Numeric`) | None
497
493
  `preferences_menu_item` | None | `on_clicked`
498
494
  `progress_bar` | `value` (`Numeric`) | None
499
495
  `progress_bar_column(name as String)` | None | None
@@ -745,6 +741,9 @@ Available nested `path` shapes:
745
741
  - `arc(x_center as Numeric, y_center as Numeric, radius as Numeric, start_angle as Numeric, sweep as Numeric, is_negative as Boolean)`
746
742
  - `line(x as Numeric, y as Numeric)`
747
743
  - `bezier(c1_x as Numeric, c1_y as Numeric, c2_x as Numeric, c2_y as Numeric, end_x as Numeric, end_y as Numeric)`
744
+ - `polygon(point_array as Array of Arrays of Numeric or Array of Numeric)`: closed figure of lines; can receive points as [[x1, y1], [x2, y2], ...] or [x1, y1, x2, y2, ...]
745
+ - `polyline(point_array as Array of Arrays of Numeric or Array of Numeric)`: open figure of lines; can receive points as [[x1, y1], [x2, y2], ...] or [x1, y1, x2, y2, ...]
746
+ - `polybezier(point_array as Array of Arrays of Numeric or Array of Numeric)`: open figure of beziers; can receive points as [[start_x1, start_y1], [c1_x2, c1_y2, c2_x2, c2_y2, end_x2, end_y2], [c1_x3, c1_y3, c2_x3, c2_y3, end_x3, end_y3], ...] or [start_x1, start_y1, c1_x2, c1_y2, c2_x2, c2_y2, end_x2, end_y2, c1_x3, c1_y3, c2_x3, c2_y3, end_x3, end_y3, ...]
748
747
  - `figure(x=nil as Numeric, y=nil as Numeric)` (composite that can contain other shapes) (can set `closed true` to connect last point to first point automatically)
749
748
 
750
749
  Check [examples/area_gallery.rb](#area-gallery) for an overiew of all `path` shapes.
@@ -799,6 +798,12 @@ Note that when nesting an `area` directly underneath `window` (without a layout
799
798
 
800
799
  To redraw an `area`, you may call the `#queue_redraw_all` method, or simply `#redraw`.
801
800
 
801
+ `area` has the following Glimmer-added API methods/attributes:
802
+ - `request_auto_redraw`: requests auto redraw upon changes to nested stable `path` or shapes
803
+ - `pause_auto_redraw`: pause auto redraw upon changes to nested stable `path` or shapes (useful to avoid too many micro-change redraws, to group all redraws as one after many micro-changes)
804
+ - `resume_auto_redraw`: resume auto redraw upon changes to nested stable `path` or shapes
805
+ - `auto_redraw_enabled`/`auto_redraw_enabled?`/`auto_redraw_enabled=`: an attribute to disable/enable auto redraw on an `area` upon changes to nested stable `path` or shapes
806
+
802
807
  A transform `matrix` can be set on a path by building a `matrix(m11 = nil, m12 = nil, m21 = nil, m22 = nil, m31 = nil, m32 = nil) {operations}` proxy object and then setting via `transform` property, or alternatively by building and setting the matrix in one call to `transform(m11 = nil, m12 = nil, m21 = nil, m22 = nil, m31 = nil, m32 = nil) {operations}` passing it the matrix arguments and/or content operations.
803
808
 
804
809
  When instantiating a `matrix` object, it always starts with identity matrix.
@@ -4059,31 +4064,24 @@ window('Area Gallery', 400, 400) {
4059
4064
  fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
4060
4065
  }
4061
4066
  path { # declarative stable path
4062
- figure(100, 100) {
4063
- line(100, 400)
4064
- line(400, 100)
4065
- line(400, 400)
4066
-
4067
- closed true
4068
- }
4069
-
4067
+ polygon(100, 100, 100, 400, 400, 100, 400, 400)
4068
+
4070
4069
  fill r: 202, g: 102, b: 104, a: 0.5
4071
4070
  stroke r: 0, g: 0, b: 0
4072
4071
  }
4073
4072
  path { # declarative stable path
4074
- figure(0, 0) {
4075
- bezier(200, 100, 100, 200, 400, 100)
4076
- bezier(300, 100, 100, 300, 100, 400)
4077
- bezier(100, 300, 300, 100, 400, 400)
4078
-
4079
- closed true
4080
- }
4073
+ polybezier(0, 0, 200, 100, 100, 200, 400, 100, 300, 100, 100, 300, 100, 400, 100, 300, 300, 100, 400, 400)
4081
4074
 
4082
4075
  fill r: 202, g: 102, b: 204, a: 0.5
4083
4076
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4084
4077
  }
4085
4078
  path { # declarative stable path
4086
- arc(400, 220, 180, 90, 90, false)
4079
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
4080
+
4081
+ stroke r: 0, g: 0, b: 0, thickness: 2
4082
+ }
4083
+ path { # declarative stable path
4084
+ arc(404, 216, 190, 90, 90, false)
4087
4085
 
4088
4086
  # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
4089
4087
  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}]
@@ -4095,9 +4093,9 @@ window('Area Gallery', 400, 400) {
4095
4093
  fill r: 202, g: 102, b: 204, a: 0.5
4096
4094
  stroke r: 0, g: 0, b: 0, thickness: 2
4097
4095
  }
4098
- text(160, 40, 100) { # x, y, width
4096
+ text(161, 40, 100) { # x, y, width
4099
4097
  string('Area Gallery') {
4100
- font family: 'Times', size: 14
4098
+ font family: 'Arial', size: 14
4101
4099
  color :black
4102
4100
  }
4103
4101
  }
@@ -4246,18 +4244,42 @@ window('Area Gallery', 400, 400) {
4246
4244
  end_x 400
4247
4245
  end_y 400
4248
4246
  }
4249
-
4250
- closed true
4251
4247
  }
4252
4248
 
4253
4249
  fill r: 202, g: 102, b: 204, a: 0.5
4254
4250
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4255
4251
  }
4252
+ path { # declarative stable path
4253
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
4254
+ figure {
4255
+ x 100
4256
+ y 100
4257
+
4258
+ line {
4259
+ x 400
4260
+ y 100
4261
+ }
4262
+ line {
4263
+ x 100
4264
+ y 400
4265
+ }
4266
+ line {
4267
+ x 400
4268
+ y 400
4269
+ }
4270
+ line {
4271
+ x 0
4272
+ y 0
4273
+ }
4274
+ }
4275
+
4276
+ stroke r: 0, g: 0, b: 0, thickness: 2
4277
+ }
4256
4278
  path { # declarative stable path
4257
4279
  arc {
4258
- x_center 400
4259
- y_center 220
4260
- radius 180
4280
+ x_center 404
4281
+ y_center 216
4282
+ radius 190
4261
4283
  start_angle 90
4262
4284
  sweep 90
4263
4285
  is_negative false
@@ -4278,12 +4300,12 @@ window('Area Gallery', 400, 400) {
4278
4300
  stroke r: 0, g: 0, b: 0, thickness: 2
4279
4301
  }
4280
4302
  text {
4281
- x 160
4303
+ x 161
4282
4304
  y 40
4283
4305
  width 100
4284
4306
 
4285
4307
  string {
4286
- font family: 'Times', size: 14
4308
+ font family: 'Arial', size: 14
4287
4309
  color :black
4288
4310
 
4289
4311
  'Area Gallery'
@@ -4354,42 +4376,35 @@ window('Area Gallery', 400, 400) {
4354
4376
  path { # a dynamic path is added semi-declaratively inside on_draw block
4355
4377
  square(0, 0, 100)
4356
4378
  square(100, 100, 400)
4357
-
4379
+
4358
4380
  fill r: 102, g: 102, b: 204
4359
4381
  }
4360
4382
  path { # a dynamic path is added semi-declaratively inside on_draw block
4361
4383
  rectangle(0, 100, 100, 400)
4362
4384
  rectangle(100, 0, 400, 100)
4363
-
4385
+
4364
4386
  # linear gradient (has x0, y0, x1, y1, and stops)
4365
4387
  fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
4366
4388
  }
4367
4389
  path { # a dynamic path is added semi-declaratively inside on_draw block
4368
- figure(100, 100) {
4369
- line(100, 400)
4370
- line(400, 100)
4371
- line(400, 400)
4372
-
4373
- closed true
4374
- }
4375
-
4390
+ polygon(100, 100, 100, 400, 400, 100, 400, 400)
4391
+
4376
4392
  fill r: 202, g: 102, b: 104, a: 0.5
4377
4393
  stroke r: 0, g: 0, b: 0
4378
4394
  }
4379
4395
  path { # a dynamic path is added semi-declaratively inside on_draw block
4380
- figure(0, 0) {
4381
- bezier(200, 100, 100, 200, 400, 100)
4382
- bezier(300, 100, 100, 300, 100, 400)
4383
- bezier(100, 300, 300, 100, 400, 400)
4384
-
4385
- closed true
4386
- }
4387
-
4396
+ polybezier(0, 0, 200, 100, 100, 200, 400, 100, 300, 100, 100, 300, 100, 400, 100, 300, 300, 100, 400, 400)
4397
+
4388
4398
  fill r: 202, g: 102, b: 204, a: 0.5
4389
4399
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4390
4400
  }
4391
4401
  path { # a dynamic path is added semi-declaratively inside on_draw block
4392
- arc(400, 220, 180, 90, 90, false)
4402
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
4403
+
4404
+ stroke r: 0, g: 0, b: 0, thickness: 2
4405
+ }
4406
+ path { # a dynamic path is added semi-declaratively inside on_draw block
4407
+ arc(404, 216, 190, 90, 90, false)
4393
4408
 
4394
4409
  # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
4395
4410
  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}]
@@ -4401,9 +4416,9 @@ window('Area Gallery', 400, 400) {
4401
4416
  fill r: 202, g: 102, b: 204, a: 0.5
4402
4417
  stroke r: 0, g: 0, b: 0, thickness: 2
4403
4418
  }
4404
- text(160, 40, 100) { # x, y, width
4419
+ text(161, 40, 100) { # x, y, width
4405
4420
  string('Area Gallery') {
4406
- font family: 'Times', size: 14
4421
+ font family: 'Arial', size: 14
4407
4422
  color :black
4408
4423
  }
4409
4424
  }
@@ -4518,10 +4533,10 @@ window('Area Gallery', 400, 400) {
4518
4533
  x 400
4519
4534
  y 400
4520
4535
  }
4521
-
4536
+
4522
4537
  closed true
4523
4538
  }
4524
-
4539
+
4525
4540
  fill r: 202, g: 102, b: 104, a: 0.5
4526
4541
  stroke r: 0, g: 0, b: 0
4527
4542
  }
@@ -4554,18 +4569,42 @@ window('Area Gallery', 400, 400) {
4554
4569
  end_x 400
4555
4570
  end_y 400
4556
4571
  }
4557
-
4558
- closed true
4559
4572
  }
4560
-
4573
+
4561
4574
  fill r: 202, g: 102, b: 204, a: 0.5
4562
4575
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
4563
4576
  }
4577
+ path { # a dynamic path is added semi-declaratively inside on_draw block
4578
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
4579
+ figure {
4580
+ x 100
4581
+ y 100
4582
+
4583
+ line {
4584
+ x 400
4585
+ y 100
4586
+ }
4587
+ line {
4588
+ x 100
4589
+ y 400
4590
+ }
4591
+ line {
4592
+ x 400
4593
+ y 400
4594
+ }
4595
+ line {
4596
+ x 0
4597
+ y 0
4598
+ }
4599
+ }
4600
+
4601
+ stroke r: 0, g: 0, b: 0, thickness: 2
4602
+ }
4564
4603
  path { # a dynamic path is added semi-declaratively inside on_draw block
4565
4604
  arc {
4566
- x_center 400
4567
- y_center 220
4568
- radius 180
4605
+ x_center 404
4606
+ y_center 216
4607
+ radius 190
4569
4608
  start_angle 90
4570
4609
  sweep 90
4571
4610
  is_negative false
@@ -4586,12 +4625,12 @@ window('Area Gallery', 400, 400) {
4586
4625
  stroke r: 0, g: 0, b: 0, thickness: 2
4587
4626
  }
4588
4627
  text {
4589
- x 160
4628
+ x 161
4590
4629
  y 40
4591
4630
  width 100
4592
4631
 
4593
4632
  string {
4594
- font family: 'Times', size: 14
4633
+ font family: 'Arial', size: 14
4595
4634
  color :black
4596
4635
 
4597
4636
  'Area Gallery'
@@ -4908,20 +4947,13 @@ end
4908
4947
 
4909
4948
  # method-based custom control representing a graph path
4910
4949
  def graph_path(width, height, should_extend, &block)
4911
- locations = point_locations(width, height)
4950
+ locations = point_locations(width, height).flatten
4912
4951
  path {
4913
- first_location = locations[0] # x and y
4914
- figure(first_location[0], first_location[1]) {
4915
- locations.each do |loc|
4916
- line(loc[0], loc[1])
4917
- end
4918
- if should_extend
4919
- line(width, height)
4920
- line(0, height)
4921
-
4922
- closed true
4923
- end
4924
- }
4952
+ if should_extend
4953
+ polygon(locations + [width, height, 0, height])
4954
+ else
4955
+ polyline(locations)
4956
+ end
4925
4957
 
4926
4958
  # apply a transform to the coordinate space for this path so (0, 0) is the top-left corner of the graph
4927
4959
  transform {
@@ -6232,6 +6264,7 @@ class Tetris
6232
6264
 
6233
6265
  BLOCK_SIZE = 25
6234
6266
  BEVEL_CONSTANT = 20
6267
+ COLOR_GRAY = {r: 192, g: 192, b: 192}
6235
6268
 
6236
6269
  attr_reader :game
6237
6270
 
@@ -6264,19 +6297,74 @@ class Tetris
6264
6297
  Model::Game::PLAYFIELD_HEIGHT.times do |row|
6265
6298
  Model::Game::PLAYFIELD_HEIGHT.times do |column|
6266
6299
  Glimmer::DataBinding::Observer.proc do |new_color|
6267
- @blocks[row][column].fill = new_color
6300
+ Glimmer::LibUI.queue_main do
6301
+ color = Glimmer::LibUI.interpret_color(new_color)
6302
+ block = @blocks[row][column]
6303
+ block[:background_square].fill = color
6304
+ block[:top_bevel_edge].fill = {r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT}
6305
+ block[:right_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
6306
+ block[:bottom_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
6307
+ block[:left_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
6308
+ block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : color
6309
+ end
6268
6310
  end.observe(@game.playfield[row][column], :color)
6269
6311
  end
6270
6312
  end
6271
6313
  end
6272
6314
 
6273
6315
  def playfield(playfield_width: , playfield_height: , block_size: )
6274
- area {
6275
- @blocks = playfield_height.times.map do |row|
6276
- playfield_width.times.map do |column|
6277
- block(row: row, column: column, block_size: block_size)
6278
- end
6316
+ @blocks = []
6317
+ vertical_box {
6318
+ padded false
6319
+
6320
+ playfield_height.times.map do |row|
6321
+ @blocks << []
6322
+ horizontal_box {
6323
+ padded false
6324
+
6325
+ playfield_width.times.map do |column|
6326
+ @blocks.last << block(row: row, column: column, block_size: block_size)
6327
+ end
6328
+ }
6279
6329
  end
6330
+ }
6331
+ end
6332
+
6333
+ def block(row: , column: , block_size: )
6334
+ block = {}
6335
+ bevel_pixel_size = 0.16 * block_size.to_f
6336
+ color = Glimmer::LibUI.interpret_color(Model::Block::COLOR_CLEAR)
6337
+ area {
6338
+ block[:background_square] = path {
6339
+ square(0, 0, block_size)
6340
+
6341
+ fill color
6342
+ }
6343
+ block[:top_bevel_edge] = path {
6344
+ polygon(0, 0, block_size, 0, block_size - bevel_pixel_size, bevel_pixel_size, bevel_pixel_size, bevel_pixel_size)
6345
+
6346
+ fill r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT
6347
+ }
6348
+ block[:right_bevel_edge] = path {
6349
+ polygon(block_size, 0, block_size - bevel_pixel_size, bevel_pixel_size, block_size - bevel_pixel_size, block_size - bevel_pixel_size, block_size, block_size)
6350
+
6351
+ fill r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT
6352
+ }
6353
+ block[:bottom_bevel_edge] = path {
6354
+ polygon(block_size, block_size, 0, block_size, bevel_pixel_size, block_size - bevel_pixel_size, block_size - bevel_pixel_size, block_size - bevel_pixel_size)
6355
+
6356
+ fill r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT
6357
+ }
6358
+ block[:left_bevel_edge] = path {
6359
+ polygon(0, 0, 0, block_size, bevel_pixel_size, block_size - bevel_pixel_size, bevel_pixel_size, bevel_pixel_size)
6360
+
6361
+ fill r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT
6362
+ }
6363
+ block[:border_square] = path {
6364
+ square(0, 0, block_size)
6365
+
6366
+ stroke COLOR_GRAY
6367
+ }
6280
6368
 
6281
6369
  on_key_down do |key_event|
6282
6370
  case key_event
@@ -6304,14 +6392,7 @@ class Tetris
6304
6392
  end
6305
6393
  end
6306
6394
  }
6307
- end
6308
-
6309
- def block(row: , column: , block_size: )
6310
- path {
6311
- square(column * block_size, row * block_size, block_size)
6312
-
6313
- fill Model::Block::COLOR_CLEAR
6314
- }
6395
+ block
6315
6396
  end
6316
6397
 
6317
6398
  def start_moving_tetrominos_down
@@ -6321,7 +6402,10 @@ class Tetris
6321
6402
  end
6322
6403
 
6323
6404
  def show_game_over_dialog
6324
- msg_box('Game Over', "Score: #{@game.high_scores.first.score}")
6405
+ Glimmer::LibUI.queue_main do
6406
+ msg_box('Game Over', "Score: #{@game.high_scores.first.score}\nLines: #{@game.high_scores.first.lines}\nLevel: #{@game.high_scores.first.level}")
6407
+ @game.restart!
6408
+ end
6325
6409
  end
6326
6410
  end
6327
6411
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.17
1
+ 0.2.18
@@ -18,31 +18,24 @@ window('Area Gallery', 400, 400) {
18
18
  fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
19
19
  }
20
20
  path { # declarative stable path
21
- figure(100, 100) {
22
- line(100, 400)
23
- line(400, 100)
24
- line(400, 400)
25
-
26
- closed true
27
- }
28
-
21
+ polygon(100, 100, 100, 400, 400, 100, 400, 400)
22
+
29
23
  fill r: 202, g: 102, b: 104, a: 0.5
30
24
  stroke r: 0, g: 0, b: 0
31
25
  }
32
26
  path { # declarative stable path
33
- figure(0, 0) {
34
- bezier(200, 100, 100, 200, 400, 100)
35
- bezier(300, 100, 100, 300, 100, 400)
36
- bezier(100, 300, 300, 100, 400, 400)
37
-
38
- closed true
39
- }
27
+ polybezier(0, 0, 200, 100, 100, 200, 400, 100, 300, 100, 100, 300, 100, 400, 100, 300, 300, 100, 400, 400)
40
28
 
41
29
  fill r: 202, g: 102, b: 204, a: 0.5
42
30
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
43
31
  }
44
32
  path { # declarative stable path
45
- arc(400, 220, 180, 90, 90, false)
33
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
34
+
35
+ stroke r: 0, g: 0, b: 0, thickness: 2
36
+ }
37
+ path { # declarative stable path
38
+ arc(404, 216, 190, 90, 90, false)
46
39
 
47
40
  # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
48
41
  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}]
@@ -54,9 +47,9 @@ window('Area Gallery', 400, 400) {
54
47
  fill r: 202, g: 102, b: 204, a: 0.5
55
48
  stroke r: 0, g: 0, b: 0, thickness: 2
56
49
  }
57
- text(160, 40, 100) { # x, y, width
50
+ text(161, 40, 100) { # x, y, width
58
51
  string('Area Gallery') {
59
- font family: 'Times', size: 14
52
+ font family: 'Arial', size: 14
60
53
  color :black
61
54
  }
62
55
  }
@@ -88,18 +88,42 @@ window('Area Gallery', 400, 400) {
88
88
  end_x 400
89
89
  end_y 400
90
90
  }
91
-
92
- closed true
93
91
  }
94
92
 
95
93
  fill r: 202, g: 102, b: 204, a: 0.5
96
94
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
97
95
  }
96
+ path { # declarative stable path
97
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
98
+ figure {
99
+ x 100
100
+ y 100
101
+
102
+ line {
103
+ x 400
104
+ y 100
105
+ }
106
+ line {
107
+ x 100
108
+ y 400
109
+ }
110
+ line {
111
+ x 400
112
+ y 400
113
+ }
114
+ line {
115
+ x 0
116
+ y 0
117
+ }
118
+ }
119
+
120
+ stroke r: 0, g: 0, b: 0, thickness: 2
121
+ }
98
122
  path { # declarative stable path
99
123
  arc {
100
- x_center 400
101
- y_center 220
102
- radius 180
124
+ x_center 404
125
+ y_center 216
126
+ radius 190
103
127
  start_angle 90
104
128
  sweep 90
105
129
  is_negative false
@@ -120,12 +144,12 @@ window('Area Gallery', 400, 400) {
120
144
  stroke r: 0, g: 0, b: 0, thickness: 2
121
145
  }
122
146
  text {
123
- x 160
147
+ x 161
124
148
  y 40
125
149
  width 100
126
150
 
127
151
  string {
128
- font family: 'Times', size: 14
152
+ font family: 'Arial', size: 14
129
153
  color :black
130
154
 
131
155
  'Area Gallery'
@@ -8,42 +8,35 @@ window('Area Gallery', 400, 400) {
8
8
  path { # a dynamic path is added semi-declaratively inside on_draw block
9
9
  square(0, 0, 100)
10
10
  square(100, 100, 400)
11
-
11
+
12
12
  fill r: 102, g: 102, b: 204
13
13
  }
14
14
  path { # a dynamic path is added semi-declaratively inside on_draw block
15
15
  rectangle(0, 100, 100, 400)
16
16
  rectangle(100, 0, 400, 100)
17
-
17
+
18
18
  # linear gradient (has x0, y0, x1, y1, and stops)
19
19
  fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
20
20
  }
21
21
  path { # a dynamic path is added semi-declaratively inside on_draw block
22
- figure(100, 100) {
23
- line(100, 400)
24
- line(400, 100)
25
- line(400, 400)
26
-
27
- closed true
28
- }
29
-
22
+ polygon(100, 100, 100, 400, 400, 100, 400, 400)
23
+
30
24
  fill r: 202, g: 102, b: 104, a: 0.5
31
25
  stroke r: 0, g: 0, b: 0
32
26
  }
33
27
  path { # a dynamic path is added semi-declaratively inside on_draw block
34
- figure(0, 0) {
35
- bezier(200, 100, 100, 200, 400, 100)
36
- bezier(300, 100, 100, 300, 100, 400)
37
- bezier(100, 300, 300, 100, 400, 400)
38
-
39
- closed true
40
- }
41
-
28
+ polybezier(0, 0, 200, 100, 100, 200, 400, 100, 300, 100, 100, 300, 100, 400, 100, 300, 300, 100, 400, 400)
29
+
42
30
  fill r: 202, g: 102, b: 204, a: 0.5
43
31
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
44
32
  }
45
33
  path { # a dynamic path is added semi-declaratively inside on_draw block
46
- arc(400, 220, 180, 90, 90, false)
34
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
35
+
36
+ stroke r: 0, g: 0, b: 0, thickness: 2
37
+ }
38
+ path { # a dynamic path is added semi-declaratively inside on_draw block
39
+ arc(404, 216, 190, 90, 90, false)
47
40
 
48
41
  # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
49
42
  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}]
@@ -55,9 +48,9 @@ window('Area Gallery', 400, 400) {
55
48
  fill r: 202, g: 102, b: 204, a: 0.5
56
49
  stroke r: 0, g: 0, b: 0, thickness: 2
57
50
  }
58
- text(160, 40, 100) { # x, y, width
51
+ text(161, 40, 100) { # x, y, width
59
52
  string('Area Gallery') {
60
- font family: 'Times', size: 14
53
+ font family: 'Arial', size: 14
61
54
  color :black
62
55
  }
63
56
  }
@@ -53,10 +53,10 @@ window('Area Gallery', 400, 400) {
53
53
  x 400
54
54
  y 400
55
55
  }
56
-
56
+
57
57
  closed true
58
58
  }
59
-
59
+
60
60
  fill r: 202, g: 102, b: 104, a: 0.5
61
61
  stroke r: 0, g: 0, b: 0
62
62
  }
@@ -89,18 +89,42 @@ window('Area Gallery', 400, 400) {
89
89
  end_x 400
90
90
  end_y 400
91
91
  }
92
-
93
- closed true
94
92
  }
95
-
93
+
96
94
  fill r: 202, g: 102, b: 204, a: 0.5
97
95
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
98
96
  }
97
+ path { # a dynamic path is added semi-declaratively inside on_draw block
98
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
99
+ figure {
100
+ x 100
101
+ y 100
102
+
103
+ line {
104
+ x 400
105
+ y 100
106
+ }
107
+ line {
108
+ x 100
109
+ y 400
110
+ }
111
+ line {
112
+ x 400
113
+ y 400
114
+ }
115
+ line {
116
+ x 0
117
+ y 0
118
+ }
119
+ }
120
+
121
+ stroke r: 0, g: 0, b: 0, thickness: 2
122
+ }
99
123
  path { # a dynamic path is added semi-declaratively inside on_draw block
100
124
  arc {
101
- x_center 400
102
- y_center 220
103
- radius 180
125
+ x_center 404
126
+ y_center 216
127
+ radius 190
104
128
  start_angle 90
105
129
  sweep 90
106
130
  is_negative false
@@ -121,12 +145,12 @@ window('Area Gallery', 400, 400) {
121
145
  stroke r: 0, g: 0, b: 0, thickness: 2
122
146
  }
123
147
  text {
124
- x 160
148
+ x 161
125
149
  y 40
126
150
  width 100
127
151
 
128
152
  string {
129
- font family: 'Times', size: 14
153
+ font family: 'Arial', size: 14
130
154
  color :black
131
155
 
132
156
  'Area Gallery'
@@ -31,20 +31,13 @@ end
31
31
 
32
32
  # method-based custom control representing a graph path
33
33
  def graph_path(width, height, should_extend, &block)
34
- locations = point_locations(width, height)
34
+ locations = point_locations(width, height).flatten
35
35
  path {
36
- first_location = locations[0] # x and y
37
- figure(first_location[0], first_location[1]) {
38
- locations.each do |loc|
39
- line(loc[0], loc[1])
40
- end
41
- if should_extend
42
- line(width, height)
43
- line(0, height)
44
-
45
- closed true
46
- end
47
- }
36
+ if should_extend
37
+ polygon(locations + [width, height, 0, height])
38
+ else
39
+ polyline(locations)
40
+ end
48
41
 
49
42
  # apply a transform to the coordinate space for this path so (0, 0) is the top-left corner of the graph
50
43
  transform {
@@ -31,9 +31,9 @@ class Tetris
31
31
  LETTER_COLORS = {
32
32
  I: :cyan,
33
33
  J: :blue,
34
- L: :dark_yellow,
34
+ L: :olive,
35
35
  O: :yellow,
36
- S: :green,
36
+ S: :lime,
37
37
  T: :magenta,
38
38
  Z: :red,
39
39
  }
data/examples/tetris.rb CHANGED
@@ -1,24 +1,3 @@
1
- # Copyright (c) 2021 Andy Maleh
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining
4
- # a copy of this software and associated documentation files (the
5
- # "Software"), to deal in the Software without restriction, including
6
- # without limitation the rights to use, copy, modify, merge, publish,
7
- # distribute, sublicense, and/or sell copies of the Software, and to
8
- # permit persons to whom the Software is furnished to do so, subject to
9
- # the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be
12
- # included in all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
-
22
1
  require 'glimmer-dsl-libui'
23
2
 
24
3
  require_relative 'tetris/model/game'
@@ -28,6 +7,7 @@ class Tetris
28
7
 
29
8
  BLOCK_SIZE = 25
30
9
  BEVEL_CONSTANT = 20
10
+ COLOR_GRAY = {r: 192, g: 192, b: 192}
31
11
 
32
12
  attr_reader :game
33
13
 
@@ -60,19 +40,74 @@ class Tetris
60
40
  Model::Game::PLAYFIELD_HEIGHT.times do |row|
61
41
  Model::Game::PLAYFIELD_HEIGHT.times do |column|
62
42
  Glimmer::DataBinding::Observer.proc do |new_color|
63
- @blocks[row][column].fill = new_color
43
+ Glimmer::LibUI.queue_main do
44
+ color = Glimmer::LibUI.interpret_color(new_color)
45
+ block = @blocks[row][column]
46
+ block[:background_square].fill = color
47
+ block[:top_bevel_edge].fill = {r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT}
48
+ block[:right_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
49
+ block[:bottom_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
50
+ block[:left_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
51
+ block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : color
52
+ end
64
53
  end.observe(@game.playfield[row][column], :color)
65
54
  end
66
55
  end
67
56
  end
68
57
 
69
58
  def playfield(playfield_width: , playfield_height: , block_size: )
70
- area {
71
- @blocks = playfield_height.times.map do |row|
72
- playfield_width.times.map do |column|
73
- block(row: row, column: column, block_size: block_size)
74
- end
59
+ @blocks = []
60
+ vertical_box {
61
+ padded false
62
+
63
+ playfield_height.times.map do |row|
64
+ @blocks << []
65
+ horizontal_box {
66
+ padded false
67
+
68
+ playfield_width.times.map do |column|
69
+ @blocks.last << block(row: row, column: column, block_size: block_size)
70
+ end
71
+ }
75
72
  end
73
+ }
74
+ end
75
+
76
+ def block(row: , column: , block_size: )
77
+ block = {}
78
+ bevel_pixel_size = 0.16 * block_size.to_f
79
+ color = Glimmer::LibUI.interpret_color(Model::Block::COLOR_CLEAR)
80
+ area {
81
+ block[:background_square] = path {
82
+ square(0, 0, block_size)
83
+
84
+ fill color
85
+ }
86
+ block[:top_bevel_edge] = path {
87
+ polygon(0, 0, block_size, 0, block_size - bevel_pixel_size, bevel_pixel_size, bevel_pixel_size, bevel_pixel_size)
88
+
89
+ fill r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT
90
+ }
91
+ block[:right_bevel_edge] = path {
92
+ polygon(block_size, 0, block_size - bevel_pixel_size, bevel_pixel_size, block_size - bevel_pixel_size, block_size - bevel_pixel_size, block_size, block_size)
93
+
94
+ fill r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT
95
+ }
96
+ block[:bottom_bevel_edge] = path {
97
+ polygon(block_size, block_size, 0, block_size, bevel_pixel_size, block_size - bevel_pixel_size, block_size - bevel_pixel_size, block_size - bevel_pixel_size)
98
+
99
+ fill r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT
100
+ }
101
+ block[:left_bevel_edge] = path {
102
+ polygon(0, 0, 0, block_size, bevel_pixel_size, block_size - bevel_pixel_size, bevel_pixel_size, bevel_pixel_size)
103
+
104
+ fill r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT
105
+ }
106
+ block[:border_square] = path {
107
+ square(0, 0, block_size)
108
+
109
+ stroke COLOR_GRAY
110
+ }
76
111
 
77
112
  on_key_down do |key_event|
78
113
  case key_event
@@ -100,14 +135,7 @@ class Tetris
100
135
  end
101
136
  end
102
137
  }
103
- end
104
-
105
- def block(row: , column: , block_size: )
106
- path {
107
- square(column * block_size, row * block_size, block_size)
108
-
109
- fill Model::Block::COLOR_CLEAR
110
- }
138
+ block
111
139
  end
112
140
 
113
141
  def start_moving_tetrominos_down
@@ -117,7 +145,10 @@ class Tetris
117
145
  end
118
146
 
119
147
  def show_game_over_dialog
120
- msg_box('Game Over', "Score: #{@game.high_scores.first.score}")
148
+ Glimmer::LibUI.queue_main do
149
+ msg_box('Game Over', "Score: #{@game.high_scores.first.score}\nLines: #{@game.high_scores.first.lines}\nLevel: #{@game.high_scores.first.level}")
150
+ @game.restart!
151
+ end
121
152
  end
122
153
  end
123
154
 
Binary file
@@ -37,6 +37,7 @@ module Glimmer
37
37
  end
38
38
 
39
39
  def interpret(parent, keyword, *args, &block)
40
+ args = [args] if args.size > 1 && Glimmer::LibUI::Shape.shape_class(keyword).parameters.size == 1
40
41
  Glimmer::LibUI::Shape.create(keyword, parent, args, &block)
41
42
  end
42
43
 
@@ -109,6 +109,31 @@ module Glimmer
109
109
  queue_redraw_all
110
110
  end
111
111
 
112
+ def request_auto_redraw
113
+ # TODO implement functionality to delay queuing area redraws until post_add_content has been called (area definition is done). Maybe offer an option to enable redrawing before area is closed too.
114
+ queue_redraw_all if auto_redraw_enabled?
115
+ end
116
+
117
+ def auto_redraw_enabled(value = nil)
118
+ if value.nil?
119
+ @auto_redraw_enabled = true if @auto_redraw_enabled.nil?
120
+ @auto_redraw_enabled
121
+ else
122
+ @auto_redraw_enabled = !!value
123
+ end
124
+ end
125
+ alias auto_redraw_enabled? auto_redraw_enabled
126
+ alias auto_redraw_enabled= auto_redraw_enabled
127
+ alias set_auto_redraw_enabled auto_redraw_enabled
128
+
129
+ def pause_auto_redraw
130
+ self.auto_redraw_enabled = false
131
+ end
132
+
133
+ def resume_auto_redraw
134
+ self.auto_redraw_enabled = true
135
+ end
136
+
112
137
  private
113
138
 
114
139
  def build_control
@@ -68,12 +68,16 @@ module Glimmer
68
68
  if args.empty?
69
69
  @fill ||= {}
70
70
  else
71
- @fill = Glimmer::LibUI.interpret_color(args)
72
- @parent_proxy&.queue_redraw_all
71
+ new_color = Glimmer::LibUI.interpret_color(args)
72
+ if new_color != @fill
73
+ @fill_observer&.unobserve(@fill) if @fill
74
+ @fill = new_color
75
+ request_auto_redraw
76
+ end
73
77
  end
74
78
  @fill.tap do
75
79
  @fill_observer ||= Glimmer::DataBinding::Observer.proc do
76
- @parent_proxy&.queue_redraw_all
80
+ request_auto_redraw
77
81
  end
78
82
  @fill_observer.observe(@fill)
79
83
  end
@@ -92,12 +96,16 @@ module Glimmer
92
96
  if args.empty?
93
97
  @stroke ||= {}
94
98
  else
95
- @stroke = Glimmer::LibUI.interpret_color(args)
96
- @parent_proxy&.queue_redraw_all
99
+ new_color = Glimmer::LibUI.interpret_color(args)
100
+ if new_color != @stroke
101
+ @stroke_observer&.unobserve(@stroke) if @stroke
102
+ @stroke = Glimmer::LibUI.interpret_color(args)
103
+ request_auto_redraw
104
+ end
97
105
  end
98
106
  @stroke.tap do
99
107
  @stroke_observer ||= Glimmer::DataBinding::Observer.proc do
100
- @parent_proxy&.queue_redraw_all
108
+ request_auto_redraw
101
109
  end
102
110
  @stroke_observer.observe(@stroke)
103
111
  end
@@ -137,7 +145,11 @@ module Glimmer
137
145
  end
138
146
 
139
147
  def redraw
140
- @parent_proxy&.queue_redraw_all
148
+ @parent_proxy&.redraw
149
+ end
150
+
151
+ def request_auto_redraw
152
+ @parent_proxy&.request_auto_redraw
141
153
  end
142
154
 
143
155
  private
@@ -41,8 +41,10 @@ module Glimmer
41
41
  if value.nil?
42
42
  @closed
43
43
  else
44
- @closed = value
45
- area_proxy&.queue_redraw_all
44
+ if !!value != !!@closed
45
+ @closed = value
46
+ request_auto_redraw
47
+ end
46
48
  end
47
49
  end
48
50
  alias closed= closed
@@ -0,0 +1,45 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Shape
27
+ class Polybezier < Shape
28
+ parameters :point_array
29
+ parameter_defaults []
30
+
31
+ def draw(area_draw_params)
32
+ alternating_x_y_array = point_array.to_a.compact.flatten
33
+ unless alternating_x_y_array.empty?
34
+ ::LibUI.draw_path_new_figure(path_proxy.libui, alternating_x_y_array[0], alternating_x_y_array[1])
35
+ ((alternating_x_y_array.size - 2) / 6).times do |n|
36
+ point_alternating_x_y_index = n * 6
37
+ ::LibUI.draw_path_bezier_to(path_proxy.libui, alternating_x_y_array[point_alternating_x_y_index + 2], alternating_x_y_array[point_alternating_x_y_index + 3], alternating_x_y_array[point_alternating_x_y_index + 4], alternating_x_y_array[point_alternating_x_y_index + 5], alternating_x_y_array[point_alternating_x_y_index + 6], alternating_x_y_array[point_alternating_x_y_index + 7])
38
+ end
39
+ end
40
+ super
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Shape
27
+ class Polygon < Shape
28
+ parameters :point_array
29
+ parameter_defaults []
30
+
31
+ def draw(area_draw_params)
32
+ alternating_x_y_array = point_array.to_a.compact.flatten
33
+ unless alternating_x_y_array.empty?
34
+ ::LibUI.draw_path_new_figure(path_proxy.libui, alternating_x_y_array[0], alternating_x_y_array[1])
35
+ ((alternating_x_y_array.size - 2) / 2).times do |n|
36
+ point_alternating_x_y_index = n * 2
37
+ ::LibUI.draw_path_line_to(path_proxy.libui, alternating_x_y_array[point_alternating_x_y_index + 2], alternating_x_y_array[point_alternating_x_y_index + 3])
38
+ end
39
+ ::LibUI.draw_path_close_figure(path_proxy.libui)
40
+ end
41
+ super
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,45 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Shape
27
+ class Polyline < Shape
28
+ parameters :point_array
29
+ parameter_defaults []
30
+
31
+ def draw(area_draw_params)
32
+ alternating_x_y_array = point_array.to_a.compact.flatten
33
+ unless alternating_x_y_array.empty?
34
+ ::LibUI.draw_path_new_figure(path_proxy.libui, alternating_x_y_array[0], alternating_x_y_array[1])
35
+ ((alternating_x_y_array.size - 2) / 2).times do |n|
36
+ point_alternating_x_y_index = n * 2
37
+ ::LibUI.draw_path_line_to(path_proxy.libui, alternating_x_y_array[point_alternating_x_y_index + 2], alternating_x_y_array[point_alternating_x_y_index + 3])
38
+ end
39
+ end
40
+ super
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -87,7 +87,11 @@ module Glimmer
87
87
  end
88
88
 
89
89
  def redraw
90
- area_proxy&.queue_redraw_all
90
+ area_proxy&.auto_redraw
91
+ end
92
+
93
+ def request_auto_redraw
94
+ area_proxy&.request_auto_redraw
91
95
  end
92
96
 
93
97
  def destroy
@@ -113,8 +117,10 @@ module Glimmer
113
117
  method_name = method_name.to_s
114
118
  parameter_index = self.class.parameters.index(method_name_parameter)
115
119
  if method_name.start_with?('set_') || method_name.end_with?('=') || !args.empty?
116
- @args[parameter_index] = args.first
117
- area_proxy&.queue_redraw_all
120
+ if args.first != @args[parameter_index]
121
+ @args[parameter_index] = args.first
122
+ request_auto_redraw
123
+ end
118
124
  else
119
125
  @args[parameter_index]
120
126
  end
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.17
4
+ version: 0.2.18
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-11-03 00:00:00.000000000 Z
11
+ date: 2021-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -344,6 +344,9 @@ files:
344
344
  - lib/glimmer/libui/shape/circle.rb
345
345
  - lib/glimmer/libui/shape/figure.rb
346
346
  - lib/glimmer/libui/shape/line.rb
347
+ - lib/glimmer/libui/shape/polybezier.rb
348
+ - lib/glimmer/libui/shape/polygon.rb
349
+ - lib/glimmer/libui/shape/polyline.rb
347
350
  - lib/glimmer/libui/shape/rectangle.rb
348
351
  - lib/glimmer/libui/shape/square.rb
349
352
  - sounds/AlanWalker-Faded.mid