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

Author Topic: mouse coord out until resize by any amount  (Read 8234 times)

0 Members and 1 Guest are viewing this topic.

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #15 on: June 27, 2008, 04:01:51 am »
cool, no luck yet, i am going to look at it this weekend too, i havent made a win32 window in a long time so having to relearn a whole bunch in the process, but i guess it will give me some hair on my chest,

i am actually enjoying the challenge, and hope to solve it, i got a nifty program called source navigator which is helping me stacks to jump around in your code...till anon

SirJulio

  • Full Member
  • ***
  • Posts: 241
    • View Profile
mouse coord out until resize by any amount
« Reply #16 on: June 27, 2008, 04:18:23 am »
Hi,

I think i found the problem.

When SFML trying to create a window with a client area egal to screen resolution (or highest), then, resulting client area is smallest than the requested VideoMode (maybe title bar size). ATM, SFML width and height are initialized before any window creation, and not updated after that :

Code: [Select]
// LoC 145 (WindowImplWin32.cpp)
    int Width  = myWidth  = Mode.Width;
    int Height = myHeight = Mode.Height;


If the client area of the windows is smaller than the requested video mode (if you pass GetDesktopMode(), it will be) window GetHeigth and GetWidth will be false until a WM_SIZE notif (which will call GetClientRect).

This could be fix with a GetClientRect call after the window creation :

Code: [Select]
LoC 171 WindowImplWin32.cpp
    // Create the window
    if (HasUnicodeSupport())
    {
        wchar_t WTitle[256];
        int NbChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Title.c_str(), static_cast<int>(Title.size()), WTitle, sizeof(WTitle) / sizeof(*WTitle));
        WTitle[NbChars] = L'\0';
        myHandle = CreateWindowW(ourClassNameW, WTitle, Win32Style, Left, Top, Width, Height, NULL, NULL, GetModuleHandle(NULL), this);
    }
    else
    {
        myHandle = CreateWindowA(ourClassNameA, Title.c_str(), Win32Style, Left, Top, Width, Height, NULL, NULL, GetModuleHandle(NULL), this);
    }

// ==== NEW ====
    if (!Fullscreen)
    {
        RECT clientRect = {0, 0, 0, 0};
        if (!GetClientRect(myHandle, &clientRect))
        {
            // ...
        }
        myWidth = clientRect.right - clientRect.left;
        myHeight = clientRect.bottom - clientRect.top;
    }
// ==== /NEW ====


I don't know how openGL context creation is influenced by this modification, but the OP code works perfectly with it (in all resolution, fulscreen etc).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32503
    • View Profile
    • SFML's website
    • Email
mouse coord out until resize by any amount
« Reply #17 on: June 27, 2008, 05:10:05 am »
The client area always matches the requested mode :
Code: [Select]
WindowImplWin32.cpp

  163     if (!Fullscreen)
  164     {
  165         RECT Rect = {0, 0, Width, Height};
  166         AdjustWindowRect(&Rect, Win32Style, false);
  167         Width  = Rect.right - Rect.left;
  168         Height = Rect.bottom - Rect.top;
  169     }

So it shouldn't be necessary to get the client size after creation :|
Laurent Gomila - SFML developer

SirJulio

  • Full Member
  • ***
  • Posts: 241
    • View Profile
mouse coord out until resize by any amount
« Reply #18 on: June 27, 2008, 05:55:53 am »
Yeap you're right, it shouldn't =p

e.g. i use 1280x1024, with getDesktopMode VideoMode is at 1280x1024, and Rect from AdjustRect is at 1288x1058 (window area) but the final window size (include border and title) is 1288x1036. That's why your final client area is shrinked (requested : 1280x1024 real : 1280x1002).

Some tests with differents window size :

Code: [Select]
   // Create the window
    if (HasUnicodeSupport())
    {
        wchar_t WTitle[256];
        int NbChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Title.c_str(), static_cast<int>(Title.size()), WTitle, sizeof(WTitle) / sizeof(*WTitle));
        WTitle[NbChars] = L'\0';
        myHandle = CreateWindowW(ourClassNameW, WTitle, Win32Style, Left, Top, Width, Height, NULL, NULL, GetModuleHandle(NULL), this);
    }
    else
    {
        myHandle = CreateWindowA(ourClassNameA, Title.c_str(), Win32Style, Left, Top, Width, Height, NULL, NULL, GetModuleHandle(NULL), this);
    }

    {
        if (!Fullscreen)
        {
            RECT clientRect , windowRect = {0, 0, 0, 0};
            GetClientRect(myHandle, &clientRect);
            GetWindowRect(myHandle, &windowRect);
            myWidth = clientRect.right - clientRect.left;
            myHeight = clientRect.bottom - clientRect.top;
            int realWidth = windowRect.right - windowRect.left;
            int realHeight = windowRect.bottom - windowRect.top;
            std::cout << "Requested client : " << Mode.Width << "x" << Mode.Height << " Real client : " << myWidth << "x" << myHeight << std::endl;
            std::cout << "Requested window : " << Width << "x" << Height << " Real client : " << realWidth << "x" << realHeight << std::endl;

        }
    }


800x600 (OK) :
Quote
Requested client : 800x600 Real client : 800x600
Requested window : 808x634 Real client : 808x634


1024x768 (OK) :
Quote
Requested client : 1024x768 Real client : 1024x768
Requested window : 1032x802 Real client : 1032x802


1280x1024 (desktop resolution) :
Quote
Requested client : 1280x1024 Real client : 1280x1002
Requested window : 1288x1058 Real client : 1288x1036


1280x1024 (with sfNone instead of sfResize | sfClose)
Quote
Requested client : 1280x1024 Real client : 1280x1024
Requested window : 1280x1024 Real client : 1280x1024

I don't know why CreateWindow reduce your window size (maybe there is a maximum window size ?) but it does. =)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32503
    • View Profile
    • SFML's website
    • Email
mouse coord out until resize by any amount
« Reply #19 on: June 27, 2008, 06:11:50 am »
Damn, I have to find out what's going on. Probably some OS internal magic... :|
Laurent Gomila - SFML developer

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #20 on: June 27, 2008, 02:03:13 pm »
yeah i also noticed that, that the screen dimension that i print out shrinks  when i resize, even though the height has not changed at all, but been at work the whole day, going to look more at it this weekend, one of us is going to solve this soon as it is not many files to deal with.


edit-->add

also thanks SirJulio, that definitely seems to be where the problem lies, at first i thought it might be something just with getdesktop, but if i do something like the following


Code: [Select]

sfVideoMode Mode = {GetSystemMetrics( SM_CXSCREEN )-x, GetSystemMetrics( SM_CYSCREEN )-x, 32};


and i start x at 0, and increment, only when x reaches 25 will my screen and input behave.

SirJulio

  • Full Member
  • ***
  • Posts: 241
    • View Profile
mouse coord out until resize by any amount
« Reply #21 on: June 27, 2008, 03:24:50 pm »
Yeap, i think we have our problems too.

I made some tests with wininspector and apparently on my comp, 1292x1036 seems to be the larger size I can use for any window (notepad for the test). This values is exactly what GetSystemMetricsSM_C[X|Y]MAXTRACK) returns. After some querying, Caption bar vertical size of sizable window is 26 (SM_CYCAPTION), and border of the window is 4 (SM_CYBORDER), so we found our magical number. Window cannot be higher than 1036 (always on my res : 1024) and for sizable window we must count caption and border size (26 + 2 * 4 = 34), so we cannot have a client area higher than 1002 (1036 - 34), which is equivalent to prior results. If your window is created with sfNone (noborder no caption), you don't have the problem because resulting window will be at the correct size (no need to count border and caption).

According to MSDN, you can override this behavior by processing WM_GETMINMAXINFO notif.

But, IMHO, creating a window higher than the screen vertical resolution (which seems possible) is not a good thing, dev request a VideoMode, but uses GetWidth and GetHeight to keep all calculs relative. If GetDesketopMode, create a client area smaller than the requested one, this is not a problem but GetWidth and GetHeigth return by Window must be correct.

So, i think that "post-calculate" the real Width and Height would be the best methods for this kind of situation. =)

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #22 on: June 28, 2008, 02:58:18 am »
ok i have come up with a solution will post it now, actually very very simple!

just need to add check for fullscreen mode.as the problem was just calculate interior render window.

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #23 on: June 28, 2008, 03:12:50 am »
ok here we go this was the only part i needed to change,

Code: [Select]

////////////////////////////////////////////////////////////
/// Create the window implementation
////////////////////////////////////////////////////////////
WindowImplWin32::WindowImplWin32(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, WindowSettings& Params) :
myHandle          (NULL),
myCallback        (0),
myCursor          (NULL),
myKeyRepeatEnabled(true)
{
    // Register the window class at first call
    if (ourWindowCount == 0)
        RegisterWindowClass();

//    changes here
    int Left   = (GetDeviceCaps(GetDC(NULL), HORZRES) - Mode.Width)  / 2;
    int Top    = (GetDeviceCaps(GetDC(NULL), VERTRES) - Mode.Height) / 2;

    //first calculate outer dimension
    int Width  = Mode.Width;
    int Height = Mode.Height;


//  
    //then calculate dimensions of render view
    myWidth  = Width - (2*GetSystemMetrics( SM_CXSIZEFRAME ));
    myHeight = Height - (2*GetSystemMetrics( SM_CYSIZEFRAME )) - GetSystemMetrics( SM_CYCAPTION );


    // Choose the window style according to the Style parameter
    DWORD Win32Style = WS_VISIBLE;
    if (WindowStyle == Style::None)
    {
        Win32Style |= WS_POPUP;
    }
    else
    {
        if (WindowStyle & Style::Titlebar) Win32Style |= WS_CAPTION | WS_MINIMIZEBOX;
        if (WindowStyle & Style::Resize)   Win32Style |= WS_THICKFRAME | WS_MAXIMIZEBOX;
        if (WindowStyle & Style::Close)    Win32Style |= WS_SYSMENU;
    }

    // In windowed mode, adjust width and height so that window will have the requested client area
    bool Fullscreen = (WindowStyle & Style::Fullscreen) != 0;
    /*  if (!Fullscreen)
    REMOVED THIS AND OPTED FOR TOP AS IT WAS THROWING OUT, I THINK,EITHER WAY NOT NEEDED
    */

    // Create the window
    if (HasUnicodeSupport())
    {
        wchar_t WTitle[256];
        int NbChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Title.c_str(), static_cast<int>(Title.size()), WTitle, sizeof(WTitle) / sizeof(*WTitle));
        WTitle[NbChars] = L'\0';
        myHandle = CreateWindowW(ourClassNameW, WTitle, Win32Style, Left, Top, Width, Height, NULL, NULL, GetModuleHandle(NULL), this);
    }
    else
    {
        myHandle = CreateWindowA(ourClassNameA, Title.c_str(), Win32Style, Left, Top, Width, Height, NULL, NULL, GetModuleHandle(NULL), this);
    }




i checked the resize event and that is fine, and is the only other place that i could see that myWidth/myHeight was being changed,
also checked fullscreen mode and seemed to work just fine,


later.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32503
    • View Profile
    • SFML's website
    • Email
mouse coord out until resize by any amount
« Reply #24 on: June 28, 2008, 11:15:10 am »
Ok I see. I've changed the code so that now the window's client size is calculated again after its creation.

vurentjie, I don't think your idea of calculating manually the window's external size was the way to go, especially if you don't take the style in account. Anyway it was also more complicated than just recomputing the size after creation ;)

Thank you guys for your help, let me know if everything's fine now or not :)
Laurent Gomila - SFML developer

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #25 on: June 28, 2008, 10:26:22 pm »
cool no worry, i will grab the updates, was merely what i came up with in the situation, and worked, but thanks.

 

anything