NLS Engine  v0.1
The Next Logical Step in game engine design.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
D3DFont.cpp
Go to the documentation of this file.
00001 
00012 #include "D3DFont.h"
00013 
00014 // System Library Includes
00015 
00016 // Application Library Includes
00017 #include <EngineConfig.h>
00018 
00019 // Local Includes
00020 #include "../../../sharedbase/Entity.h"
00021 #include "../../../sharedbase/MessageRouter.h"
00022 #include "../../../sharedbase/Envelope.h"
00023 #include "../../Types.h"
00024 
00025 // Forward Declarations
00026 
00027 // Typedefs and data structures
00028 
00029 // Constants
00030 
00031 // Class methods
00032 namespace GraphicsCore {
00033 #define SUBSCRIBE_BASIC(msgid, handler)   {std::shared_ptr<Subscriber> handler_sptr(new Subscriber(boost::bind((&handler), this, _1))); this->msgrouter->Subscribe((msgid), handler_sptr);}
00034 #define UNSUBSCRIBE_BASIC(msgid, handler) {std::shared_ptr<Subscriber> handler_sptr(new Subscriber(boost::bind((&handler), this, _1))); this->c->Unsubscribe((msgid), handler_sptr);}
00035 #define SUBSCRIBE_DIRECTED(msgid, handler)   {std::shared_ptr<DirectedSubscriber> handler_sptr(new DirectedSubscriber(boost::bind((&handler), this, _1))); this->msgrouter->SubscribeDirected((msgid), handler_sptr);}
00036 #define UNSUBSCRIBE_DIRECTED(msgid, handler) {std::shared_ptr<DirectedSubscriber> handler_sptr(new DirectedSubscriber(boost::bind((&handler), this, _1))); this->msgrouter->UnsubscribeDirected((msgid), handler_sptr);}
00037 
00038   D3DFont::D3DFont( EntitySPTR entity, ModuleInterface* mod, LPDIRECT3DDEVICE9 device, MessageRouter* msgrtr, unsigned int width /*= 5*/, unsigned int height /*= 12*/, unsigned int weight /*= FW_NORMAL*/, bool italic /*= false*/ ) : RenderableComponent(entity, mod) {
00039     this->msgrouter = msgrtr;
00040     D3DXCreateFont(device, height, width, weight, 1, italic, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,  DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Arial", &this->font);
00041     D3DXCreateSprite(device, &this->sprite);
00042     SUBSCRIBE_BASIC(1101, D3DFont::SetText);
00043     this->text = "";
00044   }
00045 
00046   D3DFont::~D3DFont( void ) {
00047 
00048   }
00049 
00050   void D3DFont::SetDialogRect( unsigned int offX, unsigned int offY, unsigned int width, unsigned int height )
00051   {
00052     this->dialogrect.left = offX;
00053     this->dialogrect.top = offY;
00054     this->dialogrect.right = offX + width;
00055     this->dialogrect.bottom = offY + height;
00056   }
00057 
00058   void D3DFont::SetText( EnvelopeSPTR env ) {
00059     this->text = env->GetDataString(0);
00060   }
00061 
00062   void D3DFont::Render( LPDIRECT3DDEVICE9 dev ) {
00063     if (this->text != "") {
00064       Vector3 pos(this->owner->GetWorldPosition());
00065       
00066       RECT position;
00067       position.left = (long) pos.x + this->dialogrect.left;
00068       position.top = (long) pos.y + this->dialogrect.top;
00069       position.right = (long) pos.x + this->dialogrect.right;
00070       position.bottom = (long) pos.y + this->dialogrect.bottom;
00071 
00072       this->sprite->Begin(D3DXSPRITE_ALPHABLEND);
00073       this->font->DrawTextA(this->sprite, this->text.c_str(), this->text.length(), &position, DT_LEFT|DT_WORDBREAK, 0xFFFFFFFF);
00074       this->sprite->End();
00075     }
00076   }
00077 }