Planeshift

pseffectobjtext2d.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_2D_HEADER
00021 #define PS_EFFECT_OBJ_TEXT_2D_HEADER
00022 
00023 #include <csgeom/vector2.h>
00024 #include <csutil/array.h>
00025 
00026 #include "pseffectobj.h"
00027 #include "effects/pseffectobjtextable.h"
00028 
00029 class psEffect2DRenderer;
00030 class psEffect2DElement;
00031 class psEffect2DTextElement;
00032 class psEffect2DImgElement;
00033 
00038 enum psEffectBackgroundAlign
00039 {
00040     EA_NONE = 0,
00041 
00042     EA_TOP_LEFT,
00043     EA_TOP,
00044     EA_TOP_RIGHT,
00045 
00046     EA_LEFT,
00047     EA_CENTER,
00048     EA_RIGHT,
00049 
00050     EA_BOTTOM_LEFT,
00051     EA_BOTTOM,
00052     EA_BOTTOM_RIGHT
00053 };
00054 struct psEffectBackgroundElem
00055 {
00056     psEffectBackgroundAlign     align;
00057 
00058     int                         umin;
00059     int                         vmin;
00060     int                         umax;
00061     int                         vmax;
00062 
00063     bool                        scale;
00064     bool                        tile;
00065     int                         offsetx;
00066     int                         offsety;
00067 };
00068 
00069 class psEffectObjText2D : public psEffectObj, public psEffectObjTextable
00070 {
00071 private:
00072     csRef<iGraphics3D>      g3d;
00073     csRef<iGraphics2D>      g2d;
00074     csRef<iTextureManager>  txtmgr;
00075 
00076     // font
00077     csString            fontName;
00078     int                 fontSize;
00079     csRef<iFont>        font;
00080 
00081     int                 maxWidth;
00082     int                 maxHeight;
00083 
00084     psEffectBackgroundAlign             backgroundAlign;
00085     iMaterialWrapper*                   backgroundMat;
00086     csArray<psEffectBackgroundElem>     backgroundElems;
00087 
00088     csArray<psEffect2DElement*>    elems;
00089 
00090 public:
00091     psEffectObjText2D(iView* parentView, psEffect2DRenderer* renderer2d);
00092     ~psEffectObjText2D();
00093 
00094     // draws 2d text
00095     bool SetText(const csArray<psEffectTextElement> &elements);
00096     bool SetText(const csArray<psEffectTextRow> &rows);
00097     bool SetText(int rows, ...);
00098 
00099     // inheritted function overloads
00100     bool Load(iDocumentNode* node, iLoaderContext* ldr_context);
00101     bool Render(const csVector3 &up);
00102     bool AttachToAnchor(psEffectAnchor* newAnchor);
00103     bool Update(csTicks elapsed);
00104     psEffectObj* Clone() const;
00105 
00106 protected:
00107 
00108     bool PostSetup();
00109     void DrawTextElement(const psEffectTextElement &element);
00110 };
00111 
00114 #endif