Commit 76c4b423 authored by Christian Winter's avatar Christian Winter

wip. mousehandler not needed any more. now View-class controls everything

parent 7dd09e91
......@@ -23,6 +23,7 @@
//Renderer.setContext(this.currentView.context);
this.layoutGUI();
this.redrawAllViews();
}
initializeClasses() {
......@@ -31,7 +32,6 @@
Preferences.init();
Input.init();
MouseHandler.init();
Logic.init();
Saver.init();
File.init();
......@@ -81,6 +81,7 @@
this.currentView = view;
this.currentView.activate();
this.currentView.canvas.focus();
}
redrawAllViews() {
......
This diff is collapsed.
This diff is collapsed.
......@@ -5,7 +5,7 @@
this.zoom = 1;
this.minZoom = 0.1;
this.maxZoom = 1000;
this.canvasOffset = new Vector2(0, 0);
this.position = new Vector2(0, 0);
// TODO better way to initialize?
//this.multiplyZoomBy(1, true);
......@@ -56,7 +56,7 @@
popCameraCenter() {
let newWorldCenter = this.screenSpaceToCanvasSpace(this.center);
let diff = newWorldCenter.subtractVector(this.worldCenter);
this.canvasOffset = this.canvasOffset.addVector(diff);
this.position = this.position.addVector(diff);
this.center = undefined;
this.worldCenter = undefined;
......@@ -66,12 +66,12 @@
screenSpaceToCanvasSpace(vec2) {
return vec2
.divide(this.zoom)
.subtractVector(this.canvasOffset);
.subtractVector(this.position);
}
canvasSpaceToScreenSpace(vec2) {
return vec2
.addVector(this.canvasOffset)
.addVector(this.position)
.multiply(this.zoom)
;
}
......@@ -87,7 +87,7 @@
pivot = Vector2.zero;
this.setZoom(1, false);
this.canvasOffset = (new Vector2(this.view.canvas.width * 0.5, this.view.canvas.height * 0.5));
this.position = (new Vector2(this.view.canvas.width * 0.5, this.view.canvas.height * 0.5));
this.view.renderer.redraw();
}
......
......@@ -51,10 +51,10 @@
p2 = p2.copy();
if (!screenSpace) {
p1.x += this.view.camera.canvasOffset.x;
p1.y += this.view.camera.canvasOffset.y;
p2.x += this.view.camera.canvasOffset.x;
p2.y += this.view.camera.canvasOffset.y;
p1.x += this.view.camera.position.x;
p1.y += this.view.camera.position.y;
p2.x += this.view.camera.position.x;
p2.y += this.view.camera.position.y;
p1.x *= this.view.camera.zoom;
p1.y *= this.view.camera.zoom;
......@@ -120,10 +120,10 @@
p2 = line.end.position.copy();
if (!screenSpace) {
p1.x += this.view.camera.canvasOffset.x;
p1.y += this.view.camera.canvasOffset.y;
p2.x += this.view.camera.canvasOffset.x;
p2.y += this.view.camera.canvasOffset.y;
p1.x += this.view.camera.position.x;
p1.y += this.view.camera.position.y;
p2.x += this.view.camera.position.x;
p2.y += this.view.camera.position.y;
p1.x *= this.view.camera.zoom;
p1.y *= this.view.camera.zoom;
......@@ -179,8 +179,8 @@
circle = this.batchedCircles[key];
center.setValues(circle.x, circle.y);
if (!screenSpace) {
center.x += this.view.camera.canvasOffset.x;
center.y += this.view.camera.canvasOffset.y;
center.x += this.view.camera.position.x;
center.y += this.view.camera.position.y;
center.x *= this.view.camera.zoom;
center.y *= this.view.camera.zoom;
......@@ -202,8 +202,8 @@
center = center.copy();
if (!screenSpace) {
center.x += this.view.camera.canvasOffset.x;
center.y += this.view.camera.canvasOffset.y;
center.x += this.view.camera.position.x;
center.y += this.view.camera.position.y;
center.x *= this.view.camera.zoom;
center.y *= this.view.camera.zoom;
......@@ -236,10 +236,14 @@
}
tmpRedraw() {
console.log("tmpRedraw")
this.currentContext.clearRect(0, 0, this.view.canvas.width, this.view.canvas.height);
this.screenBounds = this.view.camera.getVisibleBounds();
this.drawLineFromTo(Vector2.zero, new Vector2(100, 100), 1, 'black', false, false);
this.drawLineFromTo(Vector2.zero, new Vector2(100, 100), 1, 'red', true, true);
for (let line of File.currentLayer.lines){
this.drawLineFromTo(line.start.position, line.end.position, line.thickness, line.color.toString(), false, false);
}
}
redraw(step) {
......
......@@ -26,7 +26,7 @@ Exporter = new class {
this.renderResultWindow.document.write('</style></head>');
// save values
let prevZoom = Application.currentView.camera.zoom;
let prevCanvasOffset = Application.currentView.camera.canvasOffset.copy();
let prevposition = Application.currentView.camera.position.copy();
// preparation
Logic.isRenderPreviewing = true;
......@@ -35,7 +35,7 @@ Exporter = new class {
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));
Application.currentView.camera.canvasOffset = offset;
Application.currentView.camera.position = offset;
Application.currentView.camera.zoom = Preferences.renderScaleFactor;
Renderer.setContext(renderContext);
......@@ -48,7 +48,7 @@ Exporter = new class {
// restore
Application.currentView.camera.zoom = prevZoom;
Application.currentView.camera.canvasOffset = prevCanvasOffset;
Application.currentView.camera.position = prevposition;
Renderer.setContext(context);
Renderer.showCursor = true;
Renderer.setQualitySetting(Preferences.qualitySetting);
......
......@@ -26,6 +26,8 @@
catch (err) {
this.newFile();
GUI.notify("Error loading previous session. Created new one.", 'green');
this.createFileFromSVGString('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1024" height="1024" viewBox="-512 -512 1024 1024"> <g name="New Layer" visible="true" hideInRenderPreview="false" > <line x1="256" y1="0" x2="128" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="0" y1="0" x2="-128" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="0" y1="32" x2="0" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-128" y1="32" x2="-128" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-128" y1="0" x2="-128" y2="-32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="128" y1="0" x2="0" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="128" y1="32" x2="128" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="128" y1="0" x2="128" y2="-32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="256" y1="32" x2="256" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="256" y1="0" x2="256" y2="-32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="0" y1="0" x2="0" y2="-32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-256" y1="64" x2="-256" y2="32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-256" y1="32" x2="-256" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-128" y1="0" x2="-256" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-256" y1="0" x2="-256" y2="-32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-224" y1="32" x2="-256" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-224" y1="32" x2="-256" y2="64" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-256" y1="0" x2="-288" y2="32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-256" y1="64" x2="-288" y2="32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-96" y1="32" x2="-128" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-96" y1="32" x2="-128" y2="64" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-128" y1="0" x2="-160" y2="32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="-128" y1="64" x2="-160" y2="32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="32" y1="32" x2="0" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="32" y1="32" x2="0" y2="64" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="0" y1="0" x2="-32" y2="32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="0" y1="64" x2="-32" y2="32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="160" y1="32" x2="128" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="160" y1="32" x2="128" y2="64" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="128" y1="0" x2="96" y2="32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="128" y1="64" x2="96" y2="32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="288" y1="32" x2="256" y2="0" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="288" y1="32" x2="256" y2="64" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="256" y1="0" x2="224" y2="32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> <line x1="256" y1="64" x2="224" y2="32" stroke="#000000" stroke-opacity="1" stroke-width="1" stroke-linecap="round"/> </svg>');
}
}
......@@ -128,7 +130,8 @@
//File.createNewLayer(true);
File.updateStats();
Application.redrawAllViews();
// WIP
//Application.redrawAllViews();
// END copy paste
let viewBox = svg.getAttribute("viewBox");
......@@ -216,7 +219,8 @@
GUI.buildPrefabUI();
GUI.objectHierarchyChanged();
Application.redrawAllViews();
// WIP
// Application.redrawAllViews();
File.updateStats();
}
}
\ No newline at end of file
......@@ -112,7 +112,7 @@
Application.currentView.camera.zoomBy(-0.1 * Application.currentView.camera.zoom, false);
// TODO maybe better way to do it? with less calls?
Application.currentView.camera.canvasOffset = (new Vector2(canvas.width * 0.5, canvas.height * 0.5)).divide(Application.currentView.camera.zoom).subtractVector(Preferences.artBounds.origin.addVector(Preferences.artBounds.size.multiply(0.5)));
Application.currentView.camera.position = (new Vector2(canvas.width * 0.5, canvas.height * 0.5)).divide(Application.currentView.camera.zoom).subtractVector(Preferences.artBounds.origin.addVector(Preferences.artBounds.size.multiply(0.5)));
Application.redrawAllViews();
break;
case Key.B: // B
......
......@@ -9,7 +9,7 @@
update(screenPosDelta)
{
Application.currentView.camera.canvasOffset = Application.currentView.camera.canvasOffset.addVector(screenPosDelta.divide(Application.currentView.camera.zoom));
Application.currentView.camera.position = Application.currentView.camera.position.addVector(screenPosDelta.divide(Application.currentView.camera.zoom));
Application.redrawAllViews();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment