Package totalcross.ui

Class ImageControl


  • public class ImageControl
    extends Control
    A control that can show an image bigger than its area and that can be dragged using a pen to show the hidden parts. Note that, by default, events (and dragging) are disabled. You must call setEventsEnabled to allow dragging.
    • Field Detail

      • scrollValue

        public static int scrollValue
        The amount to scroll when in penless mode. Defaults to 10.
      • centerImage

        public boolean centerImage
        Set to true to center the image in the control when it is loaded
      • lastX

        public int lastX
        The last position used for X and Y.
      • lastY

        public int lastY
        The last position used for X and Y.
      • borderColor

        public int borderColor
        Change this member to set the border color. You may also set it to -1 if you don't want a border color. Note: starting on TotalCross 3.1, the border is drawn around the color and no longer around the image, because it was not working on OpenGL devices.
      • allowBeyondLimits

        public boolean allowBeyondLimits
        Set to true to let the image be dragged beyond container limits. Should be false for open gl.
      • drawOp

        public int drawOp
        Dumb field to keep compilation compatibility with TC 1
      • hwScale

        public boolean hwScale
        Set to true to enable zooming in open gl devices.
      • tempHwScale

        public double tempHwScale
        Temporary values to set the hwScaleW/hwScaleH to during draw.
      • scaleToFit

        public boolean scaleToFit
        Set to true to scale the image to fit the bounds.
      • strechImage

        public boolean strechImage
        Set to true, with scaleToFit, to strech the image.
    • Constructor Detail

      • ImageControl

        public ImageControl​(Image img)
        Constructs an ImageControl using the given image.
      • ImageControl

        public ImageControl()
        Constructs with no initial image. You must set the image with the setImage method.
    • Method Detail

      • setEventsEnabled

        public void setEventsEnabled​(boolean enabled)
        Pass true to enable dragging and events on the image.
      • setPressedEventsEnabled

        public void setPressedEventsEnabled​(boolean enabled)
        Pass true to enable this ImageControl to send Press events. Note that it will disable drag and resize of the image.
      • setImage

        public void setImage​(Image img)
        Sets the image to the given one. If the image size is different, you must explicitly call setRect again if you want to resize the control.
      • setImage

        public void setImage​(Image img,
                             boolean resetPositions)
        Sets the image to the given one, optionally resetting the image position. If the image size is different, you must explicitly call setRect again if you want to resize the control.
      • onEvent

        public void onEvent​(Event event)
        Description copied from class: Control
        Called to process key, pen, control and other posted events.
        Overrides:
        onEvent in class Control
        Parameters:
        event - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • moveTo

        public boolean moveTo​(int newX,
                              int newY)
        Moves to the given coordinates, respecting the current moving policy regarding allowBeyondLimits.
        Returns:
        True if the image's position was changed.
      • onBoundsChanged

        protected void onBoundsChanged​(boolean screenChanged)
        Description copied from class: Control
        Called after a setRect.
        Overrides:
        onBoundsChanged in class Control
        Parameters:
        screenChanged - If the bounds were changed due to a screen change (rotation, collapse)
      • onPaint

        public void onPaint​(Graphics g)
        Description copied from class: Control
        Called to draw the control. When this method is called, the graphics object passed has been translated into the coordinate system of the control and the area behind the control has already been painted.
        Overrides:
        onPaint in class Control
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • getImageWidth

        public int getImageWidth()
        Returns the image's width; when scaling, returns the scaled width.
      • getImageHeight

        public int getImageHeight()
        Returns the image's height; when scaling, returns the scaled height.
      • getPreferredWidth

        public int getPreferredWidth()
        Description copied from class: Control
        Returns the preferred width of this control.
        Overrides:
        getPreferredWidth in class Control
      • getPreferredHeight

        public int getPreferredHeight()
        Description copied from class: Control
        Returns the preferred height of this control.
        Overrides:
        getPreferredHeight in class Control
      • getImage

        public Image getImage()
        Returns the current image assigned to this ImageControl.
      • getOriginalImage

        public Image getOriginalImage()
        Returns the original image assigned to this ImageControl. Note that getImage() returns the image scaled, while getOriginalImage() returns the unscaled image.
      • setBackground

        public void setBackground​(Image img)
        Sets the given image as a freezed background of this image control.
      • getBackground

        public Image getBackground()
        Returns the background image set with setBackground
      • getVisibleImage

        public Image getVisibleImage​(boolean includeBackground)
                              throws ImageException
        Gets an image representing the portion being shown. If all image is being shown, returns the currently assigned image.
        Throws:
        ImageException
      • handleGeographicalFocusChangeKeys

        public Control handleGeographicalFocusChangeKeys​(KeyEvent ke)
        Description copied from class: Control
        Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.
        Overrides:
        handleGeographicalFocusChangeKeys in class Control
        Parameters:
        ke - The KeyEvent to be processed
        Returns:
        The control that should get focus as a result of this KeyEvent. Null if this control did not handle the KeyEvent.
        See Also:
        Settings.geographicalFocus