Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I want to put here some information for those, who do separately drawing of picture and moving -zooming it.</p> <p>This may be useful when you want to store zooms and position of viewport.</p> <p>Here is drawer:</p> <pre><code>function redraw_ctx(){ self.ctx.clearRect(0,0,canvas_width, canvas_height) self.ctx.save() self.ctx.scale(self.data.zoom, self.data.zoom) // self.ctx.translate(self.data.position.left, self.data.position.top) // position second // Here We draw useful scene My task - image: self.ctx.drawImage(self.img ,0,0) // position 0,0 - we already prepared self.ctx.restore(); // Restore!!! } </code></pre> <p>Notice <strong>scale MUST be first</strong>.</p> <p>And here is zoomer: </p> <pre><code>function zoom(zf, px, py){ // zf - is a zoom factor, which in my case was one of (0.1, -0.1) // px, py coordinates - is point within canvas // eg. px = evt.clientX - canvas.offset().left // py = evt.clientY - canvas.offset().top var z = self.data.zoom; var x = self.data.position.left; var y = self.data.position.top; var nz = z + zf; // getting new zoom var K = (z*z + z*zf) // putting some magic var nx = x - ( (px*zf) / K ); var ny = y - ( (py*zf) / K); self.data.position.left = nx; // renew positions self.data.position.top = ny; self.data.zoom = nz; // ... and zoom self.redraw_ctx(); // redraw context } </code></pre> <p>and, of course, we would need a dragger:</p> <pre><code>this.my_cont.mousemove(function(evt){ if (is_drag){ var cur_pos = {x: evt.clientX - off.left, y: evt.clientY - off.top} var diff = {x: cur_pos.x - old_pos.x, y: cur_pos.y - old_pos.y} self.data.position.left += (diff.x / self.data.zoom); // we want to move the point of cursor strictly self.data.position.top += (diff.y / self.data.zoom); old_pos = cur_pos; self.redraw_ctx(); } }) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload