From f4f0e607ebbb5bdb549872e1bea24ae4f48ed325 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Wed, 27 Mar 2019 16:19:16 -0400 Subject: [PATCH] asset editor undo w/ ctrl+z; working on editor tools --- doc/notes.txt | 6 ++--- src/pixed/pixeleditor.ts | 56 +++++++++++++++++++++++++++++++--------- src/views.ts | 19 +++++++++++--- src/windows.ts | 13 ++++++++++ tss | 2 +- 5 files changed, 75 insertions(+), 21 deletions(-) diff --git a/doc/notes.txt b/doc/notes.txt index 3d5dacba..1e9c6063 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -102,15 +102,13 @@ TODO: - landscape mode for arcade ports - pixel editor - edit sprites and tiles at same time (multiple views) - - persist palette selections + - persist palette/tilemap selections - more tools for editing - map editor - metasprites - - update nested data, palette/tile refs properly - throw errors when bad/no refs - - careful with mouse capture out of frame + - capture so we get mouseUp() out of frame - per-View keyboard shortcuts - - global undo WEB WORKER FORMAT diff --git a/src/pixed/pixeleditor.ts b/src/pixed/pixeleditor.ts index c68a06ea..6d1173c9 100644 --- a/src/pixed/pixeleditor.ts +++ b/src/pixed/pixeleditor.ts @@ -2,6 +2,7 @@ import { hex, rgb2bgr, rle_unpack } from "../util"; import { ProjectWindows } from "../windows"; +declare var Mousetrap; export type UintArray = number[] | Uint8Array | Uint16Array | Uint32Array; //{[i:number]:number}; @@ -892,6 +893,7 @@ class PixEditor extends Viewer { curpalcol : number = -1; currgba : number; palbtns : JQuery[]; + offscreen : Map = new Map(); getPositionFromEvent(e) { var x = Math.floor(e.offsetX * this.width / $(this.canvas).width()); @@ -938,6 +940,16 @@ class PixEditor extends Viewer { this.commit(); // TODO: pixcanvas.releaseCapture(); }); + /* + Mousetrap.bind('ctrl+shift+h', this.flipX.bind(this)); + Mousetrap.bind('ctrl+shift+v', this.flipY.bind(this)); + Mousetrap.bind('ctrl+shift+9', this.rotate90.bind(this)); + Mousetrap.bind('ctrl+shift+left', this.translate.bind(this, -1, 0)); + Mousetrap.bind('ctrl+shift+right', this.translate.bind(this, 1, 0)); + Mousetrap.bind('ctrl+shift+up', this.translate.bind(this, 0, -1)); + Mousetrap.bind('ctrl+shift+down', this.translate.bind(this, 0, 1)); + */ + // TODO: remove when unbound aeditor.empty(); aeditor.append(this.canvas); @@ -945,18 +957,29 @@ class PixEditor extends Viewer { this.setPaletteColor(1); } - getPixel(x, y) { - var ofs = x+y*this.width; - return this.rgbdata[ofs]; + getPixel(x:number, y:number) : number { + x = Math.round(x); + y = Math.round(y); + if (x < 0 || x >= this.width || y < 0 || y >= this.height) { + return this.offscreen[x+','+y] | this.palette[0]; + } else { + var ofs = x+y*this.width; + return this.rgbdata[ofs]; + } } - setPixel(x, y, rgba) { - if (x < 0 || x >= this.width || y < 0 || y >= this.height) return; - var ofs = x+y*this.width; - var oldrgba = this.rgbdata[ofs]; - if (oldrgba != rgba) { - this.rgbdata[ofs] = rgba; - this.updateImage(); + setPixel(x:number, y:number, rgba:number) : void { + x = Math.round(x); + y = Math.round(y); + if (x < 0 || x >= this.width || y < 0 || y >= this.height) { + this.offscreen[x+','+y] = rgba; + } else { + var ofs = x+y*this.width; + var oldrgba = this.rgbdata[ofs]; + if (oldrgba != rgba) { + this.rgbdata[ofs] = rgba; + this.updateImage(); + } } } @@ -977,6 +1000,7 @@ class PixEditor extends Viewer { } commit() { + this.updateImage(); this.left.refreshLeft(); } @@ -1004,15 +1028,23 @@ class PixEditor extends Viewer { return this.getPixel(xx, yy); }); } - flipx() { + rotate90() { + this.rotate(90); + } + flipX() { this.remapPixels((x,y) => { return this.getPixel(this.width-1-x, y); }); } - flipy() { + flipY() { this.remapPixels((x,y) => { return this.getPixel(x, this.height-1-y); }); } + translate(dx:number, dy:number) { + this.remapPixels((x,y) => { + return this.getPixel(x+dx, y+dy); + }); + } } diff --git a/src/views.ts b/src/views.ts index fc20dfd9..51673177 100644 --- a/src/views.ts +++ b/src/views.ts @@ -8,6 +8,7 @@ import { hex, lpad, rpad, safeident, rgb2bgr } from "./util"; import { CodeAnalyzer } from "./analysis"; import { platform, platform_id, compparams, current_project, lastDebugState, projectWindows } from "./ui"; import * as pixed from "./pixed/pixeleditor"; +declare var Mousetrap; export interface ProjectView { createDiv(parent:HTMLElement, text:string) : HTMLElement; @@ -25,6 +26,7 @@ export interface ProjectView { clearErrors?() : void; setTimingResult?(result:CodeAnalyzer) : void; recreateOnResize? : boolean; + undoStep?() : void; }; declare var CodeMirror; @@ -146,8 +148,8 @@ export class SourceEditor implements ProjectView { var oldtext = this.editor.getValue(); if (oldtext != text) { // find minimum range to undo - for (var i=0; i