1
Resize Shapes
Thibaud edited this page 2026-03-19 22:40:54 +01:00

Plan: Resize Shapes

Overview

Add the ability to resize shapes by dragging corner handles on selected shapes.

Current State

  • Selection already draws red corner handles via ShapeDraftman.drawHandlerIfSelected()
  • Controller handles mouse events for selection and moving
  • Selection uses SelectionAttributes on shapes

Implementation Plan

1. ResizeHandle enum

  • Create ResizeHandle enum in shapes/ package with positions: NW, N, NE, E, SE, S, SW, W
  • Each handle knows its cursor type

2. Controller changes

  • Add mouse state: resizing (boolean), activeHandle (ResizeHandle), resizeOrigin (Point)
  • Add getHandleAt(Point) method to find which handle is clicked
  • Modify mouse handlers:
    • mousePressed: If click is on a handle, enter resize mode
    • mouseDragged: If resizing, calculate delta and call shape's resize method
    • mouseReleased: Exit resize mode
  • Add cursor changes based on handle position

3. Shape interface changes

  • Add resize(ResizeHandle handle, int dx, int dy) method to Shape interface
  • Implement in AbstractShape or each concrete shape
  • For basic shapes (rectangle, circle, triangle):
    • Rectangle: adjust width/height based on handle
    • Circle: adjust radius (maintain aspect ratio or allow ellipse)
    • Triangle: adjust vertices

4. Visual feedback

  • Update ShapeDraftman to use different handle positions (not just corners)
  • Consider showing resize preview during drag

Files to modify

  • shapes/Shape.java - add resize method
  • ui/Controller.java - mouse handling for resize
  • shapes/SRectangle.java, SCircle.java, STriangle.java - implement resize logic

Alternative consideration

  • Could use a separate Resizer class to keep Controller clean
  • Could implement resize in AbstractShape for common logic