Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
0
void HelloWorld::Start()
{
    helloScene_ = new Scene(context_);
    CreateObjects();
    CreateText();
    SubscribeToEvents();
    
    
    //Rocket stuff
    Rocket::Core::SetRenderInterface(&rocketRenderer);
    Rocket::Core::SetSystemInterface(&rocketSystemInterface);
    
    Rocket::Core::Initialise();
    int w = GetSubsystem<Graphics>()->GetWidth();
    int h = GetSubsystem<Graphics>()->GetHeight();
    rocketContext = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(w, h));
    if(rocketContext == NULL)
    {
        Rocket::Core::Shutdown();
        throw "Dead in the water";
    }
    
    Rocket::Core::FontDatabase::LoadFontFace("Data/Fonts/Delicious-Bold.otf");
    Rocket::Core::FontDatabase::LoadFontFace("Data/Fonts/Delicious-BoldItalic.otf");
    Rocket::Core::FontDatabase::LoadFontFace("Data/Fonts/Delicious-Italic.otf");
    Rocket::Core::FontDatabase::LoadFontFace("Data/Fonts/Delicious-Roman.otf");
    
    Rocket::Core::ElementDocument *Document = rocketContext->LoadDocument("Data/UI/rocketDemo.html");
    
    if(Document)
    {
        Document->Show();
        Document->RemoveReference();
    };
}
Ejemplo n.º 3
0
void HelloWorld::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
    //float timeStep = eventData[Update::P_TIMESTEP].GetFloat();        
    rocketContext->Update();
    
    if (GetSubsystem<Input>()->GetKeyDown(KEY_ESC))
        GetSubsystem<Engine>()->Exit();
}
void GuiDemo::initRocket()
{
	GK_ASSERT(m_scene && !m_rkContext);

	gkWindow* window = m_scene->getDisplayWindow();
	// Rocket initialisation.
	m_rkOgreRenderer = new RenderInterfaceOgre3D(window->getWidth(), window->getHeight());
	Rocket::Core::SetRenderInterface(m_rkOgreRenderer);

	m_rkOgreSystem = new SystemInterfaceOgre3D();
	Rocket::Core::SetSystemInterface(m_rkOgreSystem);

	Rocket::Core::Initialise();
	Rocket::Controls::Initialise();


	installRocketFonts();

	m_rkContext = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(window->getWidth(), window->getHeight()));
	Rocket::Debugger::Initialise(m_rkContext);

	m_rkFileInterface = new FileInterfaceOgre3D();
	Rocket::Core::SetFileInterface(m_rkFileInterface);


	// Load the mouse cursor and release the caller's reference.
	Rocket::Core::ElementDocument* cursor = m_rkContext->LoadMouseCursor(ROCKET_CURSOR_PAGE);
	if (cursor)
		cursor->RemoveReference();

	m_document = m_rkContext->LoadDocument(ROCKET_DEMO_PAGE);
	if (m_document)
	{
		Rocket::Core::Element* button = m_document->GetElementById(DEMO_PAGE_BUTTON_ID);
		if (button)
			button->AddEventListener("click", this);
		m_document->Show();		
	}

	m_rkEventListener  = new RocketEventListener(window, m_rkContext);
	m_rkRenderListener = new RocketRenderListener(window->getRenderWindow(), m_scene->getManager(), m_rkContext);
}
void GuiDemo::uninitRocket()
{
	if (m_document) m_document->RemoveReference();
	m_document = 0;

	// Shutdown Rocket.
	if (m_rkContext) m_rkContext->RemoveReference();
	m_rkContext = 0;
	Rocket::Core::Shutdown();

	delete m_rkOgreSystem; m_rkOgreSystem = 0;
	delete m_rkOgreRenderer; m_rkOgreRenderer = 0;
	delete m_rkFileInterface; m_rkFileInterface = 0;

	delete m_rkEventListener; m_rkEventListener = 0;
	delete m_rkRenderListener; m_rkRenderListener = 0;
}
Ejemplo n.º 6
0
ShortcutBar::ShortcutBar(PlayerData& playerData, Metadata& metadata, GameStateType stateType, Rocket::Core::Context& rocketContext) :
   m_rocketContext(rocketContext),
   m_metadata(metadata),
   m_playerData(playerData),
   m_stateType(stateType)
{
   m_rocketContext.AddReference();

   m_shortcutBarDocument = rocketContext.LoadDocument("data/gui/shortcutBar.rml");
   if(m_shortcutBarDocument != nullptr)
   {
      m_shortcutContainer = m_shortcutBarDocument->GetElementById("shortcutContainer");
      if (m_shortcutContainer != nullptr)
      {
         m_bindings.bindAction(m_shortcutContainer, "dragdrop", [this](Rocket::Core::Event& event) { usableDropped(event); });
         m_bindings.bindAction(m_shortcutContainer, "click", [this](Rocket::Core::Event& event) { shortcutClicked(event); });
      }

      refresh();

      m_shortcutBarDocument->Show();
   }
}
Ejemplo n.º 7
0
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;
};
Ejemplo n.º 8
0
void HelloWorld::HandlePostRender(StringHash eventType, VariantMap &eventData)
{
    rocketContext->Render();
}
Ejemplo n.º 9
0
void HelloWorld::Stop()
{
    rocketContext->RemoveReference();
    Rocket::Core::Shutdown();
}
Ejemplo n.º 10
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;
}