ImageEn, unit imageenview |
|
TImageEnView.OnLayerNotifyEx
Declaration
property OnLayerNotifyEx: TIELayerNotify;
Description
Occurs whenever layer actions occur, e.g selecting, moving or resizing. This event only fires on user actions (not programmatic changes).
OnLayerNotifyEx is the same as
OnLayerNotify except that it returns extra events where the layer index may be invalid (for layers that are not yet created or have already been removed). For example, with the
ielBeginCreating event, the layer index will be -1.
With
OnLayerNotify, the layer index is guaranteed to be valid because it skips any events for invalid layers. For events that are returned by
OnLayerNotify, the layer index will be the same as
OnLayerNotifyEx.
Note: If you use the
layer parameter, you must check that it a valid index, i.e. >=0 and
LayersCount
| Demos\LayerEditing\StampTextAndShapes\StampLayers.dpr |
// Log all resizing of layers
procedure TfrmMain.IEView1LayerNotifyEx(Sender: TObject; layer: integer; event: TIELayerEvent);
var
ALayer: TIELayer;
i: Integer;
sChangedLayers: string;
begin
if event = ielResized then
begin
sChangedLayers := '';
for i := 0 to IEView1.LayersCount - 1 do
begin
ALayer := IEView1.Layers[ I ];
if ( ALayer.Locked = False ) and ALayer.Selected then
sChangedLayers := sChangedLayers + IntToStr( i ) +',';
end;
if sChangedLayers <> '' then
begin
SetLength( sChangedLayers, Length( sChangedLayers ) - 1 ); // Remove final comma
memLog.Lines.Add( 'Layers Resized: ' + sChangedLayers );
end;
end;
end;
// Auto-size text only after rotation
procedure TMainForm.ImageEnView1LayerNotifyEx(Sender: TObject; layer: Integer;
event: TIELayerEvent);
begin
if ( ImageEnView1.Layers[ layer ] is TIETextLayer ) and ( event is ielRotated ) then
begin
TIETextLayer( ImageEnView1.Layers[ layer ]).SizeToText();
ImageEnView1.Update();
end;
end;
// Refresh layer viewer (see TImageEnMView.AssignLayers) for any events that change the layers list, or the way layers look
procedure TMainForm.ImageEnView1LayerNotifyEx(Sender: TObject; layer: Integer; event: TIELayerEvent);
begin
if event in [ ielSelected, ielDeselected, ielMoved, ielResized, ielRotated, ielCreated, ielMerged, ielGrouped, ielAction, ielEdited, ielEditedProps, ielEditedPoints, ielRemoved, ielArranged ] then
RefreshLayerViewer();
end;
// Automatically merge added layers to the background (e.g. "Select to draw" shapes onto image)
procedure Tfmain.ImageEnView1LayerNotifyEx(Sender: TObject; layer: Integer; event: TIELayerEvent);
begin
if AutoMergeLayers and ( layer >= 0 ) and ( layer < ImageEnView1.LayersCount ) then // Ensure it is a valid layer
begin
// For text layers with automatic text editing (loAutoTextEditing in LayerOptions) don't merge till we complete editing
if (( ImageEnView1.Layers[layer].Kind = ielkText ) and ( event = ielEdited )) or
(( ImageEnView1.Layers[layer].Kind <> ielkText ) and ( event = ielCreated )) then
ImageEnView1.LayersMerge( 0, layer );
end;
end;
// Prevent user from entering too much text
procedure Tfmain.ImageEnView1LayerNotifyEx(Sender: TObject; layer: Integer; event: TIELayerEvent);
const
Maximum_Text_Length = 10;
var
editor: TIEEdit;
pos: Integer;
s: string;
begin
if ( Maximum_Text_Length > 0 ) and ( event = ielTextEditorChange ) then
begin
if ImageEnView1.LayersTextEditor is TIEEdit then
begin
editor := TIEEdit( ImageEnView1.LayersTextEditor );
if Length( editor.Text ) > Maximum_Text_Length then
begin
pos := editor.SelStart;
s := editor.Text;
SetLength( s, Maximum_Text_Length );
editor.Text := s;
editor.SelStart := pos;
end;
end;
end;
end;
See Also
◼OnLayerNotify
◼OnLayerSelectionChange
◼OnLayerMoveSize
◼OnNewLayer