Skip to content

Commit

Permalink
added canvas resizing on window resize
Browse files Browse the repository at this point in the history
  • Loading branch information
apedyashev committed Oct 28, 2014
1 parent 050f462 commit d3c039b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions realistic-pen.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function RealisticPen(inCanvas, inOptions) {
_painters = null,
_updateInterval = null,
_canvas = null,
_container = null,
_canvasDefWidth = 200,
_canvasDefHeight = 200,
_options = {
Expand Down Expand Up @@ -70,16 +71,15 @@ function RealisticPen(inCanvas, inOptions) {


function _init( inCanvas, inOptions ) {
var container = inCanvas.parentNode;
_container = inCanvas.parentNode;

if (inOptions) {
_options = _extend(_options, inOptions);
}

_options.penColor = _ensureRgb(_options.penColor);

inCanvas.width = container.offsetWidth ? container.offsetWidth : _canvasDefWidth;
inCanvas.height = container.offsetHeight ? container.offsetHeight : _canvasDefHeight;


_canvas = inCanvas;
_context = _canvas.getContext("2d");
Expand Down Expand Up @@ -179,10 +179,17 @@ function RealisticPen(inCanvas, inOptions) {
_canvas.removeEventListener('touchmove', onCanvasTouchMove, false);
_canvas.removeEventListener('touchend', onCanvasTouchEnd, false);
}
},
onCanvasResize = function() {
_canvas.width = _container.offsetWidth ? _container.offsetWidth : _canvasDefWidth;
_canvas.height = _container.offsetHeight ? _container.offsetHeight : _canvasDefHeight;
};

_canvas.addEventListener('mousedown', onCanvasMouseDown, false);
_canvas.addEventListener('touchstart', onCanvasTouchStart, false);
window.addEventListener('resize', onCanvasResize, false);

onCanvasResize();
}

function _extend(object, properties) {
Expand Down
2 changes: 1 addition & 1 deletion realistic-pen.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d3c039b

Please sign in to comment.