Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[enhance] plugins: convert canvas to new syntax.

  • Loading branch information...
commit eb8186f3db922160bb33e3c8df1af877a9642e06 1 parent a6ba4aa
Arthur Azevedo de Amorim arthuraa authored
Showing with 315 additions and 226 deletions.
  1. +1 −1  lib/plugins/_tags
  2. +314 −225 lib/plugins/browser_canvas/bslCanvas.js
2  lib/plugins/_tags
View
@@ -1,7 +1,7 @@
# -*- conf -*- (for emacs)
<badop>: traverse, classic_syntax
-<browser_canvas>: traverse, classic_syntax
+<browser_canvas>: traverse
<crypto>: traverse, classic_syntax
<gcharts>: traverse, classic_syntax
<hlnet>: traverse, classic_syntax
539 lib/plugins/browser_canvas/bslCanvas.js
View
@@ -10,31 +10,32 @@
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-##extern-type Dom.private.element
-##extern-type Canvas.context
-##extern-type Canvas.pattern
-##extern-type Canvas.gradient
-##extern-type Image.data
-##extern-type Image.image
-##extern-type Canvas.canvas
-##extern-type Video.video
-##opa-type Canvas.style
+/** @externType Dom.private.element */
+/** @externType Canvas.context */
+/** @externType Canvas.pattern */
+/** @externType Canvas.gradient */
+/** @externType Image.data */
+/** @externType Image.image */
+/** @externType Canvas.canvas */
+/** @externType Video.video */
+/** @opaType Canvas.style */
// Canvas
-##register get: Dom.private.element -> opa[option(Canvas.canvas)]
-##args(canvas)
-{
- if(canvas && canvas[0] && canvas[0].getContext)
- {
- return js_some(canvas[0])
- }
- return js_none
+/**
+ * @register {Dom.private.element -> opa[option(Canvas.canvas)]}
+ */
+function get(canvas) {
+ if(canvas && canvas[0] && canvas[0].getContext) {
+ return js_some(canvas[0]);
+ }
+ return js_none;
}
-##register to_data_url: Canvas.canvas, string -> opa[option(string)]
-##args(canvas, name)
-{
+/**
+ * @register {Canvas.canvas, string -> opa[option(string)]}
+ */
+function to_data_url(canvas, name) {
if(canvas.toDataURL && canvas.toDataURL(name))
{
return js_some(canvas.toDataURL(name))
@@ -42,23 +43,26 @@
return js_none
}
-##register get_width: Canvas.canvas -> int
-##args(canvas)
-{
+/**
+ * @register {Canvas.canvas -> int}
+ */
+function get_width(canvas) {
return canvas.width;
}
-##register get_height: Canvas.canvas -> int
-##args(canvas)
-{
+/**
+ * @register {Canvas.canvas -> int}
+ */
+function get_height(canvas) {
return canvas.height;
}
// Context
-##register get_context: Canvas.canvas, string -> opa[option(Canvas.context)]
-##args(canvas, name)
-{
+/**
+ * @register {Canvas.canvas, string -> opa[option(Canvas.context)]}
+ */
+function get_context(canvas, name) {
if(canvas.getContext && canvas.getContext(name))
{
return js_some(canvas.getContext(name))
@@ -67,100 +71,115 @@
}
// State
-##register save: Canvas.context -> void
-##args(context)
-{
+/**
+ * @register {Canvas.context -> void}
+ */
+function save(context) {
context.save()
}
-##register restore: Canvas.context -> void
-##args(context)
-{
+/**
+ * @register {Canvas.context -> void}
+ */
+function restore(context) {
context.restore()
}
// transformations (default transform is the identity matrix)
-##register scale: Canvas.context, float, float -> void
-##args(context, x, y)
-{
+/**
+ * @register {Canvas.context, float, float -> void}
+ */
+function scale(context, x, y) {
context.scale(x, y)
}
-##register rotate: Canvas.context, float -> void
-##args(context, x)
-{
+/**
+ * @register {Canvas.context, float -> void}
+ */
+function rotate(context, x) {
context.rotate(x)
}
-##register translate: Canvas.context, int, int -> void
-##args(context, x, y)
-{
+/**
+ * @register {Canvas.context, int, int -> void}
+ */
+function translate(context, x, y) {
context.translate(x,y)
}
-##register transform: Canvas.context, int, int, int, int, int, int -> void
-##args(context, a, b, c, d, e, f)
-{
+/**
+ * @register {Canvas.context, int, int, int, int, int, int -> void}
+ */
+function transform(context, a, b, c, d, e, f) {
context.transform(a, b, c, d, e, f)
}
-##register set_transform: Canvas.context, int, int, int, int, int, int -> void
-##args(context, a, b, c, d, e, f)
-{
+/**
+ * @register {Canvas.context, int, int, int, int, int, int -> void}
+ */
+function set_transform(context, a, b, c, d, e, f) {
context.setTransform(a, b, c, d, e, f)
}
// compositing
-##register set_global_alpha: Canvas.context, float -> void
-##args(context, a)
-{
+/**
+ * @register {Canvas.context, float -> void}
+ */
+function set_global_alpha(context, a) {
context.globalAlpha = a
}
-##register get_global_alpha: Canvas.context -> float
-##args(context)
-{
+/**
+ * @register {Canvas.context -> float}
+ */
+function get_global_alpha(context) {
return context.globalAlpha
}
// colors and styles
-##register set_stroke_style_color: Canvas.context, string -> void
-##args(context, c)
-{
+/**
+ * @register {Canvas.context, string -> void}
+ */
+function set_stroke_style_color(context, c) {
context.strokeStyle = c
}
-##register set_stroke_style_gradient: Canvas.context, Canvas.gradient -> void
-##args(context, c)
-{
+/**
+ * @register {Canvas.context, Canvas.gradient -> void}
+ */
+function set_stroke_style_gradient(context, c) {
context.strokeStyle = c
}
-##register set_stroke_style_pattern: Canvas.context, Canvas.pattern -> void
-##args(context, c)
-{
+/**
+ * @register {Canvas.context, Canvas.pattern -> void}
+ */
+function set_stroke_style_pattern(context, c) {
context.strokeStyle = c
}
-##register set_fill_style_color: Canvas.context, string -> void
-##args(context, c)
-{
+/**
+ * @register {Canvas.context, string -> void}
+ */
+function set_fill_style_color(context, c) {
context.fillStyle = c
}
-##register set_fill_style_gradient: Canvas.context, Canvas.gradient -> void
-##args(context, c)
-{
+/**
+ * @register {Canvas.context, Canvas.gradient -> void}
+ */
+function set_fill_style_gradient(context, c) {
context.fillStyle = c
}
-##register set_fill_style_pattern: Canvas.context, Canvas.pattern -> void
-##args(context, c)
-{
+/**
+ * @register {Canvas.context, Canvas.pattern -> void}
+ */
+function set_fill_style_pattern(context, c) {
context.fillStyle = c
}
@@ -189,220 +208,259 @@ function canvas_get_style_getter(c){
}
-##register get_stroke_style: Canvas.context -> opa[Canvas.style]
-##args(context)
-{
+/**
+ * @register {Canvas.context -> opa[Canvas.style]}
+ */
+function get_stroke_style(context) {
return canvas_get_style_getter(context.strokeStyle)
}
-##register get_fill_style: Canvas.context -> opa[Canvas.style]
-##args(context)
-{
+/**
+ * @register {Canvas.context -> opa[Canvas.style]}
+ */
+function get_fill_style(context) {
return canvas_get_style_getter(context.fillStyle)
}
//Gradient
-##register add_color_stop: Canvas.gradient, float, string -> void
-##args(gradient,offset,color)
-{
+/**
+ * @register {Canvas.gradient, float, string -> void}
+ */
+function add_color_stop(gradient,offset,color) {
gradient.addColorStop(offset, color)
}
-##register create_linear_gradient: Canvas.context, int, int, int, int -> Canvas.gradient
-##args(context,x0,y0,x1,y1)
-{
+/**
+ * @register {Canvas.context, int, int, int, int -> Canvas.gradient}
+ */
+function create_linear_gradient(context,x0,y0,x1,y1) {
return context.createLinearGradient(x0, y0, x1, y1)
}
-##register create_radial_gradient : Canvas.context, int, int, int, int, int, int -> Canvas.gradient
-##args(context,x0,y0,r0,x1,y1,r1)
-{
+/**
+ * @register {Canvas.context, int, int, int, int, int, int -> Canvas.gradient}
+ */
+function create_radial_gradient (context,x0,y0,r0,x1,y1,r1) {
return context.createRadialGradient(x0, y0, r0, x1, y1, r1)
}
//pattern
-##register create_pattern_i \ bslcanvas_create_pattern : Canvas.context, Image.image, string -> Canvas.pattern
-##register create_pattern_v \ bslcanvas_create_pattern : Canvas.context, Video.video, string -> Canvas.pattern
-##register create_pattern_c \ bslcanvas_create_pattern : Canvas.context, Canvas.canvas, string -> Canvas.pattern
+/**
+ * @register {Canvas.context, Image.image, string -> Canvas.pattern} create_pattern_i bslcanvas_create_pattern
+ */
+/**
+ * @register {Canvas.context, Video.video, string -> Canvas.pattern} create_pattern_v bslcanvas_create_pattern
+ */
+/**
+ * @register {Canvas.context, Canvas.canvas, string -> Canvas.pattern} create_pattern_c bslcanvas_create_pattern
+ */
function bslcanvas_create_pattern(context, image, repeat)
{
context.createPattern(image, repeat)
}
// line caps/joins
-##register get_line_width: Canvas.context -> float
-##args(context)
-{
+/**
+ * @register {Canvas.context -> float}
+ */
+function get_line_width(context) {
return context.lineWidth
}
-##register set_line_width: Canvas.context, float -> void
-##args(context,size)
-{
+/**
+ * @register {Canvas.context, float -> void}
+ */
+function set_line_width(context,size) {
context.lineWidth = size
}
-##register set_line_cap: Canvas.context, string -> void
-##args(context, cap)
-{
+/**
+ * @register {Canvas.context, string -> void}
+ */
+function set_line_cap(context, cap) {
context.lineCap = cap
}
-##register get_line_cap: Canvas.context -> string
-##args(context)
-{
+/**
+ * @register {Canvas.context -> string}
+ */
+function get_line_cap(context) {
return context.lineCap
}
-##register set_line_join: Canvas.context, string -> void
-##args(context, join)
-{
+/**
+ * @register {Canvas.context, string -> void}
+ */
+function set_line_join(context, join) {
context.lineJoin = join
}
-##register get_line_join: Canvas.context -> string
-##args(context)
-{
+/**
+ * @register {Canvas.context -> string}
+ */
+function get_line_join(context) {
return context.lineJoin
}
-##register set_miter_limit: Canvas.context, float -> void
-##args(context, limit)
-{
+/**
+ * @register {Canvas.context, float -> void}
+ */
+function set_miter_limit(context, limit) {
context.miterLimit = limit
}
-##register get_miter_limit: Canvas.context -> float
-##args(context)
-{
+/**
+ * @register {Canvas.context -> float}
+ */
+function get_miter_limit(context) {
return context.miterLimit
}
// shadows
-##register set_shadow_color: Canvas.context, string -> void
-##args(context,color)
-{
+/**
+ * @register {Canvas.context, string -> void}
+ */
+function set_shadow_color(context,color) {
context.shadowColor=color
}
-##register get_shadow_color: Canvas.context -> string
-##args(context)
-{
+/**
+ * @register {Canvas.context -> string}
+ */
+function get_shadow_color(context) {
return context.shadowColor
}
-##register set_shadow_offset_x: Canvas.context, int -> void
-##args(context,offset)
-{
+/**
+ * @register {Canvas.context, int -> void}
+ */
+function set_shadow_offset_x(context,offset) {
context.shadowOffsetX=offset
}
-##register get_shadow_offset_x: Canvas.context -> int
-##args(context)
-{
+/**
+ * @register {Canvas.context -> int}
+ */
+function get_shadow_offset_x(context) {
return context.shadowOffsetX
}
-##register set_shadow_offset_y: Canvas.context, int -> void
-##args(context,offset)
-{
+/**
+ * @register {Canvas.context, int -> void}
+ */
+function set_shadow_offset_y(context,offset) {
context.shadowOffsetY=offset
}
-##register get_shadow_offset_y: Canvas.context -> int
-##args(context)
-{
+/**
+ * @register {Canvas.context -> int}
+ */
+function get_shadow_offset_y(context) {
return context.shadowOffsetY
}
-##register set_shadow_blur: Canvas.context, int -> void
-##args(context,blur)
-{
+/**
+ * @register {Canvas.context, int -> void}
+ */
+function set_shadow_blur(context, blur) {
context.shadowBlur=blur
}
-##register get_shadow_blur: Canvas.context -> int
-##args(context)
-{
+/**
+ * @register {Canvas.context -> int}
+ */
+function get_shadow_blur(context) {
return context.shadowBlur
}
// rects
-##register clear_rect: Canvas.context, int ,int, int, int -> void
-##args(context,x,y,w,h)
-{
+/**
+ * @register {Canvas.context, int ,int, int, int -> void}
+ */
+function clear_rect(context,x,y,w,h) {
context.clearRect(x, y, w, h)
}
-##register fill_rect: Canvas.context, int ,int, int, int -> void
-##args(context,x,y,w,h)
-{
+/**
+ * @register {Canvas.context, int ,int, int, int -> void}
+ */
+function fill_rect(context,x,y,w,h) {
context.fillRect(x, y, w, h)
}
-##register stroke_rect: Canvas.context, int ,int, int, int -> void
-##args(context,x,y,w,h)
-{
+/**
+ * @register {Canvas.context, int ,int, int, int -> void}
+ */
+function stroke_rect(context,x,y,w,h) {
context.strokeRect(x, y, w, h)
}
// path API
-##register begin_path: Canvas.context -> void
-##args(context)
-{
+/**
+ * @register {Canvas.context -> void}
+ */
+function begin_path(context) {
context.beginPath()
}
-##register close_path: Canvas.context -> void
-##args(context)
-{
+/**
+ * @register {Canvas.context -> void}
+ */
+function close_path(context) {
context.closePath()
}
-##register move_to: Canvas.context, int, int -> void
-##args(context, x, y)
-{
+/**
+ * @register {Canvas.context, int, int -> void}
+ */
+function move_to(context, x, y) {
context.moveTo(x, y)
}
-##register line_to: Canvas.context, int, int -> void
-##args(context, x, y)
-{
+/**
+ * @register {Canvas.context, int, int -> void}
+ */
+function line_to(context, x, y) {
context.lineTo(x, y)
}
-##register quadratic_curve_to: Canvas.context, int, int, int, int -> void
-##args(context, cpx, cpy, x, y)
-{
+/**
+ * @register {Canvas.context, int, int, int, int -> void}
+ */
+function quadratic_curve_to(context, cpx, cpy, x, y) {
context.quadraticCurveTo(cpx, cpy, x, y)
}
-##register bezier_curve_to: Canvas.context, int, int, int, int, int, int -> void
-##args(context, cp1x, cp1y, cp2x, cp2y, x, y)
-{
+/**
+ * @register {Canvas.context, int, int, int, int, int, int -> void}
+ */
+function bezier_curve_to(context, cp1x, cp1y, cp2x, cp2y, x, y) {
context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
}
-##register arc_to: Canvas.context, int, int, int, int, int -> void
-##args(context, x1, y1, x2, y2, radius)
-{
+/**
+ * @register {Canvas.context, int, int, int, int, int -> void}
+ */
+function arc_to(context, x1, y1, x2, y2, radius) {
context.arcTo( x1, y1, x2, y2, radius)
}
-##register arc: Canvas.context, int, int, int, float, float, bool -> void
-##args(context, centerX, centerY, radius, startingAngle, endingAngle, counterclockwise)
-{
- context.arc(centerX, centerY, radius, startingAngle,
+/**
+ * @register {Canvas.context, int, int, int, float, float, bool -> void}
+ */
+function arc(context, centerX, centerY, radius, startingAngle, endingAngle, counterclockwise) {
+ context.arc(centerX, centerY, radius, startingAngle,
endingAngle, counterclockwise);
}
-##register rect: Canvas.context, int, int, int, int -> void
-##args(context, x, y, w, h)
-{
+/**
+ * @register {Canvas.context, int, int, int, int -> void}
+ */
+function rect(context, x, y, w, h) {
context.rect( x, y, w, h)
}
@@ -412,27 +470,31 @@ function bslcanvas_create_pattern(context, image, repeat)
// context.rect( x, y, w, h)
// }
-##register fill: Canvas.context -> void
-##args(context)
-{
+/**
+ * @register {Canvas.context -> void}
+ */
+function fill(context) {
context.fill()
}
-##register stroke: Canvas.context -> void
-##args(context)
-{
+/**
+ * @register {Canvas.context -> void}
+ */
+function stroke(context) {
context.stroke()
}
-##register clip: Canvas.context -> void
-##args(context)
-{
+/**
+ * @register {Canvas.context -> void}
+ */
+function clip(context) {
context.clip()
}
-##register is_point_in_path : Canvas.context, int, int -> bool
-##args(context, x, y)
-{
+/**
+ * @register {Canvas.context, int, int -> bool}
+ */
+function is_point_in_path (context, x, y) {
return context.isPointInPath(x, y)
}
@@ -441,71 +503,96 @@ function bslcanvas_create_pattern(context, image, repeat)
// text
-##register set_font: Canvas.context, string -> void
-##args(context, fontText)
-{
+/**
+ * @register {Canvas.context, string -> void}
+ */
+function set_font(context, fontText) {
context.font = fontText
}
-##register set_text_align: Canvas.context, string -> void
-##args(context, alignText)
-{
+/**
+ * @register {Canvas.context, string -> void}
+ */
+function set_text_align(context, alignText) {
context.textAlign = alignText
}
-##register set_text_baseline: Canvas.context, string -> void
-##args(context, baselineText)
-{
+/**
+ * @register {Canvas.context, string -> void}
+ */
+function set_text_baseline(context, baselineText) {
context.textBaseline = baselineText
}
-##register stroke_text: Canvas.context, string, int, int -> void
-##args(context, text, x, y)
-{
+/**
+ * @register {Canvas.context, string, int, int -> void}
+ */
+function stroke_text(context, text, x, y) {
context.strokeText(text, x, y)
}
-##register fill_text: Canvas.context, string, int, int -> void
-##args(context, text, x, y)
-{
+/**
+ * @register {Canvas.context, string, int, int -> void}
+ */
+function fill_text(context, text, x, y) {
context.fillText(text, x, y)
}
-##register measure_text: Canvas.context, string -> int
-##args(context, text)
-{
+/**
+ * @register {Canvas.context, string -> int}
+ */
+function measure_text(context, text) {
return context.measureText(text).width
}
// drawing images
-##register create_image : string -> Image.image
-##args(data)
-{
+/**
+ * @register {string -> Image.image}
+ */
+function create_image (data) {
var img = new Image();
img.src = data;
return img
}
-##register draw_image_i \ bslcanvas_draw_image: Canvas.context, Image.image, int, int -> void
-##register draw_image_c \ bslcanvas_draw_image: Canvas.context, Canvas.canvas, int, int -> void
-##register draw_image_v \ bslcanvas_draw_image: Canvas.context, Video.video, int, int -> void
+/**
+ * @register {Canvas.context, Image.image, int, int -> void} draw_image_i bslcanvas_draw_image
+ */
+/**
+ * @register {Canvas.context, Canvas.canvas, int, int -> void} draw_image_c bslcanvas_draw_image
+ */
+/**
+ * @register {Canvas.context, Video.video, int, int -> void} draw_image_v bslcanvas_draw_image
+ */
function bslcanvas_draw_image(context, image, x, y)
{
return context.drawImage(image, x ,y)
}
-##register draw_image_di \ bslcanvas_draw_image_d: Canvas.context, Image.image, int, int, int, int -> void
-##register draw_image_dc \ bslcanvas_draw_image_d: Canvas.context, Canvas.canvas, int, int, int, int -> void
-##register draw_image_dv \ bslcanvas_draw_image_d: Canvas.context, Video.video, int, int, int, int -> void
+/**
+ * @register {Canvas.context, Image.image, int, int, int, int -> void} draw_image_di bslcanvas_draw_image_d
+ */
+/**
+ * @register {Canvas.context, Canvas.canvas, int, int, int, int -> void} draw_image_dc bslcanvas_draw_image_d
+ */
+/**
+ * @register {Canvas.context, Video.video, int, int, int, int -> void} draw_image_dv bslcanvas_draw_image_d
+ */
function bslcanvas_draw_image_d(context, image, x, y, w, h)
{
return context.drawImage(image, x ,y, w ,h)
}
-##register draw_image_fi \ bslcanvas_draw_image_f: Canvas.context, Image.image, int, int, int, int, int, int, int, int -> void
-##register draw_image_fc \ bslcanvas_draw_image_f: Canvas.context, Canvas.canvas, int, int, int, int, int, int, int, int -> void
-##register draw_image_fv \ bslcanvas_draw_image_f: Canvas.context, Video.video, int, int, int, int, int, int, int, int -> void
+/**
+ * @register {Canvas.context, Image.image, int, int, int, int, int, int, int, int -> void} draw_image_fi bslcanvas_draw_image_f
+ */
+/**
+ * @register {Canvas.context, Canvas.canvas, int, int, int, int, int, int, int, int -> void} draw_image_fc bslcanvas_draw_image_f
+ */
+/**
+ * @register {Canvas.context, Video.video, int, int, int, int, int, int, int, int -> void} draw_image_fv bslcanvas_draw_image_f
+ */
function bslcanvas_draw_image_f(context, image, sx, sy, sw, sh, dx, dy, dw, dh)
{
return context.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh)
@@ -513,18 +600,20 @@ function bslcanvas_draw_image_f(context, image, sx, sy, sw, sh, dx, dy, dw, dh)
// pixel manipulation
-##register put_image_data: Canvas.context, Image.data, int, int -> void
-##args(context, data, x, y)
-{
+/**
+ * @register {Canvas.context, Image.data, int, int -> void}
+ */
+function put_image_data(context, data, x, y) {
context.putImageData(data, x ,y)
}
//other
-##register get_image : Dom.private.element -> opa[option(Image.image)]
-##args(dom)
-{
+/**
+ * @register {Dom.private.element -> opa[option(Image.image)]}
+ */
+function get_image (dom) {
if (dom && dom[0] && (dom[0].tagName.toLowerCase() == "img") && dom[0].complete){
return js_some(dom[0])
}
Please sign in to comment.
Something went wrong with that request. Please try again.