jclic 2.1.21 → 2.1.22
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/CHANGELOG.md +4 -0
- package/dist/jclic-node.js +1 -1
- package/dist/jclic-node.js.map +1 -1
- package/dist/jclic.min.js +2 -2
- package/dist/jclic.min.js.map +1 -1
- package/package.json +1 -1
- package/src/GlobalData.js +1 -1
- package/dist/1078.jclic-node.js +0 -282
- package/dist/1078.jclic-node.js.map +0 -1
- package/dist/1196.jclic-node.js +0 -808
- package/dist/1196.jclic-node.js.map +0 -1
- package/dist/1253.jclic-node.js +0 -1432
- package/dist/1253.jclic-node.js.map +0 -1
- package/dist/13.jclic-node.js +0 -103
- package/dist/13.jclic-node.js.map +0 -1
- package/dist/1567.jclic-node.js +0 -2313
- package/dist/1567.jclic-node.js.map +0 -1
- package/dist/1588.jclic-node.js +0 -602
- package/dist/1588.jclic-node.js.map +0 -1
- package/dist/1725.jclic-node.js +0 -836
- package/dist/1725.jclic-node.js.map +0 -1
- package/dist/1731.jclic-node.js +0 -438
- package/dist/1731.jclic-node.js.map +0 -1
- package/dist/1842.jclic-node.js +0 -651
- package/dist/1842.jclic-node.js.map +0 -1
- package/dist/2160.jclic-node.js +0 -1016
- package/dist/2160.jclic-node.js.map +0 -1
- package/dist/222.jclic-node.js +0 -129
- package/dist/222.jclic-node.js.map +0 -1
- package/dist/2316.jclic-node.js +0 -949
- package/dist/2316.jclic-node.js.map +0 -1
- package/dist/2355.jclic-node.js +0 -371
- package/dist/2355.jclic-node.js.map +0 -1
- package/dist/2366.jclic-node.js +0 -431
- package/dist/2366.jclic-node.js.map +0 -1
- package/dist/2379.jclic-node.js +0 -202
- package/dist/2379.jclic-node.js.map +0 -1
- package/dist/2437.jclic-node.js +0 -450
- package/dist/2437.jclic-node.js.map +0 -1
- package/dist/2531.jclic-node.js +0 -869
- package/dist/2531.jclic-node.js.map +0 -1
- package/dist/2608.jclic-node.js +0 -160
- package/dist/2608.jclic-node.js.map +0 -1
- package/dist/2715.jclic-node.js +0 -554
- package/dist/2715.jclic-node.js.map +0 -1
- package/dist/277.jclic-node.js +0 -22
- package/dist/277.jclic-node.js.map +0 -1
- package/dist/2921.jclic-node.js +0 -660
- package/dist/2921.jclic-node.js.map +0 -1
- package/dist/2952.jclic-node.js +0 -101
- package/dist/2952.jclic-node.js.map +0 -1
- package/dist/3018.jclic-node.js +0 -421
- package/dist/3018.jclic-node.js.map +0 -1
- package/dist/3019.jclic-node.js +0 -682
- package/dist/3019.jclic-node.js.map +0 -1
- package/dist/3231.jclic-node.js +0 -274
- package/dist/3231.jclic-node.js.map +0 -1
- package/dist/331.jclic-node.js +0 -115
- package/dist/331.jclic-node.js.map +0 -1
- package/dist/3391.jclic-node.js +0 -276
- package/dist/3391.jclic-node.js.map +0 -1
- package/dist/3502.jclic-node.js +0 -671
- package/dist/3502.jclic-node.js.map +0 -1
- package/dist/3653.jclic-node.js +0 -982
- package/dist/3653.jclic-node.js.map +0 -1
- package/dist/371.jclic.min.js +0 -2
- package/dist/371.jclic.min.js.map +0 -1
- package/dist/3856.jclic-node.js +0 -575
- package/dist/3856.jclic-node.js.map +0 -1
- package/dist/4112.jclic-node.js +0 -659
- package/dist/4112.jclic-node.js.map +0 -1
- package/dist/4123.jclic-node.js +0 -910
- package/dist/4123.jclic-node.js.map +0 -1
- package/dist/427.jclic-node.js +0 -894
- package/dist/427.jclic-node.js.map +0 -1
- package/dist/4483.jclic-node.js +0 -327
- package/dist/4483.jclic-node.js.map +0 -1
- package/dist/4548.jclic-node.js +0 -1078
- package/dist/4548.jclic-node.js.map +0 -1
- package/dist/466.jclic-node.js +0 -99
- package/dist/466.jclic-node.js.map +0 -1
- package/dist/485.jclic-node.js +0 -783
- package/dist/485.jclic-node.js.map +0 -1
- package/dist/4921.jclic-node.js +0 -500
- package/dist/4921.jclic-node.js.map +0 -1
- package/dist/5091.jclic-node.js +0 -239
- package/dist/5091.jclic-node.js.map +0 -1
- package/dist/520.jclic-node.js +0 -550
- package/dist/520.jclic-node.js.map +0 -1
- package/dist/5312.jclic-node.js +0 -1126
- package/dist/5312.jclic-node.js.map +0 -1
- package/dist/5338.jclic-node.js +0 -212
- package/dist/5338.jclic-node.js.map +0 -1
- package/dist/5344.jclic-node.js +0 -229
- package/dist/5344.jclic-node.js.map +0 -1
- package/dist/5550.jclic-node.js +0 -238
- package/dist/5550.jclic-node.js.map +0 -1
- package/dist/5626.jclic-node.js +0 -614
- package/dist/5626.jclic-node.js.map +0 -1
- package/dist/5977.jclic-node.js +0 -1081
- package/dist/5977.jclic-node.js.map +0 -1
- package/dist/6148.jclic-node.js +0 -345
- package/dist/6148.jclic-node.js.map +0 -1
- package/dist/6176.jclic-node.js +0 -481
- package/dist/6176.jclic-node.js.map +0 -1
- package/dist/6221.jclic-node.js +0 -1072
- package/dist/6221.jclic-node.js.map +0 -1
- package/dist/6238.jclic-node.js +0 -718
- package/dist/6238.jclic-node.js.map +0 -1
- package/dist/6454.jclic-node.js +0 -1413
- package/dist/6454.jclic-node.js.map +0 -1
- package/dist/6565.jclic-node.js +0 -294
- package/dist/6565.jclic-node.js.map +0 -1
- package/dist/6579.jclic-node.js +0 -719
- package/dist/6579.jclic-node.js.map +0 -1
- package/dist/6715.jclic-node.js +0 -148
- package/dist/6715.jclic-node.js.map +0 -1
- package/dist/6777.jclic-node.js +0 -171
- package/dist/6777.jclic-node.js.map +0 -1
- package/dist/6782.jclic-node.js +0 -1611
- package/dist/6782.jclic-node.js.map +0 -1
- package/dist/6847.jclic-node.js +0 -601
- package/dist/6847.jclic-node.js.map +0 -1
- package/dist/6856.jclic-node.js +0 -252
- package/dist/6856.jclic-node.js.map +0 -1
- package/dist/696.jclic-node.js +0 -1821
- package/dist/696.jclic-node.js.map +0 -1
- package/dist/698.jclic-node.js +0 -583
- package/dist/698.jclic-node.js.map +0 -1
- package/dist/704.jclic-node.js +0 -80
- package/dist/704.jclic-node.js.map +0 -1
- package/dist/7046.jclic-node.js +0 -735
- package/dist/7046.jclic-node.js.map +0 -1
- package/dist/7220.jclic-node.js +0 -156
- package/dist/7220.jclic-node.js.map +0 -1
- package/dist/7257.jclic-node.js +0 -931
- package/dist/7257.jclic-node.js.map +0 -1
- package/dist/743.jclic-node.js +0 -583
- package/dist/743.jclic-node.js.map +0 -1
- package/dist/757.jclic-node.js +0 -1072
- package/dist/757.jclic-node.js.map +0 -1
- package/dist/7781.jclic-node.js +0 -202
- package/dist/7781.jclic-node.js.map +0 -1
- package/dist/7912.jclic-node.js +0 -2103
- package/dist/7912.jclic-node.js.map +0 -1
- package/dist/827.jclic-node.js +0 -708
- package/dist/827.jclic-node.js.map +0 -1
- package/dist/8276.jclic-node.js +0 -409
- package/dist/8276.jclic-node.js.map +0 -1
- package/dist/8322.jclic-node.js +0 -498
- package/dist/8322.jclic-node.js.map +0 -1
- package/dist/8641.jclic-node.js +0 -360
- package/dist/8641.jclic-node.js.map +0 -1
- package/dist/8837.jclic-node.js +0 -651
- package/dist/8837.jclic-node.js.map +0 -1
- package/dist/8895.jclic-node.js +0 -151
- package/dist/8895.jclic-node.js.map +0 -1
- package/dist/9072.jclic-node.js +0 -1285
- package/dist/9072.jclic-node.js.map +0 -1
- package/dist/9078.jclic-node.js +0 -935
- package/dist/9078.jclic-node.js.map +0 -1
- package/dist/9103.jclic-node.js +0 -718
- package/dist/9103.jclic-node.js.map +0 -1
- package/dist/9359.jclic-node.js +0 -145
- package/dist/9359.jclic-node.js.map +0 -1
- package/dist/9409.jclic-node.js +0 -921
- package/dist/9409.jclic-node.js.map +0 -1
- package/dist/9513.jclic-node.js +0 -720
- package/dist/9513.jclic-node.js.map +0 -1
- package/dist/9704.jclic-node.js +0 -81
- package/dist/9704.jclic-node.js.map +0 -1
- package/dist/9950.jclic-node.js +0 -827
- package/dist/9950.jclic-node.js.map +0 -1
package/dist/4123.jclic-node.js
DELETED
|
@@ -1,910 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.id = 4123;
|
|
3
|
-
exports.ids = [4123];
|
|
4
|
-
exports.modules = {
|
|
5
|
-
|
|
6
|
-
/***/ 4123:
|
|
7
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
8
|
-
|
|
9
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
10
|
-
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
11
|
-
/* harmony export */ });
|
|
12
|
-
/* unused harmony exports defaults, flags, TextGrid */
|
|
13
|
-
/* harmony import */ var _AWT_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7912);
|
|
14
|
-
/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1253);
|
|
15
|
-
/* harmony import */ var _AbstractBox_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9513);
|
|
16
|
-
/* harmony import */ var _TextGridContent_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1842);
|
|
17
|
-
/**
|
|
18
|
-
* File : boxes/TextGrid.js
|
|
19
|
-
* Created : 12/06/2015
|
|
20
|
-
* By : Francesc Busquets <francesc@gmail.com>
|
|
21
|
-
*
|
|
22
|
-
* JClic.js
|
|
23
|
-
* An HTML5 player of JClic activities
|
|
24
|
-
* https://projectestac.github.io/jclic.js
|
|
25
|
-
*
|
|
26
|
-
* @source https://github.com/projectestac/jclic.js
|
|
27
|
-
*
|
|
28
|
-
* @license EUPL-1.2
|
|
29
|
-
* @licstart
|
|
30
|
-
* (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)
|
|
31
|
-
*
|
|
32
|
-
* Licensed under the EUPL, Version 1.1 or -as soon they will be approved by
|
|
33
|
-
* the European Commission- subsequent versions of the EUPL (the "Licence");
|
|
34
|
-
* You may not use this work except in compliance with the Licence.
|
|
35
|
-
*
|
|
36
|
-
* You may obtain a copy of the Licence at:
|
|
37
|
-
* https://joinup.ec.europa.eu/software/page/eupl
|
|
38
|
-
*
|
|
39
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
40
|
-
* distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
|
|
41
|
-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
42
|
-
* Licence for the specific language governing permissions and limitations
|
|
43
|
-
* under the Licence.
|
|
44
|
-
* @licend
|
|
45
|
-
* @module
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Default values
|
|
55
|
-
* @type {object}
|
|
56
|
-
*/
|
|
57
|
-
const defaults = {
|
|
58
|
-
MIN_CELL_SIZE: 12,
|
|
59
|
-
DEFAULT_CELL_SIZE: 20,
|
|
60
|
-
MIN_INTERNAL_MARGIN: 2
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Binary flags used to mark status
|
|
65
|
-
* @type {object}
|
|
66
|
-
*/
|
|
67
|
-
const flags = {
|
|
68
|
-
NORMAL: 0,
|
|
69
|
-
INVERTED: 1,
|
|
70
|
-
HIDDEN: 2,
|
|
71
|
-
LOCKED: 4,
|
|
72
|
-
MARKED: 8,
|
|
73
|
-
TRANSPARENT: 16
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* This class is a special type of {@link module:boxes/AbstractBox.AbstractBox AbstractBox} that displays a grid of single
|
|
78
|
-
* characters.
|
|
79
|
-
*
|
|
80
|
-
* It's used {@link module:activities/textGrid/CrossWord.CrossWord CrossWord} and {@link module:activities/textGrid/WordSearch.WordSearch WordSearch} activities.
|
|
81
|
-
* @extends module:boxes/AbstractBox.AbstractBox
|
|
82
|
-
*/
|
|
83
|
-
class TextGrid extends _AbstractBox_js__WEBPACK_IMPORTED_MODULE_2__["default"] {
|
|
84
|
-
/**
|
|
85
|
-
* TextGrid constructor
|
|
86
|
-
* @param {module:boxes/AbstractBox.AbstractBox} parent - The AbstractBox to which this text grid belongs
|
|
87
|
-
* @param {module:AWT.Container} container - The container where this text grid is placed.
|
|
88
|
-
* @param {module:boxes/BoxBase.BoxBase} boxBase - The object where colors, fonts, border and other graphic properties
|
|
89
|
-
* @param {number} x - `X` coordinate of the upper left corner of this grid
|
|
90
|
-
* @param {number} y - `Y` coordinate of the upper left corner of this grid
|
|
91
|
-
* @param {number} ncw - Number of columns of the grid
|
|
92
|
-
* @param {number} nch - Nomber of rows of the grid
|
|
93
|
-
* @param {number} cellW - Width of the cells
|
|
94
|
-
* @param {number} cellH - Height of the cells
|
|
95
|
-
* @param {boolean} border - When `true`, a border must be drawn between the cells
|
|
96
|
-
*/
|
|
97
|
-
constructor(parent, container, boxBase, x, y, ncw, nch, cellW, cellH, border) {
|
|
98
|
-
// *TextGrid* extends [AbstractBox](AbstractBox.html)
|
|
99
|
-
super(parent, container, boxBase);
|
|
100
|
-
this.pos.x = x;
|
|
101
|
-
this.pos.y = y;
|
|
102
|
-
this.nCols = Math.max(1, ncw);
|
|
103
|
-
this.nRows = Math.max(1, nch);
|
|
104
|
-
this.cellWidth = Math.max(cellW, defaults.MIN_CELL_SIZE);
|
|
105
|
-
this.cellHeight = Math.max(cellH, defaults.MIN_CELL_SIZE);
|
|
106
|
-
this.dim.width = cellW * this.nCols;
|
|
107
|
-
this.dim.height = cellH * this.nRows;
|
|
108
|
-
this.setChars(' ');
|
|
109
|
-
this.preferredBounds = new _AWT_js__WEBPACK_IMPORTED_MODULE_0__/* .Rectangle */ .M_(this.pos, this.dim);
|
|
110
|
-
this.setBorder(border);
|
|
111
|
-
this.cursorTimer = new _AWT_js__WEBPACK_IMPORTED_MODULE_0__/* .Timer */ .M4(() => this.blink(0), 500, false);
|
|
112
|
-
this.cursorEnabled = false;
|
|
113
|
-
this.useCursor = false;
|
|
114
|
-
this.wildTransparent = false;
|
|
115
|
-
this.cursor = new _AWT_js__WEBPACK_IMPORTED_MODULE_0__/* .Point */ .bR();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Factory constructor that creates an empty grid based on a {@link module:boxes/TextGridContent.TextGridContent TextGridContent}
|
|
120
|
-
* @param {module:boxes/AbstractBox.AbstractBox} parent - The AbstractBox to which the text grid belongs
|
|
121
|
-
* @param {module:AWT.Container} container - The container where the text grid will be placed.
|
|
122
|
-
* @param {number} x - `X` coordinate of the upper left corner of the grid
|
|
123
|
-
* @param {number} y - `Y` coordinate of the upper left corner of the grid
|
|
124
|
-
* @param {module:boxes/TextGridContent.TextGridContent} tgc - Object with the content and other settings of the grid
|
|
125
|
-
* @param {boolean} wildTransparent - When `true`, the wildcard character will be transparent
|
|
126
|
-
* @returns {module:boxes/TextGrid.TextGrid}
|
|
127
|
-
*/
|
|
128
|
-
static createEmptyGrid(parent, container, x, y, tgc, wildTransparent) {
|
|
129
|
-
const result = new TextGrid(parent, container, tgc.style,
|
|
130
|
-
x, y, tgc.ncw, tgc.nch, tgc.w, tgc.h, tgc.border);
|
|
131
|
-
result.wild = tgc.wild;
|
|
132
|
-
result.randomChars = tgc.randomChars;
|
|
133
|
-
result.wildTransparent = wildTransparent;
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Sets the characters to be placed in the cells of this TextGrid
|
|
139
|
-
* @param {string} text
|
|
140
|
-
*/
|
|
141
|
-
setChars(text) {
|
|
142
|
-
this.chars = [];
|
|
143
|
-
this.answers = [];
|
|
144
|
-
this.attributes = [];
|
|
145
|
-
for (let py = 0; py < this.nRows; py++) {
|
|
146
|
-
const line = py < text.length ? text[py] : '';
|
|
147
|
-
this.chars[py] = line.split('');
|
|
148
|
-
this.answers[py] = [];
|
|
149
|
-
this.attributes[py] = [];
|
|
150
|
-
for (let px = 0; px < this.nCols; px++) {
|
|
151
|
-
if (px >= line.length)
|
|
152
|
-
this.chars[py][px] = ' ';
|
|
153
|
-
this.answers[py][px] = this.chars[py][px];
|
|
154
|
-
this.attributes[py][px] = flags.NORMAL;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Substitutes the current content of all cells with wildcards with a randomly generated char.
|
|
161
|
-
* @see TextGridContent#randomChars
|
|
162
|
-
*/
|
|
163
|
-
randomize() {
|
|
164
|
-
for (let py = 0; py < this.nRows; py++)
|
|
165
|
-
for (let px = 0; px < this.nCols; px++)
|
|
166
|
-
if (this.chars[py][px] === this.wild)
|
|
167
|
-
this.chars[py][px] = this.randomChars.charAt(
|
|
168
|
-
Math.floor(Math.random() * this.randomChars.length));
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Clears or sets global attributes to all cells
|
|
173
|
-
* @param {boolean} lockWild - When `true`, the wildcard cells will be marked with special
|
|
174
|
-
* attributes (used in CrossWords to mark black cells)
|
|
175
|
-
* @param {boolean} clearChars - When `true`, the current content of cells will be erased.
|
|
176
|
-
*/
|
|
177
|
-
setCellAttributes(lockWild, clearChars) {
|
|
178
|
-
let atr = flags.LOCKED;
|
|
179
|
-
if (this.wildTransparent)
|
|
180
|
-
atr |= flags.TRANSPARENT;
|
|
181
|
-
else
|
|
182
|
-
atr |= flags.INVERTED | flags.HIDDEN;
|
|
183
|
-
for (let py = 0; py < this.nRows; py++) {
|
|
184
|
-
for (let px = 0; px < this.nCols; px++) {
|
|
185
|
-
if (lockWild && this.chars[py][px] === this.wild)
|
|
186
|
-
this.attributes[py][px] = atr;
|
|
187
|
-
else {
|
|
188
|
-
this.attributes[py][px] = flags.NORMAL;
|
|
189
|
-
if (clearChars)
|
|
190
|
-
this.chars[py][px] = ' ';
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Sets or unsets the `locked` properties (black cell) to a specific cell.
|
|
198
|
-
* @param {number} px - The logical 'X' coordinate of the cell
|
|
199
|
-
* @param {number} py - The logical 'Y' coordinate of the cell
|
|
200
|
-
* @param {boolean} locked - When true, the `locked` attribute will be on.
|
|
201
|
-
*/
|
|
202
|
-
setCellLocked(px, py, locked) {
|
|
203
|
-
if (px >= 0 && px < this.nCols && py >= 0 && py < this.nRows) {
|
|
204
|
-
this.attributes[py][px] = locked ?
|
|
205
|
-
flags.LOCKED |
|
|
206
|
-
(this.wildTransparent ?
|
|
207
|
-
flags.TRANSPARENT :
|
|
208
|
-
flags.INVERTED |
|
|
209
|
-
flags.HIDDEN) :
|
|
210
|
-
flags.NORMAL;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* For a specific cell located at column `rx` and row `ry`, finds the number of words delimited
|
|
216
|
-
* by wildchars located behind its current position and in the same row and column. Used in
|
|
217
|
-
* {@link module:activities/textGrid/CrossWord.CrossWord CrossWord} activities to find the definition for a specific cell.
|
|
218
|
-
*
|
|
219
|
-
* The result is returned as 'x' and 'y' properties of a logical point.
|
|
220
|
-
* @param {number} rx - The 'X' position of the cell
|
|
221
|
-
* @param {number} ry - The 'Y' position of the cell
|
|
222
|
-
* @returns {module:AWT.Point} - The logical positions of the definition for this cell inside the list
|
|
223
|
-
* of current definitions of its row and column. '0' means first definition of its row/column,
|
|
224
|
-
* '1' the second one, etc.
|
|
225
|
-
*/
|
|
226
|
-
getItemFor(rx, ry) {
|
|
227
|
-
if (!this.isValidCell(rx, ry))
|
|
228
|
-
return null;
|
|
229
|
-
|
|
230
|
-
const point = new _AWT_js__WEBPACK_IMPORTED_MODULE_0__/* .Point */ .bR();
|
|
231
|
-
let
|
|
232
|
-
inBlack = false,
|
|
233
|
-
startCount = false;
|
|
234
|
-
|
|
235
|
-
for (let px = 0; px < rx; px++) {
|
|
236
|
-
if ((this.attributes[ry][px] & flags.LOCKED) !== 0) {
|
|
237
|
-
if (!inBlack) {
|
|
238
|
-
if (startCount)
|
|
239
|
-
point.x++;
|
|
240
|
-
inBlack = true;
|
|
241
|
-
}
|
|
242
|
-
} else {
|
|
243
|
-
startCount = true;
|
|
244
|
-
inBlack = false;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
inBlack = false;
|
|
248
|
-
startCount = false;
|
|
249
|
-
for (let py = 0; py < ry; py++) {
|
|
250
|
-
if ((this.attributes[py][rx] & flags.LOCKED) !== 0) {
|
|
251
|
-
if (!inBlack) {
|
|
252
|
-
if (startCount)
|
|
253
|
-
point.y++;
|
|
254
|
-
inBlack = true;
|
|
255
|
-
}
|
|
256
|
-
} else {
|
|
257
|
-
startCount = true;
|
|
258
|
-
inBlack = false;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return point;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Whether the blinking cursor must be enabled or disabled.
|
|
266
|
-
* @param {boolean} status
|
|
267
|
-
*/
|
|
268
|
-
setCursorEnabled(status) {
|
|
269
|
-
this.cursorEnabled = status;
|
|
270
|
-
if (status === true)
|
|
271
|
-
this.startCursorBlink();
|
|
272
|
-
else
|
|
273
|
-
this.stopCursorBlink();
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Starts the {@link module:AWT.Timer} that makes the cursor blink.
|
|
278
|
-
*/
|
|
279
|
-
startCursorBlink() {
|
|
280
|
-
if (this.useCursor && this.cursorEnabled && this.cursorTimer && !this.cursorTimer.isRunning()) {
|
|
281
|
-
this.blink(1);
|
|
282
|
-
this.cursorTimer.start();
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Stops the {@link module:AWT.Timer} that makes the cursor blink.
|
|
288
|
-
*/
|
|
289
|
-
stopCursorBlink() {
|
|
290
|
-
if (this.cursorTimer && this.cursorTimer.isRunning()) {
|
|
291
|
-
this.cursorTimer.stop();
|
|
292
|
-
this.blink(-1);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Moves the cursor in the specified x and y directions.
|
|
298
|
-
* @param {number} dx - Amount to move in the 'X' axis
|
|
299
|
-
* @param {number} dy - Amount to move in the 'Y' axis
|
|
300
|
-
* @param {boolean} skipLocked - Skip locked cells (wildcards in {@link module:activities/textGrid/CrossWord.CrossWord CrossWord})
|
|
301
|
-
*/
|
|
302
|
-
moveCursor(dx, dy, skipLocked) {
|
|
303
|
-
if (this.useCursor) {
|
|
304
|
-
const point = this.findNextCellWithAttr(this.cursor.x, this.cursor.y,
|
|
305
|
-
skipLocked ? flags.LOCKED : flags.NORMAL,
|
|
306
|
-
dx, dy, false);
|
|
307
|
-
|
|
308
|
-
if (!this.cursor.equals(point))
|
|
309
|
-
this.setCursorAt(point.x, point.y, skipLocked);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Finds the coordinates of the nearest non-locked cell (non-wildcard) moving on the indicated
|
|
315
|
-
* 'X' and 'Y' directions.
|
|
316
|
-
* @param {module:AWT.Point} - Logical coordinates of the starting point
|
|
317
|
-
* @param {number} dx - 0 means no movement, 1 go right, -1 go left.
|
|
318
|
-
* @param {number} dy - 0 means no movement, 1 go down, -1 go up.
|
|
319
|
-
* @returns {module:AWT.Point}
|
|
320
|
-
*/
|
|
321
|
-
findFreeCell(from, dx, dy) {
|
|
322
|
-
let result = null;
|
|
323
|
-
if (from && (dx !== 0 || dy !== 0)) {
|
|
324
|
-
const scan = new _AWT_js__WEBPACK_IMPORTED_MODULE_0__/* .Point */ .bR(from);
|
|
325
|
-
while (result === null) {
|
|
326
|
-
scan.x += dx;
|
|
327
|
-
scan.y += dy;
|
|
328
|
-
if (scan.x < 0 || scan.x >= this.nCols || scan.y < 0 || scan.y >= this.nRows)
|
|
329
|
-
break;
|
|
330
|
-
if (!this.getCellAttribute(scan.x, scan.y, flags.LOCKED))
|
|
331
|
-
result = scan;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return result;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Finds the first cell with the specified attributes at the specified state, starting
|
|
339
|
-
* at specified point.
|
|
340
|
-
* @param {number} startX - Starting X coordinate
|
|
341
|
-
* @param {number} startY - Starting Y coordinate
|
|
342
|
-
* @param {number} attr - Attribute to check. See {@link module:boxes/TextGrid.TextGrid.flags}.
|
|
343
|
-
* @param {number} dx - 0 means no movement, 1 go right, -1 go left.
|
|
344
|
-
* @param {number} dy - 0 means no movement, 1 go down, -1 go up.
|
|
345
|
-
* @param {boolean} attrState - Desired state (enabled or disabled) of `attr`
|
|
346
|
-
* @returns {module:AWT.Point}
|
|
347
|
-
*/
|
|
348
|
-
findNextCellWithAttr(startX, startY, attr, dx, dy, attrState) {
|
|
349
|
-
const point = new _AWT_js__WEBPACK_IMPORTED_MODULE_0__/* .Point */ .bR(startX + dx, startY + dy);
|
|
350
|
-
while (true) {
|
|
351
|
-
if (point.x < 0) {
|
|
352
|
-
point.x = this.nCols - 1;
|
|
353
|
-
if (point.y > 0)
|
|
354
|
-
point.y--;
|
|
355
|
-
else
|
|
356
|
-
point.y = this.nRows - 1;
|
|
357
|
-
} else if (point.x >= this.nCols) {
|
|
358
|
-
point.x = 0;
|
|
359
|
-
if (point.y < this.nRows - 1)
|
|
360
|
-
point.y++;
|
|
361
|
-
else
|
|
362
|
-
point.y = 0;
|
|
363
|
-
}
|
|
364
|
-
if (point.y < 0) {
|
|
365
|
-
point.y = this.nRows - 1;
|
|
366
|
-
if (point.x > 0)
|
|
367
|
-
point.x--;
|
|
368
|
-
else
|
|
369
|
-
point.x = this.nCols - 1;
|
|
370
|
-
} else if (point.y >= this.nRows) {
|
|
371
|
-
point.y = 0;
|
|
372
|
-
if (point.x < this.nCols - 1)
|
|
373
|
-
point.x++;
|
|
374
|
-
else
|
|
375
|
-
point.x = 0;
|
|
376
|
-
}
|
|
377
|
-
if (point.x === startX && point.y === startY ||
|
|
378
|
-
this.getCellAttribute(point.x, point.y, attr) === attrState)
|
|
379
|
-
break;
|
|
380
|
-
point.x += dx;
|
|
381
|
-
point.y += dy;
|
|
382
|
-
}
|
|
383
|
-
return point;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Sets the blinking cursor at a specific point
|
|
388
|
-
* @param {number} px - X coordinate
|
|
389
|
-
* @param {number} py - Y coordinate
|
|
390
|
-
* @param {boolean} skipLocked - Skip locked (wildcard) cells
|
|
391
|
-
*/
|
|
392
|
-
setCursorAt(px, py, skipLocked) {
|
|
393
|
-
this.stopCursorBlink();
|
|
394
|
-
if (this.isValidCell(px, py)) {
|
|
395
|
-
this.cursor.x = px;
|
|
396
|
-
this.cursor.y = py;
|
|
397
|
-
this.useCursor = true;
|
|
398
|
-
if (skipLocked && this.getCellAttribute(px, py, flags.LOCKED)) {
|
|
399
|
-
this.moveCursor(1, 0, skipLocked);
|
|
400
|
-
} else {
|
|
401
|
-
if (this.cursorEnabled)
|
|
402
|
-
this.startCursorBlink();
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Sets the `useCursor` property of this text grid
|
|
409
|
-
* @param {boolean} value
|
|
410
|
-
*/
|
|
411
|
-
setUseCursor(value) {
|
|
412
|
-
this.useCursor = value;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Gets the current position of the blinking cursor
|
|
417
|
-
* @returns {module:AWT.Point}
|
|
418
|
-
*/
|
|
419
|
-
getCursor() {
|
|
420
|
-
return this.cursor;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Counts the number of cells of this grid with the specified character
|
|
425
|
-
* @param {string} ch
|
|
426
|
-
* @returns {number}
|
|
427
|
-
*/
|
|
428
|
-
countCharsLike(ch) {
|
|
429
|
-
let result = 0;
|
|
430
|
-
for (let py = 0; py < this.nRows; py++)
|
|
431
|
-
for (let px = 0; px < this.nCols; px++)
|
|
432
|
-
if (this.chars[py][px] === ch)
|
|
433
|
-
result++;
|
|
434
|
-
return result;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* Gets the number of cells of this grid
|
|
439
|
-
* @returns {number}
|
|
440
|
-
*/
|
|
441
|
-
getNumCells() {
|
|
442
|
-
return this.nRows * this.nCols;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* Counts the number of coincidences between the `answers` array and the current content of this grid
|
|
447
|
-
* @param {boolean} checkCase - Make comparisions case-sensitive
|
|
448
|
-
* @returns {number}
|
|
449
|
-
*/
|
|
450
|
-
countCoincidences(checkCase) {
|
|
451
|
-
let result = 0;
|
|
452
|
-
if (this.answers)
|
|
453
|
-
for (let py = 0; py < this.nRows; py++)
|
|
454
|
-
for (let px = 0; px < this.nCols; px++)
|
|
455
|
-
if (this.isCellOk(px, py, checkCase))
|
|
456
|
-
result++;
|
|
457
|
-
return result;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Checks if a specific cell is equivalent to the content of `answers` at its position
|
|
462
|
-
* @param {number} px - X coordinate
|
|
463
|
-
* @param {number} py - Y coordinate
|
|
464
|
-
* @param {boolean} checkCase - Make comparisions case-sensitive
|
|
465
|
-
* @returns {boolean}
|
|
466
|
-
*/
|
|
467
|
-
isCellOk(px, py, checkCase) {
|
|
468
|
-
let result = false;
|
|
469
|
-
if (this.isValidCell(px, py)) {
|
|
470
|
-
const ch = this.chars[py][px];
|
|
471
|
-
if (ch !== this.wild) {
|
|
472
|
-
const ch2 = this.answers[py][px];
|
|
473
|
-
if (ch === ch2 ||
|
|
474
|
-
!checkCase && ch.toUpperCase() === ch2.toUpperCase())
|
|
475
|
-
result = true;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
return result;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* Gets the logical coordinates (in 'cell' units) of a device point into the grid
|
|
483
|
-
* @param {module:AWT.Point} devicePoint
|
|
484
|
-
* @returns {module:AWT.Point}
|
|
485
|
-
*/
|
|
486
|
-
getLogicalCoords(devicePoint) {
|
|
487
|
-
if (!this.contains(devicePoint))
|
|
488
|
-
return null;
|
|
489
|
-
const
|
|
490
|
-
px = Math.floor((devicePoint.x - this.pos.x) / this.cellWidth),
|
|
491
|
-
py = Math.floor((devicePoint.y - this.pos.y) / this.cellHeight);
|
|
492
|
-
|
|
493
|
-
return this.isValidCell(px, py) ? new _AWT_js__WEBPACK_IMPORTED_MODULE_0__/* .Point */ .bR(px, py) : null;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* Checks if the specified logical coordinates are inside the valid bounds of the grid.
|
|
498
|
-
* @param {number} px - 'X' coordinate
|
|
499
|
-
* @param {number} py - 'Y' coordinate
|
|
500
|
-
* @returns {boolean}
|
|
501
|
-
*/
|
|
502
|
-
isValidCell(px, py) {
|
|
503
|
-
return px < this.nCols && py < this.nRows && px >= 0 && py >= 0;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* Sets the specified character as a content of the cell at specified coordinates
|
|
508
|
-
* @param {number} px - 'X' coordinate
|
|
509
|
-
* @param {number} py - 'Y' coordinate
|
|
510
|
-
* @param {string} ch - The character to set.
|
|
511
|
-
*/
|
|
512
|
-
setCharAt(px, py, ch) {
|
|
513
|
-
if (this.isValidCell(px, py)) {
|
|
514
|
-
this.chars[py][px] = ch;
|
|
515
|
-
this.repaintCell(px, py);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
* Gets the character of the cell at the specified coordinates
|
|
521
|
-
* @param {number} px - 'X' coordinate
|
|
522
|
-
* @param {number} py - 'Y' coordinate
|
|
523
|
-
* @returns {string}
|
|
524
|
-
*/
|
|
525
|
-
getCharAt(px, py) {
|
|
526
|
-
return this.isValidCell(px, py) ? this.chars[py][px] : ' ';
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* Gets the text formed by the letters between two cells that share a straight line on the grid.
|
|
531
|
-
* The text can be formed horizontally, vertically and diagonal, both in left-to-right or
|
|
532
|
-
* right-to-left direction.
|
|
533
|
-
* @param {number} x0 - 'X' coordinate of the first cell
|
|
534
|
-
* @param {number} y0 - 'Y' coordinate of the first cell
|
|
535
|
-
* @param {number} x1 - 'X' coordinate of the second cell
|
|
536
|
-
* @param {number} y1 - 'Y' coordinate of the second cell
|
|
537
|
-
* @returns {string}
|
|
538
|
-
*/
|
|
539
|
-
getStringBetween(x0, y0, x1, y1) {
|
|
540
|
-
let sb = '';
|
|
541
|
-
if (this.isValidCell(x0, y0) && this.isValidCell(x1, y1)) {
|
|
542
|
-
let
|
|
543
|
-
dx = x1 - x0,
|
|
544
|
-
dy = y1 - y0;
|
|
545
|
-
if (dx === 0 || dy === 0 || Math.abs(dx) === Math.abs(dy)) {
|
|
546
|
-
const steps = Math.max(Math.abs(dx), Math.abs(dy));
|
|
547
|
-
if (steps > 0) {
|
|
548
|
-
dx /= steps;
|
|
549
|
-
dy /= steps;
|
|
550
|
-
}
|
|
551
|
-
for (let i = 0; i <= steps; i++)
|
|
552
|
-
sb += this.getCharAt(x0 + dx * i, y0 + dy * i);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
return sb;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* Sets a specific attribute to all cells forming a straight line between two cells on the grid.
|
|
560
|
-
* @param {number} x0 - 'X' coordinate of the first cell
|
|
561
|
-
* @param {number} y0 - 'Y' coordinate of the first cell
|
|
562
|
-
* @param {number} x1 - 'X' coordinate of the second cell
|
|
563
|
-
* @param {number} y1 - 'Y' coordinate of the second cell
|
|
564
|
-
* @param {number} attribute - The binary flag representing this attribute. See {@link module:boxes/TextGrid.TextGrid.flags}.
|
|
565
|
-
* @param {boolean} value - Whether to set or unset the attribute.
|
|
566
|
-
*/
|
|
567
|
-
setAttributeBetween(x0, y0, x1, y1, attribute, value) {
|
|
568
|
-
if (this.isValidCell(x0, y0) && this.isValidCell(x1, y1)) {
|
|
569
|
-
let
|
|
570
|
-
dx = x1 - x0,
|
|
571
|
-
dy = y1 - y0;
|
|
572
|
-
|
|
573
|
-
if (dx === 0 || dy === 0 || Math.abs(dx) === Math.abs(dy)) {
|
|
574
|
-
const steps = Math.max(Math.abs(dx), Math.abs(dy));
|
|
575
|
-
if (steps > 0) {
|
|
576
|
-
dx /= steps;
|
|
577
|
-
dy /= steps;
|
|
578
|
-
}
|
|
579
|
-
for (let i = 0; i <= steps; i++)
|
|
580
|
-
this.setAttribute(x0 + dx * i, y0 + dy * i, attribute, value);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
/**
|
|
586
|
-
* Sets or unsets a specifi attrobut to a cell.
|
|
587
|
-
* @param {number} px - The 'X' coordinate of the cell
|
|
588
|
-
* @param {number} py - The 'Y' coordinate of the cell
|
|
589
|
-
* @param {number} attribute - The binary flag representing this attribute. See {@link module:boxes/TextGrid.TextGrid.flags}.
|
|
590
|
-
* @param {boolean} state - Whether to set or unset the attribute.
|
|
591
|
-
*/
|
|
592
|
-
setAttribute(px, py, attribute, state) {
|
|
593
|
-
if (this.isValidCell(px, py)) {
|
|
594
|
-
if (this.attribute === flags.MARKED && !state)
|
|
595
|
-
this.repaintCell(px, py);
|
|
596
|
-
this.attributes[py][px] &= ~attribute;
|
|
597
|
-
this.attributes[py][px] |= state ? attribute : 0;
|
|
598
|
-
if (attribute !== flags.MARKED || state)
|
|
599
|
-
this.repaintCell(px, py);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
/**
|
|
604
|
-
* Sets the specified attribute to all cells.
|
|
605
|
-
* @param {number} attribute - The binary flag representing this attribute. See {@link module:boxes/TextGrid.TextGrid.flags}.
|
|
606
|
-
* @param {boolean} state - Whether to set or unset the attribute.
|
|
607
|
-
*/
|
|
608
|
-
setAllCellsAttribute(attribute, state) {
|
|
609
|
-
for (let py = 0; py < this.nRows; py++)
|
|
610
|
-
for (let px = 0; px < this.nCols; px++)
|
|
611
|
-
this.setAttribute(px, py, attribute, state);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
/**
|
|
615
|
-
* Gets the specified attribute of a cell
|
|
616
|
-
* @param {number} px - The 'X' coordinate of the cell
|
|
617
|
-
* @param {number} py - The 'Y' coordinate of the cell
|
|
618
|
-
* @param {number} attribute - The binary flag representing this attribute. See {@link module:boxes/TextGrid.TextGrid.flags}.
|
|
619
|
-
* @returns {boolean} - `true` if the cell has this attribute, `false` otherwise.
|
|
620
|
-
*/
|
|
621
|
-
getCellAttribute(px, py, attribute) {
|
|
622
|
-
return this.isValidCell(px, py) ? (this.attributes[py][px] & attribute) !== 0 : false;
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
/**
|
|
626
|
-
* Gets the rectangle enclosing a specific cell
|
|
627
|
-
* @param {number} px - The 'X' coordinate of the cell
|
|
628
|
-
* @param {number} py - The 'Y' coordinate of the cell
|
|
629
|
-
* @returns {module:AWT.Rectangle}
|
|
630
|
-
*/
|
|
631
|
-
getCellRect(px, py) {
|
|
632
|
-
return new _AWT_js__WEBPACK_IMPORTED_MODULE_0__/* .Rectangle */ .M_(this.pos.x + px * this.cellWidth, this.pos.y + py * this.cellHeight, this.cellWidth, this.cellHeight);
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
/**
|
|
636
|
-
* Gets the rectangle enclosing a specific cell, including the border thick.
|
|
637
|
-
* @param {number} px - The 'X' coordinate of the cell
|
|
638
|
-
* @param {number} py - The 'Y' coordinate of the cell
|
|
639
|
-
* @returns {module:AWT.Rectangle}
|
|
640
|
-
*/
|
|
641
|
-
getCellBorderBounds(px, py) {
|
|
642
|
-
const isMarked = this.getCellAttribute(px, py, flags.MARKED);
|
|
643
|
-
if (!this.border && !isMarked)
|
|
644
|
-
return this.getCellRect(px, py);
|
|
645
|
-
|
|
646
|
-
const
|
|
647
|
-
style = this.getBoxBaseResolve(),
|
|
648
|
-
strk = isMarked ? style.markerStroke : style.borderStroke;
|
|
649
|
-
|
|
650
|
-
return this.getCellRect(px, py).grow(strk.lineWidth, strk.lineWidth);
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
/**
|
|
654
|
-
* Repaints a cell
|
|
655
|
-
* @param {number} px - The 'X' coordinate of the cell
|
|
656
|
-
* @param {number} py - The 'Y' coordinate of the cell
|
|
657
|
-
*/
|
|
658
|
-
repaintCell(px, py) {
|
|
659
|
-
if (this.container)
|
|
660
|
-
this.container.invalidate(this.getCellBorderBounds(px, py)).update();
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
/**
|
|
664
|
-
* Gets the preferred size of this grid
|
|
665
|
-
* @returns {module:AWT.Dimension}
|
|
666
|
-
*/
|
|
667
|
-
getPreferredSize() {
|
|
668
|
-
return this.preferredBounds.dim;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
/**
|
|
672
|
-
* Gets the minimum size of this grid
|
|
673
|
-
* @returns {module:AWT.Dimension}
|
|
674
|
-
*/
|
|
675
|
-
getMinimumSize() {
|
|
676
|
-
return new _AWT_js__WEBPACK_IMPORTED_MODULE_0__/* .Dimension */ .fg(defaults.MIN_CELL_SIZE * this.nCols, defaults.MIN_CELL_SIZE * this.nRows);
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
/**
|
|
680
|
-
* Scales the grid to a new size
|
|
681
|
-
* @param {number} scale - The factor used to multiply all coordinates and sizes
|
|
682
|
-
* @returns {module:AWT.Dimension}
|
|
683
|
-
*/
|
|
684
|
-
getScaledSize(scale) {
|
|
685
|
-
return new _AWT_js__WEBPACK_IMPORTED_MODULE_0__/* .Dimension */ .fg(
|
|
686
|
-
(0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__/* .roundTo */ .GB)(scale * this.preferredBounds.dim.width, this.nCols),
|
|
687
|
-
(0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__/* .roundTo */ .GB)(scale * this.preferredBounds.dim.height, this.nRows));
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
/**
|
|
691
|
-
* Overrides {@link module:boxes/AbstractBox.AbstractBox#setBounds}
|
|
692
|
-
* @override
|
|
693
|
-
* @param {AWT.Rectangle|number} rect - An AWT.Rectangle object, or the `x` coordinate of the
|
|
694
|
-
* upper-left corner of a new rectangle.
|
|
695
|
-
* @param {number} [y] - `y` coordinate of the upper-left corner of the new rectangle.
|
|
696
|
-
* @param {number} [w] - Width of the new rectangle.
|
|
697
|
-
* @param {number} [h] - Height of the new rectangle.
|
|
698
|
-
*/
|
|
699
|
-
setBounds(rect, y, w, h) {
|
|
700
|
-
super.setBounds(rect, y, w, h);
|
|
701
|
-
this.cellWidth = this.dim.width / this.nCols;
|
|
702
|
-
this.cellHeight = this.dim.height / this.nRows;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* Overrides {@link module:boxes/AbstractBox.AbstractBox#updateContent}
|
|
707
|
-
* @override
|
|
708
|
-
* @param {external:CanvasRenderingContext2D} ctx - The canvas rendering context used to draw the
|
|
709
|
-
* grid.
|
|
710
|
-
* @param {module:AWT.Rectangle} [dirtyRegion] - The area that must be repainted. `null` refers to the whole box.
|
|
711
|
-
*/
|
|
712
|
-
updateContent(ctx, dirtyRegion) {
|
|
713
|
-
const style = this.getBoxBaseResolve();
|
|
714
|
-
|
|
715
|
-
// test font size
|
|
716
|
-
ctx.font = style.font.cssFont();
|
|
717
|
-
ctx.textBaseline = 'alphabetic';
|
|
718
|
-
style.prepareText(ctx, 'W',
|
|
719
|
-
this.cellWidth - 2 * defaults.MIN_INTERNAL_MARGIN,
|
|
720
|
-
this.cellHeight - 2 * defaults.MIN_INTERNAL_MARGIN);
|
|
721
|
-
|
|
722
|
-
const ch = [];
|
|
723
|
-
const ry = (this.cellHeight - style.font.getHeight()) / 2 + style.font.getMetrics().ascent;
|
|
724
|
-
|
|
725
|
-
for (let py = 0; py < this.nRows; py++) {
|
|
726
|
-
for (let px = 0; px < this.nCols; px++) {
|
|
727
|
-
const bxr = this.getCellBorderBounds(px, py);
|
|
728
|
-
if (bxr.intersects(dirtyRegion)) {
|
|
729
|
-
const attr = this.attributes[py][px];
|
|
730
|
-
if ((attr & flags.TRANSPARENT) === 0) {
|
|
731
|
-
const isInverted = (attr & flags.INVERTED) !== 0;
|
|
732
|
-
const isMarked = (attr & flags.MARKED) !== 0;
|
|
733
|
-
const isCursor = this.useCursor && this.cursor.x === px && this.cursor.y === py;
|
|
734
|
-
const boxBounds = this.getCellRect(px, py);
|
|
735
|
-
ctx.fillStyle = isCursor && this.cursorBlink ?
|
|
736
|
-
style.inactiveColor :
|
|
737
|
-
isInverted ? style.textColor : style.backColor;
|
|
738
|
-
boxBounds.fill(ctx);
|
|
739
|
-
ctx.strokeStyle = 'black';
|
|
740
|
-
if ((attr & flags.HIDDEN) === 0) {
|
|
741
|
-
ch[0] = this.chars[py][px];
|
|
742
|
-
if (ch[0]) {
|
|
743
|
-
const dx = boxBounds.pos.x + (this.cellWidth - ctx.measureText(ch[0]).width) / 2;
|
|
744
|
-
const dy = boxBounds.pos.y + ry;
|
|
745
|
-
|
|
746
|
-
if (style.shadow) {
|
|
747
|
-
// Render text shadow
|
|
748
|
-
const d = Math.max(1, style.font.size / 10);
|
|
749
|
-
ctx.fillStyle = style.shadowColor;
|
|
750
|
-
ctx.fillText(ch[0], dx + d, dy + d);
|
|
751
|
-
}
|
|
752
|
-
// Render text
|
|
753
|
-
ctx.fillStyle = isInverted ? style.backColor
|
|
754
|
-
: this.isAlternative() ? style.alternativeColor : style.textColor;
|
|
755
|
-
ctx.fillText(ch[0], dx, dy);
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
if (this.border || isMarked) {
|
|
759
|
-
ctx.strokeStyle = style.borderColor;
|
|
760
|
-
style[isMarked ? 'markerStroke' : 'borderStroke'].setStroke(ctx);
|
|
761
|
-
if (isMarked)
|
|
762
|
-
ctx.globalCompositeOperation = 'xor';
|
|
763
|
-
|
|
764
|
-
// Draw border
|
|
765
|
-
boxBounds.stroke(ctx);
|
|
766
|
-
|
|
767
|
-
// Reset ctx default values
|
|
768
|
-
if (isMarked)
|
|
769
|
-
ctx.globalCompositeOperation = 'source-over';
|
|
770
|
-
}
|
|
771
|
-
ctx.strokeStyle = 'black';
|
|
772
|
-
_AWT_js__WEBPACK_IMPORTED_MODULE_0__/* .Stroke */ .tc.prototype.setStroke(ctx);
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
return true;
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
/**
|
|
781
|
-
* Makes the cursor blink, alternating between two states. This method should be called only by
|
|
782
|
-
* {@link module:boxes/TextGrid.TextGrid#cursorTimer}
|
|
783
|
-
* @param {boolean} status
|
|
784
|
-
*/
|
|
785
|
-
blink(status) {
|
|
786
|
-
// TODO: Move blink and timer to ActivityPanel
|
|
787
|
-
if (this.useCursor) {
|
|
788
|
-
this.cursorBlink = status === 1 ? true : status === -1 ? false : !this.cursorBlink;
|
|
789
|
-
this.repaintCell(this.cursor.x, this.cursor.y);
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
/**
|
|
794
|
-
* Stops the cursor timer if not `null` and active
|
|
795
|
-
*/
|
|
796
|
-
end() {
|
|
797
|
-
if (this.cursorTimer) {
|
|
798
|
-
this.cursorTimer.stop();
|
|
799
|
-
this.cursorTimer = null;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
Object.assign(TextGrid.prototype, {
|
|
805
|
-
/**
|
|
806
|
-
* Number of rows
|
|
807
|
-
* @name module:boxes/TextGrid.TextGrid#nRows
|
|
808
|
-
* @type {number} */
|
|
809
|
-
nRows: 1,
|
|
810
|
-
/**
|
|
811
|
-
* Number of columns
|
|
812
|
-
* @name module:boxes/TextGrid.TextGrid#nCols
|
|
813
|
-
* @type {number} */
|
|
814
|
-
nCols: 1,
|
|
815
|
-
/**
|
|
816
|
-
* Two-dimension array of characters
|
|
817
|
-
* @name module:boxes/TextGrid.TextGrid#chars
|
|
818
|
-
* @type {string[][]} */
|
|
819
|
-
chars: null,
|
|
820
|
-
/**
|
|
821
|
-
* Two-dimension array with the expected characters, used to check user's answers.
|
|
822
|
-
* @name module:boxes/TextGrid.TextGrid#answers
|
|
823
|
-
* @type {string[][]} */
|
|
824
|
-
answers: null,
|
|
825
|
-
/**
|
|
826
|
-
* Two-dimension array of bytes used as containers of boolean attributes
|
|
827
|
-
* @name module:boxes/TextGrid.TextGrid#attributes
|
|
828
|
-
* @see TextGrid.flags
|
|
829
|
-
* @type {number[][]} */
|
|
830
|
-
attributes: null,
|
|
831
|
-
/**
|
|
832
|
-
* The cell width, in pixels
|
|
833
|
-
* @name module:boxes/TextGrid.TextGrid#cellWidth
|
|
834
|
-
* @type {number} */
|
|
835
|
-
cellWidth: 20,
|
|
836
|
-
/**
|
|
837
|
-
* The cell height, in pixels
|
|
838
|
-
* @name module:boxes/TextGrid.TextGrid#cellHeight
|
|
839
|
-
* @type {number} */
|
|
840
|
-
cellHeight: 20,
|
|
841
|
-
/**
|
|
842
|
-
* The preferred bounds of this grid
|
|
843
|
-
* @name module:boxes/TextGrid.TextGrid#preferredBounds
|
|
844
|
-
* @type {module:AWT.Rectangle} */
|
|
845
|
-
preferredBounds: null,
|
|
846
|
-
/**
|
|
847
|
-
* The character to be used as wildcard
|
|
848
|
-
* @name module:boxes/TextGrid.TextGrid#wild
|
|
849
|
-
* @type {string} */
|
|
850
|
-
wild: _TextGridContent_js__WEBPACK_IMPORTED_MODULE_3__["default"].prototype.wild,
|
|
851
|
-
/**
|
|
852
|
-
* Characters that can be used when randomizing the content of this grid
|
|
853
|
-
* @name module:boxes/TextGrid.TextGrid#randomChars
|
|
854
|
-
* @see TextGridContent#randomChars
|
|
855
|
-
* @type {string} */
|
|
856
|
-
randomChars: _TextGridContent_js__WEBPACK_IMPORTED_MODULE_3__["default"].prototype.randomChars,
|
|
857
|
-
/**
|
|
858
|
-
* Whether the blinking cursor is enabled or disabled
|
|
859
|
-
* @name module:boxes/TextGrid.TextGrid#cursorEnabled
|
|
860
|
-
* @type {boolean} */
|
|
861
|
-
cursorEnabled: false,
|
|
862
|
-
/**
|
|
863
|
-
* Whether this grid uses a blinking cursor or not
|
|
864
|
-
* @name module:boxes/TextGrid.TextGrid#useCursor
|
|
865
|
-
* @type {boolean} */
|
|
866
|
-
useCursor: false,
|
|
867
|
-
/**
|
|
868
|
-
* The current position of the cursor
|
|
869
|
-
* @name module:boxes/TextGrid.TextGrid#cursor
|
|
870
|
-
* @type {module:AWT.Point} */
|
|
871
|
-
cursor: null,
|
|
872
|
-
/**
|
|
873
|
-
* `true` when the cursor is "blinking" (cell drawn with {@link module:boxes/BoxBase.BoxBase BoxBase} `inverse` attributes)
|
|
874
|
-
* @name module:boxes/TextGrid.TextGrid#cursorBlink
|
|
875
|
-
* @type {boolean} */
|
|
876
|
-
cursorBlink: false,
|
|
877
|
-
/**
|
|
878
|
-
* Controls the blinking of the cursor
|
|
879
|
-
* @name module:boxes/TextGrid.TextGrid#cursorTimer
|
|
880
|
-
* @type {module:AWT.Timer} */
|
|
881
|
-
cursorTimer: null,
|
|
882
|
-
/**
|
|
883
|
-
* Whether the wildcard character is transparent or opaque
|
|
884
|
-
* @name module:boxes/TextGrid.TextGrid#wildTransparent
|
|
885
|
-
* @type {boolean} */
|
|
886
|
-
wildTransparent: false,
|
|
887
|
-
});
|
|
888
|
-
|
|
889
|
-
/**
|
|
890
|
-
* TextGrid default values
|
|
891
|
-
* @name module:boxes/TextGrid.TextGrid.defaults
|
|
892
|
-
* @constant
|
|
893
|
-
* @type {object} */
|
|
894
|
-
TextGrid.defaults = defaults;
|
|
895
|
-
|
|
896
|
-
/**
|
|
897
|
-
* Binary flags used to mark status
|
|
898
|
-
* @name module:boxes/TextGrid.TextGrid.flags
|
|
899
|
-
* @constant
|
|
900
|
-
* @type {object} */
|
|
901
|
-
TextGrid.flags = flags;
|
|
902
|
-
|
|
903
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (TextGrid);
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
/***/ })
|
|
907
|
-
|
|
908
|
-
};
|
|
909
|
-
;
|
|
910
|
-
//# sourceMappingURL=4123.jclic-node.js.map
|