Skip to content

Commit

Permalink
add compositeOperation argument to Surface.blit
Browse files Browse the repository at this point in the history
pretty much what pygames special_flags argument does: it affects how the two surfaces are composited. compare:

 * http://www.pygame.org/docs/ref/surface.html#Surface.fill
 * http://dev.w3.org/html5/2dcontext/#dom-context-2d-globalcompositeoperation
  • Loading branch information
oberhamsi committed Jan 22, 2012
1 parent 9d1c862 commit 7d737a0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/gamejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,10 @@ Surface.prototype._smooth = function() {
* is not supplied the blit happens at [0,0].
* @param {gamesjs.Rect|Array} area the Area from the passed Surface which
* should be blitted onto this Surface.
* @param {Number} [special_flags] FIXME add special flags for composite operations
* @param {Number} compositionOperation how the source and target surfaces are composited together; one of: source-atop, source-in, source-out, source-over (default), destination-atop, destination-in, destination-out, destination-over, lighter, copy, xor; for an explanation of these values see: http://dev.w3.org/html5/2dcontext/#dom-context-2d-globalcompositeoperation
* @returns {gamejs.Rect} Rect actually repainted
*/
Surface.prototype.blit = function(src, dest, area, special_flags) {
Surface.prototype.blit = function(src, dest, area, compositeOperation) {

var rDest, rArea;

Expand All @@ -594,6 +594,7 @@ Surface.prototype.blit = function(src, dest, area, special_flags) {
} else {
rDest = new Rect([0,0], src.getSize());
}
compositeOperation = compositeOperation || 'source-over';

// area within src to be drawn
if (area instanceof Rect) {
Expand All @@ -610,6 +611,7 @@ Surface.prototype.blit = function(src, dest, area, special_flags) {
}

this.context.save();
this.context.globalCompositeOperation = compositeOperation;
// first translate, then rotate
var m = matrix.translate(matrix.identity(), rDest.left, rDest.top);
m = matrix.multiply(m, src._matrix);
Expand Down

0 comments on commit 7d737a0

Please sign in to comment.