Passing union instance to native function doesn't populate it #315
Unanswered
pizzadox9999
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I have the following problem and this question: I have this Event union in C from CSFML. Do I have to use the sfEvt in front of every enumeration?
The problem is that in the Event class the EvenType is null after passing a new Event instance to
CsfmlGraphicsLibrary public int sfRenderWindow_pollEvent(Pointer renderWindow, Pointer event);.
I do it by calling getMemory on the Event instance. I would expect that the eventType member of the Event class is Populated with the corresponding eventType from the EvenType Enum. By the way I don't come about it to mention that is a GREAT project.
The other parts like creating the window and moving it are working but the EventHandling is a mystery to me(not in sfml but how I translate it to Java)
The typedef union of Event.h the rest are structs. It should be said that i didn't use the sf in the Java class names. I figured it wouldn't make a different because it didn't also with the RenderWindow class.
I'm thrilled for you'r help. Best regards pizza.
PS: If you need more code i'll upload it to github and I wonder if I have made the same mistak as #288
`typedef union
{
sfEventType type; ///< Type of the event
sfSizeEvent size; ///< Size event parameters
sfKeyEvent key; ///< Key event parameters
sfTextEvent text; ///< Text event parameters
sfMouseMoveEvent mouseMove; ///< Mouse move event parameters
sfMouseButtonEvent mouseButton; ///< Mouse button event parameters
sfMouseWheelEvent mouseWheel; ///< Mouse wheel event parameters (deprecated)
sfMouseWheelScrollEvent mouseWheelScroll; ///< Mouse wheel event parameters
sfJoystickMoveEvent joystickMove; ///< Joystick move event parameters
sfJoystickButtonEvent joystickButton; ///< Joystick button event parameters
sfJoystickConnectEvent joystickConnect; ///< Joystick (dis)connect event parameters
sfTouchEvent touch; ///< Touch events parameters
sfSensorEvent sensor; ///< Sensor event parameters
} sfEvent;
the Event union Java Translation
public class Event extends Union {
public enum EventType { // is the C eventType enum
sfEvtClosed, ///< The window requested to be closed (no data)
sfEvtResized, ///< The window was resized (data in event.size)
sfEvtLostFocus, ///< The window lost the focus (no data)
sfEvtGainedFocus, ///< The window gained the focus (no data)
sfEvtTextEntered, ///< A character was entered (data in event.text)
sfEvtKeyPressed, ///< A key was pressed (data in event.key)
sfEvtKeyReleased, ///< A key was released (data in event.key)
sfEvtMouseWheelMoved, ///< The mouse wheel was scrolled (data in event.mouseWheel) (deprecated)
sfEvtMouseWheelScrolled, ///< The mouse wheel was scrolled (data in event.mouseWheelScroll)
sfEvtMouseButtonPressed, ///< A mouse button was pressed (data in event.mouseButton)
sfEvtMouseButtonReleased, ///< A mouse button was released (data in event.mouseButton)
sfEvtMouseMoved, ///< The mouse cursor moved (data in event.mouseMove)
sfEvtMouseEntered, ///< The mouse cursor entered the area of the window (no data)
sfEvtMouseLeft, ///< The mouse cursor left the area of the window (no data)
sfEvtJoystickButtonPressed, ///< A joystick button was pressed (data in event.joystickButton)
sfEvtJoystickButtonReleased, ///< A joystick button was released (data in event.joystickButton)
sfEvtJoystickMoved, ///< The joystick moved along an axis (data in event.joystickMove)
sfEvtJoystickConnected, ///< A joystick was connected (data in event.joystickConnect)
sfEvtJoystickDisconnected, ///< A joystick was disconnected (data in event.joystickConnect)
sfEvtTouchBegan, ///< A touch event began (data in event.touch)
sfEvtTouchMoved, ///< A touch moved (data in event.touch)
sfEvtTouchEnded, ///< A touch event ended (data in event.touch)
sfEvtSensorChanged, ///< A sensor value changed (data in event.sensor)
sfEvtCount ///< Keep last -- the total number of event types
}
}
//the Java GraphicsLib translation
public interface CsfmlGraphicsLibrary {
//RenderWindow Api from RenderWindow.hin Graphics Module
public Pointer sfRenderWindow_create(VideoMode mode, String title, int style, ContextSettings settings);
public void sfRenderWindow_destroy(Pointer renderWindow);
public void sfRenderWindow_close(Pointer renderWindow);
public int sfRenderWindow_isOpen(Pointer renderWindow);
public ContextSettings sfRenderWindow_getSettings(Pointer renderWindow);
public int sfRenderWindow_pollEvent(Pointer renderWindow, Pointer event);
public int sfRenderWindow_waitEvent(Pointer renderWindow, Pointer event);
public Vector2i sfRenderWindow_getPosition(Pointer renderWindow);
public void sfRenderWindow_setPosition(Pointer renderWindow, Vector2i position);
public Vector2u sfRenderWindow_getSize(Pointer renderWindow);
public void sfRenderWindow_setSize(Pointer renderWindow, Vector2u size);
public void sfRenderWindow_setTitle(Pointer renderWindow, String title);
}`
output from console if I log the "returned" object from the said function
Event {
type = - null -
size = - null -
key = - null -
text = - null -
mouseMove = - null -
mouseButton = - null -
mouseWheelScroll = - null -
joystickMove = - null -
joystickButton = - null -
joystickConnect = - null -
touch = - null -
sensor = - null -
}
Beta Was this translation helpful? Give feedback.
All reactions