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
 Using BrushTool with code only (no mouse used)
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Sybren

34 Posts

Posted - Sep 18 2018 :  14:01:26  Show Profile  Reply
I'm trying to repaint an image using the BrushTool possibilities. This way I can create a kind of cool graffiti effect. Scrolling over the 'brush' forum topics, I couldn't find an answer.

The code I'm currently using is based on program code to actually move the mouse between two points (I can't seem the mouse to continuously move over more than 2 points), while 'pressing' the left mouse button:

procedure TForm1.Button1Click(Sender: TObject);
var
  i, j: integer;
  Pt, St: TPoint;
begin
   { Define the starting point = left-top corner of image 'RightImg' }
   { 10 pixels from the left-top edges }
   St.x := RightImg.Left + 10;
   St.y := RightImg.Top + 10; 
   { draw 25 random brush lines within the boundaries of the image }
   for j := 1 to 25 do 
   begin 
     { required to draw one brush line }
     for i := 1 to 2 do
     begin  
      { effectively 10 pixels from the right-bottom edges }
      Pt.X := St.X + random(RightImg.Width - 20);
      Pt.Y := St.Y + random(RightImg.Height - 20);
      { Convert Pt to screen coordinates relative to the 65535 mouse-steps across the screen }
      Pt := ClientToScreen(Pt);
      Pt.x := Round(Pt.x * (65535 / Screen.Width));
      Pt.y := Round(Pt.y * (65535 / Screen.Height));
      { Simulate the mouse move }
      Mouse_Event(MOUSEEVENTF_ABSOLUTE or
                  MOUSEEVENTF_MOVE,
                  Pt.x, Pt.y, 0, 0);
      { Simulate the left mouse button down }
      if i = 1 then Mouse_Event(MOUSEEVENTF_ABSOLUTE or
                  MOUSEEVENTF_LEFTDOWN,
                  Pt.x, Pt.y, 0, 0);
      { Simulate the left mouse button up }
      if i = 2 then Mouse_Event(MOUSEEVENTF_ABSOLUTE or
                  MOUSEEVENTF_LEFTUP,
                  Pt.x, Pt.y, 0, 0);
    end; 
    { optional when 'Application.ProcessMessages' is used }
    RightImg.Update;
    { optional: to watch the painting take place }
    Application.ProcessMessages; 
  end;
end;

Additional settings to activate the BrushTool:

  RightImg.BrushTool.BrushShape := iecsCircle;
  RightImg.BrushTool.BrushFill := iebfTextured;
  RightImg.BrushTool.BrushSize := 50;
  RightImg.BrushTool.BrushColor := clRed;
  RightImg.MouseInteract := [miBrushTool];
  RightImg.BrushTool.PaintMode := iepmContinuous;

The code works fine, and I can see an animated brush drawing random lines.
However, I'd like to avoid the mouse events. When the application runs I don't like the idea of 'hijacking' the mouse for this effect. My preferred solution would be to use code to move the brush in the background, with no mouse interactions required, and then show it after a final refresh.

Can this be done?

Thanks for your support,
Sybren

xequte

39053 Posts

Posted - Sep 18 2018 :  16:59:21  Show Profile  Reply
Hi Sybren

I'm sorry, there are actually some useful methods for this, but they are not easily discoverable in the documentation (I will improve that).

Please see:

https://www.imageen.com/help/TIEBrushToolInteraction.StartPainting.html

Which will allow you to achieve this without faking mouse movements.




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

Sybren

34 Posts

Posted - Sep 19 2018 :  05:43:42  Show Profile  Reply
Hi Nigel,

Thank you for your prompt response.

I tried to apply the example code, but it seems that these (e.g. '.StartPainting') are actions of the TImageEnView component?

Sorry to say... I'm not familiar with actions. Perhaps a simple hint or example how to use the code is very welcome.

Thanks for your support.

Sybren
Go to Top of Page

xequte

39053 Posts

Posted - Sep 20 2018 :  01:30:07  Show Profile  Reply
Sorry Sybren,

I just remembered, those are not public properties in 8.1.0. I will make them so in 8.1.1 (next week).


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

Sybren

34 Posts

Posted - Oct 07 2018 :  14:52:12  Show Profile  Reply
Hi Nigel,

With your 8.1.1 release the brush now perfectly works in code.
Thank you for the quick action!

Sybren
Go to Top of Page

xequte

39053 Posts

Posted - Oct 07 2018 :  17:40:46  Show Profile  Reply
Excellent

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