Class MouseDrawComponent
java.lang.Object
de.gurkenlabs.litiengine.gui.GuiComponent
de.gurkenlabs.litiengine.gui.ImageComponent
de.gurkenlabs.litiengine.gui.MouseDrawComponent
- All Implemented Interfaces:
IRenderable,Tweenable,MouseListener,MouseMotionListener,MouseWheelListener,EventListener
Represents a GUI component that supports freehand drawing using mouse input.
-
Field Summary
Fields inherited from class de.gurkenlabs.litiengine.gui.ImageComponent
BACKGROUND_DISABLED_INDEX, BACKGROUND_HOVER_INDEX, BACKGROUND_INDEX, BACKGROUND_PRESSED_INDEXFields inherited from class de.gurkenlabs.litiengine.gui.GuiComponent
ICON_FONT -
Constructor Summary
ConstructorsConstructorDescriptionMouseDrawComponent(double x, double y, double width, double height, Spritesheet spritesheet, String text, Image image) Creates a new instance of theMouseDrawComponent. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the entire drawing space, removing all drawings.doubleGets the size of the brush used for drawing.Gets the current color of the brush.Gets the current drawing space.voidHandles mouse drag events to draw or erase on the component.voidrender(Graphics2D g) Renders the component and the current drawing on the graphics context.voidsetBrushSize(double newSize) Sets the size of the brush used for drawing.voidsetDrawingColor(Color color) Sets the color of the brush used for drawing.Methods inherited from class de.gurkenlabs.litiengine.gui.ImageComponent
getBackground, getHorizontalImagePadding, getImage, getImageAlign, getImageScaleInterpolation, getImageScaleMode, getImageValign, getSpritesheet, getSpritesheetScaleFactor, getSpritesheetScaleInterpolation, getSpritesheetScaleMode, getVerticalImagePadding, rescaleImage, setHeight, setHorizontalImagePadding, setImage, setImageAlign, setImageScaleInterpolation, setImageScaleMode, setImageValign, setSpritesheet, setSpritesheet, setSpritesheet, setSpritesheetScaleFactor, setSpritesheetScaleInterpolation, setSpritesheetScaleMode, setVerticalImagePadding, setWidthMethods 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, 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
-
Constructor Details
-
MouseDrawComponent
public MouseDrawComponent(double x, double y, double width, double height, Spritesheet spritesheet, String text, Image image) Creates a new instance of theMouseDrawComponent.- Parameters:
x- The x-coordinate of the component's position.y- The y-coordinate of the component's position.width- The width of the component.height- The height of the component.spritesheet- The spritesheet associated with the component.text- The text displayed on the component.image- The image used for rendering the component.
-
-
Method Details
-
render
Renders the component and the current drawing on the graphics context.- Specified by:
renderin interfaceIRenderable- Overrides:
renderin classImageComponent- Parameters:
g- TheGraphics2Dcontext used for rendering.- See Also:
-
setBrushSize
public void setBrushSize(double newSize) Sets the size of the brush used for drawing.- Parameters:
newSize- The new brush size.
-
getBrushSize
public double getBrushSize()Gets the size of the brush used for drawing.- Returns:
- The current brush size.
-
getDrawingColor
Gets the current color of the brush.- Returns:
- The current drawing color.
-
setDrawingColor
Sets the color of the brush used for drawing.- Parameters:
color- The new drawing color.
-
mouseDragged
Handles mouse drag events to draw or erase on the component. Left mouse button draws with the current brush color, while right mouse button clears the area.- Specified by:
mouseDraggedin interfaceMouseMotionListener- Overrides:
mouseDraggedin classGuiComponent- Parameters:
e- TheMouseEventtriggered by dragging the mouse.
-
clearDrawingSpace
public void clearDrawingSpace()Clears the entire drawing space, removing all drawings. -
getDrawingSpace
Gets the current drawing space.- Returns:
- The
BufferedImageused for drawing.
-