1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _THEMES_H_
#define _THEMES_H_
#include <string>
#include <iostream>
#include <sys/types.h>
#ifndef WIN32
#include <dirent.h>
#else
#include <windows.h>
#endif /* WIN32 */
#include <SDL.h>
#include <SDL_image.h>
#include "SoundMgr.h"
#include "globals.h"
#include "GameRenderer.h"
#include "Menu.h"
#include "MenuItem.h"
#include "MenuItemMonitor.h"
#define TH_DIR "themes"
#define TH_NET "net.png"
#define TH_LEFTMALE "plml.png"
#define TH_RIGHTMALE "plmr.png"
#define TH_LEFTFEMALE "plfl.png"
#define TH_RIGHTFEMALE "plfr.png"
#define TH_BACKGROUND_JPG "background.jpg"
#define TH_BACKGROUND_PNG "background.png"
#define TH_BACKGROUND_BIG_JPG "background_big.jpg"
#define TH_BACKGROUND_BIG_PNG "background_big.png"
#define TH_BALL "ball.png"
#define TH_FONT "Font.png"
#define TH_FONTINV "FontInv.png"
#define TH_CONFNAME "theme.conf"
extern std::string ThemeDir;
class Theme {
private:
std::string _name;
bool _hasnet; // To possibly add the image of the net (not used yet)
std::string _background;
std::string _net;
std::string _font;
std::string _fontinv;
std::string _leftmale;
std::string _rightmale;
std::string _leftfemale;
std::string _rightfemale;
std::string _ball;
std::string _confFile;
std::string TD;
bool _hasConfFile;
bool _bigBackground;
bool _checkTheme(); // Theme Validation
public:
Theme(std::string name) {
#ifndef WIN32
DIR *dir;
if ((dir = opendir(ThemeDir.c_str())) == NULL) {
ThemeDir = "/usr/share/games/gav/" + ThemeDir;
if ((dir = opendir(ThemeDir.c_str())) == NULL) {
std::cerr << "Cannot find themes directory\n";
exit(0);
} else
closedir(dir);
} else
closedir(dir);
configuration.currentTheme = name;
TD = ThemeDir + "/" + name + "/";
#else
HANDLE hFindFile ;
WIN32_FIND_DATA ffdData ;
hFindFile = FindFirstFile (ThemeDir.c_str(), &ffdData) ;
if (hFindFile == INVALID_HANDLE_VALUE)
{
std::cerr << "Cannot find themes directory\n" ;
exit(0) ;
}
FindClose (hFindFile) ;
TD = ThemeDir + "\\" + name + "\\" ;
#endif /* WIN32 */
_name = name;
_bigBackground = configuration.bgBig;
if ( _bigBackground ) {
printf("Big Background hack: FIX IT!\n");
configuration.env.w = BIG_ENVIRONMENT_WIDTH;
configuration.env.h = BIG_ENVIRONMENT_HEIGHT;
double rat = ((double) configuration.desiredResolution.y) /
(double) BIG_ENVIRONMENT_HEIGHT;
int w = (int) (rat * BIG_ENVIRONMENT_WIDTH);
int h = configuration.desiredResolution.y;
configuration.setResolution(w, h);
configuration.scaleFactors(BIG_ENVIRONMENT_WIDTH,
BIG_ENVIRONMENT_HEIGHT);
} else {
configuration.env.w = ENVIRONMENT_WIDTH;
configuration.env.h = ENVIRONMENT_HEIGHT;
configuration.setResolutionToDesired();
configuration.scaleFactors(ENVIRONMENT_WIDTH, ENVIRONMENT_HEIGHT);
}
_net = TD + TH_NET;
if (!_bigBackground)
_background = TD + TH_BACKGROUND_PNG;
else
_background = TD + TH_BACKGROUND_BIG_PNG;
_font = TD + TH_FONT;
_fontinv = TD + TH_FONTINV;
_leftmale = TD + TH_LEFTMALE;
_rightmale = TD + TH_RIGHTMALE;
_leftfemale = TD + TH_LEFTFEMALE;
_rightfemale = TD + TH_RIGHTFEMALE;
_confFile = TD + TH_CONFNAME;
_ball = TD + TH_BALL;
_hasnet = Theme::_checkTheme();
// ::background = IMG_Load(background());
// TODO: fetch the environment size (and therefore the ratios)
// from the background image
//if ( CurrentTheme->hasnet() ) IMG_Load(CurrentTheme->net());
//screenFlags = SDL_DOUBLEBUF|SDL_HWSURFACE;
screenFlags |= SDL_DOUBLEBUF;
screen = SDL_SetVideoMode(configuration.resolution.x,
configuration.resolution.y,
videoinfo->vfmt->BitsPerPixel,
screenFlags);
::background = new LogicalFrameSeq(background(), 1, false);
gameRenderer = new GameRenderer(configuration.resolution.x,
configuration.resolution.y,
configuration.env.w,
configuration.env.h);
cga = new ScreenFont(font(), FONT_FIRST_CHAR, FONT_NUMBER);
cgaInv = new ScreenFont(fontinv(), FONT_FIRST_CHAR, FONT_NUMBER);
MenuItemMonitor().apply();
#ifdef AUDIO
if ( soundMgr )
delete(soundMgr);
soundMgr = new SoundMgr((TD+"sounds").c_str(),
(ThemeDir+"/../sounds").c_str());
#endif // AUDIO
}
~Theme() {
delete(::background);
delete(cga);
delete(cgaInv);
delete(gameRenderer);
}
#define _CCS(str) ((str).c_str())
inline const char * name() { return( _CCS(_name) );}
inline bool hasnet() { return( _hasnet );}
inline bool bigBackground() { return( _bigBackground );}
inline const char * background() { return( _CCS(_background) );}
inline const char * net() { return( _CCS(_net) );}
inline const char * font() { return( _CCS(_font) );}
inline const char * fontinv() { return( _CCS(_fontinv) );}
inline const char * leftmale() { return( _CCS(_leftmale) );}
inline const char * rightmale() { return( _CCS(_rightmale) );}
inline const char * leftfemale() { return( _CCS(_leftfemale) );}
inline const char * rightfemale(){ return( _CCS(_rightfemale) );}
inline const char * ball() { return( _CCS(_ball) );}
void loadConf();
class ThemeErrorException {
public:
std::string message;
ThemeErrorException(std::string msg) {
message = msg;
}
};
};
extern Theme *CurrentTheme;
inline void setThemeDir(std::string h) { ThemeDir = h; }
#endif
|