Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - r4zzz4k

Pages: [1]
1
Maybe you're right. Anyway thanks for taking the time to answer and good luck with the project development :)

2
Paragraph 9.5.1 of C++ Standard says:
Quote
one special guarantee is made in order to
simplify the use of unions: If a POD-union contains several POD-structs that share a common initial
sequence (9.2), and if an object of this POD-union type contains one of the POD-structs, it is permitted to
inspect the common initial sequence of any of POD-struct members
Because these structs contain only ints and enum, they are PODs. So it's really legal to use both sf::Event::MouseMoveEvent and sf::Event::MouseButtonEvent no matter of what kind of mouse event is got.
So this change to members' order will really simplify user code a bit.

3
Thanks for really fast answer!
I realize that it can be an undefined behavior, but this works in gcc (4.7) and msvc (2010 express), and probably on other compilers due to representation of this structures inside of union in memory. Moreover, I've seen such assumptions in several other unrelated frameworks. I'm going to look into the C++ Standard and find some information there.

4
Window / sf::Event::MouseMoveEvent and sf::Event::MouseButtonEvent
« on: July 31, 2012, 03:36:10 pm »
First of all, I want to express my gratitude and respect to developers of this really great library. I find it quite easy-to-use and at the same time very powerful. Great job! :)

I'm doing small framework to make a GUI based on Graphics package. After polling new event I check it's source (keyboard or mouse). If it's related to mouse, I get cursor position and use it onwards.
window.pollEvent(event);
sf::Vector2i mousePointer(event.mouseMove);
Control* curUnderMouse = nullptr;
...
for(auto control: m_controls)
{
    if(control->hitTest(mousePointer))
    {
        curUnderMouse = control;
        break;
    }
}
 
I already realized my fault that event.mouseMove and event.mouseButton store cursor coordinates differently.
struct MouseMoveEvent
{
    int x;
    int y;
};
struct MouseButtonEvent
{
    Mouse::Button button;
    int x;
    int y;
};
 
I've corrected my error, but here is my question: won't be better to declare MouseButtonEvent as
struct MouseButtonEvent
{
    int x;
    int y;
    Mouse::Button button;
};
 
to make user code simpler in many situations? Just because these structs are in union, there will be no need to check mouse event type just to get mouse cursor position.

Anyway, it's really great library and I'm looking forward it's further development. And sorry for my English :)

Pages: [1]