Class MouseDrawComponent

All Implemented Interfaces:
IRenderable, Tweenable, MouseListener, MouseMotionListener, MouseWheelListener, EventListener

public class MouseDrawComponent extends ImageComponent
Represents a GUI component that supports freehand drawing using mouse input.
  • Constructor Details

    • MouseDrawComponent

      public MouseDrawComponent(double x, double y, double width, double height, Spritesheet spritesheet, String text, Image image)
      Creates a new instance of the MouseDrawComponent.
      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

      public void render(Graphics2D g)
      Renders the component and the current drawing on the graphics context.
      Specified by:
      render in interface IRenderable
      Overrides:
      render in class ImageComponent
      Parameters:
      g - The Graphics2D context 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

      public Color getDrawingColor()
      Gets the current color of the brush.
      Returns:
      The current drawing color.
    • setDrawingColor

      public void setDrawingColor(Color color)
      Sets the color of the brush used for drawing.
      Parameters:
      color - The new drawing color.
    • mouseDragged

      public void mouseDragged(MouseEvent e)
      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:
      mouseDragged in interface MouseMotionListener
      Overrides:
      mouseDragged in class GuiComponent
      Parameters:
      e - The MouseEvent triggered by dragging the mouse.
    • clearDrawingSpace

      public void clearDrawingSpace()
      Clears the entire drawing space, removing all drawings.
    • getDrawingSpace

      public BufferedImage getDrawingSpace()
      Gets the current drawing space.
      Returns:
      The BufferedImage used for drawing.