diff --git a/src/css/style.css b/src/css/style.css index e542731f..e9c5f88b 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -60,6 +60,8 @@ body { .right-column { vertical-align: top; margin-left: 10px; + height: 100%; + position: relative; } .drawing-canvas-container { diff --git a/src/js/controller/CursorCoordinatesController.js b/src/js/controller/CursorCoordinatesController.js index b44a4855..5d948fec 100644 --- a/src/js/controller/CursorCoordinatesController.js +++ b/src/js/controller/CursorCoordinatesController.js @@ -3,41 +3,62 @@ ns.CursorCoordinatesController = function (piskelController) { this.piskelController = piskelController; - this.dragOrigin = null; + this.origin = null; + this.coordinates = {x:-1,y:-1}; + }; ns.CursorCoordinatesController.prototype.init = function () { this.coordinatesContainer = document.querySelector('.cursor-coordinates'); + $.subscribe(Events.CURSOR_MOVED, this.onCursorMoved_.bind(this)); $.subscribe(Events.DRAG_START, this.onDragStart_.bind(this)); $.subscribe(Events.DRAG_END, this.onDragEnd_.bind(this)); + $.subscribe(Events.FRAME_SIZE_CHANGED, this.redraw.bind(this)); + + this.redraw(); }; - ns.CursorCoordinatesController.prototype.onCursorMoved_ = function (event, x, y) { - var currentFrame = this.piskelController.getCurrentFrame(); + ns.CursorCoordinatesController.prototype.redraw = function () { var html = ''; - if (this.dragOrigin) { - html += this.dragOrigin.x + ':' + this.dragOrigin.y + ' to '; + if (this.origin) { + html += this.origin.x + ':' + this.origin.y + ' to '; } + var x = this.coordinates.x; + var y = this.coordinates.y; + var currentFrame = this.piskelController.getCurrentFrame(); if (currentFrame.containsPixel(x, y)) { html += x + ':' + y; - if (this.dragOrigin) { - var dX = Math.abs(x-this.dragOrigin.x) + 1; - var dY = Math.abs(y-this.dragOrigin.y) + 1; + if (this.origin) { + var dX = Math.abs(x-this.origin.x) + 1; + var dY = Math.abs(y-this.origin.y) + 1; html += ' (' + dX + 'x' + dY +')'; } } - this.coordinatesContainer.innerHTML = html; + this.coordinatesContainer.innerHTML = this.getFrameSizeHTML_() + html; + }; + + ns.CursorCoordinatesController.prototype.getFrameSizeHTML_ = function () { + var w = this.piskelController.getWidth(); + var h = this.piskelController.getHeight(); + return '['+w+'x'+h+'] '; + }; + + ns.CursorCoordinatesController.prototype.onCursorMoved_ = function (event, x, y) { + this.coordinates = {x:x, y:y}; + this.redraw(); }; ns.CursorCoordinatesController.prototype.onDragStart_ = function (event, x, y) { - this.dragOrigin = {x:x, y:y}; + this.origin = {x:x, y:y}; + this.redraw(); }; ns.CursorCoordinatesController.prototype.onDragEnd_ = function (event, x, y) { - this.dragOrigin = null; + this.origin = null; + this.redraw(); }; })(); \ No newline at end of file