Browse files

updates

  • Loading branch information...
1 parent bf34a91 commit f3134ee93aff902ebafbac84ff15ce584adb4518 @caleb committed May 29, 2014
Showing with 226 additions and 210 deletions.
  1. +1 −0 .gitignore
  2. +8 −3 Brocfile.js
  3. +1 −1 lib/bootstrap.js
  4. +204 −0 lib/drawing.coffee
  5. +9 −205 lib/{rodeo_crop.coffee → rodeo-crop.coffee}
  6. +2 −0 package.json
  7. +1 −1 public/index.html
View
1 .gitignore
@@ -1 +1,2 @@
/node_modules
+/tmp
View
11 Brocfile.js
@@ -2,6 +2,7 @@ var filterCoffeeScript = require('broccoli-coffee')
var uglifyJavaScript = require('broccoli-uglify-js')
var compileES6 = require('broccoli-es6-concatenator')
var pickFiles = require('broccoli-static-compiler')
+var moveFile = require('broccoli-file-mover')
var mergeTrees = require('broccoli-merge-trees')
function preprocess(tree) {
@@ -32,9 +33,13 @@ var libJs = compileES6(libAndDependencies, {
'rodeo-crop/bootstrap.js'
],
wrapInEval: false,
- outputFile: '/javascripts/rodeo_crop.js'
+ outputFile: '/javascripts/rodeo-crop.js'
})
-var uglifiedLibJs = uglifyJavaScript(libJs)
+var uglifiedLibJs = moveFile(libJs, {
+ srcFile: '/javascripts/rodeo-crop.js',
+ destFile: '/javascripts/rodeo-crop.min.js'
+})
+uglifiedLibJs = uglifyJavaScript(uglifiedLibJs)
-module.exports = new mergeTrees([libJs, publicDir, uglifiedLibJs], { overwrite: true })
+module.exports = new mergeTrees([libJs, uglifiedLibJs, publicDir], { overwrite: true })
View
2 lib/bootstrap.js
@@ -1 +1 @@
-window.RodeoCrop = requireModule('rodeo-crop/rodeo_crop').default;
+window.RodeoCrop = requireModule('rodeo-crop/rodeo-crop').default;
View
204 lib/drawing.coffee
@@ -0,0 +1,204 @@
+`import _ from "rodeo-crop/funderscore"`
+
+drawing = {}
+
+class Drawable
+ constructor: (options) ->
+ @options = options
+
+ @x = options.x
+ @y = options.y
+ @w = options.w
+ @h = options.h
+ @scale = options.scale
+ @parent = options.parent
+ @canvas = options.canvas
+ @children = options.children || []
+ @dragable = options.dragable || false
+
+ onCanvasSizeChange: () ->
+ @options.onCanvasSizeChange.call @ if _.isFunction @options.onCanvasSizeChange
+
+ set: (options) ->
+ for own key, value of options
+ @[key] = value
+
+ bounds: ->
+ {
+ x: 0
+ y: 0
+ w: @w
+ h: @h
+ }
+
+ frame: ->
+ {
+ x: @x
+ y: @y
+ w: @w
+ h: @h
+ }
+
+ convertToParent: (point) ->
+ frame = @frame()
+ {
+ x: point.x + frame.x
+ y: point.y + frame.y
+ }
+
+ convertFromParent: (point) ->
+ frame = @frame()
+ {
+ x: point.x - frame.x
+ y: point.y - frame.y
+ }
+
+ convertToCanvas: (point) ->
+ parent = @
+ x = point.x
+ y = point.y
+ while parent
+ x += parent.frame().x
+ y += parent.frame().y
+
+ parent = parent.parent
+
+ {
+ x: x
+ y: y
+ }
+
+ convertFromCanvas: (point) ->
+ parent = @
+ x = point.x
+ y = point.y
+ while parent
+ x -= parent.frame().x
+ y -= parent.frame().y
+
+ parent = parent.parent
+
+ {
+ x: x
+ y: y
+ }
+
+ positionContext: (ctx, fn) ->
+ if @parent
+ pos = @convertToCanvas @parent.bounds()
+ ctx.translate pos.x, pos.y
+ fn.call @, ctx
+
+ isolateAndMoveToParent: (ctx, fn) ->
+ ctx.save()
+ @positionContext ctx, (ctx) ->
+ fn.call @, ctx
+ ctx.restore()
+
+ containsCanvasPoint: (point) ->
+ localPoint = @convertFromCanvas point
+ @containsPoint localPoint
+
+ containsPoint: (point) ->
+ frame = @frame()
+ 0 <= point.x <= frame.w &&
+ 0 <= point.y <= frame.h
+
+ addChild: (child) ->
+ child.parent = @
+ @children.push child
+
+ removeChild: (child) ->
+ i = @children.indexOf child
+ if i >= 0
+ child.parent = null
+ @children.splice i, 1
+
+ drawChildren: (ctx) ->
+ for child in @children
+ child.draw ctx
+
+ draw: (ctx) ->
+ # noop
+
+drawing.Drawable = Drawable
+
+class CanvasImage extends Drawable
+ constructor: (options) ->
+ super options
+
+ @source = options.source
+ @naturalWidth = options.naturalWidth
+ @naturalHeight = options.naturalHeight
+ @onLoad = options.onLoad
+
+ @loadImage()
+
+ naturalBounds: () ->
+ {
+ x: 0
+ y: 0
+ w: @naturalWidth
+ h: @naturalHeight
+ }
+
+ resizeToParent: () ->
+ cw = @parent.frame().w
+ ch = @parent.frame().h
+
+ scaleX = 1
+ scaleY = 1
+
+ scaleX = cw / @naturalWidth if @naturalWidth > cw
+ scaleY = ch / @naturalHeight if @naturalHeight > ch
+
+ @scale = Math.min scaleX, scaleY
+ @w = (@naturalWidth * @scale)|0
+ @h = (@naturalHeight * @scale)|0
+
+ centerOnParent: () ->
+ @x = ((@parent.frame().w / 2) - (@w / 2))|0
+ @y = ((@parent.frame().h / 2) - (@h / 2))|0
+
+ draw: (ctx) ->
+ @isolateAndMoveToParent ctx, (ctx) ->
+ ctx.drawImage @img, 0, 0, @w, @h
+
+ @drawChildren ctx
+
+ onCanvasSizeChange: ->
+ super()
+ for child in @children
+ child.onCanvasSizeChange()
+
+ loadImage: ->
+ @img = document.createElement 'img'
+ @img.onload = =>
+ @naturalWidth = @img.naturalWidth
+ @naturalHeight = @img.naturalHeight
+ @onLoad.call @ if _.isFunction @onLoad
+ @img.src = @source
+
+drawing.CanvasImage = CanvasImage
+
+class Rectangle extends Drawable
+ constructor: (options) ->
+ super options
+ @fillStyle = options.fillStyle || 'rgba(0, 0, 0, 0)'
+ @strokeStyle = options.strokeStyle
+ @lineWidth = options.lineWidth
+
+ draw: (ctx) ->
+ @isolateAndMoveToParent ctx, (ctx) =>
+ ctx.fillStyle = @fillStyle if @fillStyle
+ ctx.strokeStyle = @strokeStyle if @strokeStyle
+ ctx.lineWidth = @lineWidth if @lineWidth
+ ctx.beginPath()
+ ctx.rect 0, 0, @w, @h
+ ctx.closePath()
+ ctx.fill() if @fillStyle
+ ctx.stroke() if @lineWidth && @strokeStyle
+
+drawing.Rectangle = Rectangle
+
+`export default drawing`
View
214 lib/rodeo_crop.coffee → lib/rodeo-crop.coffee
@@ -1,201 +1,9 @@
`import _ from "rodeo-crop/funderscore"`
+`import drawing from "rodeo-crop/drawing"`
RodeoCrop = {}
-class Drawable
- constructor: (options) ->
- @options = options
-
- @x = options.x
- @y = options.y
- @w = options.w
- @h = options.h
- @scale = options.scale
- @parent = options.parent
- @canvas = options.canvas
- @children = options.children || []
- @dragable = options.dragable || false
-
- onCanvasSizeChange: () ->
- @options.onCanvasSizeChange.call @ if _.isFunction @options.onCanvasSizeChange
-
- set: (options) ->
- for own key, value of options
- @[key] = value
-
- bounds: ->
- {
- x: 0
- y: 0
- w: @w
- h: @h
- }
-
- frame: ->
- {
- x: @x
- y: @y
- w: @w
- h: @h
- }
-
- convertToParent: (point) ->
- frame = @frame()
- {
- x: point.x + frame.x
- y: point.y + frame.y
- }
-
- convertFromParent: (point) ->
- frame = @frame()
- {
- x: point.x - frame.x
- y: point.y - frame.y
- }
-
- convertToCanvas: (point) ->
- parent = @
- x = point.x
- y = point.y
- while parent
- x += parent.frame().x
- y += parent.frame().y
-
- parent = parent.parent
-
- {
- x: x
- y: y
- }
-
- convertFromCanvas: (point) ->
- parent = @
- x = point.x
- y = point.y
- while parent
- x -= parent.frame().x
- y -= parent.frame().y
-
- parent = parent.parent
-
- {
- x: x
- y: y
- }
-
- positionContext: (ctx, fn) ->
- if @parent
- pos = @convertToCanvas @parent.bounds()
- ctx.translate pos.x, pos.y
- fn.call @, ctx
-
- isolateAndMoveToParent: (ctx, fn) ->
- ctx.save()
- @positionContext ctx, (ctx) ->
- fn.call @, ctx
- ctx.restore()
-
- containsCanvasPoint: (point) ->
- localPoint = @convertFromCanvas point
- @containsPoint localPoint
-
- containsPoint: (point) ->
- frame = @frame()
- 0 <= point.x <= frame.w &&
- 0 <= point.y <= frame.h
-
- addChild: (child) ->
- child.parent = @
- @children.push child
-
- removeChild: (child) ->
- i = @children.indexOf child
- if i >= 0
- child.parent = null
- @children.splice i, 1
-
- drawChildren: (ctx) ->
- for child in @children
- child.draw ctx
-
- draw: (ctx) ->
- # noop
-
-class CanvasImage extends Drawable
- constructor: (options) ->
- super options
-
- @source = options.source
- @naturalWidth = options.naturalWidth
- @naturalHeight = options.naturalHeight
- @onLoad = options.onLoad
-
- @loadImage()
-
- naturalBounds: () ->
- {
- x: 0
- y: 0
- w: @naturalWidth
- h: @naturalHeight
- }
-
- resizeToParent: () ->
- cw = @parent.frame().w
- ch = @parent.frame().h
-
- scaleX = 1
- scaleY = 1
-
- scaleX = cw / @naturalWidth if @naturalWidth > cw
- scaleY = ch / @naturalHeight if @naturalHeight > ch
-
- @scale = Math.min scaleX, scaleY
- @w = (@naturalWidth * @scale)|0
- @h = (@naturalHeight * @scale)|0
-
- centerOnParent: () ->
- @x = ((@parent.frame().w / 2) - (@w / 2))|0
- @y = ((@parent.frame().h / 2) - (@h / 2))|0
-
- draw: (ctx) ->
- @isolateAndMoveToParent ctx, (ctx) ->
- ctx.drawImage @img, 0, 0, @w, @h
-
- @drawChildren ctx
-
- onCanvasSizeChange: ->
- super()
- for child in @children
- child.onCanvasSizeChange()
-
- loadImage: ->
- @img = document.createElement 'img'
- @img.onload = =>
- @naturalWidth = @img.naturalWidth
- @naturalHeight = @img.naturalHeight
- @onLoad.call @ if _.isFunction @onLoad
- @img.src = @source
-
-class Rectangle extends Drawable
- constructor: (options) ->
- super options
- @fillStyle = options.fillStyle || 'rgba(0, 0, 0, 0)'
- @strokeStyle = options.strokeStyle
- @lineWidth = options.lineWidth
-
- draw: (ctx) ->
- @isolateAndMoveToParent ctx, (ctx) =>
- ctx.fillStyle = @fillStyle if @fillStyle
- ctx.strokeStyle = @strokeStyle if @strokeStyle
- ctx.lineWidth = @lineWidth if @lineWidth
- ctx.beginPath()
- ctx.rect 0, 0, @w, @h
- ctx.closePath()
- ctx.fill() if @fillStyle
- ctx.stroke() if @lineWidth && @strokeStyle
-
-class CropBox extends Drawable
+class CropBox extends drawing.Drawable
constructor: (options) ->
super _.extend
dragable: true
@@ -205,10 +13,10 @@ class CropBox extends Drawable
@handleSize = options.handleSize || 10
@screenStyle = options.screenStyle || 'rgba(0, 0, 0, .75)'
- @topScreen = new Rectangle fillStyle: @screenStyle
- @leftScreen = new Rectangle fillStyle: @screenStyle
- @rightScreen = new Rectangle fillStyle: @screenStyle
- @bottomScreen = new Rectangle fillStyle: @screenStyle
+ @topScreen = new drawing.Rectangle fillStyle: @screenStyle
+ @leftScreen = new drawing.Rectangle fillStyle: @screenStyle
+ @rightScreen = new drawing.Rectangle fillStyle: @screenStyle
+ @bottomScreen = new drawing.Rectangle fillStyle: @screenStyle
@cropX = options.cropX || 0
@cropY = options.cropY || 0
@@ -480,7 +288,7 @@ class CropBox extends Drawable
frame = @frame()
newRect = (x, y) =>
- return new Rectangle
+ return new drawing.Rectangle
parent: @
x: x - (@handleSize / 2) - 0.5
y: y - (@handleSize / 2) - 0.5
@@ -558,7 +366,7 @@ class CropBox extends Drawable
@drawCropLines ctx
@drawHandles ctx
-class Stage extends Drawable
+class Stage extends drawing.Drawable
initialize: (options) ->
@canvas = options.canvas
@@ -629,7 +437,7 @@ class Cropper
canvas: @canvas
createImage: () ->
- @image = new CanvasImage
+ @image = new drawing.CanvasImage
canvas: @canvas
source: @imageSource
onLoad: () =>
@@ -746,10 +554,6 @@ class Cropper
@valid = true
window.requestAnimationFrame => @runLoop()
-RodeoCrop.Drawable = Drawable
-RodeoCrop.CanvasImage = CanvasImage
-RodeoCrop.CropBox = CropBox
-RodeoCrop.Stage = Stage
RodeoCrop.Cropper = Cropper
`export default RodeoCrop`
View
2 package.json
@@ -16,6 +16,8 @@
"broccoli-es6-concatenator": "0.1.5",
"broccoli-uglify-js": "0.1.3",
"broccoli-coffee": "0.1.0",
+ "broccoli-static-compiler": "0.1.4",
+ "broccoli-file-mover": "~0.2.0",
"broccoli-merge-trees": "^0.1.3"
}
}
View
2 public/index.html
@@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
- <script src="build/rodeo_crop.js"></script>
+ <script src="javascripts/rodeo-crop.js"></script>
<style>
body, html { height: 100%; margin: 0; padding: 0; }

0 comments on commit f3134ee

Please sign in to comment.