Add a cursor to the editor

This commit is contained in:
Eevee (Evelyn Woods) 2020-12-30 11:52:27 -07:00
parent 09d220b2a3
commit d700561c0f
3 changed files with 29 additions and 1 deletions

View File

@ -617,6 +617,7 @@ export class Level extends LevelInterface {
}
}
else if (tile.type.on_power) {
// FIXME this isn't quite right since there's seemingly a 1-frame delay
add_to_edge_map(circuit.tiles, tile, DIRECTIONS[edge].bit);
wired_outputs.add(tile);
}

View File

@ -2097,6 +2097,10 @@ export class Editor extends PrimaryView {
}
setup() {
// Add more bits to SVG overlay
this.svg_cursor = mk_svg('rect.overlay-cursor', {x: 0, y: 0, width: 1, height: 1});
this.svg_overlay.append(this.svg_cursor);
// Keyboard shortcuts
window.addEventListener('keydown', ev => {
if (! this.active)
@ -2161,6 +2165,17 @@ export class Editor extends PrimaryView {
window.addEventListener('mousemove', ev => {
if (! this.active)
return;
let [x, y] = this.renderer.cell_coords_from_event(ev);
if (this.is_in_bounds(x, y)) {
this.svg_cursor.classList.add('--visible');
this.svg_cursor.setAttribute('x', x);
this.svg_cursor.setAttribute('y', y);
}
else {
this.svg_cursor.classList.remove('--visible');
}
if (! this.mouse_op)
return;
if ((ev.buttons & this.mouse_op.button_mask) === 0) {

View File

@ -1413,6 +1413,14 @@ body.--debug #player-debug {
stroke-width: 0.0625;
fill: none;
}
#editor .level-editor-overlay rect.overlay-cursor {
display: none;
stroke: hsla(225, 100%, 60%, 0.5);
fill: hsla(225, 100%, 75%, 0.25);
}
#editor .level-editor-overlay rect.overlay-cursor.--visible {
display: initial;
}
#editor .level-editor-overlay rect.overlay-cxn {
stroke: red;
}
@ -1523,7 +1531,11 @@ body.--debug #player-debug {
#editor .palette {
isolation: isolate;
grid-area: palette;
padding-right: 0.25em; /* in case of scrollbar */
width: calc(32px * 8 + 4px * 9);
padding-right: 1em; /* make room for scrollbar so we don't get a horizontal one */
/* TODO when there IS a scrollbar, the h2s are slightly narrower. think this is an
* unexpected consequence of using min-content, which i guess does not take the
* possibility of a scrollbar into account */
overflow-y: auto;
}
#editor .palette h2 {