/* Irrlicht Library Wrapper Created by: Nathan Adams Denzel Morris Copyright (C) 2007 This software is licensed under the GNU/GPL. This software may not be used for commerical purposes. */ #include #include #include #include #include #include "IrrLib.h" #include "IrrData.h" #include "IrrLibGUI.h" #include "IrrLibBase.h" #include using namespace irr; using namespace core; using namespace scene; using namespace video; using namespace io; using namespace gui; using namespace std; template std::string to_string( const type & value) { std::ostringstream streamOut; streamOut << value; return streamOut.str(); } IrrLibGUI::IrrLibGUI() { //NA does it need to do anything at init? this->nStaticText = 0; this->nButton = 0; this->nButtonid = 100; this->nListBoxid = 200; this->nListBox = 0; //this->nListBoxid = 300; //this->arrStaticText = new IGUIStaticText[10]; //this->env = this->device->getGUIEnvironment(); //NA yes we do! } IrrLibGUI::~IrrLibGUI() { //NA Do we have to delete anything? } void IrrLibGUI::SetEnv(IGUIEnvironment* env) { this->env = env; //env->addButton(rect(10,210,110,210 + 32), 0, 109, L"Quit", L"Exits Program"); } int IrrLibGUI::addButton(const core::rect< s32 > & rectangle, IGUIElement *parent, s32 id, const wchar_t * text, const wchar_t * tooltiptext) { arrButton.push_back(this->env->addButton(rectangle, parent, id, text, tooltiptext)); ++nButton; ++nButtonid; return nButtonid - 1; } IrrObj IrrLibGUI::addListBox(const irr::core::rect< irr::s32 > &rectangle, IGUIElement * parent) { irr::gui::IGUIListBox* tmp = this->env->addListBox(rectangle, parent, nListBoxid); arrListBox.push_back(tmp); //we introduce a new datatype; IrroObj IrrObj ret; ret.eventid = nListBoxid; ret.objectid = nListBox; ++nListBox; ++nListBoxid; return ret; } IrrObj IrrLibGUI::AddListBox(int x1, int y1, int x2, int y2, IGUIElement * parent) { return addListBox(rect(x1, y1, x2, y2), parent); } IrrObj IrrLibGUI::AddListBox(const irr::core::rect< irr::s32 > &rectangle, IGUIElement * parent) { return addListBox(rectangle, parent); } void IrrLibGUI::AddStringToListBox(int nLbox, std::string text) { this->arrListBox[nLbox]->addItem(stdstring_to_stringw(text).c_str()); //this->arrListBox[0]->addItem(L"TEST"); } std::string IrrLibGUI::getSelectListString(int lstbox) { //stringc tmp = this->arrListBox[lstbox]->getListItem(this->arrListBox[lstbox]->getSelected()); s32 selected = this->arrListBox[lstbox]->getSelected(); //const wchar_t* tmp = this->arrListBox[lstbox]->getListItem(selected); //irr::core::stringw tmp; char out[255]; //tmp = this->arrListBox[lstbox]->getText(); irr::core::stringc tmp(arrListBox[lstbox]->getListItem(arrListBox[lstbox]->getSelected())); //cout << tmp.c_str() << endl; //wcstombs(out, tmp, tmp.length()); //cout << tmp[0] << endl; // std::stringstream ss; //for (int i = 0; i < tmp.size(); ++i) //ss << tmp.c_str(); std::string ret = tmp.c_str(); return ret; } void IrrLibGUI::Clear() { this->env->clear(); } void IrrLibGUI::DrawAll() { this->env->drawAll(); } int IrrLibGUI::AddToStaticArray(irr::gui::IGUIStaticText * addme) { //arrStaticText[nStaticText] = addme; arrStaticText.push_back(addme); this->nStaticText++; this->nButtonid++; return this->nStaticText; } void IrrLibGUI::AddStaticText() { //rect(20,30,300,80), this->env->addStaticText(L"Powered by IrrLib.", rect(20,30,300,80), true); } int IrrLibGUI::AddStaticText(std::string message) { irr::gui::IGUIStaticText * addthis; stringw tmpw(message.c_str()); addthis = this->env->addStaticText(tmpw.c_str(), rect(20,30,300,80), true); return AddToStaticArray(addthis); } int IrrLibGUI::AddStaticText(std::string message, int x1, int y1, int x2, int y2) { irr::gui::IGUIStaticText * addthis; stringw tmpw(message.c_str()); addthis = this->env->addStaticText(tmpw.c_str(), rect(x1,y1,x2,y2), true); return AddToStaticArray(addthis); } int IrrLibGUI::AddStaticText(std::string message, int x1, int y1, int x2, int y2, bool border, bool wordwrap) { irr::gui::IGUIStaticText * addthis; stringw tmpw(message.c_str()); addthis = this->env->addStaticText(tmpw.c_str(), rect(x1,y1,x2,y2), border, wordwrap); return AddToStaticArray(addthis); } int IrrLibGUI::AddStaticText(std::string message, int x1, int y1, int x2, int y2, bool border, bool wordwrap, int id, bool fillbackground) { irr::gui::IGUIStaticText * addthis; stringw tmpw(message.c_str()); addthis = this->env->addStaticText(tmpw.c_str(), rect(x1,y1,x2,y2), border, wordwrap, 0, id, fillbackground); return AddToStaticArray(addthis); } int IrrLibGUI::AddStaticText(std::string message, const core::rect< s32 > &rectangle) { irr::gui::IGUIStaticText * addthis; stringw tmpw(message.c_str()); addthis = this->env->addStaticText(tmpw.c_str(), rectangle); return AddToStaticArray(addthis); } int IrrLibGUI::AddStaticText(std::string message, const core::rect< s32 > &rectangle, bool border, bool wordwrap) { irr::gui::IGUIStaticText * addthis; stringw tmpw(message.c_str()); addthis = this->env->addStaticText(tmpw.c_str(), rectangle, border, wordwrap); return AddToStaticArray(addthis); } int IrrLibGUI::AddStaticText(std::string message, const core::rect< s32 > &rectangle, bool border, bool wordwrap, int id, bool fillbackground) { irr::gui::IGUIStaticText * addthis; stringw tmpw(message.c_str()); addthis = this->env->addStaticText(tmpw.c_str(), rectangle, border, wordwrap, 0, id, fillbackground); return AddToStaticArray(addthis); } void IrrLibGUI::ChangeStaticText(int nstatictext, std::string message) { stringw tmpw(message.c_str()); this->arrStaticText[this->nStaticText-1]->setText(tmpw.c_str()); } void IrrLibGUI::ChangeFont(std::string fontfile) { IGUISkin* skin = this->env->getSkin(); IGUIFont* font = this->env->getFont(fontfile.c_str()); if (font) skin->setFont(font); } int IrrLibGUI::AddButton(std::string text, int x1, int y1, int x2, int y2, std::string tooltiptext = "") { return addButton(rect(x1, y1, x2, y2), 0, nButtonid, stdstring_to_stringw(text).c_str(), stdstring_to_stringw(tooltiptext).c_str()); } int IrrLibGUI::AddButton(std::string text, core::rect & rect, std::string tooltiptext = "") { return addButton(rect, 0, nButtonid, stdstring_to_stringw(text).c_str(), stdstring_to_stringw(tooltiptext).c_str()); }