00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <iostream>
00013 #include <strings.h>
00014 #include <irrlicht.h>
00015 #include <vector>
00016 #include <sstream>
00017
00018 #include "IrrLib.h"
00019 #include "IrrData.h"
00020 #include "IrrLibGUI.h"
00021 #include "IrrLibBase.h"
00022 #include <stdlib.h>
00023
00024 using namespace irr;
00025 using namespace core;
00026 using namespace scene;
00027 using namespace video;
00028 using namespace io;
00029 using namespace gui;
00030
00031 using namespace std;
00032
00033 template<class type> std::string to_string( const type & value)
00034 {
00035 std::ostringstream streamOut;
00036
00037 streamOut << value;
00038
00039 return streamOut.str();
00040 }
00041
00042 IrrLibGUI::IrrLibGUI()
00043 {
00044
00045 this->nStaticText = 0;
00046 this->nButton = 0;
00047 this->nButtonid = 100;
00048 this->nListBoxid = 200;
00049 this->nListBox = 0;
00050
00051
00052
00053 }
00054
00055 IrrLibGUI::~IrrLibGUI()
00056 {
00057
00058 }
00059
00060 void IrrLibGUI::SetEnv(IGUIEnvironment* env)
00061 {
00062 this->env = env;
00063
00064 }
00065
00066 IrrObj IrrLibGUI::addButton(const core::rect< s32 > & rectangle, IGUIElement *parent, s32 id, const wchar_t * text, const wchar_t * tooltiptext)
00067 {
00068 arrButton.push_back(this->env->addButton(rectangle, parent, id, text, tooltiptext));
00069 ++nButton;
00070 ++nButtonid;
00071 IrrObj ret;
00072 ret.objectid = --nButtonid;
00073 return ret;
00074 }
00075
00076 IrrObj IrrLibGUI::addListBox(const irr::core::rect< irr::s32 > &rectangle, IGUIElement * parent)
00077 {
00078 irr::gui::IGUIListBox* tmp = this->env->addListBox(rectangle, parent, nListBoxid);
00079 arrListBox.push_back(tmp);
00080
00081 IrrObj ret;
00082 ret.eventid = nListBoxid;
00083 ret.objectid = nListBox;
00084 ++nListBox;
00085 ++nListBoxid;
00086 return ret;
00087 }
00088
00089 IrrObj IrrLibGUI::AddListBox(int x1, int y1, int x2, int y2, IGUIElement * parent)
00090 {
00091 return addListBox(rect<s32>(x1, y1, x2, y2), parent);
00092 }
00093
00094 IrrObj IrrLibGUI::AddListBox(const irr::core::rect< irr::s32 > &rectangle, IGUIElement * parent)
00095 {
00096 return addListBox(rectangle, parent);
00097 }
00098
00099 void IrrLibGUI::AddStringToListBox(IrrObj nLbox, stringw text)
00100 {
00101 this->arrListBox[nLbox.objectid]->addItem(text.c_str());
00102
00103 }
00104
00105 std::string IrrLibGUI::getSelectListString(IrrObj lstbox)
00106 {
00107
00108 s32 selected = this->arrListBox[lstbox.objectid]->getSelected();
00109
00110
00111 char out[255];
00112
00113 irr::core::stringc tmp(arrListBox[lstbox.objectid]->getListItem(arrListBox[lstbox.objectid]->getSelected()));
00114
00115
00116
00117
00118
00119
00120 std::string ret = tmp.c_str();
00121 return ret;
00122 }
00123
00124 void IrrLibGUI::Clear()
00125 {
00126 this->env->clear();
00127 }
00128
00129 void IrrLibGUI::DrawAll()
00130 {
00131 this->env->drawAll();
00132 }
00133
00134 IrrObj IrrLibGUI::AddToStaticArray(irr::gui::IGUIStaticText * addme)
00135 {
00136
00137 arrStaticText.push_back(addme);
00138 this->nStaticText++;
00139 this->nButtonid++;
00140 IrrObj ret;
00141 ret.objectid = this->nStaticText;
00142 return ret;
00143 }
00144
00145 void IrrLibGUI::AddStaticText()
00146 {
00147
00148 this->env->addStaticText(L"Powered by IrrLib.", rect<s32>(20,30,300,80), true);
00149 }
00150
00151 IrrObj IrrLibGUI::AddStaticText(stringw message)
00152 {
00153 irr::gui::IGUIStaticText * addthis;
00154 addthis = this->env->addStaticText(message.c_str(), rect<s32>(20,30,300,80), true);
00155 return AddToStaticArray(addthis);
00156 }
00157
00158 IrrObj IrrLibGUI::AddStaticText(stringw message, int x1, int y1, int x2, int y2)
00159 {
00160 irr::gui::IGUIStaticText * addthis;
00161 addthis = this->env->addStaticText(message.c_str(), rect<s32>(x1,y1,x2,y2), true);
00162 return AddToStaticArray(addthis);
00163 }
00164
00165 IrrObj IrrLibGUI::AddStaticText(stringw message, int x1, int y1, int x2, int y2, bool border, bool wordwrap)
00166 {
00167 irr::gui::IGUIStaticText * addthis;
00168 addthis = this->env->addStaticText(message.c_str(), rect<s32>(x1,y1,x2,y2), border, wordwrap);
00169 return AddToStaticArray(addthis);
00170 }
00171
00172 IrrObj IrrLibGUI::AddStaticText(stringw message, int x1, int y1, int x2, int y2, bool border, bool wordwrap, int id, bool fillbackground)
00173 {
00174 irr::gui::IGUIStaticText * addthis;
00175 addthis = this->env->addStaticText(message.c_str(), rect<s32>(x1,y1,x2,y2), border, wordwrap, 0, id, fillbackground);
00176 return AddToStaticArray(addthis);
00177 }
00178
00179 IrrObj IrrLibGUI::AddStaticText(stringw message, const core::rect< s32 > &rectangle)
00180 {
00181 irr::gui::IGUIStaticText * addthis;
00182 addthis = this->env->addStaticText(message.c_str(), rectangle);
00183 return AddToStaticArray(addthis);
00184 }
00185
00186 IrrObj IrrLibGUI::AddStaticText(stringw message, const core::rect< s32 > &rectangle, bool border, bool wordwrap)
00187 {
00188 irr::gui::IGUIStaticText * addthis;
00189 addthis = this->env->addStaticText(message.c_str(), rectangle, border, wordwrap);
00190 return AddToStaticArray(addthis);
00191 }
00192
00193 IrrObj IrrLibGUI::AddStaticText(stringw message, const core::rect< s32 > &rectangle, bool border, bool wordwrap, int id, bool fillbackground)
00194 {
00195 irr::gui::IGUIStaticText * addthis;
00196 addthis = this->env->addStaticText(message.c_str(), rectangle, border, wordwrap, 0, id, fillbackground);
00197 return AddToStaticArray(addthis);
00198 }
00199
00200 void IrrLibGUI::ChangeStaticText(IrrObj nstatictext, stringw message)
00201 {
00202
00203 this->arrStaticText[nstatictext.objectid]->setText(message.c_str());
00204 }
00205
00206 void IrrLibGUI::ChangeFont(stringc fontfile)
00207 {
00208 IGUISkin* skin = this->env->getSkin();
00209 IGUIFont* font = this->env->getFont(fontfile.c_str());
00210 if (font)
00211 skin->setFont(font);
00212 }
00213
00214 IrrObj IrrLibGUI::AddButton(stringw text, int x1, int y1, int x2, int y2, stringw tooltiptext = "")
00215 {
00216 return addButton(rect<s32>(x1, y1, x2, y2), 0, nButtonid, text.c_str(), tooltiptext.c_str());
00217 }
00218
00219 IrrObj IrrLibGUI::AddButton(stringw text, core::rect<s32> & rect, stringw tooltiptext = "")
00220 {
00221 return addButton(rect, 0, nButtonid, text.c_str(), tooltiptext.c_str());
00222 }