Prints some subtitles
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Tue, 12 Aug 2008 18:22:20 +0000 (15:22 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Tue, 12 Aug 2008 18:28:36 +0000 (15:28 -0300)
movie.c

diff --git a/movie.c b/movie.c
index 88dc03f..31da099 100644 (file)
--- a/movie.c
+++ b/movie.c
 
 #define WIDTH 800
 #define HEIGHT 600
+#define HBORDER 32
+#define VBORDER 8
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <cairo.h>
 #include <SDL.h>
 #include <SDL_image.h>
+#include <SDL_ttf.h>
 
 #define SWAP(x, y) do { \
        x ^= y; y ^= x; x ^= y; \
@@ -34,6 +37,8 @@
 #define IS_CENTER(cx, cy, x, y) \
        ((x + WIDTH/2 == cx) && (y + HEIGHT/2 == cy))
 
+TTF_Font *font;
+
 SDL_Rect *points;
 int psize;
 
@@ -161,6 +166,9 @@ GetNextImage (SDL_Surface *image)
   SDL_Surface *slice;
   SDL_Rect center;
   SDL_Surface *scale;
+  SDL_Surface *text;
+  SDL_Rect box;
+  SDL_Color Yellow = { 255, 255, 0, 0};
   center = GetNextPoint (), GetNextPoint (), GetNextPoint ();
   slice = SDL_CreateRGBSurface (SDL_SWSURFACE, WIDTH/2, HEIGHT/2,
                                 32,
@@ -173,6 +181,19 @@ GetNextImage (SDL_Surface *image)
   SDL_UpdateRect (slice, 0, 0, 0, 0);
   scale = CairoTarget (slice);
   SDL_FreeSurface (slice);
+  text = TTF_RenderUTF8_Solid (font, "GNU", Yellow);
+  box.w = text->w + HBORDER;
+  box.h = text->h + VBORDER;
+  box.x = (WIDTH - text->w - HBORDER) / 2;
+  box.y = HEIGHT - (text->h + 32 + VBORDER/2);
+  SDL_FillRect (scale, &box, SDL_MapRGB (scale->format, 0, 0, 0));
+  box.x += HBORDER/2;
+  box.y += VBORDER/2;
+  box.w -= HBORDER;
+  box.h -= VBORDER;
+  SDL_BlitSurface (text, NULL, scale, &box);
+  SDL_UpdateRect (scale, 0, 0, 0, 0);
+  SDL_FreeSurface (text);
   return scale;
 }
 
@@ -195,6 +216,8 @@ main (int argc, char **argv)
   SDL_Event event;
   ReadPoints ("pro-gnu");
   SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
+  TTF_Init ();
+  font = TTF_OpenFont ("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", 48);
   screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
   image = IMG_Load ("/home/cascardo/fotos/debconf.jpg");
   SDL_AddTimer (0, ShowNext, NULL);
@@ -210,6 +233,8 @@ main (int argc, char **argv)
     }
   }
   SDL_FreeSurface (image);
+  TTF_CloseFont (font);
+  TTF_Quit ();
   SDL_Quit ();
   free (points);
   return 0;