// This updates the overlay
        private void UpdateOverlay()
        {
            // We must redraw the tiles to the canvas when the stats to view has changed
            if (lastviewstats != BuilderPlug.InterfaceForm.ViewStats)
            {
                RedrawAllTiles();
                lastviewstats = BuilderPlug.InterfaceForm.ViewStats;
            }

            // Render the overlay
            if (renderer.StartOverlay(true))
            {
                // Render the canvas to screen
                RectangleF r = new RectangleF(0, 0, canvas.Width, canvas.Height);
                renderer.RenderRectangleFilled(r, PixelColor.FromColor(Color.White), false, image);

                // Render any selection
                if (selecting)
                {
                    RenderMultiSelection();
                }

                // Finish our rendering to this layer.
                renderer.Finish();
            }
        }
Example #2
0
        // MANDATORY: You must override this event and handle it to draw the map
        // In this example, we're not going to draw the map at all, but the example image instead.
        public override void OnRedrawDisplay()
        {
            base.OnRedrawDisplay();

            // We don't have to clear the other layers or anything, because they are not used
            // anyway (see how the presentation above is configured to show only the Overlay layer)

            // Clear the overlay and begin rendering to it.
            if (renderer.StartOverlay(true))
            {
                // Rectangle of coordinates where to draw the image.
                // We use untranslated coordinates: this means the coordinates here
                // are already in screen space.
                RectangleF r = new RectangleF(20.0f, 20.0f, 428.0f, 332.0f);

                // Show the picture!
                renderer.RenderRectangleFilled(r, PixelColor.FromColor(Color.White), false, exampleimage);

                // Finish our rendering to this layer.
                renderer.Finish();
            }

            // We now present it to the user on the display,
            // with the previously defined presentation settings.
            renderer.Present();
        }
        // This shows a polygon
        private void ShowPolygon(LinkedList <EarClipVertex> p)
        {
            LinkedListNode <EarClipVertex> v  = p.First;
            LinkedListNode <EarClipVertex> v2 = p.Last;

            // Go for all vertices in the polygon
            while (v != null)
            {
                for (int a = 0; a < 1; a++)
                {
                    // Start with a clear display
                    if (renderer.StartPlotter(true))
                    {
                        // Render lines and vertices
                        renderer.PlotLinedefSet(General.Map.Map.Linedefs);
                        renderer.PlotVerticesSet(General.Map.Map.Vertices);

                        // Show line
                        renderer.PlotLine(v.Value.Position, v2.Value.Position, PixelColor.FromColor(Color.White));

                        // Done
                        renderer.Finish();
                        renderer.Present();
                    }

                    //Thread.Sleep(10);

                    // Start with a clear display
                    if (renderer.StartPlotter(true))
                    {
                        // Render lines and vertices
                        renderer.PlotLinedefSet(General.Map.Map.Linedefs);
                        renderer.PlotVerticesSet(General.Map.Map.Vertices);

                        // Show line
                        renderer.PlotLine(v.Value.Position, v2.Value.Position, PixelColor.FromColor(Color.Red));

                        // Done
                        renderer.Finish();
                        renderer.Present();
                    }

                    // Wait a bit
                    //Thread.Sleep(40);
                    Application.DoEvents();
                }

                v2 = v;
                v  = v.Next;
            }
        }
Example #4
0
 // Constructor
 public NodesViewerMode()
 {
     // Make a list of distict colors we can use to
     // display multiple things on the screen
     // Note that black and white are not in this list, because
     // these are the most likely colors for the user's background
     distinctcolors = new List <PixelColor>();
     distinctcolors.Add(PixelColor.FromColor(Color.Blue));
     distinctcolors.Add(PixelColor.FromColor(Color.Orange));
     distinctcolors.Add(PixelColor.FromColor(Color.ForestGreen));
     distinctcolors.Add(PixelColor.FromColor(Color.Sienna));
     distinctcolors.Add(PixelColor.FromColor(Color.LightPink));
     distinctcolors.Add(PixelColor.FromColor(Color.Purple));
     distinctcolors.Add(PixelColor.FromColor(Color.Cyan));
     distinctcolors.Add(PixelColor.FromColor(Color.LawnGreen));
     distinctcolors.Add(PixelColor.FromColor(Color.PaleGoldenrod));
     distinctcolors.Add(PixelColor.FromColor(Color.Red));
     distinctcolors.Add(PixelColor.FromColor(Color.Yellow));
     distinctcolors.Add(PixelColor.FromColor(Color.LightSkyBlue));
     distinctcolors.Add(PixelColor.FromColor(Color.DarkGray));
     distinctcolors.Add(PixelColor.FromColor(Color.Magenta));
 }
Example #5
0
        /// <summary>
        /// Build the polygon for a specific subsector
        /// </summary>
        private void BuildSubsectorPoly(int ss, IEnumerable <Split> nodesplits)
        {
            // Begin with a giant square polygon that covers the entire map
            List <Vector2D> poly = new List <Vector2D>(16);

            poly.Add(new Vector2D(-General.Map.FormatInterface.MaxCoordinate, General.Map.FormatInterface.MaxCoordinate));
            poly.Add(new Vector2D(General.Map.FormatInterface.MaxCoordinate, General.Map.FormatInterface.MaxCoordinate));
            poly.Add(new Vector2D(General.Map.FormatInterface.MaxCoordinate, -General.Map.FormatInterface.MaxCoordinate));
            poly.Add(new Vector2D(-General.Map.FormatInterface.MaxCoordinate, -General.Map.FormatInterface.MaxCoordinate));

            // Crop the polygon by the node tree splits
            foreach (Split s in nodesplits)
            {
                CropPolygon(poly, s);
            }

            // Crop the polygon by the subsector segs
            for (int i = 0; i < ssectors[ss].numsegs; i++)
            {
                Split s;
                Seg   sg = segs[ssectors[ss].firstseg + i];

                //mxd. Sanity check, because some segs in Doom maps refer to non-existing verts.
                if (sg.startvertex > verts.Length - 1 || sg.endvertex > verts.Length - 1)
                {
                    continue;
                }

                s.pos   = verts[sg.startvertex];
                s.delta = verts[sg.endvertex] - verts[sg.startvertex];
                CropPolygon(poly, s);
            }

            if (poly.Count > 1)
            {
                // Remove any zero-length lines
                Vector2D prevpoint = poly[0];
                for (int i = poly.Count - 1; i >= 0; i--)
                {
                    if (Vector2D.DistanceSq(poly[i], prevpoint) < 0.001f)
                    {
                        poly.RemoveAt(i);
                    }
                    else
                    {
                        prevpoint = poly[i];
                    }
                }
            }

            ssectors[ss].points = poly.ToArray();

            // Setup vertices for rendering
            if (poly.Count >= 3)
            {
                FlatVertex[] fverts   = new FlatVertex[(poly.Count - 2) * 3];
                int          intcolor = PixelColor.FromColor(Color.Gray).WithAlpha(100).ToInt();
                int          pi       = 0;
                for (int t = 0; t < (poly.Count - 2); t++)
                {
                    fverts[pi].x     = poly[0].x;
                    fverts[pi].y     = poly[0].y;
                    fverts[pi].c     = intcolor;
                    fverts[pi + 1].x = poly[t + 1].x;
                    fverts[pi + 1].y = poly[t + 1].y;
                    fverts[pi + 1].c = intcolor;
                    fverts[pi + 2].x = poly[t + 2].x;
                    fverts[pi + 2].y = poly[t + 2].y;
                    fverts[pi + 2].c = intcolor;
                    pi += 3;
                }
                ssectors[ss].vertices = fverts;
            }
        }
Example #6
0
        // Draw the display
        public override void OnRedrawDisplay()
        {
            base.OnRedrawDisplay();

            if (form == null)
            {
                return;
            }

            if (renderer.StartPlotter(true))
            {
                if (form.SelectedTab == 0)
                {
                    // Render all subsectors in original color
                    for (int si = 0; si < ssectors.Length; si++)
                    {
                        Subsector s = ssectors[si];
                        PlotSubsectorLines(s.points, PixelColor.FromColor(Color.Gray));
                    }

                    if (mouseinssector > -1)
                    {
                        PlotSubsectorLines(ssectors[mouseinssector].points, General.Colors.Highlight);
                    }

                    // Draw additional vertices
                    if (form.ShowSegsVertices)
                    {
                        for (int i = General.Map.Map.Vertices.Count; i < verts.Length; i++)
                        {
                            renderer.PlotVertexAt(verts[i], ColorCollection.VERTICES);
                        }
                    }
                }

                if (form.SelectedTab == 1)
                {
                    renderer.PlotLinedefSet(General.Map.Map.Linedefs);

                    // Render selected node split
                    if ((form.ViewSplitIndex >= 0) && (form.ViewSplitIndex < nodes.Length))
                    {
                        Node n = nodes[form.ViewSplitIndex];

                        // Draw parent splits
                        int parentsplit = n.parent;
                        while (parentsplit > -1)
                        {
                            Node pn = nodes[parentsplit];
                            renderer.PlotLine(pn.linestart, pn.linestart + pn.linedelta, General.Colors.Selection);
                            parentsplit = pn.parent;
                        }

                        // Draw this split
                        renderer.PlotLine(n.linestart, n.linestart + n.linedelta, General.Colors.Highlight);
                    }
                }

                if (form.SelectedTab == 2)
                {
                    renderer.PlotLinedefSet(General.Map.Map.Linedefs);

                    // Render selected subsector
                    if ((form.ViewSubsectorIndex >= 0) && (form.ViewSubsectorIndex < ssectors.Length))
                    {
                        Subsector s = ssectors[form.ViewSubsectorIndex];
                        PlotSubsectorLines(s.points, General.Colors.Highlight);
                    }

                    // Draw selected segment
                    if (form.ViewSegIndex > -1)
                    {
                        Seg sg = segs[form.ViewSegIndex];
                        renderer.PlotLine(verts[sg.startvertex], verts[sg.endvertex], General.Colors.Selection);
                    }
                }

                renderer.Finish();
            }

            if (renderer.StartOverlay(true))
            {
                switch (form.SelectedTab)
                {
                case 0:
                    if (mouseinssector > -1)
                    {
                        // Render all subsectors in original color
                        for (int si = 0; si < ssectors.Length; si++)
                        {
                            Subsector s = ssectors[si];
                            DrawSubsectorArea(s.vertices);
                        }
                        DrawSubsectorArea(ssectors[mouseinssector].vertices, General.Colors.Highlight);
                    }
                    else
                    {
                        // Render all subsectors with distinct colors
                        for (int si = 0; si < ssectors.Length; si++)
                        {
                            Subsector  s     = ssectors[si];
                            PixelColor color = distinctcolors[si % distinctcolors.Count];
                            DrawSubsectorArea(s.vertices, color);
                        }
                    }
                    break;

                case 1:
                    if ((form.ViewSplitIndex >= 0) && (form.ViewSplitIndex < nodes.Length))
                    {
                        Node n = nodes[form.ViewSplitIndex];

                        // Draw areas. We draw these first, because they would otherwise erase any splits we want to show.
                        DrawSplitArea(n.leftbox, form.ViewSplitIndex, true, new PixelColor(100, 50, 80, 255));
                        DrawSplitArea(n.rightbox, form.ViewSplitIndex, false, new PixelColor(100, 20, 220, 20));

                        // Draw parent splits
                        int parentsplit = n.parent;
                        while (parentsplit > -1)
                        {
                            Node pn = nodes[parentsplit];
                            renderer.RenderLine(pn.linestart, pn.linestart + pn.linedelta, 1f, General.Colors.Selection, true);
                            parentsplit = pn.parent;
                        }

                        // Draw this split
                        renderer.RenderLine(n.linestart, n.linestart + n.linedelta, 1f, General.Colors.Highlight, true);
                    }
                    break;

                case 2:
                    if ((form.ViewSubsectorIndex >= 0) && (form.ViewSubsectorIndex < ssectors.Length))
                    {
                        Subsector s = ssectors[form.ViewSubsectorIndex];

                        // Draw area
                        DrawSubsectorArea(s.vertices, General.Colors.Highlight);

                        // Draw selected segment
                        if (form.ViewSegIndex > -1)
                        {
                            Seg sg = segs[form.ViewSegIndex];
                            renderer.RenderLine(verts[sg.startvertex], verts[sg.endvertex], 1f, General.Colors.Selection, true);
                        }
                    }
                    break;
                }

                renderer.Finish();
            }

            renderer.Present();
        }
Example #7
0
        // Constructor
        internal ConfigurationInfo(Configuration cfg, string filename)
        {
            // Initialize
            this.filename    = filename;
            this.config      = cfg;        //mxd
            this.settingskey = Path.GetFileNameWithoutExtension(filename).ToLower();

            // Load settings from game configuration
            this.name            = config.ReadSetting("game", "<unnamed game>");
            this.defaultlumpname = config.ReadSetting("defaultlumpname", "");

            // Load settings from program configuration
            this.nodebuildersave       = General.Settings.ReadSetting("configurations." + settingskey + ".nodebuildersave", MISSING_NODEBUILDER);
            this.nodebuildertest       = General.Settings.ReadSetting("configurations." + settingskey + ".nodebuildertest", MISSING_NODEBUILDER);
            this.formatinterface       = config.ReadSetting("formatinterface", "").ToLowerInvariant(); //mxd
            this.defaultscriptcompiler = cfg.ReadSetting("defaultscriptcompiler", "");                 //mxd
            this.resources             = new DataLocationList(General.Settings.Config, "configurations." + settingskey + ".resources");
            this.startmode             = General.Settings.ReadSetting("configurations." + settingskey + ".startmode", "VerticesMode");
            this.enabled = General.Settings.ReadSetting("configurations." + settingskey + ".enabled", config.ReadSetting("enabledbydefault", false));             //mxd

            //mxd. Read test engines
            testEngines = new List <EngineInfo>();
            IDictionary list = General.Settings.ReadSetting("configurations." + settingskey + ".engines", new ListDictionary());

            currentEngineIndex = Math.Max(0, General.Settings.ReadSetting("configurations." + settingskey + ".currentengineindex", 0));

            // No engine list found? Use old engine properties
            if (list.Count == 0)
            {
                EngineInfo info = new EngineInfo();
                info.TestProgram      = General.Settings.ReadSetting("configurations." + settingskey + ".testprogram", "");
                info.TestProgramName  = General.Settings.ReadSetting("configurations." + settingskey + ".testprogramname", EngineInfo.DEFAULT_ENGINE_NAME);
                info.TestParameters   = General.Settings.ReadSetting("configurations." + settingskey + ".testparameters", "");
                info.TestShortPaths   = General.Settings.ReadSetting("configurations." + settingskey + ".testshortpaths", false);
                info.CustomParameters = General.Settings.ReadSetting("configurations." + settingskey + ".customparameters", false);
                info.TestSkill        = General.Settings.ReadSetting("configurations." + settingskey + ".testskill", 3);
                testEngines.Add(info);
                currentEngineIndex = 0;
            }
            else
            {
                //read engines settings from config
                foreach (DictionaryEntry de in list)
                {
                    string     path = "configurations." + settingskey + ".engines." + de.Key;
                    EngineInfo info = new EngineInfo();
                    info.TestProgram      = General.Settings.ReadSetting(path + ".testprogram", "");
                    info.TestProgramName  = General.Settings.ReadSetting(path + ".testprogramname", EngineInfo.DEFAULT_ENGINE_NAME);
                    info.TestParameters   = General.Settings.ReadSetting(path + ".testparameters", "");
                    info.TestShortPaths   = General.Settings.ReadSetting(path + ".testshortpaths", false);
                    info.CustomParameters = General.Settings.ReadSetting(path + ".customparameters", false);
                    info.TestSkill        = General.Settings.ReadSetting(path + ".testskill", 3);
                    testEngines.Add(info);
                }

                if (currentEngineIndex >= testEngines.Count)
                {
                    currentEngineIndex = 0;
                }
            }

            //mxd. read custom linedef colors
            List <LinedefColorPreset> colorPresets = new List <LinedefColorPreset>();

            list = General.Settings.ReadSetting("configurations." + settingskey + ".linedefcolorpresets", new ListDictionary());

            //no presets? add "classic" ones then.
            if (list.Count == 0)
            {
                colorPresets.Add(new LinedefColorPreset("Any action", PixelColor.FromColor(System.Drawing.Color.PaleGreen), -1, 0, new List <string>(), new List <string>(), true));
            }
            else
            {
                //read custom linedef colors from config
                foreach (DictionaryEntry de in list)
                {
                    string        path          = "configurations." + settingskey + ".linedefcolorpresets." + de.Key;
                    string        presetname    = General.Settings.ReadSetting(path + ".name", "Unnamed");
                    bool          presetenabled = General.Settings.ReadSetting(path + ".enabled", true);
                    PixelColor    color         = PixelColor.FromInt(General.Settings.ReadSetting(path + ".color", -1));
                    int           action        = General.Settings.ReadSetting(path + ".action", 0);
                    int           activation    = General.Settings.ReadSetting(path + ".activation", 0);
                    List <string> flags         = new List <string>();
                    flags.AddRange(General.Settings.ReadSetting(path + ".flags", "").Split(LINEDEF_COLOR_PRESET_FLAGS_SEPARATOR, StringSplitOptions.RemoveEmptyEntries));
                    List <string> restrictedFlags = new List <string>();
                    restrictedFlags.AddRange(General.Settings.ReadSetting(path + ".restrictedflags", "").Split(LINEDEF_COLOR_PRESET_FLAGS_SEPARATOR, StringSplitOptions.RemoveEmptyEntries));
                    LinedefColorPreset preset = new LinedefColorPreset(presetname, color, action, activation, flags, restrictedFlags, presetenabled);
                    colorPresets.Add(preset);
                }
            }
            linedefColorPresets = colorPresets.ToArray();

            // Make list of things filters
            thingsfilters = new List <ThingsFilter>();
            IDictionary cfgfilters = General.Settings.ReadSetting("configurations." + settingskey + ".thingsfilters", new Hashtable());

            foreach (DictionaryEntry de in cfgfilters)
            {
                thingsfilters.Add(new ThingsFilter(General.Settings.Config, "configurations." + settingskey + ".thingsfilters." + de.Key));
            }

            // Make list of texture sets
            texturesets = new List <DefinedTextureSet>();
            IDictionary sets = General.Settings.ReadSetting("configurations." + settingskey + ".texturesets", new Hashtable());

            foreach (DictionaryEntry de in sets)
            {
                texturesets.Add(new DefinedTextureSet(General.Settings.Config, "configurations." + settingskey + ".texturesets." + de.Key));
            }

            // Make list of edit modes
            this.editmodes = new Dictionary <string, bool>(StringComparer.Ordinal);
            IDictionary modes = General.Settings.ReadSetting("configurations." + settingskey + ".editmodes", new Hashtable());

            foreach (DictionaryEntry de in modes)
            {
                if (de.Key.ToString().StartsWith(MODE_ENABLED_KEY))
                {
                    editmodes.Add(de.Value.ToString(), true);
                }
                else if (de.Key.ToString().StartsWith(MODE_DISABLED_KEY))
                {
                    editmodes.Add(de.Value.ToString(), false);
                }
            }
        }
Example #8
0
        private bool ParseGlowingFlats()
        {
            // Next sould be opening brace
            if (!NextTokenIs("{", false))
            {
                ReportError("Expected opening brace");
                return(false);
            }

            // Parse inner blocks
            while (SkipWhitespace(true))
            {
                string token = ReadToken().ToLowerInvariant();
                if (token == "}")
                {
                    break;                              // End of Glow structure
                }
                switch (token)
                {
                case "walls":
                case "flats":
                    if (!NextTokenIs("{", false))
                    {
                        ReportError("Expected opening brace");
                        return(false);
                    }

                    while (SkipWhitespace(true))
                    {
                        token = ReadToken();
                        if (token == "}")
                        {
                            break;
                        }

                        // Add glow data
                        long flatnamehash = General.Map.Data.GetFullLongFlatName(Lump.MakeLongName(token, General.Map.Options.UseLongTextureNames));
                        glowingflats[flatnamehash] = new GlowingFlatData
                        {
                            Height                = DEFAULT_GLOW_HEIGHT * 2,
                            Fullbright            = true,
                            Color                 = new PixelColor(255, 255, 255, 255),
                            CalculateTextureColor = true
                        };
                    }
                    break;

                case "subwalls":
                case "subflats":
                    if (!NextTokenIs("{", false))
                    {
                        ReportError("Expected opening brace");
                        return(false);
                    }

                    while (SkipWhitespace(true))
                    {
                        token = ReadToken();
                        if (token == "}")
                        {
                            break;
                        }

                        // Add glow data
                        long flatnamehash = General.Map.Data.GetFullLongFlatName(Lump.MakeLongName(token, General.Map.Options.UseLongTextureNames));
                        glowingflats[flatnamehash] = new GlowingFlatData
                        {
                            Height                = DEFAULT_GLOW_HEIGHT * 2,
                            Fullblack             = true,
                            Subtractive           = true,
                            Color                 = new PixelColor(255, 0, 0, 0),
                            CalculateTextureColor = false
                        };
                    }
                    break;

                case "subtexture":
                case "texture":
                {
                    int    color;
                    int    glowheight         = DEFAULT_GLOW_HEIGHT;
                    bool   subtractivetexture = (token == "subtexture");
                    string texturename        = StripQuotes(ReadToken(false));

                    if (string.IsNullOrEmpty(texturename))
                    {
                        ReportError("expected " + token + " name");
                        return(false);
                    }

                    // Now we should find a comma
                    if (!NextTokenIs(",", false))
                    {
                        ReportError("Expected a comma");
                        return(false);
                    }

                    // Next is color
                    SkipWhitespace(true);
                    token = ReadToken();

                    if (!int.TryParse(token, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out color))
                    {
                        //probably it's a color name?
                        Color c = Color.FromName(token);                                 //should be similar to C++ color name detection, I suppose
                        if (c.IsKnownColor)
                        {
                            color = PixelColor.FromColor(c).ToInt();
                        }
                        else
                        {
                            ReportError("expected glow color value, but got \"" + token + "\"");
                            return(false);
                        }
                    }

                    // The glow data is valid at thispoint. Let's get texture hash
                    long texturehash = General.Map.Data.GetFullLongFlatName(Lump.MakeLongName(texturename, General.Map.Options.UseLongTextureNames));

                    // Now we can find a comma
                    if (!NextTokenIs(",", false))
                    {
                        // Add glow data
                        glowingflats[texturehash] = new GlowingFlatData
                        {
                            Height                = glowheight * 2,
                            Subtractive           = subtractivetexture,
                            Color                 = PixelColor.FromInt(color).WithAlpha(255),
                            CalculateTextureColor = false
                        };
                        continue;
                    }

                    // Can be glow height
                    SkipWhitespace(true);
                    token = ReadToken();

                    int h;
                    if (int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out h))
                    {
                        // Can't pass glowheight directly cause TryParse will unconditionally set it to 0
                        glowheight = h;

                        // Now we can find a comma
                        if (!NextTokenIs(",", false))
                        {
                            // Add glow data
                            glowingflats[texturehash] = new GlowingFlatData
                            {
                                Height                = glowheight * 2,
                                Subtractive           = subtractivetexture,
                                Color                 = PixelColor.FromInt(color).WithAlpha(255),
                                CalculateTextureColor = false
                            };
                            continue;
                        }

                        // Read the flag
                        SkipWhitespace(true);
                        token = ReadToken().ToLowerInvariant();
                    }

                    // Next is "fullbright" or "fullblack" flag
                    bool fullbright = (token == "fullbright");
                    bool fullblack  = (!subtractivetexture && token == "fullblack");

                    if (!fullblack && !fullbright)
                    {
                        string expectedflags = (subtractivetexture ? "\"fullbright\"" : "\"fullbright\" or \"fullblack\"");
                        ReportError("expected " + expectedflags + " flag, but got \"" + token + "\"");
                        return(false);
                    }

                    // Add glow data
                    glowingflats[texturehash] = new GlowingFlatData
                    {
                        Height                = glowheight * 2,
                        Fullbright            = fullbright,
                        Fullblack             = fullblack,
                        Subtractive           = subtractivetexture,
                        Color                 = PixelColor.FromInt(color).WithAlpha(255),
                        CalculateTextureColor = false
                    };
                }
                break;
                }
            }

            // All done here
            return(true);
        }
        // This shows a polygon
        private void ShowEarClip(EarClipVertex[] found, LinkedList <EarClipVertex> remains)
        {
            EarClipVertex prev, first;

            for (int a = 0; a < 2; a++)
            {
                // Start with a clear display
                if (renderer.StartPlotter(true))
                {
                    // Render lines and vertices
                    renderer.PlotLinedefSet(General.Map.Map.Linedefs);
                    renderer.PlotVerticesSet(General.Map.Map.Vertices);

                    // Go for all remaining vertices
                    prev = null; first = null;
                    foreach (EarClipVertex v in remains)
                    {
                        // Show the line
                        if (prev != null)
                        {
                            renderer.PlotLine(v.Position, prev.Position, PixelColor.FromColor(Color.Yellow));
                        }
                        if (prev == null)
                        {
                            first = v;
                        }
                        prev = v;

                        if (v.IsReflex)
                        {
                            renderer.PlotVertexAt(v.Position, ColorCollection.SELECTION);
                        }
                        else
                        {
                            renderer.PlotVertexAt(v.Position, ColorCollection.VERTICES);
                        }
                    }
                    if (first != null)
                    {
                        renderer.PlotLine(first.Position, prev.Position, PixelColor.FromColor(Color.Yellow));
                    }

                    if (found != null)
                    {
                        renderer.PlotLine(found[0].Position, found[1].Position, PixelColor.FromColor(Color.BlueViolet));
                        renderer.PlotLine(found[1].Position, found[2].Position, PixelColor.FromColor(Color.BlueViolet));
                        renderer.PlotLine(found[2].Position, found[0].Position, PixelColor.FromColor(Color.BlueViolet));
                        renderer.PlotVertexAt(found[1].Position, ColorCollection.INDICATION);
                    }

                    // Done
                    renderer.Finish();
                    renderer.Present();
                }
                Thread.Sleep(10);
                Application.DoEvents();

                // Start with a clear display
                if (renderer.StartPlotter(true))
                {
                    // Render lines and vertices
                    renderer.PlotLinedefSet(General.Map.Map.Linedefs);
                    renderer.PlotVerticesSet(General.Map.Map.Vertices);

                    // Go for all remaining vertices
                    prev = null; first = null;
                    foreach (EarClipVertex v in remains)
                    {
                        // Show the line
                        if (prev != null)
                        {
                            renderer.PlotLine(v.Position, prev.Position, PixelColor.FromColor(Color.Yellow));
                        }
                        if (prev == null)
                        {
                            first = v;
                        }
                        prev = v;

                        if (v.IsReflex)
                        {
                            renderer.PlotVertexAt(v.Position, ColorCollection.SELECTION);
                        }
                        else
                        {
                            renderer.PlotVertexAt(v.Position, ColorCollection.VERTICES);
                        }
                    }
                    if (first != null)
                    {
                        renderer.PlotLine(first.Position, prev.Position, PixelColor.FromColor(Color.Yellow));
                    }

                    // Done
                    renderer.Finish();
                    renderer.Present();
                }
                //Thread.Sleep(10);
            }
        }
        // This shows a polygon
        private void ShowRemaining(LinkedList <EarClipVertex> remains)
        {
            LinkedListNode <EarClipVertex> v;

            for (int a = 0; a < 100; a++)
            {
                OnRedrawDisplay();
                Thread.Sleep(10);
                Application.DoEvents();

                // Start with a clear display
                if (renderer.StartPlotter(true))
                {
                    // Render lines and vertices
                    renderer.PlotLinedefSet(General.Map.Map.Linedefs);
                    renderer.PlotVerticesSet(General.Map.Map.Vertices);

                    // Go for all vertices in the polygon
                    v = remains.First;
                    while (v != null)
                    {
                        // Show the line
                        if (v.Next != null)
                        {
                            renderer.PlotLine(v.Value.Position, v.Next.Value.Position, PixelColor.FromColor(Color.Yellow));
                        }
                        v = v.Next;
                    }

                    // Show last line as well
                    renderer.PlotLine(remains.Last.Value.Position, remains.First.Value.Position, PixelColor.FromColor(Color.Yellow));

                    // Done
                    renderer.Finish();
                    renderer.Present();
                }

                // Wait a bit
                Thread.Sleep(60);
            }
        }
        // Mouse released
        public override void OnMouseUp(MouseEventArgs e)
        {
            ICollection <Sector> selected;
            PixelColor           c;

            base.OnMouseUp(e);

            // Item highlighted?
            if ((highlighted != null) && !highlighted.IsDisposed)
            {
                Sector s = highlighted;

                // Remove highlight to avoid confusion
                Highlight(null);

                // Get a triangulator and bind events
                Triangulation t = new Triangulation();
                t.OnShowPolygon = ShowPolygon;
                t.OnShowEarClip = ShowEarClip;
                //t.OnShowRemaining = ShowRemaining;
                t.Triangulate(s);

                // Start with a clear display
                if (renderer.StartPlotter(true))
                {
                    // Render lines and vertices
                    renderer.PlotLinedefSet(General.Map.Map.Linedefs);
                    renderer.PlotVerticesSet(General.Map.Map.Vertices);

                    // Go for all triangle vertices to render the inside lines only
                    for (int i = 0; i < t.Vertices.Count; i += 3)
                    {
                        if (t.Sidedefs[i + 0] == null)
                        {
                            renderer.PlotLine(t.Vertices[i + 0], t.Vertices[i + 1], PixelColor.FromColor(Color.DeepSkyBlue));
                        }
                        if (t.Sidedefs[i + 1] == null)
                        {
                            renderer.PlotLine(t.Vertices[i + 1], t.Vertices[i + 2], PixelColor.FromColor(Color.DeepSkyBlue));
                        }
                        if (t.Sidedefs[i + 2] == null)
                        {
                            renderer.PlotLine(t.Vertices[i + 2], t.Vertices[i + 0], PixelColor.FromColor(Color.DeepSkyBlue));
                        }
                    }

                    // Go for all triangle vertices to renderthe outside lines only
                    for (int i = 0; i < t.Vertices.Count; i += 3)
                    {
                        if (t.Sidedefs[i + 0] != null)
                        {
                            renderer.PlotLine(t.Vertices[i + 0], t.Vertices[i + 1], PixelColor.FromColor(Color.Red));
                        }
                        if (t.Sidedefs[i + 1] != null)
                        {
                            renderer.PlotLine(t.Vertices[i + 1], t.Vertices[i + 2], PixelColor.FromColor(Color.Red));
                        }
                        if (t.Sidedefs[i + 2] != null)
                        {
                            renderer.PlotLine(t.Vertices[i + 2], t.Vertices[i + 0], PixelColor.FromColor(Color.Red));
                        }
                    }

                    // Done
                    renderer.Finish();
                    renderer.Present();
                    Thread.Sleep(200);
                }
            }
        }
Example #12
0
        // This updates the overlay
        private void UpdateOverlay()
        {
            MapSet map = General.Map.Map;

            if (renderer.StartOverlay(true))
            {
                if (selected != null)
                {
                    int manualhiddencolor  = PixelColor.FromColor(Color.Red).ToInt();
                    int manualvisiblecolor = PixelColor.FromColor(Color.DeepSkyBlue).ToInt();
                    int tablevisiblecolor  = PixelColor.FromColor(Color.Blue).ToInt();

                    Array.Clear(manualsectors, 0, manualsectors.Length);

                    List <RejectSet> targets;
                    if (BuilderPlug.Me.RejectChanges.TryGetValue(selected.FixedIndex, out targets))
                    {
                        // Draw all sectors that were set manually
                        foreach (RejectSet rs in targets)
                        {
                            Sector ts = BuilderPlug.Me.GetSectorByFixedIndex(rs.target);
                            switch (rs.state)
                            {
                            case RejectState.ForceHidden: RenderSectorFilled(ts, manualhiddencolor); break;

                            case RejectState.ForceVisible: RenderSectorFilled(ts, manualvisiblecolor); break;

                            default: throw new NotImplementedException();
                            }
                            manualsectors[rs.target] = true;
                        }
                    }

                    // For all remaining sectors in the table, render them as the nodebuilder decided
                    bool[] tabletargets = BuilderPlug.Me.UnmodifiedTable[selected.Index];
                    for (int i = 0; i < tabletargets.Length; i++)
                    {
                        if (manualsectors[i])
                        {
                            continue;
                        }
                        if (tabletargets[i])
                        {
                            continue;
                        }

                        RenderSectorFilled(map.GetSectorByIndex(i), tablevisiblecolor);
                    }
                }
                else
                {
                    int indicationcolor = General.Colors.Indication.ToInt();
                    foreach (KeyValuePair <int, List <RejectSet> > ss in BuilderPlug.Me.RejectChanges)
                    {
                        RenderSectorFilled(BuilderPlug.Me.GetSectorByFixedIndex(ss.Key), indicationcolor);
                    }
                }

                renderer.Finish();
            }
        }