adding textShapes

This commit is contained in:
Anton Georgiev 2014-08-19 16:54:01 +00:00
parent df1a015041
commit 40afd09431
3 changed files with 67 additions and 33 deletions

View File

@ -31,11 +31,12 @@ Template.slide.helpers
shapes = Meteor.Shapes.find({whiteboardId: currentSlide?.slide?.id}).fetch()
for s in shapes
shapeInfo = s.shape?.shape
shapeInfo = s.shape?.shape or @data.shape
shapeType = shapeInfo?.type
for num in [0..3] # the coordinates must be in the range 0 to 1
shapeInfo.points[num] = shapeInfo.points[num] / 100
if shapeType isnt "text"
for num in [0..3] # the coordinates must be in the range 0 to 1
shapeInfo.points[num] = shapeInfo.points[num] / 100
wpm.makeShape(shapeType, shapeInfo)
wpm.updateShape(shapeType, shapeInfo)
@ -43,11 +44,12 @@ Template.slide.helpers
#### SHAPE ####
Template.shape.rendered = ->
# @data is the shape object coming from the {{#each}} in the html file
shapeInfo = @data.shape?.shape
shapeInfo = @data.shape?.shape or @data.shape
shapeType = shapeInfo?.type
for num in [0..3] # the coordinates must be in the range 0 to 1
shapeInfo.points[num] = shapeInfo.points[num] / 100
if shapeType isnt "text"
for num in [0..3] # the coordinates must be in the range 0 to 1
shapeInfo.points[num] = shapeInfo.points[num] / 100
wpm = Template.slide.whiteboardPaperModel
wpm.makeShape(shapeType, shapeInfo)

View File

@ -355,7 +355,8 @@ class @WhiteboardPaperModel
when "triangle"
@currentTriangle.update(data)
when "text"
@currentText.update.apply(@currentText, data)
#@currentText.update.apply(@currentText, data)
@currentText.update(data)
else
console.log "shape not recognized at updateShape", shape
@ -382,7 +383,8 @@ class @WhiteboardPaperModel
when "text"
@currentText = @_createTool(shape)
toolModel = @currentText
tool = @currentText.make.apply(@currentText, data)
#tool = @currentText.make.apply(@currentText, data)
tool = @currentText.make(data)
else
console.log "shape not recognized at makeShape", shape
if tool?

View File

@ -3,7 +3,6 @@ class @WhiteboardTextModel extends WhiteboardToolModel
constructor: (@paper) ->
super @paper
# the defintion of this shape, kept so we can redraw the shape whenever needed
# format: x, y, width, height, colour, fontSize, calcFontSize, text
@definition = [0, 0, 0, 0, "#000", 0, 0, ""]
@ -12,20 +11,37 @@ class @WhiteboardTextModel extends WhiteboardToolModel
# @textY = null
# Make a text on the whiteboard
make: (x, y, width, height, colour, fontSize, calcFontSize, text) ->
#make: (x, y, width, height, colour, fontSize, calcFontSize, text) ->
make: (startingData) ->
console.log "making a text:" + JSON.stringify startingData
x = startingData.x
y = startingData.y
width = startingData.textBoxWidth
height = startingData.textBoxHeight
colour = startingData.fontColor
fontSize = startingData.fontSize
calcFontSize = startingData.calcedFontSize
text = startingData.text
#backgroundColor?!
@definition =
shape: "text"
data: [x, y, width, height, colour, fontSize, calcFontSize, text]
calcFontSize = (calcFontSize/100 * @gh)
#calcFontSize = (calcFontSize/100 * @gh)
x = (x * @gw) + @xOffset
y = (y * @gh) + @yOffset + calcFontSize
width = width/100 * @gw
colour = Utils.strokeAndThickness(colour)["stroke"]
#colour = Utils.strokeAndThickness(colour)["stroke"]
colour = Meteor.call("strokeAndThickness",colour, false)
@obj = @paper.text(x, y, "")
@obj = @paper.text(x/100, y/100, "")
@obj.attr
fill: colour
fill: Meteor.call("strokeAndThickness",colour, false)
"font-family": "Arial" # TODO: make dynamic
"font-size": calcFontSize
@obj.node.style["text-anchor"] = "start" # force left align
@ -37,43 +53,57 @@ class @WhiteboardTextModel extends WhiteboardToolModel
# @param {number} y1 the y value of the top left corner
# @param {number} x2 the x value of the bottom right corner
# @param {number} y2 the y value of the bottom right corner
update: (x, y, width, height, colour, fontSize, calcFontSize, text) ->
#update: (x, y, width, height, colour, fontSize, calcFontSize, text) ->
update: (startingData) ->
console.log "updating text" + JSON.stringify startingData
x = startingData.x
y = startingData.y
width = startingData.textBoxWidth
height = startingData.textBoxHeight
colour = startingData.fontColor
fontSize = startingData.fontSize
calcFontSize = startingData.calcedFontSize
text = startingData.text
if @obj?
@definition.data = [x, y, width, height, colour, fontSize, calcFontSize, text]
calcFontSize = (calcFontSize/100 * @gh)
x = (x * @gw) + @xOffset
width = width/100 * @gw
colour = Utils.strokeAndThickness(colour)["stroke"]
#colour = Utils.strokeAndThickness(colour)["stroke"]
@obj.attr
fill: colour
fill: Meteor.call("strokeAndThickness",colour, false)
"font-size": calcFontSize
cell = @obj.node
while cell? and cell.hasChildNodes()
cell.removeChild(cell.firstChild)
textFlow(text, cell, width, x, calcFontSize, false)
Meteor.call("textFlow", text, cell, width, x, calcFontSize, false)
# Draw a text on the whiteboard
# @param {string} colour the colour of the object
# @param {number} thickness the thickness of the object's line(s)
draw: (x, y, width, height, colour, fontSize, calcFontSize, text) ->
calcFontSize = (calcFontSize/100 * @gh)
x = x * @gw + @xOffset
y = (y * @gh) + @yOffset + calcFontSize
width = width/100 * @gw
colour = Utils.strokeAndThickness(colour)["stroke"]
# draw: (x, y, width, height, colour, fontSize, calcFontSize, text) ->
# calcFontSize = (calcFontSize/100 * @gh)
# x = x * @gw + @xOffset
# y = (y * @gh) + @yOffset + calcFontSize
# width = width/100 * @gw
# #colour = Utils.strokeAndThickness(colour)["stroke"]
el = @paper.text(x, y, "")
el.attr
fill: colour
"font-family": "Arial" # TODO: make dynamic
"font-size": calcFontSize
el.node.style["text-anchor"] = "start" # force left align
el.node.style["textAnchor"] = "start" # for firefox, 'cause they like to be different
textFlow(text, el.node, width, x, calcFontSize, false)
el
# el = @paper.text(x, y, "")
# el.attr
# fill: Meteor.call("strokeAndThickness",colour, false)
# "font-family": "Arial" # TODO: make dynamic
# "font-size": calcFontSize
# el.node.style["text-anchor"] = "start" # force left align
# el.node.style["textAnchor"] = "start" # for firefox, 'cause they like to be different
# Meteor.call("textFlow", text, el.node, width, x, calcFontSize, false)
# el
# When first dragging the mouse to create the textbox size
# @param {number} x the x value of cursor at the time in relation to the left side of the browser