Clear() public method

public Clear ( ) : void
return void
        /// <summary>
        /// Read texture data and bg color from environments
        /// </summary>
        public void HandleEnvironments(RenderEnvironment.Usage usage)
        {
            SimulatedEnvironment simenv;

            switch (usage)
            {
            case RenderEnvironment.Usage.Background:

                if (background_environment != null)
                {
                    simenv = background_environment.SimulateEnvironment(true);
                    if (simenv != null)
                    {
                        bg_color = simenv.BackgroundColor;
                    }
                }
                else
                {
                    bg_color = Color.Empty;
                    bg.Clear();
                }
                BitmapConverter.EnvironmentBitmapFromEvaluator(background_environment, bg, Gamma, PlanarProjection);
                break;

            case RenderEnvironment.Usage.Skylighting:
                bool resampled = false;
                if (skylight_environment != null)
                {
                    simenv = skylight_environment.SimulateEnvironment(true);
                    if (simenv != null)
                    {
                        sky_color = simenv.BackgroundColor;
                    }
                }
                else
                {
                    sky_color = Color.Empty;
                    sky.Clear();
                }
                if (!resampled)
                {
                    BitmapConverter.EnvironmentBitmapFromEvaluator(skylight_environment, sky, Gamma, false);
                }

                break;

            case RenderEnvironment.Usage.ReflectionAndRefraction:
                if (reflection_environment != null)
                {
                    simenv = reflection_environment.SimulateEnvironment(true);
                    if (simenv != null)
                    {
                        refl_color = simenv.BackgroundColor;
                    }
                }
                else
                {
                    refl_color = Color.Empty;
                    refl.Clear();
                }
                BitmapConverter.EnvironmentBitmapFromEvaluator(reflection_environment, refl, Gamma, false);
                break;
            }
        }
        public void HandleWallpaper(ViewInfo view, bool scaleToFit)
        {
            var file = Rhino.Render.Utilities.FindFile(RhinoDoc.ActiveDoc, view.WallpaperFilename);

            bool modifiedWallpaper = false;

            modifiedWallpaper |= m_old_hidden != view.WallpaperHidden | m_old_grayscale != view.ShowWallpaperInGrayScale;
            modifiedWallpaper |= m_old_scaletofit != scaleToFit;
            modifiedWallpaper |= !m_old_wallpaper.Equals(file);
            modified          |= modifiedWallpaper;

            if (string.IsNullOrEmpty(file) || !File.Exists(file))
            {
                Rhino.RhinoApp.OutputDebugString($"{file} not found, clearing and returning\n");
                wallpaper.Clear();
                wallpaper_solid = color1;
                return;
            }

            if (!modifiedWallpaper)
            {
                return;
            }

            m_old_hidden     = view.WallpaperHidden;
            m_old_grayscale  = view.ShowWallpaperInGrayScale;
            m_old_scaletofit = scaleToFit;
            m_old_wallpaper  = file ?? "";
            var crc = Rhino.RhinoMath.CRC32(27, System.Text.Encoding.UTF8.GetBytes(m_old_wallpaper));

            Rhino.RhinoApp.OutputDebugString($"Handling wallpaper, reading {file}\n");
            try
            {
                int near, far;
                var screenport = view.Viewport.GetScreenPort(out near, out far);
                var bottom     = screenport.Bottom;
                var top        = screenport.Top;
                var left       = screenport.Left;
                var right      = screenport.Right;

                // color matrix used for conversion to gray scale
                ColorMatrix cmgray = new ColorMatrix(
                    new[] {
                    new[] { 0.3f, 0.3f, 0.3f, 0.0f, 0.0f },
                    new[] { .59f, .59f, .59f, 0.0f, 0.0f },
                    new[] { .11f, .11f, .11f, 0.0f, 0.0f },
                    new[] { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f },
                    new[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
                }
                    );
                ColorMatrix cmcolor = new ColorMatrix(
                    new[] {
                    new[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f },
                    new[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
                    new[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f },
                    new[] { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f },
                    new[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
                }
                    );
                ImageAttributes attr = new ImageAttributes();
                attr.SetColorMatrix(view.ShowWallpaperInGrayScale ? cmgray : cmcolor);

                var    w           = Math.Abs(right - left);
                var    h           = Math.Abs(bottom - top);
                var    viewport_ar = (float)w / h;
                Bitmap bm          = new Bitmap(file);
                var    image_ar    = (float)bm.Width / bm.Height;

                int nw = 0;
                int nh = 0;
                int x  = 0;
                int y  = 0;
                if (image_ar > viewport_ar)
                {
                    x  = 0;
                    nw = w;
                    nh = (int)(w / image_ar);
                    y  = (int)(h * 0.5 - nh * 0.5);
                }
                else
                {
                    y  = 0;
                    nh = h;
                    nw = (int)(h * image_ar);
                    x  = (int)(w * 0.5 - nw * 0.5);
                }

                Bitmap newBitmap = new Bitmap(w, h);

                var col = Color.Aqua;
                if (color1 != Color.Empty)
                {
                    col = color1;
                }
                var brush  = new SolidBrush(col);
                var p      = new Point(x, y);
                var bmsize = new Size(nw, nh);
                if (scaleToFit)
                {
                    bmsize = new Size(w, h);
                    p      = new Point(0, 0);
                }
                using (Graphics g = Graphics.FromImage(newBitmap))
                {
                    g.FillRectangle(brush, new Rectangle(Point.Empty, newBitmap.Size));
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    if (!view.WallpaperHidden)
                    {
                        g.DrawImage(bm, new Rectangle(p, bmsize), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel, attr);
                    }
                }
                var wallpaperbm = BitmapConverter.ReadByteBitmapFromBitmap(crc, newBitmap.Size.Width, newBitmap.Size.Height, newBitmap);
                wallpaperbm.ApplyGamma(Gamma);
                wallpaper.TexByte = wallpaperbm.Data;
                if (RcCore.It.EngineSettings.SaveDebugImages)
                {
                    wallpaperbm.SaveBitmaps();
                }
                wallpaper.TexWidth  = newBitmap.Width;
                wallpaper.TexHeight = newBitmap.Height;
                wallpaper.Name      =
                    $"{file}_{newBitmap.Width}x{newBitmap.Height}_{view.WallpaperHidden}_{view.ShowWallpaperInGrayScale}_{scaleToFit}_{id}";
            }
            catch (Exception e)
            {
                Rhino.RhinoApp.OutputDebugString($"wallpaper failure: {e.Message}.\n");
                wallpaper.Clear();
            }
        }