Skip to content

Commit acc319a

Browse files
committed
fixes from reviewer
1 parent 1a408af commit acc319a

File tree

5 files changed

+55
-49
lines changed

5 files changed

+55
-49
lines changed

src/core/p5.Renderer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class ClonableObject {
3535

3636
class Renderer {
3737
static states = {
38-
background: null,
3938
strokeColor: null,
4039
strokeSet: false,
4140
fillColor: null,

src/core/p5.Renderer2D.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ class Renderer2D extends Renderer {
168168
background(...args) {
169169
if (args.length === 0) {
170170
return this;// setter with no args does nothing
171-
//return this.states.background; // getter (#8278)
172171
}
173-
let bgForState = null;
174172
this.push();
175173
this.resetMatrix();
176174
if (args[0] instanceof Image) {
@@ -180,7 +178,6 @@ class Renderer2D extends Renderer {
180178
this.drawingContext.globalAlpha = args[1] / 255;
181179
}
182180
this._pInst.image(img, 0, 0, this.width, this.height);
183-
bgForState = img; // save for getter (#8278)
184181
} else {
185182
// create background rect
186183
const color = this._pInst.color(...args);
@@ -203,11 +200,9 @@ class Renderer2D extends Renderer {
203200
if (this._isErasing) {
204201
this._pInst.erase();
205202
}
206-
bgForState = color; // save for getter (#8278)
207203
}
208204
this.pop();
209205

210-
this.states.setValue('background', bgForState); // set state (#8278)
211206
return this;
212207
}
213208

src/image/loading_displaying.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,11 +1138,8 @@ function loadingDisplaying(p5, fn){
11381138
* sets the alpha value. For example, `tint(255, 0, 0, 100)` will give images
11391139
* a red tint and make them transparent.
11401140
*
1141-
* Calling `tint()` without an argument returns the current tint as a <a href="#/p5.Color">p5.Color</a> object.
1142-
*
1143-
* @method frameRate
1144-
* @param {Number} fps number of frames to draw per second.
1145-
* @chainable
1141+
* Calling `tint()` without an argument returns the current tint as a
1142+
* <a href="#/p5.Color">p5.Color</a> object.
11461143
*
11471144
* @method tint
11481145
* @param {Number} v1 red or hue value.

src/type/textCore.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,29 +1459,37 @@ function textCore(p5, fn) {
14591459

14601460
Renderer.prototype.textAlign = function (h, v) {
14611461

1462-
// the setter
1463-
if (typeof h !== 'undefined') {
1464-
// accept what is returned from the getter
1462+
if (arguments.length === 0) { // the getter
1463+
return {
1464+
horizontal: this.states.textAlign,
1465+
vertical: this.states.textBaseline
1466+
};
1467+
}
1468+
1469+
// allow an object with horizontal and vertical properties
1470+
if (typeof h === 'object' && h !== null) {
1471+
if (h.hasOwnProperty('vertical')) {
1472+
v = h.vertical;
1473+
}
14651474
if (h.hasOwnProperty('horizontal')) {
14661475
h = h.horizontal;
14671476
}
1477+
}
1478+
1479+
// horizontal value as separate argument
1480+
if (typeof h === 'string' || h instanceof String) {
14681481
this.states.setValue('textAlign', h);
1469-
if (h.hasOwnProperty('vertical') && typeof v === 'undefined') {
1470-
v = h.vertical;
1471-
}
1472-
if (typeof v !== 'undefined') {
1473-
if (v === fn.CENTER) {
1474-
v = textCoreConstants._CTX_MIDDLE;
1475-
}
1476-
this.states.setValue('textBaseline', v);
1482+
}
1483+
1484+
// vertical value as separate argument
1485+
if (typeof v === 'string' || v instanceof String) {
1486+
if (v === fn.CENTER) {
1487+
v = textCoreConstants._CTX_MIDDLE;
14771488
}
1478-
return this._applyTextProperties();
1489+
this.states.setValue('textBaseline', v);
14791490
}
1480-
// the getter
1481-
return {
1482-
horizontal: this.states.textAlign,
1483-
vertical: this.states.textBaseline
1484-
};
1491+
1492+
return this._applyTextProperties();
14851493
};
14861494

14871495
Renderer.prototype._currentTextFont = function () {

test/unit/webgl/p5.RendererGL.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,46 +1492,52 @@ suite('p5.RendererGL', function() {
14921492
suite('tint() in WEBGL mode', function() {
14931493
test('default tint value is set and not null', function() {
14941494
myp5.createCanvas(100, 100, myp5.WEBGL);
1495-
assert.deepEqual(myp5._renderer.states.tint.array(), [1,1,1,1]);
1495+
assert.deepEqual(myp5._renderer.states.tint
1496+
._getRGBA([255, 255, 255, 255]), [255, 255, 255, 255]);
14961497
});
14971498

14981499

14991500

15001501
test('tint value is modified correctly when tint() is called', function() {
15011502

1502-
function assertDeepEqualColor(actual, expected) {
1503-
if (typeof actual === 'string' && typeof expected === 'string') {
1504-
assert.equal(actual, expected);
1505-
} else {
1506-
assert.deepEqual(actual, myp5.color(expected).array());
1507-
}
1503+
function assertColorEq(tint, colArray) {
1504+
assert.deepEqual(tint._getRGBA([255, 255, 255, 255]), colArray);
15081505
}
1506+
15091507
myp5.createCanvas(100, 100, myp5.WEBGL);
1508+
15101509
myp5.tint(0, 153, 204, 126);
1511-
assertDeepEqualColor(myp5._renderer.states.tint.array(), [0, 153, 204, 126]);
1510+
assertColorEq(myp5._renderer.states.tint, [0, 153, 204, 126]);
1511+
15121512
myp5.tint(100, 120, 140);
1513-
assertDeepEqualColor(myp5._renderer.states.tint.array(), [100, 120, 140, 255]);
1514-
1513+
assertColorEq(myp5._renderer.states.tint, [100, 120, 140, 255]);
1514+
15151515
myp5.tint('violet');
1516-
// Note that in WEBGL mode, we don't convert color strings to arrays until the shader,
1516+
// Note that in WEBGL mode, we don't convert color strings to arrays until the shader,
15171517
// so the tint state is still the string 'violet' at this point, not the array [238, 130, 238, 255].
1518-
//assertDeepEqualColor(myp5._renderer.states.tint.array(), [238, 130, 238, 255]);
1519-
assertDeepEqualColor(myp5._renderer.states.tint.array(), 'violet');
1518+
//assertDeepEqualColor(myp5._renderer.states.tint, [238, 130, 238, 255]);
1519+
assert.equal(myp5._renderer.states.tint, 'violet');
15201520

15211521
myp5.tint(100);
1522-
assertDeepEqualColor(myp5._renderer.states.tint.array(), [100, 100, 100, 255]);
1522+
assertColorEq(myp5._renderer.states.tint, [100, 100, 100, 255]);
1523+
15231524
myp5.tint(100, 126);
1524-
assertDeepEqualColor(myp5._renderer.states.tint.array(), [100, 100, 100, 126]);
1525+
assertColorEq(myp5._renderer.states.tint, [100, 100, 100, 126]);
1526+
15251527
myp5.tint([100, 126, 0, 200]);
1526-
assertDeepEqualColor(myp5._renderer.states.tint.array(), [100, 126, 0, 200]);
1528+
assertColorEq(myp5._renderer.states.tint, [100, 126, 0, 200]);
1529+
15271530
myp5.tint([100, 126, 0]);
1528-
assertDeepEqualColor(myp5._renderer.states.tint.array(), [100, 126, 0, 255]);
1531+
assertColorEq(myp5._renderer.states.tint, [100, 126, 0, 255]);
1532+
15291533
myp5.tint([100]);
1530-
assertDeepEqualColor(myp5._renderer.states.tint.array(), [100, 100, 100, 255]);
1534+
assertColorEq(myp5._renderer.states.tint, [100, 100, 100, 255]);
1535+
15311536
myp5.tint([100, 126]);
1532-
assertDeepEqualColor(myp5._renderer.states.tint.array(), [100, 100, 100, 126]);
1537+
assertColorEq(myp5._renderer.states.tint, [100, 100, 100, 126]);
1538+
15331539
myp5.tint(myp5.color(255, 204, 0));
1534-
assertDeepEqualColor(myp5._renderer.states.tint.array(), [255, 204, 0, 255]);
1540+
assertColorEq(myp5._renderer.states.tint, [255, 204, 0, 255]);
15351541
});
15361542

15371543
test('tint should be reset after draw loop', function() {
@@ -1548,7 +1554,8 @@ suite('p5.RendererGL', function() {
15481554
};
15491555
});
15501556
}).then(function(_tint) {
1551-
assert.deepEqual(_tint.array(), [1, 1, 1, 1]);
1557+
assert.deepEqual(_tint._getRGBA([255, 255, 255, 255]),
1558+
[255, 255, 255, 255]);
15521559
});
15531560
});
15541561
});

0 commit comments

Comments
 (0)