00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "TextBillboardComponent.h"
00018 #include "../../core/GameManager.h"
00019
00020
00021
00022
00023 TextBillboardComponent::TextBillboardComponent(Entity *parent)
00024 : BillboardComponent(parent, true)
00025 {
00026 init(GameManager::Instance()->getGUIEnvironment()->getBuiltInFont(), 0,
00027 dimension2df(10.0f, 10.0f), SColor(255, 255, 255, 255), SColor(255, 255, 255, 255));
00028 }
00029
00030
00031 TextBillboardComponent::TextBillboardComponent(Entity *parent, const std::string &fontFileName,
00032 const wchar_t *text, const dimension2df &size,
00033 const SColor &colorTop, const SColor &colorBottom)
00034 : BillboardComponent(parent, true)
00035 {
00036 init(GameManager::Instance()->getGUIEnvironment()->getFont(fontFileName.c_str()),
00037 text, size, colorTop, colorBottom);
00038 }
00039
00040
00041 TextBillboardComponent::TextBillboardComponent(Entity *parent, const std::string &fontFileName,
00042 const std::string &text, const dimension2df &size,
00043 const SColor &colorTop, const SColor &colorBottom)
00044 : BillboardComponent(parent, true)
00045 {
00046 core::stringw wBuffer = core::stringw(text.c_str());
00047 init(GameManager::Instance()->getGUIEnvironment()->getFont(fontFileName.c_str()),
00048 wBuffer.c_str(), size, colorTop, colorBottom);
00049 }
00050
00051
00052 TextBillboardComponent::~TextBillboardComponent()
00053 {
00054 mBillboardTextSN->remove();
00055 mBillboardSN = NULL;
00056 mSceneNode = NULL;
00057 }
00058
00059
00060 void TextBillboardComponent::init(IGUIFont *font, const wchar_t *text, const dimension2df &size,
00061 const SColor &colorTop, const SColor &colorBottom)
00062 {
00063
00064 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00065
00066
00067 mBillboardTextSN = pSceneMgr->addBillboardTextSceneNode(font, text, 0, size,
00068 pParent->getAbsolutePosition(),
00069 pParent->getID(),
00070 colorTop, colorBottom);
00071 mBillboardSN = mBillboardTextSN;
00072 mSceneNode = mBillboardTextSN;
00073
00074
00075 mTriSelector = pSceneMgr->createTriangleSelectorFromBoundingBox(mBillboardTextSN);
00076 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00077 }
00078
00079
00080 IBillboardTextSceneNode* TextBillboardComponent::getBillboardTextSceneNode()
00081 {
00082 return mBillboardTextSN;
00083 }
00084
00085
00086 void TextBillboardComponent::setText(const std::string &text)
00087 {
00088 core::stringw wBuffer = core::stringw(text.c_str());
00089 mBillboardTextSN->setText(wBuffer.c_str());
00090 }
00091
00092
00093 void TextBillboardComponent::setText(const wchar_t *text)
00094 {
00095 mBillboardTextSN->setText(text);
00096 }
00097
00098
00099 void TextBillboardComponent::setTextColor(const SColor &color)
00100 {
00101 mBillboardTextSN->setTextColor(color);
00102 }
00103
00104
00105 bool TextBillboardComponent::parseXML(IXMLReader *file, Entity *entity)
00106 {
00107
00108 TextBillboardComponent *component = NULL;
00109
00110
00111 if(file->getNodeType() == io::EXN_ELEMENT)
00112 {
00113 if(stringw("TextBillboardComponent") == file->getNodeName())
00114 {
00115
00116 component = new TextBillboardComponent(entity);
00117 }
00118 }
00119
00120 if(component == NULL)
00121 return false;
00122
00123
00124 while(file->read())
00125 {
00126 switch(file->getNodeType())
00127 {
00128 case io::EXN_ELEMENT:
00129
00130
00131 if(stringw("text") == file->getNodeName())
00132 {
00133 stringc value = file->getAttributeValue(L"value");
00134 component->setText(value.c_str());
00135 }
00136
00137
00138 else if(stringw("textColor") == file->getNodeName())
00139 {
00140 component->setColor( SColor( file->getAttributeValueAsInt(L"a"),
00141 file->getAttributeValueAsInt(L"r"),
00142 file->getAttributeValueAsInt(L"g"),
00143 file->getAttributeValueAsInt(L"b") ) );
00144 }
00145
00146
00147 else if(!BillboardComponent::parseBaseXML(file, component))
00148 SceneComponent::parseBaseXML(file, component);
00149
00150 break;
00151
00152 case io::EXN_ELEMENT_END:
00153
00154
00155 if(stringw("TextBillboardComponent") == file->getNodeName())
00156 return true;
00157
00158 break;
00159
00160 default:
00161
00162 break;
00163 }
00164
00165 }
00166
00167
00168 return false;
00169 }
00170
00171