1 /************************************************************************
2  * This file is part of Wizznic.                                        *
3  * Copyright 2009-2015 Jimmy Christensen <dusted@dusted.dk>             *
4  * Wizznic is free software: you can redistribute it and/or modify      *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation, either version 3 of the License, or    *
7  * (at your option) any later version.                                  *
8  *                                                                      *
9  * Wizznic is distributed in the hope that it will be useful,           *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
12  * GNU General Public License for more details.                         *
13  *                                                                      *
14  * You should have received a copy of the GNU General Public License    *
15  * along with Wizznic.  If not, see <http://www.gnu.org/licenses/>.     *
16  ************************************************************************/
17 
18 #include <stdio.h>
19 #include <string.h>
20 
21 #include "about.h"
22 #include "scrollbar.h"
23 #include "list/list.h"
24 #include "defs.h"
25 #include "text.h"
26 
27 static char** lines;
28 int numLines;
29 
aboutInit()30 void aboutInit()
31 {
32   char buf[128];
33   list_t* txt;
34   listItem* it;
35   FILE* fp = fopen( DATADIR"data/about.txt", "r");
36 
37   if(!fp)
38   {
39     printf("Couldn't open "DATADIR"data/about.txt\n");
40        return;
41 
42   }
43   txt = listInit(NULL);
44 
45   while( fgets(buf, 128, fp ) )
46   {
47     int l = strlen(buf);
48     it = listAppendData(txt, malloc( l+1 ) );
49     strcpy( (char*)(it->data), buf );
50   }
51 
52   numLines = txt->count;
53   lines = malloc( sizeof(char*)*numLines );
54   listAddToArray((void*)lines,txt);
55   listFree(txt);
56 }
57 
58 //Return number of lines of text
aboutScreen(SDL_Surface * screen,int * menuPosY,int menuChangeY)59 int aboutScreen(SDL_Surface* screen, int* menuPosY,  int menuChangeY)
60 {
61   int i;
62   for(i=*menuPosY; i < 23+*menuPosY && i < numLines; i++)
63     txtWrite(screen, FONTSMALL, lines[i], HSCREENW-160+28, HSCREENH-120+40+(i-*menuPosY)*8);
64 
65   i=scrollBar(screen, HSCREENW-160+6,HSCREENH-120+40, numLines-15, *menuPosY,menuChangeY);
66   if( i != -1 )
67   {
68     *menuPosY=i;
69   }
70 
71   return(numLines-15);
72 }
73