#include "Irr2D.h" using namespace irr; using namespace core; using namespace video; using namespace std; using namespace gui; void Irr2D::addLine(position2d start, position2d end, 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->device->getVideoDriver()->draw2DLine(this->start[i], this->end[i], this->color[i]); } void Irr2D::clearLines() { this->numLines = 0; this->start.clear(); this->end.clear(); this->color.clear(); } void Irr2D::addTexture(stringw path, Irr2DObj &obj) { texture.push_back(this->device->getVideoDriver()->getTexture(path.c_str())); obj.setObjectID(numTextures); this->numTextures++; } void Irr2D::loadText(stringw textMapPath, stringw listofChars,u32 numColumns) { this->textmap = this->device->getVideoDriver()->getTexture(textMapPath.c_str()); this->strText = listofChars; dimension2d dim; dim = this->textmap->getSize(); u32 numRows = listofChars.size() / numColumns; s32 width = dim.Width / numColumns; s32 height = dim.Height / numRows; //core::rect rect(0,0,width, height); for(unsigned int i = 0; i < numRows; i++) { for (unsigned int x = 0; x < numColumns; x++) { this->text.push_back(rect(x*width, i*height, (x*width)+width, (i*height)+height)); } } } void Irr2D::drawText(stringw str, position2d pos) { s32 pos2; for(unsigned int i = 0; i < str.size(); i++) { pos2 = this->strText.find(str.subString(i, 1).c_str()); this->device->getVideoDriver()->draw2DImage(this->textmap, pos, text[pos2]); } } IrrlichtDevice* Irr2D::getDevice() { return this->device; } void Irr2D::setDevice(IrrlichtDevice*& device) { this->device = device; } void Irr2D::drawTexture(Irr2DObj & obj) { position2d pos; vector2d pos2 = obj.getPosition(); pos.X = (s32)pos2.X; pos.Y = (s32)pos2.Y; this->device->getVideoDriver()->draw2DImage(this->texture[obj.getObjectID()], pos); } int Irr2D::makeFont() { IGUIFont* font = this->device->getGUIEnvironment()->getBuiltInFont(); this->fonts.push_back(font); //this->numFonts++; return this->numFonts++; } int Irr2D::makeFont(irr::core::stringc file) { IGUIFont* font = device->getGUIEnvironment()->getFont(file.c_str()); this->fonts.push_back(font); return this->numFonts++; } void Irr2D::drawFont(int fontID, irr::core::stringw text, irr::core::rect pos, irr::video::SColor color) { this->fonts[fontID]->draw(text.c_str(), pos, color); }