Open coderextreme opened 4 months ago
Implementation notes (to self, or to any brave contributor that would like to submit pull request solving this -- we welcome it, it's an easy task, and you can learn Pascal, and GTK or WinAPI, and some Castle Game Engine along the way!) :
This task should be done in Castle Game Engine, https://github.com/castle-engine/castle-engine/ . There's likely zero code modification actually necessary to castle-model-viewer code (in this repo, https://github.com/castle-engine/castle-model-viewer/ ) to make it work.
For macOS, this shall be already working.
Requires dedicated code for Linux/FreeBSD/etc. (using current GTK2 backend, soon GTK3, but this change is likely very compatible to all GTK versions). The relevant code is in src/window/gtk/castlewindow_gtk.inc
( https://github.com/castle-engine/castle-engine/blob/master/src/window/gtk/castlewindow_gtk.inc ). The task is to somehow register for GTK event (using callback) to know "when user drags and drops files on this window" and then call DoDropFiles
(procedure TCastleWindow.DoDropFiles(const FileNames: array of string);
).
Similarly, requires dedicated code for Windows. The relevant code is in src/window/windows/castlewindow_winapi.inc
( https://github.com/castle-engine/castle-engine/blob/master/src/window/windows/castlewindow_winapi.inc ). The task is similar to Linux: somehow register (using WinAPI call) to know "when user drags and drops files on this window" and then call DoDropFiles
.
On the user side (developer using the engine through TCastleWindow), one can observe the files being dropped using TCastleWindow.OnDropFiles
. The castle-model-viewer code already listens and reacts to this event ( https://github.com/castle-engine/castle-model-viewer/blob/master/castle_model_viewer.dpr#L1329 implements DropFiles
callback). So, if you do the above-described tasks on the Windows and GTK backends, the rest should "just work" -- castle-model-viewer will react to files being dropped on it.
This appears to be an OLE thing on Windows:
https://learn.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-registerdragdrop
One must implement an interface.
I wonder if this feature is already available in some version of GDK.
I will do some more searching and report back.
John
On Wed, May 15, 2024 at 11:58 AM Michalis Kamburelis < @.***> wrote:
Implementation notes (to self, or to any brave contributor that would like to submit pull request solving this -- we welcome it, it's an easy task, and you can learn Pascal, and GTK or WinAPI, and some Castle Game Engine along the way!) :
-
This task should be done in Castle Game Engine, https://github.com/castle-engine/castle-engine/ . There's likely zero code modification actually necessary to castle-model-viewer code (in this repo, https://github.com/castle-engine/castle-model-viewer/ ) to make it work.
For macOS, this shall be already working.
Requires dedicated code for Linux/FreeBSD/etc. (using current GTK2 backend, soon GTK3, but this change is likely very compatible to all GTK versions). The relevant code is in src/window/gtk/castlewindow_gtk.inc ( https://github.com/castle-engine/castle-engine/blob/master/src/window/gtk/castlewindow_gtk.inc ). The task is to somehow register for GTK event (using callback) to know "when user drags and drops files on this window" and then call DoDropFiles (procedure TCastleWindow.DoDropFiles(const FileNames: array of string);).
Similarly, requires dedicated code for Windows. The relevant code is in src/window/windows/castlewindow_winapi.inc ( https://github.com/castle-engine/castle-engine/blob/master/src/window/windows/castlewindow_winapi.inc ). The task is similar to Linux: somehow register (using WinAPI call) to know "when user drags and drops files on this window" and then call DoDropFiles.
On the user side (developer using the engine through TCastleWindow), one can observe the files being dropped using TCastleWindow.OnDropFiles. The castle-model-viewer code already listens and reacts to this event ( https://github.com/castle-engine/castle-model-viewer/blob/master/castle_model_viewer.dpr#L1329 implements DropFiles callback). So, if you do the above-described tasks on the Windows and GTK backends, the rest should "just work" -- castle-model-viewer will react to files being dropped on it.
— Reply to this email directly, view it on GitHub https://github.com/castle-engine/castle-model-viewer/issues/95#issuecomment-2113034425, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFMJ53JMYEZNS67IN24KILZCOH4FAVCNFSM6AAAAABHWMD5V6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJTGAZTINBSGU . You are receiving this because you authored the thread.Message ID: @.***>
Here is GDK information I found, but I am unsure which version:
https://refspecs.linuxbase.org/gtk/2.6/gdk/gdk-Drag-and-Drop.html
Well, it looks like GDK 2, so perfect.
Probably CGE does not compile against GDK 2 on Windows. Waiting for a recent GDK version may solve the Windows port, if GDK supports DnD on Windows. I am not sure if adding layers is desirable on Windows.
I am not prepared to do any C/C++ compiling in Visual Studio, but I have recently used GTK 4 using gcc.
I have only set up CGE in Docker, so someone may beat me to it. I realize that not everyone run Windows. I will do some searching on how to set up a CGE dev environment on Windows.
On Thu, May 16, 2024 at 9:30 AM John Carlson @.***> wrote:
This appears to be an OLE thing on Windows:
https://learn.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-registerdragdrop
One must implement an interface.
I wonder if this feature is already available in some version of GDK.
I will do some more searching and report back.
John
On Wed, May 15, 2024 at 11:58 AM Michalis Kamburelis < @.***> wrote:
Implementation notes (to self, or to any brave contributor that would like to submit pull request solving this -- we welcome it, it's an easy task, and you can learn Pascal, and GTK or WinAPI, and some Castle Game Engine along the way!) :
-
This task should be done in Castle Game Engine, https://github.com/castle-engine/castle-engine/ . There's likely zero code modification actually necessary to castle-model-viewer code (in this repo, https://github.com/castle-engine/castle-model-viewer/ ) to make it work.
For macOS, this shall be already working.
Requires dedicated code for Linux/FreeBSD/etc. (using current GTK2 backend, soon GTK3, but this change is likely very compatible to all GTK versions). The relevant code is in src/window/gtk/castlewindow_gtk.inc ( https://github.com/castle-engine/castle-engine/blob/master/src/window/gtk/castlewindow_gtk.inc ). The task is to somehow register for GTK event (using callback) to know "when user drags and drops files on this window" and then call DoDropFiles (procedure TCastleWindow.DoDropFiles(const FileNames: array of string);).
Similarly, requires dedicated code for Windows. The relevant code is in src/window/windows/castlewindow_winapi.inc ( https://github.com/castle-engine/castle-engine/blob/master/src/window/windows/castlewindow_winapi.inc ). The task is similar to Linux: somehow register (using WinAPI call) to know "when user drags and drops files on this window" and then call DoDropFiles.
On the user side (developer using the engine through TCastleWindow), one can observe the files being dropped using TCastleWindow.OnDropFiles. The castle-model-viewer code already listens and reacts to this event ( https://github.com/castle-engine/castle-model-viewer/blob/master/castle_model_viewer.dpr#L1329 implements DropFiles callback). So, if you do the above-described tasks on the Windows and GTK backends, the rest should "just work" -- castle-model-viewer will react to files being dropped on it.
— Reply to this email directly, view it on GitHub https://github.com/castle-engine/castle-model-viewer/issues/95#issuecomment-2113034425, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFMJ53JMYEZNS67IN24KILZCOH4FAVCNFSM6AAAAABHWMD5V6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJTGAZTINBSGU . You are receiving this because you authored the thread.Message ID: @.***>
Our GTK backend supports only Unix now, not Windows.
Reasons: In principle, GTK works on Windows too, but it required various tweaks, and then context initialization would require to combine GTK + wgl. It is possible, and it was working in the past, but we consciously removed that possibility -- because of low practical usage. In the end, every Windows developer wanted to use WinAPI backend, not GTK. And trying to extend GTK backend by testing only "GTK on Windows" would be doomed, since you should actually test it when users use it, which is on Linux.
So, the simplest answer: You need Linux (real or in virtual machine) to test GTK backend. If you are on Windows, using WSL is actually the simplest way to "get Linux inside your Windows box". But if you are also new to Linux, I advise to just install Linux as a regular system on your computer.
I have installed Linux in the past, but there were issues with the mouse being trapped, and I'd have to go to the console to free it. This would then happen again. Rinse, repeat.
John
On Fri, May 17, 2024 at 6:09 AM Michalis Kamburelis < @.***> wrote:
Our GTK backend supports only Unix now, not Windows.
Reasons: In principle, GTK works on Windows too, but it required various tweaks, and then context initialization would require to combine GTK + wgl. It is possible, and it was working in the past, but we consciously removed that possibility -- because of low practical usage. In the end, every Windows developer wanted to use WinAPI backend, not GTK. And trying to extend GTK backend by testing only "GTK on Windows" would be doomed, since you should actually test it when users use it, which is on Linux.
So, the simplest answer: You need Linux (real or in virtual machine) to test GTK backend. If you are on Windows, using WSL is actually the simplest way to "get Linux inside your Windows box". But if you are also new to Linux, I advise to just install Linux as a regular system on your computer.
— Reply to this email directly, view it on GitHub https://github.com/castle-engine/castle-model-viewer/issues/95#issuecomment-2117337455, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFMJ5ZFS5B7QWOYI4WDE53ZCXQOTAVCNFSM6AAAAABHWMD5V6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJXGMZTONBVGU . You are receiving this because you authored the thread.Message ID: @.***>
Okay, I have created a new source environment for engine, now going to look at Windows Drag and Drop.
Note: On Windows the solution is in https://github.com/castle-engine/castle-engine/pull/608 (only pending review now, but looks good :) ).
From Discord:
Question, can I drag and drop files into the model viewer?
Request approved by Michalis.