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 VIRTUALSURFACE_HH_ 00018 # define VIRTUALSURFACE_HH_ 00019 00020 # include "Surface.hh" 00021 00031 class VirtualSurface : public Surface 00032 { 00033 public: 00034 VirtualSurface(); 00035 VirtualSurface(const std::string& name, SDL_Surface* surf); 00036 VirtualSurface(const std::string& name, int width, int height); 00037 virtual ~VirtualSurface(); 00038 00042 void addChild(Surface* child); 00045 void removeChild(Surface* child); 00048 int getChildrenNb() const; 00049 00053 void updateChildZOrder(); 00054 00055 virtual void enable(); 00056 virtual void show(); 00057 virtual void setZoom(double zoom); 00058 virtual void update(); 00059 virtual void render(); 00060 00065 void invalidate(const Rect& zone); 00071 void invalidate(const Point& pos, const Point& size); 00072 00073 template <class Class> 00074 struct TraverseCallback { 00075 typedef void (Class::*Method)(Surface *); 00076 }; 00077 00078 template <class Class> 00079 void traverse(VirtualSurface *root, Class* object, 00080 typename TraverseCallback<Class>::Method method) 00081 { 00082 VirtualSurface *s; 00083 SurfaceList::iterator it; 00084 00085 for (it = children_list_.begin(); it != children_list_.end(); ++it) 00086 { 00087 s = dynamic_cast<VirtualSurface *>(*it); 00088 if (s != 0) 00089 s->traverse(s, object, method); 00090 (object->*method)(*it); 00091 } 00092 } 00093 00094 protected: 00097 void unlockChildrenList(); 00098 00099 typedef std::vector<Surface*> SurfaceList; 00100 SurfaceList children_list_; 00101 00102 typedef std::vector<Rect> RectList; 00103 RectList invalidated_surf_; 00104 00105 bool children_list_lock_; 00106 bool sort_children_; 00107 SurfaceList children_to_add_; 00108 00109 std::string name_; 00110 }; 00111 00112 #endif /* !VIRTUALSURFACE_HH_ */
1.6.3