Recent

Author Topic: SDL2 drag and drop image [SOLVED]  (Read 2486 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 590
Re: SDL2 drag and drop image
« Reply #15 on: November 23, 2024, 09:47:12 am »
Why is there a function “ SDL_DROPFILE” as it does not work.
And if it works there is no example of correct usage.

jamie

  • Hero Member
  • *****
  • Posts: 6791
Re: SDL2 drag and drop image
« Reply #16 on: November 23, 2024, 04:38:09 pm »
Shooting from the hip, because I am stupid, have you tried enabling the "AllowDropFiles" in the form?

Jamie
The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 3791
Re: SDL2 drag and drop image
« Reply #17 on: November 23, 2024, 04:47:19 pm »
@Jamie:
That wouldn't help in any way.

The SDL eventloop is never ran.

@Pe3s:
Normally SDL creates its own window and takes responsibility for 'catching' the events that are generated from the 'outside'. Because the SDL window is embedded in a LCL control SDL is not able to take care of that unless running in a SDL eventloop (again: a loop that is never ran).


So, use the form drag and drop events.

Anything else is just pure speculation because there is no description of what the end-goal actually is.

As I wrote before, the concept of your solution simply does not compute.

And no matter what, either using form events or SDL events the code still needs to handle those events and actually do something with the filename. It does not matter where that exactly is done (in SDL or LCL).

In basics the SDL in the panel right now is nothing more than a glorified image control and should be treated the same.
« Last Edit: November 23, 2024, 04:49:37 pm by TRon »
I do not have to remember anything anymore thanks to total-recall.

Pe3s

  • Hero Member
  • *****
  • Posts: 590
Re: SDL2 drag and drop image
« Reply #18 on: November 23, 2024, 04:56:55 pm »
I want to open the dropped file as it is done via open dialog.
the sdl window does not support dropping files. OnDropFiles of Lazarus. If we drop them on the form, they load, but most of the window is occupied by the sdl window.
The matter would be simple if the sdl window inherited the lcl event handler

jamie

  • Hero Member
  • *****
  • Posts: 6791
Re: SDL2 drag and drop image
« Reply #19 on: November 23, 2024, 04:59:57 pm »
Ok, I know in windows you need to register the window handle for it to receive drop file notifications.

In other targets, I have no idea.
The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 3791
Re: SDL2 drag and drop image
« Reply #20 on: November 23, 2024, 05:01:32 pm »
The matter would be simple if the sdl window inherited the lcl event handler
Yes, that would solve it but SDL doesn't (how could it ?).

As a test you could try an use the onidle event of the application to run your SDL event poll and see if SDL at least generates the event.

In case that doesn't work then the only way that I know of is to use the form events and handling things manually.
« Last Edit: November 23, 2024, 05:05:37 pm by TRon »
I do not have to remember anything anymore thanks to total-recall.

jamie

  • Hero Member
  • *****
  • Posts: 6791
Re: SDL2 drag and drop image
« Reply #21 on: November 23, 2024, 05:16:47 pm »
Last time I remember, those Messages from the OS in windows are blocked and only the embedded support for the drag and drop that the LCL works because it's handled elsewhere to allow it. But basically, they are blocked thus you need to actually hook into the message event to see it.

 I've ported over code from Delphi doing Drag and Drop and wouldn't work in the LCL because of these messages being blocked and had to resort to hooking it.

 I do have a unit to make it easy to insert blocked messages for the form but its only for the LCL/Laz because Delphi does not have this issue.

 Have a good day.

Jamie


 
The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 3791
Re: SDL2 drag and drop image
« Reply #22 on: November 23, 2024, 05:20:32 pm »
Indeed, something like that should be able to do the trick jamie.

However these kind of things are usually not for the casual user.

There is a reason I hinted at having a look at the gl controls because they need to do something similar and based on that one could probably come up with an embedded SDL control (in case it doesn't exist yet).
I do not have to remember anything anymore thanks to total-recall.

jamie

  • Hero Member
  • *****
  • Posts: 6791
Re: SDL2 drag and drop image
« Reply #23 on: November 23, 2024, 06:14:12 pm »
On the windows side of things, it's possible the whole thing is blocked and even the LCL support may not work if you have one these conditions.

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-changewindowmessagefilterex
 This also has something to do with app elevations permissions.
Jamie
The only true wisdom is knowing you know nothing

Pe3s

  • Hero Member
  • *****
  • Posts: 590
Re: SDL2 drag and drop image
« Reply #24 on: November 24, 2024, 09:19:59 am »
Thank you for your help in solving the problem.
Application.OnIdle solved the problem

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ApplicationIdle(Sender: TObject; var Done: Boolean);
  2. begin
  3.   ProcessSDLEvents;
  4.   Done := False;
  5. end;
  6.  

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormShow(Sender: TObject);
  2. begin
  3.   InitializeSDL;
  4.   Application.OnIdle := @ApplicationIdle;
  5. end;
  6.  

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormDestroy(Sender: TObject);
  2. begin
  3.   Application.OnIdle := nil;
  4.   ShutdownSDL;
  5. end;
  6.  

 

TinyPortal © 2005-2018