added zoom/drag controls, control panel minimizer

This commit is contained in:
MaxRobinsonTheGreat
2020-07-23 15:27:44 -06:00
parent 8fb471025e
commit b0af739747
7 changed files with 131 additions and 25 deletions

View File

@@ -22,37 +22,20 @@ class CanvasController{
defineEvents() {
this.canvas.addEventListener('mousemove', e => {
var prev_cell = this.cur_cell;
var prev_org = this.cur_org;
this.mouse_x = e.offsetX;
this.mouse_y = e.offsetY;
var colRow = this.env.grid_map.xyToColRow(this.mouse_x, this.mouse_y);
this.mouse_c = colRow[0];
this.mouse_r = colRow[1];
this.cur_cell = this.env.grid_map.cellAt(this.mouse_c, this.mouse_r);
this.cur_org = this.cur_cell.owner;
if (this.cur_org != prev_org || this.cur_cell != prev_cell) {
this.env.renderer.clearAllHighlights(true);
if (this.cur_org != null && this.highlight_org) {
this.env.renderer.highlightOrganism(this.cur_org);
}
else if (this.cur_cell != null) {
this.env.renderer.highlightCell(this.cur_cell, true);
}
}
this.updateMouseLocation(e.offsetX, e.offsetY)
this.mouseMove();
});
this.canvas.addEventListener('mouseup', function(evt) {
evt.preventDefault();
this.updateMouseLocation(evt.offsetX, evt.offsetY)
this.left_click=false;
this.right_click=false;
}.bind(this));
this.canvas.addEventListener('mousedown', function(evt) {
evt.preventDefault();
this.updateMouseLocation(evt.offsetX, evt.offsetY)
if (evt.button == 0) {
this.left_click = true;
}
@@ -73,6 +56,29 @@ class CanvasController{
}
updateMouseLocation(offsetX, offsetY) {
var prev_cell = this.cur_cell;
var prev_org = this.cur_org;
this.mouse_x = offsetX;
this.mouse_y = offsetY;
var colRow = this.env.grid_map.xyToColRow(this.mouse_x, this.mouse_y);
this.mouse_c = colRow[0];
this.mouse_r = colRow[1];
this.cur_cell = this.env.grid_map.cellAt(this.mouse_c, this.mouse_r);
this.cur_org = this.cur_cell.owner;
if (this.cur_org != prev_org || this.cur_cell != prev_cell) {
this.env.renderer.clearAllHighlights(true);
if (this.cur_org != null && this.highlight_org) {
this.env.renderer.highlightOrganism(this.cur_org);
}
else if (this.cur_cell != null) {
this.env.renderer.highlightCell(this.cur_cell, true);
}
}
}
mouseMove() {
alert("mouse move must be overriden");
}