*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Sun, 14 Jan 2007 23:57:43 +0000 (23:57 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Sun, 14 Jan 2007 23:57:43 +0000 (23:57 +0000)
mmsoftware/paradise_adventure/src/main.c

index 7a9cfb3..3b79d4b 100644 (file)
@@ -1,4 +1,4 @@
-/* $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
@@ -39,12 +39,6 @@ struct scene {
        const char      *text;
 };
 
-struct font {
-       const char      *name;
-       int             pt;
-       TTF_Font        *fnt;
-};
-
 typedef struct text {
        TTF_Font        *fnt;
        int             numlines, alloclines;
@@ -62,9 +56,6 @@ static void           scene_switch(const char *, const char *, int,
                            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 *);
@@ -81,12 +72,15 @@ static void         text_free(text_t *);
 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,
@@ -113,7 +107,7 @@ static const struct scene scenes[] = {
        { "cavern_stairs",              "cavern",       80,
                "Some text here"
        },
-       { "cavern_gold",                "cavern2",      128,
+       { "cavern_gold",                "cavern2",      80,
                "Some more text here"
        },
        { "gardens_house",              "castle",       80,
@@ -132,20 +126,6 @@ static const struct scene scenes[] = {
 };
 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 */
@@ -187,6 +167,11 @@ main(int argc, char **argv)
                    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
@@ -202,7 +187,16 @@ main(int argc, char **argv)
        /*
         * 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();
@@ -250,6 +244,8 @@ screen_draw(void)
        (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);
@@ -310,7 +306,7 @@ scene_switch(const char *img, const char *mus, int vol, const char *text)
        }
 
        /* 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;
@@ -372,38 +368,6 @@ scene_next(void)
        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.