// Mouse moves public override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); // Not holding any buttons? if (e.Button == MouseButtons.None) { // Find the nearest thing within highlight range Thing t = MapSet.NearestThingSquareRange(General.Map.ThingsFilter.VisibleThings, mousemappos, BuilderPlug.Me.HighlightThingsRange / renderer.Scale); // Highlight if not the same if (t != highlighted) { Highlight(t); } } }
// This moves the selected things relatively // Returns true when things has actually moved private bool MoveThingsRelative(Vector2D offset, bool snapgrid, bool snapnearest) { Vector2D oldpos = dragitem.Position; Vector2D tl, br; // don't move if the offset contains invalid data if (!offset.IsFinite()) { return(false); } // Find the outmost things tl = br = oldpositions[0]; for (int i = 0; i < oldpositions.Count; i++) { if (oldpositions[i].x < tl.x) { tl.x = (int)oldpositions[i].x; } if (oldpositions[i].x > br.x) { br.x = (int)oldpositions[i].x; } if (oldpositions[i].y > tl.y) { tl.y = (int)oldpositions[i].y; } if (oldpositions[i].y < br.y) { br.y = (int)oldpositions[i].y; } } // Snap to nearest? if (snapnearest) { // Find nearest unselected item within selection range Thing nearest = MapSet.NearestThingSquareRange(unselectedthings, mousemappos, BuilderPlug.Me.StitchRange / renderer.Scale); if (nearest != null) { // Move the dragged item dragitem.Move((Vector2D)nearest.Position); // Adjust the offset offset = (Vector2D)nearest.Position - dragitemposition; // Do not snap to grid! snapgrid = false; } } // Snap to grid? if (snapgrid) { // Move the dragged item dragitem.Move(dragitemposition + offset); // Snap item to grid dragitem.SnapToGrid(); // Adjust the offset offset += (Vector2D)dragitem.Position - (dragitemposition + offset); } // Make sure the offset is inside the map boundaries if (offset.x + tl.x < General.Map.FormatInterface.LeftBoundary) { offset.x = General.Map.FormatInterface.LeftBoundary - tl.x; } if (offset.x + br.x > General.Map.FormatInterface.RightBoundary) { offset.x = General.Map.FormatInterface.RightBoundary - br.x; } if (offset.y + tl.y > General.Map.FormatInterface.TopBoundary) { offset.y = General.Map.FormatInterface.TopBoundary - tl.y; } if (offset.y + br.y < General.Map.FormatInterface.BottomBoundary) { offset.y = General.Map.FormatInterface.BottomBoundary - br.y; } // Drag item moved? if (!snapgrid || ((Vector2D)dragitem.Position != oldpos)) { int i = 0; // Move selected geometry foreach (Thing t in selectedthings) { // Move vertex from old position relative to the // mouse position change since drag start t.Move(oldpositions[i] + offset); // Next i++; } // Moved return(true); } else { // No changes return(false); } }
// This moves the selected things relatively // Returns true when things has actually moved private bool MoveThingsRelative(Vector2D offset, bool snapgrid, bool snapgridincrement, bool snapnearest, bool snapcardinal) { //mxd. If snap to cardinal directions is enabled, modify the offset if (snapcardinal) { float angle = Angle2D.DegToRad((General.ClampAngle((int)Angle2D.RadToDeg(offset.GetAngle()) + 44)) / 90 * 90); offset = new Vector2D(0, -offset.GetLength()).GetRotated(angle); snapgridincrement = true; // We don't want to move Things away from the cardinal directions } Vector2D oldpos = dragitem.Position; Vector2D tl, br; // don't move if the offset contains invalid data if (!offset.IsFinite()) { return(false); } // Find the outmost things tl = br = oldpositions[0]; for (int i = 0; i < oldpositions.Count; i++) { if (oldpositions[i].x < tl.x) { tl.x = (int)oldpositions[i].x; } if (oldpositions[i].x > br.x) { br.x = (int)oldpositions[i].x; } if (oldpositions[i].y > tl.y) { tl.y = (int)oldpositions[i].y; } if (oldpositions[i].y < br.y) { br.y = (int)oldpositions[i].y; } } // Snap to nearest? if (snapnearest) { // Find nearest unselected item within selection range Thing nearest = MapSet.NearestThingSquareRange(unselectedthings, mousemappos, BuilderPlug.Me.StitchRange / renderer.Scale); if (nearest != null) { // Move the dragged item dragitem.Move((Vector2D)nearest.Position); // Adjust the offset offset = (Vector2D)nearest.Position - dragitemposition; // Do not snap to grid! snapgrid = false; snapgridincrement = false; //mxd } } // Snap to grid? if (snapgrid || snapgridincrement) { // Move the dragged item dragitem.Move(dragitemposition + offset); // Snap item to grid increment (mxd) if (snapgridincrement) { dragitem.Move(General.Map.Grid.SnappedToGrid(dragitemposition + offset) - dragstartoffset); } else // Or to the grid itself { dragitem.SnapToGrid(); } // Adjust the offset offset += (Vector2D)dragitem.Position - (dragitemposition + offset); } // Make sure the offset is inside the map boundaries if (offset.x + tl.x < General.Map.Config.LeftBoundary) { offset.x = General.Map.Config.LeftBoundary - tl.x; } if (offset.x + br.x > General.Map.Config.RightBoundary) { offset.x = General.Map.Config.RightBoundary - br.x; } if (offset.y + tl.y > General.Map.Config.TopBoundary) { offset.y = General.Map.Config.TopBoundary - tl.y; } if (offset.y + br.y < General.Map.Config.BottomBoundary) { offset.y = General.Map.Config.BottomBoundary - br.y; } // Drag item moved? if ((!snapgrid && !snapgridincrement) || ((Vector2D)dragitem.Position != oldpos)) { int i = 0; // Move selected geometry foreach (Thing t in selectedthings) { // Move vertex from old position relative to the // mouse position change since drag start t.Move(oldpositions[i] + offset); // Next i++; } // Moved return(true); } else { // No changes return(false); } }
// Mouse moves public override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); // Not holding any buttons? if (e.Button == MouseButtons.None) { General.Interface.SetCursor(Cursors.Default); // Find the nearest linedef within highlight range Linedef l = General.Map.Map.NearestLinedef(mousemappos); if (l != null) { // Check on which side of the linedef the mouse is float side = l.SideOfLine(mousemappos); if (side > 0) { // Is there a sidedef here? if (l.Back != null) { // Highlight if not the same if (l.Back.Sector != highlighted) { Highlight(l.Back.Sector); } } else if (highlighted != null) { // Highlight nothing Highlight(null); } } else { // Is there a sidedef here? if (l.Front != null) { // Highlight if not the same if (l.Front.Sector != highlighted) { Highlight(l.Front.Sector); } } else if (highlighted != null) { // Highlight nothing Highlight(null); } } } else if (highlighted != null) { // Highlight nothing Highlight(null); } //mxd. Find the nearest linedef within default highlight range l = General.Map.Map.NearestLinedefRange(mousemappos, 20 / renderer.Scale); //mxd. We are not interested in single-sided lines, unless they have zoneboundary flag... if (l != null && ((l.Front == null || l.Back == null) && !l.IsFlagSet(ZoneBoundaryFlag))) { l = null; } //mxd. Set as highlighted bool redrawrequired = false; if (highlightedline != l) { highlightedline = l; redrawrequired = true; } //mxd. Highlighted environment changed? if (oldhighlightedsoundenvironment != highlightedsoundenvironment) { oldhighlightedsoundenvironment = highlightedsoundenvironment; redrawrequired = true; } //mxd. Find the nearest thing within default highlight range if (highlightedline == null && highlightedsoundenvironment != null) { Thing t = MapSet.NearestThingSquareRange(highlightedsoundenvironment.Things, mousemappos, 10 / renderer.Scale); if (highlightedthing != t) { highlightedthing = t; redrawrequired = true; } } else if (highlightedthing != null) { highlightedthing = null; redrawrequired = true; } //mxd if (redrawrequired) { // Show highlight info if (highlightedline != null && !highlightedline.IsDisposed) { General.Interface.ShowLinedefInfo(highlightedline); } else if (highlighted != null && !highlighted.IsDisposed) { General.Interface.ShowSectorInfo(highlighted); } else { General.Interface.HideInfo(); } // Redraw display General.Interface.RedrawDisplay(); } } }
// Mouse moving public override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (selecting) { ClearHighlighted(); RenderMultiSelection(); } else { // ano - a lot of this is from codeimp's buildermodes plugins if (e.Button == MouseButtons.None) { Linedef l = General.Map.Map.NearestLinedefRange( mousemappos, HIGHLIGHT_RANGE / renderer.Scale); Thing t = MapSet.NearestThingSquareRange( General.Map.ThingsFilter.VisibleThings, mousemappos, HIGHLIGHT_THINGS_RANGE / renderer.Scale); Vertex v = General.Map.Map.NearestVertexSquareRange( mousemappos, HIGHLIGHT_VERTICES_RANGE / renderer.Scale); Sector s = null; Linedef ls = l; if (ls == null) { ls = General.Map.Map.NearestLinedef(mousemappos); } if (ls != null) { // Check on which side of the linedef the mouse is float side = ls.SideOfLine(mousemappos); if (side > 0) { // Is there a sidedef here? if (ls.Back != null) { s = ls.Back.Sector; } } else if (ls.Front != null) { s = ls.Front.Sector; } } HighlightType htype = HighlightType.Null; if (v != null) { htype = HighlightType.Vertex; } if (t != null) { if (htype == HighlightType.Null) { htype = HighlightType.Thing; } else if (htype == HighlightType.Vertex && v.DistanceToSq(mousemappos) > t.DistanceToSq(mousemappos)) { // figure out which is closer and highlight that one htype = HighlightType.Thing; } } if (l != null) { switch (htype) { case HighlightType.Vertex: break; case HighlightType.Thing: if (l.SafeDistanceToSq(mousemappos, false) < t.DistanceToSq(mousemappos)) { // figure out which is closer and highlight that one htype = HighlightType.Linedef; } break; default: htype = HighlightType.Linedef; break; } } if (htype == HighlightType.Null && s != null) { htype = HighlightType.Sector; } switch (htype) { case HighlightType.Linedef: HighlightLinedef(l); break; case HighlightType.Sector: HighlightSector(s); break; case HighlightType.Vertex: HighlightVertex(v); break; case HighlightType.Thing: HighlightThing(t); break; case HighlightType.Null: default: // highlight nothing ClearHighlighted(); renderer.Present(); break; } // switch } if (renderer.StartOverlay(true)) { DrawCursor(); renderer.Finish(); renderer.Present(); } } }