def zoom_in(self): if self._zoom <= 0.33: self._zoom += 0.33 elif self._zoom <= 0.5: self._zoom += 0.5 else: self._zoom += 1 self.set_transform() self.strokeWidth = 1 / self._zoom self.cursorSize = 2 / self._zoom self.move_cursor(self._last_cursor_pos) if not self._do_drawing: window.requestAnimationFrame(self.draw)
def zoom_out(self): if self._zoom > 1: self._zoom -= 1 elif self._zoom > 0.5: self._zoom -= 0.5 elif self._zoom > 0.33: self._zoom -= 0.33 self.set_transform() #self.strokeWidth = 0.25 if self._zoom > 1 else 1 self.strokeWidth = 1 / self._zoom self.cursorSize = 2 / self._zoom self.move_cursor(self._last_cursor_pos) if not self._do_drawing: window.requestAnimationFrame(self.draw)
def draw(self): if self._do_drawing: window.requestAnimationFrame(self.draw) self.ctx.setTransform(1, 0, 0, 1, 0, 0) self.ctx.clearRect(0, 0, self.ctx.canvas.width, self.ctx.canvas.height) self.set_transform() self.ctx.lineWidth = self.strokeWidth self.ctx.lineCap = self.lineCap self.ctx.strokeStyle = self.strokeColor if self._line_paths: self.ctx.stroke(self._line_paths) self.ctx.fillStyle = self.cursorColor if self._cursor_paths: self.ctx.fill(self._cursor_paths)
def move(self, x, y): self._position = (self._mouse_down_position[0] + x, self._mouse_down_position[1] + y) self.set_transform() if not self._do_drawing: window.requestAnimationFrame(self.draw)
def clear(self): self._line_paths = [] self._cursor_paths = [] if not self._do_drawing: window.requestAnimationFrame(self.draw)
def start_drawing(self): if not self._do_drawing: self._do_drawing = True window.requestAnimationFrame(self.draw)
def force_redraw(self): if not self._do_drawing: window.requestAnimationFrame(self.draw)