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 void CGraphicString::Draw() const 00042 { 00043 CFontManager::Instance().DrawString(*this); 00044 } 00045 00046 //----------------------------------------------------------------------- 00047 TVector2I CGraphicString::GetPixelSize() const 00048 { 00049 return CFontManager::Instance().GetStringPixelSize(*this); 00050 } 00051 00052 //----------------------------------------------------------------------- 00053 void CGraphicString::Align(ulong nMode, const CRectangle& Rect) 00054 { 00055 // Size in pixels 00056 TVector2I PSize = GetPixelSize(); 00057 00058 // Horizontal alignement 00059 if (nMode & ALIGN_RIGHT) 00060 { 00061 Position.x = Rect.Right() - PSize.x; 00062 } 00063 else if (nMode & ALIGN_HCENTER) 00064 { 00065 Position.x = Rect.Left() + (Rect.Width() - PSize.x) / 2; 00066 } 00067 else // by default : ALIGN_LEFT 00068 { 00069 Position.x = Rect.Left(); 00070 } 00071 00072 // Vertical alignement 00073 if (nMode & ALIGN_BOTTOM) 00074 { 00075 Position.y = Rect.Bottom() - PSize.y; 00076 } 00077 else if (nMode & ALIGN_VCENTER) 00078 { 00079 Position.y = Rect.Top() + (Rect.Height() - PSize.y) / 2; 00080 } 00081 else // by default : ALIGN_TOP 00082 { 00083 Position.y = Rect.Top(); 00084 } 00085 } 00086 00087 } // namespace Keos
1.5.1-p1