Planeshift

pseffect2drenderer.h

Go to the documentation of this file.
00001 /*
00002 * Author: Andrew Robberts
00003 *
00004 * Copyright (C) 2007 Atomic Blue ([email protected], http://www.atomicblue.org)
00005 *
00006 *
00007 * This program is free software; you can redistribute it and/or
00008 * modify it under the terms of the GNU General Public License
00009 * as published by the Free Software Foundation (version 2 of the License)
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 *
00018 */
00019 
00020 #ifndef PS_EFFECT_2D_RENDERER
00021 #define PS_EFFECT_2D_RENDERER
00022 
00023 #include <csutil/parray.h>
00024 #include <cstool/cspixmap.h>
00025 #include <csgeom/csrect.h>
00026 #include <ivideo/texture.h>
00027 #include <ivideo/graph3d.h>
00028 #include <ivideo/graph2d.h>
00029 #include <ivideo/fontserv.h>
00030 
00035 #define PS_EFFECT_2D_TEXT_MAX_CHARS 512
00036 
00039 class psEffect2DElement
00040 {
00041 protected:
00042     int zOrder;
00043     int alpha;
00044 
00045 public:
00046     int originx;
00047     int originy;
00048 
00049 public:
00050     psEffect2DElement(int zOrder, int alpha);
00051     virtual ~psEffect2DElement();
00052     int GetZOrder() const;
00053     int GetAlpha() const;
00054     void SetAlpha(int alpha);
00055     virtual void Draw(iGraphics3D* g3d, iGraphics2D* g2d);
00056 };
00057 
00060 class psEffect2DTextElement : public psEffect2DElement
00061 {
00062 public:
00063     csRef<iFont>    font;
00064     char            text[PS_EFFECT_2D_TEXT_MAX_CHARS];
00065     int             x;
00066     int             y;
00067     int             fgColor;
00068     int             bgColor;
00069     int                         shadowColor;
00070     int                         outlineColor;
00071 
00072 public:
00073     psEffect2DTextElement(int zOrder, iFont* font, const char* text, int x, int y, int fgColor, int bgColor, int outlineColor, int shadowColor, int alpha);
00074     virtual ~psEffect2DTextElement();
00075     virtual void Draw(iGraphics3D* g3d, iGraphics2D* g2d);
00076 };
00077 
00080 class psEffect2DImgElement : public psEffect2DElement
00081 {
00082 public:
00083     csRef<iTextureHandle> texHandle;
00084     csRect                texRect;
00085     csRect                destRect;
00086     bool                  tiled;
00087 
00088 public:
00089     psEffect2DImgElement(int zOrder, iTextureHandle* texHandle, const csRect &texRect, const csRect &destRect, int alpha, bool tiled);
00090     virtual ~psEffect2DImgElement();
00091     virtual void Draw(iGraphics3D* g3d, iGraphics2D* g2d);
00092 };
00093 
00096 class psEffect2DRenderer
00097 {
00098 private:
00099     csPDelArray<psEffect2DElement>  effect2DElements;
00100 
00101 public:
00102     psEffect2DRenderer();
00103     ~psEffect2DRenderer();
00104 
00105     psEffect2DElement* Add2DElement(psEffect2DElement* elem);
00106     void Remove2DElement(psEffect2DElement* elem);
00107     void Remove2DElementByIndex(size_t index);
00108     void RemoveAll2DElements();
00109     size_t Get2DElementCount() const;
00110 
00111     void Render(iGraphics3D* g3d, iGraphics2D* g2d);
00112 };
00113 
00116 #endif // PS_EFFECT_2D_RENDERER