Commit 9ac8e6c9 authored by Christian Winter's avatar Christian Winter

general rework. wip

parent ca7f708d
......@@ -55,9 +55,9 @@
<script src="scripts/managers/GUI.js"></script>
<script src="scripts/saving/Exporter.js"></script>
<script src="scripts/Color.js"></script>
<script src="scripts/Settings.js"></script>
<script src="scripts/LineManipulator.js"></script>
<script src="scripts/Color.js"></script>
<script src="scripts/managers/Logic.js"></script>
<script src="scripts/managers/Selection.js"></script>
......@@ -74,8 +74,9 @@
<script src="scripts/Application.js"></script>
<script>
var Application;
function onLoad() {
var App = new Application();
Application = new App();
}
</script>
......
class Application {
class App {
constructor() {
console.log("Application.constructor()");
this.initializeClasses();
this.currentState; // Drawing, EditingPrefab
this.views = [];
this.currentView = new View();
this.initializeClasses();
window.addEventListener("keydown", evt => Input.keyDown(evt), false);
window.addEventListener("keyup", evt => Input.keyUp(evt), false);
GUI.genereateGridSettings();
Logic.start();
Logic.start();
Renderer.setContext(this.currentView.context);
}
initializeClasses() {
GUI.init();
Preferences.init();
//Key.init();
Input.init();
MouseHandler.init();
Logic.init();
Saver.init();
File.init();
//Camera.init();
Renderer.init();
RenderManager.init();
Exporter.init();
Settings.init();
Selection.init();
GridManager.init();
......
......@@ -20,7 +20,7 @@
GUI.buildPrefabUI();
Camera.resetView();
Application.currentView.camera.resetView();
}
static createNewPrefabFromSelection() {
......
// TODO check which variables are not used and remove them
class Settings {
static init() {
Settings = new class {
constructor() {
this.emblemRed = new Color(124, 0, 0, 1);//'#7c0000';
this.artBoundsLineWidth = 2;
......
class View {
constructor() {
// canvas
this.canvas = document.getElementById('canvas');
this.canvas.contentEditable = true; // to make canvas.focus() working
......@@ -13,7 +14,7 @@
this.canvas.style.background = Settings.canvasColor;
// context
this.context = this.canvas.getContext('2d');
this.camera = new Camera(this);
......@@ -22,7 +23,9 @@
// this.uiButtons = [];
// this.uiButtonPanel= [];
Renderer.setContext(this.context);
// renderer
// this.renderer = new Renderer();
// this.renderer.setContext(this.context);
}
// onmouseenter
......
......@@ -19,7 +19,7 @@
}
drawGrid() {
let bounds = Camera.getVisibleBounds();
let bounds = Application.currentView.camera.getVisibleBounds();
let min = new Vector2(bounds.left, bounds.top);
let max = new Vector2(bounds.right, bounds.bottom);
let sMin = this.getNearestPointFor(min);
......
......@@ -19,7 +19,7 @@
}
drawGrid() {
let bounds = Camera.getVisibleBounds();
let bounds = Application.currentView.camera.getVisibleBounds();
let min = new Vector2(bounds.left, bounds.top);
let max = new Vector2(bounds.right, bounds.bottom);
let minMax = new Vector2(bounds.left, bounds.bottom);
......
class Key {
static init() {
Key = new class {
constructor() {
this.A = 65;
this.B = 66;
this.C = 67;
......
......@@ -6,7 +6,7 @@ class MouseHandler {
this.processingWaitingState = false;
this.mouseMovedAfterMouseDown = false;
waitingForStart.push(this);
//waitingForStart.push(this);
}
static start() {
......@@ -58,7 +58,7 @@ class MouseHandler {
}
}
//GUI.writeToStats("Camera.canvasOffset", Camera.canvasOffset.toString());
//GUI.writeToStats("Application.currentView.camera.canvasOffset", Application.currentView.camera.canvasOffset.toString());
this.oldPosScreenSpace = newPosScreenSpace;
Renderer.redraw();
}
......@@ -391,9 +391,9 @@ class MouseHandler {
}
else if (!e.shiftKey && !e.ctrlKey) {
if (e.deltaY < 0) // upscroll
Camera.multiplyZoomBy(1.1, true);
Application.currentView.camera.multiplyZoomBy(1.1, true);
else if (e.deltaY > 0)
Camera.multiplyZoomBy(0.9, true);
Application.currentView.camera.multiplyZoomBy(0.9, true);
this.mouseMove(e);
}
......
......@@ -8,7 +8,7 @@
this.canvasOffset = new Vector2(0, 0);
// TODO better way to initialize?
this.multiplyZoomBy(1, true);
//this.multiplyZoomBy(1, true);
}
multiplyZoomBy(delta, keepCenter)
......@@ -38,7 +38,6 @@
if (keepCenter)
this.pushCameraCenter();
console.log(this)
this.zoom = Math.min(this.maxZoom, Math.max(this.minZoom, val));
if (keepCenter)
......
var pivot = new Vector2(0, 0);
var canvas;
var context;
var offscreenCanvas;
var offscreenContext;
......@@ -34,7 +32,7 @@ function onLoad() {
Logic.init();
Saver.init();
File.init();
Camera.init();
Application.currentView.camera.init();
Renderer.init();
RenderManager.init();
......@@ -65,12 +63,6 @@ class Logic {
}
static start() {
window.addEventListener("keydown", evt => Input.keyDown(evt), false);
window.addEventListener("keyup", evt => Input.keyUp(evt), false);
// window.addEventListener("keydown", evt => CanvasKeyHandler.KeyDown(evt), false);
// window.addEventListener("keyup", evt => CanvasKeyHandler.KeyUp(evt), false);
window.addEventListener("contextmenu", function (e) { e.preventDefault(); return false; });
window.addEventListener('resize', this.layoutGUI, false);
window.addEventListener('focus', function () {
......@@ -89,25 +81,12 @@ class Logic {
window.onerror = function () {
if (Preferences.developerMode == true)
GUI.notify("<font color='red'>An error occured! Press F12 to see what went wrong.</font>");
Logic._clearStates();
//Logic._clearStates();
};
canvas = document.getElementById('canvas');
canvas.contentEditable = true; // to make canvas.focus() working
context = canvas.getContext('2d');
Renderer.setContext(context);
offscreenCanvas = document.getElementById('offscreenCanvas');
offscreenContext = offscreenCanvas.getContext('2d');
canvas.addEventListener("mousemove", evt => MouseHandler.mouseMove(evt));
canvas.addEventListener("mouseup", evt => MouseHandler.mouseUp(evt));
canvas.addEventListener("mousedown", evt => MouseHandler.mouseDown(evt));
canvas.addEventListener("wheel", evt => MouseHandler.mouseScroll(evt));
canvas.addEventListener("mouseenter", evt => MouseHandler.canvasMouseEnter(evt));
canvas.addEventListener("mouseleave", evt => MouseHandler.canvasMouseLeave(evt));
toolbar = document.getElementById('toolbar');
// Setup the dnd listeners.
......@@ -115,13 +94,11 @@ class Logic {
dropZone.addEventListener('dragover', Saver.handleDragOver, false);
dropZone.addEventListener('drop', Saver.handleFileSelect, false);
canvas.style.background = Settings.canvasColor;
this.layoutGUI();
Saver.loadAutoSave();
File.updateStats();
Renderer.redraw();
for (var i = 0; i < waitingForStart.length; i++) {
waitingForStart[i].start();
......@@ -149,14 +126,6 @@ class Logic {
GUI.stats.style.left = canvas.right - 50;
// TODO magic
GUI.stats.style.top = GUI.menubar.offsetHeight + 75;
/*
offscreenCanvas.width = canvas.width;
offscreenCanvas.height = canvas.height;
offscreenCanvas.style.left = canvas.width - 50;
offscreenCanvas.style.top= canvas.height - 50;
*/
Renderer.redraw();
}
static setState(state) {
......
......@@ -37,8 +37,8 @@
return;
}
} else {
let p1_ = Camera.screenSpaceToCanvasSpace(p1);
let p2_ = Camera.screenSpaceToCanvasSpace(p2);
let p1_ = Application.currentView.camera.screenSpaceToCanvasSpace(p1);
let p2_ = Application.currentView.camera.screenSpaceToCanvasSpace(p2);
if (!this.screenBounds.containsLine(p1_, p2_, thickness)) {
++this.culledLinesCounter;
return;
......@@ -49,20 +49,20 @@
p2 = p2.copy();
if (!screenSpace) {
p1.x += Camera.canvasOffset.x;
p1.y += Camera.canvasOffset.y;
p2.x += Camera.canvasOffset.x;
p2.y += Camera.canvasOffset.y;
p1.x += Application.currentView.camera.canvasOffset.x;
p1.y += Application.currentView.camera.canvasOffset.y;
p2.x += Application.currentView.camera.canvasOffset.x;
p2.y += Application.currentView.camera.canvasOffset.y;
p1.x *= Camera.zoom;
p1.y *= Camera.zoom;
p2.x *= Camera.zoom;
p2.y *= Camera.zoom;
p1.x *= Application.currentView.camera.zoom;
p1.y *= Application.currentView.camera.zoom;
p2.x *= Application.currentView.camera.zoom;
p2.y *= Application.currentView.camera.zoom;
}
if (!screenSpaceThickness)
thickness *= Camera.zoom;
thickness *= Application.currentView.camera.zoom;
this.currentContext.beginPath();
this.currentContext.lineWidth = thickness;
......@@ -104,7 +104,7 @@
this.currentContext.beginPath();
if (!screenSpaceThickness)
thickness *= Camera.zoom;
thickness *= Application.currentView.camera.zoom;
this.currentContext.lineWidth = thickness;
......@@ -118,15 +118,15 @@
p2 = line.end.position.copy();
if (!screenSpace) {
p1.x += Camera.canvasOffset.x;
p1.y += Camera.canvasOffset.y;
p2.x += Camera.canvasOffset.x;
p2.y += Camera.canvasOffset.y;
p1.x *= Camera.zoom;
p1.y *= Camera.zoom;
p2.x *= Camera.zoom;
p2.y *= Camera.zoom;
p1.x += Application.currentView.camera.canvasOffset.x;
p1.y += Application.currentView.camera.canvasOffset.y;
p2.x += Application.currentView.camera.canvasOffset.x;
p2.y += Application.currentView.camera.canvasOffset.y;
p1.x *= Application.currentView.camera.zoom;
p1.y *= Application.currentView.camera.zoom;
p2.x *= Application.currentView.camera.zoom;
p2.y *= Application.currentView.camera.zoom;
}
this.currentContext.moveTo(p1.x, p1.y);
......@@ -145,8 +145,8 @@
return;
if (!screenSpaceSize) {
radius *= Camera.zoom;
thickness *= Camera.zoom;
radius *= Application.currentView.camera.zoom;
thickness *= Application.currentView.camera.zoom;
}
// TODO margin doesnt help much. circles sometimes still seem chopped off
......@@ -177,11 +177,11 @@
circle = this.batchedCircles[key];
center.setValues(circle.x, circle.y);
if (!screenSpace) {
center.x += Camera.canvasOffset.x;
center.y += Camera.canvasOffset.y;
center.x += Application.currentView.camera.canvasOffset.x;
center.y += Application.currentView.camera.canvasOffset.y;
center.x *= Camera.zoom;
center.y *= Camera.zoom;
center.x *= Application.currentView.camera.zoom;
center.y *= Application.currentView.camera.zoom;
}
this.currentContext.drawImage(offscreenCanvas, center.x - (radius + thickness + margin), center.y - (radius + thickness + margin));
++this.copiedCirclesCounter;
......@@ -200,16 +200,16 @@
center = center.copy();
if (!screenSpace) {
center.x += Camera.canvasOffset.x;
center.y += Camera.canvasOffset.y;
center.x += Application.currentView.camera.canvasOffset.x;
center.y += Application.currentView.camera.canvasOffset.y;
center.x *= Camera.zoom;
center.y *= Camera.zoom;
center.x *= Application.currentView.camera.zoom;
center.y *= Application.currentView.camera.zoom;
radius *= Camera.zoom;
radius *= Application.currentView.camera.zoom;
}
if (!screenSpaceThickness) {
thickness *= Camera.zoom;
thickness *= Application.currentView.camera.zoom;
}
this.currentContext.beginPath();
......@@ -249,7 +249,7 @@
}
this.currentContext.clearRect(0, 0, canvas.width, canvas.height);
this.screenBounds = Camera.getVisibleBounds();
this.screenBounds = Application.currentView.camera.getVisibleBounds();
this.drawnLinesCounter = 0;
this.culledLinesCounter = 0;
......@@ -317,8 +317,8 @@
let o = Preferences.artBounds.origin;
let s = Preferences.artBounds.size;
o = Camera.canvasSpaceToScreenSpace(o);
s = s.multiply(Camera.zoom);
o = Application.currentView.camera.canvasSpaceToScreenSpace(o);
s = s.multiply(Application.currentView.camera.zoom);
let os = o.addVector(s);
......@@ -337,7 +337,7 @@
continue;
if (layer.hideInRenderPreview)
this.currentContext.setLineDash([(Settings.guideDashSize) * Camera.zoom, (Settings.guideDashSize) * Camera.zoom]);
this.currentContext.setLineDash([(Settings.guideDashSize) * Application.currentView.camera.zoom, (Settings.guideDashSize) * Application.currentView.camera.zoom]);
for (let line of layer.lines)
this.batchLine(new Line(line.start.position, line.end.position), false);
......@@ -349,7 +349,7 @@
}
// current layer
if (File.currentLayer.hideInRenderPreview)
this.currentContext.setLineDash([(Settings.guideDashSize) * Camera.zoom, (Settings.guideDashSize) * Camera.zoom]);
this.currentContext.setLineDash([(Settings.guideDashSize) * Application.currentView.camera.zoom, (Settings.guideDashSize) * Application.currentView.camera.zoom]);
for (let line of File.currentLayer.lines)
this.batchLine(new Line(line.start.position, line.end.position), false);
......@@ -402,8 +402,8 @@
let origin = Preferences.artBounds.origin;
let size = Preferences.artBounds.size;
origin = Camera.canvasSpaceToScreenSpace(origin);
size = size.multiply(Camera.zoom);
origin = Application.currentView.camera.canvasSpaceToScreenSpace(origin);
size = size.multiply(Application.currentView.camera.zoom);
// TODO not culled
if (this.currentContext == context) {
......@@ -414,8 +414,8 @@
}
static generateGradient(start, end, toColor) {
start = Camera.canvasSpaceToScreenSpace(start);
end = Camera.canvasSpaceToScreenSpace(end);
start = Application.currentView.camera.canvasSpaceToScreenSpace(start);
end = Application.currentView.camera.canvasSpaceToScreenSpace(end);
let gradient = this.currentContext.createLinearGradient(start.x, start.y, end.x, end.y);
gradient.addColorStop(0, Settings.selectionColorFill);
......@@ -436,8 +436,8 @@
let origin = Preferences.artBounds.origin;
let size = Preferences.artBounds.size;
origin = Camera.canvasSpaceToScreenSpace(origin);
size = size.multiply(Camera.zoom);
origin = Application.currentView.camera.canvasSpaceToScreenSpace(origin);
size = size.multiply(Application.currentView.camera.zoom);
// TODO not culled
this.currentContext.lineWidth = Settings.artBoundsLineWidth;
......@@ -454,14 +454,14 @@
return;
if (File.currentLayer.hideInRenderPreview)
this.currentContext.setLineDash([Settings.guideDashSize * Camera.zoom, Settings.guideDashSize * Camera.zoom]);
this.currentContext.setLineDash([Settings.guideDashSize * Application.currentView.camera.zoom, Settings.guideDashSize * Application.currentView.camera.zoom]);
for (let line of Selection.data.lines)
this.drawLineFromTo(line.start.position.addVector(delta), line.end.position.addVector(delta), line.thickness + this.outlineSize / Camera.zoom, Settings.selectionColor);
this.drawLineFromTo(line.start.position.addVector(delta), line.end.position.addVector(delta), line.thickness + this.outlineSize / Application.currentView.camera.zoom, Settings.selectionColor);
for (let p of Selection.data.points) {
let color = this.generateGradient(p.position.addVector(delta), p.opposite.position, Color.transparent());
this.drawLineFromTo(p.position.addVector(delta), p.opposite.position, p.line.thickness + this.outlineSize / Camera.zoom, color, false, false);
this.drawLineFromTo(p.position.addVector(delta), p.opposite.position, p.line.thickness + this.outlineSize / Application.currentView.camera.zoom, color, false, false);
}
// selected points
......@@ -469,7 +469,7 @@
{
let radius = (Preferences.showLineHandles) ? p.line.thickness * this.handleSizeFactor : p.line.thickness * 0.5;
// TODO use batching
this.drawRealCircle(p.position.addVector(delta), radius + this.outlineSize * 0.5 / Camera.zoom, this.outlineSize / Camera.zoom, Settings.selectionColor, false, false, true)
this.drawRealCircle(p.position.addVector(delta), radius + this.outlineSize * 0.5 / Application.currentView.camera.zoom, this.outlineSize / Application.currentView.camera.zoom, Settings.selectionColor, false, false, true)
}
if (File.currentLayer.hideInRenderPreview)
......@@ -590,7 +590,7 @@
if (Logic.isPreviewing() && !Preferences.renderGuideLayers)
return;
else
this.currentContext.setLineDash([Settings.guideDashSize * Camera.zoom, Settings.guideDashSize * Camera.zoom]);
this.currentContext.setLineDash([Settings.guideDashSize * Application.currentView.camera.zoom, Settings.guideDashSize * Application.currentView.camera.zoom]);
}
for (let line of Selection.data.lines)
......@@ -620,9 +620,9 @@
if (!Logic.isPreviewing()) {
for (let line of Selection.data.lines.concat(Selection.data.partialLines)) {
if (drawDotted)
this.currentContext.setLineDash([line.thickness * 6 * Camera.zoom, line.thickness * 4 * Camera.zoom]);
this.currentContext.setLineDash([line.thickness * 6 * Application.currentView.camera.zoom, line.thickness * 4 * Application.currentView.camera.zoom]);
if (File.currentLayer.hideInRenderPreview)
this.currentContext.setLineDash([Settings.guideDashSize * Camera.zoom, Settings.guideDashSize * Camera.zoom]);
this.currentContext.setLineDash([Settings.guideDashSize * Application.currentView.camera.zoom, Settings.guideDashSize * Application.currentView.camera.zoom]);
let thickness = drawDotted ? line.thickness * 0.5 : line.thickness;
let color = line.color.copy();
......@@ -687,7 +687,7 @@
if (Logic.isRenderPreviewing && Preferences.renderGuideLayers == false)
return;
this.currentContext.setLineDash([Settings.guideDashSize * Camera.zoom, Settings.guideDashSize * Camera.zoom]);
this.currentContext.setLineDash([Settings.guideDashSize * Application.currentView.camera.zoom, Settings.guideDashSize * Application.currentView.camera.zoom]);
for (let line of layer.lines)
this.batchLine(line, false);
......@@ -711,7 +711,7 @@
if (Logic.currentState.startPosLMB && !Logic.currentState.stoppedLMB) {
let start = Logic.currentState.startPosLMB;
let end = Logic.currentState.currentPosLMB;
this.currentContext.setLineDash([Settings.guideDashSize * Camera.zoom, Settings.guideDashSize * Camera.zoom]);
this.currentContext.setLineDash([Settings.guideDashSize * Application.currentView.camera.zoom, Settings.guideDashSize * Application.currentView.camera.zoom]);
this.drawLineFromTo(start, end, currentLineThickness, 'black', false);
this.currentContext.setLineDash([]);
}
......@@ -720,7 +720,7 @@
static drawCursor() {
if (Logic.currentState instanceof MeasureState) {
let size = cursorRange * Math.PI * 2 / 6 * Camera.zoom;
let size = cursorRange * Math.PI * 2 / 6 * Application.currentView.camera.zoom;
this.currentContext.setLineDash([size, size]);
}
......@@ -737,7 +737,7 @@
static drawPivot() {
if (Preferences.usePivot) {
let radius = 10 / Camera.zoom;
let radius = 10 / Application.currentView.camera.zoom;
let color = Color.black();
this.drawRealCircle(pivot, radius, 1, color, false, true, false);
......@@ -847,12 +847,12 @@
let screenpos;
if (dontSnap)
screenpos = Camera.canvasSpaceToScreenSpace(mousePosition.copy());
screenpos = Application.currentView.camera.canvasSpaceToScreenSpace(mousePosition.copy());
else
screenpos = Camera.canvasSpaceToScreenSpace(currentPosition.copy());
screenpos = Application.currentView.camera.canvasSpaceToScreenSpace(currentPosition.copy());
if (Logic.currentState.artBounds)
screenpos = Camera.canvasSpaceToScreenSpace(mousePosition.copy().rounded());
screenpos = Application.currentView.camera.canvasSpaceToScreenSpace(mousePosition.copy().rounded());
this.drawLineFromTo(new Vector2(0, screenpos.y), new Vector2(canvas.width, screenpos.y), Settings.crossHairLineWidth, Settings.crossHairColor, true, true);
this.drawLineFromTo(new Vector2(screenpos.x, 0), new Vector2(screenpos.x, canvas.height), Settings.crossHairLineWidth, Settings.crossHairColor, true, true);
......@@ -871,18 +871,18 @@
// */
// x
let dashSize = GridManager.grid.width * Camera.zoom * dashFactor;
let dashSize = GridManager.grid.width * Application.currentView.camera.zoom * dashFactor;
this.currentContext.setLineDash([dashSize, dashSize]);
this.drawLineFromTo(p1, p1.addVector(new Vector2(size.x, 0)), 2, 'black', false, true);
// y
dashSize = GridManager.grid.height * Camera.zoom * dashFactor;
dashSize = GridManager.grid.height * Application.currentView.camera.zoom * dashFactor;
this.currentContext.setLineDash([dashSize, dashSize]);
this.drawLineFromTo(p1.addVector(new Vector2(size.x, 0)), p2, 2, 'black', false, true);
this.currentContext.setLineDash([]);
// xy-diagonal
dashSize = Math.sqrt(GridManager.grid.width * GridManager.grid.width + GridManager.grid.height * GridManager.grid.height) * Camera.zoom * dashFactor;
dashSize = Math.sqrt(GridManager.grid.width * GridManager.grid.width + GridManager.grid.height * GridManager.grid.height) * Application.currentView.camera.zoom * dashFactor;
this.currentContext.setLineDash([dashSize, dashSize]);
this.drawLineFromTo(p1, p2, 2, 'black', false, true);
this.currentContext.setLineDash([]);
......@@ -898,7 +898,7 @@
// x
let pos = p1.copy();
pos.x += size.x * 0.5;
pos = Camera.canvasSpaceToScreenSpace(pos);
pos = Application.currentView.camera.canvasSpaceToScreenSpace(pos);
pos.y = (size.y > 0) ? pos.y - offset.y : pos.y + offset.y;
this.currentContext.fillText(+((size.x / GridManager.grid.width).toFixed(2)), pos.x, pos.y);
......@@ -907,31 +907,31 @@
// y
pos = p2.copy();
pos.y -= size.y * 0.5;
pos = Camera.canvasSpaceToScreenSpace(pos);
pos = Application.currentView.camera.canvasSpaceToScreenSpace(pos);
pos.x = (size.x > 0) ? pos.x + offset.x : pos.x - offset.x;
this.currentContext.fillText(+((size.y / GridManager.grid.height).toFixed(2)), pos.x, pos.y);
// xy
pos = p1.addVector(p2).divide(2);
let off = LineManipulator.rotatePositionByAngle(size.normalized().multiply(30), Vector2.zero, -90);
off = off.divide(Camera.zoom);
off = off.divide(Application.currentView.camera.zoom);
off = (size.y > 0) ? off.flipped() : off;
pos = (size.x > 0) ? pos.addVector(off) : pos.subtractVector(off);
pos = Camera.canvasSpaceToScreenSpace(pos);
pos = Application.currentView.camera.canvasSpaceToScreenSpace(pos);
let x = size.x / GridManager.grid.width;
let y = size.y / GridManager.grid.height;
this.currentContext.fillText(+(Math.sqrt(x*x + y*y).toFixed(2)), pos.x, pos.y);
// angle
pos = p1.addVector(size.normalized().multiply(33 / Camera.zoom));
pos = p1.addVector(size.normalized().multiply(33 / Application.currentView.camera.zoom));
pos = LineManipulator.rotatePositionByAngle(pos, p1, 180);
pos = Camera.canvasSpaceToScreenSpace(pos);
pos = Application.currentView.camera.canvasSpaceToScreenSpace(pos);
let num = +(Math.atan2(size.y, size.x) * (180 / Math.PI)).toFixed(2);
this.currentContext.fillText(num + "°", pos.x, pos.y);
// crosshair line end
let s = 10 / Camera.zoom;
let s = 10 / Application.currentView.camera.zoom;
let crossSize = new Vector2(s, s);
this.drawLineFromTo(p2.addVector(crossSize), p2.subtractVector(crossSize), 1, 'black', false, true);
crossSize.x = -crossSize.x;
......@@ -953,14 +953,14 @@
this.currentContext.strokeStyle = Settings.selectionColor;
this.currentContext.fillStyle = Settings.boxSelectionColor;
let leftTop = Camera.canvasSpaceToScreenSpace(Logic.currentState.startPos);
let leftTop = Application.currentView.camera.canvasSpaceToScreenSpace(Logic.currentState.startPos);
let sizeCanvasSpace = Logic.currentState.currentPos.subtractVector(Logic.currentState.startPos);
let size = sizeCanvasSpace.multiply(Camera.zoom);
let size = sizeCanvasSpace.multiply(Application.currentView.camera.zoom);
if (Logic.currentState.artBounds) {
leftTop = Camera.canvasSpaceToScreenSpace(Logic.currentState.startPos.rounded());
leftTop = Application.currentView.camera.canvasSpaceToScreenSpace(Logic.currentState.startPos.rounded());
sizeCanvasSpace = Logic.currentState.currentPos.subtractVector(Logic.currentState.startPos).rounded();
size = sizeCanvasSpace.multiply(Camera.zoom);
size = sizeCanvasSpace.multiply(Application.currentView.camera.zoom);
}
this.currentContext.rect(leftTop.x, leftTop.y, size.x, size.y);
......
class Exporter {
static init() {
console.log("Exporter created. ");
Exporter = new class {
constructor() {
this.renderResultWindow = null;
}
static renderPNG() // img
renderPNG() // img
{
let renderCanvas = document.createElement('canvas');
let renderContext = renderCanvas.getContext('2d');
......@@ -26,8 +25,8 @@ class Exporter {
this.renderResultWindow.document.write('*{margin:0;padding0;');
this.renderResultWindow.document.write('</style></head>');
// save values
let prevZoom = Camera.zoom;
let prevCanvasOffset = Camera.canvasOffset.copy();
let prevZoom = Application.currentView.camera.zoom;
let prevCanvasOffset = Application.currentView.camera.canvasOffset.copy();
// preparation
Logic.isRenderPreviewing = true;
......@@ -36,9 +35,9 @@ class Exporter {
offset = offset.addVector(Preferences.artBounds.size.multiply(0.5));
offset = offset.subtractVector(Preferences.artBounds.origin);
offset = offset.subtractVector((new Vector2(renderCanvas.width * 0.5, renderCanvas.height * 0.5)).divide(Preferences.renderScaleFactor));
Camera.canvasOffset = offset;
Application.currentView.camera.canvasOffset = offset;
Camera.zoom = Preferences.renderScaleFactor;
Application.currentView.camera.zoom = Preferences.renderScaleFactor;
Renderer.setContext(renderContext);
Renderer.showCursor = false;
......@@ -48,8 +47,8 @@ class Exporter {
this.renderResultWindow.document.write("<img src='" + renderCanvas.toDataURL("image/png") + "' alt='Rendered image'/>");