typedefbool(* SfuiEventCallback)(class sfui*, sf::Event);
...
class sfui {
...
public:
/** Function to call (if any) when the window is closed */
SfuiEventCallback OnClosed;
/** Function to call (if any) when the window is resized */
SfuiEventCallback OnResized;
/** Function to call (if any) when window focus is lost */
SfuiEventCallback OnLostFocus;
/** Function to call (if any) when window focus is gained */
SfuiEventCallback OnGainedFocus;
/** Function to call (if any) when a key is pressed */
SfuiEventCallback OnKeyPressed;
/** Function to call (if any) when a key is released */
SfuiEventCallback OnKeyReleased;
/** Function to call (if any) when the mouse moves */
SfuiEventCallback OnMouseWheelMoved;
/** Function to call (if any) when a mouse button is pressed */
SfuiEventCallback OnMouseButtonPressed;
/** Function to call (if any) when a mouse button is released */
SfuiEventCallback OnMouseButtonReleased;
/** Function to call (if any) when the mouse moves */
SfuiEventCallback OnMouseMoved;
...
};
But when a key is pressed, there is a segmentation fault (unless I leave sfui::OnKeyPressed as NULL).
Basically what I'm trying to do is have a pointer to a function that can be used to set handlers for events. The idea is that there is a default action and a user-defined action. The user can set a handler for each event or leave the pointers set to NULL (as they are in the constructors), in which case the default action is taken (usually just returntrue;). If the user doesn't want the handler to be called any more they should be able to set the function pointer to NULL and the default action will be performed next time the event occurs. What is the proper way to do this?