Fixed the scrolling issue. Forgot that the DrawingContext used by gradient was global...
[supertux.git] / src / type.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 // 
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 //  02111-1307, USA.
20
21 #include "SDL_image.h"
22
23 #include "string.h"
24 #include "stdlib.h"
25 #include "setup.h"
26 #include "globals.h"
27 #include "screen/screen.h"
28 #include "defines.h"
29 #include "type.h"
30 #include "scene.h"
31
32 void string_list_init(string_list_type* pstring_list)
33 {
34   pstring_list->num_items = 0;
35   pstring_list->active_item = -1;
36   pstring_list->item = NULL;
37 }
38
39 char* string_list_active(string_list_type* pstring_list)
40 {
41   if(pstring_list == NULL)
42     return "";
43
44   if(pstring_list->active_item != -1)
45     return pstring_list->item[pstring_list->active_item];
46   else
47     return "";
48 }
49
50 void string_list_add_item(string_list_type* pstring_list,const  char* str)
51 {
52   char *pnew_string;
53   pnew_string = (char*) malloc(sizeof(char)*(strlen(str)+1));
54   strcpy(pnew_string,str);
55   ++pstring_list->num_items;
56   pstring_list->item = (char**) realloc(pstring_list->item,sizeof(char**)*pstring_list->num_items);
57   pstring_list->item[pstring_list->num_items-1] = pnew_string;
58   if(pstring_list->active_item == -1)
59     pstring_list->active_item = 0;
60 }
61
62 void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig)
63 {
64   int i;
65   string_list_free(pstring_list);
66   for(i = 0; i < pstring_list_orig.num_items; ++i)
67     string_list_add_item(pstring_list,pstring_list_orig.item[i]);
68 }
69
70 int string_list_find(string_list_type* pstring_list,const  char* str)
71 {
72   int i;
73   for(i = 0; i < pstring_list->num_items; ++i)
74     {
75       if(strcmp(pstring_list->item[i],str) == 0)
76         {
77           return i;
78         }
79     }
80   return -1;
81 }
82
83 void string_list_sort(string_list_type* pstring_list)
84 {
85   int i,j,y;
86
87   for(j = 0; j < pstring_list->num_items; ++j)
88     for(i = 0; i < pstring_list->num_items-1; ++i)
89       {
90
91         y = strcmp(pstring_list->item[i],pstring_list->item[i+1]);
92         if(y == 0)
93           {
94             continue;
95           }
96         else if(y < 0)
97           {
98             continue;
99           }
100         else if(y > 0)
101           {
102             char* char_pointer;
103             char_pointer = pstring_list->item[i];
104             pstring_list->item[i] = pstring_list->item[i+1];
105             pstring_list->item[i+1] = char_pointer;
106             continue;
107           }
108
109       }
110
111 }
112
113 void string_list_free(string_list_type* pstring_list)
114 {
115   if(pstring_list != NULL)
116     {
117       int i;
118       for(i=0; i < pstring_list->num_items; ++i)
119         free(pstring_list->item[i]);
120       free(pstring_list->item);
121       pstring_list->item = NULL;
122       pstring_list->num_items = 0;
123       pstring_list->active_item = -1;
124     }
125 }