glimmer-dsl-gtk 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +521 -6
- data/VERSION +1 -1
- data/glimmer-dsl-gtk.gemspec +0 -0
- data/images/breaking-blue-wave.png +0 -0
- data/lib/glimmer/gtk/shape/path.rb +29 -0
- data/lib/glimmer/gtk/shape.rb +34 -20
- data/lib/glimmer/gtk/transformable.rb +93 -0
- data/lib/glimmer/gtk/widget_proxy/drawing_area_proxy.rb +8 -1
- data/samples/cairo/arc.rb +44 -0
- data/samples/cairo/arc_negative.rb +44 -0
- data/samples/cairo/clip.rb +34 -0
- data/samples/cairo/clip_image.rb +28 -0
- data/samples/cairo/curve_to.rb +39 -0
- data/samples/cairo/dashes.rb +30 -0
- data/samples/cairo/fill_and_stroke2.rb +36 -0
- data/samples/cairo/fill_style.rb +43 -0
- data/samples/cairo/gradient.rb +31 -0
- data/samples/cairo/image.rb +23 -0
- data/samples/cairo/image_gradient.rb +32 -0
- data/samples/cairo/multi_segment_caps.rb +27 -0
- data/samples/cairo/rounded_rectangle.rb +20 -0
- data/samples/cairo/set_line_cap.rb +53 -0
- data/samples/cairo/set_line_join.rb +43 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3230b55893dbd6faaa1a5ba29d191e0f55586d6d6147e5274286162d02d972c
|
4
|
+
data.tar.gz: ac79a95afc0e0f3cbaf37d501477beace1a810bdfdf82eb10d53d79094d2dedf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8258cdcf3a83e552a8b24b4ed1d431b1c79414f5ff8c0f4a17779e40b95bd648c8470ca8fa54fcaf7622e34a534828cb137c543d9217ae83df5f969a0636beca
|
7
|
+
data.tar.gz: f01a32a3d485115028622c4235997c4018c369bf350fa23efbe6877a508afd047147c2f5a134e83367af007762d894f753ed2c3afb4bc2baddb7819ea42a7220
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.6
|
4
|
+
|
5
|
+
- samples/cairo/clip_image.rb
|
6
|
+
- samples/cairo/curve_to.rb
|
7
|
+
- samples/cairo/dashes.rb
|
8
|
+
- samples/cairo/fill_and_stroke2.rb
|
9
|
+
- samples/cairo/fill_style.rb
|
10
|
+
- samples/cairo/gradient.rb
|
11
|
+
- samples/cairo/image.rb
|
12
|
+
- samples/cairo/image_gradient.rb
|
13
|
+
- samples/cairo/multi_segment_caps.rb
|
14
|
+
- samples/cairo/rounded_rectangle.rb
|
15
|
+
- samples/cairo/set_line_cap.rb
|
16
|
+
- samples/cairo/set_line_join.rb
|
17
|
+
- Supported nested sub-paths (nesting `path` within another `path`)
|
18
|
+
- Support declarative `fill`/`paint` of `image, x, y` in cairo graphics
|
19
|
+
- Support declarative transforms on cairo graphics shapes: `translate`, `scale`, `rotate`
|
20
|
+
- Support applying transform on `drawing_area` `paint`
|
21
|
+
|
3
22
|
## 0.0.5
|
4
23
|
|
5
24
|
- Support `drawing_area#paint(red, green, blue)` operation to set the initial `drawing_area` paint color base
|
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 GTK 0.0.
|
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 GTK 0.0.6
|
2
2
|
## Ruby-GNOME Desktop Development GUI Library
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-gtk.svg)](http://badge.fury.io/rb/glimmer-dsl-gtk)
|
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)
|
@@ -80,7 +80,7 @@ gem install glimmer-dsl-gtk
|
|
80
80
|
|
81
81
|
Add the following to `Gemfile`:
|
82
82
|
```
|
83
|
-
gem 'glimmer-dsl-gtk', '~> 0.0.
|
83
|
+
gem 'glimmer-dsl-gtk', '~> 0.0.6'
|
84
84
|
```
|
85
85
|
|
86
86
|
And, then run:
|
@@ -152,13 +152,13 @@ Note that it is usually recommended to observe external model objects (not `self
|
|
152
152
|
|
153
153
|
[Cairo](https://www.cairographics.org/) is the engine behind drawing arbitrary 2D geometric shapes in [GTK](https://www.gtk.org/).
|
154
154
|
|
155
|
-
In [Glimmer DSL for GTK](https://rubygems.org/gems/glimmer-dsl-gtk), you can draw Cairo shapes declaratively in a way similar to how SVG works, but using one language; Ruby, thus being able to utilize Ruby logic (e.g. if statement or each loop) with it effortlessly when needed.
|
155
|
+
In [Glimmer DSL for GTK](https://rubygems.org/gems/glimmer-dsl-gtk), you can draw Cairo shapes declaratively in a way similar to how SVG works, but using one language; Ruby, thus being able to utilize Ruby logic (e.g. if statement or each loop) with it effortlessly when needed. Declarative syntax also yields less code that is simpler, not dependent on ordering of nested properties, and more understandable/maintainable.
|
156
156
|
|
157
157
|
Below is a quick tutorial consisting of samples inspired and ported from [Mohit Sindhwani's blog post "Cairo with Ruby - Samples using RCairo"](https://notepad.onghu.com/2021/cairo-samples-in-ruby/).
|
158
158
|
|
159
159
|
### Arc
|
160
160
|
|
161
|
-
|
161
|
+
[samples/cairo/arc.rb](/samples/cairo/arc.rb)
|
162
162
|
|
163
163
|
```ruby
|
164
164
|
require 'glimmer-dsl-gtk'
|
@@ -211,7 +211,7 @@ window {
|
|
211
211
|
|
212
212
|
### Arc Negative
|
213
213
|
|
214
|
-
|
214
|
+
[samples/cairo/arc_negative.rb](/samples/cairo/arc_negative.rb)
|
215
215
|
|
216
216
|
```ruby
|
217
217
|
require 'glimmer-dsl-gtk'
|
@@ -264,7 +264,7 @@ window {
|
|
264
264
|
|
265
265
|
### Clip
|
266
266
|
|
267
|
-
|
267
|
+
[samples/cairo/clip.rb](/samples/cairo/clip.rb)
|
268
268
|
|
269
269
|
```ruby
|
270
270
|
require 'glimmer-dsl-gtk'
|
@@ -305,6 +305,521 @@ window {
|
|
305
305
|
|
306
306
|
![Clip](/screenshots/glimmer-dsl-gtk-mac-cairo-clip.png)
|
307
307
|
|
308
|
+
### Clip Image
|
309
|
+
|
310
|
+
[samples/cairo/clip_image.rb](/samples/cairo/clip_image.rb)
|
311
|
+
|
312
|
+
```ruby
|
313
|
+
require 'glimmer-dsl-gtk'
|
314
|
+
|
315
|
+
include Glimmer
|
316
|
+
|
317
|
+
window {
|
318
|
+
title 'Clip Image'
|
319
|
+
default_size 256, 256
|
320
|
+
|
321
|
+
drawing_area {
|
322
|
+
paint 242.25, 242.25, 242.25
|
323
|
+
|
324
|
+
arc(128.0, 128.0, 76.8, 0, 2 * Math::PI) {
|
325
|
+
clip true # designate arc as the clipping area
|
326
|
+
}
|
327
|
+
|
328
|
+
rectangle(0, 0, 256, 256) {
|
329
|
+
# Source image is from:
|
330
|
+
# - https://www.publicdomainpictures.net/en/view-image.php?image=7683&picture=breaking-blue-wave
|
331
|
+
# Converted to PNG before using it
|
332
|
+
image = Cairo::ImageSurface.from_png(File.expand_path(File.join('..', '..', 'images', 'breaking-blue-wave.png'), __dir__))
|
333
|
+
w = image.width
|
334
|
+
h = image.height
|
335
|
+
|
336
|
+
scale 256.0/w, 256.0/h, exclude: :shape # applies scale to fill source image only
|
337
|
+
fill image, 0, 0
|
338
|
+
}
|
339
|
+
}
|
340
|
+
}.show
|
341
|
+
```
|
342
|
+
|
343
|
+
![Clip Image](/screenshots/glimmer-dsl-gtk-mac-cairo-clip-image.png)
|
344
|
+
|
345
|
+
### Curve to
|
346
|
+
|
347
|
+
[samples/cairo/curve_to.rb](/samples/cairo/curve_to.rb)
|
348
|
+
|
349
|
+
```ruby
|
350
|
+
require 'glimmer-dsl-gtk'
|
351
|
+
|
352
|
+
include Glimmer
|
353
|
+
|
354
|
+
window {
|
355
|
+
title 'Curve to'
|
356
|
+
default_size 256, 256
|
357
|
+
|
358
|
+
drawing_area {
|
359
|
+
paint 242.25, 242.25, 242.25
|
360
|
+
|
361
|
+
x=25.6
|
362
|
+
y=128.0
|
363
|
+
x1=102.4
|
364
|
+
y1=230.4
|
365
|
+
x2=153.6
|
366
|
+
y2=25.6
|
367
|
+
x3=230.4
|
368
|
+
y3=128.0
|
369
|
+
|
370
|
+
path {
|
371
|
+
move_to x, y
|
372
|
+
curve_to x1, y1, x2, y2, x3, y3
|
373
|
+
|
374
|
+
line_width 10
|
375
|
+
stroke 0, 0, 0
|
376
|
+
}
|
377
|
+
|
378
|
+
path {
|
379
|
+
move_to x,y
|
380
|
+
line_to x1,y1
|
381
|
+
move_to x2,y2
|
382
|
+
line_to x3,y3
|
383
|
+
|
384
|
+
line_width 6
|
385
|
+
stroke 255, 51, 51, 0.6
|
386
|
+
}
|
387
|
+
}
|
388
|
+
}.show
|
389
|
+
```
|
390
|
+
|
391
|
+
![Curve to](/screenshots/glimmer-dsl-gtk-mac-cairo-curve-to.png)
|
392
|
+
|
393
|
+
### Dashes
|
394
|
+
|
395
|
+
[samples/cairo/dashes.rb](/samples/cairo/dashes.rb)
|
396
|
+
|
397
|
+
```ruby
|
398
|
+
require 'glimmer-dsl-gtk'
|
399
|
+
|
400
|
+
include Glimmer
|
401
|
+
|
402
|
+
window {
|
403
|
+
title 'Dashes'
|
404
|
+
default_size 256, 256
|
405
|
+
|
406
|
+
drawing_area {
|
407
|
+
paint 242.25, 242.25, 242.25
|
408
|
+
|
409
|
+
dashes = [ 50.0, # ink
|
410
|
+
10.0, # skip
|
411
|
+
10.0, # ink
|
412
|
+
10.0 # skip
|
413
|
+
]
|
414
|
+
offset = -50.0
|
415
|
+
|
416
|
+
path {
|
417
|
+
move_to 128.0, 25.6
|
418
|
+
line_to 230.4, 230.4
|
419
|
+
rel_line_to -102.4, 0.0
|
420
|
+
curve_to 51.2, 230.4, 51.2, 128.0, 128.0, 128.0
|
421
|
+
|
422
|
+
line_width 10
|
423
|
+
dash dashes, offset
|
424
|
+
stroke 0, 0, 0
|
425
|
+
}
|
426
|
+
}
|
427
|
+
}.show
|
428
|
+
```
|
429
|
+
|
430
|
+
![Dashes](/screenshots/glimmer-dsl-gtk-mac-cairo-dashes.png)
|
431
|
+
|
432
|
+
### Fill and Stroke 2
|
433
|
+
|
434
|
+
(note: there is no Fill and Stroke 1; this was adopted from [Mohit's blog post](https://notepad.onghu.com/2021/cairo-samples-in-ruby/), which only mentioned Fill and Stroke 2)
|
435
|
+
|
436
|
+
[samples/cairo/fill_and_stroke2.rb](/samples/cairo/fill_and_stroke2.rb)
|
437
|
+
|
438
|
+
```ruby
|
439
|
+
require 'glimmer-dsl-gtk'
|
440
|
+
|
441
|
+
include Glimmer
|
442
|
+
|
443
|
+
window {
|
444
|
+
title 'Fill and Stroke 2'
|
445
|
+
default_size 256, 256
|
446
|
+
|
447
|
+
drawing_area {
|
448
|
+
paint 242.25, 242.25, 242.25
|
449
|
+
|
450
|
+
path {
|
451
|
+
move_to 128.0, 25.6
|
452
|
+
line_to 230.4, 230.4
|
453
|
+
rel_line_to -102.4, 0.0
|
454
|
+
curve_to 51.2, 230.4, 51.2, 128.0, 128.0, 128.0
|
455
|
+
close_path
|
456
|
+
|
457
|
+
fill 0, 0, 255
|
458
|
+
stroke 0, 0, 0
|
459
|
+
line_width 10
|
460
|
+
}
|
461
|
+
|
462
|
+
path {
|
463
|
+
move_to 64.0, 25.6
|
464
|
+
rel_line_to 51.2, 51.2
|
465
|
+
rel_line_to -51.2, 51.2
|
466
|
+
rel_line_to -51.2, -51.2
|
467
|
+
close_path
|
468
|
+
|
469
|
+
fill 0, 0, 255
|
470
|
+
stroke 0, 0, 0
|
471
|
+
line_width 10
|
472
|
+
}
|
473
|
+
}
|
474
|
+
}.show
|
475
|
+
```
|
476
|
+
|
477
|
+
![Fill and Stroke 2](/screenshots/glimmer-dsl-gtk-mac-cairo-fill-and-stroke2.png)
|
478
|
+
|
479
|
+
### Fill Style
|
480
|
+
|
481
|
+
[samples/cairo/fill_style.rb](/samples/cairo/fill_style.rb)
|
482
|
+
|
483
|
+
```ruby
|
484
|
+
require 'glimmer-dsl-gtk'
|
485
|
+
|
486
|
+
include Glimmer
|
487
|
+
|
488
|
+
window {
|
489
|
+
title 'Fill Style'
|
490
|
+
default_size 256, 256
|
491
|
+
|
492
|
+
drawing_area {
|
493
|
+
paint 242.25, 242.25, 242.25
|
494
|
+
|
495
|
+
path {
|
496
|
+
rectangle 12, 12, 232, 70
|
497
|
+
path { # sub-path
|
498
|
+
arc 64, 64, 40, 0, 2*Math::PI
|
499
|
+
}
|
500
|
+
path { # sub-path
|
501
|
+
arc_negative 192, 64, 40, 0, -2*Math::PI
|
502
|
+
}
|
503
|
+
|
504
|
+
fill_rule Cairo::FILL_RULE_EVEN_ODD
|
505
|
+
line_width 6
|
506
|
+
fill 0, 178.5, 0
|
507
|
+
stroke 0, 0, 0
|
508
|
+
}
|
509
|
+
|
510
|
+
path {
|
511
|
+
rectangle 12, 12, 232, 70
|
512
|
+
path { # sub-path
|
513
|
+
arc 64, 64, 40, 0, 2*Math::PI
|
514
|
+
}
|
515
|
+
path { # sub-path
|
516
|
+
arc_negative 192, 64, 40, 0, -2*Math::PI
|
517
|
+
}
|
518
|
+
|
519
|
+
translate 0, 128
|
520
|
+
fill_rule Cairo::FILL_RULE_WINDING
|
521
|
+
line_width 6
|
522
|
+
fill 0, 0, 229.5
|
523
|
+
stroke 0, 0, 0
|
524
|
+
}
|
525
|
+
}
|
526
|
+
}.show
|
527
|
+
```
|
528
|
+
|
529
|
+
![Fill Style](/screenshots/glimmer-dsl-gtk-mac-cairo-fill-style.png)
|
530
|
+
|
531
|
+
### Gradient
|
532
|
+
|
533
|
+
[samples/cairo/gradient.rb](/samples/cairo/gradient.rb)
|
534
|
+
|
535
|
+
```ruby
|
536
|
+
require 'glimmer-dsl-gtk'
|
537
|
+
|
538
|
+
include Glimmer
|
539
|
+
|
540
|
+
window {
|
541
|
+
title 'Gradient'
|
542
|
+
default_size 256, 256
|
543
|
+
|
544
|
+
drawing_area {
|
545
|
+
paint 242.25, 242.25, 242.25
|
546
|
+
|
547
|
+
# Create the Linear Pattern
|
548
|
+
rectangle(0, 0, 256, 256) {
|
549
|
+
pat = Cairo::LinearPattern.new(0.0, 0.0, 0.0, 256.0)
|
550
|
+
pat.add_color_stop_rgba(1, 0, 0, 0, 1)
|
551
|
+
pat.add_color_stop_rgba(0, 1, 1, 1, 1)
|
552
|
+
|
553
|
+
fill pat
|
554
|
+
}
|
555
|
+
|
556
|
+
# Create the radial pattern
|
557
|
+
arc(128.0, 128.0, 76.8, 0, 2 * Math::PI) {
|
558
|
+
pat = Cairo::RadialPattern.new(115.2, 102.4, 25.6,
|
559
|
+
102.4, 102.4, 128.0)
|
560
|
+
pat.add_color_stop_rgba(0, 1, 1, 1, 1)
|
561
|
+
pat.add_color_stop_rgba(1, 0, 0, 0, 1)
|
562
|
+
|
563
|
+
fill pat
|
564
|
+
}
|
565
|
+
}
|
566
|
+
}.show
|
567
|
+
```
|
568
|
+
|
569
|
+
![Gradient](/screenshots/glimmer-dsl-gtk-mac-cairo-gradient.png)
|
570
|
+
|
571
|
+
### Image
|
572
|
+
|
573
|
+
[samples/cairo/image.rb](/samples/cairo/image.rb)
|
574
|
+
|
575
|
+
```ruby
|
576
|
+
require 'glimmer-dsl-gtk'
|
577
|
+
|
578
|
+
include Glimmer
|
579
|
+
|
580
|
+
window {
|
581
|
+
title 'Image'
|
582
|
+
default_size 256, 256
|
583
|
+
|
584
|
+
drawing_area {
|
585
|
+
paint 242.25, 242.25, 242.25
|
586
|
+
|
587
|
+
image = Cairo::ImageSurface.from_png(File.expand_path(File.join('..', '..', 'images', 'breaking-blue-wave.png'), __dir__))
|
588
|
+
w = image.width
|
589
|
+
h = image.height
|
590
|
+
|
591
|
+
translate 128.0, 128.0
|
592
|
+
rotate 45*Math::PI/180
|
593
|
+
scale 256.0/w, 256.0/h
|
594
|
+
translate -0.5*w, -0.5*h
|
595
|
+
|
596
|
+
paint image, 0, 0
|
597
|
+
}
|
598
|
+
}.show
|
599
|
+
```
|
600
|
+
|
601
|
+
![Image](/screenshots/glimmer-dsl-gtk-mac-cairo-image.png)
|
602
|
+
|
603
|
+
### Image Gradient
|
604
|
+
|
605
|
+
[samples/cairo/image_gradient.rb](/samples/cairo/image_gradient.rb)
|
606
|
+
|
607
|
+
```ruby
|
608
|
+
require 'glimmer-dsl-gtk'
|
609
|
+
|
610
|
+
include Glimmer
|
611
|
+
|
612
|
+
window {
|
613
|
+
title 'Image Gradient'
|
614
|
+
default_size 256, 256
|
615
|
+
|
616
|
+
drawing_area {
|
617
|
+
paint 242.25, 242.25, 242.25
|
618
|
+
|
619
|
+
image = Cairo::ImageSurface.from_png(File.expand_path(File.join('..', '..', 'images', 'breaking-blue-wave.png'), __dir__))
|
620
|
+
w = image.width
|
621
|
+
h = image.height
|
622
|
+
|
623
|
+
# Load the image as a surface pattern
|
624
|
+
pattern = Cairo::SurfacePattern.new(image)
|
625
|
+
pattern.extend = Cairo::EXTEND_REPEAT
|
626
|
+
|
627
|
+
# Set up the scale matrix
|
628
|
+
pattern.matrix = Cairo::Matrix.scale(w/256.0 * 5.0, h/256.0 * 5.0)
|
629
|
+
|
630
|
+
rectangle(0, 0, 256, 256) {
|
631
|
+
translate 128.0, 128.0
|
632
|
+
rotate Math::PI / 4
|
633
|
+
scale 1/Math.sqrt(2), 1/Math.sqrt(2)
|
634
|
+
translate -128.0, -128.0
|
635
|
+
|
636
|
+
fill pattern
|
637
|
+
}
|
638
|
+
}
|
639
|
+
}.show
|
640
|
+
```
|
641
|
+
|
642
|
+
![Image Gradient](/screenshots/glimmer-dsl-gtk-mac-cairo-image-gradient.png)
|
643
|
+
|
644
|
+
### Multi Segment Caps
|
645
|
+
|
646
|
+
[samples/cairo/multi_segment_caps.rb](/samples/cairo/multi_segment_caps.rb)
|
647
|
+
|
648
|
+
```ruby
|
649
|
+
require 'glimmer-dsl-gtk'
|
650
|
+
|
651
|
+
include Glimmer
|
652
|
+
|
653
|
+
window {
|
654
|
+
title 'Multi Segment Caps'
|
655
|
+
default_size 256, 256
|
656
|
+
|
657
|
+
drawing_area {
|
658
|
+
paint 242.25, 242.25, 242.25
|
659
|
+
|
660
|
+
path {
|
661
|
+
move_to 50.0, 75.0
|
662
|
+
line_to 200.0, 75.0
|
663
|
+
|
664
|
+
move_to 50.0, 125.0
|
665
|
+
line_to 200.0, 125.0
|
666
|
+
|
667
|
+
move_to 50.0, 175.0
|
668
|
+
line_to 200.0, 175.0
|
669
|
+
|
670
|
+
line_width 30
|
671
|
+
line_cap Cairo::LINE_CAP_ROUND
|
672
|
+
stroke 0, 0, 0
|
673
|
+
}
|
674
|
+
}
|
675
|
+
}.show
|
676
|
+
```
|
677
|
+
|
678
|
+
![Multi Segment Caps](/screenshots/glimmer-dsl-gtk-mac-cairo-multi-segment-caps.png)
|
679
|
+
|
680
|
+
### Rounded Rectangle
|
681
|
+
|
682
|
+
[samples/cairo/rounded_rectangle.rb](/samples/cairo/rounded_rectangle.rb)
|
683
|
+
|
684
|
+
```ruby
|
685
|
+
require 'glimmer-dsl-gtk'
|
686
|
+
|
687
|
+
include Glimmer
|
688
|
+
|
689
|
+
window {
|
690
|
+
title 'Rounded Rectangle'
|
691
|
+
default_size 256, 256
|
692
|
+
|
693
|
+
drawing_area {
|
694
|
+
paint 242.25, 242.25, 242.25
|
695
|
+
|
696
|
+
path {
|
697
|
+
rounded_rectangle(25.6, 25.6, 204.8, 204.8, 20)
|
698
|
+
|
699
|
+
fill 127.5, 127.5, 255
|
700
|
+
line_width 10.0
|
701
|
+
stroke 127.5, 0, 0, 0.5
|
702
|
+
}
|
703
|
+
}
|
704
|
+
}.show
|
705
|
+
```
|
706
|
+
|
707
|
+
![Rounded Rectangle](/screenshots/glimmer-dsl-gtk-mac-cairo-rounded-rectangle.png)
|
708
|
+
|
709
|
+
### Set line cap
|
710
|
+
|
711
|
+
[samples/cairo/set_line_cap.rb](/samples/cairo/set_line_cap.rb)
|
712
|
+
|
713
|
+
```ruby
|
714
|
+
require 'glimmer-dsl-gtk'
|
715
|
+
|
716
|
+
include Glimmer
|
717
|
+
|
718
|
+
window {
|
719
|
+
title 'Set line cap'
|
720
|
+
default_size 256, 256
|
721
|
+
|
722
|
+
drawing_area {
|
723
|
+
paint 242.25, 242.25, 242.25
|
724
|
+
|
725
|
+
# The main code
|
726
|
+
path {
|
727
|
+
move_to 64.0, 50.0
|
728
|
+
line_to 64.0, 200.0
|
729
|
+
|
730
|
+
line_cap Cairo::LINE_CAP_BUTT # default
|
731
|
+
line_width 30
|
732
|
+
stroke 0, 0, 0
|
733
|
+
}
|
734
|
+
|
735
|
+
path {
|
736
|
+
move_to 128.0, 50.0
|
737
|
+
line_to 128.0, 200.0
|
738
|
+
|
739
|
+
line_cap Cairo::LINE_CAP_ROUND
|
740
|
+
line_width 30
|
741
|
+
stroke 0, 0, 0
|
742
|
+
}
|
743
|
+
|
744
|
+
path {
|
745
|
+
move_to 192.0, 50.0
|
746
|
+
line_to 192.0, 200.0
|
747
|
+
|
748
|
+
line_cap Cairo::LINE_CAP_SQUARE
|
749
|
+
line_width 30
|
750
|
+
stroke 0, 0, 0
|
751
|
+
}
|
752
|
+
|
753
|
+
# draw helping lines */
|
754
|
+
path {
|
755
|
+
move_to 64.0, 50.0
|
756
|
+
line_to 64.0, 200.0
|
757
|
+
move_to 128.0, 50.0
|
758
|
+
line_to 128.0, 200.0
|
759
|
+
move_to 192.0, 50.0
|
760
|
+
line_to 192.0, 200.0
|
761
|
+
|
762
|
+
line_width 2.56
|
763
|
+
stroke 255, 51, 51
|
764
|
+
}
|
765
|
+
}
|
766
|
+
}.show
|
767
|
+
```
|
768
|
+
|
769
|
+
![Set line cap](/screenshots/glimmer-dsl-gtk-mac-cairo-set-line-cap.png)
|
770
|
+
|
771
|
+
### Set line join
|
772
|
+
|
773
|
+
[samples/cairo/set_line_join.rb](/samples/cairo/set_line_join.rb)
|
774
|
+
|
775
|
+
```ruby
|
776
|
+
require 'glimmer-dsl-gtk'
|
777
|
+
|
778
|
+
include Glimmer
|
779
|
+
|
780
|
+
window {
|
781
|
+
title 'Set line join'
|
782
|
+
default_size 256, 256
|
783
|
+
|
784
|
+
drawing_area {
|
785
|
+
paint 242.25, 242.25, 242.25
|
786
|
+
|
787
|
+
# The main code
|
788
|
+
path {
|
789
|
+
move_to 76.8, 84.48
|
790
|
+
rel_line_to 51.2, -51.2
|
791
|
+
rel_line_to 51.2, 51.2
|
792
|
+
|
793
|
+
line_join Cairo::LINE_JOIN_MITER # default
|
794
|
+
line_width 40.96
|
795
|
+
stroke 0, 0, 0
|
796
|
+
}
|
797
|
+
|
798
|
+
path {
|
799
|
+
move_to 76.8, 161.28
|
800
|
+
rel_line_to 51.2, -51.2
|
801
|
+
rel_line_to 51.2, 51.2
|
802
|
+
|
803
|
+
line_join Cairo::LINE_JOIN_BEVEL
|
804
|
+
line_width 40.96
|
805
|
+
stroke 0, 0, 0
|
806
|
+
}
|
807
|
+
|
808
|
+
path {
|
809
|
+
move_to 76.8, 238.08
|
810
|
+
rel_line_to 51.2, -51.2
|
811
|
+
rel_line_to 51.2, 51.2
|
812
|
+
|
813
|
+
line_join Cairo::LINE_JOIN_ROUND
|
814
|
+
line_width 40.96
|
815
|
+
stroke 0, 0, 0
|
816
|
+
}
|
817
|
+
}
|
818
|
+
}.show
|
819
|
+
```
|
820
|
+
|
821
|
+
![Set line join](/screenshots/glimmer-dsl-gtk-mac-cairo-set-line-join.png)
|
822
|
+
|
308
823
|
## Girb (Glimmer IRB)
|
309
824
|
|
310
825
|
You can run the `girb` command (`bin/girb` if you cloned the project locally):
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/glimmer-dsl-gtk.gemspec
CHANGED
Binary file
|
Binary file
|
@@ -69,17 +69,46 @@ module Glimmer
|
|
69
69
|
@drawing_operations = []
|
70
70
|
end
|
71
71
|
|
72
|
+
def post_initialize_child(child)
|
73
|
+
child_paths << child if child.is_a?(Path)
|
74
|
+
end
|
75
|
+
|
76
|
+
def child_paths
|
77
|
+
@child_paths ||= []
|
78
|
+
end
|
79
|
+
|
72
80
|
def draw_shape(drawing_area_widget, cairo_context)
|
81
|
+
previous_matrix = cairo_context.matrix
|
82
|
+
apply_transforms(cairo_context, target: :shape)
|
73
83
|
cairo_context.new_path
|
74
84
|
@drawing_operations.each do |drawing_operation_details|
|
75
85
|
cairo_context.send(drawing_operation_details[0], *drawing_operation_details[1])
|
76
86
|
end
|
87
|
+
child_paths.each do |child|
|
88
|
+
cairo_context.new_sub_path
|
89
|
+
child.drawing_operations.each do |drawing_operation_details|
|
90
|
+
cairo_context.send(drawing_operation_details[0], *drawing_operation_details[1])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
cairo_context.set_matrix(previous_matrix)
|
77
94
|
end
|
78
95
|
|
79
96
|
def arc(*args)
|
80
97
|
@drawing_operations << [:arc, args]
|
81
98
|
end
|
82
99
|
|
100
|
+
def arc_negative(*args)
|
101
|
+
@drawing_operations << [:arc_negative, args]
|
102
|
+
end
|
103
|
+
|
104
|
+
def rectangle(*args)
|
105
|
+
@drawing_operations << [:rectangle, args]
|
106
|
+
end
|
107
|
+
|
108
|
+
def rounded_rectangle(*args)
|
109
|
+
@drawing_operations << [:rounded_rectangle, args]
|
110
|
+
end
|
111
|
+
|
83
112
|
def move_to(*args)
|
84
113
|
@drawing_operations << [:move_to, args]
|
85
114
|
end
|