glimmer-dsl-gtk 0.0.4 → 0.0.5

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: 13f25c4ca569b9dd667c4d87e2e175d9c953f9e613ab572cffda63f8cb181fb1
4
- data.tar.gz: 4b28c418c1957467b0eaa9de2dbbd03cf9e63542a3e3d6425c6d101c04f90c09
3
+ metadata.gz: 24b62b2f4e0a04f84595c76365e2fb324d1b94dcd956e185b5a0f3f20665f333
4
+ data.tar.gz: 87363190b99d77589cf76be2a9035d77313a3cc64c3e431c0ec64dd0cb8f6c84
5
5
  SHA512:
6
- metadata.gz: 62541e82fbb67f300bee346c685942a24c98a93662830021d75b4c4fe6b4e0eba0ca4ad048f745f54b051d52e990d9d3220c551d47cb33f163d9c3c9812d3bce
7
- data.tar.gz: 7a0af395ce5e7ed8da206052341dc98ef7a4eb0d967413bdb9deb21f15647a07713fea1b0fca1296acc6bff46d96251ff2a9fb0a9962f34383328f36e041560a
6
+ metadata.gz: cff0baef7fb9455823af170bb63bee5059b297741b1994024d7c99c9140d77c5b13ac27e06fb1861561742da3f09d74513eefe46d64e893856f938f829749bf0
7
+ data.tar.gz: 83c024c42ecbaa1928c7909d31bbcf43ead432a1b5c4852909511a155668935c2ccbd18f819082eeaacc2a84000a4b88d0386e5b795b7d2e670fae9e11072362
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.5
4
+
5
+ - Support `drawing_area#paint(red, green, blue)` operation to set the initial `drawing_area` paint color base
6
+ - Support `arc` as an operation inside `path` in Cairo declarative shape syntax
7
+ - Support `arc_negative` cairo graphics shape
8
+ - Support cairo graphics shape `clip`
9
+
3
10
  ## 0.0.4
4
11
 
5
12
  - Tetris Menu Bar
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.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.5
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.4'
83
+ gem 'glimmer-dsl-gtk', '~> 0.0.5'
84
84
  ```
85
85
 
86
86
  And, then run:
@@ -136,7 +136,7 @@ SomeGlimmerApplication.new.launch
136
136
  - Properties: All GTK widget properties can be set via lowercase underscored names (without the 'set_' prefix) nested under widget keywords (e.g. `window {title 'Hello, World'}` sets `title` property of `window`)
137
137
  - Signals: All GTK signals can be wired with `on(signal) { ... }` syntax (e.g. `on(:activate) { do_something }`)
138
138
 
139
- #### MVC Observer Pattern
139
+ ### MVC Observer Pattern
140
140
 
141
141
  In Smalltalk-MVC ([Model View Controller](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) Architectural Pattern), the View is an active View that observes the Model for changes and updates itself.
142
142
 
@@ -148,6 +148,163 @@ The model is automatically enhanced as an `Glimmer::DataBinding::ObservableModel
148
148
 
149
149
  Note that it is usually recommended to observe external model objects (not `self`), but `self` is OK in very simple cases or presentation-related attributes only.
150
150
 
151
+ ### Declarative Cairo Graphics
152
+
153
+ [Cairo](https://www.cairographics.org/) is the engine behind drawing arbitrary 2D geometric shapes in [GTK](https://www.gtk.org/).
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.
156
+
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
+
159
+ ### Arc
160
+
161
+ Example (you may copy/paste in [`girb`](#girb-glimmer-irb))
162
+
163
+ ```ruby
164
+ require 'glimmer-dsl-gtk'
165
+
166
+ include Glimmer
167
+
168
+ window {
169
+ title 'Hello, Drawing Area!'
170
+ default_size 256, 256
171
+
172
+ drawing_area {
173
+ # Surface Paint
174
+ paint 242.25, 242.25, 242.25
175
+
176
+ # Set up the parameters
177
+ xc = 128.0
178
+ yc = 128.0
179
+ radius = 100.0
180
+ angle1 = 45.0 * (Math::PI/180.0) # angles are specified
181
+ angle2 = 180.0 * (Math::PI/180.0) # in radians
182
+
183
+ # The main arc
184
+ arc(xc, yc, radius, angle1, angle2) {
185
+ stroke 0, 0, 0
186
+ line_width 10
187
+ }
188
+
189
+ # Draw helping lines
190
+
191
+ # First, the circle at the centre
192
+ arc(xc, yc, 10.0, 0, 2*Math::PI) {
193
+ fill 255, 51, 51, 0.6
194
+ }
195
+
196
+ # Then, the lines reaching out
197
+ path {
198
+ arc xc, yc, radius, angle1, angle1
199
+ line_to xc, yc
200
+ arc xc, yc, radius, angle2, angle2
201
+ line_to xc, yc
202
+
203
+ stroke 255, 51, 51, 0.6
204
+ line_width 6
205
+ }
206
+ }
207
+ }.show
208
+ ```
209
+
210
+ ![Arc](/screenshots/glimmer-dsl-gtk-mac-cairo-arc.png)
211
+
212
+ ### Arc Negative
213
+
214
+ Example (you may copy/paste in [`girb`](#girb-glimmer-irb))
215
+
216
+ ```ruby
217
+ require 'glimmer-dsl-gtk'
218
+
219
+ include Glimmer
220
+
221
+ window {
222
+ title 'Arc Negative'
223
+ default_size 256, 256
224
+
225
+ drawing_area {
226
+ # Surface Paint
227
+ paint 255, 255, 255
228
+
229
+ # Set up the parameters
230
+ xc = 128.0
231
+ yc = 128.0
232
+ radius = 100.0
233
+ angle1 = 45.0 * (Math::PI/180.0) # angles are specified
234
+ angle2 = 180.0 * (Math::PI/180.0) # in radians
235
+
236
+ # The main negative arc
237
+ arc_negative(xc, yc, radius, angle1, angle2) {
238
+ stroke 0, 0, 0
239
+ line_width 10
240
+ }
241
+
242
+ # Draw helping lines
243
+
244
+ # First, the circle at the centre
245
+ arc(xc, yc, 10.0, 0, 2*Math::PI) {
246
+ fill 255, 51, 51, 0.6
247
+ }
248
+
249
+ # Then, the lines reaching out
250
+ path {
251
+ arc(xc, yc, radius, angle1, angle1)
252
+ line_to(xc, yc)
253
+ arc(xc, yc, radius, angle2, angle2)
254
+ line_to(xc, yc)
255
+
256
+ stroke 255, 51, 51, 0.6
257
+ line_width 6
258
+ }
259
+ }
260
+ }.show
261
+ ```
262
+
263
+ ![Arc Negative](/screenshots/glimmer-dsl-gtk-mac-cairo-arc-negative.png)
264
+
265
+ ### Clip
266
+
267
+ Example (you may copy/paste in [`girb`](#girb-glimmer-irb))
268
+
269
+ ```ruby
270
+ require 'glimmer-dsl-gtk'
271
+
272
+ include Glimmer
273
+
274
+ window {
275
+ title 'Clip'
276
+ default_size 256, 256
277
+
278
+ drawing_area {
279
+ # Surface Paint
280
+ paint 255, 255, 255
281
+
282
+ # Designate arc as the clipping area
283
+ arc(128.0, 128.0, 76.8, 0, 2 * Math::PI) {
284
+ clip true
285
+ }
286
+
287
+ # Rectangle will get clipped by arc
288
+ rectangle(0, 0, 256, 256) {
289
+ fill 0, 0, 0
290
+ }
291
+
292
+ # Path will get clipped by arc
293
+ path {
294
+ move_to 0, 0
295
+ line_to 256, 256
296
+ move_to 256, 0
297
+ line_to 0, 256
298
+
299
+ stroke 0, 255, 0
300
+ line_width 10
301
+ }
302
+ }
303
+ }.show
304
+ ```
305
+
306
+ ![Clip](/screenshots/glimmer-dsl-gtk-mac-cairo-clip.png)
307
+
151
308
  ## Girb (Glimmer IRB)
152
309
 
153
310
  You can run the `girb` command (`bin/girb` if you cloned the project locally):
@@ -378,9 +535,7 @@ window {
378
535
  default_size 400, 400
379
536
 
380
537
  drawing_area {
381
- rectangle(0, 0, 400, 400) {
382
- fill 255, 255, 255
383
- }
538
+ paint 255, 255, 255
384
539
 
385
540
  arc(85, 85, 45, (Math::PI/180)*90, -(Math::PI/180)*90) {
386
541
  fill 255, 0, 0
@@ -492,61 +647,60 @@ window {
492
647
 
493
648
  drawing_area {
494
649
  on(:draw) do |drawing_area_widget, cairo_context|
495
- cairo_context.rectangle(0, 0, 400, 400)
496
- cairo_context.set_source_rgb(255, 255, 255)
497
- cairo_context.fill
650
+ cairo_context.set_source_rgb(255/255.0, 255/255.0, 255/255.0)
651
+ cairo_context.paint
498
652
 
499
653
  cairo_context.arc(85, 85, 45, (Math::PI/180)*90, -(Math::PI/180)*90)
500
654
  cairo_context.set_source_rgb(255, 0, 0)
501
655
  cairo_context.fill
502
656
 
503
657
  cairo_context.arc(85, 85, 45, (Math::PI/180)*90, -(Math::PI/180)*90)
504
- cairo_context.set_source_rgb(0, 128, 255)
658
+ cairo_context.set_source_rgb(0, 128/255.0, 255/255.0)
505
659
  cairo_context.set_line_width(3)
506
660
  cairo_context.stroke
507
661
 
508
662
  cairo_context.arc(85, 185, 45, (Math::PI/180)*100, -(Math::PI/180)*30)
509
- cairo_context.set_source_rgb(255, 0, 0)
663
+ cairo_context.set_source_rgb(255/255.0, 0, 0)
510
664
  cairo_context.fill
511
665
 
512
666
  cairo_context.arc(85, 185, 45, (Math::PI/180)*100, -(Math::PI/180)*30)
513
- cairo_context.set_source_rgb(0, 128, 255)
667
+ cairo_context.set_source_rgb(0, 128/255.0, 255/255.0)
514
668
  cairo_context.set_line_width(3)
515
669
  cairo_context.stroke
516
670
 
517
671
  cairo_context.circle(85, 285, 45)
518
- cairo_context.set_source_rgb(255, 0, 0)
672
+ cairo_context.set_source_rgb(255/255.0, 0, 0)
519
673
  cairo_context.fill
520
674
 
521
675
  cairo_context.circle(85, 285, 45)
522
- cairo_context.set_source_rgb(0, 128, 255)
676
+ cairo_context.set_source_rgb(0, 128/255.0, 255/255.0)
523
677
  cairo_context.set_line_width(3)
524
678
  cairo_context.stroke
525
679
 
526
680
  cairo_context.rectangle(140, 40, 180, 90)
527
- cairo_context.set_source_rgb(255, 255, 0)
681
+ cairo_context.set_source_rgb(255/255.0, 255/255.0, 0)
528
682
  cairo_context.fill
529
683
 
530
684
  cairo_context.rectangle(140, 40, 180, 90)
531
- cairo_context.set_source_rgb(255, 0, 0)
685
+ cairo_context.set_source_rgb(255/255.0, 0, 0)
532
686
  cairo_context.set_line_width(3)
533
687
  cairo_context.stroke
534
688
 
535
689
  cairo_context.rounded_rectangle(140, 140, 180, 90, 30, 20)
536
- cairo_context.set_source_rgb(255, 255, 0)
690
+ cairo_context.set_source_rgb(255/255.0, 255/255.0, 0)
537
691
  cairo_context.fill
538
692
 
539
693
  cairo_context.rounded_rectangle(140, 140, 180, 90, 30, 20)
540
- cairo_context.set_source_rgb(255, 0, 0)
694
+ cairo_context.set_source_rgb(255/255.0, 0, 0)
541
695
  cairo_context.set_line_width(3)
542
696
  cairo_context.stroke
543
697
 
544
698
  cairo_context.triangle(140, 240, 320, 240, 230, 330)
545
- cairo_context.set_source_rgb(255, 255, 0)
699
+ cairo_context.set_source_rgb(255/255.0, 255/255.0, 0)
546
700
  cairo_context.fill
547
701
 
548
702
  cairo_context.triangle(140, 240, 320, 240, 230, 330)
549
- cairo_context.set_source_rgb(255, 0, 0)
703
+ cairo_context.set_source_rgb(255/255.0, 0, 0)
550
704
  cairo_context.set_line_width(3)
551
705
  cairo_context.stroke
552
706
 
@@ -555,7 +709,7 @@ window {
555
709
  cairo_context.curve_to 190, 60, 200, 80, 210, 70
556
710
  cairo_context.curve_to 240, 80, 250, 100, 260, 90
557
711
  cairo_context.curve_to 290, 90, 300, 110, 310, 100
558
- cairo_context.set_source_rgb(0, 255, 0)
712
+ cairo_context.set_source_rgb(0, 255/255.0, 0)
559
713
  cairo_context.fill
560
714
 
561
715
  cairo_context.new_path
@@ -563,7 +717,7 @@ window {
563
717
  cairo_context.curve_to 190, 60, 200, 80, 210, 70
564
718
  cairo_context.curve_to 240, 80, 250, 100, 260, 90
565
719
  cairo_context.curve_to 290, 90, 300, 110, 310, 100
566
- cairo_context.set_source_rgb(0, 0, 255)
720
+ cairo_context.set_source_rgb(0, 0, 255/255.0)
567
721
  cairo_context.stroke
568
722
 
569
723
  cairo_context.new_path
@@ -574,7 +728,7 @@ window {
574
728
  cairo_context.line_to 200, 200
575
729
  cairo_context.line_to 180, 170
576
730
  cairo_context.close_path
577
- cairo_context.set_source_rgb(0, 255, 0)
731
+ cairo_context.set_source_rgb(0, 255/255.0, 0)
578
732
  cairo_context.fill
579
733
 
580
734
  cairo_context.new_path
@@ -585,7 +739,7 @@ window {
585
739
  cairo_context.line_to 200, 200
586
740
  cairo_context.line_to 180, 170
587
741
  cairo_context.close_path
588
- cairo_context.set_source_rgb(0, 0, 255)
742
+ cairo_context.set_source_rgb(0, 0, 255/255.0)
589
743
  cairo_context.stroke
590
744
 
591
745
  cairo_context.new_path
@@ -596,7 +750,7 @@ window {
596
750
  cairo_context.line_to 200, 280
597
751
  cairo_context.line_to 180, 270
598
752
  cairo_context.close_path
599
- cairo_context.set_source_rgb(0, 255, 0)
753
+ cairo_context.set_source_rgb(0, 255/255.0, 0)
600
754
  cairo_context.fill
601
755
 
602
756
  cairo_context.new_path
@@ -607,7 +761,7 @@ window {
607
761
  cairo_context.line_to 200, 280
608
762
  cairo_context.line_to 180, 270
609
763
  cairo_context.close_path
610
- cairo_context.set_source_rgb(0, 0, 255)
764
+ cairo_context.set_source_rgb(0, 0, 255/255.0)
611
765
  cairo_context.stroke
612
766
 
613
767
  cairo_context.new_path
@@ -617,7 +771,7 @@ window {
617
771
  cairo_context.line_to 220, 340
618
772
  cairo_context.line_to 200, 330
619
773
  cairo_context.line_to 180, 320
620
- cairo_context.set_source_rgb(0, 0, 255)
774
+ cairo_context.set_source_rgb(0, 0, 255/255.0)
621
775
  cairo_context.stroke
622
776
  end
623
777
  }
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
Binary file
@@ -0,0 +1,70 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # GNU LESSER GENERAL PUBLIC LICENSE
4
+ # Version 3, 29 June 2007
5
+ #
6
+ # Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
7
+ #
8
+ # Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
9
+ #
10
+ # This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
11
+ #
12
+ # 0. Additional Definitions.
13
+ # As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
14
+ #
15
+ # “The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
16
+ #
17
+ # An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
18
+ #
19
+ # A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
20
+ #
21
+ # The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
22
+ #
23
+ # The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
24
+ #
25
+ # 1. Exception to Section 3 of the GNU GPL.
26
+ # You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
27
+ #
28
+ # 2. Conveying Modified Versions.
29
+ # If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
30
+ #
31
+ # a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
32
+ # b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
33
+ # 3. Object Code Incorporating Material from Library Header Files.
34
+ # The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
35
+ #
36
+ # a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
37
+ # b) Accompany the object code with a copy of the GNU GPL and this license document.
38
+ # 4. Combined Works.
39
+ # You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
40
+ #
41
+ # a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
42
+ # b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
43
+ # c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
44
+ # d) Do one of the following:
45
+ # 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
46
+ # 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
47
+ # e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
48
+ # 5. Combined Libraries.
49
+ # You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
50
+ #
51
+ # a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
52
+ # b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
53
+ # 6. Revised Versions of the GNU Lesser General Public License.
54
+ # The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
55
+ #
56
+ # Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
57
+ #
58
+ # If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
59
+
60
+ module Glimmer
61
+ module Gtk
62
+ # Represents Gtk shape objects drawn on area widget, like rectangle, arc, and path
63
+ class Shape
64
+ class ArcNegative < Shape
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ Dir[File.expand_path("./#{File.basename(__FILE__, '.rb')}/*.rb", __dir__)].each {|f| require f}
@@ -75,6 +75,10 @@ module Glimmer
75
75
  cairo_context.send(drawing_operation_details[0], *drawing_operation_details[1])
76
76
  end
77
77
  end
78
+
79
+ def arc(*args)
80
+ @drawing_operations << [:arc, args]
81
+ end
78
82
 
79
83
  def move_to(*args)
80
84
  @drawing_operations << [:move_to, args]
@@ -102,6 +102,10 @@ module Glimmer
102
102
  end
103
103
  accumulator
104
104
  end
105
+
106
+ def normalize_one_based_color(rgb)
107
+ rgb.each_with_index.map {|single_color, i| i == 3 ? single_color : single_color / 255.0}
108
+ end
105
109
  end
106
110
 
107
111
  SHAPE_FILL_PROPERTIES = [:fill_rule]
@@ -109,7 +113,7 @@ module Glimmer
109
113
  SHAPE_GENERAL_PROPERTIES = [:matrix, :operator, :tolerance]
110
114
 
111
115
  attr_reader :parent, :args, :keyword, :block
112
- attr_accessor :fill, :stroke
116
+ attr_accessor :fill, :stroke, :clip
113
117
  attr_accessor *(SHAPE_FILL_PROPERTIES + SHAPE_STROKE_PROPERTIES + SHAPE_GENERAL_PROPERTIES)
114
118
  # TODO consider automatically setting attribute accessors by looking up set_xyz methods on cairo context
115
119
 
@@ -150,6 +154,11 @@ module Glimmer
150
154
  draw_shape(drawing_area_widget, cairo_context)
151
155
  draw_stroke(drawing_area_widget, cairo_context)
152
156
  end
157
+
158
+ if clip
159
+ draw_shape(drawing_area_widget, cairo_context)
160
+ draw_clip(drawing_area_widget, cairo_context)
161
+ end
153
162
  end
154
163
 
155
164
  # Invokes cairo_context#underscored_shape_class_name method by default
@@ -188,8 +197,15 @@ module Glimmer
188
197
  cairo_context.stroke
189
198
  end
190
199
 
200
+ def draw_clip(drawing_area_widget, cairo_context)
201
+ SHAPE_GENERAL_PROPERTIES.each do |property|
202
+ cairo_context.send("set_#{property}", send(property)) if send(property)
203
+ end
204
+ cairo_context.clip
205
+ end
206
+
191
207
  def normalize_one_based_color(rgb)
192
- rgb.each_with_index.map {|single_color, i| i == 3 ? single_color : single_color / 255.0}
208
+ self.class.normalize_one_based_color(rgb)
193
209
  end
194
210
 
195
211
  def respond_to?(method_name, include_private = false, &block)
@@ -74,6 +74,11 @@ module Glimmer
74
74
  def post_add_content
75
75
  super
76
76
  @gtk.signal_connect(:draw) do |drawing_area_widget, cairo_context|
77
+ if @paint
78
+ cairo_context.set_source_rgb(Shape.normalize_one_based_color(@paint))
79
+ cairo_context.paint
80
+ end
81
+
77
82
  shapes.each do |shape|
78
83
  shape.draw(drawing_area_widget, cairo_context)
79
84
  end
@@ -87,6 +92,10 @@ module Glimmer
87
92
  super
88
93
  end
89
94
  end
95
+
96
+ def paint(*args)
97
+ @paint = args
98
+ end
90
99
  end
91
100
  end
92
101
  end
@@ -7,9 +7,7 @@ window {
7
7
  default_size 400, 400
8
8
 
9
9
  drawing_area {
10
- rectangle(0, 0, 400, 400) {
11
- fill 255, 255, 255
12
- }
10
+ paint 255, 255, 255
13
11
 
14
12
  arc(85, 85, 45, (Math::PI/180)*90, -(Math::PI/180)*90) {
15
13
  fill 255, 0, 0
@@ -8,61 +8,60 @@ window {
8
8
 
9
9
  drawing_area {
10
10
  on(:draw) do |drawing_area_widget, cairo_context|
11
- cairo_context.rectangle(0, 0, 400, 400)
12
- cairo_context.set_source_rgb(255, 255, 255)
13
- cairo_context.fill
11
+ cairo_context.set_source_rgb(255/255.0, 255/255.0, 255/255.0)
12
+ cairo_context.paint
14
13
 
15
14
  cairo_context.arc(85, 85, 45, (Math::PI/180)*90, -(Math::PI/180)*90)
16
15
  cairo_context.set_source_rgb(255, 0, 0)
17
16
  cairo_context.fill
18
17
 
19
18
  cairo_context.arc(85, 85, 45, (Math::PI/180)*90, -(Math::PI/180)*90)
20
- cairo_context.set_source_rgb(0, 128, 255)
19
+ cairo_context.set_source_rgb(0, 128/255.0, 255/255.0)
21
20
  cairo_context.set_line_width(3)
22
21
  cairo_context.stroke
23
22
 
24
23
  cairo_context.arc(85, 185, 45, (Math::PI/180)*100, -(Math::PI/180)*30)
25
- cairo_context.set_source_rgb(255, 0, 0)
24
+ cairo_context.set_source_rgb(255/255.0, 0, 0)
26
25
  cairo_context.fill
27
26
 
28
27
  cairo_context.arc(85, 185, 45, (Math::PI/180)*100, -(Math::PI/180)*30)
29
- cairo_context.set_source_rgb(0, 128, 255)
28
+ cairo_context.set_source_rgb(0, 128/255.0, 255/255.0)
30
29
  cairo_context.set_line_width(3)
31
30
  cairo_context.stroke
32
31
 
33
32
  cairo_context.circle(85, 285, 45)
34
- cairo_context.set_source_rgb(255, 0, 0)
33
+ cairo_context.set_source_rgb(255/255.0, 0, 0)
35
34
  cairo_context.fill
36
35
 
37
36
  cairo_context.circle(85, 285, 45)
38
- cairo_context.set_source_rgb(0, 128, 255)
37
+ cairo_context.set_source_rgb(0, 128/255.0, 255/255.0)
39
38
  cairo_context.set_line_width(3)
40
39
  cairo_context.stroke
41
40
 
42
41
  cairo_context.rectangle(140, 40, 180, 90)
43
- cairo_context.set_source_rgb(255, 255, 0)
42
+ cairo_context.set_source_rgb(255/255.0, 255/255.0, 0)
44
43
  cairo_context.fill
45
44
 
46
45
  cairo_context.rectangle(140, 40, 180, 90)
47
- cairo_context.set_source_rgb(255, 0, 0)
46
+ cairo_context.set_source_rgb(255/255.0, 0, 0)
48
47
  cairo_context.set_line_width(3)
49
48
  cairo_context.stroke
50
49
 
51
50
  cairo_context.rounded_rectangle(140, 140, 180, 90, 30, 20)
52
- cairo_context.set_source_rgb(255, 255, 0)
51
+ cairo_context.set_source_rgb(255/255.0, 255/255.0, 0)
53
52
  cairo_context.fill
54
53
 
55
54
  cairo_context.rounded_rectangle(140, 140, 180, 90, 30, 20)
56
- cairo_context.set_source_rgb(255, 0, 0)
55
+ cairo_context.set_source_rgb(255/255.0, 0, 0)
57
56
  cairo_context.set_line_width(3)
58
57
  cairo_context.stroke
59
58
 
60
59
  cairo_context.triangle(140, 240, 320, 240, 230, 330)
61
- cairo_context.set_source_rgb(255, 255, 0)
60
+ cairo_context.set_source_rgb(255/255.0, 255/255.0, 0)
62
61
  cairo_context.fill
63
62
 
64
63
  cairo_context.triangle(140, 240, 320, 240, 230, 330)
65
- cairo_context.set_source_rgb(255, 0, 0)
64
+ cairo_context.set_source_rgb(255/255.0, 0, 0)
66
65
  cairo_context.set_line_width(3)
67
66
  cairo_context.stroke
68
67
 
@@ -71,7 +70,7 @@ window {
71
70
  cairo_context.curve_to 190, 60, 200, 80, 210, 70
72
71
  cairo_context.curve_to 240, 80, 250, 100, 260, 90
73
72
  cairo_context.curve_to 290, 90, 300, 110, 310, 100
74
- cairo_context.set_source_rgb(0, 255, 0)
73
+ cairo_context.set_source_rgb(0, 255/255.0, 0)
75
74
  cairo_context.fill
76
75
 
77
76
  cairo_context.new_path
@@ -79,7 +78,7 @@ window {
79
78
  cairo_context.curve_to 190, 60, 200, 80, 210, 70
80
79
  cairo_context.curve_to 240, 80, 250, 100, 260, 90
81
80
  cairo_context.curve_to 290, 90, 300, 110, 310, 100
82
- cairo_context.set_source_rgb(0, 0, 255)
81
+ cairo_context.set_source_rgb(0, 0, 255/255.0)
83
82
  cairo_context.stroke
84
83
 
85
84
  cairo_context.new_path
@@ -90,7 +89,7 @@ window {
90
89
  cairo_context.line_to 200, 200
91
90
  cairo_context.line_to 180, 170
92
91
  cairo_context.close_path
93
- cairo_context.set_source_rgb(0, 255, 0)
92
+ cairo_context.set_source_rgb(0, 255/255.0, 0)
94
93
  cairo_context.fill
95
94
 
96
95
  cairo_context.new_path
@@ -101,7 +100,7 @@ window {
101
100
  cairo_context.line_to 200, 200
102
101
  cairo_context.line_to 180, 170
103
102
  cairo_context.close_path
104
- cairo_context.set_source_rgb(0, 0, 255)
103
+ cairo_context.set_source_rgb(0, 0, 255/255.0)
105
104
  cairo_context.stroke
106
105
 
107
106
  cairo_context.new_path
@@ -112,7 +111,7 @@ window {
112
111
  cairo_context.line_to 200, 280
113
112
  cairo_context.line_to 180, 270
114
113
  cairo_context.close_path
115
- cairo_context.set_source_rgb(0, 255, 0)
114
+ cairo_context.set_source_rgb(0, 255/255.0, 0)
116
115
  cairo_context.fill
117
116
 
118
117
  cairo_context.new_path
@@ -123,7 +122,7 @@ window {
123
122
  cairo_context.line_to 200, 280
124
123
  cairo_context.line_to 180, 270
125
124
  cairo_context.close_path
126
- cairo_context.set_source_rgb(0, 0, 255)
125
+ cairo_context.set_source_rgb(0, 0, 255/255.0)
127
126
  cairo_context.stroke
128
127
 
129
128
  cairo_context.new_path
@@ -133,7 +132,7 @@ window {
133
132
  cairo_context.line_to 220, 340
134
133
  cairo_context.line_to 200, 330
135
134
  cairo_context.line_to 180, 320
136
- cairo_context.set_source_rgb(0, 0, 255)
135
+ cairo_context.set_source_rgb(0, 0, 255/255.0)
137
136
  cairo_context.stroke
138
137
  end
139
138
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-gtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
@@ -170,6 +170,7 @@ files:
170
170
  - lib/glimmer/gtk.rb
171
171
  - lib/glimmer/gtk/shape.rb
172
172
  - lib/glimmer/gtk/shape/arc.rb
173
+ - lib/glimmer/gtk/shape/arc_negative.rb
173
174
  - lib/glimmer/gtk/shape/circle.rb
174
175
  - lib/glimmer/gtk/shape/path.rb
175
176
  - lib/glimmer/gtk/shape/polygon.rb