leveleditor level-settings menu is working now. introduced string_list_type.
[supertux.git] / src / type.c
1 //
2 // C Implementation: type
3 //
4 // Description:
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #include "SDL_image.h"
14 #include "string.h"
15 #include "stdlib.h"
16 #include "setup.h"
17 #include "globals.h"
18 #include "screen.h"
19 #include "defines.h"
20 #include "type.h"
21 #include "scene.h"
22
23 void string_list_init(string_list_type* pstring_list)
24 {
25 pstring_list->num_items = 0;
26 pstring_list->active_item = -1;
27 pstring_list->item = NULL;
28 }
29
30 char* string_list_active(string_list_type* pstring_list)
31 {
32 if(pstring_list == NULL)
33 return "";
34
35 if(pstring_list->active_item != -1)
36 return pstring_list->item[pstring_list->active_item];
37 else
38 return "";
39 }
40
41 void string_list_add_item(string_list_type* pstring_list, char* str)
42 {
43 char *pnew_string;
44 pnew_string = (char*) malloc(sizeof(char)*(strlen(str)+1));
45 strcpy(pnew_string,str);
46 ++pstring_list->num_items;
47 pstring_list->item = (char**) realloc(pstring_list->item,sizeof(char**)*pstring_list->num_items);
48 pstring_list->item[pstring_list->num_items-1] = pnew_string;
49 if(pstring_list->active_item == -1)
50 pstring_list->active_item = 0;
51 }
52
53 void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig)
54 {
55 int i;
56 string_list_free(pstring_list);
57 for(i = 0; i < pstring_list_orig.num_items; ++i)
58 string_list_add_item(pstring_list,pstring_list_orig.item[i]);
59 }
60
61 void string_list_free(string_list_type* pstring_list)
62 {
63 if(pstring_list != NULL)
64 {
65   int i;
66   for(i=0; i < pstring_list->num_items; ++i)
67     free(pstring_list->item[i]);
68 free(pstring_list->item);
69 pstring_list->item = NULL;
70 pstring_list->num_items = 0;
71 pstring_list->active_item = -1;
72 }
73 }