1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
| #include "console.h"
#include <RendererModules/IrrlichtRenderer/irrlichtrenderer.h>
#include <iostream>
#include <vector>
#include <sstream>
#include <windows.h>
console::console(){
idevice = irr::createDevice(irr::video::EDT_OPENGL, irr::core::dimension2d<irr::s32>(800, 600), 32, false, false, false);
driver = idevice->getVideoDriver();
idevice->getCursorControl()->setVisible(false);
running = true;
c = NULL;
CEGUI::IrrlichtRenderer *myRenderer = new CEGUI::IrrlichtRenderer(idevice);
new CEGUI::System(myRenderer);
CEGUI::SchemeManager::getSingleton().loadScheme("./data/gui/schemes/TaharezLook.scheme");
CEGUI::FontManager::getSingleton().createFont("./data/gui/fonts/Commonwealth-10.font");
CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
idevice->setEventReceiver(this);
display();
}
console::~console(){
if (c)
delete c;
}
bool console::OnEvent(irr::SEvent e){
if (!idevice)
return false;
switch (e.EventType){
case irr::EET_MOUSE_INPUT_EVENT:
// inject mouse position
CEGUI::System::getSingleton().injectMousePosition((float)e.MouseInput.X, (float)e.MouseInput.Y);
// inject mouse clic
switch (e.MouseInput.Event){
case irr::EMIE_LMOUSE_PRESSED_DOWN :
CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
break;
case irr::EMIE_LMOUSE_LEFT_UP :
CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
break;
case irr::EMIE_MOUSE_WHEEL :
CEGUI::System::getSingleton().injectMouseWheelChange(e.MouseInput.Wheel);
break;
default:
break;
}
return true;
case irr::EET_KEY_INPUT_EVENT:
if (e.KeyInput.PressedDown){
// inject all the special keys
switch(e.KeyInput.Key){
case irr::KEY_RETURN: CEGUI::System::getSingleton().injectKeyDown(CEGUI::Key::Return); break;
case irr::KEY_BACK: CEGUI::System::getSingleton().injectKeyDown(CEGUI::Key::Backspace); break;
case irr::KEY_TAB: CEGUI::System::getSingleton().injectKeyDown(CEGUI::Key::Tab); break;
default:
CEGUI::System::getSingleton().injectChar(e.KeyInput.Char);
break;
}
}
break;
default:
return false;
}
return false;
}
void console::display(){
CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton ();
winMgr.destroyAllWindows();
CEGUI::Window* background = winMgr.createWindow("TaharezLook/StaticImage");
background->setProperty ("Image", "set:BackgroundImage image:full_image");
background->setProperty ("FrameEnabled", "false");
background->setProperty ("BackgroundEnabled", "false");
background->addChildWindow (winMgr.loadWindowLayout ("./data/gui/layouts/screen.layout", "root/"));
CEGUI::WindowManager::getSingleton().getWindow("root/b_ok")->
subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&console::handle_ok, this));
CEGUI::System::getSingleton ().setGUISheet (background);
}
void console::process(){
CEGUI::Editbox *eb = static_cast<CEGUI::Editbox*>(CEGUI::WindowManager::getSingleton().getWindow("root/input"));
std::string str = std::string(eb->getText().c_str());
eb->setText("");
add_msg_output(std::string(">>")+str);
if (str == "")
return;
// check if "quit"
if (str == "quit"){
running = false;
return;
}
// let's explode the string
std::istringstream iss(str);
std::vector<std::string> command_line;
std::string temp;
while (std::getline(iss, temp, ' ')){
command_line.push_back(temp);
}
// check if "connect"
if (command_line[0] == "connect"){
if (command_line.size() < 5){
std::string msg = "Too few arguments : connect [host] [port] [login] [pass]";
add_msg_output(msg);
return;
}else{
// extract the port number
std::istringstream s(command_line[2]);
int port;
s >> port;
if (c)
delete c;
try{
c = new connection(this, command_line[1], port, command_line[3], command_line[4]);
}catch(std::string& e){
if (e == "delete me")
if (c){delete c; c = NULL;}
}catch(std::exception &e){
add_msg_output(std::string(e.what()));
if (c){delete c; c = NULL;}
}catch(...){
add_msg_output(std::string("Erreur"));
if (c){delete c; c = NULL;}
}
}
return;
}
// else, send to the server
if (c)
std::string out = c->send(str);
else
add_msg_output(std::string("connect first"));
}
void console::run(){
asio::deadline_timer timer(io, boost::posix_time::seconds(0));
while (running && driver && idevice->run()){
driver->beginScene(true, true, irr::video::SColor(0,100,100,100));
CEGUI::System::getSingleton().renderGUI();
driver->endScene();
timer.expires_at(timer.expires_at() + boost::posix_time::millisec(10));
timer.wait();
}
}
void console::add_msg_output(std::string& s){
CEGUI::MultiColumnList *m = static_cast<CEGUI::MultiColumnList*>(CEGUI::WindowManager::getSingleton().getWindow("root/output"));
CEGUI::String current = m->getText();
current.append(s);
current.append("\n");
m->setText(current);
} |
Partager