zoom in, zoom out
This commit is contained in:
parent
8bd2b71c5e
commit
af7e1b8d85
50
src/main.js
50
src/main.js
|
|
@ -51,7 +51,6 @@ let redoStack = [];
|
||||||
|
|
||||||
let layoutElements = []
|
let layoutElements = []
|
||||||
|
|
||||||
let appVersion = "0.6.1-alpha"
|
|
||||||
let minFileVersion = "1.0"
|
let minFileVersion = "1.0"
|
||||||
let maxFileVersion = "2.0"
|
let maxFileVersion = "2.0"
|
||||||
|
|
||||||
|
|
@ -61,6 +60,8 @@ let fileWidth = 1500
|
||||||
let fileHeight = 1000
|
let fileHeight = 1000
|
||||||
let fileFps = 12
|
let fileFps = 12
|
||||||
|
|
||||||
|
let zoomLevel = 1
|
||||||
|
|
||||||
let playing = false
|
let playing = false
|
||||||
|
|
||||||
let clipboard = []
|
let clipboard = []
|
||||||
|
|
@ -148,6 +149,8 @@ let config = {
|
||||||
paste: "v",
|
paste: "v",
|
||||||
delete: "Backspace",
|
delete: "Backspace",
|
||||||
group: "g",
|
group: "g",
|
||||||
|
zoomIn: "+",
|
||||||
|
zoomOut: "-",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1091,7 +1094,6 @@ class BaseShape {
|
||||||
ctx.fill()
|
ctx.fill()
|
||||||
}
|
}
|
||||||
if (this.stroked) {
|
if (this.stroked) {
|
||||||
console.log(this.curves)
|
|
||||||
for (let curve of this.curves) {
|
for (let curve of this.curves) {
|
||||||
ctx.strokeStyle = curve.color
|
ctx.strokeStyle = curve.color
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
|
|
@ -1856,6 +1858,10 @@ window.addEventListener("keydown", (e) => {
|
||||||
delete_action()
|
delete_action()
|
||||||
} else if (e.key == config.shortcuts.group && mod == true) {
|
} else if (e.key == config.shortcuts.group && mod == true) {
|
||||||
actions.group.create()
|
actions.group.create()
|
||||||
|
} else if (e.key == config.shortcuts.zoomIn && mod == true) {
|
||||||
|
zoomIn()
|
||||||
|
} else if (e.key == config.shortcuts.zoomOut && mod == true) {
|
||||||
|
zoomOut()
|
||||||
}
|
}
|
||||||
else if (e.key == "ArrowRight") {
|
else if (e.key == "ArrowRight") {
|
||||||
if (mod == true) {
|
if (mod == true) {
|
||||||
|
|
@ -2199,6 +2205,26 @@ async function render() {
|
||||||
document.querySelector("body").style.cursor = "default"
|
document.querySelector("body").style.cursor = "default"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function zoomIn() {
|
||||||
|
if (zoomLevel < 8) {
|
||||||
|
zoomLevel *= 2
|
||||||
|
updateUI()
|
||||||
|
updateMenu()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function zoomOut() {
|
||||||
|
if (zoomLevel > 1/8) {
|
||||||
|
zoomLevel /= 2
|
||||||
|
updateUI()
|
||||||
|
updateMenu()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function resetZoom() {
|
||||||
|
zoomLevel = 1;
|
||||||
|
updateUI()
|
||||||
|
updateMenu()
|
||||||
|
}
|
||||||
|
|
||||||
function stage() {
|
function stage() {
|
||||||
let stage = document.createElement("canvas")
|
let stage = document.createElement("canvas")
|
||||||
let scroller = document.createElement("div")
|
let scroller = document.createElement("div")
|
||||||
|
|
@ -2915,11 +2941,16 @@ function updateLayout(element) {
|
||||||
|
|
||||||
function updateUI() {
|
function updateUI() {
|
||||||
for (let canvas of canvases) {
|
for (let canvas of canvases) {
|
||||||
|
canvas.width = fileWidth * zoomLevel
|
||||||
|
canvas.height = fileHeight * zoomLevel
|
||||||
|
canvas.style.width = `${fileWidth * zoomLevel}px`
|
||||||
|
canvas.style.height = `${fileHeight * zoomLevel}px`
|
||||||
let ctx = canvas.getContext("2d")
|
let ctx = canvas.getContext("2d")
|
||||||
ctx.resetTransform();
|
ctx.resetTransform();
|
||||||
|
ctx.scale(zoomLevel, zoomLevel)
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.fillStyle = "white"
|
ctx.fillStyle = "white"
|
||||||
ctx.fillRect(0,0,canvas.width,canvas.height)
|
ctx.fillRect(0,0,fileWidth,fileHeight)
|
||||||
|
|
||||||
context.ctx = ctx;
|
context.ctx = ctx;
|
||||||
root.draw(context)
|
root.draw(context)
|
||||||
|
|
@ -3245,13 +3276,18 @@ async function updateMenu() {
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
text: "Zoom In",
|
text: "Zoom In",
|
||||||
enabled: false,
|
enabled: true,
|
||||||
action: () => {}
|
action: zoomIn
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: "Zoom Out",
|
text: "Zoom Out",
|
||||||
enabled: false,
|
enabled: true,
|
||||||
action: () => {}
|
action: zoomOut
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "Reset Zoom",
|
||||||
|
enabled: zoomLevel != 1,
|
||||||
|
action: resetZoom
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue