void GUI::onSFMLEvent(sf::Event& event) { sf::Vector2i mouse_pos; switch (event.type) { case sf::Event::MouseMoved: this->m_context->injectMousePosition(event.mouseMove.x, event.mouseMove.y); break; case sf::Event::KeyPressed: this->m_context->injectKeyDown(toCEGUIKey(event.key.code)); break; case sf::Event::KeyReleased: this->m_context->injectKeyUp(toCEGUIKey(event.key.code)); break; case sf::Event::TextEntered: this->m_context->injectChar(event.text.unicode); break; case sf::Event::MouseButtonPressed: this->m_context->injectMouseButtonDown(toCEGUIMouseButton(event.mouseButton.button)); break; case sf::Event::MouseButtonReleased: this->m_context->injectMouseButtonUp(toCEGUIMouseButton(event.mouseButton.button)); break; case sf::Event::MouseWheelMoved: this->m_context->injectMouseWheelChange(static_cast<float>(event.mouseWheel.delta)); break; } }
void GameDesktop::handleEvent(const sf::Event &event) { bool handled = false; CEGUI::GUIContext& context = CEGUI::System::getSingleton().getDefaultGUIContext(); sf::Vector2i mouse_pos; switch (event.type) { case sf::Event::TextEntered: handled = context.injectChar(event.text.unicode); break; case sf::Event::KeyPressed: handled = context.injectKeyDown(toCEGUIKey(event.key.code)); break; case sf::Event::KeyReleased: handled = context.injectKeyUp(toCEGUIKey(event.key.code)); break; case sf::Event::MouseMoved: mouse_pos = sf::Mouse::getPosition(screen_); handled = context.injectMousePosition(static_cast<float>(mouse_pos.x), static_cast<float>(mouse_pos.y)); break; case sf::Event::MouseButtonPressed: handled = context.injectMouseButtonDown(toCEGUIMouseButton(event.mouseButton.button)); break; case sf::Event::MouseButtonReleased: handled = context.injectMouseButtonUp(toCEGUIMouseButton(event.mouseButton.button)); break; case sf::Event::MouseWheelMoved: handled = context.injectMouseWheelChange(static_cast<float>(event.mouseWheel.delta)); break; case sf::Event::Resized: CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Sizef(event.size.width, event.size.height)); break; } // If mouse is over an UI element, we do not initiate drag scrolling if (!handled) { // we can handle this event here, CEGUI didn't use it ... } }
bool GUI::handleInput(sf::Event& event) { CEGUI::System* sys = CEGUI::System::getSingletonPtr(); switch(event.type) { case sf::Event::TextEntered: return sys->injectChar(event.text.unicode); case sf::Event::KeyPressed: return sys->injectKeyDown(toCEGUIKey(event.key.code)); case sf::Event::Event::KeyReleased: return sys->injectKeyUp(toCEGUIKey(event.key.code)); case sf::Event::MouseMoved: return sys->injectMousePosition(static_cast<float>(event.mouseMove.x), static_cast<float>(event.mouseMove.y)); case sf::Event::MouseButtonPressed: return sys->injectMouseButtonDown(toCEGUIMouseButton(event.mouseButton.button)); case sf::Event::MouseButtonReleased: return sys->injectMouseButtonUp(toCEGUIMouseButton(event.mouseButton.button)); case sf::Event::MouseWheelMoved: return sys->injectMouseWheelChange(static_cast<float>(event.mouseWheel.delta)); default: return false; } }