Commit 3d393ef3 authored by Christian Winter's avatar Christian Winter

wip

parent 9ac8e6c9
......@@ -38,6 +38,11 @@ body {
color: #ccc;
overflow: hidden;
}
#canvasContainer{
width: auto;
height: auto;
background-color: red;
}
canvas {
display: block; /* To remove the scrollbars */
......
......@@ -160,7 +160,7 @@
</div>
<div class="toolcategory">
<p class="foldingHeader">Tools</p>
<p class="foldingHeader">Tools</p>
<div class="toolcategorycontainer">
<button type="button" onclick="LineManipulator.subdivide()">Subdivide</button>
......@@ -190,7 +190,7 @@
</div>
<canvas id="canvas"></canvas>
<div id="canvasContainer"></div>
<canvas id="offscreenCanvas" width="0" height="0"></canvas>
<div id="stats" class="stats"></div>
<div id="rightarea" class="toolarea">
......
......@@ -4,19 +4,26 @@
this.currentState; // Drawing, EditingPrefab
this.currentView = null;
this.views = [];
this.currentView = new View();
this.views.push(new View());
this.views.push(new View());
this.initializeClasses();
window.addEventListener("keydown", evt => Input.keyDown(evt), false);
window.addEventListener("keyup", evt => Input.keyUp(evt), false);
window.addEventListener('resize', evt => this.layoutGUI(evt), false);
GUI.genereateGridSettings();
Logic.start();
Renderer.setContext(this.currentView.context);
//Renderer.setContext(this.currentView.context);
this.layoutGUI();
}
initializeClasses() {
......@@ -28,7 +35,6 @@
Logic.init();
Saver.init();
File.init();
Renderer.init();
RenderManager.init();
Selection.init();
......@@ -38,4 +44,43 @@
PrefabManager.init();
}
layoutGUI() {
let topLeft = Vector2.zero;
let size = new Vector2();
size.x = window.innerWidth - leftarea.offsetWidth - rightarea.offsetWidth;
size.y = window.innerHeight - GUI.menubar.offsetHeight - GUI.statusbar.offsetHeight;
topLeft.x = leftarea.offsetWidth;
let width = size.x / this.views.length;
let height = size.y;
for (let i=0; i<this.views.length; ++i){
this.views[i].canvas.style.left = topLeft.x + width * i;
this.views[i].canvas.width = width;
this.views[i].canvas.height = height;
}
/*
toolbar.style.left = canvas.style.left;
toolbar.style.width = canvas.width;
toolbar.style.top = GUI.menubar.offsetHeight;
*/
GUI.stats.style.right = 350;
// TODO magic
GUI.stats.style.top = GUI.menubar.offsetHeight + 75;
}
setView(view) {
this.currentView = view;
if (view == null)
return;
}
redraw() {
}
}
\ No newline at end of file
Utilities = new class {
getMousePos(e) {
let rect = canvas.getBoundingClientRect();
return new Vector2(
e.clientX - rect.left,
e.clientY - rect.top
);
}
deleteArrayEntry(array, entry) {
for (var i = 0; i < array.length; ++i) {
if (array[i] == entry) {
......
class View {
constructor() {
let canvasContainer = document.getElementById('canvasContainer');
// canvas
this.canvas = document.getElementById('canvas');
this.canvas = document.createElement('canvas');
canvasContainer.appendChild(this.canvas);
this.canvas.contentEditable = true; // to make canvas.focus() working
this.canvas.addEventListener("mousemove", evt => MouseHandler.mouseMove(evt));
this.canvas.addEventListener("mouseup", evt => MouseHandler.mouseUp(evt));
this.canvas.addEventListener("mousedown", evt => MouseHandler.mouseDown(evt));
this.canvas.addEventListener("wheel", evt => MouseHandler.mouseScroll(evt));
this.canvas.addEventListener("mousemove", evt => this.mouseMove(evt));
this.canvas.addEventListener("mouseup", evt => this.mouseUp(evt));
this.canvas.addEventListener("mousedown", evt => this.mouseDown(evt));
this.canvas.addEventListener("wheel", evt => this.mouseScroll(evt));
this.canvas.addEventListener("mouseenter", evt => MouseHandler.canvasMouseEnter(evt));
this.canvas.addEventListener("mouseleave", evt => MouseHandler.canvasMouseLeave(evt));
this.canvas.addEventListener("mouseenter", evt => this.mouseEnter(evt));
this.canvas.addEventListener("mouseleave", evt => this.mouseExit(evt));
this.canvas.style.background = Settings.canvasColor;
......@@ -24,10 +26,45 @@
// this.uiButtonPanel= [];
// renderer
// this.renderer = new Renderer();
// this.renderer.setContext(this.context);
this.renderer = new Renderer(this);
this.renderer.setContext(this.context);
}
// onmouseenter
// onmouseleave
mouseMove(e) {
//console.log(this._getMousePos(e));
}
mouseUp(e) {
console.log(this._getMousePos(e));
}
mouseDown(e) {
console.log(this._getMousePos(e));
}
mouseScroll(e) {
//console.log(this._getMousePos(e));
}
mouseEnter(e) {
//console.log(this._getMousePos(e));
this.canvas.style.background = 'green';
Application.setView(this);
}
mouseExit(e) {
//console.log(this._getMousePos(e));
this.canvas.style.background = 'grey';
Application.setView(null);
}
_getMousePos(e) {
let rect = this.canvas.getBoundingClientRect();
return new Vector2(
e.clientX - rect.left,
e.clientY - rect.top
);
}
}
\ No newline at end of file
......@@ -64,7 +64,6 @@ class Logic {
static start() {
window.addEventListener("contextmenu", function (e) { e.preventDefault(); return false; });
window.addEventListener('resize', this.layoutGUI, false);
window.addEventListener('focus', function () {
Input.clearKeys();
if (Preferences.developerMode)
......@@ -113,17 +112,19 @@ class Logic {
});
}
// WIP remove?
static layoutGUI() {
/*
canvas.width = window.innerWidth - leftarea.offsetWidth - rightarea.offsetWidth;
canvas.height = window.innerHeight - GUI.menubar.offsetHeight - GUI.statusbar.offsetHeight;
canvas.style.left = leftarea.offsetWidth;
//canvas.style.top = GUI.menubar.offsetHeight;
toolbar.style.left = canvas.style.left;
toolbar.style.width = canvas.width;
toolbar.style.top = GUI.menubar.offsetHeight;
GUI.stats.style.left = canvas.right - 50;
*/
// TODO magic
GUI.stats.style.top = GUI.menubar.offsetHeight + 75;
}
......
This diff is collapsed.
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