bool RocketUIManager::handleMouseEvent(EventDispatcher* sender, const Event& event) { const MouseEvent& e = static_cast<const MouseEvent&>(event); if(!mRenderSystemWrapper || !mRenderSystemWrapper->getContext(e.dispatcher)) return true; Rocket::Core::Context* ctx = mRenderSystemWrapper->getContext(e.dispatcher); if(e.getType() == MouseEvent::MOUSE_MOVE) { int keyModifierState = getKeyModifierState(); ctx->ProcessMouseMove(e.mouseX, e.mouseY, keyModifierState); if (e.relativeZ != 0) { ctx->ProcessMouseWheel(e.relativeZ / -120, keyModifierState); return !doCapture(ctx); } } else if(e.getType() == MouseEvent::MOUSE_DOWN) { ctx->ProcessMouseButtonDown((int) e.button, getKeyModifierState()); return !doCapture(ctx); } else if(e.getType() == MouseEvent::MOUSE_UP) { ctx->ProcessMouseButtonUp((int) e.button, getKeyModifierState()); } return true; }
int main(int argc, char **argv) { #ifdef ROCKET_PLATFORM_WIN32 DoAllocConsole(); #endif int window_width = 1024; int window_height = 768; sf::RenderWindow MyWindow(sf::VideoMode(window_width, window_height), "libRocket with SFML"); RocketSFMLRenderer Renderer; RocketSFMLSystemInterface SystemInterface; ShellFileInterface FileInterface("../Samples/assets/"); if(!MyWindow.IsOpened()) return 1; Renderer.SetWindow(&MyWindow); Rocket::Core::SetFileInterface(&FileInterface); Rocket::Core::SetRenderInterface(&Renderer); Rocket::Core::SetSystemInterface(&SystemInterface); if(!Rocket::Core::Initialise()) return 1; Rocket::Core::FontDatabase::LoadFontFace("Delicious-Bold.otf"); Rocket::Core::FontDatabase::LoadFontFace("Delicious-BoldItalic.otf"); Rocket::Core::FontDatabase::LoadFontFace("Delicious-Italic.otf"); Rocket::Core::FontDatabase::LoadFontFace("Delicious-Roman.otf"); Rocket::Core::Context *Context = Rocket::Core::CreateContext("default", Rocket::Core::Vector2i(MyWindow.GetWidth(), MyWindow.GetHeight())); Rocket::Debugger::Initialise(Context); Rocket::Core::ElementDocument *Document = Context->LoadDocument("demo.rml"); if(Document) { Document->Show(); Document->RemoveReference(); }; while(MyWindow.IsOpened()) { static sf::Event event; MyWindow.Clear(); Context->Render(); MyWindow.Display(); while(MyWindow.GetEvent(event)) { switch(event.Type) { case sf::Event::Resized: Renderer.Resize(); break; case sf::Event::MouseMoved: Context->ProcessMouseMove(event.MouseMove.X, event.MouseMove.Y, SystemInterface.GetKeyModifiers(&MyWindow)); break; case sf::Event::MouseButtonPressed: Context->ProcessMouseButtonDown(event.MouseButton.Button, SystemInterface.GetKeyModifiers(&MyWindow)); break; case sf::Event::MouseButtonReleased: Context->ProcessMouseButtonUp(event.MouseButton.Button, SystemInterface.GetKeyModifiers(&MyWindow)); break; case sf::Event::MouseWheelMoved: Context->ProcessMouseWheel(event.MouseWheel.Delta, SystemInterface.GetKeyModifiers(&MyWindow)); break; case sf::Event::TextEntered: if (event.Text.Unicode > 32) Context->ProcessTextInput(event.Text.Unicode); break; case sf::Event::KeyPressed: Context->ProcessKeyDown(SystemInterface.TranslateKey(event.Key.Code), SystemInterface.GetKeyModifiers(&MyWindow)); break; case sf::Event::KeyReleased: if(event.Key.Code == sf::Key::F8) { Rocket::Debugger::SetVisible(!Rocket::Debugger::IsVisible()); }; Context->ProcessKeyUp(SystemInterface.TranslateKey(event.Key.Code), SystemInterface.GetKeyModifiers(&MyWindow)); break; case sf::Event::Closed: return 1; break; }; }; Context->Update(); }; return 0; };
int main(int argc, char *argv[]) { Options& options = Options::GetInstance(); options.LoadFromCommandLine(argc, argv); options.LoadFromIniFile("gravity.ini"); GRAVITY_LOG(info, "Client started."); sf::ContextSettings settings; settings.depthBits = 0; settings.stencilBits = 8; settings.antialiasingLevel = options.msaa; int style = options.fullscreen ? sf::Style::Fullscreen : sf::Style::Default; sf::RenderWindow window(sf::VideoMode(options.hres, options.vres, options.bitdepth), "Gravity", style, settings); ::Gravity::Game::Game game; game.Start(); BoundingCamera camera(Vec2f(400, 300), Vec2f()); // ROCKET RocketRendererInterfaceImpl rendererInterface; RocketSystemInterfaceImpl systemInterface; RocketShellInterfaceImpl shellInterface("../data/gui/"); rendererInterface.target = &window; rendererInterface.states = (sf::RenderStates *) &sf::RenderStates::Default; Rocket::Core::SetFileInterface(&shellInterface); Rocket::Core::SetRenderInterface(&rendererInterface); Rocket::Core::SetSystemInterface(&systemInterface); if(!Rocket::Core::Initialise()) return 0; Rocket::Controls::Initialise(); Rocket::Core::FontDatabase::LoadFontFace("Delicious-Bold.otf"); Rocket::Core::FontDatabase::LoadFontFace("Delicious-BoldItalic.otf"); Rocket::Core::FontDatabase::LoadFontFace("Delicious-Italic.otf"); Rocket::Core::FontDatabase::LoadFontFace("Delicious-Roman.otf"); Rocket::Core::FontDatabase::LoadFontFace("DejaVuSans-Bold.ttf"); Rocket::Core::FontDatabase::LoadFontFace("DejaVuSans-BoldOblique.ttf"); Rocket::Core::FontDatabase::LoadFontFace("DejaVuSans-Oblique.ttf"); Rocket::Core::FontDatabase::LoadFontFace("DejaVuSans.ttf"); Rocket::Core::Context *Context = Rocket::Core::CreateContext("default", Rocket::Core::Vector2i(window.getSize().x, window.getSize().y)); Rocket::Debugger::Initialise(Context); //Rocket::Debugger::SetVisible(true); Rocket::Core::ElementDocument *document = Context->LoadDocument("my.rml"); if(document) { document->Show(); document->RemoveReference(); }; // END ROCKET //Rocket::Core::ElementDocument* document; std::cout << "OpenGL Version" << window.getSettings().ContextSettings::majorVersion << "." << window.getSettings().ContextSettings::minorVersion << std::endl; sf::ContextSettings settingz = window.getSettings(); std::cout << settingz.majorVersion << "." << settingz.minorVersion << std::endl; while(window.isOpen()) { sf::Event event; Entity* ship = game.GetWorld().GetEntities()[0]; while (window.pollEvent(event)) { //window.PollEvent(event); if (event.type == sf::Event::Closed) window.close(); if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)) return 0; if ((event.type == sf::Event::MouseWheelMoved)) { options.renderscale += event.mouseWheel.delta*.1f; } if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space)) { Shape* bombShape = Shape::CreateBombShape(); Entity* bomb = new Entity(game.GetWorld(), *bombShape, ship->GetPos() + Vec2f(1, 1)); bomb->SetVel(ship->GetVel()); bomb->SetMass(0.01f); game.GetWorld().AddEntity(*bomb); } switch(event.type) { case sf::Event::Resized: //rendererInterface.Resize(); break; case sf::Event::MouseMoved: Context->ProcessMouseMove(event.mouseMove.x, event.mouseMove.y, systemInterface.GetKeyModifiers(&window)); break; case sf::Event::MouseButtonPressed: Context->ProcessMouseButtonDown(event.mouseButton.button, systemInterface.GetKeyModifiers(&window)); break; case sf::Event::MouseButtonReleased: Context->ProcessMouseButtonUp(event.mouseButton.button, systemInterface.GetKeyModifiers(&window)); break; case sf::Event::MouseWheelMoved: Context->ProcessMouseWheel(event.mouseWheel.delta, systemInterface.GetKeyModifiers(&window)); break; case sf::Event::TextEntered: if (event.text.unicode > 32) Context->ProcessTextInput(event.text.unicode); break; case sf::Event::KeyPressed: Context->ProcessKeyDown(systemInterface.TranslateKey(event.key.code), systemInterface.GetKeyModifiers(&window)); break; case sf::Event::KeyReleased: if(event.key.code == sf::Keyboard::F8) { Rocket::Debugger::SetVisible(!Rocket::Debugger::IsVisible()); }; Context->ProcessKeyUp(systemInterface.TranslateKey(event.key.code), systemInterface.GetKeyModifiers(&window)); break; case sf::Event::Closed: return 1; break; }; } int rotate = sf::Keyboard::isKeyPressed(sf::Keyboard::Right) - sf::Keyboard::isKeyPressed(sf::Keyboard::Left); bool forward = sf::Keyboard::isKeyPressed(sf::Keyboard::Up); sf::View nView(Vec2f(options.hres, options.vres), Vec2f(options.hres, options.vres)); camera.Update(ship->GetPos() * options.renderscale); nView.move(camera.GetPos() - Vec2f(options.hres, options.vres)); ship->Rotate(rotate*2); if (forward) ship->ApplyForce(Vec2f(0.f, 2.f).Rotate(ship->GetAngle())); window.clear(); window.setView(nView); DrawWorld(window, game.GetWorld(), 0.f); sf::View viewEmpty = window.getDefaultView(); window.setView(viewEmpty); Context->Update(); Context->Render(); window.setFramerateLimit(60); window.display(); game.Step(); } game.Stop(); return 0; }