Aller à la documentation de ce fichier.00001 #include <CEGUI/RendererModules/OpenGL/CEGUIOpenGLRenderer.h>
00002 #include <CEGUI/CEGUIDefaultResourceProvider.h>
00003 #include <CEGUI/CEGUIImageset.h>
00004 #include <CEGUI/CEGUIFont.h>
00005 #include <CEGUI/CEGUIScheme.h>
00006 #include <CEGUI/falagard/CEGUIFalWidgetLookManager.h>
00007 #include <CEGUI/CEGUIWindowManager.h>
00008 #include <CEGUI/CEGUIScriptModule.h>
00009 #include <CEGUI/CEGUIXMLParser.h>
00010 #include <CEGUI/CEGUISchemeManager.h>
00011 #include <CEGUI/CEGUIFontManager.h>
00012 #include <CEGUI/CEGUIImagesetManager.h>
00013 #include <CEGUI/ScriptingModules/LuaScriptModule/CEGUILua.h>
00014 #include <CEGUI/ScriptingModules/LuaScriptModule/support/tolua++/tolua++.h>
00015 #include "edt/LuaInterface.hpp"
00016 #include <CEGUI/CEGUIEvent.h>
00017 #include <CEGUI/CEGUIEventArgs.h>
00018 #include <CEGUI/CEGUISubscriberSlot.h>
00019
00020
00021
00022 #include <iostream>
00023 #include "edt/GUI.hpp"
00024 #include <edt/SFML.hpp>
00025 #include <edt/Editeur.hpp>
00026
00027
00028 namespace edt {
00029
00030 GUI::GUI() {
00031 initialiserCastEvent();
00032 }
00033
00034 GUI::~GUI() {
00035
00036 }
00037
00038 void GUI::init() {
00039 CEGUI::OpenGLRenderer& myRenderer = CEGUI::OpenGLRenderer::create();
00040
00041 cSys = &CEGUI::System::create( myRenderer );
00042
00043 initialiserRessources();
00044 chargerRessources();
00045
00046
00047 cSys->setDefaultFont("DejaVuSans-10");
00048
00049 cSys->setDefaultMouseCursor( "TaharezLook", "MouseArrow" );
00050
00051 cSys->setDefaultTooltip( "TaharezLook/Tooltip" );
00052
00053
00054 cSys->executeScriptFile("gui_editeur.lua","lua_scripts");
00055
00056 CEGUI::Window* myRoot = CEGUI::WindowManager::getSingleton().loadWindowLayout( "Editeur.layout" );
00057 cSys->setGUISheet( myRoot );
00058
00059 cSys->executeScriptFile("gui_init_editeur.lua","lua_scripts");
00060 }
00061
00062 void GUI::dessiner() const
00063 {
00064 CEGUI::System::getSingleton().renderGUI();
00065 }
00066
00067 void GUI::initialiserRessources() {
00068
00069 CEGUI::DefaultResourceProvider* rp = static_cast<CEGUI::DefaultResourceProvider*>
00070 (CEGUI::System::getSingleton().getResourceProvider());
00071
00072 rp->setResourceGroupDirectory("schemes", "data/gui/schemes/");
00073 rp->setResourceGroupDirectory("imagesets", "data/gui/imagesets/");
00074 rp->setResourceGroupDirectory("fonts", "data/gui/fonts/");
00075 rp->setResourceGroupDirectory("layouts", "data/gui/layouts/");
00076 rp->setResourceGroupDirectory("looknfeels", "data/gui/looknfeel/");
00077 rp->setResourceGroupDirectory("lua_scripts", "data/gui/lua_scripts/");
00078
00079
00080 CEGUI::Imageset::setDefaultResourceGroup("imagesets");
00081 CEGUI::Font::setDefaultResourceGroup("fonts");
00082 CEGUI::Scheme::setDefaultResourceGroup("schemes");
00083 CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
00084 CEGUI::WindowManager::setDefaultResourceGroup("layouts");
00085 CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");
00086
00087
00088 CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();
00089 if (parser->isPropertyPresent("SchemaDefaultResourceGroup"))
00090 parser->setProperty("SchemaDefaultResourceGroup", "schemas");
00091 }
00092
00093 void GUI::chargerRessources() {
00094
00095 CEGUI::FontManager::getSingleton().create("DejaVuSans-10.font");
00096 CEGUI::SchemeManager::getSingleton().create( "TaharezLook.scheme" );
00097 CEGUI::ImagesetManager::getSingleton().create("TaharezLook.imageset");
00098
00099 CEGUI::ImagesetManager::getSingleton().create("Vanilla.imageset");
00100 CEGUI::SchemeManager::getSingleton().create( "VanillaSkin.scheme" );
00101
00102
00103 CEGUI::LuaScriptModule* lsm = &CEGUI::LuaScriptModule::create();
00104 cSys->setScriptingModule(lsm);
00105 tolua_LuaInterface_open(lsm->getLuaState());
00106 }
00107
00108 void GUI::tocHorloge() {
00109 cSys->injectTimePulse((float)(horloge.GetElapsedTime()/1000.));
00110 horloge.Reset();
00111 }
00112
00113 bool GUI::captureEvent(const sf::Event& Event)
00114 {
00115 switch (Event.Type)
00116 {
00117 case sf::Event::MouseLeft :
00118 return cSys->injectMouseLeaves();
00119 case sf::Event::TextEntered:
00120 return cSys->injectChar(Event.Text.Unicode);
00121 case sf::Event::KeyPressed:
00122 return cSys->injectKeyDown(toCEGUIKey(Event.Key.Code));
00123 case sf::Event::KeyReleased:
00124 return cSys->injectKeyUp(toCEGUIKey(Event.Key.Code));
00125 case sf::Event::MouseMoved:
00126 return cSys->injectMousePosition(static_cast<float>(Event.MouseMove.X), static_cast<float>(Event.MouseMove.Y));
00127 case sf::Event::MouseButtonPressed:
00128 return cSys->injectMouseButtonDown(toCEGUIMouseButton(Event.MouseButton.Button));
00129 case sf::Event::MouseButtonReleased:
00130 return cSys->injectMouseButtonUp(toCEGUIMouseButton(Event.MouseButton.Button));
00131 case sf::Event::MouseWheelMoved:
00132 return cSys->injectMouseWheelChange(static_cast<float>(Event.MouseWheel.Delta));
00133
00134 default :
00135 return false;
00136 }
00137 }
00138
00139
00140 CEGUI::Key::Scan GUI::toCEGUIKey(const sf::Keyboard::Key& Code) const
00141 {
00142 if (keys.find(Code) == keys.end())
00143 return (CEGUI::Key::Scan)0;
00144
00145 return keys.at(Code);
00146 }
00147
00148 CEGUI::MouseButton GUI::toCEGUIMouseButton(const sf::Mouse::Button& Button) const
00149 {
00150 if (mouses.find(Button) == mouses.end())
00151 return (CEGUI::MouseButton)0;
00152
00153 return mouses.at(Button);
00154 }
00155
00156 void GUI::initialiserCastEvent()
00157 {
00158
00159 keys[sf::Keyboard::Escape] = CEGUI::Key::Escape ;
00160 keys[sf::Keyboard::Num1] = CEGUI::Key::One ;
00161 keys[sf::Keyboard::Num2] = CEGUI::Key::Two ;
00162 keys[sf::Keyboard::Num3] = CEGUI::Key::Three ;
00163 keys[sf::Keyboard::Num4] = CEGUI::Key::Four ;
00164 keys[sf::Keyboard::Num5] = CEGUI::Key::Five ;
00165 keys[sf::Keyboard::Num6] = CEGUI::Key::Six ;
00166 keys[sf::Keyboard::Num7] = CEGUI::Key::Seven ;
00167 keys[sf::Keyboard::Num8] = CEGUI::Key::Eight ;
00168 keys[sf::Keyboard::Num9] = CEGUI::Key::Nine ;
00169 keys[sf::Keyboard::Num0] = CEGUI::Key::Zero ;
00170 keys[sf::Keyboard::Dash] = CEGUI::Key::Minus ;
00171 keys[sf::Keyboard::Equal] = CEGUI::Key::Equals ;
00172 keys[sf::Keyboard::Back] = CEGUI::Key::Backspace ;
00173 keys[sf::Keyboard::Tab] = CEGUI::Key::Tab ;
00174 keys[sf::Keyboard::Q] = CEGUI::Key::Q ;
00175 keys[sf::Keyboard::W] = CEGUI::Key::W ;
00176 keys[sf::Keyboard::E] = CEGUI::Key::E ;
00177 keys[sf::Keyboard::R] = CEGUI::Key::R ;
00178 keys[sf::Keyboard::T] = CEGUI::Key::T ;
00179 keys[sf::Keyboard::Y] = CEGUI::Key::Y ;
00180 keys[sf::Keyboard::U] = CEGUI::Key::U ;
00181 keys[sf::Keyboard::I] = CEGUI::Key::I ;
00182 keys[sf::Keyboard::O] = CEGUI::Key::O ;
00183 keys[sf::Keyboard::P] = CEGUI::Key::P ;
00184 keys[sf::Keyboard::LBracket] = CEGUI::Key::LeftBracket ;
00185 keys[sf::Keyboard::RBracket] = CEGUI::Key::RightBracket ;
00186 keys[sf::Keyboard::Return] = CEGUI::Key::Return ;
00187 keys[sf::Keyboard::LControl] = CEGUI::Key::LeftControl ;
00188 keys[sf::Keyboard::A] = CEGUI::Key::A ;
00189 keys[sf::Keyboard::S] = CEGUI::Key::S ;
00190 keys[sf::Keyboard::D] = CEGUI::Key::D ;
00191 keys[sf::Keyboard::F] = CEGUI::Key::F ;
00192 keys[sf::Keyboard::G] = CEGUI::Key::G ;
00193 keys[sf::Keyboard::H] = CEGUI::Key::H ;
00194 keys[sf::Keyboard::J] = CEGUI::Key::J ;
00195 keys[sf::Keyboard::K] = CEGUI::Key::K ;
00196 keys[sf::Keyboard::L] = CEGUI::Key::L ;
00197 keys[sf::Keyboard::SemiColon] = CEGUI::Key::Semicolon ;
00198 keys[sf::Keyboard::LShift] = CEGUI::Key::LeftShift ;
00199 keys[sf::Keyboard::BackSlash] = CEGUI::Key::Backslash ;
00200 keys[sf::Keyboard::Z] = CEGUI::Key::Z ;
00201 keys[sf::Keyboard::X] = CEGUI::Key::X ;
00202 keys[sf::Keyboard::C] = CEGUI::Key::C ;
00203 keys[sf::Keyboard::V] = CEGUI::Key::V ;
00204 keys[sf::Keyboard::B] = CEGUI::Key::B ;
00205 keys[sf::Keyboard::N] = CEGUI::Key::N ;
00206 keys[sf::Keyboard::M] = CEGUI::Key::M ;
00207 keys[sf::Keyboard::Comma] = CEGUI::Key::Comma ;
00208 keys[sf::Keyboard::Period] = CEGUI::Key::Period ;
00209 keys[sf::Keyboard::Slash] = CEGUI::Key::Slash ;
00210 keys[sf::Keyboard::RShift] = CEGUI::Key::RightShift ;
00211 keys[sf::Keyboard::Multiply] = CEGUI::Key::Multiply ;
00212 keys[sf::Keyboard::LAlt] = CEGUI::Key::LeftAlt ;
00213 keys[sf::Keyboard::Space] = CEGUI::Key::Space ;
00214 keys[sf::Keyboard::F1] = CEGUI::Key::F1 ;
00215 keys[sf::Keyboard::F2] = CEGUI::Key::F2 ;
00216 keys[sf::Keyboard::F3] = CEGUI::Key::F3 ;
00217 keys[sf::Keyboard::F4] = CEGUI::Key::F4 ;
00218 keys[sf::Keyboard::F5] = CEGUI::Key::F5 ;
00219 keys[sf::Keyboard::F6] = CEGUI::Key::F6 ;
00220 keys[sf::Keyboard::F7] = CEGUI::Key::F7 ;
00221 keys[sf::Keyboard::F8] = CEGUI::Key::F8 ;
00222 keys[sf::Keyboard::F9] = CEGUI::Key::F9 ;
00223 keys[sf::Keyboard::F10] = CEGUI::Key::F10 ;
00224 keys[sf::Keyboard::Numpad7] = CEGUI::Key::Numpad7 ;
00225 keys[sf::Keyboard::Numpad8] = CEGUI::Key::Numpad8 ;
00226 keys[sf::Keyboard::Numpad9] = CEGUI::Key::Numpad9 ;
00227 keys[sf::Keyboard::Subtract] = CEGUI::Key::Subtract ;
00228 keys[sf::Keyboard::Numpad4] = CEGUI::Key::Numpad4 ;
00229 keys[sf::Keyboard::Numpad5] = CEGUI::Key::Numpad5 ;
00230 keys[sf::Keyboard::Numpad6] = CEGUI::Key::Numpad6 ;
00231 keys[sf::Keyboard::Add] = CEGUI::Key::Add ;
00232 keys[sf::Keyboard::Numpad1] = CEGUI::Key::Numpad1 ;
00233 keys[sf::Keyboard::Numpad2] = CEGUI::Key::Numpad2 ;
00234 keys[sf::Keyboard::Numpad3] = CEGUI::Key::Numpad3 ;
00235 keys[sf::Keyboard::Numpad0] = CEGUI::Key::Numpad0 ;
00236 keys[sf::Keyboard::F11] = CEGUI::Key::F11 ;
00237 keys[sf::Keyboard::F12] = CEGUI::Key::F12 ;
00238 keys[sf::Keyboard::F13] = CEGUI::Key::F13 ;
00239 keys[sf::Keyboard::F14] = CEGUI::Key::F14 ;
00240 keys[sf::Keyboard::F15] = CEGUI::Key::F15 ;
00241 keys[sf::Keyboard::RControl] = CEGUI::Key::RightControl ;
00242 keys[sf::Keyboard::Divide] = CEGUI::Key::Divide ;
00243 keys[sf::Keyboard::RAlt] = CEGUI::Key::RightAlt ;
00244 keys[sf::Keyboard::Pause] = CEGUI::Key::Pause ;
00245 keys[sf::Keyboard::Home] = CEGUI::Key::Home ;
00246 keys[sf::Keyboard::Up] = CEGUI::Key::ArrowUp ;
00247 keys[sf::Keyboard::PageUp] = CEGUI::Key::PageUp ;
00248 keys[sf::Keyboard::Left] = CEGUI::Key::ArrowLeft ;
00249 keys[sf::Keyboard::Right] = CEGUI::Key::ArrowRight ;
00250 keys[sf::Keyboard::End] = CEGUI::Key::End ;
00251 keys[sf::Keyboard::Down] = CEGUI::Key::ArrowDown ;
00252 keys[sf::Keyboard::PageDown] = CEGUI::Key::PageDown ;
00253 keys[sf::Keyboard::Insert] = CEGUI::Key::Insert ;
00254 keys[sf::Keyboard::Delete] = CEGUI::Key::Delete ;
00255
00256 mouses[sf::Mouse::Left] = CEGUI::LeftButton;
00257 mouses[sf::Mouse::Middle] = CEGUI::MiddleButton;
00258 mouses[sf::Mouse::Right] = CEGUI::RightButton;
00259 mouses[sf::Mouse::XButton1] = CEGUI::X1Button;
00260 mouses[sf::Mouse::XButton2] = CEGUI::X2Button;
00261 }
00262
00263 }