1
/***************************************************************************
3
- description: theme related code
6
copyright : (C) 2003 by Jesse Andrews et al
7
email : jdandr2@tux4kids.net
8
***************************************************************************/
10
/***************************************************************************
12
* This program is free software; you can redistribute it and/or modify *
13
* it under the terms of the GNU General Public License as published by *
14
* the Free Software Foundation; either version 2 of the License, or *
15
* (at your option) any later version. *
17
***************************************************************************/
24
const char PATHS[NUM_PATHS][FNLEN] = {
26
"/usr/share/"PACKAGE"/data",
27
"/usr/local/share/"PACKAGE"/data",
28
DATA_PREFIX"/share/"PACKAGE"/data"
31
SDL_Surface *letters[255] = { NULL };
32
unsigned char ALPHABET[256];
33
unsigned char KEYMAP[256];
34
unsigned char FINGER[256][10];
36
unsigned char realPath[2][FNLEN];
37
char themeName[FNLEN];
41
#define MAX_LANGUAGES 100
43
/* setup_theme: this function is in charge of setting up
44
* the paths that the loaders use. It will set a variable
45
* numPaths = 1 or 2. 1 if we are just using the default,
46
* 2 if there are two themes. Then it will edit the varible
47
* Paths[]. It will always put the theme path first, then
50
void setupTheme( char *dirName ) {
51
static struct stat dirStats;
54
useEnglish=1; // default is to use English if we cannot find theme
56
for (i=0; i<NUM_PATHS; i++) {
58
stat( PATHS[i], &dirStats );
59
if (S_IFDIR & dirStats.st_mode) {
60
strncpy( realPath[1], PATHS[i], FNLEN-1);
61
strncpy( themeName, "", FNLEN-1 );
65
if (dirName != NULL) {
68
/* find the path to the theme */
69
sprintf( fullDir, "%s/themes/%s", realPath[1], dirName );
71
stat( fullDir, &dirStats );
72
if (S_IFDIR & dirStats.st_mode) {
74
strncpy( realPath[0], fullDir, FNLEN-1 );
75
strncpy( themeName, dirName, FNLEN-1 );
80
void chooseTheme( void ) {
81
SDL_Surface *titles[MAX_LANGUAGES];
82
SDL_Surface *select[MAX_LANGUAGES];
83
SDL_Surface *left, *right;
84
SDL_Rect leftRect, rightRect;
85
SDL_Surface *world, *map, *photo;
86
SDL_Rect worldRect, photoRect;
87
SDL_Rect titleRects[8];
94
unsigned char fn[FNLEN];
95
unsigned char themeNames[MAX_LANGUAGES][FNLEN];
96
unsigned char themePaths[MAX_LANGUAGES][FNLEN];
99
char old_realPath[FNLEN];
102
struct dirent *themesFile;
103
struct stat fileStats;
105
old_useEnglish = useEnglish;
106
strncpy( old_realPath, realPath[0], FNLEN-1 );
108
sprintf( fn, "%s/themes/", realPath[1]);
109
themesDir = opendir(fn);
112
themesFile = readdir(themesDir);
116
/* we ignore any hidden file and CVS */
118
if (themesFile->d_name[0] == '.')
121
if (strcmp("CVS", themesFile->d_name)==0)
124
/* check to see if it is a directory */
125
sprintf( fn, "%s/themes/%s", realPath[1], themesFile->d_name);
128
stat( fn, &fileStats );
130
if (S_IFDIR & fileStats.st_mode) {
131
/* HACK: we should get the names from file :) */
132
strncpy( themeNames[themes], themesFile->d_name, FNLEN-1);
133
strncpy( themePaths[themes++], themesFile->d_name, FNLEN-1 );
140
// HACK: is font empty now???
141
font = LoadFont( ttf_font, ttf_font_size );
143
titles[0] = black_outline( "english", font, &white );
144
select[0] = black_outline( "english", font, &yellow);
145
for (i = 1; i<themes; i++) {
146
titles[i] = black_outline( themeNames[i], font, &white );
147
select[i] = black_outline( themeNames[i], font, &yellow);
150
world = LoadImage("world.png", IMG_ALPHA);
151
worldRect.x = 480 - (world->w/2);
152
worldRect.w = world->w;
154
worldRect.h = world->h;
160
useEnglish = old_useEnglish;
162
bkg = LoadImage("main_bkg.png", IMG_REGULAR);
164
left = LoadImage("left.png", IMG_ALPHA);
165
leftRect.w = left->w; leftRect.h = left->h;
166
leftRect.x = 160 - 80 - (leftRect.w/2); leftRect.y = 430;
168
right = LoadImage("right.png", IMG_ALPHA);
169
rightRect.w = right->w; rightRect.h = right->h;
170
rightRect.x = 160 + 80 - (rightRect.w/2); rightRect.y = 430;
172
/* set initial rect sizes */
173
titleRects[0].y = 30;
174
titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
175
for (i = 1; i<8; i++) {
176
titleRects[i].y = titleRects[i-1].y + 50;
177
titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
182
while (SDL_PollEvent(&event))
183
switch (event.type) {
187
case SDL_MOUSEMOTION:
188
for (i=0; (i<8) && (loc-(loc%8)+i<themes); i++)
189
if (inRect( titleRects[i], event.motion.x, event.motion.y )) {
195
case SDL_MOUSEBUTTONDOWN:
196
if (inRect( leftRect, event.button.x, event.button.y ))
197
if (loc-(loc%8)-8 >= 0) {
201
if (inRect( rightRect, event.button.x, event.button.y ))
202
if (loc-(loc%8)+8 < themes) {
206
for (i=0; (i<8) && (loc-(loc%8)+i<themes); i++)
207
if (inRect(titleRects[i], event.button.x, event.button.y)) {
210
/* --- set theme --- */
211
setupTheme(themePaths[loc]);
213
/* --- english --- */
221
if (event.key.keysym.sym == SDLK_ESCAPE) {
222
useEnglish = old_useEnglish;
223
strncpy( realPath[0], old_realPath, FNLEN-1 );
227
if (event.key.keysym.sym == SDLK_RETURN) {
229
/* --- set theme --- */
230
setupTheme(themePaths[loc]);
232
/* --- english --- */
239
if ((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_PAGEUP)) {
240
if (loc-(loc%8)-8 >= 0)
244
if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN)) {
245
if (loc-(loc%8)+8 < themes)
250
if (event.key.keysym.sym == SDLK_UP) {
255
if (event.key.keysym.sym == SDLK_DOWN) {
261
if (old_loc != loc) {
264
SDL_BlitSurface( bkg, NULL, screen, NULL );
266
SDL_BlitSurface( world, NULL, screen, &worldRect );
268
if (loc) setupTheme(themePaths[loc]); else setupTheme(NULL);
270
map = LoadImage( "map.png", IMG_ALPHA|IMG_NOT_REQUIRED );
272
SDL_BlitSurface( map, NULL, screen, &worldRect );
273
SDL_FreeSurface( map );
276
photo = LoadImage( "photo.png", IMG_ALPHA|IMG_NOT_REQUIRED );
278
photoRect.x = 480 - (photo->w/2);
280
photoRect.w = photo->w;
281
photoRect.h = photo->h;
282
SDL_BlitSurface( photo, NULL, screen, &photoRect );
283
SDL_FreeSurface( photo );
286
start = loc - (loc % 8);
287
for (i = start; i<MIN(start+8,themes); i++) {
288
titleRects[i%8].x = 160 - (titles[i]->w/2);
290
SDL_BlitSurface(select[loc], NULL, screen, &titleRects[i%8]);
292
SDL_BlitSurface(titles[i], NULL, screen, &titleRects[i%8]);
295
/* --- draw buttons --- */
298
SDL_BlitSurface( left, NULL, screen, &leftRect );
301
SDL_BlitSurface( right, NULL, screen, &rightRect );
303
SDL_UpdateRect(screen, 0, 0, 0 ,0);
309
/* --- clear graphics before quiting --- */
311
for (i = 0; i<themes; i++) {
312
SDL_FreeSurface(titles[i]);
313
SDL_FreeSurface(select[i]);
316
SDL_FreeSurface(world);
317
SDL_FreeSurface(bkg);
318
SDL_FreeSurface(left);
319
SDL_FreeSurface(right);