Surface.hh

00001 /*
00002 ** TowBowlTactics, a turn-based strategy football game.
00003 **
00004 ** Copyright (C) 2006-2010 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 SURFACE_HH_
00018 # define SURFACE_HH_
00019 
00020 # include <SDL.h>
00021 # include "tools.hh"
00022 
00023 class VirtualSurface;
00024 
00038 class Surface
00039 {
00040 public:
00041   Surface();
00042   Surface(SDL_Surface* surf, double zoom = 1., double angle = 0., const std::string& filename = "");
00043   Surface(const std::string filename, double zoom = 1., double angle = 0.);
00044   Surface(int width, int height);
00045   virtual ~Surface();
00046 
00047   // On-copy methods.
00048   Surface(const Surface& s);
00049   Surface& operator=(const Surface& s);
00050 
00052   Point         getPos() const;
00053 
00055   Point         getSize() const;
00056 
00059   const Rect&   getRect() const;
00060 
00067   virtual Rect  getScreenRect() const;
00068 
00069   
00070   double        getZoom() const;
00071   double        getAngle() const;
00072   int           getZ() const;
00073   SDL_Surface*  getSDLSurface();
00074 
00075   virtual void  setPos(const Point& pos);
00076   void          setPos(int x, int y);
00077   void          setSize(const Point& size);
00078   virtual void  setZoom(double zoom);
00079   virtual void  setAngle(double angle);
00080   virtual void  setZ(int z);
00081 
00082   void      setInheritAlpha(bool enabled);
00083 
00086   virtual void  enable();
00090   virtual void  disable();
00092   bool      isEnabled() const;
00093   
00096   virtual void  show();
00099   virtual void  hide();
00100   // !@brief Whether it is displayed or not.
00101   bool          isShown() const;
00102 
00106   void create(int width, int height, SDL_Surface* ref_surface = NULL);
00107 
00109   void load(const std::string filename, double zoom = 1., double angle = 0.);
00110 
00112   void free();
00113 
00126   virtual void  update();
00127   
00128   virtual void blit(Surface& to);
00129   virtual void blit(Surface& to, const Rect& to_rect, const Rect& from_rect);
00130 
00131   friend std::ostream& operator<< (std::ostream& os, const Surface& s);
00132   
00133 protected:
00134 
00135   
00139   virtual void render() {}
00140 
00141   // Sort by Z component. Used by VirtualSurface.
00142   struct ZSort : public std::binary_function<const Surface*, const Surface*, bool>
00143   {
00144     bool operator()(const Surface* lhs, const Surface* rhs);
00145   };
00146 
00147   // Sort by filename-zoom-angle. Used by ResourceCenter
00148   struct ImgSort : public std::binary_function<const Surface*, const Surface*, bool>
00149   {
00150     bool operator()(const Surface& lhs, const Surface& rhs);    
00151   };
00152 
00158   virtual Rect  getRenderRect() const;
00159 
00162   void blitAlpha(SDL_Surface *src_surf, SDL_Surface *dst_surf,
00163          SDL_Rect* src_rect, unsigned dst_x, unsigned dst_y);
00164 
00165   SDL_Surface*  surf_;
00166 
00167 private:
00168   std::string   filename_;
00169   Rect          rect_;          
00170   Rect          orig_rect_;     
00171   double        zoom_;
00172   double        angle_;
00173   int           z_;
00174   bool      inherit_alpha_;
00175   bool      enabled_;
00176   bool          show_;
00177 
00178 protected:
00179   bool            redraw_all_;
00180   VirtualSurface* parent_;
00181 
00182   friend class VirtualSurface;
00183   friend class ResourceCenter; // for stats
00184 };
00185 
00186 #endif /* !SURFACE_HH_ */
Generated on Mon Apr 5 21:17:14 2010 for Stechec/TBT by  doxygen 1.6.3