Пример #1
0
        // Constructor
        internal TextFont()
        {
            Configuration cfg;
            Stream        fontdata;
            StreamReader  fontreader;

            string[] resnames;

            // Initialize
            characters = new FontCharacter[256];

            // Make chars configuration
            cfg = new Configuration();

            // Find a resource named Font.cfg
            resnames = General.ThisAssembly.GetManifestResourceNames();
            foreach (string rn in resnames)
            {
                // Found it?
                if (rn.EndsWith(FONT_RESOURCE, StringComparison.InvariantCultureIgnoreCase))
                {
                    // Get a stream from the resource
                    fontdata   = General.ThisAssembly.GetManifestResourceStream(rn);
                    fontreader = new StreamReader(fontdata, Encoding.ASCII);

                    // Load configuration from stream
                    cfg.InputConfiguration(fontreader.ReadToEnd());

                    // Done
                    fontreader.Dispose();
                    fontdata.Dispose();
                    break;
                }
            }

            // Get the charset from configuration
            IDictionary cfgchars = cfg.ReadSetting("chars", new Hashtable());

            // Go for all defined chars
            foreach (DictionaryEntry item in cfgchars)
            {
                // Get the character Hashtable
                IDictionary chr = (IDictionary)item.Value;
                int         i   = Convert.ToInt32(item.Key);

                // This is ancient code of mine.
                // The charater sizes were based on 800x600 resolution.
                characters[i].width  = (float)(int)chr["width"] / 40f;
                characters[i].height = (float)(int)chr["height"] / 30f;
                characters[i].u1     = (float)chr["u1"];
                characters[i].v1     = (float)chr["v1"];
                characters[i].u2     = (float)chr["u2"];
                characters[i].v2     = (float)chr["v2"];
            }

            // We have no destructor
            GC.SuppressFinalize(this);
        }
 // This saves colors to configuration
 internal void SaveColors(Configuration cfg)
 {
     // Write all colors to config
     for (int i = 0; i < NUM_COLORS; i++)
     {
         // Write color
         cfg.WriteSetting("colors.color" + i.ToString(CultureInfo.InvariantCulture), colors[i].ToInt());
     }
 }
        }                                                                                                                                         //mxd

        #endregion

        #region ================== Constructor / Disposer

        // Constructor for settings from configuration
        internal ColorCollection(Configuration cfg)
        {
            // Initialize
            colors       = new PixelColor[NUM_COLORS];
            brightcolors = new PixelColor[NUM_COLORS];
            darkcolors   = new PixelColor[NUM_COLORS];

            // Read all colors from config
            for (int i = 0; i < NUM_COLORS; i++)
            {
                // Read color
                colors[i] = PixelColor.FromInt(cfg.ReadSetting("colors.color" + i.ToString(CultureInfo.InvariantCulture), 0));
            }

            //mxd. Set new colors (previously these were defined in GZBuilder.default.cfg)
            if (colors[BACKGROUND].ToInt() == 0)
            {
                colors[BACKGROUND] = PixelColor.FromInt(-16777216);
            }
            if (colors[VERTICES].ToInt() == 0)
            {
                colors[VERTICES] = PixelColor.FromInt(-11425537);
            }
            if (colors[LINEDEFS].ToInt() == 0)
            {
                colors[LINEDEFS] = PixelColor.FromInt(-1);
            }
            if (colors[MODELWIRECOLOR].ToInt() == 0)
            {
                colors[MODELWIRECOLOR] = PixelColor.FromInt(-4259937);
            }
            if (colors[INFOLINECOLOR].ToInt() == 0)
            {
                colors[INFOLINECOLOR] = PixelColor.FromInt(-3750145);
            }
            if (colors[HIGHLIGHT].ToInt() == 0)
            {
                colors[HIGHLIGHT] = PixelColor.FromInt(-21504);
            }
            if (colors[SELECTION].ToInt() == 0)
            {
                colors[SELECTION] = PixelColor.FromInt(-49152);
            }
            if (colors[INDICATION].ToInt() == 0)
            {
                colors[INDICATION] = PixelColor.FromInt(-128);
            }
            if (colors[GRID].ToInt() == 0)
            {
                colors[GRID] = PixelColor.FromInt(-12171706);
            }
            if (colors[GRID64].ToInt() == 0)
            {
                colors[GRID64] = PixelColor.FromInt(-13018769);
            }
            if (colors[CROSSHAIR3D].ToInt() == 0)
            {
                colors[CROSSHAIR3D] = PixelColor.FromInt(-16711681);                                              // Unused!
            }
            if (colors[HIGHLIGHT3D].ToInt() == 0)
            {
                colors[HIGHLIGHT3D] = PixelColor.FromInt(-24576);
            }
            if (colors[SELECTION3D].ToInt() == 0)
            {
                colors[SELECTION3D] = PixelColor.FromInt(-49152);
            }
            if (colors[SCRIPTBACKGROUND].ToInt() == 0)
            {
                colors[SCRIPTBACKGROUND] = PixelColor.FromInt(-1);
            }
            if (colors[LINENUMBERS].ToInt() == 0)
            {
                colors[LINENUMBERS] = PixelColor.FromInt(-13921873);
            }
            if (colors[PLAINTEXT].ToInt() == 0)
            {
                colors[PLAINTEXT] = PixelColor.FromInt(-16777216);
            }
            if (colors[COMMENTS].ToInt() == 0)
            {
                colors[COMMENTS] = PixelColor.FromInt(-16744448);
            }
            if (colors[KEYWORDS].ToInt() == 0)
            {
                colors[KEYWORDS] = PixelColor.FromInt(-16741493);
            }
            if (colors[LITERALS].ToInt() == 0)
            {
                colors[LITERALS] = PixelColor.FromInt(-16776999);
            }
            if (colors[CONSTANTS].ToInt() == 0)
            {
                colors[CONSTANTS] = PixelColor.FromInt(-8372160);
            }

            // Set new thing colors
            if (colors[THINGCOLOR00].ToInt() == 0)
            {
                colors[THINGCOLOR00] = PixelColor.FromColor(Color.DimGray);
            }
            if (colors[THINGCOLOR01].ToInt() == 0)
            {
                colors[THINGCOLOR01] = PixelColor.FromColor(Color.RoyalBlue);
            }
            if (colors[THINGCOLOR02].ToInt() == 0)
            {
                colors[THINGCOLOR02] = PixelColor.FromColor(Color.ForestGreen);
            }
            if (colors[THINGCOLOR03].ToInt() == 0)
            {
                colors[THINGCOLOR03] = PixelColor.FromColor(Color.LightSeaGreen);
            }
            if (colors[THINGCOLOR04].ToInt() == 0)
            {
                colors[THINGCOLOR04] = PixelColor.FromColor(Color.Firebrick);
            }
            if (colors[THINGCOLOR05].ToInt() == 0)
            {
                colors[THINGCOLOR05] = PixelColor.FromColor(Color.DarkViolet);
            }
            if (colors[THINGCOLOR06].ToInt() == 0)
            {
                colors[THINGCOLOR06] = PixelColor.FromColor(Color.DarkGoldenrod);
            }
            if (colors[THINGCOLOR07].ToInt() == 0)
            {
                colors[THINGCOLOR07] = PixelColor.FromColor(Color.Silver);
            }
            if (colors[THINGCOLOR08].ToInt() == 0)
            {
                colors[THINGCOLOR08] = PixelColor.FromColor(Color.Gray);
            }
            if (colors[THINGCOLOR09].ToInt() == 0)
            {
                colors[THINGCOLOR09] = PixelColor.FromColor(Color.DeepSkyBlue);
            }
            if (colors[THINGCOLOR10].ToInt() == 0)
            {
                colors[THINGCOLOR10] = PixelColor.FromColor(Color.LimeGreen);
            }
            if (colors[THINGCOLOR11].ToInt() == 0)
            {
                colors[THINGCOLOR11] = PixelColor.FromColor(Color.PaleTurquoise);
            }
            if (colors[THINGCOLOR12].ToInt() == 0)
            {
                colors[THINGCOLOR12] = PixelColor.FromColor(Color.Tomato);
            }
            if (colors[THINGCOLOR13].ToInt() == 0)
            {
                colors[THINGCOLOR13] = PixelColor.FromColor(Color.Violet);
            }
            if (colors[THINGCOLOR14].ToInt() == 0)
            {
                colors[THINGCOLOR14] = PixelColor.FromColor(Color.Yellow);
            }
            if (colors[THINGCOLOR15].ToInt() == 0)
            {
                colors[THINGCOLOR15] = PixelColor.FromColor(Color.WhiteSmoke);
            }
            if (colors[THINGCOLOR16].ToInt() == 0)
            {
                colors[THINGCOLOR16] = PixelColor.FromColor(Color.LightPink);
            }
            if (colors[THINGCOLOR17].ToInt() == 0)
            {
                colors[THINGCOLOR17] = PixelColor.FromColor(Color.DarkOrange);
            }
            if (colors[THINGCOLOR18].ToInt() == 0)
            {
                colors[THINGCOLOR18] = PixelColor.FromColor(Color.DarkKhaki);
            }
            if (colors[THINGCOLOR19].ToInt() == 0)
            {
                colors[THINGCOLOR19] = PixelColor.FromColor(Color.Goldenrod);
            }

            //mxd. Set the rest of new colors (previously these were also defined in GZBuilder.default.cfg)
            if (colors[THREEDFLOORCOLOR].ToInt() == 0)
            {
                colors[THREEDFLOORCOLOR] = PixelColor.FromInt(-65536);
            }
            if (colors[SCRIPTINDICATOR].ToInt() == 0)
            {
                colors[SCRIPTINDICATOR] = PixelColor.FromInt(-16711936);
            }
            if (colors[SCRIPTBRACEHIGHLIGHT].ToInt() == 0)
            {
                colors[SCRIPTBRACEHIGHLIGHT] = PixelColor.FromInt(-16711681);
            }
            if (colors[SCRIPTBADBRACEHIGHLIGHT].ToInt() == 0)
            {
                colors[SCRIPTBADBRACEHIGHLIGHT] = PixelColor.FromInt(-65536);
            }
            if (colors[SCRIPTWHITESPACE].ToInt() == 0)
            {
                colors[SCRIPTWHITESPACE] = PixelColor.FromInt(-8355712);
            }
            if (colors[SCRIPTSELECTIONFORE].ToInt() == 0)
            {
                colors[SCRIPTSELECTIONFORE] = PixelColor.FromInt(-1);
            }
            if (colors[SCRIPTSELECTIONBACK].ToInt() == 0)
            {
                colors[SCRIPTSELECTIONBACK] = PixelColor.FromInt(-13395457);
            }
            if (colors[STRINGS].ToInt() == 0)
            {
                colors[STRINGS] = PixelColor.FromInt(-8388608);
            }
            if (colors[INCLUDES].ToInt() == 0)
            {
                colors[INCLUDES] = PixelColor.FromInt(-9868951);
            }
            if (colors[SCRIPTFOLDFORE].ToInt() == 0)
            {
                colors[SCRIPTFOLDFORE] = PixelColor.FromColor(SystemColors.ControlDark);
            }
            if (colors[SCRIPTFOLDBACK].ToInt() == 0)
            {
                colors[SCRIPTFOLDBACK] = PixelColor.FromColor(SystemColors.ControlLightLight);
            }
            if (colors[PROPERTIES].ToInt() == 0)
            {
                colors[PROPERTIES] = PixelColor.FromInt(-16752191);
            }

            // Create assist colors
            CreateAssistColors();

            // Create color correction table
            CreateCorrectionTable();

            // We have no destructor
            GC.SuppressFinalize(this);
        }