Class ImageComponent
java.lang.Object
de.gurkenlabs.litiengine.gui.GuiComponent
de.gurkenlabs.litiengine.gui.ImageComponent
- All Implemented Interfaces:
IRenderable,Tweenable,MouseListener,MouseMotionListener,MouseWheelListener,EventListener
- Direct Known Subclasses:
CheckBox,MouseDrawComponent,TextFieldComponent
The ImageComponent class extends the GuiComponent class to provide functionality for handling images and spritesheets within a GUI component. It
supports various image scaling modes, alignment, and a caching mechanism to retain the scaled images in memory.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intFields inherited from class de.gurkenlabs.litiengine.gui.GuiComponent
ICON_FONT -
Constructor Summary
ConstructorsConstructorDescriptionImageComponent(double x, double y, double width, double height) Constructs an ImageComponent with the specified position and dimensions.ImageComponent(double x, double y, double width, double height, Spritesheet spritesheet, String text, Image image) Constructs an ImageComponent with the specified position, dimensions, spritesheet, text, and image.ImageComponent(double x, double y, double width, double height, Image image) Constructs an ImageComponent with the specified position, dimensions, and image.ImageComponent(double x, double y, double width, double height, String text) Constructs an ImageComponent with the specified position, dimensions, and text.ImageComponent(double x, double y, Image image) Constructs an ImageComponent with the specified position and image. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the background image for the component based on its current state.doubleGets the horizontal padding for the image.getImage()Retrieves the image to be displayed by the component.Gets the horizontal alignment of the image within the component.intGets the interpolation type used for scaling the image.Gets the scale mode for the image.Gets the vertical alignment of the image within the component.protected SpritesheetRetrieves the spritesheet used by the component.floatGets the scale factor for the spritesheet.intGets the interpolation type used for scaling the spritesheet.Gets the scale mode for the spritesheet.doubleGets the vertical padding for the image.voidrender(Graphics2D g) Renders the component using the provided Graphics2D context.voidRescales the base image according to the component's dimensions and the specified image scale mode.voidsetHeight(double height) Sets the height of the component and rescales the image.voidsetHorizontalImagePadding(double horizontalImagePadding) Sets the horizontal padding for the image.voidSets the image to be displayed by the component and rescales it.voidsetImageAlign(Align imageAlign) Sets the horizontal alignment of the image within the component.voidsetImageScaleInterpolation(int imageScaleInterpolation) Sets the interpolation type used for scaling the image and rescales it.voidsetImageScaleMode(ImageScaleMode imageScaleMode) Sets the scale mode for the image and rescales it.voidsetImageValign(Valign imageValign) Sets the vertical alignment of the image within the component.voidSets the spritesheet to be used by the component.voidsetSpritesheet(Spritesheet spr, ImageScaleMode scaleMode) Sets the spritesheet and its scale mode to be used by the component.voidsetSpritesheet(Spritesheet spr, ImageScaleMode scaleMode, float scaleFactor) Sets the spritesheet, its scale mode, and scale factor to be used by the component.voidsetSpritesheetScaleFactor(float spritesheetScaleFactor) Sets the scale factor for the spritesheet.voidsetSpritesheetScaleInterpolation(int spritesheetScaleInterpolation) Sets the interpolation type used for scaling the spritesheet and rescales the image.voidsetSpritesheetScaleMode(ImageScaleMode spritesheetScaleMode) Sets the scale mode for the spritesheet and rescales the image.voidsetVerticalImagePadding(double verticalImagePadding) Sets the vertical padding for the image.voidsetWidth(double width) Sets the width of the component and rescales the image.Methods inherited from class de.gurkenlabs.litiengine.gui.GuiComponent
addRenderedListener, addRenderListener, getAppearance, getAppearanceDisabled, getAppearanceHovered, getBoundingBox, getCenterX, getCenterY, getClickConsumer, getComponentId, getComponents, getCurrentAppearance, getFont, getHeight, getHoverConsumer, getHoverSound, getLocation, getMouseDraggedConsumer, getMouseEnterConsumer, getMouseLeaveConsumer, getMouseMovedConsumer, getMousePressedConsumer, getMouseReleasedConsumer, getMouseWheelConsumer, getName, getShape, getTag, getText, getTextAlign, getTextAngle, getTextShadowColor, getTextShadowRadius, getTextToRender, getTextValign, getTextX, getTextY, getTweenValues, getWidth, getX, getY, hasAutomaticLineBreaks, hasTextAntialiasing, hasTextShadow, initializeComponents, isEnabled, isForwardMouseEvents, isHovered, isPressed, isSelected, isSuspended, isVisible, mouseClicked, mouseDragged, mouseEntered, mouseEventShouldBeForwarded, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, onClicked, onHovered, onMouseDragged, onMouseEnter, onMouseLeave, onMouseMoved, onMousePressed, onMouseReleased, onMouseWheelScrolled, onTextChanged, prepare, removeListener, removeListener, setAutomaticLineBreaks, setDimension, setEnabled, setFont, setFontSize, setForwardMouseEvents, setHovered, setHoverSound, setLocation, setLocation, setName, setSelected, setTag, setText, setTextAlign, setTextAngle, setTextAntialiasing, setTextShadow, setTextShadowColor, setTextShadowRadius, setTextValign, setTextX, setTextY, setTweenValues, setVisible, setX, setY, suspend, toggleSelection, toggleSuspension
-
Field Details
-
BACKGROUND_INDEX
public static final int BACKGROUND_INDEX- See Also:
-
BACKGROUND_HOVER_INDEX
public static final int BACKGROUND_HOVER_INDEX- See Also:
-
BACKGROUND_PRESSED_INDEX
public static final int BACKGROUND_PRESSED_INDEX- See Also:
-
BACKGROUND_DISABLED_INDEX
public static final int BACKGROUND_DISABLED_INDEX- See Also:
-
-
Constructor Details
-
ImageComponent
Constructs an ImageComponent with the specified position and image.- Parameters:
x- The x-coordinate of the component.y- The y-coordinate of the component.image- The image to be displayed by the component.
-
ImageComponent
public ImageComponent(double x, double y, double width, double height) Constructs an ImageComponent with the specified position and dimensions.- Parameters:
x- The x-coordinate of the component.y- The y-coordinate of the component.width- The width of the component.height- The height of the component.
-
ImageComponent
Constructs an ImageComponent with the specified position, dimensions, and text.- Parameters:
x- The x-coordinate of the component.y- The y-coordinate of the component.width- The width of the component.height- The height of the component.text- The text to be displayed by the component.
-
ImageComponent
Constructs an ImageComponent with the specified position, dimensions, and image.- Parameters:
x- The x-coordinate of the component.y- The y-coordinate of the component.width- The width of the component.height- The height of the component.image- The image to be displayed by the component.
-
ImageComponent
public ImageComponent(double x, double y, double width, double height, Spritesheet spritesheet, String text, Image image) Constructs an ImageComponent with the specified position, dimensions, spritesheet, text, and image.- Parameters:
x- The x-coordinate of the component.y- The y-coordinate of the component.width- The width of the component.height- The height of the component.spritesheet- The spritesheet to be used by the component.text- The text to be displayed by the component.image- The image to be displayed by the component.
-
-
Method Details
-
getBackground
Retrieves the background image for the component based on its current state. The image is fetched from a cache if available, otherwise it is generated and added to the cache.- Returns:
- The background image, or null if no spritesheet is set.
-
rescaleImage
public void rescaleImage()Rescales the base image according to the component's dimensions and the specified image scale mode. The rescaled image is cached to improve performance on subsequent calls. -
getImage
Retrieves the image to be displayed by the component. If a scaled image is available, it returns the scaled image; otherwise, it returns the base image.- Returns:
- The image to be displayed by the component.
-
getImageAlign
Gets the horizontal alignment of the image within the component.- Returns:
- The horizontal alignment of the image.
-
getImageScaleMode
Gets the scale mode for the image.- Returns:
- The scale mode for the image.
-
getSpritesheetScaleMode
Gets the scale mode for the spritesheet.- Returns:
- The scale mode for the spritesheet.
-
getSpritesheetScaleFactor
public float getSpritesheetScaleFactor()Gets the scale factor for the spritesheet.- Returns:
- The scale factor for the spritesheet.
-
getHorizontalImagePadding
public double getHorizontalImagePadding()Gets the horizontal padding for the image.- Returns:
- The horizontal padding for the image.
-
setHorizontalImagePadding
public void setHorizontalImagePadding(double horizontalImagePadding) Sets the horizontal padding for the image.- Parameters:
horizontalImagePadding- The horizontal padding to set.
-
getVerticalImagePadding
public double getVerticalImagePadding()Gets the vertical padding for the image.- Returns:
- The vertical padding for the image.
-
setVerticalImagePadding
public void setVerticalImagePadding(double verticalImagePadding) Sets the vertical padding for the image.- Parameters:
verticalImagePadding- The vertical padding to set.
-
getImageValign
Gets the vertical alignment of the image within the component.- Returns:
- The vertical alignment of the image.
-
render
Renders the component using the provided Graphics2D context. If the component is suspended or not visible, the method returns immediately. Otherwise, it renders the background image (if available) and the main image (if available), and then calls the superclass's render method.- Specified by:
renderin interfaceIRenderable- Overrides:
renderin classGuiComponent- Parameters:
g- The Graphics2D context used for rendering.- See Also:
-
setImage
Sets the image to be displayed by the component and rescales it.- Parameters:
image- The image to be displayed by the component.
-
setImageScaleMode
Sets the scale mode for the image and rescales it.- Parameters:
imageScaleMode- The scale mode for the image.
-
getImageScaleInterpolation
public int getImageScaleInterpolation()Gets the interpolation type used for scaling the image. The interpolation type is one of the AffineTransformOp integer constants: - AffineTransformOp.TYPE_NEAREST_NEIGHBOR - AffineTransformOp.TYPE_BILINEAR - AffineTransformOp.TYPE_BICUBIC- Returns:
- The interpolation type used for scaling the image.
-
setImageScaleInterpolation
public void setImageScaleInterpolation(int imageScaleInterpolation) Sets the interpolation type used for scaling the image and rescales it. The interpolation type should be one of the AffineTransformOp integer constants: - AffineTransformOp.TYPE_NEAREST_NEIGHBOR - AffineTransformOp.TYPE_BILINEAR - AffineTransformOp.TYPE_BICUBIC- Parameters:
imageScaleInterpolation- The interpolation type used for scaling the image.
-
setSpritesheetScaleMode
Sets the scale mode for the spritesheet and rescales the image.- Parameters:
spritesheetScaleMode- The scale mode for the spritesheet.
-
setSpritesheetScaleFactor
public void setSpritesheetScaleFactor(float spritesheetScaleFactor) Sets the scale factor for the spritesheet.- Parameters:
spritesheetScaleFactor- The scale factor for the spritesheet.
-
getSpritesheetScaleInterpolation
public int getSpritesheetScaleInterpolation()Gets the interpolation type used for scaling the spritesheet. The interpolation type should be one of theAffineTransformOpinterpolation constants:- Returns:
- The interpolation type used for scaling the spritesheet.
-
setSpritesheetScaleInterpolation
public void setSpritesheetScaleInterpolation(int spritesheetScaleInterpolation) Sets the interpolation type used for scaling the spritesheet and rescales the image. The interpolation type should be one of theAffineTransformOpinterpolation constants:- Parameters:
spritesheetScaleInterpolation- The interpolation type used for scaling the spritesheet.
-
setSpritesheet
Sets the spritesheet to be used by the component.- Parameters:
spr- The spritesheet to be used by the component.
-
setSpritesheet
Sets the spritesheet and its scale mode to be used by the component.- Parameters:
spr- The spritesheet to be used by the component.scaleMode- The scale mode for the spritesheet.
-
setSpritesheet
Sets the spritesheet, its scale mode, and scale factor to be used by the component.- Parameters:
spr- The spritesheet to be used by the component.scaleMode- The scale mode for the spritesheet.scaleFactor- The scale factor for the spritesheet.
-
setImageAlign
Sets the horizontal alignment of the image within the component.- Parameters:
imageAlign- The horizontal alignment of the image.
-
setImageValign
Sets the vertical alignment of the image within the component.- Parameters:
imageValign- The vertical alignment of the image.
-
setHeight
public void setHeight(double height) Sets the height of the component and rescales the image.- Overrides:
setHeightin classGuiComponent- Parameters:
height- The new height of the component.
-
setWidth
public void setWidth(double width) Sets the width of the component and rescales the image.- Overrides:
setWidthin classGuiComponent- Parameters:
width- The new width of the component.
-
getSpritesheet
Retrieves the spritesheet used by the component.- Returns:
- The spritesheet used by the component.
-