Skip to content

Commit 1d1a0d3

Browse files
author
Nathan Bolton
committed
Gut the windowlayer
1 parent a4bd81a commit 1d1a0d3

File tree

1 file changed

+2
-143
lines changed

1 file changed

+2
-143
lines changed

js/rpg_core/WindowLayer.js

Lines changed: 2 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ WindowLayer.prototype.initialize = function() {
1616
PIXI.Container.call(this);
1717
this._width = 0;
1818
this._height = 0;
19-
this._tempCanvas = null;
20-
this._translationMatrix = [1, 0, 0, 0, 1, 0, 0, 0, 1];
21-
22-
this._windowMask = new PIXI.Graphics();
23-
this._windowMask.beginFill(0xffffff, 1);
24-
this._windowMask.drawRect(0, 0, 0, 0);
25-
this._windowMask.endFill();
26-
this._windowRect = this._windowMask.graphicsData[0].shape;
27-
28-
this._renderSprite = null;
29-
this.filterArea = new PIXI.Rectangle();
30-
this.filters = [WindowLayer.voidFilter];
3119

3220
//temporary fix for memory leak bug
3321
this.on('removed', this.onRemoveAsAChild);
@@ -100,137 +88,8 @@ WindowLayer.prototype.update = function() {
10088
});
10189
};
10290

103-
/**
104-
* @method _renderCanvas
105-
* @param {Object} renderSession
106-
* @private
107-
*/
108-
WindowLayer.prototype.renderCanvas = function(renderer) {
109-
if (!this.visible || !this.renderable) {
110-
return;
111-
}
112-
113-
if (!this._tempCanvas) {
114-
this._tempCanvas = document.createElement('canvas');
115-
}
116-
117-
this._tempCanvas.width = Graphics.width;
118-
this._tempCanvas.height = Graphics.height;
119-
120-
var realCanvasContext = renderer.context;
121-
var context = this._tempCanvas.getContext('2d');
122-
123-
context.save();
124-
context.clearRect(0, 0, Graphics.width, Graphics.height);
125-
context.beginPath();
126-
context.rect(this.x, this.y, this.width, this.height);
127-
context.closePath();
128-
context.clip();
129-
130-
renderer.context = context;
131-
132-
for (var i = 0; i < this.children.length; i++) {
133-
var child = this.children[i];
134-
if (child._isWindow && child.visible && child.openness > 0) {
135-
this._canvasClearWindowRect(renderer, child);
136-
context.save();
137-
child.renderCanvas(renderer);
138-
context.restore();
139-
}
140-
}
141-
142-
context.restore();
143-
144-
renderer.context = realCanvasContext;
145-
renderer.context.setTransform(1, 0, 0, 1, 0, 0);
146-
renderer.context.globalCompositeOperation = 'source-over';
147-
renderer.context.globalAlpha = 1;
148-
renderer.context.drawImage(this._tempCanvas, 0, 0);
149-
150-
for (var j = 0; j < this.children.length; j++) {
151-
if (!this.children[j]._isWindow) {
152-
this.children[j].renderCanvas(renderer);
153-
}
154-
}
155-
};
156-
157-
/**
158-
* @method _canvasClearWindowRect
159-
* @param {Object} renderSession
160-
* @param {Window} window
161-
* @private
162-
*/
163-
WindowLayer.prototype._canvasClearWindowRect = function(renderSession, window) {
164-
var rx = this.x + window.x;
165-
var ry = this.y + window.y + window.height / 2 * (1 - window._openness / 255);
166-
var rw = window.width;
167-
var rh = window.height * window._openness / 255;
168-
renderSession.context.clearRect(rx, ry, rw, rh);
169-
};
170-
171-
/**
172-
* @method _render
173-
* @param {Object} renderSession
174-
* @private
175-
*/
176-
WindowLayer.prototype.render = function(renderer) {
177-
if (!this.visible || !this.renderable) {
178-
return;
179-
}
180-
181-
if (this.children.length==0) {
182-
return;
183-
}
184-
185-
renderer.flush();
186-
this.filterArea.copy(this);
187-
renderer.filterManager.pushFilter(this, this.filters);
188-
renderer.currentRenderer.start();
189-
190-
var shift = new PIXI.Point();
191-
var rt = renderer._activeRenderTarget;
192-
var projectionMatrix = rt.projectionMatrix;
193-
shift.x = Math.round((projectionMatrix.tx + 1) / 2 * rt.sourceFrame.width);
194-
shift.y = Math.round((projectionMatrix.ty + 1) / 2 * rt.sourceFrame.height);
195-
196-
for (var i = 0; i < this.children.length; i++) {
197-
var child = this.children[i];
198-
if (child._isWindow && child.visible && child.openness > 0) {
199-
this._maskWindow(child, shift);
200-
renderer.maskManager.pushScissorMask(this, this._windowMask);
201-
renderer.clear();
202-
renderer.maskManager.popScissorMask();
203-
renderer.currentRenderer.start();
204-
child.render(renderer);
205-
renderer.currentRenderer.flush();
206-
}
207-
}
208-
209-
renderer.flush();
210-
renderer.filterManager.popFilter();
211-
renderer.maskManager.popScissorMask();
212-
213-
for (var j = 0; j < this.children.length; j++) {
214-
if (!this.children[j]._isWindow) {
215-
this.children[j].render(renderer);
216-
}
217-
}
218-
};
219-
220-
/**
221-
* @method _maskWindow
222-
* @param {Window} window
223-
* @private
224-
*/
225-
WindowLayer.prototype._maskWindow = function(window, shift) {
226-
this._windowMask._currentBounds = null;
227-
this._windowMask.boundsDirty = true;
228-
var rect = this._windowRect;
229-
rect.x = this.x + shift.x + window.x;
230-
rect.y = this.y + shift.y + window.y + window.height / 2 * (1 - window._openness / 255);
231-
rect.width = window.width;
232-
rect.height = window.height * window._openness / 255;
233-
};
91+
WindowLayer.prototype.render = PIXI.Container.prototype.render;
92+
WindowLayer.prototype.renderCanvas = PIXI.Container.prototype.renderCanvas;
23493

23594
// The important members from Pixi.js
23695

0 commit comments

Comments
 (0)