Giter Club home page Giter Club logo

sfml-eventmanager's Introduction

SFML-EventManager

Little helper to allow callbacks based event management with SFML

Installation

1. Clone repo ❤️

2. Include header

#include "event_manager.hpp"

Usage

1. Declare your callbacks

// Instanciate an events manager
sfev::EventManager evm(window);
// Add a close callback
evm.addEventCallback(sf::Event::EventType::Closed, [&](const sf::Event&) {window.close(); });

Example of Mouse and Keyboard events handling

using cEvent = const sf::Event&;

// Add Key event callback
evm.addKeyPressedCallback(sf::Keyboard::A, [&](cEvent) {std::cout << "A Pressed" << std::endl; });
evm.addKeyReleasedCallback(sf::Keyboard::A, [&](cEvent) {std::cout << "A released" << std::endl; });

// Add Mouse button event callback
evm.addMousePressedCallback(sf::Mouse::Left, [&](cEvent) {std::cout << "Mouse LEFT pressed" << std::endl; });
evm.addMouseReleasedCallback(sf::Mouse::Left, [&](cEvent) {std::cout << "Mouse LEFT released" << std::endl; });

// Add another Mouse button event callback
evm.addMousePressedCallback(sf::Mouse::Right, [&](cEvent) {std::cout << "Mouse RIGHT pressed" << std::endl; });
evm.addMouseReleasedCallback(sf::Mouse::Right, [&](cEvent) {std::cout << "Mouse RIGHT released" << std::endl; });

2. Enjoy clean events pooling loop

while (window.isOpen())
{
  // Clean and peaceful
  evm.processEvents();

  window.clear();
  ...
  window.display();
}

Technical details

The callback is a std::function<void(const sf::Event& event)> so you can pass any callable object with this signature.

sfml-eventmanager's People

Contributors

johnbuffer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.