-/* $Id: main.c,v 1.15 2007/01/12 12:28:19 mmondor Exp $ */
+/* $Id: main.c,v 1.16 2007/01/14 23:57:43 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
const char *text;
};
-struct font {
- const char *name;
- int pt;
- TTF_Font *fnt;
-};
-
typedef struct text {
TTF_Font *fnt;
int numlines, alloclines;
const char *);
static void scene_next(void);
-static void fonts_load(void);
-static TTF_Font *font_next(void);
-
static char *text_tok(char *, char *);
static char *text_alloc(text_t *);
static text_t *text_create(TTF_Font *, const char *);
static int main_quit = 0;
static SDL_Surface *img_border = NULL, *img_textarea = NULL,
- *img_painting = NULL;
+ *img_painting = NULL, *img_toolsarea = NULL;
static Mix_Music *music = NULL;
static char *painting_file = NULL, *music_file = NULL;
+static TTF_Font *font;
+static SDL_Color fontcol = { 0x00, 0x00, 0x00 };
+
/* These will actually be provided via dynamic configuration, but to test */
static const struct scene scenes[] = {
{ "gardens_smallbridge", "adventure1", 80,
{ "cavern_stairs", "cavern", 80,
"Some text here"
},
- { "cavern_gold", "cavern2", 128,
+ { "cavern_gold", "cavern2", 80,
"Some more text here"
},
{ "gardens_house", "castle", 80,
};
static int curscene = 0;
-static struct font fonts[] = {
- { "celtic", 14, NULL }, /* nice */
- { "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 */
IMG_GetError());
exit(EXIT_FAILURE);
}
+ if ((img_toolsarea = IMG_Load("img/screen_toolsarea.png")) == NULL) {
+ (void) fprintf(stderr, "main() - IMG_Load(toolsarea) - %s\n",
+ IMG_GetError());
+ exit(EXIT_FAILURE);
+ }
/*
* Audio
/*
* TTF
*/
- fonts_load();
+ if (TTF_Init() == -1) {
+ (void) fprintf(stderr, "main() - TTF_Init() - %s\n",
+ TTF_GetError());
+ exit(EXIT_FAILURE);
+ }
+ if ((font = TTF_OpenFont("font/deloise.ttf", 20)) == NULL) {
+ (void) fprintf(stderr, "main() - TTF_OpenFont(deloise) - %s\n",
+ TTF_GetError());
+ exit(EXIT_FAILURE);
+ }
/* XXX */
screen_draw();
(void) SDL_BlitSurface(img_border, NULL, screen_surface, NULL);
r = (SDL_Rect){ 798, 16, 0, 0 };
(void) SDL_BlitSurface(img_textarea, NULL, screen_surface, &r);
+ r = (SDL_Rect) { 798, 624, 0, 0 };
+ (void) SDL_BlitSurface(img_toolsarea, NULL, screen_surface, &r);
if (img_painting != NULL) {
r = (SDL_Rect){ 16, 16, 0, 0 };
(void) SDL_BlitSurface(img_painting, NULL, screen_surface, &r);
}
/* Draw text */
- if ((txt = text_create(font_next(), text)) != NULL) {
+ if ((txt = text_create(font, text)) != NULL) {
SDL_Rect r;
SDL_Surface *s;
int i, y, h;
curscene++;
}
-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;
-}
-
/*
* strtok(3) replacement which only takes '\0' ' ' and '\n' in consideration
* and also returns the terminating character.