@@ -13,6 +13,7 @@ import {
1313 selectorSelectedEllipse ,
1414} from "reduxes/annotation/selector" ;
1515import { DrawObject , DrawState , DrawType } from "reduxes/annotation/type" ;
16+ import { selectorCurrentImageInEditorProps } from "reduxes/annotationmanager/selecetor" ;
1617import { CIRCLE_STYLE , CORNER_RADIUS , LINE_STYLE } from "../const" ;
1718import { EllipseCompProps , EllipseProps , EllipseSpec } from "../type" ;
1819import useCommonShapeEvent from "../useCommonShapeEvent" ;
@@ -47,7 +48,9 @@ function EllipseComp({
4748 const commonShapeEvent = useCommonShapeEvent ( { drawObject : spec } ) ;
4849 const currentDrawState = useSelector ( selectorCurrentDrawState ) ;
4950 const drawObjectState = useSelector ( selectorDrawObjectState ( spec . id ) ) ;
50-
51+ const currentImageInEditorProps = useSelector (
52+ selectorCurrentImageInEditorProps
53+ ) ;
5154 const [ strokeWidth , setStrokeWidth ] = useState < number > (
5255 spec . cssStyle . strokeWidth
5356 ) ;
@@ -75,28 +78,62 @@ function EllipseComp({
7578 trRef . current . getLayer ( ) . batchDraw ( ) ;
7679 }
7780 } , [ isSelected ] ) ;
78- const [ stage , setStage ] = useState < Konva . Stage | null > ( null ) ;
7981
8082 const groupDragBound = ( pos : Vector2d ) => {
8183 let { x, y } = pos ;
82- const sw = stage ? stage . width ( ) : 0 ;
83- const sh = stage ? stage . height ( ) : 0 ;
84- if ( shapeRef && shapeRef . current ) {
84+ if ( shapeRef && shapeRef . current && currentImageInEditorProps ) {
85+ const { clientRectOfBaseImage } = currentImageInEditorProps ;
8586 const box = shapeRef . current . getClientRect ( ) ;
8687
87- if ( y - box . height / 2 < 0 ) y = box . height / 2 ;
88- if ( x - box . width / 2 < 0 ) x = box . width / 2 ;
89- if ( y + box . height / 2 > sh ) y = sh - box . height / 2 ;
90- if ( x + box . width / 2 > sw ) x = sw - box . width / 2 ;
91- return { x, y } ;
88+ if ( clientRectOfBaseImage ) {
89+ if ( x - box . width / 2 < clientRectOfBaseImage . x ) {
90+ x = clientRectOfBaseImage . x + box . width / 2 ;
91+ }
92+ if ( y - box . height / 2 < clientRectOfBaseImage . y ) {
93+ y = clientRectOfBaseImage . y + box . height / 2 ;
94+ }
95+ if (
96+ x + box . width >
97+ clientRectOfBaseImage . x + clientRectOfBaseImage . width
98+ ) {
99+ x =
100+ clientRectOfBaseImage . x +
101+ clientRectOfBaseImage . width -
102+ box . width / 2 ;
103+ }
104+ if (
105+ y + box . height >
106+ clientRectOfBaseImage . y + clientRectOfBaseImage . height
107+ ) {
108+ y =
109+ clientRectOfBaseImage . y +
110+ clientRectOfBaseImage . height -
111+ box . height / 2 ;
112+ }
113+ }
92114 }
93- return { x : 0 , y : 0 } ;
94- } ;
95115
96- const handleDragStart = ( e : KonvaEventObject < DragEvent > ) => {
97- setStage ( e . target . getStage ( ) ) ;
98- commonShapeEvent . handleDragStart ( e ) ;
116+ return {
117+ x,
118+ y,
119+ } ;
99120 } ;
121+ // const groupDragBound = (pos: Vector2d) => {
122+ // let { x, y } = pos;
123+ // const sw = stage ? stage.width() : 0;
124+ // const sh = stage ? stage.height() : 0;
125+ // if (shapeRef && shapeRef.current) {
126+ // const box = shapeRef.current.getClientRect();
127+
128+ // if (y - box.height / 2 < 0) y = box.height / 2;
129+ // if (x - box.width / 2 < 0) x = box.width / 2;
130+ // if (y + box.height / 2 > sh) y = sh - box.height / 2;
131+ // if (x + box.width / 2 > sw) x = sw - box.width / 2;
132+ // return { x, y };
133+ // }
134+ // return { x: 0, y: 0 };
135+ // };
136+
100137 const handleTransformEnd = ( e : KonvaEventObject < Event > ) => {
101138 const node = shapeRef . current ;
102139 if ( ! node ) return ;
@@ -150,7 +187,6 @@ function EllipseComp({
150187 onMouseOut = { onMouseOut }
151188 draggable = { commonShapeEvent . isLock !== true }
152189 onDragEnd = { handleDragEnd }
153- onDragStart = { handleDragStart }
154190 onTransformEnd = { handleTransformEnd }
155191 strokeScaleEnabled = { false }
156192 { ...spec }
0 commit comments