public void addRenderer2d(IRenderer2D renderer) { _renderers.Add(renderer); }
public void removeRenderer2d(IRenderer2D renderer) { _renderers.Remove(renderer); }
// This returns the aligned and snapped draw position public static DrawnVertex GetCurrentPosition(Vector2D mousemappos, bool snaptonearest, bool snaptogrid, IRenderer2D renderer, List <DrawnVertex> points) { DrawnVertex p = new DrawnVertex(); Vector2D vm = mousemappos; float vrange = BuilderPlug.Me.StitchRange / renderer.Scale; // Snap to nearest? if (snaptonearest) { // Go for all drawn points foreach (DrawnVertex v in points) { if (Vector2D.DistanceSq(mousemappos, v.pos) < (vrange * vrange)) { p.pos = v.pos; p.stitch = true; p.stitchline = true; return(p); } } // Try the nearest vertex Vertex nv = General.Map.Map.NearestVertexSquareRange(mousemappos, vrange); if (nv != null) { p.pos = nv.Position; p.stitch = true; p.stitchline = true; return(p); } // Try the nearest linedef Linedef nl = General.Map.Map.NearestLinedefRange(mousemappos, BuilderPlug.Me.StitchRange / renderer.Scale); if (nl != null) { // Snap to grid? if (snaptogrid) { // Get grid intersection coordinates List <Vector2D> coords = nl.GetGridIntersections(); // Find nearest grid intersection bool found = false; double found_distance = float.MaxValue; Vector2D found_coord = new Vector2D(); foreach (Vector2D v in coords) { Vector2D delta = mousemappos - v; if (delta.GetLengthSq() < found_distance) { found_distance = delta.GetLengthSq(); found_coord = v; found = true; } } if (found) { // Align to the closest grid intersection p.pos = found_coord; p.stitch = true; p.stitchline = true; return(p); } } else { // Aligned to line p.pos = nl.NearestOnLine(mousemappos); p.stitch = true; p.stitchline = true; return(p); } } } else { // Always snap to the first drawn vertex so that the user can finish a complete sector without stitching if (points.Count > 0) { if (Vector2D.DistanceSq(mousemappos, points[0].pos) < (vrange * vrange)) { p.pos = points[0].pos; p.stitch = true; p.stitchline = false; return(p); } } } // if the mouse cursor is outside the map bondaries check if the line between the last set point and the // mouse cursor intersect any of the boundary lines. If it does, set the position to this intersection if (points.Count > 0 && (mousemappos.x < General.Map.Config.LeftBoundary || mousemappos.x > General.Map.Config.RightBoundary || mousemappos.y > General.Map.Config.TopBoundary || mousemappos.y < General.Map.Config.BottomBoundary)) { Line2D dline = new Line2D(mousemappos, points[points.Count - 1].pos); bool foundintersection = false; double u = 0.0f; List <Line2D> blines = new List <Line2D>(); // lines for left, top, right and bottom bondaries blines.Add(new Line2D(General.Map.Config.LeftBoundary, General.Map.Config.BottomBoundary, General.Map.Config.LeftBoundary, General.Map.Config.TopBoundary)); blines.Add(new Line2D(General.Map.Config.LeftBoundary, General.Map.Config.TopBoundary, General.Map.Config.RightBoundary, General.Map.Config.TopBoundary)); blines.Add(new Line2D(General.Map.Config.RightBoundary, General.Map.Config.TopBoundary, General.Map.Config.RightBoundary, General.Map.Config.BottomBoundary)); blines.Add(new Line2D(General.Map.Config.RightBoundary, General.Map.Config.BottomBoundary, General.Map.Config.LeftBoundary, General.Map.Config.BottomBoundary)); // check for intersections with boundaries for (int i = 0; i < blines.Count; i++) { if (!foundintersection) { // only check for intersection if the last set point is not on the // line we are checking against if (blines[i].GetSideOfLine(points[points.Count - 1].pos) != 0.0f) { foundintersection = blines[i].GetIntersection(dline, out u); } } } // if there was no intersection set the position to the last set point if (!foundintersection) { vm = points[points.Count - 1].pos; } else { vm = dline.GetCoordinatesAt(u); } } // Snap to grid? if (snaptogrid) { // Aligned to grid p.pos = General.Map.Grid.SnappedToGrid(vm); // special handling if (p.pos.x > General.Map.Config.RightBoundary) { p.pos.x = General.Map.Config.RightBoundary; } if (p.pos.y < General.Map.Config.BottomBoundary) { p.pos.y = General.Map.Config.BottomBoundary; } p.stitch = snaptonearest; p.stitchline = snaptonearest; return(p); } else { // Normal position p.pos = vm; p.stitch = snaptonearest; p.stitchline = snaptonearest; return(p); } }
public virtual void OnEarlyRender(IRenderer2D renderer2D) { }
// Rendering public override void PlotSelection(IRenderer2D renderer) { renderer.PlotSector(sector, General.Colors.Selection); }
// Rendering public override void PlotSelection(IRenderer2D renderer) { renderer.PlotLinedef(line, General.Colors.Selection); renderer.PlotVertex(line.Start, ColorCollection.VERTICES); renderer.PlotVertex(line.End, ColorCollection.VERTICES); }
// This is called for rendering public virtual void RenderThingsSelection(IRenderer2D renderer) { }
// This is called for rendering public virtual void RenderOverlaySelection(IRenderer2D renderer, FindReplaceObject[] selection) { }
// This renders the associated things with the indication color public static void RenderReverseAssociations(IRenderer2D renderer, Association asso, List <Line3D> eventlines) { // Tag must be above zero if (General.GetByIndex(asso.Tags, 0) < 1) { return; } // Things foreach (Thing t in General.Map.Map.Things) { // Get the thing type info ThingTypeInfo ti = General.Map.Data.GetThingInfoEx(t.Type); // Known action on this thing? if ((t.Action > 0) && General.Map.Config.LinedefActions.ContainsKey(t.Action)) { //Do not draw the association if this is a child link. // This prevents a reverse link to a thing via an argument, when it should be a direct tag-to-tag link instead. if (ti != null && asso.DirectLinkType < 0 && asso.DirectLinkType != -t.Type) { continue; } LinedefActionInfo action = General.Map.Config.LinedefActions[t.Action]; if (((action.Args[0].Type == (int)asso.Type) && (asso.Tags.Contains(t.Args[0]))) || ((action.Args[1].Type == (int)asso.Type) && (asso.Tags.Contains(t.Args[1]))) || ((action.Args[2].Type == (int)asso.Type) && (asso.Tags.Contains(t.Args[2]))) || ((action.Args[3].Type == (int)asso.Type) && (asso.Tags.Contains(t.Args[3]))) || ((action.Args[4].Type == (int)asso.Type) && (asso.Tags.Contains(t.Args[4])))) { renderer.RenderThing(t, General.Colors.Indication, General.Settings.ActiveThingsAlpha); if (General.Settings.GZShowEventLines) { eventlines.Add(new Line3D(t.Position, asso.Center)); //mxd } } //If there is a link setup on this thing, and it matches the association, then draw a direct link to any matching tag if (ti != null && asso.DirectLinkType == t.Type && asso.Tags.Contains(t.Tag)) { renderer.RenderThing(t, General.Colors.Indication, General.Settings.ActiveThingsAlpha); if (General.Settings.GZShowEventLines) { eventlines.Add(new Line3D(t.Position, asso.Center)); } } } //mxd. Thing action on this thing? else if (t.Action == 0) { //Draw the association, unless it is a child link. // This prevents a reverse link to a thing via an argument, when it should be a direct tag-to-tag link instead. if (ti != null && asso.DirectLinkType >= 0 && Math.Abs(asso.DirectLinkType) != t.Type) { if (((ti.Args[0].Type == (int)asso.Type) && (asso.Tags.Contains(t.Args[0]))) || ((ti.Args[1].Type == (int)asso.Type) && (asso.Tags.Contains(t.Args[1]))) || ((ti.Args[2].Type == (int)asso.Type) && (asso.Tags.Contains(t.Args[2]))) || ((ti.Args[3].Type == (int)asso.Type) && (asso.Tags.Contains(t.Args[3]))) || ((ti.Args[4].Type == (int)asso.Type) && (asso.Tags.Contains(t.Args[4])))) { renderer.RenderThing(t, General.Colors.Indication, General.Settings.ActiveThingsAlpha); if (General.Settings.GZShowEventLines) { eventlines.Add(new Line3D(t.Position, asso.Center)); } } } } } }
// This is called for rendering public virtual void PlotSelection(IRenderer2D renderer) { }
public void removeRenderer(IRenderer2D renderer2d) { _view.removeRenderer2d(renderer2d); }
public void addRenderer(IRenderer2D renderer2d) { _view.addRenderer2d(renderer2d); }
public virtual void OnLateRender(IRenderer2D renderer2D) { }
public void Render(Vector2 position, IRenderer2D renderer) { renderer.Submit(position, this); }
// This is called for rendering public virtual void RenderOverlaySelection(IRenderer2D renderer) { }
// This is called for rendering public virtual void RenderThingsSelection(IRenderer2D renderer, FindReplaceObject[] selection) { }
public RendererBitmapSource(IRenderer2D <RenderSourceType, ElementValueType> inner_renderer, IFunction <ElementValueType, System.Drawing.Color> converter) { this.inner_renderer = inner_renderer; this.converter = converter; }
// from CodeImp's DrawGeometryMode public static Vector2D GetCurrentPosition(Vector2D mousemappos, bool snaptonearest, bool snaptogrid, IRenderer2D renderer) { Vector2D output = new Vector2D(); Vector2D vm = mousemappos; float vrange = BuilderPlug.Me.StitchRange / renderer.Scale; // Snap to nearest? if (snaptonearest) { // Try the nearest vertex Vertex nv = General.Map.Map.NearestVertexSquareRange(mousemappos, vrange); if (nv != null) { output = nv.Position; return(output); } // Try the nearest linedef Linedef nl = General.Map.Map.NearestLinedefRange(mousemappos, BuilderPlug.Me.StitchRange / renderer.Scale); if (nl != null) { // Snap to grid? if (snaptogrid) { // Get grid intersection coordinates List <Vector2D> coords = nl.GetGridIntersections(); // Find nearest grid intersection bool found = false; float found_distance = float.MaxValue; Vector2D found_coord = new Vector2D(); foreach (Vector2D v in coords) { Vector2D delta = mousemappos - v; if (delta.GetLengthSq() < found_distance) { found_distance = delta.GetLengthSq(); found_coord = v; found = true; } } if (found) { // Align to the closest grid intersection output = found_coord; return(output); } } else { // Aligned to line output = nl.NearestOnLine(mousemappos); return(output); } } } // Snap to grid? if (snaptogrid) { // Aligned to grid output = General.Map.Grid.SnappedToGrid(vm); // special handling if (output.x > General.Map.Config.RightBoundary) { output.x = General.Map.Config.RightBoundary; } if (output.y < General.Map.Config.BottomBoundary) { output.y = General.Map.Config.BottomBoundary; } return(output); } else { // Normal position output = vm; return(output); } }
// Rendering public override void PlotSelection(IRenderer2D renderer) { renderer.PlotVertex(vertex1, ColorCollection.SELECTION); }
// This returns the aligned and snapped draw position public static DrawnVertex GetCurrentPosition(Vector2D mousemappos, bool snaptonearest, bool snaptogrid, bool snaptocardinal, bool usefourcardinaldirections, IRenderer2D renderer, List <DrawnVertex> points) { DrawnVertex p = new DrawnVertex(); p.stitch = true; //mxd. Setting these to false seems to be a good way to create invalid geometry... p.stitchline = true; //mxd snaptocardinal = (snaptocardinal && points.Count > 0); //mxd. Don't snap to cardinal when there are no points //mxd. If snap to cardinal directions is enabled and we have points, modify mouse position Vector2D vm, gridoffset; if (snaptocardinal) { Vector2D offset = mousemappos - points[points.Count - 1].pos; float angle; if (usefourcardinaldirections) { angle = Angle2D.DegToRad((General.ClampAngle((int)Angle2D.RadToDeg(offset.GetAngle()))) / 90 * 90 + 45); } else { angle = Angle2D.DegToRad((General.ClampAngle((int)Angle2D.RadToDeg(offset.GetAngle()) + 22)) / 45 * 45); } offset = new Vector2D(0, -offset.GetLength()).GetRotated(angle); vm = points[points.Count - 1].pos + offset; //mxd. We need to be snapped relative to initial position Vector2D prev = points[points.Count - 1].pos; gridoffset = prev - General.Map.Grid.SnappedToGrid(prev); } else { vm = mousemappos; gridoffset = new Vector2D(); } float vrange = BuilderPlug.Me.StitchRange / renderer.Scale; // Snap to nearest? if (snaptonearest) { // Go for all drawn points foreach (DrawnVertex v in points) { if (Vector2D.DistanceSq(vm, v.pos) < (vrange * vrange)) { p.pos = v.pos; return(p); } } // Try the nearest vertex Vertex nv = General.Map.Map.NearestVertexSquareRange(vm, vrange); if (nv != null) { //mxd. Line angle must stay the same if (snaptocardinal) { Line2D ourline = new Line2D(points[points.Count - 1].pos, vm); if (Math.Round(ourline.GetSideOfLine(nv.Position), 1) == 0) { p.pos = nv.Position; return(p); } } else { p.pos = nv.Position; return(p); } } // Try the nearest linedef. mxd. We'll need much bigger stitch distance when snapping to cardinal directions Linedef nl = General.Map.Map.NearestLinedefRange(vm, BuilderPlug.Me.StitchRange / renderer.Scale); if (nl != null) { //mxd. Line angle must stay the same if (snaptocardinal) { Line2D ourline = new Line2D(points[points.Count - 1].pos, vm); Line2D nearestline = new Line2D(nl.Start.Position, nl.End.Position); Vector2D intersection = Line2D.GetIntersectionPoint(nearestline, ourline, false); if (!float.IsNaN(intersection.x)) { // Intersection is on nearestline? float u = Line2D.GetNearestOnLine(nearestline.v1, nearestline.v2, intersection); if (u < 0f || u > 1f) { } else { p.pos = new Vector2D((float)Math.Round(intersection.x, General.Map.FormatInterface.VertexDecimals), (float)Math.Round(intersection.y, General.Map.FormatInterface.VertexDecimals)); return(p); } } } // Snap to grid? else if (snaptogrid) { // Get grid intersection coordinates List <Vector2D> coords = nl.GetGridIntersections(); // Find nearest grid intersection bool found = false; float found_distance = float.MaxValue; Vector2D found_coord = new Vector2D(); foreach (Vector2D v in coords) { Vector2D delta = vm - v; if (delta.GetLengthSq() < found_distance) { found_distance = delta.GetLengthSq(); found_coord = v; found = true; } } if (found) { // Align to the closest grid intersection p.pos = found_coord; return(p); } } else { // Aligned to line p.pos = nl.NearestOnLine(vm); return(p); } } } else { // Always snap to the first drawn vertex so that the user can finish a complete sector without stitching if (points.Count > 0) { if (Vector2D.DistanceSq(vm, points[0].pos) < (vrange * vrange)) { p.pos = points[0].pos; return(p); } } } // if the mouse cursor is outside the map bondaries check if the line between the last set point and the // mouse cursor intersect any of the boundary lines. If it does, set the position to this intersection if (points.Count > 0 && (mousemappos.x < General.Map.Config.LeftBoundary || mousemappos.x > General.Map.Config.RightBoundary || mousemappos.y > General.Map.Config.TopBoundary || mousemappos.y < General.Map.Config.BottomBoundary)) { Line2D dline = new Line2D(mousemappos, points[points.Count - 1].pos); bool foundintersection = false; float u = 0.0f; List <Line2D> blines = new List <Line2D>(); // lines for left, top, right and bottom boundaries blines.Add(new Line2D(General.Map.Config.LeftBoundary, General.Map.Config.BottomBoundary, General.Map.Config.LeftBoundary, General.Map.Config.TopBoundary)); blines.Add(new Line2D(General.Map.Config.LeftBoundary, General.Map.Config.TopBoundary, General.Map.Config.RightBoundary, General.Map.Config.TopBoundary)); blines.Add(new Line2D(General.Map.Config.RightBoundary, General.Map.Config.TopBoundary, General.Map.Config.RightBoundary, General.Map.Config.BottomBoundary)); blines.Add(new Line2D(General.Map.Config.RightBoundary, General.Map.Config.BottomBoundary, General.Map.Config.LeftBoundary, General.Map.Config.BottomBoundary)); // check for intersections with boundaries for (int i = 0; i < blines.Count; i++) { if (!foundintersection) { // only check for intersection if the last set point is not on the // line we are checking against if (blines[i].GetSideOfLine(points[points.Count - 1].pos) != 0.0f) { foundintersection = blines[i].GetIntersection(dline, out u); } } } // if there was no intersection set the position to the last set point if (!foundintersection) { vm = points[points.Count - 1].pos; } else { vm = dline.GetCoordinatesAt(u); } } // Snap to grid? if (snaptogrid) { // Aligned to grid p.pos = General.Map.Grid.SnappedToGrid(vm - gridoffset) + gridoffset; // special handling if (p.pos.x > General.Map.Config.RightBoundary) { p.pos.x = General.Map.Config.RightBoundary; } if (p.pos.y < General.Map.Config.BottomBoundary) { p.pos.y = General.Map.Config.BottomBoundary; } return(p); } else { // Normal position p.pos.x = (float)Math.Round(vm.x); //mxd p.pos.y = (float)Math.Round(vm.y); //mxd return(p); } }
// Rendering public override void RenderOverlaySelection(IRenderer2D renderer) { renderer.RenderRectangleFilled(new RectangleF((float)(vertex.Position.x - 3), (float)(vertex.Position.y - 3), 6f, 6f), General.Colors.Selection, true); }
// Rendering public override void RenderOverlaySelection(IRenderer2D renderer) { renderer.RenderThing(thing, General.Colors.Selection, General.Settings.ActiveThingsAlpha); }
// Rendering public override void RenderOverlaySelection(IRenderer2D renderer) { renderer.RenderThing(thing, renderer.DetermineThingColor(thing), 1.0f); }
public void Render(Vector2 position, IRenderer2D renderer) { Info.Reference.Render(position + Info.RenderOffset, renderer); }
public Layer(Application program) { m_App = program; m_Renderer2D = new BatchRenderer2D(); m_RenderableEntities = m_EntityContext.GetGroup(GameMatcher.AllOf(GameMatcher.Position, GameMatcher.Renderable)); }