ImageEn, unit imageenview |
|
TImageEnView.OnLayerNotify
Declaration
property OnLayerNotify: TIELayerNotify;
Description
Occurs whenever layer actions occur, e.g selecting, moving or resizing. This event only fires on user actions (not programmatic changes).
OnLayerNotify and
OnLayerNotifyEx are the same, except that
OnLayerNotifyEx 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.
The following events do not occur with
OnLayerNotify: ielBeginResizing, ielBeginRotating, ielBeginMoving, ielBeginCreating
| Demos\LayerEditing\StampTextAndShapes\StampLayers.dpr |
// Log all resizing of layers
procedure TfrmMain.IEView1LayerNotify(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.ImageEnView1LayerNotify(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;
// Automatically merge added layers to the background (e.g. "Select to draw" shapes onto image)
procedure Tfmain.ImageEnView1LayerNotify(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.ImageEnView1LayerNotify(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
◼OnLayerNotifyEx
◼OnLayerSelectionChange
◼OnLayerMoveSize
◼OnNewLayer