genericrenderer.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_GENERICRENDERER_H
00023 #define FIFE_GENERICRENDERER_H
00024 
00025 // Standard C++ library includes
00026 
00027 // 3rd party library includes
00028 
00029 // FIFE includes
00030 // These includes are split up in two parts, separated by one empty line
00031 // First block: files included from the FIFE root src directory
00032 // Second block: files included from the same folder
00033 #include "view/rendererbase.h"
00034 
00035 namespace FIFE {
00036     class RenderBackend;
00037     class AbstractFont;
00038     class ImagePool;
00039     class AnimationPool;
00040 
00041     class GenericRendererNode {
00042     public:
00043         GenericRendererNode(Instance* attached_instance, Location* relative_location, const Point &relative_point = Point(0,0));
00044         GenericRendererNode(Instance* attached_instance, const Point &relative_point = Point(0,0));
00045         GenericRendererNode(Location* attached_location, const Point &relative_point = Point(0,0));
00046         GenericRendererNode(const Point &attached_point);
00047         ~GenericRendererNode();
00048 
00049         void setAttached(Instance* attached_instance, Location* relative_location, const Point &relative_point);
00050         void setAttached(Instance* attached_instance, Location* relative_location);
00051         void setAttached(Instance* attached_instance, const Point &relative_point);
00052         void setAttached(Instance* attached_instance);
00053         void setAttached(Location* attached_location, const Point &relative_point);
00054         void setAttached(Location* attached_location);
00055         void setAttached(const Point &attached_point);
00056 
00057         void setRelative(Location* relative_location);
00058         void setRelative(Location* relative_location, Point relative_point);
00059         void setRelative(const Point &relative_point);
00060 
00061         Instance* getAttachedInstance();
00062         Location* getAttachedLocation();
00063         Point getAttachedPoint();
00064 
00065         Location* getOffsetLocation();
00066         Point getOffsetPoint();
00067 
00068         Instance* getInstance();
00069         Location* getLocation();
00070         Point getPoint();
00071 
00072         Point getCalculatedPoint(Camera* cam, Layer* layer, std::vector<Instance*>& instances);
00073     private:
00074         Instance* m_instance;
00075         Location* m_location;
00076         Point m_point;
00077     };
00078     class GenericRendererElementInfo {
00079     public:
00080         virtual void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {};
00081         virtual ~GenericRendererElementInfo() {};
00082     };
00083 
00084     class GenericRendererLineInfo : public GenericRendererElementInfo {
00085     public:
00086         void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
00087         GenericRendererLineInfo(GenericRendererNode n1, GenericRendererNode n2, uint8_t r, uint8_t g, uint8_t b);
00088         virtual ~GenericRendererLineInfo() {};
00089     private:
00090         GenericRendererNode m_edge1;
00091         GenericRendererNode m_edge2;
00092         uint8_t m_red;
00093         uint8_t m_green;
00094         uint8_t m_blue;
00095     };
00096     class GenericRendererPointInfo : public GenericRendererElementInfo {
00097     public:
00098         void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
00099         GenericRendererPointInfo(GenericRendererNode n, uint8_t r, uint8_t g, uint8_t b);
00100         virtual ~GenericRendererPointInfo() {};
00101     private:
00102         GenericRendererNode m_anchor;
00103         uint8_t m_red;
00104         uint8_t m_green;
00105         uint8_t m_blue;
00106     };
00107     class GenericRendererQuadInfo : public GenericRendererElementInfo {
00108     public:
00109         void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
00110         GenericRendererQuadInfo(GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b);
00111         virtual ~GenericRendererQuadInfo() {};
00112     private:
00113         GenericRendererNode m_edge1;
00114         GenericRendererNode m_edge2;
00115         GenericRendererNode m_edge3;
00116         GenericRendererNode m_edge4;
00117         uint8_t m_red;
00118         uint8_t m_green;
00119         uint8_t m_blue;
00120     };
00121 
00122     class GenericRendererVertexInfo : public GenericRendererElementInfo {
00123     public:
00124         void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
00125         GenericRendererVertexInfo(GenericRendererNode center, int size, uint8_t r, uint8_t g, uint8_t b);
00126         virtual ~GenericRendererVertexInfo() {};
00127     private:
00128         GenericRendererNode m_center;
00129         int m_size;
00130         uint8_t m_red;
00131         uint8_t m_green;
00132         uint8_t m_blue;
00133     };
00134 
00135     class GenericRendererImageInfo : public GenericRendererElementInfo {
00136     public:
00137         void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
00138         GenericRendererImageInfo(GenericRendererNode n, int image);
00139         virtual ~GenericRendererImageInfo() {};
00140     private:
00141         GenericRendererNode m_anchor;
00142         int m_image;
00143     };
00144     class GenericRendererAnimationInfo : public GenericRendererElementInfo {
00145     public:
00146         void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
00147         GenericRendererAnimationInfo(GenericRendererNode n, int animation);
00148         virtual ~GenericRendererAnimationInfo() {};
00149     private:
00150         GenericRendererNode m_anchor;
00151         int m_animation;
00152         unsigned int m_start_time;
00153         float m_time_scale;
00154     };
00155     class GenericRendererTextInfo : public GenericRendererElementInfo {
00156     public:
00157         void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
00158         GenericRendererTextInfo(GenericRendererNode n, AbstractFont* font, std::string text);
00159         virtual ~GenericRendererTextInfo() {};
00160     private:
00161         GenericRendererNode m_anchor;
00162         AbstractFont* m_font;
00163         std::string m_text;
00164     };
00165     class GenericRenderer: public RendererBase {
00166     public:
00171         GenericRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool);
00172 
00173         GenericRenderer(const GenericRenderer& old);
00174 
00175         RendererBase* clone();
00176 
00179         virtual ~GenericRenderer();
00180         void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances);
00181         std::string getName() { return "GenericRenderer"; }
00182 
00185         static GenericRenderer* getInstance(IRendererContainer* cnt);
00186 
00187         void addLine(const std::string &group, GenericRendererNode n1, GenericRendererNode n2, uint8_t r, uint8_t g, uint8_t b);
00188         void addPoint(const std::string &group, GenericRendererNode n, uint8_t r, uint8_t g, uint8_t b);
00189         void addQuad(const std::string &group, GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b);
00190         void addVertex(const std::string &group, GenericRendererNode n, int size, uint8_t r, uint8_t g, uint8_t b);
00191         void addText(const std::string &group, GenericRendererNode n, AbstractFont* font, const std::string &text);
00192         void addImage(const std::string &group, GenericRendererNode n, int image);
00193         void addAnimation(const std::string &group, GenericRendererNode n, int animation);
00194         void removeAll(const std::string &group);
00195 
00196     private:
00197         ImagePool* m_imagepool;
00198         AnimationPool* m_animationpool;
00199         std::map<std::string, std::vector<GenericRendererElementInfo*> > m_groups;
00200     };
00201 
00202 }
00203 
00204 #endif