/* Irrlicht Library Wrapper Created by: Nathan Adams Copyright (C) 2008 This software is licensed under the GNU/GPL. This software may not be used for commerical purposes. */ #include //#include "IrrLib.h" //#include "IrrSphere.h" //You probably aren't going to be using 3D objects in a 2D environment! #include #include #include "Irr2D.h" #include "IrrSprite.h" #include "IrrText.h" //#include "IrrLibBase.h" //#include "IrrData.h" using namespace irr; using namespace core; using namespace scene; using namespace video; using namespace io; using namespace gui; using namespace std; void Irr2D::LoadText() { text.push_back(this->driver->getTexture("0.png")); text.push_back(this->driver->getTexture("1.png")); text.push_back(this->driver->getTexture("2.png")); } Irr2D::Irr2D(){ this->numTextures = 0; this->numLines = 0; this->nImages = 0; //NA Should we set textures to new } Irr2D::~Irr2D(){ //delete Irr2DObjret; /*for(int i = 0; i < numTextures; ++i) delete this->textures[i]; delete this->textures;*/ //No more dynamic memory business yay! NA //All handled by vectors! } /*void Irr2D::SetSmgr(irr::scene::ISceneManager* smgr){ this->smgr = smgr; Sprite.SetSmgr(smgr); } void Irr2D::SetDriver(irr::video::IVideoDriver* driver){ this->driver = driver; Sprite.SetDriver(driver); }*/ Irr2DObj Irr2D::LoadTexturemap(stringc file){ this->texturemap = this->driver->getTexture(file.c_str()); } Irr2DObj Irr2D::LoadTexture(stringc file){ //this->textures[this->numTextures] = driver->getTexture(file.c_str()); textures.push_back(driver->getTexture(file.c_str())); this->numTextures++; Irr2DObj ret; ret->eventid = 0; ret->objectid = numTextures--; return ret; } void Irr2D::DrawLine(IrrPos& start, IrrPos& end, irr::video::SColor color) { this->driver->draw2DLine(start, end, color); } void Irr2D::AddLines(IrrPos& start, IrrPos& end, irr::video::SColor color) { this->start.push_back(start); this->end.push_back(end); this->color.push_back(color); this->numLines++; } void Irr2D::DrawLines() { for(int i = 0; i < numLines; ++i) this->driver->draw2DLine(this->start[i], this->end[i], this->color[i]); } void Irr2D::LoadIrrImage(Irr2DObj& in, irr::core::stringc file) { images.push_back(this->driver->getTexture(file.c_str())); //cout << "Irr2DObjret->objectid = " << (*Irr2DObjret)->objectid << endl; in->objectid = nImages; this->driver->makeColorKeyTexture(images[nImages], core::position2d(0,0)); dimension2d tmp; tmp = images[nImages]->getSize(); //cout << tmp.Height << ": " << nImages << endl; in->setHeight(tmp.Height); in->setLength(tmp.Width); //in-> in->eventid = 0; this->nImages++; //return (*Irr2DObjret); } void Irr2D::DrawImage(Irr2DObj& img) { //irr::core::position2d destPos(img->x, img->y); irr::core::position2d destPos(img->getX(), img->getY()); irr::core::rect sourcePos(0, 0, img->getHeight(), img->getLength()); //this->driver->draw2DImage(images[img->objectid], destPos); this->driver->draw2DImage(images[img->objectid], destPos); //this->driver->draw2DImage(images[img->objectid], destPos, sourcePos, SColor(255, 255, 255, 255), true); } void Irr2D::Draw2DObj(irr::core::stringc file) { //NewtonObj tmp; //tmp.irr_node = smgr->addMeshSceneNode(smgr->getMesh(file.c_str())->getMesh(0)); //IMeshSceneNode* temp; objects.push_back(smgr->addMeshSceneNode(smgr->getMesh(file.c_str())->getMesh(0))); //objects.push_back(smgr->addMeshSceneNode(smgr->getMesh(file.c_str())->getMesh(0))); objects[0]->setPosition(vector3df(-5,0,0)); objects[0]->getMaterial(0).EmissiveColor.set(255,0,255,5); } void Irr2D::DrawText(IrrText& txt) { //txt.resetCounter(); int offsetx = 0; char nc; for (int i = 0; i < txt.size(); ++i){ irr::core::position2d destPos(txt.getX()+offsetx, txt.getY()); offsetx += 18; nc = txt.getChar(i); switch (nc) { case '0': #ifdef IRRDEBUG cout << "0" << endl; #endif this->driver->draw2DImage(this->text[0], destPos); break; case '1': #ifdef IRRDEBUG cout << "1" << endl; #endif this->driver->draw2DImage(this->text[1], destPos); break; case '2': #ifdef IRRDEBUG cout << "2" << endl; #endif this->driver->draw2DImage(this->text[2], destPos); break; case '3': #ifdef IRRDEBUG cout << "3" << endl; #endif break; case '4': #ifdef IRRDEBUG cout << "4" << endl; #endif break; case '5': #ifdef IRRDEBUG cout << "5" << endl; #endif break; case '6': #ifdef IRRDEBUG cout << "6" << endl; #endif break; case '8': #ifdef IRRDEBUG cout << "7" << endl; #endif break; case '9': #ifdef IRRDEBUG cout << "8" << endl; #endif break; default: cout << "Unrecongized Character!" << endl; break; } } }