Class: Skia::Canvas
Instance Attribute Summary
Attributes inherited from Base
#ptr
Instance Method Summary
collapse
-
#clear(color = Color::TRANSPARENT) ⇒ Object
-
#clip_path(path, op = :intersect, antialias: false) ⇒ Object
-
#clip_rect(rect, op = :intersect, antialias: false) ⇒ Object
-
#clip_rrect(rrect, op = :intersect, antialias: false) ⇒ Object
-
#concat(matrix) ⇒ Object
-
#draw_arc(oval, start_angle, sweep_angle, use_center, paint) ⇒ Object
-
#draw_circle(cx, cy, radius, paint) ⇒ Object
-
#draw_color(color, blend_mode = :src_over) ⇒ Object
-
#draw_image(image, x, y, paint = nil) ⇒ Object
-
#draw_image_rect(image, src_rect, dst_rect, paint = nil) ⇒ Object
-
#draw_line(x1, y1, x2, y2, paint) ⇒ Object
-
#draw_oval(rect, paint) ⇒ Object
-
#draw_paint(paint) ⇒ Object
-
#draw_path(path, paint) ⇒ Object
-
#draw_picture(picture, matrix = nil, paint = nil) ⇒ Object
-
#draw_point(x, y, paint) ⇒ Object
-
#draw_points(points, paint, mode: :points) ⇒ Object
-
#draw_rect(rect, paint) ⇒ Object
-
#draw_round_rect(rect, radius, paint) ⇒ Object
-
#draw_rrect(rrect, paint) ⇒ Object
-
#draw_text(text, x, y, font, paint) ⇒ Object
-
#draw_text_blob(blob, x, y, paint) ⇒ Object
-
#initialize(ptr) ⇒ Canvas
constructor
A new instance of Canvas.
-
#matrix ⇒ Object
-
#matrix=(matrix) ⇒ Object
-
#reset_matrix ⇒ Object
-
#restore ⇒ Object
-
#restore_to_count(count) ⇒ Object
-
#rotate(degrees, px = nil, py = nil) ⇒ Object
-
#rotate_radians(radians) ⇒ Object
-
#save ⇒ Object
-
#save_count ⇒ Object
-
#save_layer(bounds = nil, paint = nil) ⇒ Object
-
#scale(sx, sy = sx) ⇒ Object
-
#skew(sx, sy) ⇒ Object
-
#translate(dx, dy) ⇒ Object
-
#with_save ⇒ Object
-
#with_save_layer(bounds = nil, paint = nil) ⇒ Object
Methods inherited from Base
#null?, release_callback, #to_ptr
Constructor Details
#initialize(ptr) ⇒ Canvas
Returns a new instance of Canvas.
5
6
7
|
# File 'lib/skia/canvas.rb', line 5
def initialize(ptr)
super(ptr, nil)
end
|
Instance Method Details
#clear(color = Color::TRANSPARENT) ⇒ Object
100
101
102
103
104
|
# File 'lib/skia/canvas.rb', line 100
def clear(color = Color::TRANSPARENT)
color_value = color.is_a?(Color) ? color.to_i : color
Native.sk_canvas_clear(@ptr, color_value)
self
end
|
#clip_path(path, op = :intersect, antialias: false) ⇒ Object
90
91
92
93
|
# File 'lib/skia/canvas.rb', line 90
def clip_path(path, op = :intersect, antialias: false)
Native.sk_canvas_clip_path_with_operation(@ptr, path.ptr, op, antialias)
self
end
|
#clip_rect(rect, op = :intersect, antialias: false) ⇒ Object
84
85
86
87
88
|
# File 'lib/skia/canvas.rb', line 84
def clip_rect(rect, op = :intersect, antialias: false)
rect_struct = rect.to_struct
Native.sk_canvas_clip_rect_with_operation(@ptr, rect_struct, op, antialias)
self
end
|
#clip_rrect(rrect, op = :intersect, antialias: false) ⇒ Object
95
96
97
98
|
# File 'lib/skia/canvas.rb', line 95
def clip_rrect(rrect, op = :intersect, antialias: false)
Native.sk_canvas_clip_rrect_with_operation(@ptr, rrect.ptr, op, antialias)
self
end
|
#concat(matrix) ⇒ Object
62
63
64
65
66
|
# File 'lib/skia/canvas.rb', line 62
def concat(matrix)
matrix_struct = matrix.to_struct44
Native.sk_canvas_concat(@ptr, matrix_struct)
self
end
|
#draw_arc(oval, start_angle, sweep_angle, use_center, paint) ⇒ Object
134
135
136
137
138
|
# File 'lib/skia/canvas.rb', line 134
def draw_arc(oval, start_angle, sweep_angle, use_center, paint)
oval_struct = oval.to_struct
Native.sk_canvas_draw_arc(@ptr, oval_struct, start_angle.to_f, sweep_angle.to_f, use_center, paint.ptr)
self
end
|
#draw_circle(cx, cy, radius, paint) ⇒ Object
140
141
142
143
|
# File 'lib/skia/canvas.rb', line 140
def draw_circle(cx, cy, radius, paint)
Native.sk_canvas_draw_circle(@ptr, cx.to_f, cy.to_f, radius.to_f, paint.ptr)
self
end
|
#draw_color(color, blend_mode = :src_over) ⇒ Object
106
107
108
109
110
|
# File 'lib/skia/canvas.rb', line 106
def draw_color(color, blend_mode = :src_over)
color_value = color.is_a?(Color) ? color.to_i : color
Native.sk_canvas_draw_color(@ptr, color_value, blend_mode)
self
end
|
#draw_image(image, x, y, paint = nil) ⇒ Object
188
189
190
191
|
# File 'lib/skia/canvas.rb', line 188
def draw_image(image, x, y, paint = nil)
Native.sk_canvas_draw_image(@ptr, image.ptr, x.to_f, y.to_f, paint&.ptr)
self
end
|
#draw_image_rect(image, src_rect, dst_rect, paint = nil) ⇒ Object
193
194
195
196
197
198
|
# File 'lib/skia/canvas.rb', line 193
def draw_image_rect(image, src_rect, dst_rect, paint = nil)
src_struct = src_rect&.to_struct
dst_struct = dst_rect.to_struct
Native.sk_canvas_draw_image_rect(@ptr, image.ptr, src_struct, dst_struct, paint&.ptr)
self
end
|
#draw_line(x1, y1, x2, y2, paint) ⇒ Object
162
163
164
165
|
# File 'lib/skia/canvas.rb', line 162
def draw_line(x1, y1, x2, y2, paint)
Native.sk_canvas_draw_line(@ptr, x1.to_f, y1.to_f, x2.to_f, y2.to_f, paint.ptr)
self
end
|
#draw_oval(rect, paint) ⇒ Object
145
146
147
148
149
|
# File 'lib/skia/canvas.rb', line 145
def draw_oval(rect, paint)
rect_struct = rect.to_struct
Native.sk_canvas_draw_oval(@ptr, rect_struct, paint.ptr)
self
end
|
#draw_paint(paint) ⇒ Object
112
113
114
115
|
# File 'lib/skia/canvas.rb', line 112
def draw_paint(paint)
Native.sk_canvas_draw_paint(@ptr, paint.ptr)
self
end
|
#draw_path(path, paint) ⇒ Object
151
152
153
154
|
# File 'lib/skia/canvas.rb', line 151
def draw_path(path, paint)
Native.sk_canvas_draw_path(@ptr, path.ptr, paint.ptr)
self
end
|
#draw_picture(picture, matrix = nil, paint = nil) ⇒ Object
156
157
158
159
160
|
# File 'lib/skia/canvas.rb', line 156
def draw_picture(picture, matrix = nil, paint = nil)
matrix_struct = matrix&.to_struct
Native.sk_canvas_draw_picture(@ptr, picture.ptr, matrix_struct, paint&.ptr)
self
end
|
#draw_point(x, y, paint) ⇒ Object
167
168
169
170
|
# File 'lib/skia/canvas.rb', line 167
def draw_point(x, y, paint)
Native.sk_canvas_draw_point(@ptr, x.to_f, y.to_f, paint.ptr)
self
end
|
#draw_points(points, paint, mode: :points) ⇒ Object
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/skia/canvas.rb', line 172
def draw_points(points, paint, mode: :points)
return self if points.empty?
point_structs = points.map { |point| coerce_point(point).to_struct }
points_ptr = FFI::MemoryPointer.new(Native::SKPoint, point_structs.length)
point_structs.each_with_index do |point_struct, index|
destination = Native::SKPoint.new(points_ptr + (index * Native::SKPoint.size))
destination[:x] = point_struct[:x]
destination[:y] = point_struct[:y]
end
Native.sk_canvas_draw_points(@ptr, mode, point_structs.length, points_ptr, paint.ptr)
self
end
|
#draw_rect(rect, paint) ⇒ Object
117
118
119
120
121
|
# File 'lib/skia/canvas.rb', line 117
def draw_rect(rect, paint)
rect_struct = rect.to_struct
Native.sk_canvas_draw_rect(@ptr, rect_struct, paint.ptr)
self
end
|
#draw_round_rect(rect, radius, paint) ⇒ Object
128
129
130
131
132
|
# File 'lib/skia/canvas.rb', line 128
def draw_round_rect(rect, radius, paint)
rect_struct = rect.to_struct
Native.sk_canvas_draw_round_rect(@ptr, rect_struct, radius.to_f, radius.to_f, paint.ptr)
self
end
|
#draw_rrect(rrect, paint) ⇒ Object
123
124
125
126
|
# File 'lib/skia/canvas.rb', line 123
def draw_rrect(rrect, paint)
Native.sk_canvas_draw_rrect(@ptr, rrect.ptr, paint.ptr)
self
end
|
#draw_text(text, x, y, font, paint) ⇒ Object
200
201
202
203
204
205
|
# File 'lib/skia/canvas.rb', line 200
def draw_text(text, x, y, font, paint)
text_bytes = text.encode('UTF-8')
Native.sk_canvas_draw_simple_text(@ptr, text_bytes, text_bytes.bytesize, :utf8, x.to_f, y.to_f, font.ptr,
paint.ptr)
self
end
|
#draw_text_blob(blob, x, y, paint) ⇒ Object
207
208
209
210
|
# File 'lib/skia/canvas.rb', line 207
def draw_text_blob(blob, x, y, paint)
Native.sk_canvas_draw_text_blob(@ptr, blob.ptr, x.to_f, y.to_f, paint.ptr)
self
end
|
#matrix ⇒ Object
73
74
75
76
77
|
# File 'lib/skia/canvas.rb', line 73
def matrix
m = Native::SKMatrix44.new
Native.sk_canvas_get_matrix(@ptr, m)
Matrix.from_struct44(m)
end
|
#matrix=(matrix) ⇒ Object
68
69
70
71
|
# File 'lib/skia/canvas.rb', line 68
def matrix=(matrix)
matrix_struct = matrix.to_struct44
Native.sk_canvas_set_matrix(@ptr, matrix_struct)
end
|
#reset_matrix ⇒ Object
79
80
81
82
|
# File 'lib/skia/canvas.rb', line 79
def reset_matrix
Native.sk_canvas_reset_matrix(@ptr)
self
end
|
#restore ⇒ Object
19
20
21
|
# File 'lib/skia/canvas.rb', line 19
def restore
Native.sk_canvas_restore(@ptr)
end
|
#restore_to_count(count) ⇒ Object
23
24
25
|
# File 'lib/skia/canvas.rb', line 23
def restore_to_count(count)
Native.sk_canvas_restore_to_count(@ptr, count)
end
|
#rotate(degrees, px = nil, py = nil) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/skia/canvas.rb', line 41
def rotate(degrees, px = nil, py = nil)
if px && py
translate(px, py)
Native.sk_canvas_rotate_degrees(@ptr, degrees.to_f)
translate(-px, -py)
else
Native.sk_canvas_rotate_degrees(@ptr, degrees.to_f)
end
self
end
|
#rotate_radians(radians) ⇒ Object
52
53
54
55
|
# File 'lib/skia/canvas.rb', line 52
def rotate_radians(radians)
Native.sk_canvas_rotate_radians(@ptr, radians.to_f)
self
end
|
#save ⇒ Object
9
10
11
|
# File 'lib/skia/canvas.rb', line 9
def save
Native.sk_canvas_save(@ptr)
end
|
#save_count ⇒ Object
27
28
29
|
# File 'lib/skia/canvas.rb', line 27
def save_count
Native.sk_canvas_get_save_count(@ptr)
end
|
#save_layer(bounds = nil, paint = nil) ⇒ Object
13
14
15
16
17
|
# File 'lib/skia/canvas.rb', line 13
def save_layer(bounds = nil, paint = nil)
bounds_ptr = bounds&.to_struct
paint_ptr = paint&.ptr
Native.sk_canvas_save_layer(@ptr, bounds_ptr, paint_ptr)
end
|
#scale(sx, sy = sx) ⇒ Object
36
37
38
39
|
# File 'lib/skia/canvas.rb', line 36
def scale(sx, sy = sx)
Native.sk_canvas_scale(@ptr, sx.to_f, sy.to_f)
self
end
|
#skew(sx, sy) ⇒ Object
57
58
59
60
|
# File 'lib/skia/canvas.rb', line 57
def skew(sx, sy)
Native.sk_canvas_skew(@ptr, sx.to_f, sy.to_f)
self
end
|
#translate(dx, dy) ⇒ Object
31
32
33
34
|
# File 'lib/skia/canvas.rb', line 31
def translate(dx, dy)
Native.sk_canvas_translate(@ptr, dx.to_f, dy.to_f)
self
end
|
#with_save ⇒ Object
212
213
214
215
216
217
218
219
|
# File 'lib/skia/canvas.rb', line 212
def with_save
count = save
begin
yield self
ensure
restore_to_count(count)
end
end
|
#with_save_layer(bounds = nil, paint = nil) ⇒ Object
221
222
223
224
225
226
227
228
|
# File 'lib/skia/canvas.rb', line 221
def with_save_layer(bounds = nil, paint = nil)
count = save_layer(bounds, paint)
begin
yield self
ensure
restore_to_count(count)
end
end
|