00001 #ifndef _GRAPHICS_
00002 #define _GRAPHICS_
00003
00004 #ifdef _MSC_VER // if the compiler is from Microsoft
00005 #pragma warning(disable:4786)
00006 #endif
00007
00008 #include "statuspanel.h"
00009 #include "inventorypanel.h"
00010 #include "menu.h"
00011 #include "world.h"
00012
00013 #include <SDL.h>
00014 #include <SDL_ttf.h>
00015
00016 #include <string>
00017 #include <vector>
00018
00019
00020
00021
00022 using namespace std;
00023
00031 class Graphics {
00032 public:
00036 static const unsigned int SCREEN_WIDTH;
00037
00041 static const unsigned int SCREEN_HEIGHT;
00042
00046 static const unsigned int SCREEN_BPP;
00047
00051 static const unsigned int STATUS_W;
00052
00056 static const unsigned int STATUS_H;
00057
00061 static const unsigned int STATUS_X;
00062
00066 static const unsigned int STATUS_Y;
00067
00071 static const unsigned int INVENTORY_W;
00072
00076 static const unsigned int INVENTORY_H;
00077
00081 static const unsigned int INVENTORY_X;
00082
00086 static const unsigned int INVENTORY_Y;
00087
00091 static const unsigned int FONT_SIZE;
00092
00096 static const string FONT_FILE;
00097
00102 static const unsigned int TILE_SIZE;
00103
00107 static const string TILES_FILE;
00108
00109 #ifdef SMOOTH_BORDERS
00110
00114 static const unsigned int BORDER_SIZE;
00115
00119 static const string BORDER_FILE;
00120 #endif
00121
00125 static const unsigned int PLAYER_SIZE;
00126
00130 static const string PLAYER_FILE;
00131
00135 static const unsigned int PLAYER_N_FRAMES;
00136
00137 static const unsigned int RESOURCE_SIZE;
00138 static const string RESOURCES_FILE;
00139 static const unsigned int TOOL_SIZE;
00140 static const string TOOLS_FILE;
00141 static const unsigned int BLACK;
00142
00152 Graphics();
00153
00160 Graphics(bool fullscreen);
00161
00169 ~Graphics();
00170
00171
00175 void init();
00176
00183 void drawMenu(Menu & menu);
00184
00192 void drawWorld(World & world, const bool updateNow = true);
00193
00194
00195 TTF_Font* getFont();
00196
00201 void loadData();
00202
00214 void updateText(const string* message, const char color,
00215 const string* currentText,
00216 const bool updateNow=false);
00217
00218 void toggleDebugMode();
00219
00220 private:
00224 void commonInit();
00225
00232 void drawDebugInfo(int px, int py, int velocity);
00233
00242 void drawPlayer(Player& player, int cpx, int cpy);
00243
00252 void drawTiles(int px, int py);
00253
00265 bool initVideoMode(const unsigned int width, const unsigned height,
00266 const unsigned int bpp, bool fullscreen);
00267
00272 void unloadData();
00273
00283 void updateWorldSurface(vector<Tile>& map, unsigned int mapWidth,
00284 unsigned int mapHeight,
00285 unsigned int px, unsigned int py);
00286
00292 SDL_Surface* screen;
00293
00298 StatusPanel statusPanel;
00299
00304 InventoryPanel inventoryPanel;
00305
00311 TTF_Font* font;
00312
00316 SDL_Surface* tiles;
00317
00318 #ifdef SMOOTH_BORDERS
00319
00322 SDL_Surface* borders;
00323 #endif
00324
00328 SDL_Surface* menuSurface;
00329
00333 SDL_Surface* worldSurface;
00334
00338 unsigned int ptx;
00339
00343 unsigned int pty;
00344
00345 SDL_Surface* playerSprites;
00346 SDL_Surface* resources;
00347 SDL_Surface* tools;
00348
00349 Uint32 playerColors[5];
00350
00351 bool debugMode;
00352
00353 void drawResource(Resource r);
00354 };
00355
00356 #endif