aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-04-03 11:43:53 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-04-03 11:43:53 -0700
commit55184dbb9f73febab08f7953cb692d28fdd669cd (patch)
treefd4794402847bc469d4e1331e8ed9729c96a2449
parent8ae983c6c1965a2d64f71aa28d990682b9a36347 (diff)
parente6f1f4cc81c84ee5d3db49cd5f6a1b36a59ba291 (diff)
Merge pull request #1015 from fhd/incoming
Support rotozoomSurface
-rw-r--r--AUTHORS2
-rw-r--r--src/library_sdl.js13
-rw-r--r--tests/sdl_rotozoom.c6
-rw-r--r--tests/sdl_rotozoom.pngbin338527 -> 360054 bytes
4 files changed, 18 insertions, 3 deletions
diff --git a/AUTHORS b/AUTHORS
index 0fa41dd2..e5d1ac34 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -55,4 +55,4 @@ a license to everyone to use it as detailed in LICENSE.)
* Tobias Doerffel <tobias.doerffel@gmail.com>
* Martin von Gagern <martin@von-gagern.net>
* Ting-Yuan Huang <thuang@mozilla.com>
-
+* Felix H. Dahlke <fhd@ubercode.de>
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 42207f23..71ab2277 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -1032,6 +1032,19 @@ var LibrarySDL = {
return ret;
},
+ rotozoomSurface: function(src, angle, zoom, smooth) {
+ var srcData = SDL.surfaces[src];
+ var w = srcData.width * zoom;
+ var h = srcData.height * zoom;
+ var diagonal = Math.ceil(Math.sqrt(Math.pow(w, 2) + Math.pow(h, 2)));
+ var ret = SDL.makeSurface(diagonal, diagonal, srcData.flags, false, 'rotozoomSurface');
+ var dstData = SDL.surfaces[ret];
+ dstData.ctx.translate(diagonal / 2, diagonal / 2);
+ dstData.ctx.rotate(angle * Math.PI / 180);
+ dstData.ctx.drawImage(srcData.canvas, -w / 2, -h / 2, w, h);
+ return ret;
+ },
+
SDL_SetAlpha: function(surf, flag, alpha) {
SDL.surfaces[surf].alpha = alpha;
},
diff --git a/tests/sdl_rotozoom.c b/tests/sdl_rotozoom.c
index cb6295cc..b3970f6c 100644
--- a/tests/sdl_rotozoom.c
+++ b/tests/sdl_rotozoom.c
@@ -7,12 +7,12 @@
#endif
SDL_Surface *screen;
-SDL_Surface *sprite[4];
+SDL_Surface *sprite[6];
void mainloop() {
int i;
SDL_Rect rect = { 0, 0, 100, 100 };
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < 6; i++) {
rect.x = i & 1 ? 200 : 0;
rect.y = i & 2 ? 200 : 0;
SDL_BlitSurface(sprite[i], 0, screen, &rect);
@@ -30,6 +30,8 @@ int main(int argc, char **argv) {
SDL_FillRect(sprite[1], 0, 0xA0A0A0A0);
sprite[2] = zoomSurface(sprite[0], 0.5, 0.5, SMOOTHING_ON);
sprite[3] = zoomSurface(sprite[1], 0.5, 0.5, SMOOTHING_ON);
+ sprite[4] = rotozoomSurface(sprite[0], -20, 0.3, SMOOTHING_ON);
+ sprite[5] = rotozoomSurface(sprite[1], 45, 0.5, SMOOTHING_ON);
mainloop();
diff --git a/tests/sdl_rotozoom.png b/tests/sdl_rotozoom.png
index 83ec0589..3ca8da70 100644
--- a/tests/sdl_rotozoom.png
+++ b/tests/sdl_rotozoom.png
Binary files differ