glimmer-dsl-gtk 0.0.2 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +1072 -27
  4. data/VERSION +1 -1
  5. data/glimmer-dsl-gtk.gemspec +0 -0
  6. data/images/breaking-blue-wave.png +0 -0
  7. data/lib/glimmer/dsl/gtk/observe_expression.rb +35 -0
  8. data/lib/glimmer/gtk/shape/arc_negative.rb +70 -0
  9. data/lib/glimmer/gtk/shape/path.rb +33 -0
  10. data/lib/glimmer/gtk/shape/square.rb +76 -0
  11. data/lib/glimmer/gtk/shape.rb +56 -10
  12. data/lib/glimmer/gtk/transformable.rb +93 -0
  13. data/lib/glimmer/gtk/widget_proxy/drawing_area_proxy.rb +16 -0
  14. data/lib/glimmer/gtk/widget_proxy.rb +2 -2
  15. data/samples/cairo/arc.rb +44 -0
  16. data/samples/cairo/arc_negative.rb +44 -0
  17. data/samples/cairo/clip.rb +34 -0
  18. data/samples/cairo/clip_image.rb +28 -0
  19. data/samples/cairo/curve_to.rb +39 -0
  20. data/samples/cairo/dashes.rb +30 -0
  21. data/samples/cairo/fill_and_stroke2.rb +36 -0
  22. data/samples/cairo/fill_style.rb +43 -0
  23. data/samples/cairo/gradient.rb +31 -0
  24. data/samples/cairo/image.rb +23 -0
  25. data/samples/cairo/image_gradient.rb +32 -0
  26. data/samples/cairo/multi_segment_caps.rb +27 -0
  27. data/samples/cairo/rounded_rectangle.rb +20 -0
  28. data/samples/cairo/set_line_cap.rb +53 -0
  29. data/samples/cairo/set_line_join.rb +43 -0
  30. data/samples/elaborate/tetris/model/block.rb +48 -0
  31. data/samples/elaborate/tetris/model/game.rb +320 -0
  32. data/samples/elaborate/tetris/model/past_game.rb +39 -0
  33. data/samples/elaborate/tetris/model/tetromino.rb +329 -0
  34. data/samples/elaborate/tetris.rb +338 -0
  35. data/samples/hello/hello_drawing_area.rb +1 -3
  36. data/samples/hello/hello_drawing_area_manual.rb +20 -21
  37. metadata +29 -4
@@ -0,0 +1,39 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Curve to'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ x=25.6
13
+ y=128.0
14
+ x1=102.4
15
+ y1=230.4
16
+ x2=153.6
17
+ y2=25.6
18
+ x3=230.4
19
+ y3=128.0
20
+
21
+ path {
22
+ move_to x, y
23
+ curve_to x1, y1, x2, y2, x3, y3
24
+
25
+ line_width 10
26
+ stroke 0, 0, 0
27
+ }
28
+
29
+ path {
30
+ move_to x,y
31
+ line_to x1,y1
32
+ move_to x2,y2
33
+ line_to x3,y3
34
+
35
+ line_width 6
36
+ stroke 255, 51, 51, 0.6
37
+ }
38
+ }
39
+ }.show
@@ -0,0 +1,30 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Dashes'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ dashes = [ 50.0, # ink
13
+ 10.0, # skip
14
+ 10.0, # ink
15
+ 10.0 # skip
16
+ ]
17
+ offset = -50.0
18
+
19
+ path {
20
+ move_to 128.0, 25.6
21
+ line_to 230.4, 230.4
22
+ rel_line_to -102.4, 0.0
23
+ curve_to 51.2, 230.4, 51.2, 128.0, 128.0, 128.0
24
+
25
+ line_width 10
26
+ dash dashes, offset
27
+ stroke 0, 0, 0
28
+ }
29
+ }
30
+ }.show
@@ -0,0 +1,36 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Fill and Stroke 2'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ path {
13
+ move_to 128.0, 25.6
14
+ line_to 230.4, 230.4
15
+ rel_line_to -102.4, 0.0
16
+ curve_to 51.2, 230.4, 51.2, 128.0, 128.0, 128.0
17
+ close_path
18
+
19
+ fill 0, 0, 255
20
+ stroke 0, 0, 0
21
+ line_width 10
22
+ }
23
+
24
+ path {
25
+ move_to 64.0, 25.6
26
+ rel_line_to 51.2, 51.2
27
+ rel_line_to -51.2, 51.2
28
+ rel_line_to -51.2, -51.2
29
+ close_path
30
+
31
+ fill 0, 0, 255
32
+ stroke 0, 0, 0
33
+ line_width 10
34
+ }
35
+ }
36
+ }.show
@@ -0,0 +1,43 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Fill Style'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ path {
13
+ rectangle 12, 12, 232, 70
14
+ path { # sub-path
15
+ arc 64, 64, 40, 0, 2*Math::PI
16
+ }
17
+ path { # sub-path
18
+ arc_negative 192, 64, 40, 0, -2*Math::PI
19
+ }
20
+
21
+ fill_rule Cairo::FILL_RULE_EVEN_ODD
22
+ line_width 6
23
+ fill 0, 178.5, 0
24
+ stroke 0, 0, 0
25
+ }
26
+
27
+ path {
28
+ rectangle 12, 12, 232, 70
29
+ path { # sub-path
30
+ arc 64, 64, 40, 0, 2*Math::PI
31
+ }
32
+ path { # sub-path
33
+ arc_negative 192, 64, 40, 0, -2*Math::PI
34
+ }
35
+
36
+ translate 0, 128
37
+ fill_rule Cairo::FILL_RULE_WINDING
38
+ line_width 6
39
+ fill 0, 0, 229.5
40
+ stroke 0, 0, 0
41
+ }
42
+ }
43
+ }.show
@@ -0,0 +1,31 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Gradient'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ # Create the Linear Pattern
13
+ rectangle(0, 0, 256, 256) {
14
+ pat = Cairo::LinearPattern.new(0.0, 0.0, 0.0, 256.0)
15
+ pat.add_color_stop_rgba(1, 0, 0, 0, 1)
16
+ pat.add_color_stop_rgba(0, 1, 1, 1, 1)
17
+
18
+ fill pat
19
+ }
20
+
21
+ # Create the radial pattern
22
+ arc(128.0, 128.0, 76.8, 0, 2 * Math::PI) {
23
+ pat = Cairo::RadialPattern.new(115.2, 102.4, 25.6,
24
+ 102.4, 102.4, 128.0)
25
+ pat.add_color_stop_rgba(0, 1, 1, 1, 1)
26
+ pat.add_color_stop_rgba(1, 0, 0, 0, 1)
27
+
28
+ fill pat
29
+ }
30
+ }
31
+ }.show
@@ -0,0 +1,23 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Image'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ image = Cairo::ImageSurface.from_png(File.expand_path(File.join('..', '..', 'images', 'breaking-blue-wave.png'), __dir__))
13
+ w = image.width
14
+ h = image.height
15
+
16
+ translate 128.0, 128.0
17
+ rotate 45*Math::PI/180
18
+ scale 256.0/w, 256.0/h
19
+ translate -0.5*w, -0.5*h
20
+
21
+ paint image, 0, 0
22
+ }
23
+ }.show
@@ -0,0 +1,32 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Image Gradient'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ image = Cairo::ImageSurface.from_png(File.expand_path(File.join('..', '..', 'images', 'breaking-blue-wave.png'), __dir__))
13
+ w = image.width
14
+ h = image.height
15
+
16
+ # Load the image as a surface pattern
17
+ pattern = Cairo::SurfacePattern.new(image)
18
+ pattern.extend = Cairo::EXTEND_REPEAT
19
+
20
+ # Set up the scale matrix
21
+ pattern.matrix = Cairo::Matrix.scale(w/256.0 * 5.0, h/256.0 * 5.0)
22
+
23
+ rectangle(0, 0, 256, 256) {
24
+ translate 128.0, 128.0
25
+ rotate Math::PI / 4
26
+ scale 1/Math.sqrt(2), 1/Math.sqrt(2)
27
+ translate -128.0, -128.0
28
+
29
+ fill pattern
30
+ }
31
+ }
32
+ }.show
@@ -0,0 +1,27 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Multi Segment Caps'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ path {
13
+ move_to 50.0, 75.0
14
+ line_to 200.0, 75.0
15
+
16
+ move_to 50.0, 125.0
17
+ line_to 200.0, 125.0
18
+
19
+ move_to 50.0, 175.0
20
+ line_to 200.0, 175.0
21
+
22
+ line_width 30
23
+ line_cap Cairo::LINE_CAP_ROUND
24
+ stroke 0, 0, 0
25
+ }
26
+ }
27
+ }.show
@@ -0,0 +1,20 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Rounded Rectangle'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ path {
13
+ rounded_rectangle(25.6, 25.6, 204.8, 204.8, 20)
14
+
15
+ fill 127.5, 127.5, 255
16
+ line_width 10.0
17
+ stroke 127.5, 0, 0, 0.5
18
+ }
19
+ }
20
+ }.show
@@ -0,0 +1,53 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Set line cap'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ # The main code
13
+ path {
14
+ move_to 64.0, 50.0
15
+ line_to 64.0, 200.0
16
+
17
+ line_cap Cairo::LINE_CAP_BUTT # default
18
+ line_width 30
19
+ stroke 0, 0, 0
20
+ }
21
+
22
+ path {
23
+ move_to 128.0, 50.0
24
+ line_to 128.0, 200.0
25
+
26
+ line_cap Cairo::LINE_CAP_ROUND
27
+ line_width 30
28
+ stroke 0, 0, 0
29
+ }
30
+
31
+ path {
32
+ move_to 192.0, 50.0
33
+ line_to 192.0, 200.0
34
+
35
+ line_cap Cairo::LINE_CAP_SQUARE
36
+ line_width 30
37
+ stroke 0, 0, 0
38
+ }
39
+
40
+ # draw helping lines */
41
+ path {
42
+ move_to 64.0, 50.0
43
+ line_to 64.0, 200.0
44
+ move_to 128.0, 50.0
45
+ line_to 128.0, 200.0
46
+ move_to 192.0, 50.0
47
+ line_to 192.0, 200.0
48
+
49
+ line_width 2.56
50
+ stroke 255, 51, 51
51
+ }
52
+ }
53
+ }.show
@@ -0,0 +1,43 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Set line join'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ # The main code
13
+ path {
14
+ move_to 76.8, 84.48
15
+ rel_line_to 51.2, -51.2
16
+ rel_line_to 51.2, 51.2
17
+
18
+ line_join Cairo::LINE_JOIN_MITER # default
19
+ line_width 40.96
20
+ stroke 0, 0, 0
21
+ }
22
+
23
+ path {
24
+ move_to 76.8, 161.28
25
+ rel_line_to 51.2, -51.2
26
+ rel_line_to 51.2, 51.2
27
+
28
+ line_join Cairo::LINE_JOIN_BEVEL
29
+ line_width 40.96
30
+ stroke 0, 0, 0
31
+ }
32
+
33
+ path {
34
+ move_to 76.8, 238.08
35
+ rel_line_to 51.2, -51.2
36
+ rel_line_to 51.2, 51.2
37
+
38
+ line_join Cairo::LINE_JOIN_ROUND
39
+ line_width 40.96
40
+ stroke 0, 0, 0
41
+ }
42
+ }
43
+ }.show
@@ -0,0 +1,48 @@
1
+ # Copyright (c) 2021-2022 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
+ class Tetris
23
+ module Model
24
+ class Block
25
+ COLOR_CLEAR = [255, 255, 255]
26
+
27
+ attr_accessor :color
28
+
29
+ # Initializes with color. Default color (gray) signifies an empty block
30
+ def initialize(color = COLOR_CLEAR)
31
+ @color = color
32
+ end
33
+
34
+ # Clears block color. `quietly` option indicates if it should not notify observers by setting value quietly via variable not attribute writer.
35
+ def clear
36
+ self.color = COLOR_CLEAR unless self.color == COLOR_CLEAR
37
+ end
38
+
39
+ def clear?
40
+ self.color == COLOR_CLEAR
41
+ end
42
+
43
+ def occupied?
44
+ !clear?
45
+ end
46
+ end
47
+ end
48
+ end