textmode.js 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/textmode.esm.js +965 -965
- package/dist/textmode.umd.js +13 -13
- package/dist/types/Textmode.d.ts +133 -0
- package/dist/types/errors/Error.d.ts +24 -0
- package/dist/types/errors/ErrorHandler.d.ts +77 -0
- package/dist/types/errors/index.d.ts +2 -0
- package/dist/types/exports/conversion.d.ts +1 -0
- package/dist/types/exports/filters.d.ts +1 -0
- package/dist/types/exports/input.d.ts +1 -0
- package/dist/types/exports/layering.d.ts +1 -0
- package/dist/types/exports/loadables.d.ts +1 -0
- package/dist/types/exports/loading.d.ts +1 -0
- package/dist/types/exports/plugins.d.ts +1 -0
- package/dist/types/index.d.ts +85 -0
- package/dist/types/rendering/index.d.ts +4 -0
- package/dist/types/rendering/webgl/batching/DrawQueue.d.ts +89 -0
- package/dist/types/rendering/webgl/batching/GeometryAttributeCache.d.ts +18 -0
- package/dist/types/rendering/webgl/batching/InstanceAttributeBinder.d.ts +83 -0
- package/dist/types/rendering/webgl/batching/InstanceBatch.d.ts +87 -0
- package/dist/types/rendering/webgl/batching/InstanceBuffer.d.ts +68 -0
- package/dist/types/rendering/webgl/batching/InstanceData.d.ts +56 -0
- package/dist/types/rendering/webgl/batching/InstanceWriter.d.ts +78 -0
- package/dist/types/rendering/webgl/core/Framebuffer.d.ts +94 -0
- package/dist/types/rendering/webgl/core/Renderer.d.ts +78 -0
- package/dist/types/rendering/webgl/core/Shader.d.ts +62 -0
- package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +101 -0
- package/dist/types/rendering/webgl/core/interfaces/IRenderer.d.ts +214 -0
- package/dist/types/rendering/webgl/geometries/2d/Arc.d.ts +17 -0
- package/dist/types/rendering/webgl/geometries/2d/BezierCurve.d.ts +23 -0
- package/dist/types/rendering/webgl/geometries/2d/Ellipse.d.ts +21 -0
- package/dist/types/rendering/webgl/geometries/2d/Line.d.ts +21 -0
- package/dist/types/rendering/webgl/geometries/2d/Rectangle.d.ts +21 -0
- package/dist/types/rendering/webgl/geometries/2d/Triangle.d.ts +21 -0
- package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +57 -0
- package/dist/types/rendering/webgl/geometries/immediate/ImmediateQuad.d.ts +33 -0
- package/dist/types/rendering/webgl/geometries/index.d.ts +6 -0
- package/dist/types/rendering/webgl/geometries/utils/GeometryDescriptors.d.ts +31 -0
- package/dist/types/rendering/webgl/geometries/utils/GeometryGenerator.d.ts +16 -0
- package/dist/types/rendering/webgl/index.d.ts +19 -0
- package/dist/types/rendering/webgl/materials/Material.d.ts +23 -0
- package/dist/types/rendering/webgl/materials/MaterialManager.d.ts +56 -0
- package/dist/types/rendering/webgl/materials/index.d.ts +2 -0
- package/dist/types/rendering/webgl/pipeline/MaterialBatchPipeline.d.ts +54 -0
- package/dist/types/rendering/webgl/pipeline/index.d.ts +7 -0
- package/dist/types/rendering/webgl/state/RenderState.d.ts +159 -0
- package/dist/types/rendering/webgl/types/DrawCommand.d.ts +29 -0
- package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +147 -0
- package/dist/types/rendering/webgl/types/RenderTypes.d.ts +18 -0
- package/dist/types/rendering/webgl/types/UniformTypes.d.ts +11 -0
- package/dist/types/rendering/webgl/utils/GLUtils.d.ts +68 -0
- package/dist/types/rendering/webgl/utils/ViewportCache.d.ts +3 -0
- package/dist/types/rendering/webgl/utils/hash.d.ts +102 -0
- package/dist/types/textmode/AnimationController.d.ts +110 -0
- package/dist/types/textmode/Canvas.d.ts +58 -0
- package/dist/types/textmode/Grid.d.ts +563 -0
- package/dist/types/textmode/TextmodeColor.d.ts +405 -0
- package/dist/types/textmode/Textmodifier.d.ts +113 -0
- package/dist/types/textmode/conversion/ConversionManager.d.ts +89 -0
- package/dist/types/textmode/conversion/ConversionRegistry.d.ts +78 -0
- package/dist/types/textmode/conversion/index.d.ts +2 -0
- package/dist/types/textmode/conversion/strategies/brightness.d.ts +2 -0
- package/dist/types/textmode/filters/FilterManager.d.ts +132 -0
- package/dist/types/textmode/filters/index.d.ts +2 -0
- package/dist/types/textmode/filters/types.d.ts +78 -0
- package/dist/types/textmode/interfaces/IDisposable.d.ts +14 -0
- package/dist/types/textmode/interfaces/ITextmodifier.d.ts +753 -0
- package/dist/types/textmode/interfaces/index.d.ts +2 -0
- package/dist/types/textmode/layers/Layer2DCompositor.d.ts +89 -0
- package/dist/types/textmode/layers/LayerManager.d.ts +115 -0
- package/dist/types/textmode/layers/TextmodeLayer.d.ts +105 -0
- package/dist/types/textmode/layers/index.d.ts +4 -0
- package/dist/types/textmode/layers/interfaces/ILayerManager.d.ts +158 -0
- package/dist/types/textmode/layers/interfaces/ITextmodeLayer.d.ts +821 -0
- package/dist/types/textmode/layers/types.d.ts +78 -0
- package/dist/types/textmode/loadables/ITextmodeSource.d.ts +541 -0
- package/dist/types/textmode/loadables/TextmodeImage.d.ts +45 -0
- package/dist/types/textmode/loadables/TextmodeSource.d.ts +65 -0
- package/dist/types/textmode/loadables/TextmodeTexture.d.ts +95 -0
- package/dist/types/textmode/loadables/font/CharacterColorMapper.d.ts +34 -0
- package/dist/types/textmode/loadables/font/CharacterExtractor.d.ts +22 -0
- package/dist/types/textmode/loadables/font/MetricsCalculator.d.ts +23 -0
- package/dist/types/textmode/loadables/font/TextmodeFont.d.ts +176 -0
- package/dist/types/textmode/loadables/font/TextureAtlas.d.ts +66 -0
- package/dist/types/textmode/loadables/font/index.d.ts +8 -0
- package/dist/types/textmode/loadables/font/types.d.ts +28 -0
- package/dist/types/textmode/loadables/font/typr/Typr.d.ts +20 -0
- package/dist/types/textmode/loadables/font/typr/types.d.ts +241 -0
- package/dist/types/textmode/loadables/font/utils/CmapUtils.d.ts +11 -0
- package/dist/types/textmode/loadables/font/utils/FontTableReader.d.ts +40 -0
- package/dist/types/textmode/loadables/font/utils/index.d.ts +7 -0
- package/dist/types/textmode/loadables/index.d.ts +6 -0
- package/dist/types/textmode/loadables/video/ITextmodeVideo.d.ts +339 -0
- package/dist/types/textmode/loadables/video/TextmodeVideo.d.ts +81 -0
- package/dist/types/textmode/loading/LoadingPhase.d.ts +28 -0
- package/dist/types/textmode/loading/LoadingPhaseTracker.d.ts +20 -0
- package/dist/types/textmode/loading/LoadingScreenManager.d.ts +208 -0
- package/dist/types/textmode/loading/LoadingScreenState.d.ts +22 -0
- package/dist/types/textmode/loading/LoadingScreenTheme.d.ts +26 -0
- package/dist/types/textmode/loading/LoadingScreenTransition.d.ts +17 -0
- package/dist/types/textmode/loading/index.d.ts +7 -0
- package/dist/types/textmode/loading/templates/SpinnerTemplate.d.ts +2 -0
- package/dist/types/textmode/loading/templates/index.d.ts +1 -0
- package/dist/types/textmode/loading/types.d.ts +255 -0
- package/dist/types/textmode/managers/KeyboardManager.d.ts +128 -0
- package/dist/types/textmode/managers/MouseManager.d.ts +159 -0
- package/dist/types/textmode/managers/PluginManager.d.ts +220 -0
- package/dist/types/textmode/managers/TouchManager.d.ts +237 -0
- package/dist/types/textmode/managers/index.d.ts +12 -0
- package/dist/types/textmode/mixins/AnimationMixin.d.ts +8 -0
- package/dist/types/textmode/mixins/KeyboardMixin.d.ts +13 -0
- package/dist/types/textmode/mixins/MouseMixin.d.ts +10 -0
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +8 -0
- package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +19 -0
- package/dist/types/textmode/mixins/TouchMixin.d.ts +6 -0
- package/dist/types/textmode/mixins/index.d.ts +9 -0
- package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +674 -0
- package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +234 -0
- package/dist/types/textmode/mixins/interfaces/IMouseMixin.d.ts +425 -0
- package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +2147 -0
- package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +509 -0
- package/dist/types/textmode/types.d.ts +52 -0
- package/dist/types/utils/Disposable.d.ts +18 -0
- package/dist/types/utils/TextmodeCollection.d.ts +172 -0
- package/dist/types/utils/array.d.ts +34 -0
- package/dist/types/utils/color.d.ts +61 -0
- package/dist/types/utils/input.d.ts +11 -0
- package/dist/types/utils/math.d.ts +118 -0
- package/dist/types/utils/shader.d.ts +12 -0
- package/package.json +2 -2
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { TextmodeOptions } from './types';
|
|
2
|
+
import { type RGBA } from '../utils/color';
|
|
3
|
+
/**
|
|
4
|
+
* Manages a `HTMLCanvasElement` for textmode rendering.
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
export declare class TextmodeCanvas {
|
|
8
|
+
private _canvas;
|
|
9
|
+
private _targetCanvas;
|
|
10
|
+
private _isOverlay;
|
|
11
|
+
private _canvasCreatedByUs;
|
|
12
|
+
private _externalGL;
|
|
13
|
+
private _ownsContext;
|
|
14
|
+
private _gl;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new TextmodeCanvas instance.
|
|
17
|
+
* @param opts Options for creating or using an existing canvas
|
|
18
|
+
* @ignore
|
|
19
|
+
*/
|
|
20
|
+
constructor(opts?: TextmodeOptions);
|
|
21
|
+
private _createCanvas;
|
|
22
|
+
private _createOverlayCanvas;
|
|
23
|
+
private _setupOverlayPositioning;
|
|
24
|
+
private _collectBackgroundSources;
|
|
25
|
+
/**
|
|
26
|
+
* Attempts to detect the background color behind the textmode canvas.
|
|
27
|
+
* Used internally for theming transparent UI elements like the loading screen.
|
|
28
|
+
* @ignore
|
|
29
|
+
*/
|
|
30
|
+
$sampleBackgroundColor(): RGBA | null;
|
|
31
|
+
private _positionOverlayCanvas;
|
|
32
|
+
/**
|
|
33
|
+
* Resize the canvas to the specified width and height.
|
|
34
|
+
* If width or height is not provided, it retains the current dimension.
|
|
35
|
+
* @param width The new width of the canvas in pixels.
|
|
36
|
+
* @param height The new height of the canvas in pixels.
|
|
37
|
+
* @ignore
|
|
38
|
+
*/
|
|
39
|
+
$resize(width?: number, height?: number): void;
|
|
40
|
+
/**
|
|
41
|
+
* Get the WebGL context for the canvas.
|
|
42
|
+
* Returns external context if provided, otherwise creates a new one.
|
|
43
|
+
* @ignore
|
|
44
|
+
*/
|
|
45
|
+
$getWebGLContext(): WebGL2RenderingContext;
|
|
46
|
+
/**
|
|
47
|
+
* Dispose of this TextmodeCanvas and clean up all resources.
|
|
48
|
+
* This method is idempotent and safe to call multiple times.
|
|
49
|
+
* @ignore
|
|
50
|
+
*/
|
|
51
|
+
$dispose(): void;
|
|
52
|
+
/** Getters */
|
|
53
|
+
get canvas(): HTMLCanvasElement;
|
|
54
|
+
get targetCanvas(): HTMLCanvasElement | HTMLVideoElement | null;
|
|
55
|
+
get width(): number;
|
|
56
|
+
get height(): number;
|
|
57
|
+
get ownsContext(): boolean;
|
|
58
|
+
}
|
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a position on the grid, typically using center-based coordinates.
|
|
3
|
+
*/
|
|
4
|
+
export interface GridPosition {
|
|
5
|
+
/** The X coordinate (column), often relative to the grid's center. */
|
|
6
|
+
x: number;
|
|
7
|
+
/** The Y coordinate (row), often relative to the grid's center. */
|
|
8
|
+
y: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Function type that returns a Grid instance or undefined.
|
|
12
|
+
*/
|
|
13
|
+
export type GridProvider = () => TextmodeGrid | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Manages the grid of each `TextmodeLayer` instance.
|
|
16
|
+
*
|
|
17
|
+
* The grid determines how characters are positioned and sized on the canvas.
|
|
18
|
+
* By default, the grid is responsive, meaning it recalculates the number of columns
|
|
19
|
+
* and rows based on the canvas size and the font size.
|
|
20
|
+
*
|
|
21
|
+
* You can manually set `cols` and `rows` to lock the grid to a specific size.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```javascript
|
|
25
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
26
|
+
*
|
|
27
|
+
* t.setup(() => {
|
|
28
|
+
* // Lock the grid to a fixed resolution of 40x25 characters
|
|
29
|
+
* // regardless of the window size.
|
|
30
|
+
* t.grid.cols = 40;
|
|
31
|
+
* t.grid.rows = 25;
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* t.draw(() => {
|
|
35
|
+
* t.background(0);
|
|
36
|
+
* t.charColor(0, 255, 0);
|
|
37
|
+
* t.char('#');
|
|
38
|
+
*
|
|
39
|
+
* // Draw a border around the fixed grid
|
|
40
|
+
* t.rect(t.grid.cols, t.grid.rows);
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare class TextmodeGrid {
|
|
45
|
+
/** The number of columns in the grid. */
|
|
46
|
+
private _cols;
|
|
47
|
+
/** The number of rows in the grid. */
|
|
48
|
+
private _rows;
|
|
49
|
+
/** The total width of the grid in pixels. */
|
|
50
|
+
private _width;
|
|
51
|
+
/** The total height of the grid in pixels. */
|
|
52
|
+
private _height;
|
|
53
|
+
/** The offset to the outer canvas on the x-axis when centering the grid. */
|
|
54
|
+
private _offsetX;
|
|
55
|
+
/** The offset to the outer canvas on the y-axis when centering the grid. */
|
|
56
|
+
private _offsetY;
|
|
57
|
+
/** The canvas element used to determine the grid dimensions. */
|
|
58
|
+
private _canvas;
|
|
59
|
+
/** The width of each cell in the grid. */
|
|
60
|
+
private _cellWidth;
|
|
61
|
+
/** The height of each cell in the grid. */
|
|
62
|
+
private _cellHeight;
|
|
63
|
+
/** Tracks whether cols/rows were manually overridden. */
|
|
64
|
+
private _manualDimensionsSet;
|
|
65
|
+
/** Hooks to notify listeners when grid dimensions change. */
|
|
66
|
+
private _dimensionChangeListeners;
|
|
67
|
+
/** Updates derived metrics (width/height/offset) from current cols/rows. */
|
|
68
|
+
private _syncDerivedDimensions;
|
|
69
|
+
/**
|
|
70
|
+
* Create a new grid instance.
|
|
71
|
+
* @param canvas The canvas element used to determine the grid dimensions.
|
|
72
|
+
* @param cellWidth The width of each cell in the grid.
|
|
73
|
+
* @param cellHeight The height of each cell in the grid.
|
|
74
|
+
* @ignore
|
|
75
|
+
*/
|
|
76
|
+
constructor(canvas: HTMLCanvasElement, cellWidth: number, cellHeight: number);
|
|
77
|
+
/**
|
|
78
|
+
* Register a listener invoked whenever grid dimensions change.
|
|
79
|
+
* @param handler The callback function to invoke on dimension changes.
|
|
80
|
+
* @ignore
|
|
81
|
+
*/
|
|
82
|
+
$addOnDimensionsChange(handler: () => void): void;
|
|
83
|
+
/**
|
|
84
|
+
* Remove a previously registered dimensions change listener.
|
|
85
|
+
* @param handler The callback function to remove.
|
|
86
|
+
* @ignore
|
|
87
|
+
*/
|
|
88
|
+
$removeOnDimensionsChange(handler: () => void): void;
|
|
89
|
+
/**
|
|
90
|
+
* Reset the grid to the default number of columns and rows based on the current canvas dimensions, and the grid cell dimensions.
|
|
91
|
+
*
|
|
92
|
+
* If either `cols` or `rows` were manually set, this method does nothing.
|
|
93
|
+
* Make sure to call `responsive()` first to restore responsive sizing.
|
|
94
|
+
*
|
|
95
|
+
* `textmode.js` handles calling this method automatically when the canvas is resized.
|
|
96
|
+
* You typically do not need to call this method directly.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```javascript
|
|
100
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
101
|
+
*
|
|
102
|
+
* let locked = false;
|
|
103
|
+
*
|
|
104
|
+
* t.draw(() => {
|
|
105
|
+
* t.background(0);
|
|
106
|
+
*
|
|
107
|
+
* t.charColor(255);
|
|
108
|
+
* t.char(locked ? 'L' : 'R');
|
|
109
|
+
* t.rect(t.grid.cols, t.grid.rows);
|
|
110
|
+
* });
|
|
111
|
+
*
|
|
112
|
+
* // Toggle between fixed size and responsive
|
|
113
|
+
* t.mousePressed(() => {
|
|
114
|
+
* locked = !locked;
|
|
115
|
+
* if (locked) {
|
|
116
|
+
* // Lock to small grid
|
|
117
|
+
* t.grid.cols = 20;
|
|
118
|
+
* t.grid.rows = 10;
|
|
119
|
+
* } else {
|
|
120
|
+
* // Restore responsive sizing
|
|
121
|
+
* t.grid.responsive();
|
|
122
|
+
* t.grid.reset();
|
|
123
|
+
* }
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* t.windowResized(() => {
|
|
127
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
reset(): void;
|
|
132
|
+
/**
|
|
133
|
+
* Re-assign the grid cell dimensions and `reset()` the grid.
|
|
134
|
+
* @param newCellWidth The new cell width.
|
|
135
|
+
* @param newCellHeight The new cell height.
|
|
136
|
+
* @ignore
|
|
137
|
+
*/
|
|
138
|
+
$resizeCellPixelDimensions(newCellWidth: number, newCellHeight: number): void;
|
|
139
|
+
/**
|
|
140
|
+
* Returns the width of each cell in the grid in screen pixels.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```javascript
|
|
144
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
145
|
+
*
|
|
146
|
+
* t.draw(() => {
|
|
147
|
+
* t.background(0);
|
|
148
|
+
*
|
|
149
|
+
* const w = t.grid.cellWidth;
|
|
150
|
+
* const h = t.grid.cellHeight;
|
|
151
|
+
*
|
|
152
|
+
* t.char('▓');
|
|
153
|
+
* t.charColor(255, 100, 100);
|
|
154
|
+
* t.rect(11, 11);
|
|
155
|
+
*
|
|
156
|
+
* // Display pixel dimensions
|
|
157
|
+
* const label = `${w}x${h}`;
|
|
158
|
+
* for (let i = 0; i < label.length; i++) {
|
|
159
|
+
* t.push();
|
|
160
|
+
* t.translate(i - label.length / 2, 0);
|
|
161
|
+
* t.char(label[i]);
|
|
162
|
+
* t.charColor(255);
|
|
163
|
+
* t.point();
|
|
164
|
+
* t.pop();
|
|
165
|
+
* }
|
|
166
|
+
* });
|
|
167
|
+
*
|
|
168
|
+
* t.windowResized(() => {
|
|
169
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
get cellWidth(): number;
|
|
174
|
+
/**
|
|
175
|
+
* Returns the height of each cell in the grid in screen pixels.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```javascript
|
|
179
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
180
|
+
*
|
|
181
|
+
* t.draw(() => {
|
|
182
|
+
* t.background(0);
|
|
183
|
+
*
|
|
184
|
+
* const h = t.grid.cellHeight;
|
|
185
|
+
* const rows = t.grid.rows;
|
|
186
|
+
*
|
|
187
|
+
* // Draw vertical stripes to visualize rows
|
|
188
|
+
* for (let y = -rows / 2; y < rows / 2; y++) {
|
|
189
|
+
* // Gradient based on Y position
|
|
190
|
+
* const brightness = 100 + (Math.sin(y * 0.2 + t.frameCount * 0.1) * 0.5 + 0.5) * 155;
|
|
191
|
+
* t.cellColor(0, brightness * 0.5, brightness);
|
|
192
|
+
*
|
|
193
|
+
* t.push();
|
|
194
|
+
* t.translate(0, y);
|
|
195
|
+
* // Draw a horizontal line across the center column
|
|
196
|
+
* t.char('=');
|
|
197
|
+
* t.charColor(255);
|
|
198
|
+
* t.point();
|
|
199
|
+
* t.pop();
|
|
200
|
+
* }
|
|
201
|
+
*
|
|
202
|
+
* // Display the cell height in pixels
|
|
203
|
+
* const label = `CELL H: ${h}px`;
|
|
204
|
+
* for (let i = 0; i < label.length; i++) {
|
|
205
|
+
* t.push();
|
|
206
|
+
* t.translate(i - label.length / 2, 0);
|
|
207
|
+
* t.char(label[i]);
|
|
208
|
+
* t.cellColor(0); // clear background for text
|
|
209
|
+
* t.charColor(255, 255, 0);
|
|
210
|
+
* t.point();
|
|
211
|
+
* t.pop();
|
|
212
|
+
* }
|
|
213
|
+
* });
|
|
214
|
+
*
|
|
215
|
+
* t.windowResized(() => {
|
|
216
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
217
|
+
* });
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
get cellHeight(): number;
|
|
221
|
+
/**
|
|
222
|
+
* Returns the number of columns in the grid.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```javascript
|
|
226
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
227
|
+
*
|
|
228
|
+
* t.draw(() => {
|
|
229
|
+
* t.background(0);
|
|
230
|
+
*
|
|
231
|
+
* // Draw a frame around the grid
|
|
232
|
+
* const w = t.grid.cols;
|
|
233
|
+
* const h = t.grid.rows;
|
|
234
|
+
*
|
|
235
|
+
* t.char('#');
|
|
236
|
+
* t.charColor(255, 100, 100);
|
|
237
|
+
* t.rect(w, h);
|
|
238
|
+
*
|
|
239
|
+
* // Clear center
|
|
240
|
+
* t.char(' ');
|
|
241
|
+
* t.cellColor(0);
|
|
242
|
+
* t.rect(w - 2, h - 2);
|
|
243
|
+
* });
|
|
244
|
+
*
|
|
245
|
+
* t.windowResized(() => {
|
|
246
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
247
|
+
* });
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
get cols(): number;
|
|
251
|
+
/**
|
|
252
|
+
* Sets the number of columns and locks grid sizing until `responsive()` is called.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```javascript
|
|
256
|
+
* // Locking the grid columns
|
|
257
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
258
|
+
*
|
|
259
|
+
* t.setup(() => {
|
|
260
|
+
* // Lock the grid to exactly 40 columns.
|
|
261
|
+
* // Resizing the window will now only increase the margins.
|
|
262
|
+
* t.grid.cols = 40;
|
|
263
|
+
* });
|
|
264
|
+
*
|
|
265
|
+
* t.draw(() => {
|
|
266
|
+
* t.background(0, 20, 0);
|
|
267
|
+
*
|
|
268
|
+
* // Draw a pattern that fills the 40-column width
|
|
269
|
+
* for (let x = -20; x < 20; x++) {
|
|
270
|
+
* const h = 5 + Math.sin(t.frameCount * 0.1 + x * 0.5) * 5;
|
|
271
|
+
* t.push();
|
|
272
|
+
* t.translate(x + 0.5, 0);
|
|
273
|
+
* t.charColor(0, 255, 100);
|
|
274
|
+
* t.char('+');
|
|
275
|
+
* t.rect(1, h);
|
|
276
|
+
* t.pop();
|
|
277
|
+
* }
|
|
278
|
+
*
|
|
279
|
+
* // Display the fixed column count
|
|
280
|
+
* const label = `LOCKED: ${t.grid.cols} COLS`;
|
|
281
|
+
* t.charColor(255);
|
|
282
|
+
* for(let i=0; i<label.length; i++) {
|
|
283
|
+
* t.push(); t.translate(i - label.length/2, 10); t.char(label[i]); t.point(); t.pop();
|
|
284
|
+
* }
|
|
285
|
+
* });
|
|
286
|
+
*
|
|
287
|
+
* t.windowResized(() => {
|
|
288
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
289
|
+
* });
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
set cols(newCols: number);
|
|
293
|
+
/**
|
|
294
|
+
* Returns the number of rows in the grid.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```javascript
|
|
298
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
299
|
+
*
|
|
300
|
+
* t.draw(() => {
|
|
301
|
+
* t.background(0);
|
|
302
|
+
*
|
|
303
|
+
* const rows = t.grid.rows;
|
|
304
|
+
*
|
|
305
|
+
* // Draw horizontal stripes
|
|
306
|
+
* for (let y = 0; y < rows; y++) {
|
|
307
|
+
* const brightness = (y / rows) * 255;
|
|
308
|
+
* t.cellColor(brightness, 0, 255 - brightness);
|
|
309
|
+
*
|
|
310
|
+
* // Draw a full row
|
|
311
|
+
* t.push();
|
|
312
|
+
* // Note: Default coordinates are centered.
|
|
313
|
+
* // We need to calculate Y relative to center.
|
|
314
|
+
* t.translateY(y - rows / 2 + 0.5);
|
|
315
|
+
* t.rect(t.grid.cols, 1);
|
|
316
|
+
* t.pop();
|
|
317
|
+
* }
|
|
318
|
+
* });
|
|
319
|
+
*
|
|
320
|
+
* t.windowResized(() => {
|
|
321
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
322
|
+
* });
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
get rows(): number;
|
|
326
|
+
/**
|
|
327
|
+
* Sets the number of rows and locks grid sizing until `responsive()` is called.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```javascript
|
|
331
|
+
* // Locking the grid rows
|
|
332
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
333
|
+
*
|
|
334
|
+
* t.setup(() => {
|
|
335
|
+
* // Lock the grid to exactly 15 rows.
|
|
336
|
+
* t.grid.rows = 15;
|
|
337
|
+
* });
|
|
338
|
+
*
|
|
339
|
+
* t.draw(() => {
|
|
340
|
+
* t.background(20, 0, 40);
|
|
341
|
+
*
|
|
342
|
+
* // Visualize the 15 locked rows
|
|
343
|
+
* for (let y = -7; y <= 7; y++) {
|
|
344
|
+
* const brightness = 127 + 127 * Math.sin(t.frameCount * 0.1 + y);
|
|
345
|
+
* t.push();
|
|
346
|
+
* t.translate(0, y);
|
|
347
|
+
* t.charColor(brightness, 100, 255);
|
|
348
|
+
* t.char('=');
|
|
349
|
+
* t.rect(t.grid.cols, 1);
|
|
350
|
+
* t.pop();
|
|
351
|
+
* }
|
|
352
|
+
*
|
|
353
|
+
* const label = `LOCKED: ${t.grid.rows} ROWS`;
|
|
354
|
+
* t.charColor(255, 255, 0);
|
|
355
|
+
* for(let i=0; i<label.length; i++) {
|
|
356
|
+
* t.push(); t.translate(i - label.length/2, 0); t.char(label[i]); t.cellColor(0); t.point(); t.pop();
|
|
357
|
+
* }
|
|
358
|
+
* });
|
|
359
|
+
*
|
|
360
|
+
* t.windowResized(() => {
|
|
361
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
362
|
+
* });
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
set rows(newRows: number);
|
|
366
|
+
/**
|
|
367
|
+
* Returns the total width of the grid in screen pixels.
|
|
368
|
+
*
|
|
369
|
+
* This is equal to `cols * cellWidth`.
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```javascript
|
|
373
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
374
|
+
*
|
|
375
|
+
* t.draw(() => {
|
|
376
|
+
* t.background(0);
|
|
377
|
+
*
|
|
378
|
+
* // Visualize the grid width vs window width
|
|
379
|
+
* const percent = (t.grid.width / window.innerWidth) * 100;
|
|
380
|
+
*
|
|
381
|
+
* const text = `Grid covers ${percent.toFixed(1)}% of width`;
|
|
382
|
+
*
|
|
383
|
+
* for (let i = 0; i < text.length; i++) {
|
|
384
|
+
* t.push();
|
|
385
|
+
* t.translate(i - text.length / 2, 0);
|
|
386
|
+
* t.char(text[i]);
|
|
387
|
+
* t.charColor(0, 255, 255);
|
|
388
|
+
* t.point();
|
|
389
|
+
* t.pop();
|
|
390
|
+
* }
|
|
391
|
+
* });
|
|
392
|
+
*
|
|
393
|
+
* t.windowResized(() => {
|
|
394
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
395
|
+
* });
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
get width(): number;
|
|
399
|
+
/**
|
|
400
|
+
* Returns the total height of the grid in screen pixels.
|
|
401
|
+
*
|
|
402
|
+
* This is equal to `rows * cellHeight`.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```javascript
|
|
406
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
407
|
+
*
|
|
408
|
+
* t.draw(() => {
|
|
409
|
+
* t.background(0);
|
|
410
|
+
*
|
|
411
|
+
* // Display the total grid height in pixels
|
|
412
|
+
* const h = t.grid.height;
|
|
413
|
+
* const label = `${h}px`;
|
|
414
|
+
*
|
|
415
|
+
* // Draw a vertical gradient ruler
|
|
416
|
+
* for (let i = 0; i < t.grid.rows; i++) {
|
|
417
|
+
* const y = i - t.grid.rows / 2;
|
|
418
|
+
* // Gradient from center (blue) to edges (pink)
|
|
419
|
+
* const brightness = Math.abs(y / (t.grid.rows / 2)) * 255;
|
|
420
|
+
*
|
|
421
|
+
* t.push();
|
|
422
|
+
* t.translate(0, y);
|
|
423
|
+
* t.char('|');
|
|
424
|
+
* t.charColor(255, 100, 255 - brightness);
|
|
425
|
+
* t.point();
|
|
426
|
+
* t.pop();
|
|
427
|
+
* }
|
|
428
|
+
*
|
|
429
|
+
* // Overlay the pixel height text
|
|
430
|
+
* for (let i = 0; i < label.length; i++) {
|
|
431
|
+
* t.push();
|
|
432
|
+
* t.translate(i - label.length / 2, 0);
|
|
433
|
+
* t.char(label[i]);
|
|
434
|
+
* t.cellColor(0);
|
|
435
|
+
* t.charColor(255);
|
|
436
|
+
* t.point();
|
|
437
|
+
* t.pop();
|
|
438
|
+
* }
|
|
439
|
+
* });
|
|
440
|
+
*
|
|
441
|
+
* t.windowResized(() => {
|
|
442
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
443
|
+
* });
|
|
444
|
+
* ```
|
|
445
|
+
*/
|
|
446
|
+
get height(): number;
|
|
447
|
+
/**
|
|
448
|
+
* Returns the horizontal offset (margin) in pixels from the canvas edge to the grid.
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```javascript
|
|
452
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
453
|
+
*
|
|
454
|
+
* t.draw(() => {
|
|
455
|
+
* t.background(0);
|
|
456
|
+
*
|
|
457
|
+
* const margin = t.grid.offsetX;
|
|
458
|
+
* const text = `X MARGIN: ${margin}px`;
|
|
459
|
+
*
|
|
460
|
+
* for (let i = 0; i < text.length; i++) {
|
|
461
|
+
* t.push();
|
|
462
|
+
* t.translate(i - text.length / 2, -2);
|
|
463
|
+
* t.char(text[i]);
|
|
464
|
+
* t.charColor(200, 200, 255);
|
|
465
|
+
* t.point();
|
|
466
|
+
* t.pop();
|
|
467
|
+
* }
|
|
468
|
+
* });
|
|
469
|
+
*
|
|
470
|
+
* t.windowResized(() => {
|
|
471
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
472
|
+
* });
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
get offsetX(): number;
|
|
476
|
+
/**
|
|
477
|
+
* Returns the vertical offset (margin) in pixels from the canvas edge to the grid.
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```javascript
|
|
481
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
482
|
+
*
|
|
483
|
+
* t.draw(() => {
|
|
484
|
+
* t.background(0);
|
|
485
|
+
*
|
|
486
|
+
* const margin = t.grid.offsetY;
|
|
487
|
+
* const text = `Y MARGIN: ${margin}px`;
|
|
488
|
+
*
|
|
489
|
+
* for (let i = 0; i < text.length; i++) {
|
|
490
|
+
* t.push();
|
|
491
|
+
* t.translate(i - text.length / 2, 2);
|
|
492
|
+
* t.char(text[i]);
|
|
493
|
+
* t.charColor(255, 200, 200);
|
|
494
|
+
* t.point();
|
|
495
|
+
* t.pop();
|
|
496
|
+
* }
|
|
497
|
+
* });
|
|
498
|
+
*
|
|
499
|
+
* t.windowResized(() => {
|
|
500
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
501
|
+
* });
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
get offsetY(): number;
|
|
505
|
+
/**
|
|
506
|
+
* Restores responsive sizing so subsequent `t.resizeCanvas` calls recompute cols/rows.
|
|
507
|
+
*
|
|
508
|
+
* A grid becomes non-responsive when either `cols` or `rows` is manually set.
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```javascript
|
|
512
|
+
* // Restoring responsive sizing
|
|
513
|
+
* const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
|
|
514
|
+
*
|
|
515
|
+
* let isLocked = false;
|
|
516
|
+
*
|
|
517
|
+
* t.draw(() => {
|
|
518
|
+
* t.background(0);
|
|
519
|
+
*
|
|
520
|
+
* t.charColor(isLocked ? t.color(255, 100, 100) : t.color(100, 255, 100));
|
|
521
|
+
* t.char(isLocked ? 'L' : 'R');
|
|
522
|
+
*
|
|
523
|
+
* // Draw a frame fitting the current grid
|
|
524
|
+
* t.rect(t.grid.cols - 2, t.grid.rows - 2);
|
|
525
|
+
*
|
|
526
|
+
* const msg = isLocked ? "LOCKED (Fixed 20x10)" : "RESPONSIVE (Auto-size)";
|
|
527
|
+
* for(let i=0; i<msg.length; i++) {
|
|
528
|
+
* t.push(); t.translate(i - msg.length/2, 0); t.char(msg[i]); t.cellColor(0); t.point(); t.pop();
|
|
529
|
+
* }
|
|
530
|
+
* });
|
|
531
|
+
*
|
|
532
|
+
* t.mousePressed(() => {
|
|
533
|
+
* isLocked = !isLocked;
|
|
534
|
+
*
|
|
535
|
+
* if (isLocked) {
|
|
536
|
+
* t.grid.cols = 20;
|
|
537
|
+
* t.grid.rows = 10;
|
|
538
|
+
* } else {
|
|
539
|
+
* // Restore automatic sizing based on window/canvas dimensions
|
|
540
|
+
* t.grid.responsive();
|
|
541
|
+
* t.grid.reset();
|
|
542
|
+
* }
|
|
543
|
+
* });
|
|
544
|
+
*
|
|
545
|
+
* t.windowResized(() => {
|
|
546
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
547
|
+
* });
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
responsive(): void;
|
|
551
|
+
/**
|
|
552
|
+
* Convert client coordinates (e.g. from mouse/touch events) to grid coordinates.
|
|
553
|
+
* Returns center-based coordinates matching the rendering space.
|
|
554
|
+
* Returns {x: -Infinity, y: -Infinity} if outside grid bounds.
|
|
555
|
+
* @ignore
|
|
556
|
+
*/
|
|
557
|
+
$clientToGrid(clientX: number, clientY: number): GridPosition;
|
|
558
|
+
/**
|
|
559
|
+
* Dispose the grid and remove all listeners.
|
|
560
|
+
* @ignore
|
|
561
|
+
*/
|
|
562
|
+
$dispose(): void;
|
|
563
|
+
}
|