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