diff --git a/.DS_Store b/.DS_Store index 5008ddf..6d526b3 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/public/css/canvas.css b/public/css/canvas.css index ced2a80..53faec6 100644 --- a/public/css/canvas.css +++ b/public/css/canvas.css @@ -15,10 +15,15 @@ body { position: absolute; border: 1px solid black; } -.board { +.board-draw { position: absolute; border: 1px solid black; - cursor: url('/images/paintbrush.png'), auto; + cursor: url('/images/paintbrush.png') 0 45, auto; +} +.board-erase { + position: absolute; + border: 1px solid black; + cursor: url('/images/eraser-cursor.png') 5 38, auto; } .canvases { margin-top: 70px; @@ -39,6 +44,15 @@ body { margin-left: 10px; vertical-align: middle; } +.eraser { + float: left; + margin-top: 10px; + width: 50px; + height: 50px; + margin-left: 10px; + background: none; + vertical-align: middle; +} .colour-palette { left: 50px; position: fixed; diff --git a/public/images/eraser-cursor.png b/public/images/eraser-cursor.png new file mode 100644 index 0000000..013b46e Binary files /dev/null and b/public/images/eraser-cursor.png differ diff --git a/public/images/eraser.png b/public/images/eraser.png new file mode 100644 index 0000000..2b723d7 Binary files /dev/null and b/public/images/eraser.png differ diff --git a/public/js/angular/controller/canvasController.js b/public/js/angular/controller/canvasController.js index 2c4fdea..7ced0b4 100644 --- a/public/js/angular/controller/canvasController.js +++ b/public/js/angular/controller/canvasController.js @@ -18,6 +18,8 @@ homepage.controller('CanvasController', ['$scope', 'CanvasProvider', '$timeout', var userObj = Parse.User.current(); var username = userObj.get("username"); + $scope.userAction = 'draw'; + board.height = board.width = boardSize; background.height = background.width = boardSize; new Grid(opts).draw(gridContext); @@ -30,17 +32,24 @@ homepage.controller('CanvasController', ['$scope', 'CanvasProvider', '$timeout', return CanvasProvider.getCurrent()[1]; } - function drawOn(x, y, colour) { + $scope.action = function () { + if ($scope.userAction === 'draw') { + $scope.userAction = 'erase'; + } else { + $scope.userAction = 'draw'; + } + } + function drawOn(action, x, y, colour) { + action = $scope.userAction; x = x || event.offsetX; y = y || event.offsetY; colour = colour || pixelColor; - - boardInterface.createPixel(x, y, pixelSize, colour); - socket.emit('coordinates', [x, y, colour, imgID()]); + boardInterface.createPixel(action, x, y, pixelSize, colour); + socket.emit('coordinates', [action, x, y, colour, imgID()]); }; socket.on('coordinates', function(data) { - boardInterface.createPixel(data[0], data[1], pixelSize, data[2]); + boardInterface.createPixel(data[0], data[1], data[2], pixelSize, data[3]); }); $(board).mousedown(function() { @@ -77,6 +86,7 @@ homepage.controller('CanvasController', ['$scope', 'CanvasProvider', '$timeout', var x = event.offsetX; var y = event.offsetY; pixelColor = WhatColour.pickColour(paletteCtx, x, y); + $scope.userAction = 'draw'; $('.colour-palette').fadeToggle('slow'); $('.colour-palette-toggle').fadeToggle('slow'); }) diff --git a/public/js/angular/templates/canvas.html b/public/js/angular/templates/canvas.html index 1946cb1..69fc6e9 100644 --- a/public/js/angular/templates/canvas.html +++ b/public/js/angular/templates/canvas.html @@ -8,22 +8,24 @@ colour palette toggle + eraser {{imgDesc()}} - +
- +
-
-
    -
    -
    - -
    +
    +
      +
      +
      + + +

      diff --git a/public/js/pixel.js b/public/js/pixel.js index a190768..4753f26 100644 --- a/public/js/pixel.js +++ b/public/js/pixel.js @@ -2,23 +2,22 @@ function BoardInterface(context) { this.context = context; } -BoardInterface.prototype.createPixel = function(x, y, size, pixelColor) { +BoardInterface.prototype.createPixel = function(action, x, y, size, pixelColor) { x = Math.floor(x / size) * size; - y = Math.floor(y / size) * size + (3 * size); //this adjustment at the end is for the paintbrush cursor + y = Math.floor(y / size) * size; //this adjustment at the end is for the paintbrush cursor - PixelGenerator.createDot(this.context, x, y, size, pixelColor); + PixelGenerator.createDot(this.context, action, x, y, size, pixelColor); }; var PixelGenerator = (function() { - function createDot(ctx, x, y, size, pixelColor) { - var colour = WhatColour.pickColour(ctx, x, y); - if (colour === 'rgba(0,0,0,0)') { + function createDot(ctx, action, x, y, size, pixelColor) { + if (action === 'erase') { + ctx.clearRect(x, y, size, size); + } else if (action === 'draw') { ctx.fillStyle = pixelColor; ctx.fillRect(x, y, size, size); - } else { - ctx.clearRect(x, y, size, size); } }; diff --git a/server.js b/server.js index 27110bd..635e087 100644 --- a/server.js +++ b/server.js @@ -56,7 +56,7 @@ io.on('connection', function(socket) { }); socket.on('coordinates', function(data) { - imgID = data[3]; + imgID = data[4]; socket.broadcast.to(imgID).emit('coordinates', data); });