@@ -13,31 +13,102 @@ namespace STROOP.Tabs.MapTab
1313 [ ObjectDescription ( "Tape Measure" , "Custom" ) ]
1414 public class MapTapeMeasureObject : MapLineObject
1515 {
16+ class TapeHoverData : IHoverData
17+ {
18+ MapTapeMeasureObject parent ;
19+ public bool dragA ;
20+ ContextMenuStrip rightClickMenu = new ContextMenuStrip ( ) ;
21+ float cursorY ;
22+ public TapeHoverData ( MapTapeMeasureObject parent )
23+ {
24+ this . parent = parent ;
25+
26+ var copyPositionItem = new ToolStripMenuItem ( "Copy Position" ) ;
27+ copyPositionItem . Click += ( _ , __ ) =>
28+ {
29+ Vector2 src = dragA ? parent . a : parent . b ;
30+ Vector3 vec3 = new Vector3 ( src . X , cursorY , src . Y ) ;
31+ DataObject vec3Data = new DataObject ( "Position" , vec3 ) ;
32+ vec3Data . SetText ( $ "{ vec3 . X } ; { vec3 . Y } ; { vec3 . Z } ") ;
33+ Clipboard . SetDataObject ( vec3Data ) ;
34+ } ;
35+ rightClickMenu . Items . Add ( copyPositionItem ) ;
36+
37+ var pastePositionItem = new ToolStripMenuItem ( "Paste Position" ) ;
38+ pastePositionItem . Click += ( _ , __ ) =>
39+ {
40+ bool hasData = false ;
41+ var clipboardObj = Clipboard . GetDataObject ( ) ;
42+ Vector3 textVector ;
43+ if ( ! ( hasData |= ParsingUtilities . TryParseVector3 ( clipboardObj . GetData ( DataFormats . Text ) as string , out textVector ) ) )
44+ {
45+ if ( Clipboard . GetData ( "Position" ) is Vector3 dataVector )
46+ {
47+ hasData = true ;
48+ textVector = dataVector ;
49+ }
50+ }
51+ if ( hasData )
52+ {
53+ if ( dragA )
54+ parent . a = new Vector2 ( textVector . X , textVector . Z ) ;
55+ else
56+ parent . b = new Vector2 ( textVector . X , textVector . Z ) ;
57+ }
58+ } ;
59+ rightClickMenu . Items . Add ( pastePositionItem ) ;
60+ }
61+
62+ public bool CanDrag ( ) => parent . itemEnableDragging . Checked ;
63+
64+ public void DragTo ( Vector3 newPosition )
65+ {
66+ if ( dragA )
67+ parent . a = new Vector2 ( newPosition . X , newPosition . Z ) ;
68+ else
69+ parent . b = new Vector2 ( newPosition . X , newPosition . Z ) ;
70+ parent . targetTracker . textBoxSize . Text = ( parent . Size = ( parent . a - parent . b ) . Length ) . ToString ( ) ;
71+ }
72+
73+ public void LeftClick ( ) { }
74+
75+ public void RightClick ( )
76+ {
77+ cursorY = parent . graphics . mapCursorPosition . Y ;
78+ rightClickMenu . Show ( Cursor . Position ) ;
79+ }
80+ }
81+
1682 Vector2 a , b ;
83+ new TapeHoverData hoverData ;
1784
1885 public MapTapeMeasureObject ( )
1986 {
2087 OutlineColor = Color . Orange ;
2188 OutlineWidth = 3 ;
89+ a = new Vector2 ( graphics . MapViewCenterXValue - 50 , graphics . MapViewCenterZValue ) ;
90+ b = new Vector2 ( graphics . MapViewCenterXValue + 50 , graphics . MapViewCenterZValue ) ;
91+ hoverData = new TapeHoverData ( this ) ;
2292 }
2393
2494 MapTracker targetTracker ;
95+ ToolStripMenuItem itemEnableDragging ;
2596
2697 public override ContextMenuStrip GetContextMenuStrip ( MapTracker targetTracker )
2798 {
2899 this . targetTracker = targetTracker ;
29100 if ( _contextMenuStrip == null )
30101 {
31- ToolStripMenuItem itemFreeze = new ToolStripMenuItem ( "Enable Drawing " ) ;
102+ itemEnableDragging = new ToolStripMenuItem ( "Enable dragging " ) ;
32103 var capturedMapTab = currentMapTab ;
33- itemFreeze . Click += ( sender , e ) =>
104+ itemEnableDragging . Click += ( sender , e ) =>
34105 {
35- itemFreeze . Checked = ! itemFreeze . Checked ;
106+ itemEnableDragging . Checked = ! itemEnableDragging . Checked ;
36107 } ;
37108
38109 _contextMenuStrip = new ContextMenuStrip ( ) ;
39- _contextMenuStrip . Items . Add ( itemFreeze ) ;
40- itemFreeze . PerformClick ( ) ;
110+ _contextMenuStrip . Items . Add ( itemEnableDragging ) ;
111+ itemEnableDragging . PerformClick ( ) ;
41112 }
42113
43114 return _contextMenuStrip ;
@@ -48,22 +119,24 @@ public override ContextMenuStrip GetContextMenuStrip(MapTracker targetTracker)
48119 public override string GetName ( ) => "Tape Measure" ;
49120
50121 protected override List < Vector3 > GetVertices ( MapGraphics graphics ) =>
51- new List < Vector3 > ( new [ ] { new Vector3 ( a . X , 0 , a . Y ) , new Vector3 ( b . X , 0 , b . Y ) } ) ;
52-
53-
54- //public override void NotifyMouseEvent(MouseEvent mouseEvent, bool isLeftButton, int mouseX, int mouseY)
55- //{
56- // Vector3 coords = Vector3.TransformPosition(
57- // new Vector3(2 * (float)mouseX / graphics.glControl.Width - 1, 1 - 2 * (float)mouseY / graphics.glControl.Height, 0),
58- // Matrix4.Invert(graphics.ViewMatrix));
59- // if (mouseEvent == MouseEvent.MouseDown)
60- // {
61- // if (isLeftButton)
62- // a = coords.Xy;
63- // else
64- // b = coords.Xy;
65- // targetTracker.textBoxSize.Text = (Size = (a - b).Length).ToString();
66- // }
67- //}
122+ new List < Vector3 > ( new [ ] { new Vector3 ( a . X , 0 , a . Y ) , new Vector3 ( b . X , 0 , b . Y ) } ) ;
123+
124+ public override IHoverData GetHoverData ( )
125+ {
126+ var cursor2D = new Vector2 ( graphics . mapCursorPosition . X , graphics . mapCursorPosition . Z ) ;
127+ var rad = ( 5 / graphics . MapViewScaleValue ) ;
128+ rad *= rad ;
129+ if ( ( cursor2D - a ) . LengthSquared < rad )
130+ {
131+ hoverData . dragA = true ;
132+ return hoverData ;
133+ }
134+ else if ( ( cursor2D - b ) . LengthSquared < rad )
135+ {
136+ hoverData . dragA = false ;
137+ return hoverData ;
138+ }
139+ return null ;
140+ }
68141 }
69142}
0 commit comments