Recent

Author Topic: Fairtris 2: The Ultimate Challenge  (Read 6402 times)

furious programming

  • Hero Member
  • *****
  • Posts: 864
Re: Fairtris 2: The Ultimate Challenge
« Reply #30 on: March 20, 2024, 10:28:04 pm »
The only thing that seem to fail for me is when pressing + up to the point where the window is full-screen and then pressing - again to make it a window again still does not allow me to drag. It is as if the hit-test area does not exist after the window has reached full-screen size.

Do I understand correctly that if you activate the windowed mode (the window is smaller than the screen), then press the + key to enlarge it several times until the full screen is reached (desktop fullscreen), and then press the - key once, which reduces the window, then you cannot drag it?

If so, I can't fix it because this problem is not related to the Fairtris source code. Hit-test callback is registered and works entire game session, no matter how many times you change the window size and display mode. If the window is in desktop fullscreen or in the exclusive fullscreen, this callback is still active — in these cases it just returns SDL_HITTEST_NORMAL, so dragging is not supported. If the window is smaller than the screen, it checks the position of the cursor and decide if it should allow dragging (returns SDL_HITTEST_DRAGGABLE) or not (returns SDL_HITTEST_NORMAL).

If something works incorrect then this problem must be related to the SDL itself, because the SDL fires the hit-test callback if any is registered. So, when you (or anyone else) will have some free time, please check this carefully and if it still works incorrect, then I will report this problem to SDL developers.
Lazarus 3.4 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an arcade, action/adventure game in retro style (pixel art), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

TRon

  • Hero Member
  • *****
  • Posts: 3151
Re: Fairtris 2: The Ultimate Challenge
« Reply #31 on: March 20, 2024, 10:35:24 pm »
Do I understand correctly that if you activate the windowed mode (the window is smaller than the screen), then press the + key to enlarge it several times until the full screen is reached (desktop fullscreen), and then press the - key once, which reduces the window, then you cannot drag it?
Yes, that is correct.

Quote
If something works incorrect then this problem must be related to the SDL itself, because the SDL fires the hit-test callback if any is registered. So, when you (or anyone else) will have some free time, please check this carefully and if it still works incorrect, then I will report this problem to SDL developers.
Thank you for your explanation, and I understand it. I'll tripple-check and let you know later as I want to try and see what actually happens (in chronological order) as well.
All software is open source (as long as you can read assembler)

furious programming

  • Hero Member
  • *****
  • Posts: 864
Re: Fairtris 2: The Ultimate Challenge
« Reply #32 on: March 21, 2024, 11:43:44 pm »
New stable bug-fix release is available — Fairtris 2.1.1

The Alt+Enter shortcut now can be used to toggle exclusive fullscreen. The hit-test callback support was changed, what should help with dragging the window on non-Windows platforms. If something with window dragging is still wrong, please let me know.
Lazarus 3.4 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an arcade, action/adventure game in retro style (pixel art), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

TRon

  • Hero Member
  • *****
  • Posts: 3151
Re: Fairtris 2: The Ultimate Challenge
« Reply #33 on: March 24, 2024, 08:10:26 am »
Hi furious programming:
The behaviour is as I explained before.

Are you sure this is working for Windows as intended ?

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. If not mistaken then that seems to suggest that there goes something wrong with the used logic ? The hit is registered only it is not acted upon (as intended/expected) e.g. the drag icon is not visible and the window can not be moved. I can also mention that the coordinates returned by the hit callback routines are valid.
All software is open source (as long as you can read assembler)

furious programming

  • Hero Member
  • *****
  • Posts: 864
Re: Fairtris 2: The Ultimate Challenge
« Reply #34 on: March 24, 2024, 02:49:52 pm »
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.

Quote
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):

Code: Pascal  [Select][+][-]
  1. function WindowHitTest(AWindow: PSDL_Window; const APoint: PSDL_Point; AData: Pointer): TSDL_HitTestResult; cdecl;
  2. var
  3.   Height: Integer;
  4. begin
  5.   if Placement.VideoEnabled or (Placement.WindowSize = SIZE_FULLSCREEN) then
  6.     Result := SDL_HITTEST_NORMAL
  7.   else
  8.   begin
  9.     SDL_GetWindowSize(AWindow, nil, @Height);
  10.  
  11.     if APoint^.Y < Height div 4 then
  12.     begin
  13.       Result := SDL_HITTEST_DRAGGABLE;
  14.       Placement.ExposeWindow();
  15.     end
  16.     else
  17.       Result := SDL_HITTEST_NORMAL;
  18.   end;
  19.  
  20.   Write('Hit-test! Video: ', Placement.VideoEnabled:5, ' | Size: ');
  21.   case Placement.WindowSize of
  22.     SIZE_NATIVE:     Write('SIZE_NATIVE    ');
  23.     SIZE_ZOOM_2X:    Write('SIZE_ZOOM_2X   ');
  24.     SIZE_ZOOM_3X:    Write('SIZE_ZOOM_3X   ');
  25.     SIZE_FULLSCREEN: Write('SIZE_FULLSCREEN');
  26.   end;
  27.   Write(' | Result: ');
  28.   case Result of
  29.     SDL_HITTEST_NORMAL:    WriteLn('SDL_HITTEST_NORMAL');
  30.     SDL_HITTEST_DRAGGABLE: WriteLn('SDL_HITTEST_DRAGGABLE');
  31.   end;
  32. end;

After launch, you should see the following lines in console:

Code: Pascal  [Select][+][-]
  1. 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:

Code: Pascal  [Select][+][-]
  1. Hit-test! Video: FALSE | Size: SIZE_ZOOM_2X    | Result: SDL_HITTEST_NORMAL
  2. 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:

Code: Pascal  [Select][+][-]
  1. 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:

Code: Pascal  [Select][+][-]
  1. Hit-test! Video: FALSE | Size: SIZE_ZOOM_3X    | Result: SDL_HITTEST_NORMAL
  2. 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.


Quote
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.
« Last Edit: March 24, 2024, 02:53:26 pm by furious programming »
Lazarus 3.4 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an arcade, action/adventure game in retro style (pixel art), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

TRon

  • Hero Member
  • *****
  • Posts: 3151
Re: Fairtris 2: The Ultimate Challenge
« Reply #35 on: March 25, 2024, 04:04:03 am »
After launch, you should see the following lines in console:
Uhm... no I do not see that.

I can only get that output when I actually click the left mouse button and when doing so in the first upper quarter of the window.

Thus:
Code: [Select]
Hit-test! Video: FALSE | Size: SIZE_ZOOM_2X    | Result: SDL_HITTEST_NORMAL
When pressing the left mouse button in the lower 3/4 of the window and
Code: [Select]
Hit-test! Video: FALSE | Size: SIZE_ZOOM_2X    | Result: SDL_HITTEST_DRAGGABLE
when pressing the left mouse button in the upper 1/4 of the window

Note that the video enabled placement is False on both accounts.

Quote
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:
Again, only when pressing left mousebutton:

Code: [Select]
Hit-test! Video:  TRUE | Size: SIZE_ZOOM_2X    | Result: SDL_HITTEST_NORMAL

Note, the video placement is true (not false)


Quote
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).
Yes, same results as before:
Code: [Select]
Hit-test! Video: FALSE | Size: SIZE_ZOOM_2X    | Result: SDL_HITTEST_NORMAL
Hit-test! Video: FALSE | Size: SIZE_ZOOM_2X    | Result: SDL_HITTEST_DRAGGABLE

Quote
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:
result
Code: [Select]
Hit-test! Video: FALSE | Size: SIZE_FULLSCREEN | Result: SDL_HITTEST_NORMAL


Quote
Now press the - key to reduce the window size once. From now, you should see in the console one of the following two lines:
Result
Code: [Select]
Hit-test! Video: FALSE | Size: SIZE_ZOOM_3X    | Result: SDL_HITTEST_NORMAL
Hit-test! Video: FALSE | Size: SIZE_ZOOM_3X    | Result: SDL_HITTEST_DRAGGABLE

Quote
There is no other logic that controls window dragging that this callback.
The instructions with explanations you provided in the posts is exactly why I believe there is something wrong with the logic or the order of the logic. Mind, it is just a hunch not a fact.

The problem is that it can't be seen by simply writing some lines in the callback event, that is why I worked out my own test before I responded with my previous post.

The output of that reads:
Code: [Select]
>> TPlacement.UpdateWindow()
>> TPlacement.UpdateWindowBounds()
<< TPlacement.UpdateWindowBounds()
>> TPlacement.UpdateWindowClient()
>> TPlacement.UpdateBuffer()
<< TPlacement.UpdateBuffer()
<< TPlacement.UpdateWindowClient()
>> TPlacement.UpdateWindowCursor()
<< TPlacement.UpdateWindowCursor()
>> TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindow()
>> TPlacement.UpdateWindow()
>> TPlacement.UpdateWindowBounds()
<< TPlacement.UpdateWindowBounds()
>> TPlacement.UpdateWindowClient()
>> TPlacement.UpdateBuffer()
<< TPlacement.UpdateBuffer()
<< TPlacement.UpdateWindowClient()
>> TPlacement.UpdateWindowCursor()
<< TPlacement.UpdateWindowCursor()
>> TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindow()
>> TPlacement.ExposeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
<< TPlacement.ExposeWindow()
hit 54,16 VideoEnabled = FALSE Placement.WindowSize = 0
height = 240
>> TPlacement.ExposeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
<< TPlacement.ExposeWindow()
hit 54,16 VideoEnabled = FALSE Placement.WindowSize = 0
height = 240
>> TPlacement.ExposeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
<< TPlacement.ExposeWindow()
>> TPlacement.EnlargeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
>> TPlacement.UpdateWindow()
>> TPlacement.UpdateWindowBounds()
<< TPlacement.UpdateWindowBounds()
>> TPlacement.UpdateWindowClient()
>> TPlacement.UpdateBuffer()
<< TPlacement.UpdateBuffer()
<< TPlacement.UpdateWindowClient()
>> TPlacement.UpdateWindowCursor()
<< TPlacement.UpdateWindowCursor()
>> TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindow()
<< TPlacement.EnlargeWindow()
hit 174,30 VideoEnabled = FALSE Placement.WindowSize = 1
height = 480
>> TPlacement.ExposeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
<< TPlacement.ExposeWindow()
hit 174,30 VideoEnabled = FALSE Placement.WindowSize = 1
height = 480
>> TPlacement.ExposeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
<< TPlacement.ExposeWindow()
>> TPlacement.EnlargeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
>> TPlacement.UpdateWindow()
>> TPlacement.UpdateWindowBounds()
<< TPlacement.UpdateWindowBounds()
>> TPlacement.UpdateWindowClient()
>> TPlacement.UpdateBuffer()
<< TPlacement.UpdateBuffer()
<< TPlacement.UpdateWindowClient()
>> TPlacement.UpdateWindowCursor()
<< TPlacement.UpdateWindowCursor()
>> TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindow()
<< TPlacement.EnlargeWindow()
hit 338,29 VideoEnabled = FALSE Placement.WindowSize = 2
height = 720
>> TPlacement.ExposeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
<< TPlacement.ExposeWindow()
hit 338,29 VideoEnabled = FALSE Placement.WindowSize = 2
height = 720
>> TPlacement.ExposeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
<< TPlacement.ExposeWindow()
>> TPlacement.EnlargeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
>> TPlacement.UpdateWindow()
>> TPlacement.UpdateWindowBounds()
<< TPlacement.UpdateWindowBounds()
>> TPlacement.UpdateWindowClient()
>> TPlacement.UpdateBuffer()
<< TPlacement.UpdateBuffer()
<< TPlacement.UpdateWindowClient()
>> TPlacement.UpdateWindowCursor()
<< TPlacement.UpdateWindowCursor()
>> TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindow()
<< TPlacement.EnlargeWindow()
hit 649,21 VideoEnabled = FALSE Placement.WindowSize = 3
hit 650,21 VideoEnabled = FALSE Placement.WindowSize = 3
>> TPlacement.ReduceWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
>> TPlacement.UpdateWindow()
>> TPlacement.UpdateWindowBounds()
<< TPlacement.UpdateWindowBounds()
>> TPlacement.UpdateWindowClient()
>> TPlacement.UpdateBuffer()
<< TPlacement.UpdateBuffer()
<< TPlacement.UpdateWindowClient()
>> TPlacement.UpdateWindowCursor()
<< TPlacement.UpdateWindowCursor()
>> TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindow()
<< TPlacement.ReduceWindow()
hit 248,21 VideoEnabled = FALSE Placement.WindowSize = 2
height = 720
>> TPlacement.ExposeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
<< TPlacement.ExposeWindow()
hit 248,21 VideoEnabled = FALSE Placement.WindowSize = 2
height = 720
>> TPlacement.ExposeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
<< TPlacement.ExposeWindow()
>> TPlacement.ReduceWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
>> TPlacement.UpdateWindow()
>> TPlacement.UpdateWindowBounds()
<< TPlacement.UpdateWindowBounds()
>> TPlacement.UpdateWindowClient()
>> TPlacement.UpdateBuffer()
<< TPlacement.UpdateBuffer()
<< TPlacement.UpdateWindowClient()
>> TPlacement.UpdateWindowCursor()
<< TPlacement.UpdateWindowCursor()
>> TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindowPlacement()
<< TPlacement.UpdateWindow()
<< TPlacement.ReduceWindow()
hit 146,33 VideoEnabled = FALSE Placement.WindowSize = 1
height = 480
>> TPlacement.ExposeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
<< TPlacement.ExposeWindow()
hit 146,33 VideoEnabled = FALSE Placement.WindowSize = 1
height = 480
>> TPlacement.ExposeWindow()
>> TPlacement.UpdateMonitor()
<< TPlacement.UpdateMonitor()
<< TPlacement.ExposeWindow()
But that might perhaps require a step by step explanation of order of actions taken accompanied with it.
« Last Edit: March 25, 2024, 04:05:47 am by TRon »
All software is open source (as long as you can read assembler)

furious programming

  • Hero Member
  • *****
  • Posts: 864
Re: Fairtris 2: The Ultimate Challenge
« Reply #36 on: March 25, 2024, 05:09:05 pm »
Quote
Now press the - key to reduce the window size once. From now, you should see in the console one of the following two lines:
Result
Code: [Select]
Hit-test! Video: FALSE | Size: SIZE_ZOOM_3X    | Result: SDL_HITTEST_NORMAL
Hit-test! Video: FALSE | Size: SIZE_ZOOM_3X    | Result: SDL_HITTEST_DRAGGABLE

If this is what you see after reducing window from desktop fullscreen, everything works correctly. Note that on Windows, the hit-test callback is invoked by the SDL not only after pressing the mouse button, but also during normal cursor movement over the window. However, this doesn't matter.

Quote
The instructions with explanations you provided in the posts is exactly why I believe there is something wrong with the logic or the order of the logic. Mind, it is just a hunch not a fact.

Yeah, I know. But keep in mind that dragging the window is not implemented in the Fairtris source code — it is entirely handled by the SDL. As long as FVideoEnabled and FWindowSize have correct values, dragging the window should works fine, because hit-test callback will always return appropriate values.

The window position is not controlled by the game code. The only situation when the game modifies the position of the window is when you invoke window size change — by pressing + or - key (or scrolling mouse wheel or changing the window size in the game options menu). In such case, the game changes the window size and centers the window on the current display. No matter how you change the window size, if exclusive fullscreen is disabled, the UpdateWindow method is called — for desktop fullscreen and all windowed modes. But the UpdateWindow method is not called during dragging the window.

However, during moving the window, the game code only updates placement data, without modifying them and without changing the window position. So, the SDL has a full control over dragging the window. And because of that, I have no reason to think that the game code is somehow preventing from dragging the window.



In summary, the only reason window dragging would work badly due to buggy game code would be if FVideoEnabled was set to False, FWindowSize was set to anything other than SIZE_FULLSCREEN (e.g. SIZE_ZOOM_3X), and yet the callback returned SDL_HITTEST_NORMAL for the left button press in the upper area of the window.

But from what I can see from your logs, this situation does not occur at all — FVideoEnabled is correctly set to False, FWindowSize contains the correct SIZE_ZOOM_3X value, and the callback returns SDL_HITTEST_NORMAL or SDL_HITTEST_DRAGGABLE, depending on where in the window the left mouse button is pressed. And if so, everything on the application side is correct, so the problem must be related to the SDL itself.
« Last Edit: March 26, 2024, 02:01:10 pm by furious programming »
Lazarus 3.4 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an arcade, action/adventure game in retro style (pixel art), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

furious programming

  • Hero Member
  • *****
  • Posts: 864
Re: Fairtris 2: The Ultimate Challenge
« Reply #37 on: March 27, 2024, 03:40:11 am »
New version is available — Fairtris 2.1.2
Lazarus 3.4 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an arcade, action/adventure game in retro style (pixel art), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

 

TinyPortal © 2005-2018