From 0e3419e7b485fe69c4fd0ee2bf8d027ad047124e Mon Sep 17 00:00:00 2001 From: Bala Clark Date: Wed, 7 Jul 2010 09:02:07 +0100 Subject: [PATCH] added method to scale the comic --- scripts.js | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/scripts.js b/scripts.js index f7a1eab..a02c3f2 100644 --- a/scripts.js +++ b/scripts.js @@ -28,6 +28,11 @@ function ComicBook() { var buffer = 4; var pointer = 0; var loaded = 0; + + var canvas_width; + var canvas_height; + + var scale = 1; /* * @param {String} id The canvas ID to draw the comic on. @@ -44,9 +49,19 @@ function ComicBook() { preload(srcs); // add page controls - canvas.addEventListener("click", comicOnClick, false); + canvas.addEventListener("click", navigation, false); } + /* + * Zoom the canvas + * + * @param new_scale {Number} Scale the canvas to this ratio + */ + this.zoom = function(new_scale) { + scale = new_scale; + drawPage(); + } + /** * Preload all images, draw the page only after a given number have been loaded. * @@ -83,9 +98,13 @@ function ComicBook() { if (typeof page != "object") throw "invalid page type"; - canvas.width = page.width; - canvas.height = page.height; - context.drawImage(page, 0, 0); + width = page.width * scale; + height = page.height * scale; + + canvas.width = width; + canvas.height = height; + + context.drawImage(page, 0, 0, width, height); } /** @@ -112,10 +131,18 @@ function ComicBook() { } } - function comicOnClick(e) { - switch (getCursorPosition(e)) { - case "left": drawPrevPage(); break; - case "right": drawNextPage(); break; + function navigation(e) { + + switch (e.type) { + + case "click": + switch (getCursorPosition(e)) { + case "left": drawPrevPage(); break; + case "right": drawNextPage(); break; + } + break; + + defualt: console.log(e.type); } } @@ -140,4 +167,4 @@ function ComicBook() { // check if the user clicked on the left or right side return (x <= canvas.width / 2) ? 'left' : 'right'; } -} \ No newline at end of file +}