ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 rubber stamping shapes
 New Topic  Reply to Topic
Author  Topic Next Topic  

email_toan

USA
29 Posts

Posted - Apr 21 2025 :  10:18:07  Show Profile  Reply
I'd like to allow users to add shape layers, however I'd like to temporarily change the mouse cursor to the selected shape. That way, users can preview and position the shape prior to "rubber stamping" the shape layer. It is similar to Photoshop Brush where the cursor changes to a circle.

I was thinking of creating a temporary layer and responding to mousemove event, but wanted to know if there is an easier way or if the feature already exists.

Any help would be appreciated.

xequte

38955 Posts

Posted - Apr 21 2025 :  21:50:11  Show Profile  Reply
Yes, you can do it like this:

procedure Tfmain.btnStarStampClick(Sender: TObject);
const
  Stamp_Border_Color = clRed;
  Stamp_Border_Width = 2;
  Stamp_Fill_Color   = clYellow;
  Stamp_Shape        = iesStar5;
  Stamp_Width        = 50;
  Stamp_Height       = 50;
var
  cursorBMP: TIEBitmap;
begin
  // Add a star every time the layer clicks on the image
  // Note: Can also use OnNewLayer event to customize layer

  // Set default styles
  ImageEnView1.LayerDefaults.Clear();
  ImageEnView1.LayerDefaults.Values[ IELP_BorderColor ] := ColorToString( Stamp_Border_Color );
  ImageEnView1.LayerDefaults.Values[ IELP_BorderWidth ] := IntToStr( Stamp_Border_Width );
  ImageEnView1.LayerDefaults.Values[ IELP_FillColor ] := ColorToString( Stamp_Fill_Color );
  // Easier to use DefaultLayerShape... ImageEnView1.LayerDefaults.Values[ IELP_Shape  ]    := IntToStr( Ord( Stamp_Shape ));
  ImageEnView1.LayerDefaults.Values[ IELP_Width ]     := IntToStr( Stamp_Width );
  ImageEnView1.LayerDefaults.Values[ IELP_Height ]    := IntToStr( Stamp_Height );

  ImageEnView1.LayerOptions := ImageEnView1.LayerOptions + [ loStampMode ];
  IEGlobalSettings().DefaultLayerShape := Stamp_Shape;
  ImageEnView1.MouseInteractLayers := [mlCreateShapeLayers];

  // Show a matching star shaped cursor
  cursorBMP := TIEBitmap.Create( Stamp_Width, Stamp_Height, clWhite, 0 {Transparent background} );
  try
    cursorBMP.FillWithShape( Stamp_Shape, Stamp_Width, Stamp_Height, Stamp_Border_Color, Stamp_Border_Width, Stamp_Fill_Color, True, False );
    ImageEnView1.SetZoneCursorBitmap( cursorBMP );
  finally
    cursorBMP.Free;
  end;
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

email_toan

USA
29 Posts

Posted - Apr 24 2025 :  17:29:02  Show Profile  Reply
Thanks for the code Nigel.

I'm running into an issue where passing Nil to SetZoneCursorBitmap sometime causes the cursor to disappear.

I've tried setting the self.cursor to crDefault on top of passing Nil to SetZoneCursorBitmap. It doesn't seem to resolve the issue.

Suggestions?

tn
Go to Top of Page

xequte

38955 Posts

Posted - Apr 25 2025 :  00:56:16  Show Profile  Reply
Hi

Can you test setting

ZoneCursor := iecsDefault;

Afterwards?

Also, ensure you call Update().

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

email_toan

USA
29 Posts

Posted - Apr 25 2025 :  13:13:56  Show Profile  Reply
OK, I found the issue. I needed to call SetZoneCursorBitmap(nil) prior to reloading with new a background image.
Go to Top of Page

xequte

38955 Posts

Posted - Apr 25 2025 :  17:12:07  Show Profile  Reply
Sorry, do you mean this is needed:

ImageEnView1.SetZoneCursorBitmap( nil);
ImageEnView1.IO.LoadFromFile( 'D:\image.jpg' );
ImageEnView1.SetZoneCursorBitmap( fCursorBMP );


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

email_toan

USA
29 Posts

Posted - Apr 25 2025 :  18:27:25  Show Profile  Reply
Yes, if I don't do that, the cursor eventually disappears after several image loads.
Go to Top of Page

xequte

38955 Posts

Posted - Apr 25 2025 :  21:43:26  Show Profile  Reply
Sorry, I am unable to reproduce that.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
   Topic Next Topic  
 New Topic  Reply to Topic
Jump To: