-/* $Id: main.c,v 1.8 2007/01/08 10:46:16 mmondor Exp $ */
+/* $Id: main.c,v 1.9 2007/01/08 11:46:57 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
+#include <SDL_ttf.h>
/* APPLICATION HEADERS */
#include <main.h>
/* DEFINITIONS */
+#define FADEOUT_DELAY 1000
+
struct scene {
const char *img, *mus;
int vol;
};
+struct font {
+ const char *name;
+ int pt;
+ TTF_Font *fnt;
+};
+
/* PRIVATE PROTOTYPES */
static void scene_switch(const char *, const char *, int);
static void scene_next(void);
+static void fonts_load(void);
+static TTF_Font *font_next(void);
+
/* PUBLIC GLOBALS */
};
static int curscene = 0;
+static struct font fonts[] = {
+ { "celtic", 14, NULL },
+ { "charming", 20, NULL },
+ { "darkcrystal", 12, NULL },
+ { "deloise", 18, NULL }, /* nice */
+ { "ironcarved", 16, NULL },
+ { "oldroman", 12, NULL },
+ { "santana", 14, NULL },
+ { "script", 18, NULL }, /* nice */
+ { NULL, 0, NULL }
+};
+static int curfont = 0;
+static SDL_Color fontcol = { 0x00, 0x00, 0x00 };
+
/* PRIVATE FUNCTIONS */
(void) Mix_AllocateChannels(4);
(void) Mix_ReserveChannels(2);
+ /*
+ * TTF
+ */
+ fonts_load();
+
/* XXX */
screen_draw();
scene_next();
}
/* Fadeout music */
- (void) Mix_FadeOutMusic(2000);
- SDL_Delay(2000);
+ (void) Mix_FadeOutMusic(FADEOUT_DELAY);
+ SDL_Delay(FADEOUT_DELAY);
exit(EXIT_SUCCESS);
}
SDL_Rect r;
(void) SDL_BlitSurface(img_border, NULL, screen_surface, NULL);
- r = (struct SDL_Rect){ 798, 16, 0, 0 };
+ r = (SDL_Rect){ 798, 16, 0, 0 };
(void) SDL_BlitSurface(img_textarea, NULL, screen_surface, &r);
if (img_painting != NULL) {
r = (SDL_Rect){ 16, 16, 0, 0 };
if (strcasecmp(mus, music_file) != 0) {
music_new = 1;
if (music != NULL) {
- (void) Mix_FadeOutMusic(2000);
- SDL_Delay(2000);
+ (void) Mix_FadeOutMusic(FADEOUT_DELAY);
+ SDL_Delay(FADEOUT_DELAY);
}
(void) Mix_HaltMusic();
}
static void
scene_next(void)
{
+ SDL_Surface *s;
if (scenes[curscene].img == NULL)
curscene = 0;
scene_switch(scenes[curscene].img, scenes[curscene].mus,
scenes[curscene].vol);
curscene++;
+
+ if ((s = TTF_RenderText_Blended(font_next(), "A Paradise Adventure!",
+ fontcol)) != NULL) {
+ SDL_Rect r;
+
+ r = (SDL_Rect){ 798, 16, 0, 0 };
+ (void) SDL_BlitSurface(img_textarea, NULL, screen_surface, &r);
+ r = (SDL_Rect){ 832, 32, 0, 0 };
+ (void) SDL_BlitSurface(s, NULL, screen_surface, &r);
+ SDL_FreeSurface(s);
+ }
+}
+
+static void
+fonts_load(void)
+{
+ int i;
+ char path[1024];
+
+ if (TTF_Init() == -1) {
+ (void) fprintf(stderr, "fonts_load() - TTF_Init() - %s",
+ TTF_GetError());
+ exit(EXIT_FAILURE);
+ }
+
+ for (i = 0; fonts[i].name != NULL; i++) {
+ (void) snprintf(path, 1023, "font/%s.ttf", fonts[i].name);
+ if ((fonts[i].fnt = TTF_OpenFont(path, fonts[i].pt)) == NULL) {
+ (void) fprintf(stderr,
+ "fonts_load() - %s - %s", path, TTF_GetError());
+ exit(EXIT_FAILURE);
+ }
+ }
+}
+
+static TTF_Font *
+font_next(void)
+{
+
+ if (fonts[curfont].name == NULL)
+ curfont = 0;
+
+ return fonts[curfont++].fnt;
}