ResourceCenter.hh

00001 /*
00002 ** TowBowlTactics, an adaptation of the tabletop game Blood Bowl.
00003 ** 
00004 ** Copyright (C) 2006 The TBT Team.
00005 ** 
00006 ** This program is free software; you can redistribute it and/or
00007 ** modify it under the terms of the GNU General Public License
00008 ** as published by the Free Software Foundation; either version 2
00009 ** of the License, or (at your option) any later version.
00010 ** 
00011 ** The complete GNU General Public Licence Notice can be found as the
00012 ** `NOTICE' file in the root directory.
00013 ** 
00014 ** The TBT Team consists of people listed in the `AUTHORS' file.
00015 */
00016 
00017 #ifndef RESOURCECENTER_HH_
00018 # define RESOURCECENTER_HH_
00019 
00020 # include <SDL.h>
00021 # include "tools.hh"
00022 # include "Surface.hh"
00023 
00028 class SDLError : public Exception
00029 {
00030 public:
00031   SDLError(const std::string& msg);
00032 };
00033 
00038 class TTFError : public Exception
00039 {
00040 public:
00041   TTFError(const std::string& msg);
00042 };
00043 
00044 // Forward decl for TTF_Font.
00045 struct _TTF_Font;
00046 typedef struct _TTF_Font TTF_Font;
00047 
00057 class ResourceCenter
00058 {
00059 public:
00060   ResourceCenter();
00061   ~ResourceCenter();
00062 
00064   static ResourceCenter* getInst();
00065 
00069   const std::string& getResourcePrefix() const;
00070   
00074   void setResourcePrefix(const std::string& prefix = "");
00075   
00086   Surface getImage(const std::string& filename, double zoom = 1., double angle = 0.);
00087 
00095   TTF_Font* getFont(const std::string font_name, int font_size);
00096 
00099   void releaseFont(TTF_Font* font);
00100 
00102   void printStatistics();
00103 
00104 private:
00109   SDL_Surface* loadImage(const std::string& filename);
00110 
00113   SDL_Surface* transformImage(SDL_Surface* from, double zoom, double angle);
00114 
00116   static ResourceCenter* inst_;
00117 
00118   std::string prefix_;
00119   
00120   typedef std::set<Surface, Surface::ImgSort> ImageList;
00121   ImageList             image_list_;
00122 
00126   struct LoadedFont {
00127     TTF_Font* font_;    
00128     std::string name_;  
00129     int size_;          
00130     int ref_count_;     
00131     friend bool operator< (const LoadedFont& lhs, const LoadedFont& rhs)
00132     {
00133       if (lhs.name_ < rhs.name_)
00134         return true;
00135       if (lhs.name_ > rhs.name_)
00136     return false;
00137       return lhs.size_ < rhs.size_;
00138     }
00139   };
00140   typedef std::set<LoadedFont> FontList;
00141   FontList font_list_;
00142 };
00143 
00144 #endif /* !RESOURCECENTER_HH_ */

Generated on Sat Jun 23 16:07:24 2007 for Stechec/TBT by  doxygen 1.4.7