Class: GuindillaGUI::Canvas
- Inherits:
-
Element
show all
- Defined in:
- lib/guindilla_gui/guindilla_classes.rb
Overview
—————————————————————————-#
Canvas
—————————————————————————-#
Instance Attribute Summary
Attributes inherited from Element
#attributes, #id
Attributes inherited from Guindilla
#active_id, #blocks, #elements, #inputs, #socket
Instance Method Summary
collapse
-
#arc(x, y, radius, start_angle, end_angle, attributes = {}) ⇒ Object
attributes may include ‘type: fill`, and/or `reverse: true`.
-
#arc_to(x1, y1, x2, y2, radius) ⇒ Object
HACK: works, but wtf is this? ##.
-
#canvas_circle(x, y, radius, type = "stroke") ⇒ Object
-
#canvas_rectangle(x, y, width, height, type = "stroke") ⇒ Object
-
#draw(type = "stroke", &block) ⇒ Object
-
#fill ⇒ Object
-
#fill_color(clr) ⇒ Object
-
#initialize(attributes, &block) ⇒ Canvas
constructor
A new instance of Canvas.
-
#line_color(clr) ⇒ Object
-
#line_to(x, y) ⇒ Object
-
#move_to(x, y) ⇒ Object
-
#stroke ⇒ Object
Methods inherited from Element
#get_position
Methods inherited from Guindilla
#after, #alert, #align, #append, #attributes, #audio_out, #background, #border, #border_color, #border_radius, #border_width, #bullet_list, #button, #canvas, #chart, #checkbox, #circle, #color, #color_input, #container, #display, #every, #file_input, #font, #font_family, #font_size, #h_box, #h_rule, #heading, #height, #hide, #image, #justify, #line_break, #link, #margin, #number_input, #on_click, #on_hover, #on_leave, #on_mouse_move, #opacity, #ordered_list, #padding, #para, #polygon, #radio_button, #range_slider, #rectangle, #rotate, #show, #size, #source, #square, #style, #sub_script, #sup_script, #text, #text_align, #text_input, #toggle, #transition, #triangle, #url_input, #v_box, #video_out, #web_frame, #width
Constructor Details
#initialize(attributes, &block) ⇒ Canvas
Returns a new instance of Canvas.
250
251
252
253
254
|
# File 'lib/guindilla_gui/guindilla_classes.rb', line 250
def initialize(attributes, &block)
super("canvas", attributes)
send_js(%Q~ const #{self.id}_ctx = #{self.id}.getContext("2d"); ~)
self.instance_eval &block if block_given?
end
|
Instance Method Details
#arc(x, y, radius, start_angle, end_angle, attributes = {}) ⇒ Object
attributes may include ‘type: fill`, and/or `reverse: true`
258
259
260
261
262
263
264
265
266
267
|
# File 'lib/guindilla_gui/guindilla_classes.rb', line 258
def arc(x, y, radius, start_angle, end_angle, attributes={})
attributes[:type] ? type = attributes[:type] : type = 'stroke'
attributes[:reverse] ? reverse = attributes[:reverse] : reverse = false
s_ang = (start_angle) * Math::PI / 180
e_ang = (end_angle) * Math::PI / 180
send_js(%Q~
#{self.id}_ctx.arc(#{x}, #{y}, #{radius}, #{s_ang}, #{e_ang}, #{reverse});
#{self.id}_ctx.#{type.to_s}();
~)
end
|
#arc_to(x1, y1, x2, y2, radius) ⇒ Object
HACK: works, but wtf is this? ##
269
270
271
272
273
274
|
# File 'lib/guindilla_gui/guindilla_classes.rb', line 269
def arc_to(x1, y1, x2, y2, radius) send_js(%Q~
#{self.id}_ctx.arc(#{x1}, #{y1}, #{x2}, #{y2}, #{radius});
#{self.id}_ctx.stroke();
~)
end
|
#canvas_circle(x, y, radius, type = "stroke") ⇒ Object
276
277
278
279
|
# File 'lib/guindilla_gui/guindilla_classes.rb', line 276
def canvas_circle(x, y, radius, type="stroke")
arc(x, y, radius, 0, 360, type: "#{type}")
send_js(%Q~ #{self.id}_ctx.fill; ~) if type.to_s == "fill"
end
|
#canvas_rectangle(x, y, width, height, type = "stroke") ⇒ Object
281
282
283
284
285
|
# File 'lib/guindilla_gui/guindilla_classes.rb', line 281
def canvas_rectangle(x, y, width, height, type="stroke")
send_js(%Q~
#{self.id}_ctx.#{type.to_s}Rect(#{x}, #{y}, #{width}, #{height});
~)
end
|
#draw(type = "stroke", &block) ⇒ Object
287
288
289
290
291
|
# File 'lib/guindilla_gui/guindilla_classes.rb', line 287
def draw(type="stroke", &block)
send_js(%Q~ #{self.id}_ctx.beginPath(); ~)
block.call
send_js(%Q~ #{self.id}_ctx.#{type.to_s}(); ~)
end
|
#fill ⇒ Object
293
294
295
|
# File 'lib/guindilla_gui/guindilla_classes.rb', line 293
def fill
send_js(%Q~ #{self.id}_ctx.fill(); ~)
end
|
#fill_color(clr) ⇒ Object
297
298
299
|
# File 'lib/guindilla_gui/guindilla_classes.rb', line 297
def fill_color(clr)
send_js(%Q~ #{self.id}_ctx.fillStyle = "#{clr}"; ~)
end
|
#line_color(clr) ⇒ Object
301
302
303
304
305
|
# File 'lib/guindilla_gui/guindilla_classes.rb', line 301
def line_color(clr)
send_js(%Q~
#{self.id}_ctx.strokeStyle = "#{clr}";
~)
end
|
#line_to(x, y) ⇒ Object
307
308
309
310
311
312
|
# File 'lib/guindilla_gui/guindilla_classes.rb', line 307
def line_to(x, y)
send_js(%Q~
#{self.id}_ctx.lineTo(#{x}, #{y});
#{self.id}_ctx.stroke();
~)
end
|
#move_to(x, y) ⇒ Object
314
315
316
317
318
|
# File 'lib/guindilla_gui/guindilla_classes.rb', line 314
def move_to(x, y)
send_js(%Q~
#{self.id}_ctx.moveTo(#{x}, #{y});
~)
end
|
#stroke ⇒ Object
320
321
322
|
# File 'lib/guindilla_gui/guindilla_classes.rb', line 320
def stroke
send_js(%Q~ #{self.id}_ctx.stroke(); ~)
end
|