Are you sure this is working for Windows as intended ?
Yes, changing the window size, dragging the window with mouse and toggling exclusive fullscreen with left mouse button works perfectly on Windows. It does not matter if the hit-test callback is registered once or many times, dragging the window with mouse worked and still works as expected — every time and on any display.
I ask because I can clearly see that whenever the window reaches full-screen state (pressing +) and returning to window state (pressing -) that the hit callback routine is actually invoked.
To see what is going on, just print some data in the callback to the console. Open the project options windows, go to the
Compiler Options→Config and Target branch and uncheck the
Win32 gui application, to enable the console window (or enable the console in other way). Then use the following debug code (just copy and paste whole function):
function WindowHitTest(AWindow: PSDL_Window; const APoint: PSDL_Point; AData: Pointer): TSDL_HitTestResult; cdecl;
var
Height: Integer;
begin
if Placement.VideoEnabled or (Placement.WindowSize = SIZE_FULLSCREEN) then
Result := SDL_HITTEST_NORMAL
else
begin
SDL_GetWindowSize(AWindow, nil, @Height);
if APoint^.Y < Height div 4 then
begin
Result := SDL_HITTEST_DRAGGABLE;
Placement.ExposeWindow();
end
else
Result := SDL_HITTEST_NORMAL;
end;
Write('Hit-test! Video: ', Placement.VideoEnabled:5, ' | Size: ');
case Placement.WindowSize of
SIZE_NATIVE: Write('SIZE_NATIVE ');
SIZE_ZOOM_2X: Write('SIZE_ZOOM_2X ');
SIZE_ZOOM_3X: Write('SIZE_ZOOM_3X ');
SIZE_FULLSCREEN: Write('SIZE_FULLSCREEN');
end;
Write(' | Result: ');
case Result of
SDL_HITTEST_NORMAL: WriteLn('SDL_HITTEST_NORMAL');
SDL_HITTEST_DRAGGABLE: WriteLn('SDL_HITTEST_DRAGGABLE');
end;
end;
After launch, you should see the following lines in console:
Hit-test! Video: TRUE | Size: SIZE_ZOOM_2X | Result: SDL_HITTEST_NORMAL
Window size is by default set to
SIZE_ZOOM_2X and is independent from the
FVideoEnabled, which should be set to
True if the exclusive fullscreen is active (by default is active). Then press the
Alt+Enter to disable exclusive fullscreen. Now, when you move the cursor over the game window, one of the following two lines should be printed:
Hit-test! Video: FALSE | Size: SIZE_ZOOM_2X | Result: SDL_HITTEST_NORMAL
Hit-test! Video: FALSE | Size: SIZE_ZOOM_2X | Result: SDL_HITTEST_DRAGGABLE
Video is disabled, the window is displayed in the
SIZE_ZOOM_2X size, and depends on the cursor position in the window, hit-test result should be set to
SDL_HITTEST_DRAGGABLE (if the cursor is in the top-area of the window, dedicated for dragging) or
SDL_HITTEST_NORMAL (if the cursor is in the bottom-area, dedicated to detect double-clicks).
Now, press few times the
+ key until you reach the desktop fullscreen. When you move the mouse over the window, you should see in the console the lines looks like this:
Hit-test! Video: FALSE | Size: SIZE_FULLSCREEN | Result: SDL_HITTEST_NORMAL
It doesn't matter where the cursor is in the window, hit-test callback should always return
SDL_HITTEST_NORMAL, because the dragging in any of the fullscreen modes in disabled. Now press the
- key to reduce the window size once. From now, you should see in the console one of the following two lines:
Hit-test! Video: FALSE | Size: SIZE_ZOOM_3X | Result: SDL_HITTEST_NORMAL
Hit-test! Video: FALSE | Size: SIZE_ZOOM_3X | Result: SDL_HITTEST_DRAGGABLE
Video must be set to
False, size must be
SIZE_ZOOM_3X and the result should be
SDL_HITTEST_NORMAL or
SDL_HITTEST_DRAGGABLE, depends on the cursor position in the window. Tell me what you see in the console in this case.
If not mistaken then that seems to suggest that there goes something wrong with the used logic ?
There is no other logic that controls window dragging that this callback. As long as the
FVideoEnabled and
FWindowSize fields contains correct values, the hit-test should work properly. But first, please, do the test and then we will think about other things.