added method to scale the comic
This commit is contained in:
parent
00f801d1c8
commit
0e3419e7b4
1 changed files with 36 additions and 9 deletions
37
scripts.js
37
scripts.js
|
@ -29,6 +29,11 @@ function ComicBook() {
|
|||
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.
|
||||
* @param {Object} srcs An array of all the comic page srcs, in order
|
||||
|
@ -44,7 +49,17 @@ 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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,11 +131,19 @@ function ComicBook() {
|
|||
}
|
||||
}
|
||||
|
||||
function comicOnClick(e) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue