31
General discussions / A new logo for SFML
« on: July 09, 2011, 06:12:04 pm »
Oh great job, the 5° variation is really awesome !
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
////////////////////////////////////////////////////////////
/// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <iostream>
#include <Zeven/sfZeven/sfZeven.hpp>
void Hello()
{
std::cout << "Hello world" << std::endl;
}
////////////////////////////////////////////////////////////
/// Entry point of the application
////////////////////////////////////////////////////////////
int main()
{
// Creation and settings of the SFML rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Zeven sample");
// Limitation of the framerate
App.SetFramerateLimit(40);
// Creation of the area
sf::FloatRect area(0, 0, 100, 100);
// Creation of a shape which represent the area
sf::Shape::Rectangle rectangle(area.Left, area.Top, area.Width, area.Height, sf::Color::Red);
// Get the event handler
zin::sfEventHandler<zin::sfListener>& EventHandler = zin::sfEventHandler::GetInstance();
// Creation of the mouse over listener
zin::sfMouseOverListener mouseOver(area);
// Connection to the function Hello
mouseOver.ConnectTo(sigc::ptr_fun(&Hello));
// Register the listener
EventHandler.Register(mouseOver);
// Main process loop
while( App.IsOpened() )
{
// Rest of the processor
sf::Sleep(0.02);
// Create an empty event
sf::Event Event;
// Event loop
while( App.GetEvent(Event) )
{
// Send an SFML event to the event handler
EventHandler.Recept(Event);
// Close window to exit the program
if( Event.Type == sf::Event::Closed )
App.Close();
// Esc to exit the program
if( Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Escape )
App.Close();
}
// Send the mouse position
EventHandler.Recept(App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY()));
// Update the event handler
EventHandler.Update();
// Clear the screen
App.Clear();
// Add drawable in the stack
App.Draw(rectangle);
// Displaying in the rendering window
App.Display();
}
return EXIT_SUCCESS;
}
1. You need to call Update() for each listener.
2. You need to manually append each event to your events' container.
3. You need to go through your own container to do the Update() call.
What's your thought about this ?
////////////////////////////////////////////////////////////
/// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <iostream>
#include <sfModule/sfZeven.hpp>
void Hello()
{
std::cout << "Hello world" << std::endl;
}
////////////////////////////////////////////////////////////
/// Entry point of the application
////////////////////////////////////////////////////////////
int main()
{
// Creation and settings of the SFML rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Zeven sample");
// Limitation of the framerate
App.SetFramerateLimit(40);
// Creation of the area
sf::FloatRect area(0, 0, 100, 100);
// Creation of a shape which represent the area
sf::Shape::Rectangle rectangle(area.Left, area.Top, area.Width, area.Height, sf::Color::Red);
// Creation of the mouse over listener
zin::sfMouseOverListener mouseOver(area);
// Connection to the function Hello
mouseOver.ConnectTo(PtrFun(&Hello));
// Main process loop
while( App.IsOpened() )
{
// Rest of the processor
sf::Sleep(0.02);
// Create an empty event
sf::Event Event;
// Create an event container
zin::sfEvents Events;
Events.SendMousePos(App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY()));
// Event loop
while( App.GetEvent(Event) )
{
// Add the event into the container
Events+=Event;
// Close window to exit the program
if( Event.Type == sf::Event::Closed )
App.Close();
// Esc to exit the program
if( Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Escape )
App.Close();
}
// Send the events to the listener
mouseOver.Update(Events);
// Clear the screen
App.Clear();
// Add drawable in the stack
App.Draw(rectangle);
// Displaying in the rendering window
App.Display();
}
return EXIT_SUCCESS;
}
void Hello()
{
std::cout << "Hello world !" << std::endl;
}
sf::FloatRect area(0, 0, 100, 100);
zin::sfMouseOverListener mouseOver(area);
mouseOver.ConnectTo(PtrFun(&Hello));
mouseOver.Update(...);
Could you provide a simpler example ? (even with fewer features shown)
It's hard to get an idea of how good it is with the sample code you gave.
sf::FloatRect area(50, 50, 100, 100);
zin::sfMouseOverListener mouseOver(area);
mouseOver.ConnectTo(myMouseOverFunction);
zin::sfMouseOutListener mouseOut(area);
mouseOut.ConnectTo(myMouseOutFunction);
// Connect each other :
mouseOver.ConnectTo(mouseOut);
mouseOut.ConnectTo(mouseOver);
zin::sfTextEnteredListener textEntered;
textEntered.ConnectTo(PtrFun(&myTextEnteredFunction));
mouseOver.ConnectTo(textEntered);
zin::sfTrigger trigger;
trigger.SetInput(mouseOver);
trigger.SetOutput(textEntered);
trigger.SetRepeat(true);
zin::Behavior behavior;
behavior.ConnectTo(trigger);