Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

Commit

Permalink
v0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
irskep committed Jun 6, 2018
2 parents 879878f + 48fa39f commit f9fa062
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v0.5.2
* Reset undo stack when loadSnapshot is called, fixing a memory leak
* Moving shapes with the selection tool is on the undo stack

v0.5.1:
* Fixes for React dependency
* Undo support for moving selected shapes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Literally Canvas v0.5.1
Literally Canvas v0.5.2
=======================

Literally Canvas is an extensible, open source (BSD-licensed), HTML5 drawing
Expand Down
10 changes: 10 additions & 0 deletions demo/core_demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
<a href="javascript:void(0);" class='tool' id="hide-lc">Teardown</a>
<a href="javascript:void(0);" class='tool' id="show-lc">Setup</a>
<a href="javascript:void(0);" class='tool' id="clear-lc">Clear</a>
<a href="javascript:void(0);" class='tool' id="undo-lc">Undo</a>
<a href="javascript:void(0);" class='tool' id="redo-lc">Redo</a>
</div>

<div class="toolset">
Expand Down Expand Up @@ -204,6 +206,14 @@
lc.clear();
});

$("#undo-lc").click(function() {
lc.undo();
});

$("#redo-lc").click(function() {
lc.redo();
});

// Set up our own tools...
tools = [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "literallycanvas",
"version": "0.5.1",
"version": "0.5.2",
"description": "HTML5 drawing widget",
"main": "lib/js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/core/LiterallyCanvas.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,11 @@ module.exports = class LiterallyCanvas
@setColor(k, snapshot.colors[k])

if snapshot.shapes
# reset shapes
@shapes = []
# reset undostack aswell when loading a snapshot
@undostack = []

for shapeRepr in snapshot.shapes
shape = JSONToShape(shapeRepr)
@execute(new actions.AddShapeAction(this, shape)) if shape
Expand Down
9 changes: 8 additions & 1 deletion src/core/shapes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,23 @@ defineShape 'Image',
@y = args.y or 0
@scale = args.scale or 1
@image = args.image or null
@crossOrigin = (args.image and args.image.crossOrigin) or null
getBoundingRect: ->
{@x, @y, width: @image.width * @scale, height: @image.height * @scale}
toJSON: -> {@x, @y, imageSrc: @image.src, imageObject: @image, @scale}
toJSON: () ->
toJSONData = {@x, @y, imageSrc: @image.src, imageObject: @image, @scale}
if @crossOrigin
toJSONData['crossOrigin'] = @crossOrigin
return toJSONData
fromJSON: (data) ->
img = null
if data.imageObject?.width
img = data.imageObject
else
img = new Image()
img.src = data.imageSrc
if data.crossOrigin
img.crossOrigin = data.crossOrigin
createShape('Image', {x: data.x, y: data.y, image: img, scale: data.scale})
move: ( moveInfo={} ) ->
@x = @x - moveInfo.xDiff
Expand Down

0 comments on commit f9fa062

Please sign in to comment.