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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Save layers from TImageEnLayerMView as templates?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
PeterPanino Posted - Sep 07 2020 : 09:49:05
I have a TImageEnLayerMView containing the TEXT-LAYERS on a TImageEnView:



Is there an easy way to save these layers to a file, so I can use them as templates in a later session to insert any of them into my image?
12   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Sep 10 2020 : 16:59:47
Hi Peter

There is not a const for screen position, but you can just use:

ImageEnView2.XScr2Bmp( ImageEnView2.width div 2 )


Selectable is the default state for layers, so you should unset it for the background layer.



Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Sep 10 2020 : 13:28:10
I use this double-click event-handler to insert the layer in the center of the picture in ImageEnView2:

procedure TForm1.ImageEnLayerMView1DblClick(Sender: TObject);
begin
  ImageEnView2.LayersAdd(ImageEnView1.CurrentLayer, IELayer_Pos_HCenter, IELayer_Pos_VCenter);
end;


This works well, but ONLY if the image in ImageEnView2 is completely visible. If e.g. the image is zoomed in very much and the scrollbars are scrolled down, then the layer gets inserted in the center of the image but not of the visible area. So, how to center the inserted layer in the center of the VISIBLE AREA?
PeterPanino Posted - Sep 10 2020 : 05:42:48
Perfect! Is there anything which could accidentally reset it to
ImageEnView2.Layers[0].Selectable = True
as a SIDE-EFFECT?
xequte Posted - Sep 09 2020 : 19:10:45
Hi Peter

Ensure that you set ImageEnView2.Layers[0].Selectable = False, otherwise the combination above will make it try to select layer 0 (background image) rather than create a layer.

Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Sep 09 2020 : 18:15:43
Hi Nigel,

thank you very much! now the layer gets insert inserted at the correct mouse position.

However, there is another strange issue: I have added a button to this demo project attached to my previous posting, with this click handler:

ImageEnView2.MouseInteractGeneral := [];
ImageEnView2.MouseInteractLayers := [mlMoveLayers, mlResizeLayers, mlCreateTextLayers];


Theoretically and according to the documentation, this should allow me to create new text layers with the mouse. But it does not work. Why? (I assume there must be a complex incompatibility between layer settings, but despite of searching the cause for hours, I did not find it).

Only OUTSIDE of the image area (!) I can create a text layer with the mouse:

xequte Posted - Sep 09 2020 : 17:16:32
Hi Peter

Auto-selection of layers in your demo is not occurring because lvSelection has been removed from LayerOptions.

Layer positions are relative to the background layer (layer 0). They are not control coordinates, so you need to convert them using XScr2Bmp/YScr2Bmp:

Change your drag drop code to:

ImageEnView2.LayersAdd(ImageEnView1.CurrentLayer, 
                       ImageEnView2.XScr2Bmp( X ), ImageEnView2.YScr2Bmp( Y ),
                       ImageEnView1.CurrentLayer.Width, ImageEnView1.CurrentLayer.Height);


https://www.imageen.com/help/TImageEnView.XScr2Bmp.html
https://www.imageen.com/help/TImageEnView.YScr2Bmp.html

Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Sep 09 2020 : 09:23:30
Hi Nigel,

Selecting the Layer in the attached TImageEnView works only with this event-handler code:

procedure TForm1.ImageEnLayerMView1ImageSelect(Sender: TObject; idx: Integer);
begin
  //ImageEnView1.LayersCurrent := idx + 1;
  ImageEnView1.LayersCurrent := ImageEnLayerMView1.IndexToLayer(idx);
end;


I have attached the modified \Demos\LayerEditing\Layers_AllTypes demo project to this posting which demonstrates this:

attach/PeterPanino/20209991618_Layers2.zip
4215.1 KB

But now, that the reverse-sort-order problem is solved, lets look at the insertion point problem: As I wrote in the previous posting, the layers get inserted at the wrong position, i.e. not at the mouse-pointer position. I other words, the insertion point should not be X/Y from the DragDrop event-handler but an X/Y position which gets the real mouse-pointer position inside the image area. Do you know how to get this mouse-pointer position?
xequte Posted - Sep 09 2020 : 03:57:08
Hi Peter

Selecting a layer in TImageEnLayerMView will select it in the attached TImageEnView, and vice versa.

If you are not seeing that, then there is an issue somewhere (which I cannot reproduce here). Can you reproduce it in one of our demos, such as:

\Demos\LayerEditing\Layers_AllTypes\Layers.dpr


TImageEnLayerMView index is not the same as the Layer index, because a TImageEnLayerMView may display in reversed order, or exclude some layers based on the OnIncludeLayer event. Ensure you use IndexToLayer:

https://www.imageen.com/help/TImageEnLayerMView.IndexToLayer.html



Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Sep 08 2020 : 16:49:30
•Hi Nigel,

thank you for the documentation links and the code example!

Unfortunately, selecting a Layer item in the TImageEnLayerMView does not automatically select the corresponding Layer in ImageEnView1, nor does it vice versa. There seems to be no connection between the two, although ImageEnLayerMView.AttachedImafeEnView is ImageEnView1.

So I wrote this event-handler:

procedure TForm1.ImageEnLayerMView1ImageSelect(Sender: TObject; idx: Integer);
begin
  ImageEnView1.LayersCurrent := idx + 1;
end;


And then in DraDrop event-handler:

procedure Tfmain.ImageEnView2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  ImageEnView2.LayersAdd(ImageEnView1.CurrentLayer, X, Y, ImageEnView1.CurrentLayer.Width, ImageEnView1.CurrentLayer.Height);
end;


The Layer gets inserted by drag&drop, but with a strange bug - this is the ImageEnLayerMView at run-time:



• So, when I drag the GREEN item then the RED layer gets inserted!

• And when I drag the BLUE item then the BLUE layer is inserted.

• And when I drag the RED item then the GREEN layer is inserted!

So the parameter idx in the ImageEnLayerMView1ImageSelect event-handler is based on the REVERSE sort order of the Layers list! Is this a bug?

Also, the inserted layer is not inserted at the X/Y position from the ImageEnView2DragDrop evemt-handler, but at a much lower position. Why?*

---

* This is the same issue which occurs in \Demos\LayerEditing\DragDropLayers: Increase the size of the window horizontally and vertically at run-time, and the layer dragged into the target area gets inserted not at the mouse pointer position but at another position. Obviously, there is a difference between DragDrop X/Y and the mouse pointer X/Y position inside the image area. I have not found a function which gets the mouse pointer X/Y position inside the image area.

Strangely, also when I execute this in the ImageEnView2MouseUp event-handler, then the layer also gets inserted at the wrong position (not at the mouse pointer position), if the image does not fill the whole client area:

procedure TForm1.ImageEnView2MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ImageEnView2.LayersAdd(ImageEnView1.CurrentLayer, X, Y, ImageEnView1.CurrentLayer.Width, ImageEnView1.CurrentLayer.Height);
end;
xequte Posted - Sep 07 2020 : 22:21:55
Hi Peter

You can use the OnIncludeLayer event to hide the background layer:

https://www.imageen.com/help/TImageEnLayerMView.OnIncludeLayer.html


You would need to write a bit of code to allow dragging from one TImageEnLayerMView to another.

It would go something like:
- On drop, get the layer index from the source TImageEnLayerMView

https://www.imageen.com/help/TImageEnLayerMView.IndexToLayer.html

(though it would almost certainly point to the CurrentLayer of the attached TImageEnView, so you could probably use that)

- Get the destination insertion point (where dropped in destination TImageEnLayerMView)

- Use the clone LayersInsert overload to clone the relevant layer from the source TImageEnView to the destination TImageEnView (i.e. not the TImageEnLayerMViews)

https://www.imageen.com/help/TImageEnView.LayersInsert.html

// Clone in ImageEnView2 the current layer in ImageEnView1
ImageEnView2.LayersInsert( insertPos, ImageEnView1.CurrentLayer );


Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Sep 07 2020 : 15:51:13
Also, the Background thumbnail should be hidden:



I don't need the Background thumbnail as this is only a repository for layer templates to be dragged to a TImageEnView.

Can this be done?
PeterPanino Posted - Sep 07 2020 : 15:21:09
Now I load a file layers.ien in the AttachedImageEnView of the TImageEnLayerMView:

if dlgOpenLayers.Execute then
begin
  ImageEnView1.IO.Params.PSD_LoadLayers := True;
  ImageEnView1.IO.LoadFromFile(dlgOpenLayers.FileName);  
end;


This makes the layers from layers.ien appear in the TImageEnLayerMView. (See screenshot in the previous posting).

Now I try to DRAG one of the layer thumbnails in the TImageEnLayerMView to another TImageEnView. On DragOver the dragged item gets accepted:

procedure Tfmain.ImageEnView2DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
begin
  if Source is TImageEnLayerMView then
    Accept := True;
end;


But then on DROP I am stuck:

procedure Tfmain.ImageEnView2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  // ???
end;


How to implement the DROP event-handler from TImageEnLayerMView to ImageEnView2?