aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Lyngstol <kristian@bohemians.org>2015-04-09 19:02:34 +0200
committerKristian Lyngstol <kristian@bohemians.org>2015-04-09 19:02:34 +0200
commit9c7c9174b1fe53722e39a2af9f1269186ce604fb (patch)
treea3e296ae851309a3f3860de68414e127be7bc3f0
parentcea6b388f5336f1c0321e8409628fd0907df33b6 (diff)
NMS prototype: Fix scale computation
Now accounting properly for screen offsets added by menus etc.
-rw-r--r--web/nms.gathering.org/nms2/prototype/test.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/web/nms.gathering.org/nms2/prototype/test.js b/web/nms.gathering.org/nms2/prototype/test.js
index b9ad145..a55510a 100644
--- a/web/nms.gathering.org/nms2/prototype/test.js
+++ b/web/nms.gathering.org/nms2/prototype/test.js
@@ -15,8 +15,8 @@ var canvas = {
scale:1
};
var margin = {
- x:40,
- y:100,
+ x:10,
+ y:20,
text:3
};
@@ -305,13 +305,14 @@ function canvasClick(e)
*
* Recomputes the scale and applies it.
*
- * The recomputation is pretty bad, since it doesn't take the size of the
- * header/toolbar into account at all, except through margin.*
+ * Has to use c.offset* since we are just scaling the canvas, not
+ * everything else.
+ *
*/
function resizeEvent()
{
- var width = window.innerWidth;
- var height = window.innerHeight;
+ var width = window.innerWidth - c.offsetLeft;
+ var height = window.innerHeight - c.offsetTop;
if (width / (orig.width + margin.x) > height / (orig.height + margin.y)) {
canvas.scale = height / (orig.height + margin.y);
} else {
@@ -457,6 +458,12 @@ function connectSwitches(insw1, insw2,color1, color2) {
ctx.moveTo(0,0);
}
+function debugIt(e)
+{
+ console.log("Debug triggered");
+ console.log(e);
+}
+
window.addEventListener('resize',resizeEvent,true);
document.addEventListener('load',resizeEvent,true);