dirkil2
asked on
Delphi: How to implement marching ants selection box with graphics32?
Hi there!
I am fairly new to graphics32 and unfortunately documentation about it is very sparse.
On a TImage32 I would like to let the user mark a rectangular area with the mouse as usual by clicking with the left mouse button to mark the start and then dragging the mouse with a pressed left mouse button until the rectangle like he wants it. When the user releases the left mouse button the area he defined should be marked with a rectangle (TPolygon32?) so that the border of the rectangle shows marching ants.
If someone could write me a little sample I would be very happy.
Regards,
Dirk.
I am fairly new to graphics32 and unfortunately documentation about it is very sparse.
On a TImage32 I would like to let the user mark a rectangular area with the mouse as usual by clicking with the left mouse button to mark the start and then dragging the mouse with a pressed left mouse button until the rectangle like he wants it. When the user releases the left mouse button the area he defined should be marked with a rectangle (TPolygon32?) so that the border of the rectangle shows marching ants.
If someone could write me a little sample I would be very happy.
Regards,
Dirk.
ASKER
Hi epasquier,
thank you for your code but it didn't work for me. You didn't provide the dfm file so I had to experiment a little. I added a TImage and called it img1. I also assigned an image to the Picture property. Furthermore, I attached OnMouseDown, OnMouseUp and OnMouseMove to the callbacks you provided.
What happened is the following: as soon as I click with the left mouse button the image is cleared (looks like the backfround of the window). Even when I unassign the Picture (blank background) I never see a rect.
Maybe I did something wrong. Maybe it makes sense if you can provide the whole project to make sure I have everything as you have it.
Regards,
Dirk.
thank you for your code but it didn't work for me. You didn't provide the dfm file so I had to experiment a little. I added a TImage and called it img1. I also assigned an image to the Picture property. Furthermore, I attached OnMouseDown, OnMouseUp and OnMouseMove to the callbacks you provided.
What happened is the following: as soon as I click with the left mouse button the image is cleared (looks like the backfround of the window). Even when I unassign the Picture (blank background) I never see a rect.
Maybe I did something wrong. Maybe it makes sense if you can provide the whole project to make sure I have everything as you have it.
Regards,
Dirk.
You did exactly what you had to do not having the DFM files.
are you using TImage or another derived component ?
check what you have in _StartImg after :
_StartImg.Assign(img1.Pict ure.Bitmap );
that is the background I save on the original click to be able to draw a moving rectangle while selecting the zone.
I will give you the exe later this day so that you can check at least that it is what you want.
are you using TImage or another derived component ?
check what you have in _StartImg after :
_StartImg.Assign(img1.Pict
that is the background I save on the original click to be able to draw a moving rectangle while selecting the zone.
I will give you the exe later this day so that you can check at least that it is what you want.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi epasquier!
Great that you found where the problem was. This is almost what I wanted to have. The only thing left is that the "marching ants" are not marching yet. It is just a rect with a dotted line. I would like to have the line animated. So if the line pattern is 00110011 at the beginning it should be 11001100 half a second later and then half a second later back to the starting pattern and so on. Any idea how I can achieve that?
Regards,
Dirk.
Great that you found where the problem was. This is almost what I wanted to have. The only thing left is that the "marching ants" are not marching yet. It is just a rect with a dotted line. I would like to have the line animated. So if the line pattern is 00110011 at the beginning it should be 11001100 half a second later and then half a second later back to the starting pattern and so on. Any idea how I can achieve that?
Regards,
Dirk.
I don't think it's possible with GDI (therefore by Delphi Canvas object), you would have to use GDI+ library to create a custom pattern for your pen
I'm not sure that it would be worth the trouble
I'm not sure that it would be worth the trouble
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@NevTon
Thanks for the great links you provided.
In my initial posting I mentioned that I use the graphics32 library for drawing. In the meantime I checked out a few more of the many sample programs that come with that library and in one of them (Transform demo, switch to projective tab) I found a selection with marching ants. I analysed the code and found to my surprise that the library has that functionality built-in! It's called TRubberband and you can put it on a separate layer which is very easy to use.
Thank you for your contributions - I will split the points between you. I hope you're ok with that.
Thanks for the great links you provided.
In my initial posting I mentioned that I use the graphics32 library for drawing. In the meantime I checked out a few more of the many sample programs that come with that library and in one of them (Transform demo, switch to projective tab) I found a selection with marching ants. I analysed the code and found to my surprise that the library has that functionality built-in! It's called TRubberband and you can put it on a separate layer which is very easy to use.
Thank you for your contributions - I will split the points between you. I hope you're ok with that.
Open in new window