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.
@@ -57,6 +57,8 @@
57
57
  #
58
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
59
 
60
+ require 'glimmer/gtk/transformable'
61
+
60
62
  module Glimmer
61
63
  module Gtk
62
64
  # Represents Gtk shape objects drawn on area widget, like rectangle, arc, and path
@@ -103,11 +105,25 @@ module Glimmer
103
105
  accumulator
104
106
  end
105
107
 
106
- def normalize_one_based_color(rgb)
108
+ def one_based_color_rgb(rgb)
109
+ return rgb if rgb.is_a?(Cairo::Pattern) || rgb.first.is_a?(Cairo::ImageSurface)
107
110
  rgb.each_with_index.map {|single_color, i| i == 3 ? single_color : single_color / 255.0}
108
111
  end
112
+
113
+ def set_source_dynamically(cairo_context, source_args)
114
+ source_args = one_based_color_rgb(source_args)
115
+ if source_args.is_a?(Cairo::Pattern) || source_args.first.is_a?(Cairo::ImageSurface)
116
+ cairo_context.set_source(*source_args)
117
+ elsif source_args.size == 3
118
+ cairo_context.set_source_rgb(*source_args)
119
+ elsif source_args.size == 4
120
+ cairo_context.set_source_rgba(*source_args)
121
+ end
122
+ end
109
123
  end
110
124
 
125
+ prepend Transformable
126
+
111
127
  SHAPE_FILL_PROPERTIES = [:fill_rule]
112
128
  SHAPE_STROKE_PROPERTIES = [:dash, :font_face, :font_matrix, :font_options, :font_size, :line_cap, :line_join, :line_width, :miter_limit, :scaled_font]
113
129
  SHAPE_GENERAL_PROPERTIES = [:matrix, :operator, :tolerance]
@@ -166,46 +182,44 @@ module Glimmer
166
182
  #
167
183
  # Subclasses can override
168
184
  def draw_shape(drawing_area_widget, cairo_context)
185
+ previous_matrix = cairo_context.matrix
186
+ apply_transforms(cairo_context, target: :shape)
169
187
  class_symbol = self.class.name.split('::').last
170
188
  keyword = self.class.keyword(class_symbol)
171
189
  cairo_context.send(keyword, *args)
190
+ cairo_context.set_matrix(previous_matrix)
172
191
  end
173
192
 
174
193
  def draw_fill(drawing_area_widget, cairo_context)
175
- the_fill = normalize_one_based_color(fill)
176
- if the_fill.size == 3
177
- cairo_context.set_source_rgb(*the_fill)
178
- elsif the_fill.size == 4
179
- cairo_context.set_source_rgba(*the_fill)
180
- end
194
+ previous_matrix = cairo_context.matrix
195
+ apply_transforms(cairo_context, target: :fill)
196
+ self.class.set_source_dynamically(cairo_context, fill)
181
197
  (SHAPE_FILL_PROPERTIES + SHAPE_GENERAL_PROPERTIES).each do |property|
182
- cairo_context.send("set_#{property}", send(property)) if send(property)
198
+ cairo_context.send("set_#{property}", *send(property)) if send(property)
183
199
  end
184
200
  cairo_context.fill
201
+ cairo_context.set_matrix(previous_matrix)
185
202
  end
186
203
 
187
204
  def draw_stroke(drawing_area_widget, cairo_context)
188
- the_stroke = normalize_one_based_color(stroke)
189
- if the_stroke.size == 3
190
- cairo_context.set_source_rgb(*the_stroke)
191
- elsif the_stroke.size == 4
192
- cairo_context.set_source_rgba(*the_stroke)
193
- end
205
+ previous_matrix = cairo_context.matrix
206
+ apply_transforms(cairo_context, target: :stroke)
207
+ self.class.set_source_dynamically(cairo_context, stroke)
194
208
  (SHAPE_STROKE_PROPERTIES + SHAPE_GENERAL_PROPERTIES).each do |property|
195
- cairo_context.send("set_#{property}", send(property)) if send(property)
209
+ cairo_context.send("set_#{property}", *send(property)) if send(property)
196
210
  end
197
211
  cairo_context.stroke
212
+ cairo_context.set_matrix(previous_matrix)
198
213
  end
199
214
 
200
215
  def draw_clip(drawing_area_widget, cairo_context)
216
+ previous_matrix = cairo_context.matrix
217
+ apply_transforms(cairo_context, target: :clip)
201
218
  SHAPE_GENERAL_PROPERTIES.each do |property|
202
- cairo_context.send("set_#{property}", send(property)) if send(property)
219
+ cairo_context.send("set_#{property}", *send(property)) if send(property)
203
220
  end
204
221
  cairo_context.clip
205
- end
206
-
207
- def normalize_one_based_color(rgb)
208
- self.class.normalize_one_based_color(rgb)
222
+ cairo_context.set_matrix(previous_matrix)
209
223
  end
210
224
 
211
225
  def respond_to?(method_name, include_private = false, &block)
@@ -0,0 +1,93 @@
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 transformable view elements like shapes and drawing_area
63
+ module Transformable
64
+ def initialize(keyword, parent, args, &block)
65
+ @transforms = []
66
+ super
67
+ end
68
+
69
+ # applies transform on target type (:shape, :drawing_area, :fill, :stroke, :clip)
70
+ def apply_transforms(cairo_context, target: )
71
+ @transforms.each do |transform|
72
+ operation = transform.first
73
+ args = transform.last.dup
74
+ options = args.pop
75
+ excluded_types = [options[:exclude]].flatten
76
+ cairo_context.send(operation, *args) if !excluded_types.include?(target)
77
+ end
78
+ end
79
+
80
+ def translate(x, y, options = {})
81
+ @transforms << [:translate, [x, y, options]]
82
+ end
83
+
84
+ def scale(x, y, options = {})
85
+ @transforms << [:scale, [x, y, options]]
86
+ end
87
+
88
+ def rotate(angle, options = {})
89
+ @transforms << [:rotate, [angle, options]]
90
+ end
91
+ end
92
+ end
93
+ end
@@ -57,6 +57,8 @@
57
57
  #
58
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
59
 
60
+ require 'glimmer/gtk/transformable'
61
+
60
62
  module Glimmer
61
63
  module Gtk
62
64
  class WidgetProxy
@@ -64,6 +66,8 @@ module Glimmer
64
66
  #
65
67
  # Follows the Proxy Design Pattern
66
68
  class DrawingAreaProxy < WidgetProxy
69
+ prepend Transformable
70
+
67
71
  attr_reader :shapes
68
72
 
69
73
  def initialize(keyword, parent, args, &block)
@@ -75,8 +79,11 @@ module Glimmer
75
79
  super
76
80
  @gtk.signal_connect(:draw) do |drawing_area_widget, cairo_context|
77
81
  if @paint
78
- cairo_context.set_source_rgb(Shape.normalize_one_based_color(@paint))
82
+ previous_matrix = cairo_context.matrix
83
+ apply_transforms(cairo_context, target: :drawing_area)
84
+ Shape.set_source_dynamically(cairo_context, @paint)
79
85
  cairo_context.paint
86
+ cairo_context.set_matrix(previous_matrix)
80
87
  end
81
88
 
82
89
  shapes.each do |shape|
@@ -0,0 +1,44 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Hello, Drawing Area!'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ # Surface Paint
11
+ paint 242.25, 242.25, 242.25
12
+
13
+ # Set up the parameters
14
+ xc = 128.0
15
+ yc = 128.0
16
+ radius = 100.0
17
+ angle1 = 45.0 * (Math::PI/180.0) # angles are specified
18
+ angle2 = 180.0 * (Math::PI/180.0) # in radians
19
+
20
+ # The main arc
21
+ arc(xc, yc, radius, angle1, angle2) {
22
+ stroke 0, 0, 0
23
+ line_width 10
24
+ }
25
+
26
+ # Draw helping lines
27
+
28
+ # First, the circle at the centre
29
+ arc(xc, yc, 10.0, 0, 2*Math::PI) {
30
+ fill 255, 51, 51, 0.6
31
+ }
32
+
33
+ # Then, the lines reaching out
34
+ path {
35
+ arc xc, yc, radius, angle1, angle1
36
+ line_to xc, yc
37
+ arc xc, yc, radius, angle2, angle2
38
+ line_to xc, yc
39
+
40
+ stroke 255, 51, 51, 0.6
41
+ line_width 6
42
+ }
43
+ }
44
+ }.show
@@ -0,0 +1,44 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Arc Negative'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ # Surface Paint
11
+ paint 255, 255, 255
12
+
13
+ # Set up the parameters
14
+ xc = 128.0
15
+ yc = 128.0
16
+ radius = 100.0
17
+ angle1 = 45.0 * (Math::PI/180.0) # angles are specified
18
+ angle2 = 180.0 * (Math::PI/180.0) # in radians
19
+
20
+ # The main negative arc
21
+ arc_negative(xc, yc, radius, angle1, angle2) {
22
+ stroke 0, 0, 0
23
+ line_width 10
24
+ }
25
+
26
+ # Draw helping lines
27
+
28
+ # First, the circle at the centre
29
+ arc(xc, yc, 10.0, 0, 2*Math::PI) {
30
+ fill 255, 51, 51, 0.6
31
+ }
32
+
33
+ # Then, the lines reaching out
34
+ path {
35
+ arc(xc, yc, radius, angle1, angle1)
36
+ line_to(xc, yc)
37
+ arc(xc, yc, radius, angle2, angle2)
38
+ line_to(xc, yc)
39
+
40
+ stroke 255, 51, 51, 0.6
41
+ line_width 6
42
+ }
43
+ }
44
+ }.show
@@ -0,0 +1,34 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Clip'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ # Surface Paint
11
+ paint 255, 255, 255
12
+
13
+ # Designate arc as the clipping area
14
+ arc(128.0, 128.0, 76.8, 0, 2 * Math::PI) {
15
+ clip true
16
+ }
17
+
18
+ # Rectangle will get clipped by arc
19
+ rectangle(0, 0, 256, 256) {
20
+ fill 0, 0, 0
21
+ }
22
+
23
+ # Path will get clipped by arc
24
+ path {
25
+ move_to 0, 0
26
+ line_to 256, 256
27
+ move_to 256, 0
28
+ line_to 0, 256
29
+
30
+ stroke 0, 255, 0
31
+ line_width 10
32
+ }
33
+ }
34
+ }.show
@@ -0,0 +1,28 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Clip Image'
7
+ default_size 256, 256
8
+
9
+ drawing_area {
10
+ paint 242.25, 242.25, 242.25
11
+
12
+ arc(128.0, 128.0, 76.8, 0, 2 * Math::PI) {
13
+ clip true # designate arc as the clipping area
14
+ }
15
+
16
+ rectangle(0, 0, 256, 256) {
17
+ # Source image is from:
18
+ # - https://www.publicdomainpictures.net/en/view-image.php?image=7683&picture=breaking-blue-wave
19
+ # Converted to PNG before using it
20
+ image = Cairo::ImageSurface.from_png(File.expand_path(File.join('..', '..', 'images', 'breaking-blue-wave.png'), __dir__))
21
+ w = image.width
22
+ h = image.height
23
+
24
+ scale 256.0/w, 256.0/h, exclude: :shape # applies scale to fill source image only
25
+ fill image, 0, 0
26
+ }
27
+ }
28
+ }.show
@@ -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