Scale is now a parameter to the program
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Wed, 13 Aug 2008 00:29:08 +0000 (21:29 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Wed, 13 Aug 2008 00:29:08 +0000 (21:29 -0300)
movie.c

diff --git a/movie.c b/movie.c
index 9109f5a..290787b 100644 (file)
--- a/movie.c
+++ b/movie.c
@@ -20,6 +20,8 @@
 #define HEIGHT 600
 #define HBORDER 32
 #define VBORDER 8
+#define RX (0.5)
+#define RY (0.5)
 
 #define STOP_INTERVAL (2*1000)
 #define FPS (100)
@@ -160,13 +162,16 @@ CairoTarget (SDL_Surface *image)
   static cairo_surface_t *surface = NULL;
   static cairo_t *ctx = NULL;
   cairo_surface_t *source;
+  double rx, ry;
   if (data == NULL && surface == NULL && ctx == NULL)
   {
     data = malloc (WIDTH * HEIGHT * 4);
     surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32,
                                                   WIDTH, HEIGHT, WIDTH * 4);
     ctx = cairo_create (surface);
-    cairo_scale (ctx, 2, 2);
+    rx = (double) WIDTH / (double) image->w;
+    ry = (double) HEIGHT / (double) image->h;
+    cairo_scale (ctx, rx, ry);
   }
   source = CairoFromSDL (image);
   cairo_set_source_surface (ctx, source, 0, 0);
@@ -184,14 +189,17 @@ GetNextImage (SDL_Surface *image)
   SDL_Surface *text;
   SDL_Rect box;
   SDL_Color Yellow = { 255, 255, 0, 0};
+  double rx, ry;
+  rx = RX;
+  ry = RY;
   center = GetNextPoint ();
-  slice = SDL_CreateRGBSurface (SDL_SWSURFACE, WIDTH/2, HEIGHT/2,
+  slice = SDL_CreateRGBSurface (SDL_SWSURFACE, WIDTH*rx, HEIGHT*ry,
                                 32,
                                0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
-  center.x -= (WIDTH/2) / 2;
-  center.y -= (HEIGHT/2) / 2;
-  center.w /= 2;
-  center.h /= 2;
+  center.x -= (WIDTH/2) * rx;
+  center.y -= (HEIGHT/2) * ry;
+  center.w *= rx;
+  center.h *= ry;
   SDL_BlitSurface (image, &center, slice, NULL);
   SDL_UpdateRect (slice, 0, 0, 0, 0);
   scale = CairoTarget (slice);