Planeshift

pseffectobjtext.h

Go to the documentation of this file.
00001 /*
00002  * Author: Andrew Robberts
00003  *
00004  * Copyright (C) 2003 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_OBJ_TEXT_HEADER
00021 #define PS_EFFECT_OBJ_TEXT_HEADER
00022 
00023 #include "pseffectobjquad.h"
00024 #include <imesh/sprite2d.h>
00025 
00026 #include "pseffectobjtextable.h"
00027 
00028 struct iGraphics3D;
00029 struct iGraphics2D;
00030 struct iTextureManager;
00031 struct iTextureWrapper;
00032 struct iFont;
00033 struct iParticle;
00034 class psEffect2DRenderer;
00035 
00036 
00041 class psEffectObjText : public psEffectObjQuad, public psEffectObjTextable
00042 {
00043 private:
00044     // needed managers
00045     csRef<iGraphics3D>      g3d;
00046     iGraphics2D*            g2d;
00047     csRef<iTextureManager>  txtmgr;
00048 
00049     // font
00050     csString            fontName;
00051     int                 fontSize;
00052     csRef<iFont>        font;
00053 
00054     // generated texture
00055     csRef<iTextureWrapper>      generatedTex;
00056     csRef<iMaterialWrapper>     generatedMat;
00057 
00058     int             texOriginalWidth;
00059     int             texOriginalHeight;
00060 
00061     int             texPO2Width;
00062     int             texPO2Height;
00063 
00064 public:
00065     psEffectObjText(iView* parentView, psEffect2DRenderer* renderer2d);
00066     ~psEffectObjText();
00067 
00070     virtual bool SetText(const csArray<psEffectTextElement> &elements);
00071     virtual bool SetText(const csArray<psEffectTextRow> &rows);
00072     virtual bool SetText(int rows, ...);
00073 
00074     // inheritted function overloads
00075     bool Load(iDocumentNode* node, iLoaderContext* ldr_context);
00076     psEffectObj* Clone() const;
00077 
00078 protected:
00082     bool PostSetup();
00083 
00084     void DrawTextElement(const psEffectTextElement &element);
00085 
00086     inline int ToPowerOf2(int n)
00087     {
00088         for(int a=sizeof(int) * 8-1; a>0; --a)
00089         {
00090             if(n & (1 << a))
00091             {
00092                 if(n == (1 << a))
00093                     return n;
00094                 else
00095                     return (1 << (a+1));
00096             }
00097         }
00098         return 1;
00099     };
00100 };
00101 
00104 #endif