Page:
Resize Shapes
Clone
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() Controllerhandles mouse events for selection and moving- Selection uses
SelectionAttributeson shapes
Implementation Plan
1. ResizeHandle enum
- Create
ResizeHandleenum inshapes/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 modemouseDragged: If resizing, calculate delta and call shape's resize methodmouseReleased: Exit resize mode
- Add cursor changes based on handle position
3. Shape interface changes
- Add
resize(ResizeHandle handle, int dx, int dy)method toShapeinterface - Implement in
AbstractShapeor 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
ShapeDraftmanto use different handle positions (not just corners) - Consider showing resize preview during drag
Files to modify
shapes/Shape.java- add resize methodui/Controller.java- mouse handling for resizeshapes/SRectangle.java,SCircle.java,STriangle.java- implement resize logic
Alternative consideration
- Could use a separate
Resizerclass to keep Controller clean - Could implement resize in
AbstractShapefor common logic