1 /************************************************************************
3 * voxelands - 3d voxel world sandbox game
4 * Copyright (C) Lisa 'darkrose' Milne 2016 <lisa@ltmnet.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 ************************************************************************/
22 #define _WM_EXPOSE_ALL
29 array_t
*fonts
= NULL
;
31 /* load a font file */
32 int font_load(char* file
, char* token
)
38 fonts
= array_create(ARRAY_TYPE_PTR
);
43 t
= strrchr(file
,'.');
47 f
= malloc(sizeof(font_t
));
48 f
->token
= strdup(token
);
52 if (!strcmp(t
,"ttf")) {
53 r
= font_load_ttf(f
,file
);
55 vlprintf(CN_ERROR
, "Unsupported Font: %s",file
);
64 array_push_ptr(fonts
,f
);
69 /* get a font by id */
70 font_t
*font_get(int id
)
74 font_load("font.ttf","default");
81 f
= array_get_ptr(fonts
,id
-1);
83 f
= array_get_ptr(fonts
,0);
88 /* get a font by token */
89 font_t
*font_find(char* token
)
94 font_load("font.ttf","default");
99 for (i
=0; i
<fonts
->length
; i
++) {
100 if (!strcmp(f
[i
]->token
,token
))
104 return array_get_ptr(fonts
,0);
107 /* get the id of a font */
108 int font_get_id(char* token
)
113 font_load("font.ttf","default");
118 for (i
=0; i
<fonts
->length
; i
++) {
119 if (!strcmp(f
[i
]->token
,token
))
123 if (!strcmp(token
,"default"))