glimmer-dsl-gtk 0.0.5 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.9
Binary file
@@ -69,17 +69,68 @@ 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
 
96
+ # TODO look into a way to generalize the declaration of the methods below (or perform code reuse)
97
+
98
+ def new_sub_path(*args)
99
+ @drawing_operations << [:new_sub_path, args]
100
+ end
101
+
79
102
  def arc(*args)
80
103
  @drawing_operations << [:arc, args]
81
104
  end
82
105
 
106
+ def arc_negative(*args)
107
+ @drawing_operations << [:arc_negative, args]
108
+ end
109
+
110
+ def rectangle(*args)
111
+ @drawing_operations << [:rectangle, args]
112
+ end
113
+
114
+ def rounded_rectangle(*args)
115
+ @drawing_operations << [:rounded_rectangle, args]
116
+ end
117
+
118
+ def text_path(*args)
119
+ @drawing_operations << [:text_path, args]
120
+ end
121
+
122
+ def show_text(*args)
123
+ @drawing_operations << [:show_text, args]
124
+ end
125
+
126
+ def glyph_path(*args)
127
+ @drawing_operations << [:text_path, args]
128
+ end
129
+
130
+ def show_glyphs(*args)
131
+ @drawing_operations << [:show_text, args]
132
+ end
133
+
83
134
  def move_to(*args)
84
135
  @drawing_operations << [:move_to, args]
85
136
  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
  # Represents Gtk shape objects drawn on area widget, like rectangle, arc, and path
@@ -103,18 +105,33 @@ 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
- SHAPE_STROKE_PROPERTIES = [:dash, :font_face, :font_matrix, :font_options, :font_size, :line_cap, :line_join, :line_width, :miter_limit, :scaled_font]
128
+ SHAPE_STROKE_PROPERTIES = [:dash, :line_cap, :line_join, :line_width, :miter_limit, :scaled_font]
113
129
  SHAPE_GENERAL_PROPERTIES = [:matrix, :operator, :tolerance]
130
+ SHAPE_FONT_PROPERTIES = [:font_face, :font_matrix, :font_options, :font_size]
114
131
 
115
132
  attr_reader :parent, :args, :keyword, :block
116
133
  attr_accessor :fill, :stroke, :clip
117
- attr_accessor *(SHAPE_FILL_PROPERTIES + SHAPE_STROKE_PROPERTIES + SHAPE_GENERAL_PROPERTIES)
134
+ attr_accessor *(SHAPE_FILL_PROPERTIES + SHAPE_STROKE_PROPERTIES + SHAPE_GENERAL_PROPERTIES + SHAPE_FONT_PROPERTIES)
118
135
  # TODO consider automatically setting attribute accessors by looking up set_xyz methods on cairo context
119
136
 
120
137
  def initialize(keyword, parent, args, &block)
@@ -146,16 +163,19 @@ module Glimmer
146
163
  # Subclasses must either implement draw_shape hook method or override this method directly
147
164
  def draw(drawing_area_widget, cairo_context)
148
165
  if fill
166
+ draw_font(drawing_area_widget, cairo_context)
149
167
  draw_shape(drawing_area_widget, cairo_context)
150
168
  draw_fill(drawing_area_widget, cairo_context)
151
169
  end
152
170
 
153
171
  if stroke
172
+ draw_font(drawing_area_widget, cairo_context)
154
173
  draw_shape(drawing_area_widget, cairo_context)
155
174
  draw_stroke(drawing_area_widget, cairo_context)
156
175
  end
157
176
 
158
177
  if clip
178
+ draw_font(drawing_area_widget, cairo_context)
159
179
  draw_shape(drawing_area_widget, cairo_context)
160
180
  draw_clip(drawing_area_widget, cairo_context)
161
181
  end
@@ -166,46 +186,60 @@ module Glimmer
166
186
  #
167
187
  # Subclasses can override
168
188
  def draw_shape(drawing_area_widget, cairo_context)
189
+ previous_matrix = cairo_context.matrix
190
+ apply_transforms(cairo_context, target: :shape)
169
191
  class_symbol = self.class.name.split('::').last
170
192
  keyword = self.class.keyword(class_symbol)
171
193
  cairo_context.send(keyword, *args)
194
+ cairo_context.set_matrix(previous_matrix)
172
195
  end
173
196
 
174
197
  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
181
- (SHAPE_FILL_PROPERTIES + SHAPE_GENERAL_PROPERTIES).each do |property|
182
- cairo_context.send("set_#{property}", send(property)) if send(property)
198
+ previous_matrix = cairo_context.matrix
199
+ apply_transforms(cairo_context, target: :fill)
200
+ self.class.set_source_dynamically(cairo_context, fill)
201
+ (SHAPE_GENERAL_PROPERTIES + SHAPE_FILL_PROPERTIES).each do |property|
202
+ apply_property(cairo_context, property)
183
203
  end
184
204
  cairo_context.fill
205
+ cairo_context.set_matrix(previous_matrix)
185
206
  end
186
207
 
187
- 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)
208
+ def draw_font(drawing_area_widget, cairo_context)
209
+ SHAPE_FONT_PROPERTIES.each do |property|
210
+ apply_property(cairo_context, property)
193
211
  end
194
- (SHAPE_STROKE_PROPERTIES + SHAPE_GENERAL_PROPERTIES).each do |property|
195
- cairo_context.send("set_#{property}", send(property)) if send(property)
212
+ end
213
+
214
+ def draw_stroke(drawing_area_widget, cairo_context)
215
+ previous_matrix = cairo_context.matrix
216
+ apply_transforms(cairo_context, target: :stroke)
217
+ self.class.set_source_dynamically(cairo_context, stroke)
218
+ (SHAPE_GENERAL_PROPERTIES + SHAPE_STROKE_PROPERTIES).each do |property|
219
+ apply_property(cairo_context, property)
196
220
  end
197
221
  cairo_context.stroke
222
+ cairo_context.set_matrix(previous_matrix)
198
223
  end
199
224
 
200
225
  def draw_clip(drawing_area_widget, cairo_context)
226
+ previous_matrix = cairo_context.matrix
227
+ apply_transforms(cairo_context, target: :clip)
201
228
  SHAPE_GENERAL_PROPERTIES.each do |property|
202
- cairo_context.send("set_#{property}", send(property)) if send(property)
229
+ apply_property(cairo_context, property)
203
230
  end
204
231
  cairo_context.clip
232
+ cairo_context.set_matrix(previous_matrix)
205
233
  end
206
234
 
207
- def normalize_one_based_color(rgb)
208
- self.class.normalize_one_based_color(rgb)
235
+ def apply_property(cairo_context, property)
236
+ if send(property)
237
+ if property == :font_face
238
+ cairo_context.send("select_#{property}", *send(property))
239
+ else
240
+ cairo_context.send("set_#{property}", *send(property))
241
+ end
242
+ end
209
243
  end
210
244
 
211
245
  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|
@@ -147,7 +147,7 @@ module Glimmer
147
147
 
148
148
  # Subclasses may override to perform post initialization work on an added child (normally must also call super)
149
149
  def post_initialize_child(child)
150
- @gtk.add(child.gtk) if @gtk.respond_to?(:add)
150
+ @gtk.add(child.gtk) if @gtk.respond_to?(:add) # && child.keyword != 'menu' # TODO consider moving this code to a MenuProxy
151
151
  child.gtk&.show if child.gtk&.respond_to?(:show)
152
152
  end
153
153
 
@@ -193,8 +193,20 @@ module Glimmer
193
193
  end
194
194
 
195
195
  def normalize_args(args)
196
- args.map do |arg|
197
- arg.is_a?(WidgetProxy) ? arg.gtk : arg
196
+ if args.size == 1 && args.first.is_a?(Hash)
197
+ hash_arg = args.first
198
+ hash_arg = Hash[hash_arg.map do |key, value|
199
+ normalized_value = value.respond_to?(:gtk) ? value.gtk : value
200
+ [key, normalized_value]
201
+ end]
202
+ args[0] = hash_arg
203
+ args
204
+ elsif args.is_a?(Array)
205
+ args.map do |arg|
206
+ arg.is_a?(WidgetProxy) ? arg.gtk : arg
207
+ end
208
+ else
209
+ args
198
210
  end
199
211
  end
200
212
  end
@@ -0,0 +1,44 @@
1
+ require 'glimmer-dsl-gtk'
2
+
3
+ include Glimmer
4
+
5
+ window {
6
+ title 'Arc'
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,33 @@
1
+ require 'glimmer-dsl-gtk'
2
+ require 'net/http'
3
+
4
+ image_content = Net::HTTP.get(URI('https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-gtk/master/images/breaking-blue-wave.png'))
5
+ image_file = File.join(Dir.home, 'breaking-blue-wave.png')
6
+ File.write(image_file, image_content)
7
+
8
+ include Glimmer
9
+
10
+ window {
11
+ title 'Clip Image'
12
+ default_size 256, 256
13
+
14
+ drawing_area {
15
+ paint 242.25, 242.25, 242.25
16
+
17
+ arc(128.0, 128.0, 76.8, 0, 2 * Math::PI) {
18
+ clip true # designate arc as the clipping area
19
+ }
20
+
21
+ rectangle(0, 0, 256, 256) {
22
+ # Source image is from:
23
+ # - https://www.publicdomainpictures.net/en/view-image.php?image=7683&picture=breaking-blue-wave
24
+ # Converted to PNG before using it
25
+ image = Cairo::ImageSurface.from_png(image_file)
26
+ w = image.width
27
+ h = image.height
28
+
29
+ scale 256.0/w, 256.0/h, exclude: :shape # applies scale to fill source image only
30
+ fill image, 0, 0
31
+ }
32
+ }
33
+ }.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