Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2018-04

Drag (and show) images

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Donald Ziesig

Hi All!

I am trying to write an app that allows me to drag images and show them while they are being dragged (like the cards in Solitaire).

I have been able to drag images (showing only the drag cursor) and drop them appropriately, but I haven't been able to find any recent documentation showing the use of TDragImageList and TDragObject.

The only articles that I have found are for Delphi from 2011 (which translates to Lazarus but doesn't work correctly) and some more recent that don't show the dragged image while the drag is taking place (I have that part working).

I was able to show a dragged image by adding code to the DragOver event, but that seems to take more time than it should.

Can anyone point me in the right direction for this?

Thanks,

Don Ziesig

Reply by email

Graeme Geldenhuys
to Donald Ziesig
Donald Ziesig wrote
Can anyone point me in the right direction for this?

I've never really compared LCL's drag-n-drop implementation with fpGUI's
- but they might be similar in some way. Anyway, fpGUI' visual forms designer - the fpGUI's UI Designer (<fpgui>/uidesigner/ directory) does just that. You can drag components from the component palette to the designer form, and it shows you the drag cursor and a image of the rendered widget/component while you are dragging. Maybe that might give you some ideas - or not.

The above is obviously different from dragging already placed widgets on a form - because that is simply moving the widget.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Werner Pamler
to Donald Ziesig: Hi All! I am trying to write an app that allows me to drag images and show them while…
Donald Ziesig wrote 16 lines
I am trying to write an app that allows me to drag images and show them while they are being dragged (like the cards in Solitaire). I have been able to drag images (showing only the drag cursor) and drop them appropriately, but I haven't been able to find any recent documentation showing the use of TDragImageList and TDragObject. The only articles that I have found are for Delphi from 2011 (which translates to Lazarus but doesn't work correctly) and some more recent that don't show the dragged image while the drag is taking place (I have that part working). I was able to show a dragged image by adding code to the DragOver event, but that seems to take more time than it should. Can anyone point me in the right direction for this?

There is a sample in folder examples/dragimagelist of your Lazarus installation - maybe it gets close to what you need?

Reply by email

Donald Ziesig
to Werner Pamler
Werner Pamler wrote 20 lines
Am 12.04.2018 um 00:02 schrieb Donald Ziesig via Lazarus: > I am trying to write an app that allows me to drag images and show > them while they are being dragged (like the cards in Solitaire). > > I have been able to drag images (showing only the drag cursor) and > drop them appropriately, but I haven't been able to find any recent > documentation showing the use of TDragImageList and TDragObject. > > The only articles that I have found are for Delphi from 2011 (which > translates to Lazarus but doesn't work correctly) and some more > recent that don't show the dragged image while the drag is taking > place (I have that part working). > > I was able to show a dragged image by adding code to the DragOver > event, but that seems to take more time than it should. > > Can anyone point me in the right direction for this? There is a sample in folder examples/dragimagelist of your Lazarus installation - maybe it gets close to what you need?

You're right.  It gets *close* but not quite there.  I can move the control so long as the mouse is *not* over the control while it is moving :-(. I will look at this closer in the morning and see if I can work around it (or if there is something I am missing).

Thanks!

Don

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180412/24dd411d/attachment.html>

Reply by email

Giuliano Colla
to Donald Ziesig

Il 13/04/2018 02:40, Donald Ziesig via Lazarus ha scritto:

Show quoted text 5 lines
You're right.  It gets *close* but not quite there.  I can move the control so long as the mouse is *not* over the control while it is moving :-(. I will look at this closer in the morning and see if I can work around it (or if there is something I am missing).

You might find useful, as a guideline, the code I'm using in one of my application to drag a button so that it doesn't cover the useful part of an image. Just using the OnMouseDown, OnMouseMove and OnMouseUp of your TImage, and getting rid of the code you don't need, to perform an extra action on OnMouseUp, you should be able to do the trick.

Show quoted text 46 lines
  TErrForm = class(TForm) ......   protected     ResetDragged: Boolean;     CursorPos: TPoint;     ObjectPos: TPoint; .... procedure TErrForm.ResetBtnMouseDown(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X: LongInt; Y: LongInt); begin   ResetDragged := True;   CursorPos.X := Mouse.CursorPos.X;   CursorPos.Y := Mouse.CursorPos.Y;   with ResetBtn do begin;     ObjectPos.X := Left;     ObjectPos.Y := Top;     end; end; procedure TErrForm.ResetBtnMouseMove(Sender: TObject; Shift: TShiftState;   X: LongInt; Y: LongInt); begin   if ResetDragged then begin     with ResetBtn do begin       Left := ObjectPos.X + (Mouse.CursorPos.X - CursorPos.X);       Top := ObjectPos.Y +  (Mouse.CursorPos.Y - CursorPos.Y);       ResetPos.X := (Left * NormalGeometry.ClientWidth div CurrImage.Width) + HorzScrollBar.Position;       ResetPos.Y := (Top * NormalGeometry.ClientHeight div CurrImage.Height) + VertScrollBar.Position;       end;     end; end; procedure TErrForm.ResetBtnMouseUp(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X: LongInt; Y: LongInt); begin   if ResetDragged then begin     ResetDragged := False;     Paint;     end;   if (abs(Mouse.CursorPos.X - CursorPos.X) < 10) and (abs(Mouse.CursorPos.Y - CursorPos.Y)< 10) then Close; end;

Hope that it helps.

Giuliano

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180413/b8bc4097/attachment.html>

Reply by email

Donald Ziesig
to Giuliano Colla
Giuliano Colla wrote 68 lines
Il 13/04/2018 02:40, Donald Ziesig via Lazarus ha scritto: > You're right.  It gets *close* but not quite there.  I can move the > control so long as the mouse is *not* over the control while it is > moving :-(. I will look at this closer in the morning and see if I > can work around it (or if there is something I am missing). > You might find useful, as a guideline, the code I'm using in one of my application to drag a button so that it doesn't cover the useful part of an image. Just using the OnMouseDown, OnMouseMove and OnMouseUp of your TImage, and getting rid of the code you don't need, to perform an extra action on OnMouseUp, you should be able to do the trick. >   TErrForm = class(TForm) > ...... >   protected >     ResetDragged: Boolean; >     CursorPos: TPoint; >     ObjectPos: TPoint; > .... > > procedure TErrForm.ResetBtnMouseDown(Sender: TObject; Button: > TMouseButton; >   Shift: TShiftState; X: LongInt; Y: LongInt); > begin >   ResetDragged := True; >   CursorPos.X := Mouse.CursorPos.X; >   CursorPos.Y := Mouse.CursorPos.Y; >   with ResetBtn do begin; >     ObjectPos.X := Left; >     ObjectPos.Y := Top; >     end; > end; > > procedure TErrForm.ResetBtnMouseMove(Sender: TObject; Shift: TShiftState; >   X: LongInt; Y: LongInt); > begin >   if ResetDragged then begin >     with ResetBtn do begin >       Left := ObjectPos.X + (Mouse.CursorPos.X - CursorPos.X); >       Top := ObjectPos.Y +  (Mouse.CursorPos.Y - CursorPos.Y); >       ResetPos.X := (Left * NormalGeometry.ClientWidth div > CurrImage.Width) + HorzScrollBar.Position; >       ResetPos.Y := (Top * NormalGeometry.ClientHeight div > CurrImage.Height) + VertScrollBar.Position; >       end; >     end; > end; > > procedure TErrForm.ResetBtnMouseUp(Sender: TObject; Button: TMouseButton; >   Shift: TShiftState; X: LongInt; Y: LongInt); > begin >   if ResetDragged then begin >     ResetDragged := False; >     Paint; >     end; >   if (abs(Mouse.CursorPos.X - CursorPos.X) < 10) and > (abs(Mouse.CursorPos.Y - CursorPos.Y)< 10) then Close; > end; Hope that it helps. Giuliano

Hi Giuliano!

It works perfectly. 8-) The best part is that it doesn't use any poorly documented library code and it doesn't hog the CPU either.

Many thanks,

Don

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180413/dd6aac78/attachment.html>

Reply by email