glimmer-dsl-gtk 0.0.3 → 0.0.7

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.3
1
+ 0.0.7
Binary file
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}
@@ -69,11 +69,66 @@ 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)
94
+ end
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
+
102
+ def arc(*args)
103
+ @drawing_operations << [:arc, args]
104
+ end
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]
77
132
  end
78
133
 
79
134
  def move_to(*args)
@@ -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
@@ -102,15 +104,34 @@ module Glimmer
102
104
  end
103
105
  accumulator
104
106
  end
107
+
108
+ def one_based_color_rgb(rgb)
109
+ return rgb if rgb.is_a?(Cairo::Pattern) || rgb.first.is_a?(Cairo::ImageSurface)
110
+ rgb.each_with_index.map {|single_color, i| i == 3 ? single_color : single_color / 255.0}
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
105
123
  end
106
124
 
125
+ prepend Transformable
126
+
107
127
  SHAPE_FILL_PROPERTIES = [:fill_rule]
108
- 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]
109
129
  SHAPE_GENERAL_PROPERTIES = [:matrix, :operator, :tolerance]
130
+ SHAPE_FONT_PROPERTIES = [:font_face, :font_matrix, :font_options, :font_size]
110
131
 
111
132
  attr_reader :parent, :args, :keyword, :block
112
- attr_accessor :fill, :stroke
113
- attr_accessor *(SHAPE_FILL_PROPERTIES + SHAPE_STROKE_PROPERTIES + SHAPE_GENERAL_PROPERTIES)
133
+ attr_accessor :fill, :stroke, :clip
134
+ attr_accessor *(SHAPE_FILL_PROPERTIES + SHAPE_STROKE_PROPERTIES + SHAPE_GENERAL_PROPERTIES + SHAPE_FONT_PROPERTIES)
114
135
  # TODO consider automatically setting attribute accessors by looking up set_xyz methods on cairo context
115
136
 
116
137
  def initialize(keyword, parent, args, &block)
@@ -142,14 +163,22 @@ module Glimmer
142
163
  # Subclasses must either implement draw_shape hook method or override this method directly
143
164
  def draw(drawing_area_widget, cairo_context)
144
165
  if fill
166
+ draw_font(drawing_area_widget, cairo_context)
145
167
  draw_shape(drawing_area_widget, cairo_context)
146
168
  draw_fill(drawing_area_widget, cairo_context)
147
169
  end
148
170
 
149
171
  if stroke
172
+ draw_font(drawing_area_widget, cairo_context)
150
173
  draw_shape(drawing_area_widget, cairo_context)
151
174
  draw_stroke(drawing_area_widget, cairo_context)
152
175
  end
176
+
177
+ if clip
178
+ draw_font(drawing_area_widget, cairo_context)
179
+ draw_shape(drawing_area_widget, cairo_context)
180
+ draw_clip(drawing_area_widget, cairo_context)
181
+ end
153
182
  end
154
183
 
155
184
  # Invokes cairo_context#underscored_shape_class_name method by default
@@ -157,39 +186,60 @@ module Glimmer
157
186
  #
158
187
  # Subclasses can override
159
188
  def draw_shape(drawing_area_widget, cairo_context)
189
+ previous_matrix = cairo_context.matrix
190
+ apply_transforms(cairo_context, target: :shape)
160
191
  class_symbol = self.class.name.split('::').last
161
192
  keyword = self.class.keyword(class_symbol)
162
193
  cairo_context.send(keyword, *args)
194
+ cairo_context.set_matrix(previous_matrix)
163
195
  end
164
196
 
165
197
  def draw_fill(drawing_area_widget, cairo_context)
166
- the_fill = normalize_one_based_color(fill)
167
- if the_fill.size == 3
168
- cairo_context.set_source_rgb(*the_fill)
169
- elsif the_fill.size == 4
170
- cairo_context.set_source_rgba(*the_fill)
171
- end
172
- (SHAPE_FILL_PROPERTIES + SHAPE_GENERAL_PROPERTIES).each do |property|
173
- 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)
174
203
  end
175
204
  cairo_context.fill
205
+ cairo_context.set_matrix(previous_matrix)
176
206
  end
177
207
 
178
- def draw_stroke(drawing_area_widget, cairo_context)
179
- the_stroke = normalize_one_based_color(stroke)
180
- if the_stroke.size == 3
181
- cairo_context.set_source_rgb(*the_stroke)
182
- elsif the_stroke.size == 4
183
- 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)
184
211
  end
185
- (SHAPE_STROKE_PROPERTIES + SHAPE_GENERAL_PROPERTIES).each do |property|
186
- 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)
187
220
  end
188
221
  cairo_context.stroke
222
+ cairo_context.set_matrix(previous_matrix)
189
223
  end
190
224
 
191
- def normalize_one_based_color(rgb)
192
- rgb.each_with_index.map {|single_color, i| i == 3 ? single_color : single_color / 255.0}
225
+ def draw_clip(drawing_area_widget, cairo_context)
226
+ previous_matrix = cairo_context.matrix
227
+ apply_transforms(cairo_context, target: :clip)
228
+ SHAPE_GENERAL_PROPERTIES.each do |property|
229
+ apply_property(cairo_context, property)
230
+ end
231
+ cairo_context.clip
232
+ cairo_context.set_matrix(previous_matrix)
233
+ end
234
+
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
193
243
  end
194
244
 
195
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)
@@ -74,6 +78,14 @@ module Glimmer
74
78
  def post_add_content
75
79
  super
76
80
  @gtk.signal_connect(:draw) do |drawing_area_widget, cairo_context|
81
+ if @paint
82
+ previous_matrix = cairo_context.matrix
83
+ apply_transforms(cairo_context, target: :drawing_area)
84
+ Shape.set_source_dynamically(cairo_context, @paint)
85
+ cairo_context.paint
86
+ cairo_context.set_matrix(previous_matrix)
87
+ end
88
+
77
89
  shapes.each do |shape|
78
90
  shape.draw(drawing_area_widget, cairo_context)
79
91
  end
@@ -87,6 +99,10 @@ module Glimmer
87
99
  super
88
100
  end
89
101
  end
102
+
103
+ def paint(*args)
104
+ @paint = args
105
+ end
90
106
  end
91
107
  end
92
108
  end
@@ -147,8 +147,8 @@ 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)
151
- child.gtk.show
150
+ @gtk.add(child.gtk) if @gtk.respond_to?(:add)
151
+ child.gtk&.show if child.gtk&.respond_to?(:show)
152
152
  end
153
153
 
154
154
  def window_proxy
@@ -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