Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

# KeosGraphicString.cpp

Go to the documentation of this file.

    00001 /*
    00002  * This source file is part of KEOS (Free 3D Engine)
    00003  * For the latest info, see http://www.keosengine.org/
    00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
    00005  *
    00006  * This program is free software; you can redistribute it and/or modify it under
    00007  * the terms of the GNU Lesser General Public License as published by the Free Software
    00008  * Foundation; either version 2 of the License, or (at your option) any later
    00009  * version.
    00010  *
    00011  * This program is distributed in the hope that it will be useful, but WITHOUT
    00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Lesser General Public License along with
    00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00018  * http://www.gnu.org/copyleft/lesser.txt.
    00019  *
    00020  */
    00021
    00022 #include "KeosGraphicString.h"
    00023 #include "KeosFontManager.h"
    00024
    00025 namespace Keos
    00026 {
    00027     //=======================================================================
    00028     // CGraphicString implementation
    00029     //=======================================================================
    00030
    00031     //-----------------------------------------------------------------------
    00032     CGraphicString::CGraphicString(const TVector2I& StringPosition, const String& strText, const CColor& StringColor,
    00033                                     const String& strFont) :
    00034     Position(StringPosition),
    00035     Text    (strText),
    00036     Color   (StringColor),
    00037     Font    (strFont)
    00038     {
    00039
    00040     }
    00041
    00042     //-----------------------------------------------------------------------
    00043     void CGraphicString::Draw() const
    00044     {
    00045         CFontManager::Instance().DrawString(*this);
    00046     }
    00047
    00048     //-----------------------------------------------------------------------
    00049     TVector2I CGraphicString::GetPixelSize() const
    00050     {
    00051         return CFontManager::Instance().GetStringPixelSize(*this);
    00052     }
    00053
    00054     //-----------------------------------------------------------------------
    00055     void CGraphicString::Align(ulong nMode, const CRectangle& Rect)
    00056     {
    00057         // Size in pixels
    00058         TVector2I PSize = GetPixelSize();
    00059
    00060         // Horizontal alignement
    00061         if (nMode & ALIGN_RIGHT)
    00062         {
    00063             Position.x = Rect.Right() - PSize.x;
    00064         }
    00065         else if (nMode & ALIGN_HCENTER)
    00066         {
    00067             Position.x = Rect.Left() + (Rect.Width() - PSize.x) / 2;
    00068         }
    00069         else // by default : ALIGN_LEFT
    00070         {
    00071             Position.x = Rect.Left();
    00072         }
    00073
    00074         // Vertical alignement
    00075         if (nMode & ALIGN_BOTTOM)
    00076         {
    00077             Position.y = Rect.Bottom() - PSize.y;
    00078         }
    00079         else if (nMode & ALIGN_VCENTER)
    00080         {
    00081             Position.y = Rect.Top() + (Rect.Height() - PSize.y) / 2;
    00082         }
    00083         else // by default : ALIGN_TOP
    00084         {
    00085             Position.y = Rect.Top();
    00086         }
    00087     }
    00088
    00089 } // namespace Keos