@@ -87,66 +87,14 @@ public IReadOnlyGrid<Tile> SelectedTiles
8787 {
8888 get { return this . selectedTiles ; }
8989 }
90- internal void TranslateSelectedArea ( int offsetX , int offsetY )
91- {
92- if ( this . selectedArea . IsEmpty )
93- {
94- this . InitializeSelectedArea ( ) ;
95- return ;
96- }
97-
98- int newX = MathF . Clamp ( this . selectedArea . X + offsetX , 0 , this . DisplayedTileCount . X - this . selectedArea . Width ) ;
99- int newY = MathF . Clamp ( this . selectedArea . Y + offsetY , 0 , this . DisplayedTileCount . Y - this . selectedArea . Height ) ;
10090
101- this . SelectedArea = new Rectangle ( newX , newY , this . selectedArea . Width , this . selectedArea . Height ) ;
102- this . RaiseSelectedAreaEditingFinished ( ) ;
103- this . Invalidate ( ) ;
104- }
105- internal void ExpandSelectedArea ( int diffX , int diffY )
91+ internal void RaiseKeyDownEvent ( KeyEventArgs e )
10692 {
107- if ( this . selectedArea . IsEmpty )
108- {
109- this . InitializeSelectedArea ( ) ;
110- return ;
111- }
112-
113- int newX = MathF . Max ( this . selectedArea . X + MathF . Min ( diffX , 0 ) , 0 ) ;
114- int newY = MathF . Max ( this . selectedArea . Y + MathF . Min ( diffY , 0 ) , 0 ) ;
115-
116- int newWidth = this . selectedArea . Width + MathF . Max ( diffX , 0 ) ;
117- newWidth = MathF . Min ( newWidth , this . DisplayedTileCount . X - this . selectedArea . X ) ;
118- newWidth += this . selectedArea . X - newX ;
119-
120- int newHeight = this . selectedArea . Height + MathF . Max ( diffY , 0 ) ;
121- newHeight = MathF . Min ( newHeight , this . DisplayedTileCount . Y - this . selectedArea . Y ) ;
122- newHeight += this . selectedArea . Y - newY ;
123-
124- this . SelectedArea = new Rectangle ( newX , newY , newWidth , newHeight ) ;
125- this . RaiseSelectedAreaEditingFinished ( ) ;
126- this . Invalidate ( ) ;
93+ this . OnKeyDown ( e ) ;
12794 }
128- public void ShrinkSelectedArea ( int diffX , int diffY )
95+ internal void RaiseKeyUpEvent ( KeyEventArgs e )
12996 {
130- if ( this . selectedArea . IsEmpty )
131- {
132- this . InitializeSelectedArea ( ) ;
133- return ;
134- }
135-
136- int newX = MathF . Min ( this . selectedArea . X + MathF . Max ( diffX , 0 ) ,
137- this . selectedArea . X + this . selectedArea . Width - 1 ) ;
138- int newY = MathF . Min ( this . selectedArea . Y + MathF . Max ( diffY , 0 ) ,
139- this . selectedArea . Y + this . selectedArea . Height - 1 ) ;
140-
141- int newWidth = MathF . Max ( this . selectedArea . Width + MathF . Min ( diffX , 0 ) , 1 ) ;
142- newWidth -= newX - this . selectedArea . X ;
143-
144- int newHeight = MathF . Max ( this . selectedArea . Height + MathF . Min ( diffY , 0 ) , 1 ) ;
145- newHeight -= newY - this . selectedArea . Y ;
146-
147- this . SelectedArea = new Rectangle ( newX , newY , newWidth , newHeight ) ;
148- this . RaiseSelectedAreaEditingFinished ( ) ;
149- this . Invalidate ( ) ;
97+ this . OnKeyUp ( e ) ;
15098 }
15199
152100 protected override void OnTilesetChanged ( )
@@ -538,5 +486,66 @@ private void RaiseSelectedAreaChanged()
538486 {
539487 this . SelectedAreaChanged ? . Invoke ( this , EventArgs . Empty ) ;
540488 }
489+ private void TranslateSelectedArea ( int offsetX , int offsetY )
490+ {
491+ if ( this . selectedArea . IsEmpty )
492+ {
493+ this . InitializeSelectedArea ( ) ;
494+ return ;
495+ }
496+
497+ int newX = MathF . Clamp ( this . selectedArea . X + offsetX , 0 , this . DisplayedTileCount . X - this . selectedArea . Width ) ;
498+ int newY = MathF . Clamp ( this . selectedArea . Y + offsetY , 0 , this . DisplayedTileCount . Y - this . selectedArea . Height ) ;
499+
500+ this . SelectedArea = new Rectangle ( newX , newY , this . selectedArea . Width , this . selectedArea . Height ) ;
501+ this . RaiseSelectedAreaEditingFinished ( ) ;
502+ this . Invalidate ( ) ;
503+ }
504+ private void ExpandSelectedArea ( int diffX , int diffY )
505+ {
506+ if ( this . selectedArea . IsEmpty )
507+ {
508+ this . InitializeSelectedArea ( ) ;
509+ return ;
510+ }
511+
512+ int newX = MathF . Max ( this . selectedArea . X + MathF . Min ( diffX , 0 ) , 0 ) ;
513+ int newY = MathF . Max ( this . selectedArea . Y + MathF . Min ( diffY , 0 ) , 0 ) ;
514+
515+ int newWidth = this . selectedArea . Width + MathF . Max ( diffX , 0 ) ;
516+ newWidth = MathF . Min ( newWidth , this . DisplayedTileCount . X - this . selectedArea . X ) ;
517+ newWidth += this . selectedArea . X - newX ;
518+
519+ int newHeight = this . selectedArea . Height + MathF . Max ( diffY , 0 ) ;
520+ newHeight = MathF . Min ( newHeight , this . DisplayedTileCount . Y - this . selectedArea . Y ) ;
521+ newHeight += this . selectedArea . Y - newY ;
522+
523+ this . SelectedArea = new Rectangle ( newX , newY , newWidth , newHeight ) ;
524+ this . RaiseSelectedAreaEditingFinished ( ) ;
525+ this . Invalidate ( ) ;
526+ }
527+ private void ShrinkSelectedArea ( int diffX , int diffY )
528+ {
529+ if ( this . selectedArea . IsEmpty )
530+ {
531+ this . InitializeSelectedArea ( ) ;
532+ return ;
533+ }
534+
535+ int newX = MathF . Min ( this . selectedArea . X + MathF . Max ( diffX , 0 ) ,
536+ this . selectedArea . X + this . selectedArea . Width - 1 ) ;
537+ int newY = MathF . Min ( this . selectedArea . Y + MathF . Max ( diffY , 0 ) ,
538+ this . selectedArea . Y + this . selectedArea . Height - 1 ) ;
539+
540+ int newWidth = MathF . Max ( this . selectedArea . Width + MathF . Min ( diffX , 0 ) , 1 ) ;
541+ newWidth -= newX - this . selectedArea . X ;
542+
543+ int newHeight = MathF . Max ( this . selectedArea . Height + MathF . Min ( diffY , 0 ) , 1 ) ;
544+ newHeight -= newY - this . selectedArea . Y ;
545+
546+ this . SelectedArea = new Rectangle ( newX , newY , newWidth , newHeight ) ;
547+ this . RaiseSelectedAreaEditingFinished ( ) ;
548+ this . Invalidate ( ) ;
549+ }
541550 }
542551}
0 commit comments