Advertisement
Serafim

Untitled

Oct 4th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace JSRender:Primitives:
  2.   class AbstractElement
  3.     render: abstract
  4.  
  5.     element: (ctx, cb) ->
  6.       stroke  = ctx.strokeStyle
  7.       fill    = ctx.fillStyle
  8.       ctx.beginPath()
  9.       cb(ctx)
  10.       ctx.closePath()
  11.       ctx.strokeStyle = stroke
  12.       ctx.fillStyle   = fill
  13.  
  14.     before: (render) ->
  15.       render.before (c) => @render(c)
  16.       @
  17.  
  18.     after: (render) ->
  19.       render.after (c)  => @render(c)
  20.       @
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. namespace JSRender:Primitives:
  28.   class HLine extends JSRender.Primitives.AbstractElement
  29.     constructor: (opt = {})->
  30.       @x      = watch opt.x       || 0
  31.       @y      = watch opt.y       || 0
  32.       @width  = watch opt.width   || 0
  33.       @color  = watch opt.color   || false
  34.       @size   = watch opt.size    || 1
  35.  
  36.     render: (ctx) ->
  37.       @element ctx, =>
  38.         if @color() isnt false
  39.           ctx.moveTo @x(), @y()
  40.           ctx.lineTo @x() + @width(), @y()
  41.           ctx.strokeStyle = @color()
  42.           ctx.lineWidth   = @size()
  43.           ctx.stroke()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement