Tooling
Every editor on the site is built the same way, from the same parts. A canvas where the editing happens, a set of tools that decide what the pointer does, a window for each tool, and a set of general windows that are always to hand. Learn these parts once and every editor reads the same way, whatever the media.
The sprite editor is the worked example throughout. It is being organised to this standard as its parts settle, so a few names still read the older way, such as Sprites.Media.Sprite.Tool.Draw.Controls for a tool window. The names here show the target shape, the one a new editor should follow.
The shape of an editor
An editor for a media lives under Sprites.Media.<MediaName>, so the
sprite editor is Sprites.Media.Sprite and the font editor is
Sprites.Media.Font. Two rules place everything inside it. Each tool is its own
namespace under Tool, and every window sits together under Window.
Sprites.Media.<MediaName>
.Canvas the editing surface
.Tool
.Selector picks the selected tool
.<ToolName> one namespace per tool
.Window that tool's window, shown while it is selected
.Window
.Tools the master Tool window
.Palette .Info .Frames .Layers .History general purpose windows
The sections below take each part in turn. Every table lists the members of one namespace, with the arguments, the return value, and what each one does.
Tools
A tool decides what the pointer does. One tool is selected at a time, and while it is selected a press, a drag, or a move inside the canvas runs that tool. The Draw tool lays colour, the Move tool pans and zooms, the Select tool marks a region. Picking another tool changes what the same gestures do.
Each tool is a namespace of its own,
Sprites.Media.<MediaName>.Tool.<ToolName>. The selector and the
selected tool sit one level up, in Sprites.Media.<MediaName>.Tool. The
selector is one button group, one option per tool, and it sets the selected tool the canvas
reads.
| Member | Arguments | Returns | Description |
|---|---|---|---|
Sprites.Media.Sprite.Tool.Selector | selected | Void | The tool selector: one button group, one option per tool. Picking an option sets selected. |
Sprites.Media.Sprite.Tool.Move | — | Namespace | The pan and zoom tool. A drag moves the view over the sprite. |
Sprites.Media.Sprite.Tool.Draw | — | Namespace | The paint tool. A drag lays the brush along the pointer. |
Sprites.Media.Sprite.Tool.Select | — | Namespace | The selection tool. A drag marks a region to move, rotate, or clone. |
The canvas
The canvas is the area where the editing happens. It shows a preview of the thing being edited, often zoomed in, sometimes wrapped or repeated so an edge reads clearly. What a press, a drag, or a move does inside it comes from the selected tool. The canvas holds the view and the grid, reads the selected tool, and hands each pointer gesture to that tool.
The canvas and its parts sit directly under the media namespace,
Sprites.Media.<MediaName>.
| Member | Arguments | Returns | Description |
|---|---|---|---|
Sprites.Media.Sprite.Canvas | state, selected, view | Void | The editing surface. Shows the zoomed preview and hands each pointer gesture to the selected tool. |
Sprites.Media.Sprite.View | state, view | Void | Draws the sprite pixels at the current pan and zoom. |
Sprites.Media.Sprite.Grid | width, height, aspect | Void | A thin line around every pixel, inside the sprite bounds. |
Tool windows and sub-tools
A tool may have a window of its own. It holds the tool's controls, and it shows only while that tool is selected, since it is useful only then. Picking another tool hides it and shows that tool's window in its place.
A tool has sub-tools when it does more than one thing. One sub-tool is in force at a time. The Draw tool has a Pencil that lays colour and an Eraser that clears cells, and one of them acts on each stroke. A tool may also offer a set to choose from, such as the brush sizes the Draw tool paints with.
A tool's window is
Sprites.Media.<MediaName>.Tool.<ToolName>.Window. Every other
function for that tool, its pointer handler, its sub-tool selector, its brushes, lives in the
same <ToolName> namespace, so a tool is one self-contained space.
// Sprites.Media.Sprite.Tool.Draw.js
Sprites = window.Sprites || {};
Sprites.Media = Sprites.Media || {};
Sprites.Media.Sprite = Sprites.Media.Sprite || {};
Sprites.Media.Sprite.Tool = Sprites.Media.Sprite.Tool || {};
Sprites.Media.Sprite.Tool.Draw = Sprites.Media.Sprite.Tool.Draw || {};
Sprites.Media.Sprite.Tool.Draw.Window = (subTool, radius, brushCss, paletteVisible) => {
// the Pencil and Eraser selector, the brush sizes, and the colour swatch
};
| Member | Arguments | Returns | Description |
|---|---|---|---|
Sprites.Media.Sprite.Tool.Draw.Window | subTool, radius, brushCss, paletteVisible | Void | The Draw tool window: the Pencil and Eraser selector, the brush sizes, and the colour swatch. Shown while Draw is selected. |
Sprites.Media.Sprite.Tool.Draw.Pointer | state, at, subTool, radius, colour | Value | The canvas handler. On a press or drag it lays the brush at the pointer, in the colour for Pencil or clear for Eraser, and returns the new state. |
Sprites.Media.Sprite.Tool.Draw.SubTools | subTool | Void | The Pencil and Eraser selector. Sets the sub-tool in force. |
Sprites.Media.Sprite.Tool.Draw.Brushes | radius | Void | The brush-size selector. Sets the brush reach the stroke paints with. |
General purpose windows
A general purpose window is available all the time. It sits apart from the tools, so the selected tool leaves it be. The animation frames, the layers, and the undo and redo history are general windows: they stay useful whatever tool is in force, and each opens and closes on its own. The palette and the info panel are general windows too.
Every general window, and the master Tool window, lives in
Sprites.Media.<MediaName>.Window. So the whole set of always-available
windows reads from one place.
| Member | Arguments | Returns | Description |
|---|---|---|---|
Sprites.Media.Sprite.Window.Tools | selected, windows | Void | The master Tool window: the tool selector over the window toggles. Covered on its own below. |
Sprites.Media.Sprite.Window.Palette | indexed, slots, brush, visible, edit | Void | The colour palette. Picks the painting colour, or a slot when the sprite is indexed. |
Sprites.Media.Sprite.Window.Info | modes, modeIndex, state, width, height | Void | The mode and size panel. Picks the sprite mode and its size. |
Sprites.Media.Sprite.Window.Frames | frames, current, visible | Void | The animation frames. Adds, removes, and orders the frames of the sprite. |
Sprites.Media.Sprite.Window.Layers | layers, current, visible | Void | The layers. Adds, removes, and orders the layers of the frame. |
Sprites.Media.Sprite.Window.History | history, visible | Void | The undo and redo history. Steps the edit back and forward. |
The Tool window
The Tool window is the master window, and it is a general window itself. It holds two sections. The tools section, at the top, is the selector: a set of buttons where one is the selected tool. The windows section, below it, has one button for each general window, and each button opens or closes that window on its own. So the Tool window is where a tool is chosen and where the general windows are turned on and off.
It is Sprites.Media.<MediaName>.Window.Tools. Its two sections are small
builders in the same Window namespace, so the window composes them. The
windows argument is an object of visibility values, one per general window, that
the windows section toggles and each window reads.
| Member | Arguments | Returns | Description |
|---|---|---|---|
Sprites.Media.Sprite.Window.Tools | selected, windows | Void | The Tool window: the tools section over the windows section. |
Sprites.Media.Sprite.Window.ToolList | selected | Void | The tools section: the tool selector, one button per tool, setting selected. |
Sprites.Media.Sprite.Window.WindowList | windows | Void | The windows section: one toggle per general window, each opening or closing it. |