ImageEn, unit imageenview

TIEMouseInteract


Declaration

TIEMouseInteractItems = (miZoom, miSmoothZoom, miScroll, miMovingScroll, miSelect, miSelectPolygon, miSelectCircle, miSelectZoom, miSelectMagicWand, miSelectLasso, miSelectChromaKey, miCropTool, miBrushTool, miCloneTool, miRotateTool, miColorFill, miAlphaFill, miMeasureLength, miMeasureRect, miMeasureEllipse, miMeasurePath, miMeasureAngle, miColorPicker, miRetouchTool, miAdjustBlackWhite, miPdfSelectText, miPdfSelectRgn, miDblClickZoom, miTransformTool, miPdfSelectObject, miPdfSelectAnnotation);
TIEMouseInteract = set of TIEMouseInteractItems;


Description

Actions that occur when the user moves or clicks the mouse.

Also see TIEMouseInteractLayers, which are layer editing interactions.

VIEW INTERACTIONS
Value Description
miMovingScroll Moving the mouse over the image (without requiring any clicking) will cause the image to automatically scroll (pan) (see SmoothScrollValue)
miScroll The image can be navigated by clicking with the left mouse button and dragging (Also see: MouseScrollRate)
miSelectZoom If the user selects an area, it will be automatically zoomed into (and become the new display view). Click and move the mouse to select the zoom rectangle (Notes 1 and 2)
miZoom Click the image to zoom in. Ctrl+click (or right-click) to zoom out (Note 1)
miSmoothZoom Same as miZoom except it smootly zooms to the new level (see SmoothZoomValue and Note 1)
miDblClickZoom Double-click the image to zoom in. Ctrl+double-click to zoom out (Note 1)

SELECTION INTERACTIONS
Value Description
miSelect A rectangular area can be selected (or a rounded rect if SelectionRounding > 0, or other shapes using SelectionShape). Click and move the mouse to select the rectangle. miSelect excludes miScroll and miSelectXXX. The Alt Key forces the selection to maintain its aspect ratio (Note 3)
miSelectPolygon A polygonal area can be selected. Click (and release) the left mouse button at each point of the polygon, or click and hold the left button and move to specify continuous irregular lines. Methods to terminate selection can be specified in SelectionOptions (Note 3)
miSelectCircle A circular/elliptical area can be selected. Click the left button and move the mouse. The Alt key will force a circular selection (Note 3)
miSelectMagicWand Selects an irregular region of similar colors. Click the left mouse button upon a pixel and similar colors surrounding it are selected (see MagicWandTolerance). Also affected by the options: MagicWandMode, MagicWandMaxFilter and MagicWandSize (Note 3)
miSelectLasso A polygonal area can be selected with the mouse. Click the left button and move the mouse to select a continuous irregular region (Note 3)
miSelectChromaKey Selects the subject or background in an image with a solid background color (e.g. a green screen). This is controlled by the options in ChromaKeyOptions (Note 3)

INTERACTIVE EDITING TOOLS
Value Description
miAlphaFill Enables the FillTool allowing the user to click the image to flood fill with the transparency of AlphaFillValue (Tolerance is specified by Tolerance). Hold ALT key sto switch to miColorFill
miColorFill Enables the FillTool allowing the user to click the image to flood fill with the color ColorFillValue (Tolerance is specified by Tolerance). Hold ALT key sto switch to miAlphaFill
miCropTool Enables the CropTool allowing the user to select a particular area of an image and discards the portions outside the chosen section. The Shift key snaps crop rotation to a 45 deg. angle (also see ShiftKeyLock)
miCloneTool Enables the CloneTool allowing the user to click a point on the image and then click elsewhere to clone the content from the original offset
miBrushTool Enables the BrushTool allowing the user to click or drag the image to paint
miRetouchTool Enables the RetouchTool allowing the user to perform fixes on the image with a brush, such as smudging, blurring and inpainting
miRotateTool Enables the RotateTool allowing the user to drag the image to rotate it. The Shift key (or ShiftKeyLock) snaps rotation to a 45 deg. angle (Note 4)
miTransformTool Enables the TransformTool allowing the user to stretch the image using a Thin Plate Spline Shape Transformation (Requires IEVision)

MEASUREMENT TOOLS
Value Description
miMeasureLength Click and drag the cursor to measure distances in the image (use SetScale to set the scale). See demo: Demos\ImageAnalysis\MeasureIt\MeasureIt.dpr (Note 5)
miMeasureRect Click and drag the cursor to measure rectangular areas in the image (use SetScale to set the scale). See demo: Demos\ImageAnalysis\MeasureIt\MeasureIt.dpr (Note 5)
miMeasureEllipse Click and drag the cursor to measure circular areas in the image (use SetScale to set the scale). See demo: Demos\ImageAnalysis\MeasureIt\MeasureIt.dpr (Note 5)
miMeasurePath Use multiple clicks to measure an area or length in the image (use SetScale to set the scale). See demo: Demos\ImageAnalysis\MeasureIt\MeasureIt.dpr (Note 5)
miMeasureAngle Click three points to measure an angle in the image. See demo: Demos\ImageAnalysis\MeasureIt\MeasureIt.dpr

OTHER TOOLS
Value Description
miColorPicker Changes the cursor to a color picker allowing the user to select a color from the image. Use ColorSelectActions to determine what occurs when the user selects a color. Also see: ResetAfterColorSelect
miAdjustBlackWhite Adjusts the BlackValue and WhiteValue of the image. Drag up/down to adjust window center (brightness). Drag left/right to adjust window width (contrast). Note: To apply the Black/White changes, call StretchValues
miPdfSelectText Use with the PdfViewer to allow the user to select text
miPdfSelectRgn Use with the PdfViewer to allow the user to select a rectangular region (e.g. to copy to the clipboard as an image)
miPdfSelectObject Select and edit PDF objects in the PdfViewer
miPdfSelectAnnotation Select and edit PDF Annotations in the PdfViewer

Note:
1. Zooming will have only a temporary effect if AutoShrink or AutoStretch is enabled unless you add iedoDisableAutoFitWhenZoom to DisplayOptions. Right-click will have no zoom effect popup menus are specified
2. By default, Zoom selections will be match the aspect ratio (so the image does not stretch inconsistenly). You can disable this by removing iedoMaintainAROnZoomSelect from DisplayOptions
3. Holding down the Shift key while selecting will add a new selection region. Holding down the Ctrl key will subtract from the selection. You can force behavior using ShiftKeyLock
4. Use mlRotateLayers in layer applications, and miRotateTool in other (single layer) applications
5. The units use for measurement are specified by DefaultMeasureUnit (or the OnMeasure event) and the accuracy by MeasureDecimalPlaces


Usage Notes

You can only select one of the following:
miScroll, miSelectZoom, miMeasureLength, miMeasureRect, miMeasureEllipse, miMeasurePath, miMeasureAngle,
miSelect, miSelectPolygon, miSelectCircle, miSelectMagicWand, miSelectLasso, miSelectChromaKey,
miCropTool, miBrushTool, miCloneTool, miRetouchTool, miRotateTool, miTransformTool
miColorFill, miAlphaFill, miColorPicker, miAdjustBlackWhite
miPdfSelectRgn, miPdfSelectObject, miPdfSelectAnnotation

The following are often used in combinations with others:
miZoom, miSmoothZoom, miDblClickZoom, miMovingScroll, mlEditLayerPoints,
mlMoveLayers, mlResizeLayers, mlRotateLayers (can be used with any of the miSelect* methods, except miSelectZoom)
miZoom/miSmoothZoom can be used with miScroll, miSelect, miSelectCircle, miSelectZoom, miMovingScroll, miMeasureLength, miMeasureRect, miMeasureEllipse, miMeasurePath, miMeasureAngle
miMovingScroll and miDblClickZoom can be used with all interactions
miPdfSelectText can only be used alone or with miPdfSelectRgn


Common Usages

Image Display (Drag-scroll and zoom image):
ImageEnView1.MouseInteractGeneral := [ miZoom, miScroll ];

Selection (create, move and resize layers):
ImageEnView1.MouseInteractGeneral := [ miSelect ];

Interactive Editing Tool:
ImageEnView1.MouseInteractGeneral := [ mi*Tool ]; // Always alone

Measure Lengths:
ImageEnView1.MouseInteractGeneral := [ miMeasureLength ]; // Always alone

Measure Rectangular Area:
ImageEnView1.MouseInteractGeneral := [ miMeasureRect ]; // Always alone

Measure Circular Area:
ImageEnView1.MouseInteractGeneral := [ miMeasureEllipse ]; // Always alone

Measure an Angle:
ImageEnView1.MouseInteractGeneral := [ miMeasureAngle ]; // Always alone

Selections in a multi-layer app
ImageEnView1.MouseInteractGeneral := [ miSelect, mlMoveLayers ];

Selecting text and images in PDF documents
ImageEnView1.MouseInteractGeneral := [ miPdfSelectText, miPdfSelectRgn ];


Demos

Demo  Demos\Other\MouseInteract\MouseInteract.dpr
Demo  Demos\ImageEditing\CompleteEditor\PhotoEn.dpr
Demo  Demos\Display\SoftPan\SoftPan.dpr (miMovingScroll)
Demo  Demos\ImageEditing\MakeTransparent\MakeTransparent.dpr (miColorPicker)


Examples

// Single left click zoom-in image, single right click zoom-out image, click and
// drag scroll the image (if it is bigger than client area).
ImageEnView1.MouseInteractGeneral := [ miZoom, miScroll ];

...Same but with smooth zooming
ImageEnView1.MouseInteractGeneral := [ miSmoothZoom, miScroll ];

...Similar but must double-click to zoom in, or Shift+double-click to zoom out
ImageEnView1.MouseInteractGeneral := [ miDblClickZoom, miScroll ];

// Allow rectangular selections
ImageEnView1.MouseInteractGeneral := [ miSelect ];



// Allow circular selections
ImageEnView1.MouseInteractGeneral := [ miSelectCircle ];



// Allow rounded rectangle selections
ImageEnView1.SelectionRounding := 30;
ImageEnView1.MouseInteractGeneral := [ miSelect ];

// Allow explosion shaped selections
ImageEnView1.SelectionShape := iesExplosion;
ImageEnView1.MouseInteractGeneral := [ miSelect ];

// Allow the user to select the background in an image with a chroma-key background
ImageEnView1.ChromaKeyOptions.Mode := iecSubject;
ImageEnView1.MouseInteractGeneral := [ miSelectChromaKey ];

// Allow user to make selections when there are multiple layers (current layer will be highlighted. Selecting a new layer will highlight and allow selection. Layer movement is not actually possible)
ImageEnView1.MouseInteractGeneral := [ miSelect, mlMoveLayers ];

// Allow user to make selections when there are multiple layers, including resizing and rotating layers
ImageEnView1.MouseInteractGeneral := [ miSelect, mlMoveLayers, mlResizeLayers, mlRotateLayers ];

// Enable measuring of lengths in image (Imperial)
// Set scale of 250 pixels = one inch
ImageEnView1.SetScale( 250, 1, ieuInches );
IEGlobalSettings().DefaultMeasureUnit := ieuInches;
ImageEnView1.Update();
ImageEnView1.MouseInteractGeneral := [ miMeasureLength ];

// Enable measuring of lengths in image (Metric)
// Set 100 pixels = 4cm
ImageEnView1.SetScale( 100, 4, ieuCentimeters );
IEGlobalSettings().DefaultMeasureUnit := ieuCentimeters;
ImageEnView1.Update();
ImageEnView1.MouseInteractGeneral := [ miMeasureLength ];

// Select whole image and allow user to deselect circular regions
With ImageEnView1 do
begin
  SelectionBase := iesbBitmap;
  Select( 0, 0, IEBitmap.Width, IEBitmap.Height );
  ShiftKeyLock  := [ iessCtrl_SubFromSel ];
  MouseInteractGeneral := [ miSelectCircle ];
end;

// Fill clicked areas with red
ImageEnView1.FillTool.ColorFillValue := clRed;
ImageEnView1.MouseInteractGeneral := [miColorFill];

// Fill clicked areas with 50% transparency
ImageEnView1.FillTool.AlphaFillValue := 128;
ImageEnView1.MouseInteractGeneral := [miAlphaFill];

// Selecting a color updates all tools
ImageEnView1.FillTool.ColorSelectActions := [ ieccChromaKeyColor, ieccBrushColor, ieccFillColor, ieccRotateBackground, ieccLayerFill ];
ImageEnView1.MouseInteractGeneral := [ miColorPicker ];


// Use miColorPicker to set transparent parts of image

procedure TMainForm.btnSelColorClick(Sender: TObject);
begin
  ImageEnView1.MouseInteractGeneral := [ miColorPicker ];
end;

procedure TMainForm.ImageEnView1UserInteraction(Sender: TObject; Event: TIEUserInteractionEvent; Info: Integer);
var
  c: TColor;
begin
  if Event = ieiColorPickerHover then
  begin
    // Hovering over image - show color in our panel
    pnlCurrentColor.Color := TColor( Info );
  end
  else
  if Event = ieiColorPickerClick then
  begin
    // Clicked image - set this color as transparent in our image
    c := TColor( Info );
    ImageEnView1.Proc.SetTransparentColors( c, c, 0);
  end;
end;


// Smudge the image
ImageEnView1.RetouchTool.RetouchMode    := iermSmudge;
ImageEnView1.RetouchTool.SmudgePressure := 15;
ImageEnView1.RetouchTool.Feathering     := 3;
ImageEnView1.MouseInteractGeneral       := [ miRetouchTool ];




// Apply motion blur to image
ImageEnView1.RetouchTool.RetouchMode      := iermMotionBlur ;
ImageEnView1.RetouchTool.MotionBlurSigma  := 8;
ImageEnView1.RetouchTool.MotionBlurAngle  := 180;
ImageEnView1.RetouchTool.MotionBlurRadius := 10;
ImageEnView1.MouseInteractGeneral         := [ miRetouchTool ];




// Use IEVision's Inpainting to remove blemishes in the image
ImageEnView1.RetouchTool.RetouchMode      := iermIEVisionInpaint;
ImageEnView1.RetouchTool.InpaintRangeSize := 6;
ImageEnView1.MouseInteractGeneral         := [ miRetouchTool ];




// Allow user to select images or text and copy to clipboard (automatically detecting selection based on what is under the cursor)
ImageEnView1.MouseInteractGeneral := [ miPdfSelectText, miPdfSelectRgn ];
ImageEnView1.PdfViewer.Enabled := True;

// Allow user to select text and copy to clipboard (image selection disabled)
ImageEnView1.MouseInteractGeneral := [ miPdfSelectText ];
ImageEnView1.PdfViewer.Enabled := True;




// Display a PDF document and allow editing of the page objects and annotations
ImageEnView1.PdfViewer.Enabled := True;
ImageEnView1.MouseInteractGeneral := [ miPdfSelectObject, miPdfSelectAnnotation ];
ImageEnView1.PdfViewer.AllowObjectEditing := True;
ImageEnView1.IO.LoadFromFilePDF( 'C:\document.pdf' );

// Allow user to select images and copy to clipboard (text selection disabled)
ImageEnView1.MouseInteractGeneral := [ miPdfSelectRgn ];
ImageEnView1.PdfViewer.Enabled := True;





See Also

MouseInteractGeneral
MouseInteractLayers
SelectionOptions
LayerDefaults
LayersAutoClosePolylines