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
00027 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00028 IGUIEnvironment *pGUIEnv = GameManager::Instance()->getGUIEnvironment();
00029
00030
00031 mBillboardTextSN = pSceneMgr->addBillboardTextSceneNode(pGUIEnv->getBuiltInFont(), 0, 0,
00032 dimension2df(10.0f, 10.0f),
00033 parent->getPosition(), parent->getID());
00034 mBillboardSN = mBillboardTextSN;
00035 mSceneNode = mBillboardTextSN;
00036
00037
00038 mTriSelector = pSceneMgr->createTriangleSelectorFromBoundingBox(mBillboardTextSN);
00039 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00040 }
00041
00042
00043 TextBillboardComponent::TextBillboardComponent(Entity *parent, const std::string &fontFileName,
00044 const wchar_t *text, const dimension2df &size,
00045 const SColor &colorTop, const SColor &colorBottom)
00046 : BillboardComponent(parent, true)
00047 {
00048
00049 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00050 IGUIEnvironment *pGUIEnv = GameManager::Instance()->getGUIEnvironment();
00051
00052
00053 mBillboardTextSN = pSceneMgr->addBillboardTextSceneNode(pGUIEnv->getFont(fontFileName.c_str()),
00054 text, 0, size, parent->getPosition(),
00055 parent->getID(), colorTop, colorBottom);
00056 mBillboardSN = mBillboardTextSN;
00057 mSceneNode = mBillboardTextSN;
00058
00059
00060 mTriSelector = pSceneMgr->createTriangleSelectorFromBoundingBox(mBillboardTextSN);
00061 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00062 }
00063
00064
00065 TextBillboardComponent::TextBillboardComponent(Entity *parent, const std::string &fontFileName,
00066 const std::string &text, const dimension2df &size,
00067 const SColor &colorTop, const SColor &colorBottom)
00068 : BillboardComponent(parent, true)
00069 {
00070
00071 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00072 IGUIEnvironment *pGUIEnv = GameManager::Instance()->getGUIEnvironment();
00073
00074
00075 core::stringw wBuffer = core::stringw(text.c_str());
00076 mBillboardTextSN = pSceneMgr->addBillboardTextSceneNode(pGUIEnv->getFont(fontFileName.c_str()),
00077 wBuffer.c_str(), 0, size,
00078 parent->getPosition(), parent->getID(),
00079 colorTop, colorBottom);
00080 mBillboardSN = mBillboardTextSN;
00081 mSceneNode = mBillboardTextSN;
00082
00083
00084 mTriSelector = pSceneMgr->createTriangleSelectorFromBoundingBox(mBillboardTextSN);
00085 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00086 }
00087
00088
00089 TextBillboardComponent::~TextBillboardComponent()
00090 {
00091 mBillboardTextSN->remove();
00092 mBillboardSN = NULL;
00093 mSceneNode = NULL;
00094 }
00095
00096
00097 TextBillboardComponent* TextBillboardComponent::refFactory(Entity *parent)
00098 {
00099 return new TextBillboardComponent(parent);
00100 }
00101
00102
00103 TextBillboardComponent* TextBillboardComponent::refFactory(Entity *parent,
00104 const std::string &fontFileName,
00105 const std::string &text,
00106 const dimension2df &size,
00107 const SColor &colorTop,
00108 const SColor &colorBottom)
00109 {
00110 return new TextBillboardComponent(parent, fontFileName, text, size, colorTop, colorBottom);
00111 }
00112
00113
00114 IBillboardTextSceneNode* TextBillboardComponent::getBillboardTextSceneNode()
00115 {
00116 return mBillboardTextSN;
00117 }
00118
00119
00120 void TextBillboardComponent::setText(const std::string &text)
00121 {
00122 core::stringw wBuffer = core::stringw(text.c_str());
00123 mBillboardTextSN->setText(wBuffer.c_str());
00124 }
00125
00126
00127 void TextBillboardComponent::setText(const wchar_t *text)
00128 {
00129 mBillboardTextSN->setText(text);
00130 }
00131
00132
00133 void TextBillboardComponent::setTextColor(const SColor &color)
00134 {
00135 mBillboardTextSN->setTextColor(color);
00136 }
00137
00138
00139
00140 void bindTextBillboardComponent(asIScriptEngine *engine)
00141 {
00142
00143 int r;
00144
00145
00146 r = engine->RegisterObjectType("TextBillboardComponent", sizeof(TextBillboardComponent), asOBJ_REF); assert(r >= 0);
00147
00148
00149 bindBillboardComponentBase<TextBillboardComponent>(engine, "TextBillboardComponent");
00150
00151
00152 r = engine->RegisterObjectBehaviour("TextBillboardComponent", asBEHAVE_FACTORY, "TextBillboardComponent@ f(Entity @)",
00153 asFUNCTIONPR(TextBillboardComponent::refFactory, (Entity*), TextBillboardComponent*),
00154 asCALL_CDECL); assert(r >= 0);
00155 r = engine->RegisterObjectBehaviour("TextBillboardComponent", asBEHAVE_FACTORY, "TextBillboardComponent@ f(Entity @, " \
00156 "const string &, const string &, const dimension2df &in, const SColor &in, " \
00157 "const SColor &in)", asFUNCTIONPR(TextBillboardComponent::refFactory,
00158 (Entity*, const std::string&, const std::string&, const dimension2df&,
00159 const SColor&, const SColor&), TextBillboardComponent*),
00160 asCALL_CDECL); assert(r >= 0);
00161
00162
00163 r = engine->RegisterObjectMethod("TextBillboardComponent", "void setText(const string &)",
00164 asMETHODPR(TextBillboardComponent, setText, (const std::string&), void),
00165 asCALL_THISCALL); assert(r >= 0);
00166 r = engine->RegisterObjectMethod("TextBillboardComponent", "void setTextColor(const SColor &in)",
00167 asMETHOD(TextBillboardComponent, setTextColor), asCALL_THISCALL); assert(r >= 0);
00168 }
00169
00170