@@ -24,6 +24,8 @@ public Area(int x, int y, int width, int height)
2424 Width = width ;
2525 Height = height ;
2626 }
27+ public float [ ] ToFloatArray ( ) => new float [ ] { X , Y , X + Width , Y , X + Width , Y + Height , X , Y + Height } ; // Clockwise
28+
2729 }
2830 public enum SelectorType
2931 {
@@ -32,6 +34,7 @@ public enum SelectorType
3234 Resize ,
3335 None
3436 }
37+ private Shape ? _selectedShape ;
3538
3639 private List < ( Renderer vao , Area hitbox , SelectorType type ) > _vaos ; // TODO: Just have a List<Renderer> like Shape in order to put it in the interface
3740
@@ -45,6 +48,8 @@ public void Select(Shape shape)
4548 {
4649 DeleteObjects ( ) ;
4750
51+ _selectedShape = shape ;
52+
4853 // Edge
4954 Area hitbox = new Area
5055 {
@@ -53,7 +58,7 @@ public void Select(Shape shape)
5358 Width = shape . Width ,
5459 Height = shape . Height
5560 } ;
56- _vaos . Add ( ( new Renderer ( AreaToFloatArray ( hitbox ) , new uint [ ] { 0 , 1 , 2 , 3 } , PrimitiveType . LineLoop ) , hitbox , SelectorType . Edge ) ) ;
61+ _vaos . Add ( ( new Renderer ( hitbox . ToFloatArray ( ) , new uint [ ] { 0 , 1 , 2 , 3 } , PrimitiveType . LineLoop ) , hitbox , SelectorType . Edge ) ) ;
5762
5863 // Move selector (top-left)
5964 hitbox = new Area
@@ -64,7 +69,7 @@ public void Select(Shape shape)
6469 Height = 10
6570 } ;
6671 if ( shape . IsMoveable )
67- _vaos . Add ( ( new Renderer ( AreaToFloatArray ( hitbox ) , new uint [ ] { 0 , 1 , 2 , 0 , 2 , 3 } , PrimitiveType . Triangles ) , hitbox , SelectorType . Move ) ) ;
72+ _vaos . Add ( ( new Renderer ( hitbox . ToFloatArray ( ) , new uint [ ] { 0 , 1 , 2 , 0 , 2 , 3 } , PrimitiveType . Triangles ) , hitbox , SelectorType . Move ) ) ;
6873
6974 // Resize selector (bottom-right)
7075 hitbox = new Area
@@ -75,28 +80,27 @@ public void Select(Shape shape)
7580 Height = 10
7681 } ;
7782 if ( shape . IsResizeable )
78- _vaos . Add ( ( new Renderer ( AreaToFloatArray ( hitbox ) , new uint [ ] { 0 , 1 , 2 , 0 , 2 , 3 } , PrimitiveType . Triangles ) , hitbox , SelectorType . Resize ) ) ;
79- }
80- public static float [ ] AreaToFloatArray ( Area area )
81- {
82- return new float [ ]
83- {
84- area . X , area . Y , area . X + area . Width , area . Y , area . X + area . Width , area . Y + area . Height , area . X , area . Y + area . Height // Clockwise
85- } ;
83+ _vaos . Add ( ( new Renderer ( hitbox . ToFloatArray ( ) , new uint [ ] { 0 , 1 , 2 , 0 , 2 , 3 } , PrimitiveType . Triangles ) , hitbox , SelectorType . Resize ) ) ;
8684 }
85+
8786 public void Draw ( Vector2i clientSize , Camera camera )
8887 {
8988 GL . Enable ( EnableCap . LineSmooth ) ;
90- GL . LineWidth ( 3.0f ) ;
89+ GL . LineWidth ( 3.0f ) ;
90+ Matrix4 transformation = Matrix4 . Identity ;
91+
92+ if ( _selectedShape != null )
93+ transformation = Matrix4 . CreateRotationZ ( MathHelper . DegreesToRadians ( _selectedShape . Angle ) ) ;
94+
9195 foreach ( ( Renderer vao , Area _ , SelectorType type ) part in _vaos )
9296 {
9397 if ( part . type == SelectorType . Edge )
94- part . vao . Draw ( clientSize , camera , new Color4 ( 0 , 125 , 200 , 255 ) ) ;
98+ part . vao . Draw ( clientSize , camera , new Color4 ( 0 , 125 , 200 , 255 ) , transformation ) ;
9599 else
96- part . vao . Draw ( clientSize , camera , new Color4 ( 0 , 125 , 255 , 255 ) ) ;
100+ part . vao . Draw ( clientSize , camera , new Color4 ( 0 , 125 , 255 , 255 ) , transformation ) ;
97101 }
98- GL . Disable ( EnableCap . LineSmooth ) ;
99102
103+ GL . Disable ( EnableCap . LineSmooth ) ;
100104 }
101105 /// <summary>
102106 /// Return true if the given mouse position is in the selector hitbox
0 commit comments