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.


Topics - tymofey

Pages: [1]
1
Window / Window and multiple threads
« on: September 19, 2011, 07:51:15 pm »
I have a thread one where i create the window:
Code: [Select]
sf::Window* wnd = new sf::Window(sf::VideoMode(400, 300), "some title", sf::Style::Close);
Then i pass the wnd ponter to two other threads.
In thread two i query window for events:
Code: [Select]
sf::Event event;
while (true)
    while(wnd->PollEvent(event))
    {
         //....
    }

And in thread three I draw in it:
Code: [Select]
while (true)
{
    //...
    wnd->Display();
}


The window is of course protected by proper locking.

This causes lots of
Quote
Failed to activate window's context
messages to the console. Is what i am trying to do even possible?

2
Graphics / RenderTarget::ConvertCoords backwards
« on: September 12, 2011, 08:33:30 pm »
I wanted to draw some text in RenderWindow that would be positioned near a sprite, like a label or tag always moving along with the sprite, attached to some point of it and not rotating or scaling regardless of sprite's transformations. And I was really surprised to not find a complementary function to ConvertCoords, that would convert world coordinates to screen coordinates. I believe this to be a frequently occuring task and i guess it is only reasonable to add such functionality to RenderTarget

3
Window / Event::MouseWheelEvent::Delta bug
« on: September 11, 2011, 09:38:08 am »
Under windows/sfml2 i enountered a problem where  Event::MouseWheelEvent::Delta is almost allways zero, you need to scroll the wheel REALLY fast to obtain some other sensible value. After taking a look at the ProcessEvent function in /src/SFML/Window/Win32/WindowImplWin32.cpp, i found this:
Code: [Select]

        // Mouse wheel event
        case WM_MOUSEWHEEL :
        {
            // Mouse position is in screen coordinates, convert it to window coordinates
            POINT position;
            position.x = static_cast<Int16>(LOWORD(lParam));
            position.y = static_cast<Int16>(HIWORD(lParam));
            ScreenToClient(myHandle, &position);

            Event event;
            event.Type = Event::MouseWheelMoved;
            event.MouseWheel.Delta = static_cast<Int16>(HIWORD(wParam)) / 120;
            event.MouseButton.X    = position.x;
            event.MouseButton.Y    = position.y;
            PushEvent(event);
            break;
        }


Now, after carefully reading http://msdn.microsoft.com/en-us/library/ms645617(v=vs.85).aspx, the following was noticed:
Quote
The high-order word indicates the distance the wheel is rotated, expressed in multiples or divisions of WHEEL_DELTA, which is 120.

so it becomes appearent that
Code: [Select]
event.MouseWheel.Delta = static_cast<Int16>(HIWORD(wParam)) / 120;
sets Delta to zero whenever the absolute value of HIWORD(wParam) is less than 120, which happens to be quite often.

After taking a look at the Linux implementation:
Code: [Select]
event.MouseWheel.Delta = windowEvent.xbutton.button == Button4 ? 1 : -1; which can return only 1 or -1 i believe the windows one should be changed to something like
Code: [Select]
event.MouseWheel.Delta = static_cast<Int16>(HIWORD(wParam)) > 0 ? 1 : -1;
as well, or make Delta a float to allow fractional values.

Pages: [1]