11import { Rectangle } from "../../../../dataStruct/shape/Rectangle" ;
22import { Vector } from "../../../../dataStruct/Vector" ;
33import { Renderer } from "../../../../render/canvas2d/renderer" ;
4+ import { Stage } from "../../../../stage/Stage" ;
45import { SectionMethods } from "../../../../stage/stageManager/basicMethods/SectionMethods" ;
56import { StageManager } from "../../../../stage/stageManager/StageManager" ;
7+ import { StageObject } from "../../../../stage/stageObject/abstract/StageObject" ;
68import { Section } from "../../../../stage/stageObject/entity/Section" ;
79import { Controller } from "../Controller" ;
810import { ControllerClass } from "../ControllerClass" ;
@@ -104,6 +106,9 @@ class ControllerRectangleSelectClass extends ControllerClass {
104106
105107 // 更新框选框
106108 this . selectingRectangle = Rectangle . fromTwoPoints ( this . selectStartLocation , this . selectEndLocation ) ;
109+ // 更新框选方向
110+ this . isSelectDirectionRight = this . selectStartLocation . x < this . selectEndLocation . x ;
111+
107112 // 框选框在 section框中的限制情况
108113 if ( this . mouseDownSection !== null ) {
109114 this . selectingRectangle = Rectangle . getIntersectionRectangle (
@@ -127,7 +132,7 @@ class ControllerRectangleSelectClass extends ControllerClass {
127132 if ( entity . isHiddenBySectionCollapse ) {
128133 continue ;
129134 }
130- if ( entity . collisionBox . isIntersectsWithRectangle ( this . selectingRectangle ) ) {
135+ if ( this . isSelectWithEntity ( entity ) ) {
131136 if ( Controller . lastSelectedEntityUUID . has ( entity . uuid ) ) {
132137 entity . isSelected = false ;
133138 } else {
@@ -136,7 +141,7 @@ class ControllerRectangleSelectClass extends ControllerClass {
136141 }
137142 }
138143 for ( const edge of StageManager . getLineEdges ( ) ) {
139- if ( edge . collisionBox . isIntersectsWithRectangle ( this . selectingRectangle ) ) {
144+ if ( this . isSelectWithEntity ( edge ) ) {
140145 if ( Controller . lastSelectedEdgeUUID . has ( edge . uuid ) ) {
141146 edge . isSelected = false ;
142147 } else {
@@ -159,7 +164,7 @@ class ControllerRectangleSelectClass extends ControllerClass {
159164 continue ;
160165 }
161166
162- if ( otherEntities . collisionBox . isIntersectsWithRectangle ( this . selectingRectangle ) ) {
167+ if ( this . isSelectWithEntity ( otherEntities ) ) {
163168 otherEntities . isSelected = true ;
164169 isHaveEntity = true ;
165170 }
@@ -173,7 +178,7 @@ class ControllerRectangleSelectClass extends ControllerClass {
173178 if ( edge . isHiddenBySectionCollapse ) {
174179 continue ;
175180 }
176- if ( edge . collisionBox . isIntersectsWithRectangle ( this . selectingRectangle ) ) {
181+ if ( this . isSelectWithEntity ( edge ) ) {
177182 edge . isSelected = true ;
178183 }
179184 }
@@ -186,6 +191,34 @@ class ControllerRectangleSelectClass extends ControllerClass {
186191 ControllerRectangleSelect . lastMoveLocation = worldLocation . clone ( ) ;
187192 } ;
188193
194+ /**
195+ * 判断当前的框选框是否选中了某个实体
196+ * @param entity
197+ */
198+ private isSelectWithEntity ( entity : StageObject ) {
199+ if ( entity . collisionBox && this . selectingRectangle ) {
200+ const mode = this . getSelectMode ( ) ;
201+ if ( mode === "intersect" ) {
202+ return entity . collisionBox . isIntersectsWithRectangle ( this . selectingRectangle ) ;
203+ } else {
204+ return entity . collisionBox . isContainedByRectangle ( this . selectingRectangle ) ;
205+ }
206+ }
207+ return false ;
208+ }
209+ /**
210+ * 当前的框选框的方向
211+ */
212+ private isSelectDirectionRight = false ;
213+ // 获取此时此刻应该的框选逻辑
214+ private getSelectMode ( ) : "contain" | "intersect" {
215+ if ( this . isSelectDirectionRight ) {
216+ return Stage . rectangleSelectWhenRight ;
217+ } else {
218+ return Stage . rectangleSelectWhenLeft ;
219+ }
220+ }
221+
189222 public mouseup = ( event : MouseEvent ) => {
190223 if ( event . button !== 0 ) {
191224 return ;
0 commit comments