コード例 #1
0
ファイル: Panel.cs プロジェクト: zatuliveter/reportviewercore
        internal virtual void RenderBorder(MapGraphics g)
        {
            AntiAliasing antiAliasing = g.AntiAliasing;

            g.AntiAliasing = AntiAliasing.None;
            RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));

            absoluteRectangle.X      = (float)Math.Round(absoluteRectangle.X);
            absoluteRectangle.Y      = (float)Math.Round(absoluteRectangle.Y);
            absoluteRectangle.Width  = (float)Math.Round(absoluteRectangle.Width);
            absoluteRectangle.Height = (float)Math.Round(absoluteRectangle.Height);
            try
            {
                if (BorderWidth <= 0 || BorderColor.IsEmpty || BorderStyle == MapDashStyle.None)
                {
                    return;
                }
                using (Pen pen = new Pen(BorderColor, BorderWidth))
                {
                    pen.DashStyle = MapGraphics.GetPenStyle(BorderStyle);
                    pen.Alignment = PenAlignment.Inset;
                    if (BorderWidth == 1)
                    {
                        absoluteRectangle.Width  -= 1f;
                        absoluteRectangle.Height -= 1f;
                    }
                    g.DrawRectangle(pen, absoluteRectangle.X, absoluteRectangle.Y, absoluteRectangle.Width, absoluteRectangle.Height);
                }
            }
            finally
            {
                g.AntiAliasing = antiAliasing;
            }
        }
コード例 #2
0
        public virtual void RenderBorder(MapGraphics g)
        {
            AntiAliasing antiAliasing = g.AntiAliasing;

            g.AntiAliasing = AntiAliasing.None;
            RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));

            absoluteRectangle.X      = (float)Math.Round((double)absoluteRectangle.X);
            absoluteRectangle.Y      = (float)Math.Round((double)absoluteRectangle.Y);
            absoluteRectangle.Width  = (float)Math.Round((double)absoluteRectangle.Width);
            absoluteRectangle.Height = (float)Math.Round((double)absoluteRectangle.Height);
            try
            {
                if (this.BorderWidth > 0 && !this.BorderColor.IsEmpty && this.BorderStyle != 0)
                {
                    using (Pen pen = new Pen(this.BorderColor, (float)this.BorderWidth))
                    {
                        pen.DashStyle = MapGraphics.GetPenStyle(this.BorderStyle);
                        pen.Alignment = PenAlignment.Inset;
                        if (this.BorderWidth == 1)
                        {
                            absoluteRectangle.Width  -= 1f;
                            absoluteRectangle.Height -= 1f;
                        }
                        g.DrawRectangle(pen, absoluteRectangle.X, absoluteRectangle.Y, absoluteRectangle.Width, absoluteRectangle.Height);
                    }
                }
            }
            finally
            {
                g.AntiAliasing = antiAliasing;
            }
        }
コード例 #3
0
        internal override void Render(MapGraphics g)
        {
            AntiAliasing antiAliasing = g.AntiAliasing;

            g.AntiAliasing = AntiAliasing.None;
            RectangleF rectangleF = new RectangleF(GetAbsoluteLocation(), GetAbsoluteSize());

            rectangleF.X      = (float)Math.Round(rectangleF.X);
            rectangleF.Y      = (float)Math.Round(rectangleF.Y);
            rectangleF.Width  = (float)Math.Round(rectangleF.Width);
            rectangleF.Height = (float)Math.Round(rectangleF.Height);
            if (!(rectangleF.Width > 0f) || !(rectangleF.Height > 0f))
            {
                return;
            }
            try
            {
                if (BackShadowOffset != 0)
                {
                    RectangleF rect = rectangleF;
                    rect.Offset(BackShadowOffset, BackShadowOffset);
                    g.FillRectangle(g.GetShadowBrush(), rect);
                }
                using (Brush brush = g.CreateBrush(rectangleF, BackColor, BackHatchStyle, "", MapImageWrapMode.Unscaled, Color.Empty, MapImageAlign.Center, BackGradientType, BackSecondaryColor))
                {
                    g.FillRectangle(brush, rectangleF);
                }
            }
            finally
            {
                g.AntiAliasing = antiAliasing;
            }
        }
コード例 #4
0
    public void SelectShadowQuality(ShadowQuality quality)
    {
        switch (quality)
        {
        case ShadowQuality.Low:
            RTAntiAliasing  = AntiAliasing.Samples2;
            shadowRT.width  = 1024;
            shadowRT.height = 1024;
            break;

        case ShadowQuality.Middle:
            RTAntiAliasing  = AntiAliasing.Samples4;
            shadowRT.width  = 2048;
            shadowRT.height = 2048;
            break;

        case ShadowQuality.High:
            RTAntiAliasing  = AntiAliasing.Samples8;
            shadowRT.width  = 4096;
            shadowRT.height = 4096;
            break;

        default:
            Debug.LogError("ShadowQuality Parameter Error!");
            break;
        }
        shadowRT.antiAliasing = (int)RTAntiAliasing;
    }
コード例 #5
0
 public static void DundasChartBase(Chart chart
                                    , ChartImageType chartImageType
                                    , int width
                                    , int height
                                    , BorderSkinStyle borderSkinStyle
                                    , Color borderLineColor
                                    , int borderLineWidth
                                    , Color backColor
                                    , Color backGradientEndColor
                                    , Color borderColor
                                    , ChartDashStyle borderStyle
                                    , int borderWidth
                                    , AntiAliasing antiAliasing
                                    )
 {
     DundasChartBase(chart
                     , chartImageType
                     , width
                     , height
                     , borderSkinStyle, borderLineColor, borderLineWidth
                     , backColor, backGradientEndColor
                     , borderColor, borderStyle, borderWidth
                     , ChartHatchStyle.None
                     , GradientType.None
                     , antiAliasing
                     , null
                     , ChartImageWrapMode.Unscaled
                     , ChartImageAlign.TopRight
                     , Color.Empty);
 }
コード例 #6
0
 void ISelectable.DrawSelection(MapGraphics g, RectangleF clipRect, bool designTimeSelection)
 {
     if (this.Shapes.Count != 0)
     {
         MapCore mapCore = this.GetMapCore();
         using (GraphicsPath graphicsPath = this.GetPath(g, false))
         {
             if (graphicsPath != null)
             {
                 RectangleF bounds = graphicsPath.GetBounds();
                 RectangleF rect   = bounds;
                 rect.Inflate(6f, 6f);
                 if (clipRect.IntersectsWith(rect) && !bounds.IsEmpty)
                 {
                     g.DrawSelection(bounds, designTimeSelection, mapCore.SelectionBorderColor, mapCore.SelectionMarkerColor);
                     PointF       centerPointInContentPixels = this.GetCenterPointInContentPixels(g);
                     AntiAliasing antiAliasing = g.AntiAliasing;
                     g.AntiAliasing = AntiAliasing.None;
                     g.DrawLine(Pens.Red, (float)(centerPointInContentPixels.X - 8.0), centerPointInContentPixels.Y, (float)(centerPointInContentPixels.X + 8.0), centerPointInContentPixels.Y);
                     g.DrawLine(Pens.Red, centerPointInContentPixels.X, (float)(centerPointInContentPixels.Y - 8.0), centerPointInContentPixels.X, (float)(centerPointInContentPixels.Y + 8.0));
                     g.AntiAliasing = antiAliasing;
                 }
             }
         }
     }
 }
コード例 #7
0
 public void disable()
 {
     if (m_antiAliasingComponent != null)
     {
         MonoBehaviour.DestroyImmediate(m_antiAliasingComponent);
         m_antiAliasingComponent = null;
     }
 }
コード例 #8
0
		public RayTracer(AntiAliasing antialiasing, bool renderDiffuse, bool renderHighlights, bool renderShadow, bool renderReflection, bool renderRefraction)
		{
			RenderDiffuse = renderDiffuse;
			RenderHighlights = renderHighlights;
			RenderShadow = renderShadow;
			RenderReflection = renderReflection;
			RenderRefraction = renderRefraction;
			AntiAliasing = antialiasing;
		}
コード例 #9
0
    void Awake()
    {
        //单例
        if (Instance == null)
        {
            Instance = this;
        }
        //指定跟随相机
        if (FollowTarget == null)
        {
            Debug.LogWarning("Please specify the target to follow!");
        }
        //默认阴影质量低
        RTAntiAliasing = AntiAliasing.Samples2;

        //设置衰减
        FalloffTex = (Texture2D)Resources.Load("Texture/shadow_falloff");

        //projector初始化
        projector = GetComponent <Projector> ();
        if (projector == null)
        {
            Debug.LogError("Projector Component Missing!!");
        }
        projector.orthographic     = true;
        projector.orthographicSize = ProjectionSize;
        projector.aspectRatio      = Size.x / Size.y;
        shadowMat          = new Material(Shader.Find("ShadowSystem/ProjectorShadow"));
        projector.material = shadowMat;
        shadowMat.SetTexture("_FalloffTex", FalloffTex);
        shadowMat.SetFloat("_Intensity", Intensity);
        projector.ignoreLayers = LayerIgnoreReceiver;

        //camera初始化
        shadowCam = GetComponent <Camera> ();
        if (shadowCam == null)
        {
            Debug.LogError("Camera Component Missing!!");
        }
        shadowCamTrans             = shadowCam.transform;
        shadowCam.clearFlags       = CameraClearFlags.SolidColor;
        shadowCam.backgroundColor  = new Color(0, 0, 0, 0);
        shadowCam.orthographic     = true;
        shadowCam.orthographicSize = ProjectionSize;
        shadowCam.depth            = int.MinValue;
        shadowCam.cullingMask      = LayerCaster;
        shadowRT                = new RenderTexture((int)Size.x, (int)Size.y, 0, RenderTextureFormat.ARGB32);
        shadowRT.name           = "ShadowRT";
        shadowRT.antiAliasing   = (int)RTAntiAliasing;
        shadowRT.filterMode     = FilterMode.Bilinear;
        shadowRT.wrapMode       = TextureWrapMode.Clamp;
        shadowCam.targetTexture = shadowRT;
        shadowMat.SetTexture("_ShadowTex", shadowRT);
    }
コード例 #10
0
ファイル: RayTracer.cs プロジェクト: asmboom/PixelFarm
        public RayTracer(AntiAliasing antialiasing, bool renderDiffuse, bool renderHighlights, bool renderShadow, bool renderReflection, bool renderRefraction)
        {
            // run the ray trace unit tests.
            UnitTests.Run();

            RenderDiffuse = renderDiffuse;
            RenderHighlights = renderHighlights;
            RenderShadow = renderShadow;
            RenderReflection = renderReflection;
            RenderRefraction = renderRefraction;
            AntiAliasing = antialiasing;
        }
コード例 #11
0
ファイル: RayTracer.cs プロジェクト: jeske/agg-sharp
        public RayTracer(AntiAliasing antialiasing, bool renderDiffuse, bool renderHighlights, bool renderShadow, bool renderReflection, bool renderRefraction)
        {
            // run the ray trace unit tests.
            UnitTests.Run();

            RenderDiffuse = renderDiffuse;
            RenderHighlights = renderHighlights;
            RenderShadow = renderShadow;
            RenderReflection = renderReflection;
            RenderRefraction = renderRefraction;
            AntiAliasing = antialiasing;
        }
コード例 #12
0
        internal void CopySettings(MenuSettings settings)
        {
            volume = settings.volume;

            shadows              = settings.shadows;
            shadowsQuality       = settings.shadowsQuality;
            antiAliasing         = settings.antiAliasing;
            anisotropicFiltering = settings.anisotropicFiltering;
            realTimeReflections  = settings.realTimeReflections;
            vSync      = settings.vSync;
            resolution = settings.resolution;
            fullScreen = settings.fullScreen;
        }
コード例 #13
0
 void IRenderable.RenderStaticElements(GaugeGraphics g)
 {
     if (this.Visible)
     {
         g.StartHotRegion(this);
         if (this.Image.Length != 0)
         {
             this.DrawImage(g, this.image, true);
             this.DrawImage(g, this.image, false);
             g.EndHotRegion();
         }
         else
         {
             GraphicsPath graphicsPath  = null;
             GraphicsPath graphicsPath2 = null;
             try
             {
                 graphicsPath  = this.GetTextPath(g);
                 graphicsPath2 = this.GetBackPath(g);
                 g.FillPath(Brushes.White, graphicsPath2);
                 AntiAliasing antiAliasing  = this.Common.GaugeContainer.AntiAliasing;
                 AntiAliasing antiAliasing2 = g.AntiAliasing;
                 if (this.Common.GaugeContainer.AntiAliasing == AntiAliasing.Text)
                 {
                     antiAliasing = AntiAliasing.Graphics;
                 }
                 else if (this.Common.GaugeContainer.AntiAliasing == AntiAliasing.Graphics)
                 {
                     antiAliasing = AntiAliasing.None;
                 }
                 g.AntiAliasing = antiAliasing;
                 g.FillPath(Brushes.Black, graphicsPath);
                 g.AntiAliasing = antiAliasing2;
                 g.DrawPath(Pens.Black, graphicsPath2);
                 this.Common.GaugeCore.HotRegionList.SetHotRegion(this, Point.Empty, (GraphicsPath)graphicsPath2.Clone());
             }
             finally
             {
                 if (graphicsPath != null)
                 {
                     graphicsPath.Dispose();
                 }
                 if (graphicsPath2 != null)
                 {
                     graphicsPath2.Dispose();
                 }
                 g.EndHotRegion();
             }
         }
     }
 }
コード例 #14
0
        public MenuSettings()
        {
            volume = 1;

            shadows        = Shadow.Soft;
            shadowsQuality = ShadowQuality.Ultra;

            antiAliasing         = AntiAliasing.X8;
            anisotropicFiltering = AnisotropicFiltering.Enable;
            realTimeReflections  = true;
            vSync      = VSync.Half;
            resolution = MaxResolution;
            fullScreen = true;
        }
コード例 #15
0
        internal override void Render(MapGraphics g)
        {
            g.StartHotRegion(this);
            MapDashStyle mapDashStyle = BorderStyle;

            if (!string.IsNullOrEmpty(Image))
            {
                ImageSmoothingState imageSmoothingState = new ImageSmoothingState(g);
                imageSmoothingState.Set();
                DrawImage(g, image, drawShadow: true);
                DrawImage(g, image, drawShadow: false);
                imageSmoothingState.Restore();
            }
            else
            {
                string       text         = "No image.";
                Font         font         = new Font("Microsoft Sans Serif", 8.25f);
                SizeF        sizeF        = g.MeasureString(text, font);
                StringFormat stringFormat = new StringFormat();
                stringFormat.Alignment     = StringAlignment.Center;
                stringFormat.LineAlignment = StringAlignment.Center;
                RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
                PointF     absolutePoint     = g.GetAbsolutePoint(new PointF(50f, 50f));
                new RectangleF(absolutePoint.X, absolutePoint.Y, 0f, 0f).Inflate(sizeF.Width / 2f, sizeF.Height / 2f);
                using (Brush brush = new SolidBrush(Color.Gray))
                {
                    g.DrawString(text, font, brush, absoluteRectangle, stringFormat);
                }
                mapDashStyle = MapDashStyle.Solid;
            }
            if (mapDashStyle != 0 && BorderColor != Color.Transparent && BorderWidth != 0)
            {
                using (GraphicsPath path = GetPath(g))
                {
                    using (Pen pen = GetPen())
                    {
                        AntiAliasing antiAliasing = g.AntiAliasing;
                        if (Angle % 90f == 0f)
                        {
                            g.AntiAliasing = AntiAliasing.None;
                        }
                        g.DrawPath(pen, path);
                        g.AntiAliasing = antiAliasing;
                    }
                }
            }
            g.EndHotRegion();
        }
コード例 #16
0
ファイル: Settings.cs プロジェクト: kimch2/Winterfall
    void Start()
    {
        mainCam = Camera.main;
        presetsDropdown.value = QualitySettings.GetQualityLevel();
        Refresh();

        bloomScript            = mainCam.GetComponent <Bloom>();
        motionBlurScript       = mainCam.GetComponent <MotionBlur>();
        ambientOcclusionScript = mainCam.GetComponent <AmbientOcclusion>();
        antiAliasingScript     = mainCam.GetComponent <AntiAliasing>();
        sunRaysScript          = mainCam.GetComponent <TOD_Rays>();
        cloudShadowsScript     = mainCam.GetComponent <TOD_Shadows>();
        lensAberrationsScript  = mainCam.GetComponent <LensAberrations>();

        fullscreenToggle.onValueChanged.AddListener(delegate { OnFullscreenToggle(); });
    }
コード例 #17
0
        void IRenderable.RenderStaticElements(GaugeGraphics g)
        {
            if (!Visible)
            {
                return;
            }
            g.StartHotRegion(this);
            if (Image.Length != 0)
            {
                DrawImage(g, image, drawShadow: true);
                DrawImage(g, image, drawShadow: false);
                g.EndHotRegion();
                return;
            }
            GraphicsPath graphicsPath  = null;
            GraphicsPath graphicsPath2 = null;

            try
            {
                graphicsPath  = GetTextPath(g);
                graphicsPath2 = GetBackPath(g);
                g.FillPath(Brushes.White, graphicsPath2);
                AntiAliasing antiAliasing  = Common.GaugeContainer.AntiAliasing;
                AntiAliasing antiAliasing2 = g.AntiAliasing;
                if (Common.GaugeContainer.AntiAliasing == AntiAliasing.Text)
                {
                    antiAliasing = AntiAliasing.Graphics;
                }
                else if (Common.GaugeContainer.AntiAliasing == AntiAliasing.Graphics)
                {
                    antiAliasing = AntiAliasing.None;
                }
                g.AntiAliasing = antiAliasing;
                g.FillPath(Brushes.Black, graphicsPath);
                g.AntiAliasing = antiAliasing2;
                g.DrawPath(Pens.Black, graphicsPath2);
                Common.GaugeCore.HotRegionList.SetHotRegion(this, Point.Empty, (GraphicsPath)graphicsPath2.Clone());
            }
            finally
            {
                graphicsPath?.Dispose();
                graphicsPath2?.Dispose();
                g.EndHotRegion();
            }
        }
コード例 #18
0
        internal override void RenderBorder(MapGraphics g)
        {
            AntiAliasing antiAliasing = g.AntiAliasing;

            g.AntiAliasing = AntiAliasing.None;
            RectangleF rectangleF = new RectangleF(GetAbsoluteLocation(), GetAbsoluteSize());

            rectangleF.X      = (float)Math.Round(rectangleF.X);
            rectangleF.Y      = (float)Math.Round(rectangleF.Y);
            rectangleF.Width  = (float)Math.Round(rectangleF.Width);
            rectangleF.Height = (float)Math.Round(rectangleF.Height);
            if (!(rectangleF.Width > 0f) || !(rectangleF.Height > 0f))
            {
                return;
            }
            try
            {
                if (BorderWidth <= 0 || BorderColor.IsEmpty || BorderStyle == MapDashStyle.None)
                {
                    return;
                }
                using (Pen pen = new Pen(BorderColor, BorderWidth))
                {
                    pen.DashStyle = MapGraphics.GetPenStyle(BorderStyle);
                    pen.Alignment = PenAlignment.Inset;
                    if (BorderWidth == 1)
                    {
                        rectangleF.Width  -= 1f;
                        rectangleF.Height -= 1f;
                    }
                    g.DrawRectangle(pen, rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height);
                }
            }
            finally
            {
                g.AntiAliasing = antiAliasing;
            }
        }
コード例 #19
0
        public override void RenderBorder(MapGraphics g)
        {
            AntiAliasing antiAliasing = g.AntiAliasing;

            g.AntiAliasing = AntiAliasing.None;
            RectangleF rectangleF = new RectangleF(base.GetAbsoluteLocation(), base.GetAbsoluteSize());

            rectangleF.X      = (float)Math.Round((double)rectangleF.X);
            rectangleF.Y      = (float)Math.Round((double)rectangleF.Y);
            rectangleF.Width  = (float)Math.Round((double)rectangleF.Width);
            rectangleF.Height = (float)Math.Round((double)rectangleF.Height);
            if (rectangleF.Width > 0.0 && rectangleF.Height > 0.0)
            {
                try
                {
                    if (this.BorderWidth > 0 && !this.BorderColor.IsEmpty && this.BorderStyle != 0)
                    {
                        using (Pen pen = new Pen(this.BorderColor, (float)this.BorderWidth))
                        {
                            pen.DashStyle = MapGraphics.GetPenStyle(this.BorderStyle);
                            pen.Alignment = PenAlignment.Inset;
                            if (this.BorderWidth == 1)
                            {
                                rectangleF.Width  -= 1f;
                                rectangleF.Height -= 1f;
                            }
                            g.DrawRectangle(pen, rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height);
                        }
                    }
                }
                finally
                {
                    g.AntiAliasing = antiAliasing;
                }
            }
        }
コード例 #20
0
ファイル: Panel.cs プロジェクト: zatuliveter/reportviewercore
        internal virtual void RenderBackground(MapGraphics g)
        {
            AntiAliasing antiAliasing = g.AntiAliasing;

            g.AntiAliasing = AntiAliasing.None;
            RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));

            absoluteRectangle.X      = (float)Math.Round(absoluteRectangle.X);
            absoluteRectangle.Y      = (float)Math.Round(absoluteRectangle.Y);
            absoluteRectangle.Width  = (float)Math.Round(absoluteRectangle.Width);
            absoluteRectangle.Height = (float)Math.Round(absoluteRectangle.Height);
            try
            {
                if (BackShadowOffset != 0)
                {
                    RectangleF rect = absoluteRectangle;
                    rect.Offset(BackShadowOffset, BackShadowOffset);
                    g.FillRectangle(g.GetShadowBrush(), rect);
                }
                if (IsMakeTransparentRequired())
                {
                    using (Brush brush = new SolidBrush(GetColorForMakeTransparent()))
                    {
                        g.FillRectangle(brush, absoluteRectangle);
                    }
                }
                using (Brush brush2 = g.CreateBrush(absoluteRectangle, BackColor, BackHatchStyle, "", MapImageWrapMode.Unscaled, Color.Empty, MapImageAlign.Center, BackGradientType, BackSecondaryColor))
                {
                    g.FillRectangle(brush2, absoluteRectangle);
                }
            }
            finally
            {
                g.AntiAliasing = antiAliasing;
            }
        }
コード例 #21
0
        public static void DundasChartBase(Chart chart
                                           , ChartImageType chartImageType
                                           , int width
                                           , int height
                                           , BorderSkinStyle borderSkinStyle
                                           , Color borderLineColor
                                           , int borderLineWidth
                                           , Color backColor
                                           , Color backGradientEndColor
                                           , Color borderColor
                                           , ChartDashStyle borderStyle
                                           , int borderWidth
                                           , ChartHatchStyle chartHatchStyle
                                           , GradientType gradientType
                                           , AntiAliasing antiAliasing
                                           , string backImage
                                           , ChartImageWrapMode backImageMode
                                           , ChartImageAlign backImageAlign
                                           , Color backImageTranspColor)
        {
            chart.ImageType = chartImageType;

            if (width != -1)
            {
                chart.Width = width;
            }

            if (height != -1)
            {
                chart.Height = height;
            }

            if (borderSkinStyle != BorderSkinStyle.None)
            {
                chart.BorderSkin.SkinStyle = borderSkinStyle;
            }

            if (!borderLineColor.Equals(Color.Empty))
            {
                chart.BorderLineColor = borderLineColor;
            }

            if (borderLineWidth != -1)
            {
                chart.BorderLineWidth = borderLineWidth;
            }

            if (!backColor.Equals(Color.Empty))
            {
                chart.BackColor = backColor;
            }
            // Set Back Gradient End Color
            if (!backGradientEndColor.Equals(Color.Empty))
            {
                chart.BackGradientEndColor = backGradientEndColor;
            }

            // Set Hatch Style
            // Set Border Color
            if (!borderColor.Equals(Color.Empty))
            {
                chart.BorderColor = borderColor;
            }
            // Set Border Style
            if (borderStyle != ChartDashStyle.NotSet)
            {
                chart.BorderStyle = borderStyle;
            }
            // Set Border Width
            if (borderWidth != -1)
            {
                chart.BorderWidth = borderWidth;
            }

            if (chartHatchStyle != ChartHatchStyle.None)
            {
                chart.BackHatchStyle = chartHatchStyle;
            }
            if (gradientType != GradientType.None)
            {
                chart.BackGradientType = gradientType;
            }

            if (antiAliasing != AntiAliasing.None)
            {
                chart.AntiAliasing = antiAliasing;
            }

            if (backImage != null)
            {
                chart.BackImage      = backImage;
                chart.BackImageMode  = backImageMode;
                chart.BackImageAlign = backImageAlign;

                if (!backImageTranspColor.Equals(Color.Empty))
                {
                    chart.BackImageTranspColor = backImageTranspColor;
                }
            }
        }
コード例 #22
0
        private void applyConfig()
        {
            if (m_activeConfig.mode == 0)
            {
                disable();
            }
            else if (m_activeConfig.mode == AntiAliasingMode.SMAA || m_activeConfig.mode == AntiAliasingMode.FXAA)
            {
                // First try to get it from the camera.
                if (m_antiAliasingComponent == null)
                {
                    m_antiAliasingComponent = ModDescription.camera.GetComponent <AntiAliasing>();
                }

                // If that fails then just add it
                if (m_antiAliasingComponent == null)
                {
                    m_antiAliasingComponent = ModDescription.camera.AddComponent <AntiAliasing>();
                    if (m_antiAliasingComponent == null)
                    {
                        m_activeConfig.mode = 0;
                        throw new Exception("AntiAliasingEffect: Couldn't add Antialiasing to Camera.");
                    }
                }

                m_antiAliasingComponent.enabled = true;

                switch (m_activeConfig.mode)
                {
                case AntiAliasingMode.FXAA:
                    // Enabled the FXAA settings.
                    m_antiAliasingComponent.m_FXAA.preset = FXAA.availablePresets[m_activeConfig.fxaaQuality];
                    m_antiAliasingComponent.method        = (int)AntiAliasing.Method.Fxaa;
                    break;

                case AntiAliasingMode.SMAA:
                    // Enable the required SMAA settings
                    m_antiAliasingComponent.m_SMAA.settings.quality             = m_activeConfig.smaaQuality;
                    m_antiAliasingComponent.m_SMAA.settings.edgeDetectionMethod = m_activeConfig.smaaEdgeMethod;
                    m_antiAliasingComponent.m_SMAA.temporal.enabled             = m_activeConfig.smaaTemporal;
                    m_antiAliasingComponent.m_SMAA.predication.enabled          = m_activeConfig.smaaPredication;
                    m_antiAliasingComponent.m_SMAA.predication.strength         = 0.5f;

                    m_antiAliasingComponent.method = (int)AntiAliasing.Method.Smaa;
                    break;
                }
            }
            else
            {
                m_temporalComponent = Camera.main.GetComponent <CineTemporalAntiAliasing>();
                if (m_temporalComponent == null)
                {
                    m_temporalComponent = Camera.main.gameObject.AddComponent <CineTemporalAntiAliasing>();
                    if (m_temporalComponent == null)
                    {
                        m_activeConfig.mode = 0;
                        throw new Exception("AntiAliasingEffect: Couldn't add TemporalAntiAliasing to Camera.");
                    }
                }

                m_temporalComponent.enabled = true;

                m_temporalComponent.settings.jitterSettings.sampleCount = 2;
                m_temporalComponent.settings.jitterSettings.spread      = 0.05f;

                m_temporalComponent.settings.sharpenFilterSettings.amount = 0.0f;

                //m_temporalComponent.settings.blendSettings.motionAmplification = 70.0f;
                //m_temporalComponent.settings.blendSettings.stationary = 1.0f;
                //m_temporalComponent.settings.blendSettings.moving = 0.0f;
            }
        }
コード例 #23
0
ファイル: CapturePanorama.cs プロジェクト: EliCDavis/ped-sim
        void ReinitializeBody() {
            Log("Settings changed, calling Reinitialize()");

            initializeFailed = true;

            if (!SystemInfo.supportsComputeShaders)
            {
                Debug.LogWarning("CapturePanorama requires compute shaders. Your system does not support them. " +
                    "On PC, compute shaders require DirectX 11, Windows Vista or later, and a GPU capable of Shader Model 5.0.");
                return;
            }

            lastConfiguredCaptureStereoscopic = captureStereoscopic;
            lastConfiguredPanoramaWidth = panoramaWidth;
            lastConfiguredInterpupillaryDistance = interpupillaryDistance;
            lastConfiguredNumCirclePoints = numCirclePoints;
            lastConfiguredSsaaFactor = ssaaFactor;
            lastConfiguredAntiAliasing = antiAliasing;
            lastConfiguredSaveCubemap = saveCubemap;
            lastConfiguredUseGpuTransform = useGpuTransform;

            Cleanup();

            faces = new CubemapFace[] {
			    CubemapFace.PositiveX, CubemapFace.NegativeX,
			    CubemapFace.PositiveY, CubemapFace.NegativeY,
			    CubemapFace.PositiveZ, CubemapFace.NegativeZ };

            for (int i = 0; i < faces.Length; i++)
                Debug.Assert((int)faces[i] == i); // Required for ConvertPanoramaShader

            panoramaHeight = panoramaWidth / 2;

            // We have a tower of 3 nested GameObjects. First gets the original camera position,
            // second gets the eye rotation/position relative to it, and third holds the camera with default position/rotation.
            camGos = new GameObject[3];
            for (int i = 0; i < 3; i++)
            {
                camGos[i] = new GameObject("PanoramaCaptureCamera" + i);
                camGos[i].hideFlags = HideFlags.HideAndDontSave;
                if (i > 0) camGos[i].transform.parent = camGos[i - 1].transform;
            }

            camGos[2].AddComponent<Camera>();
            cam = camGos[2].GetComponent<Camera>();
            cam.enabled = false;
            camGos[2].AddComponent<ImageEffectCopyCamera>();
            copyCameraScript = camGos[2].GetComponent<ImageEffectCopyCamera>();
            copyCameraScript.enabled = false;

            numCameras = faces.Length;
            hFov = vFov = 90.0f;
            if (captureStereoscopic)
            {
                // For stereoscopic rendering, there are a set of points lying on a horizontal circle around the origin.
                // Will have four cameras per circle point, one turned left 45 deg, one turned right 45 deg,
                // one turned up 45 deg, one turned down 45 deg. Allows covering >= 180 deg horizontal and 180 deg vertical.
                // To be able to resolve all rays, we need to choose a large enough horizontal FOV for each camera.

                float maxAngleError = 360.0f / numCirclePoints;

                // TODO: Use different hFov/vFov for top/bottom cameras and left/right cameras (vFov of top/bottom cameras especially is a lot less)

                // Given our ipd adjustment scaling f(x), the IPD range of the top/bottom cameras will be up to f(0.5)
                // of the original IPD. Hence the necessary hFov is given by 2*(pi/2 - acos(f(0.5))), usually in the 90-115 deg range.
                float extraFovForRoundingErrors = 0.001f;
                float hFovTopBottom = 2.0f * (Mathf.PI / 2.0f - Mathf.Acos(IpdScaleFunction(0.5f))) * 360.0f / (2.0f * Mathf.PI);
                hFov = Mathf.Max(90f + maxAngleError, hFovTopBottom) + extraFovForRoundingErrors; // These will usually be similar so just use max for simplicity
                vFov = 90.0f;
                numCameras = 2 + numCirclePoints * CamerasPerCirclePoint; // 2 + for top/bottom
                circleRadius = interpupillaryDistance / 2.0f;
                hFovAdjustDegrees = hFov / 2.0f;
                vFovAdjustDegrees = vFov / 2.0f;
            }

            double ppd90 = panoramaWidth * 90.0 / 360.0;
            // Match PPD at 90 degrees - if it's larger, central 90 degree section should match PPD
            cameraWidth = (int)Math.Ceiling(Math.Tan(hFov * (2.0f*Mathf.PI)/360.0f / 2.0f) * ppd90 * ssaaFactor);
            cameraHeight = (int)Math.Ceiling(Math.Tan(vFov * (2.0f * Mathf.PI) / 360.0f / 2.0f) * ppd90 * ssaaFactor);

            Log("Number of cameras: " + numCameras);
            Log("Camera dimensions: " + cameraWidth + "x" + cameraHeight);

            usingGpuTransform = useGpuTransform && convertPanoramaShader != null;

            cubemapRenderTexture = new RenderTexture(cameraWidth, cameraHeight, /*depth*/24, RenderTextureFormat.ARGB32);
            cubemapRenderTexture.antiAliasing = (int)antiAliasing;
            cubemapRenderTexture.Create();

            if (usingGpuTransform)
            {
                convertPanoramaKernelIdx = convertPanoramaShader.FindKernel("CubeMapToEquirectangular");
                convertPanoramaYPositiveKernelIdx = convertPanoramaShader.FindKernel("CubeMapToEquirectangularPositiveY");
                convertPanoramaYNegativeKernelIdx = convertPanoramaShader.FindKernel("CubeMapToEquirectangularNegativeY");
                convertPanoramaKernelIdxs = new int[] { convertPanoramaKernelIdx, convertPanoramaYPositiveKernelIdx, convertPanoramaYNegativeKernelIdx };
                convertPanoramaShader.SetInt("equirectangularWidth", panoramaWidth);
                convertPanoramaShader.SetInt("equirectangularHeight", panoramaHeight);
                convertPanoramaShader.SetInt("ssaaFactor", ssaaFactor);
                convertPanoramaShader.SetInt("cameraWidth", cameraWidth);
                convertPanoramaShader.SetInt("cameraHeight", cameraHeight);

                int sliceHeight = (panoramaHeight + ResultBufferSlices - 1) / ResultBufferSlices;
                int bitmapWidth = panoramaWidth;
                int bitmapHeight = (captureStereoscopic ? 2 * panoramaHeight : sliceHeight);
                resultPixels = new uint[bitmapWidth * bitmapHeight + 1]; // + 1 for sentinel
            }

            textureToBufferIdx = textureToBufferShader.FindKernel("TextureToBuffer");
            textureToBufferShader.SetInt("width", cameraWidth);
            textureToBufferShader.SetInt("height", cameraHeight);
            textureToBufferShader.SetFloat("gamma", QualitySettings.activeColorSpace == ColorSpace.Linear ? 1.0f/2.2f : 1.0f);

            renderStereoIdx = convertPanoramaStereoShader.FindKernel("RenderStereo");

            if ((saveCubemap || !usingGpuTransform) &&
                (cameraPixels == null || cameraPixels.Length != numCameras * cameraWidth * cameraHeight))
            {
                // Allocate once to avoid GC fragmentation
                cameraPixels = new uint[numCameras * cameraWidth * cameraHeight + 1]; // + 1 for sentinel
            }

            tanHalfHFov = Mathf.Tan(hFov * (2 * Mathf.PI) / 360.0f / 2.0f);
            tanHalfVFov = Mathf.Tan(vFov * (2 * Mathf.PI) / 360.0f / 2.0f);
            hFovAdjust = hFovAdjustDegrees * (2 * Mathf.PI) / 360.0f;
            vFovAdjust = vFovAdjustDegrees * (2 * Mathf.PI) / 360.0f;

            if (captureStereoscopic && usingGpuTransform)
            {
                convertPanoramaStereoShader.SetFloat("tanHalfHFov", tanHalfHFov);
                convertPanoramaStereoShader.SetFloat("tanHalfVFov", tanHalfVFov);
                convertPanoramaStereoShader.SetFloat("hFovAdjust", hFovAdjust);
                convertPanoramaStereoShader.SetFloat("vFovAdjust", vFovAdjust);
                convertPanoramaStereoShader.SetFloat("interpupillaryDistance", interpupillaryDistance);
                convertPanoramaStereoShader.SetFloat("circleRadius", circleRadius);
                convertPanoramaStereoShader.SetInt("numCirclePoints", numCirclePoints);
                convertPanoramaStereoShader.SetInt("equirectangularWidth", panoramaWidth);
                convertPanoramaStereoShader.SetInt("equirectangularHeight", panoramaHeight);
                convertPanoramaStereoShader.SetInt("cameraWidth", cameraWidth);
                convertPanoramaStereoShader.SetInt("cameraHeight", cameraHeight);
                convertPanoramaStereoShader.SetInt("ssaaFactor", ssaaFactor);
            }

            initializeFailed = false;
        }
コード例 #24
0
        internal override void Render(MapGraphics g)
        {
            AntiAliasing antiAliasing = g.AntiAliasing;

            try
            {
                MapCore mapCore = GetMapCore();
                if (mapCore == null)
                {
                    return;
                }
                g.AntiAliasing = AntiAliasing.None;
                base.Render(g);
                float      num = 4.5f;
                RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
                absoluteRectangle.Inflate(0f - num, 0f - num);
                if (absoluteRectangle.Width < 3f || absoluteRectangle.Height < 3f)
                {
                    return;
                }
                float           num2             = 0f;
                float           num3             = 0f;
                string          arg              = "0";
                string          arg2             = "0";
                MeasurementUnit measurementUnit  = MeasurementUnit.km;
                MeasurementUnit measurementUnit2 = MeasurementUnit.mi;
                float           num4             = absoluteRectangle.Width - 6f;
                float           kilometers       = (float)mapCore.PixelsToKilometers(num4);
                float           miles            = kilometers * KilometersToMiles;
                measurementUnit = AdjustMetricUnit(ref kilometers);
                float num5 = FloorDistance(kilometers);
                float num6 = num5 / kilometers;
                measurementUnit2 = AdjustImperialUnit(ref miles);
                float num7 = FloorDistance(miles);
                float num8 = num7 / miles;
                if (num5 >= 1f && num7 >= 1f)
                {
                    num2 = num4 * num6;
                    num3 = num4 * num8;
                    if (GetMapCore().MapControl.FormatNumberHandler != null)
                    {
                        arg  = GetMapCore().MapControl.FormatNumberHandler(GetMapCore().MapControl, num5, "G");
                        arg2 = GetMapCore().MapControl.FormatNumberHandler(GetMapCore().MapControl, num7, "G");
                    }
                    else
                    {
                        arg  = num5.ToString(CultureInfo.CurrentCulture);
                        arg2 = num7.ToString(CultureInfo.CurrentCulture);
                    }
                }
                else
                {
                    num2 = num4;
                    num3 = num4;
                }
                using (GraphicsPath path = CreateScalePath(absoluteRectangle, (int)num2, (int)num3))
                {
                    using (Brush brush = new SolidBrush(ScaleForeColor))
                    {
                        g.FillPath(brush, path);
                    }
                    using (Pen pen = new Pen(ScaleBorderColor, 1f))
                    {
                        pen.Alignment  = PenAlignment.Center;
                        pen.MiterLimit = 0f;
                        g.DrawPath(pen, path);
                    }
                    StringFormat stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone();
                    stringFormat.FormatFlags = StringFormatFlags.NoWrap;
                    using (Brush brush2 = new SolidBrush(LabelColor))
                    {
                        RectangleF textBounds      = new RectangleF(absoluteRectangle.Left + 3f, absoluteRectangle.Top, num2, absoluteRectangle.Height / 2f - 3f);
                        string     text            = string.Format(CultureInfo.CurrentCulture, "{0} {1}", arg, measurementUnit.ToString(CultureInfo.CurrentCulture));
                        SizeF      textClipSize    = g.MeasureString(text, Font, textBounds.Size, stringFormat);
                        RectangleF layoutRectangle = CreateTextClip(textBounds, textClipSize);
                        g.DrawString(text, Font, brush2, layoutRectangle, stringFormat);
                        RectangleF textBounds2      = new RectangleF(absoluteRectangle.Left + 3f, absoluteRectangle.Top + absoluteRectangle.Height / 2f + 3f, num3, absoluteRectangle.Height / 2f - 3f);
                        string     text2            = string.Format(CultureInfo.CurrentCulture, "{0} {1}", arg2, measurementUnit2.ToString(CultureInfo.CurrentCulture));
                        SizeF      textClipSize2    = g.MeasureString(text2, Font, textBounds2.Size, stringFormat);
                        RectangleF layoutRectangle2 = CreateTextClip(textBounds2, textClipSize2);
                        g.DrawString(text2, Font, brush2, layoutRectangle2, stringFormat);
                    }
                }
            }
            finally
            {
                g.AntiAliasing = antiAliasing;
            }
        }
コード例 #25
0
ファイル: RayTracer.cs プロジェクト: glocklueng/agg-sharp
		public RayTracer(AntiAliasing antialiasing, bool renderDiffuse, bool renderHighlights, bool renderShadow, bool renderReflection, bool renderRefraction)
		{
			RenderDiffuse = renderDiffuse;
			RenderHighlights = renderHighlights;
			RenderShadow = renderShadow;
			RenderReflection = renderReflection;
			RenderRefraction = renderRefraction;
			AntiAliasing = antialiasing;
		}
コード例 #26
0
        public override void Render(MapGraphics g)
        {
            AntiAliasing antiAliasing = g.AntiAliasing;

            try
            {
                MapCore mapCore = base.GetMapCore();
                if (mapCore != null)
                {
                    g.AntiAliasing = AntiAliasing.None;
                    base.Render(g);
                    float      num = 4.5f;
                    RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
                    absoluteRectangle.Inflate((float)(0.0 - num), (float)(0.0 - num));
                    if (!(absoluteRectangle.Width < 3.0) && !(absoluteRectangle.Height < 3.0))
                    {
                        float           num2             = 0f;
                        float           num3             = 0f;
                        string          text             = "0";
                        string          text2            = "0";
                        MeasurementUnit measurementUnit  = MeasurementUnit.km;
                        MeasurementUnit measurementUnit2 = MeasurementUnit.mi;
                        float           num4             = (float)(absoluteRectangle.Width - 6.0);
                        float           num5             = (float)mapCore.PixelsToKilometers(num4);
                        float           num6             = num5 * this.KilometersToMiles;
                        measurementUnit = this.AdjustMetricUnit(ref num5);
                        float num7 = (float)this.FloorDistance((double)num5);
                        float num8 = num7 / num5;
                        measurementUnit2 = this.AdjustImperialUnit(ref num6);
                        float num9  = (float)this.FloorDistance((double)num6);
                        float num10 = num9 / num6;
                        if (num7 >= 1.0 && num9 >= 1.0)
                        {
                            num2 = num4 * num8;
                            num3 = num4 * num10;
                            if (base.GetMapCore().MapControl.FormatNumberHandler != null)
                            {
                                text  = base.GetMapCore().MapControl.FormatNumberHandler(base.GetMapCore().MapControl, num7, "G");
                                text2 = base.GetMapCore().MapControl.FormatNumberHandler(base.GetMapCore().MapControl, num9, "G");
                            }
                            else
                            {
                                text  = num7.ToString(CultureInfo.CurrentCulture);
                                text2 = num9.ToString(CultureInfo.CurrentCulture);
                            }
                        }
                        else
                        {
                            num2 = num4;
                            num3 = num4;
                        }
                        using (GraphicsPath path = this.CreateScalePath(absoluteRectangle, (int)num2, (int)num3))
                        {
                            using (Brush brush = new SolidBrush(this.ScaleForeColor))
                            {
                                g.FillPath(brush, path);
                            }
                            using (Pen pen = new Pen(this.ScaleBorderColor, 1f))
                            {
                                pen.Alignment  = PenAlignment.Center;
                                pen.MiterLimit = 0f;
                                g.DrawPath(pen, path);
                            }
                            StringFormat stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone();
                            stringFormat.FormatFlags = StringFormatFlags.NoWrap;
                            using (Brush brush2 = new SolidBrush(this.LabelColor))
                            {
                                RectangleF textBounds      = new RectangleF((float)(absoluteRectangle.Left + 3.0), absoluteRectangle.Top, num2, (float)(absoluteRectangle.Height / 2.0 - 3.0));
                                string     text3           = string.Format(CultureInfo.CurrentCulture, "{0} {1}", text, ((Enum)(object)measurementUnit).ToString((IFormatProvider)CultureInfo.CurrentCulture));
                                SizeF      textClipSize    = g.MeasureString(text3, this.Font, textBounds.Size, stringFormat);
                                RectangleF layoutRectangle = this.CreateTextClip(textBounds, textClipSize);
                                g.DrawString(text3, this.Font, brush2, layoutRectangle, stringFormat);
                                RectangleF textBounds2      = new RectangleF((float)(absoluteRectangle.Left + 3.0), (float)(absoluteRectangle.Top + absoluteRectangle.Height / 2.0 + 3.0), num3, (float)(absoluteRectangle.Height / 2.0 - 3.0));
                                string     text4            = string.Format(CultureInfo.CurrentCulture, "{0} {1}", text2, ((Enum)(object)measurementUnit2).ToString((IFormatProvider)CultureInfo.CurrentCulture));
                                SizeF      textClipSize2    = g.MeasureString(text4, this.Font, textBounds2.Size, stringFormat);
                                RectangleF layoutRectangle2 = this.CreateTextClip(textBounds2, textClipSize2);
                                g.DrawString(text4, this.Font, brush2, layoutRectangle2, stringFormat);
                            }
                        }
                    }
                }
            }
            finally
            {
                g.AntiAliasing = antiAliasing;
            }
        }
コード例 #27
0
        private void OnGUI()
        {
            Camera camera;

            renderCamera = EditorGUILayout.ObjectField("Render Camera", renderCamera, typeof(Camera), true) as Camera;

            if (renderCamera == null)
            {
                GUILayout.BeginHorizontal();
                GUI.enabled = Camera.main != null;
                if (GUILayout.Button("Main Camera"))
                {
                    renderCamera = Camera.main;
                }
                GUI.enabled = true;
                if (GUILayout.Button("First Camera"))
                {
                    renderCamera = FindObjectOfType <Camera>();
                }
                GUILayout.EndHorizontal();
            }

            if (renderCamera == null)
            {
                if (SceneView.lastActiveSceneView != null)
                {
                    camera = SceneView.lastActiveSceneView.camera;
                    EditorGUILayout.HelpBox("If you don't choose a render camera, the scene camera will be used. It is recommended to use a real camera", MessageType.Warning);
                }
                else
                {
                    EditorGUILayout.HelpBox("No valid cameras found to render, please assign a camera or open a scene view", MessageType.Warning);
                    return;
                }
            }
            else
            {
                camera = renderCamera;
            }

            fileFileFormat = (FileFormat)EditorGUILayout.EnumPopup("Format", fileFileFormat);
            if (fileFileFormat == FileFormat.JPEG)
            {
                RenderJPEGOptions();
            }

#if UNITY_2019_3_OR_NEWER
            graphicsFormat = (GraphicsFormat)EditorGUILayout.EnumPopup("Graphics Format", graphicsFormat);
#else
            textureFormat       = (TextureFormat)EditorGUILayout.EnumPopup("Texture Format", textureFormat);
            renderTextureFormat = (RenderTextureFormat)EditorGUILayout.EnumPopup("Render Texture Format", renderTextureFormat);
#endif

            EditorGUILayout.BeginHorizontal();
            width  = EditorGUILayout.IntField("Width", width);
            height = EditorGUILayout.IntField("Height", height);
            EditorGUILayout.EndHorizontal();
            antiAliasing = (AntiAliasing)EditorGUILayout.EnumPopup("Anti Aliasing", antiAliasing);

            EditorGUILayout.Space();
            nameRendersByDate = EditorGUILayout.ToggleLeft("Name Renders By Date", nameRendersByDate);
            if (nameRendersByDate)
            {
                lastPath = EditorGUILayout.TextField("Output Directory", lastPath);
                if (GUILayout.Button("Choose Path"))
                {
                    lastPath = EditorUtility.OpenFolderPanel(
                        "Select Directory",
                        string.IsNullOrEmpty(lastPath) ? Application.dataPath : lastPath, "Screenshots");
                }
            }

            EditorGUILayout.Space();
            if (GUILayout.Button("Render"))
            {
                string path = "";
                if (nameRendersByDate)
                {
                    path  = lastPath + "/Render_" + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss");
                    path += fileFileFormat == FileFormat.PNG ? ".png" : ".jpeg";
                }
                else
                {
                    var currentObj = Selection.activeObject;
                    var filename   = currentObj == null ? "Render" : currentObj.name;
                    filename = filename.ToLower().Replace(' ', '_');

                    path = EditorUtility.SaveFilePanel(
                        "Save as",
                        string.IsNullOrEmpty(lastPath) ? Application.dataPath : lastPath,
                        filename,
                        fileFileFormat == FileFormat.PNG ? "png" : "jpeg");

                    lastPath = path;
                }

                Debug.Log("Outputting to: " + path);
                Debug.Log("Last Path: " + lastPath);

                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

#if UNITY_2019_3_OR_NEWER
                var texture = camera.RenderToTexture(width, height, 0, graphicsFormat, (int)antiAliasing);
#else
                var texture = camera.RenderToTexture(width, height, 0, textureFormat, renderTextureFormat, (int)antiAliasing);
#endif
                var imageData = fileFileFormat == FileFormat.PNG ? texture.EncodeToPNG() : texture.EncodeToJPG(jpegQuality);
                File.WriteAllBytes(path, imageData);
                DestroyImmediate(texture);

                AssetDatabase.Refresh();
            }
        }
コード例 #28
0
ファイル: CapturePanorama.cs プロジェクト: EliCDavis/ped-sim
        public IEnumerator CaptureScreenshotAsyncHelper(string filenameBase, bool async)
        {
            if (async)
                while (Capturing)
                    yield return null; // If CaptureScreenshot() was called programmatically multiple times, serialize the coroutines
            Capturing = true;

            if (!OnCaptureStart())
            {
                audioSource.PlayOneShot(failSound);
                Capturing = false;
                yield break;
            }

            // Have to refresh cameras each frame during video in case cameras or image effects change - consider an option for this.
            Camera[] cameras = GetCaptureCameras();
            Array.Sort(cameras, (x, y) => x.depth.CompareTo(y.depth));

            if (cameras.Length == 0)
            {
                Debug.LogWarning("No cameras found to capture");
                audioSource.PlayOneShot(failSound);
                Capturing = false;
                yield break;
            }

            // Need to do this first in case we need to reinitialize
            if (antiAliasing != AntiAliasing._1)
            {
                foreach (Camera c in cameras)
                {
                    if (c.actualRenderingPath == RenderingPath.DeferredLighting ||
                        c.actualRenderingPath == RenderingPath.DeferredShading)
                    {
                        Debug.LogWarning("CapturePanorama: Setting Anti Aliasing=1 because at least one camera in deferred mode. Use SSAA setting or Antialiasing image effect if needed.");
                        antiAliasing = AntiAliasing._1;
                        Reinitialize();
                        break;
                    }
                }
            }

            Log("Starting panorama capture");
            if (!captureEveryFrame && startSound != null && Camera.main != null)
            {
                audioSource.PlayOneShot(startSound);
            }

            List<ScreenFadeControl> fadeControls = new List<ScreenFadeControl>();
            foreach (Camera c in Camera.allCameras)
            {
                if (c.isActiveAndEnabled && c.targetTexture == null) // Is a camera visible to the player
                {
                    var fadeControl = c.gameObject.AddComponent<ScreenFadeControl>();
                    fadeControl.fadeMaterial = fadeMaterial;
                    fadeControls.Add(fadeControl);
                }
            }
            SetFadersEnabled(fadeControls, false);

            if (fadeDuringCapture && async)
                yield return StartCoroutine(FadeOut(fadeControls));

            // Make sure black is shown before we start - sometimes two frames are needed
            for (int i = 0; i < 2; i++)
                yield return new WaitForEndOfFrame();

            // Initialize compute buffers - do here instead of in Reinitialize() to work around error on Destroy()
            ComputeBuffer convertPanoramaResultBuffer = null;
            ComputeBuffer forceWaitResultConvertPanoramaStereoBuffer = null;
            if (usingGpuTransform)
            {
                if (captureStereoscopic)
                {
                    convertPanoramaResultBuffer =
                        new ComputeBuffer(/*count*/panoramaWidth * panoramaHeight * 2 + 1, /*stride*/4); // + 1 for sentinel
                    convertPanoramaStereoShader.SetBuffer(renderStereoIdx, "result", convertPanoramaResultBuffer);

                    forceWaitResultConvertPanoramaStereoBuffer = new ComputeBuffer(/*count*/1, /*stride*/4);
                    convertPanoramaStereoShader.SetBuffer(renderStereoIdx, "forceWaitResultBuffer", forceWaitResultConvertPanoramaStereoBuffer);
                }
                else
                {
                    int sliceHeight = (panoramaHeight + ResultBufferSlices - 1) / ResultBufferSlices;
                    convertPanoramaResultBuffer =
                        new ComputeBuffer(/*count*/panoramaWidth * sliceHeight + 1, /*stride*/4); // + 1 for sentinel
                    foreach (int kernelIdx in convertPanoramaKernelIdxs)
                        convertPanoramaShader.SetBuffer(kernelIdx, "result", convertPanoramaResultBuffer);
                }
            }
            int cameraPixelsBufferNumTextures = numCameras;
            overlapTextures = 0;
            int circlePointCircularBufferSize = 0;
            if (captureStereoscopic && usingGpuTransform)
            {
                overlapTextures = ssaaFactor == 1 ? 1 : 2;  // Overlap of 1 supports blending between circle points, overlap of 2 supports it even with SSAA at boundaries
                circlePointCircularBufferSize = 1 + overlapTextures;
                // 2 + for top/bottom, and divide by 2 because we're doing left/right and up/down separately
                cameraPixelsBufferNumTextures = Math.Min(numCameras, 2 + (CamerasPerCirclePoint / 2) * circlePointCircularBufferSize);
            }
            ComputeBuffer cameraPixelsBuffer = new ComputeBuffer(/*count*/cameraPixelsBufferNumTextures * cameraWidth * cameraHeight + 1, /*stride*/4);
            textureToBufferShader.SetBuffer(textureToBufferIdx, "result", cameraPixelsBuffer);

            // Set up sentinels to detect out of graphics memory
            textureToBufferShader.SetInt("sentinelIdx", cameraPixelsBuffer.count - 1);
            if (usingGpuTransform && !captureStereoscopic)
            {
                convertPanoramaShader.SetInt("cameraPixelsSentinelIdx", cameraPixelsBuffer.count - 1);
                convertPanoramaShader.SetInt("sentinelIdx", convertPanoramaResultBuffer.count - 1);
                foreach (int kernelIdx in convertPanoramaKernelIdxs)
                    convertPanoramaShader.SetBuffer(kernelIdx, "cameraPixels", cameraPixelsBuffer);
            }
            if (usingGpuTransform && captureStereoscopic)
            {
                convertPanoramaStereoShader.SetInt("cameraPixelsSentinelIdx", cameraPixelsBuffer.count - 1);
                convertPanoramaStereoShader.SetBuffer(renderStereoIdx, "cameraPixels", cameraPixelsBuffer);
            }

            ComputeBuffer forceWaitResultTextureToBufferBuffer = new ComputeBuffer(/*count*/1, /*stride*/4);
            textureToBufferShader.SetBuffer(textureToBufferIdx, "forceWaitResultBuffer", forceWaitResultTextureToBufferBuffer);

            float startTime = Time.realtimeSinceStartup;

            Quaternion headOrientation = Quaternion.identity;
#if OVR_SUPPORT
            if (OVRManager.display != null)
            {
                headOrientation = OVRManager.display.GetHeadPose(0.0).orientation;
            }
#endif
#if UNITY_5_1
            if (VRSettings.enabled && VRSettings.loadedDevice != VRDeviceType.None)
            {
                headOrientation = InputTracking.GetLocalRotation(0);
            }
#endif

            Log("Rendering camera views");
            foreach (Camera c in cameras)
                Log("Camera name: " + c.gameObject.name);

            var methodMap = new Dictionary<Camera, List<ImageEffectCopyCamera.InstanceMethodPair>>();
            foreach (Camera c in cameras)
                methodMap[c] = ImageEffectCopyCamera.GenerateMethodList(c);

            // Need to extract each cubemap into a Texture2D so we can read the pixels, but Unity bug
            // prevents this with antiAliasing: http://issuetracker.unity3d.com/issues/texture2d-dot-readpixels-fails-if-rendertexture-has-anti-aliasing-set
            // We copy the cubemap textures using a shader as a workaround.

            string suffix = "." + FormatToExtension(imageFormat);
            string filePath = "";
            // Save in separate thread to avoid hiccups
            string imagePath = saveImagePath;
            if (imagePath == null || imagePath == "")
            {
                imagePath = Application.dataPath + "/..";
            }

            convertPanoramaStereoShader.SetInt("circlePointCircularBufferSize", circlePointCircularBufferSize);
            int nextCirclePointCircularBufferStart = 0, nextCirclePointStart = 0, writeIdx = 0;
            int ilimit = usingGpuTransform ? numCameras + overlapTextures * CamerasPerCirclePoint : numCameras;
            int leftRightPhaseEnd = (ilimit - 2) / 2 + 2;
            int circlePointsRendered = 0;
            int saveCubemapImageNum = 0;

            Log("Changing quality level");
            int saveQualityLevel = QualitySettings.GetQualityLevel();
            bool qualitySettingWasChanged = false;
            string[] qualitySettingNames = QualitySettings.names;
            if (qualitySetting != qualitySettingNames[saveQualityLevel]) // Don't change if already set to it
            {
                for (int i = 0; i < qualitySettingNames.Length; i++)
                {
                    string name = qualitySettingNames[i];
                    if (name == qualitySetting)
                    {
                        QualitySettings.SetQualityLevel(i, /*applyExpensiveChanges*/false); // applyExpensiveChanges causes trouble
                        qualitySettingWasChanged = true;
                    }
                }
                if (qualitySetting != "" && !qualitySettingWasChanged)
                {
                    Debug.LogError("Quality setting specified for CapturePanorama is invalid, ignoring.", this);
                }
            }

            BeforeRenderPanorama();

            RenderTexture.active = null;
            for (int i = 0; i < ilimit; i++)
            {
                // Don't use RenderToCubemap - it causes problems with compositing multiple cameras, and requires
                // more temporary VRAM. Just render cube map manually.
                if (captureStereoscopic)
                {
                    if (i < 2)
                    {
                        // 0, 1 are top/bottom caps
                        camGos[1].transform.localPosition = Vector3.zero;
                        camGos[1].transform.localRotation = Quaternion.Euler((i == 0) ? 90.0f : -90.0f, 0.0f, 0.0f);
                    }
                    else
                    {
                        // Do all left/right textures first then all up/down textures
                        int iAdjusted, numInGroupBias;
                        if (i < leftRightPhaseEnd)
                        {
                            iAdjusted = i - 2;
                            numInGroupBias = 0;
                        }
                        else
                        {
                            iAdjusted = i - leftRightPhaseEnd;
                            numInGroupBias = 2;
                        }

                        int circlePointNum = (iAdjusted / (CamerasPerCirclePoint / 2)) % numCirclePoints;
                        int numInGroup = iAdjusted % (CamerasPerCirclePoint / 2) + numInGroupBias;

                        float circleAngle = 360.0f * circlePointNum / numCirclePoints;
                        camGos[1].transform.localPosition = Quaternion.Euler(0.0f, circleAngle, 0.0f) * Vector3.forward * circleRadius;

                        if (numInGroup < 2)
                            camGos[1].transform.localRotation = Quaternion.Euler(0.0f, circleAngle + (numInGroup == 0 ? -hFovAdjustDegrees : hFovAdjustDegrees), 0.0f);
                        else
                            camGos[1].transform.localRotation = Quaternion.Euler((numInGroup == 2 ? -vFovAdjustDegrees : vFovAdjustDegrees), circleAngle, 0.0f);

                        if (numInGroup == 1 || numInGroup == 3) circlePointsRendered++;
                    }
                }
                else
                {
                    switch ((CubemapFace)i)
                    {
                        case CubemapFace.PositiveX: camGos[1].transform.localRotation = Quaternion.Euler(  0.0f,  90.0f, 0.0f); break;
                        case CubemapFace.NegativeX: camGos[1].transform.localRotation = Quaternion.Euler(  0.0f, -90.0f, 0.0f); break;
                        case CubemapFace.PositiveY: camGos[1].transform.localRotation = Quaternion.Euler( 90.0f,   0.0f, 0.0f); break;
                        case CubemapFace.NegativeY: camGos[1].transform.localRotation = Quaternion.Euler(-90.0f,   0.0f, 0.0f); break;
                        case CubemapFace.PositiveZ: camGos[1].transform.localRotation = Quaternion.Euler(  0.0f,   0.0f, 0.0f); break;
                        case CubemapFace.NegativeZ: camGos[1].transform.localRotation = Quaternion.Euler(  0.0f, 180.0f, 0.0f); break;
                    }
                }

                foreach (Camera c in cameras)
                {
                    // To get the camera in the right eye position, migrate the camera transform to camGos[0]
                    camGos[2].transform.parent = null;
                    
                    cam.CopyFrom(c);

                    // TODO: Determine if we should reset matrices of the camera in case it's using custom transform matrices
                    
                    camGos[0].transform.localPosition = cam.transform.localPosition;
                    camGos[0].transform.localRotation = cam.transform.localRotation;
                    camGos[2].transform.parent = camGos[1].transform;
                    cam.transform.localPosition = Vector3.zero;
                    cam.transform.localRotation = Quaternion.identity;
                    copyCameraScript.enabled = methodMap[c].Count > 0;
                    copyCameraScript.onRenderImageMethods = methodMap[c];
                    cam.fieldOfView = vFov; // hFov inferred from aspect ratio of target

                    // Question: Should we adjust near clip in stereoscopic mode based on circleRadius?
                    // (avoids clipping that doesn't occur in normal camera view but might lead to unexpected bad effects)

                    camGos[0].transform.rotation *= Quaternion.Inverse(headOrientation);
                    if (useDefaultOrientation)
                        camGos[0].transform.rotation = Quaternion.identity;

                    cam.targetTexture = cubemapRenderTexture;
                    // Aspect ratio must be determined by size of render target. This is critical when Unity native VR is enabled.
                    cam.ResetAspect();

                    // Temporarily set original camera to same position/rotation/field of view as
                    // rendering camera during render. If any image effects examine camera
                    // orientation/FOV this will ensure they behave correctly.

                    Vector3 savePosition = c.transform.position;
                    Quaternion saveRotation = c.transform.rotation;
                    float saveFieldOfView = c.fieldOfView;
                    RenderTexture saveRenderTexture = c.targetTexture;

                    c.transform.position = cam.transform.position;
                    c.transform.rotation = cam.transform.rotation;
                    c.fieldOfView = cam.fieldOfView;

                    cam.Render();

                    c.transform.position = savePosition;
                    c.transform.rotation = saveRotation;
                    c.fieldOfView = saveFieldOfView;
                    c.targetTexture = saveRenderTexture;
                }
                
                // Read one pixel from texture to force render to complete before continuing
                RenderTexture.active = cubemapRenderTexture;
                forceWaitTexture.ReadPixels(new Rect(cameraWidth - 1, cameraHeight - 1, 1, 1), 0, 0);

                int forceWaitValue = 1000000 + i;
                textureToBufferShader.SetInt("forceWaitValue", forceWaitValue);
                textureToBufferShader.SetTexture(textureToBufferIdx, "source", cubemapRenderTexture);
                textureToBufferShader.SetInt("startIdx", writeIdx * cameraWidth * cameraHeight);
                textureToBufferShader.Dispatch(textureToBufferIdx, (cameraWidth + threadsX - 1) / threadsX, (cameraHeight + threadsY - 1) / threadsY, 1);

                uint[] forceWaitResult = new uint[1];
                forceWaitResultTextureToBufferBuffer.GetData(forceWaitResult);
                if (forceWaitResult[0] != forceWaitValue)
                    Debug.LogError("TextureToBufferShader: Unexpected forceWaitResult value " + forceWaitResult[0] + ", should be " + forceWaitValue);

                if (saveCubemap &&
                    ((i < 2) ||
                     (i >= 2 && i < 2 + numCirclePoints * 2) ||
                     (i >= leftRightPhaseEnd && i < leftRightPhaseEnd + numCirclePoints * 2)))
                {
                    // This is really slow - retrieving all cameraPixels data for just a portion of it. But this is mainly useful for debugging anyway.
                    cameraPixelsBuffer.GetData(cameraPixels);
                    if (cameraPixels[cameraPixelsBuffer.count - 1] != BufferSentinelValue)
                        ReportOutOfGraphicsMemory();

                    SaveCubemapImage(cameraPixels, filenameBase, suffix, imagePath, saveCubemapImageNum, writeIdx);
                    saveCubemapImageNum++;
                }

                writeIdx++;
                if (writeIdx >= cameraPixelsBufferNumTextures) writeIdx = 2; // Leave top/bottom in indexes 0/1

                // For stereoscopic GPU transform, interleave capture and rendering to decrease VRAM consumption
                if (captureStereoscopic && usingGpuTransform &&
                    ((i - 2) + 1) % (CamerasPerCirclePoint / 2) == 0 &&
                    (circlePointsRendered - nextCirclePointStart >= circlePointCircularBufferSize || i + 1 == 2 + (ilimit - 2) / 2 || i + 1 == ilimit))
                {
                    forceWaitValue = 2000000 + i;
                    convertPanoramaStereoShader.SetInt("forceWaitValue", forceWaitValue);
                    convertPanoramaStereoShader.SetInt("leftRightPass", i < leftRightPhaseEnd ? 1 : 0);
                    convertPanoramaStereoShader.SetInt("circlePointStart", nextCirclePointStart);
                    convertPanoramaStereoShader.SetInt("circlePointEnd", cameraPixelsBufferNumTextures < numCameras ? circlePointsRendered : circlePointsRendered + 1);
                    convertPanoramaStereoShader.SetInt("circlePointCircularBufferStart", nextCirclePointCircularBufferStart);
                    convertPanoramaStereoShader.Dispatch(renderStereoIdx, (panoramaWidth + threadsX - 1) / threadsX, (panoramaHeight + threadsY - 1) / threadsY, 2);

                    forceWaitResultConvertPanoramaStereoBuffer.GetData(forceWaitResult);
                    if (forceWaitResult[0] != forceWaitValue)
                        Debug.LogError("ConvertPanoramaStereoShader: Unexpected forceWaitResult value " + forceWaitResult[0] + ", should be " + forceWaitValue);

                    if (i + 1 == leftRightPhaseEnd)
                    {
                        nextCirclePointCircularBufferStart = (nextCirclePointCircularBufferStart + circlePointCircularBufferSize) % circlePointCircularBufferSize;
                        nextCirclePointStart = 0;
                        circlePointsRendered = 0;
                    }
                    else
                    {
                        nextCirclePointStart = circlePointsRendered - overlapTextures;
                        nextCirclePointCircularBufferStart = (nextCirclePointCircularBufferStart + circlePointCircularBufferSize - overlapTextures) % circlePointCircularBufferSize;
                    }
                }

                RenderTexture.active = null;
            }

            AfterRenderPanorama();

            Log("Resetting quality level");
            if (qualitySettingWasChanged)
                QualitySettings.SetQualityLevel(saveQualityLevel, /*applyExpensiveChanges*/false);

            // If we need to access the cubemap pixels on the CPU, retrieve them now
            if (saveCubemap || !usingGpuTransform)
            {
                cameraPixelsBuffer.GetData(cameraPixels);
                if (cameraPixels[cameraPixelsBuffer.count - 1] != BufferSentinelValue)
                    ReportOutOfGraphicsMemory();
            }

            RenderTexture.active = null;

            if (saveCubemap &&
                !(captureStereoscopic && usingGpuTransform)) // In this mode images are saved during capture
            {
                // Save cubemap while still faded, as fast as possible - should be pretty quick
                for (int i = 0; i < numCameras; i++)
                {
                    int bufferIdx = i;
                    SaveCubemapImage(cameraPixels, filenameBase, suffix, imagePath, i, bufferIdx);
                }
            }

            // If this is not here, the fade-in will drop frames.
            for (int i = 0; i < 2; i++)
                yield return new WaitForEndOfFrame();

            if (async && !usingGpuTransform && fadeDuringCapture)
                yield return StartCoroutine(FadeIn(fadeControls));

            filePath = imagePath + "/" + filenameBase + suffix;

            bool producedImageSuccess = false;

            {
                // Write pixels directly to .NET Bitmap for saving out
                // Based on https://msdn.microsoft.com/en-us/library/5ey6h79d%28v=vs.110%29.aspx
                Bitmap bitmap = new Bitmap(panoramaWidth, panoramaHeight * (captureStereoscopic ? 2 : 1), PixelFormat.Format32bppArgb);
                var bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
                IntPtr ptr = bmpData.Scan0;
                byte[] pixelValues = new byte[Math.Abs(bmpData.Stride) * bitmap.Height];

                // Convert to equirectangular projection - use compute shader for better performance if supported by platform

                if (async)
                    yield return StartCoroutine(CubemapToEquirectangular(cameraPixelsBuffer, cameraPixels, convertPanoramaResultBuffer, cameraWidth, cameraHeight, pixelValues, bmpData.Stride, panoramaWidth, panoramaHeight, ssaaFactor, async));
                else
                {
                    var enumerator = CubemapToEquirectangular(cameraPixelsBuffer, cameraPixels, convertPanoramaResultBuffer, cameraWidth, cameraHeight, pixelValues, bmpData.Stride, panoramaWidth, panoramaHeight, ssaaFactor, async);
                    while (enumerator.MoveNext()) { }
                }

                producedImageSuccess = (pixelValues[3] == 255);

                yield return null;
                System.Runtime.InteropServices.Marshal.Copy(pixelValues, 0, ptr, pixelValues.Length);
                bitmap.UnlockBits(bmpData);
                yield return null;

                Log("Time to take panorama screenshot: " + (Time.realtimeSinceStartup - startTime) + " sec");

                if (producedImageSuccess)
                {
                    var thread = new Thread(() =>
                    {
                        Log("Saving equirectangular image");
                        // TODO: Use better image processing library to get decent JPEG quality out.
                        bitmap.Save(filePath, FormatToDrawingFormat(imageFormat));
                    });
                    thread.Start();
                    while (thread.ThreadState == ThreadState.Running)
                        if (async)
                            yield return null;
                        else
                            Thread.Sleep(0);
                }

                bitmap.Dispose();
            }

            // Release ComputeBuffers - all done with these
            foreach (var buffer in new ComputeBuffer[] {
                convertPanoramaResultBuffer,
                cameraPixelsBuffer,
                forceWaitResultConvertPanoramaStereoBuffer,
                forceWaitResultTextureToBufferBuffer })
                if (buffer != null)
                    buffer.Release();
            convertPanoramaResultBuffer = cameraPixelsBuffer = null;

            if (async && usingGpuTransform && fadeDuringCapture)
                yield return StartCoroutine(FadeIn(fadeControls));

            foreach (ScreenFadeControl fadeControl in fadeControls)
            {
                Destroy(fadeControl);
            }
            fadeControls.Clear();

            if (producedImageSuccess && uploadImages && !captureEveryFrame)
            {
                Log("Uploading image");
                imageFileBytes = File.ReadAllBytes(filePath);
                string mimeType = FormatMimeType(imageFormat);
                if (async)
                    yield return StartCoroutine(UploadImage(imageFileBytes, filenameBase + suffix, mimeType, async));
                else
                {
                    var enumerator = UploadImage(imageFileBytes, filenameBase + suffix, mimeType, async);
                    while (enumerator.MoveNext()) { }
                }
            }
            else
            {
                if (!producedImageSuccess)
                {
                    if (failSound != null && Camera.main != null)
                        audioSource.PlayOneShot(failSound);
                }
                else if (!captureEveryFrame && doneSound != null && Camera.main != null)
                {
                    audioSource.PlayOneShot(doneSound);
                }
                Capturing = false;
            }
        }
コード例 #29
0
 public override void Render(MapGraphics g)
 {
     base.Render(g);
     if (!this.IsEmpty)
     {
         RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
         bool       flag = false;
         try
         {
             if (this.Colors.Count == 0 && this.Common != null && this.Common.MapCore.IsDesignMode())
             {
                 this.PopulateDummyData();
                 flag = true;
             }
             int             num              = (this.LabelAlignment != LabelAlignment.Alternate) ? 1 : 2;
             SwatchLabelType swatchLabelType  = this.GetLabelType();
             SizeF           colorBoxSize     = default(SizeF);
             SizeF           labelBoxSize     = default(SizeF);
             SizeF           firstCaptionSize = default(SizeF);
             SizeF           lastCaptionSize  = default(SizeF);
             this.CalculateFontDependentData(g, absoluteRectangle.Size);
             absoluteRectangle.Inflate((float)(-this.PanelPadding), (float)(-this.PanelPadding));
             if (!(absoluteRectangle.Width < 1.0) && !(absoluteRectangle.Height < 1.0))
             {
                 int[] colorsRef = this.GetColorsRef(swatchLabelType);
                 float num2      = 0f;
                 if (this.LabelInterval > 0 && this.ShowEndLabels)
                 {
                     firstCaptionSize        = g.MeasureString(this.GetLabelCaption(0, true, swatchLabelType), this.Font, absoluteRectangle.Size, StringFormat.GenericTypographic);
                     firstCaptionSize.Width += this.TrimmingProtector;
                     lastCaptionSize         = g.MeasureString(this.GetLabelCaption(this.Colors.Count - 1, false, swatchLabelType), this.Font, absoluteRectangle.Size, StringFormat.GenericTypographic);
                     lastCaptionSize.Width  += this.TrimmingProtector;
                     num2 = Math.Max(firstCaptionSize.Width, lastCaptionSize.Width);
                 }
                 bool       flag2           = !string.IsNullOrEmpty(this.Title);
                 RectangleF layoutRectangle = absoluteRectangle;
                 if (flag2)
                 {
                     float height = absoluteRectangle.Height;
                     SizeF sizeF  = g.MeasureString(this.Title, this.TitleFont, layoutRectangle.Size, StringFormat.GenericTypographic);
                     float num4   = layoutRectangle.Height = Math.Min(height, sizeF.Height + (float)this.TitleSeparatorSize);
                     absoluteRectangle.Y      += num4;
                     absoluteRectangle.Height -= num4;
                     this.titlePosition        = layoutRectangle;
                 }
                 RectangleF colorBarBounds = this.CalculateMaxColorBarBounds(g, absoluteRectangle, num2, colorsRef.Length, swatchLabelType);
                 float      num5           = 0f;
                 float      num6           = 0f;
                 if (this.LabelInterval > 0)
                 {
                     num5 = this.GetLabelMaxSize(g, absoluteRectangle.Size, swatchLabelType).Height;
                     num6 = (float)(this.TickMarkLength + this.TickMarkLabelGapSize);
                 }
                 float val = Math.Max(3f, (float)((absoluteRectangle.Height - num6) / 5.0));
                 colorBoxSize.Height   = Math.Max(val, absoluteRectangle.Height - (float)num * (num6 + num5));
                 colorBoxSize.Width    = colorBarBounds.Width / (float)colorsRef.Length;
                 colorBarBounds.Height = colorBoxSize.Height;
                 labelBoxSize.Height   = Math.Max(0f, absoluteRectangle.Height - colorBoxSize.Height) / (float)num - num6;
                 labelBoxSize.Width    = colorBoxSize.Width * (float)this.LabelInterval * (float)num;
                 if (this.LabelAlignment == LabelAlignment.Top || this.LabelAlignment == LabelAlignment.Alternate)
                 {
                     colorBarBounds.Y += labelBoxSize.Height + num6;
                 }
                 AntiAliasing antiAliasing = g.AntiAliasing;
                 try
                 {
                     g.AntiAliasing = AntiAliasing.None;
                     GraphicsPath graphicsPath  = default(GraphicsPath);
                     GraphicsPath graphicsPath2 = default(GraphicsPath);
                     this.CreateColorBarPath(absoluteRectangle, colorBarBounds, colorsRef, swatchLabelType, out graphicsPath, out graphicsPath2);
                     GraphicsPathIterator graphicsPathIterator = new GraphicsPathIterator(graphicsPath2);
                     GraphicsPath         graphicsPath3        = new GraphicsPath();
                     Pen pen = new Pen(this.OutlineColor);
                     try
                     {
                         int[] array = colorsRef;
                         foreach (int colorIndex in array)
                         {
                             graphicsPath3.Reset();
                             bool flag3 = default(bool);
                             graphicsPathIterator.NextSubpath(graphicsPath3, out flag3);
                             if (flag3)
                             {
                                 using (Brush brush = this.CreateColorBoxBrush(g, graphicsPath3.GetBounds(), colorIndex))
                                 {
                                     g.FillPath(brush, graphicsPath3);
                                 }
                             }
                         }
                         g.DrawPath(pen, graphicsPath);
                     }
                     finally
                     {
                         graphicsPath.Dispose();
                         graphicsPath2.Dispose();
                         graphicsPathIterator.Dispose();
                         graphicsPath3.Dispose();
                         pen.Dispose();
                     }
                 }
                 finally
                 {
                     g.AntiAliasing = antiAliasing;
                 }
                 if (flag2)
                 {
                     using (Brush brush2 = new SolidBrush(this.TitleColor))
                     {
                         using (StringFormat stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone())
                         {
                             stringFormat.Alignment     = this.TitleAlignment;
                             stringFormat.LineAlignment = StringAlignment.Near;
                             stringFormat.Trimming      = StringTrimming.EllipsisCharacter;
                             stringFormat.FormatFlags   = StringFormatFlags.NoWrap;
                             g.DrawString(this.Title, this.TitleFont, brush2, layoutRectangle, stringFormat);
                         }
                     }
                 }
                 if (this.Colors.Count != 0 && this.LabelInterval != 0)
                 {
                     using (StringFormat stringFormat2 = (StringFormat)StringFormat.GenericTypographic.Clone())
                     {
                         stringFormat2.Alignment     = StringAlignment.Center;
                         stringFormat2.LineAlignment = StringAlignment.Near;
                         stringFormat2.Trimming      = StringTrimming.EllipsisCharacter;
                         stringFormat2.FormatFlags   = StringFormatFlags.NoWrap;
                         using (Brush brush3 = new SolidBrush(this.LabelColor))
                         {
                             bool flag4 = this.LabelAlignment != LabelAlignment.Top;
                             if (swatchLabelType == SwatchLabelType.ShowMiddleValue)
                             {
                                 for (int j = 0; j < colorsRef.Length; j++)
                                 {
                                     if (this.MustPrintLabel(colorsRef, j, true, swatchLabelType))
                                     {
                                         StringAlignment alignment    = default(StringAlignment);
                                         RectangleF      labelBounds  = this.GetLabelBounds(j, colorsRef, absoluteRectangle, colorBarBounds, labelBoxSize, colorBoxSize, num2, true, swatchLabelType, flag4, firstCaptionSize, lastCaptionSize, out alignment);
                                         string          labelCaption = this.GetLabelCaption(j, true, swatchLabelType);
                                         if (labelBounds.Width > 1.0 && labelBounds.Height > 1.0)
                                         {
                                             if (flag4)
                                             {
                                                 labelBounds.Offset(0f, 1f);
                                             }
                                             stringFormat2.Alignment = alignment;
                                             g.DrawString(labelCaption, this.Font, brush3, labelBounds, stringFormat2);
                                         }
                                         flag4 = ((this.LabelAlignment == LabelAlignment.Alternate) ? (!flag4) : flag4);
                                     }
                                 }
                             }
                             else
                             {
                                 for (int k = 0; k < colorsRef.Length; k++)
                                 {
                                     RectangleF labelBounds2;
                                     if (this.MustPrintLabel(colorsRef, k, true, swatchLabelType))
                                     {
                                         StringAlignment alignment2 = default(StringAlignment);
                                         labelBounds2 = this.GetLabelBounds(colorsRef[k], colorsRef, absoluteRectangle, colorBarBounds, labelBoxSize, colorBoxSize, num2, true, swatchLabelType, flag4, firstCaptionSize, lastCaptionSize, out alignment2);
                                         string labelCaption2 = this.GetLabelCaption(colorsRef[k], true, swatchLabelType);
                                         if (labelBounds2.Width > 1.0 && labelBounds2.Height > 1.0)
                                         {
                                             if (flag4)
                                             {
                                                 labelBounds2.Offset(0f, 1f);
                                             }
                                             stringFormat2.Alignment = alignment2;
                                             g.DrawString(labelCaption2, this.Font, brush3, labelBounds2, stringFormat2);
                                         }
                                         flag4 = ((this.LabelAlignment == LabelAlignment.Alternate) ? (!flag4) : flag4);
                                     }
                                     if (this.MustPrintLabel(colorsRef, k, false, swatchLabelType))
                                     {
                                         StringAlignment alignment3 = default(StringAlignment);
                                         labelBounds2 = this.GetLabelBounds(colorsRef[k], colorsRef, absoluteRectangle, colorBarBounds, labelBoxSize, colorBoxSize, num2, false, swatchLabelType, flag4, firstCaptionSize, lastCaptionSize, out alignment3);
                                         string labelCaption2 = this.GetLabelCaption(colorsRef[k], false, swatchLabelType);
                                         if (labelBounds2.Width > 1.0 && labelBounds2.Height > 1.0)
                                         {
                                             if (flag4)
                                             {
                                                 labelBounds2.Offset(0f, 1f);
                                             }
                                             stringFormat2.Alignment = alignment3;
                                             g.DrawString(labelCaption2, this.Font, brush3, labelBounds2, stringFormat2);
                                         }
                                         flag4 = ((this.LabelAlignment == LabelAlignment.Alternate) ? (!flag4) : flag4);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         finally
         {
             if (flag)
             {
                 this.Colors.Clear();
             }
         }
     }
 }
コード例 #30
0
 void IRenderable.RenderDynamicElements(GaugeGraphics g)
 {
     if (this.Visible)
     {
         g.StartHotRegion(this);
         GraphicsPath graphicsPath  = null;
         GraphicsPath graphicsPath2 = null;
         Brush        brush         = null;
         Brush        brush2        = null;
         Brush        brush3        = null;
         Pen          pen           = null;
         try
         {
             graphicsPath  = this.GetBackPath(g);
             graphicsPath2 = this.GetTextPath(g);
             if (graphicsPath != null)
             {
                 if (this.BackShadowOffset != 0)
                 {
                     using (Matrix matrix = new Matrix())
                     {
                         brush3 = g.GetShadowBrush();
                         matrix.Translate((float)this.BackShadowOffset, (float)this.BackShadowOffset, MatrixOrder.Append);
                         graphicsPath.Transform(matrix);
                         g.FillPath(brush3, graphicsPath);
                         matrix.Reset();
                         matrix.Translate((float)(-this.BackShadowOffset), (float)(-this.BackShadowOffset), MatrixOrder.Append);
                         graphicsPath.Transform(matrix);
                     }
                 }
                 brush2 = this.GetBackBrush(g);
                 g.FillPath(brush2, graphicsPath);
                 pen = this.GetPen(g);
                 if (pen != null)
                 {
                     g.DrawPath(pen, graphicsPath);
                 }
                 this.Common.GaugeCore.HotRegionList.SetHotRegion(this, Point.Empty, (GraphicsPath)graphicsPath.Clone());
             }
             if (graphicsPath2 != null)
             {
                 if (this.TextShadowOffset != 0)
                 {
                     using (Matrix matrix2 = new Matrix())
                     {
                         brush3 = g.GetShadowBrush();
                         matrix2.Translate((float)this.TextShadowOffset, (float)this.TextShadowOffset, MatrixOrder.Append);
                         graphicsPath2.Transform(matrix2);
                         g.FillPath(brush3, graphicsPath2);
                         matrix2.Reset();
                         matrix2.Translate((float)(-this.TextShadowOffset), (float)(-this.TextShadowOffset), MatrixOrder.Append);
                         graphicsPath2.Transform(matrix2);
                     }
                 }
                 brush = new SolidBrush(this.TextColor);
                 AntiAliasing antiAliasing  = this.Common.GaugeContainer.AntiAliasing;
                 AntiAliasing antiAliasing2 = g.AntiAliasing;
                 if (this.Common.GaugeContainer.AntiAliasing == AntiAliasing.Text)
                 {
                     antiAliasing = AntiAliasing.Graphics;
                 }
                 else if (this.Common.GaugeContainer.AntiAliasing == AntiAliasing.Graphics)
                 {
                     antiAliasing = AntiAliasing.None;
                 }
                 g.AntiAliasing = antiAliasing;
                 g.FillPath(brush, graphicsPath2);
                 g.AntiAliasing = antiAliasing2;
             }
         }
         finally
         {
             if (graphicsPath != null)
             {
                 graphicsPath.Dispose();
             }
             if (graphicsPath2 != null)
             {
                 graphicsPath2.Dispose();
             }
             if (brush3 != null)
             {
                 brush3.Dispose();
             }
             if (brush2 != null)
             {
                 brush2.Dispose();
             }
             if (brush != null)
             {
                 brush.Dispose();
             }
             if (pen != null)
             {
                 pen.Dispose();
             }
             g.EndHotRegion();
         }
     }
 }
コード例 #31
0
        internal override void Render(MapGraphics g)
        {
            base.Render(g);
            if (IsEmpty)
            {
                return;
            }
            RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
            bool       flag = false;

            try
            {
                if (Colors.Count == 0 && Common != null && Common.MapCore.IsDesignMode())
                {
                    PopulateDummyData();
                    flag = true;
                }
                int             num              = (LabelAlignment != LabelAlignment.Alternate) ? 1 : 2;
                SwatchLabelType swatchLabelType  = GetLabelType();
                SizeF           colorBoxSize     = default(SizeF);
                SizeF           labelBoxSize     = default(SizeF);
                SizeF           firstCaptionSize = default(SizeF);
                SizeF           lastCaptionSize  = default(SizeF);
                CalculateFontDependentData(g, absoluteRectangle.Size);
                absoluteRectangle.Inflate(-PanelPadding, -PanelPadding);
                if (absoluteRectangle.Width < 1f || absoluteRectangle.Height < 1f)
                {
                    return;
                }
                int[] colorsRef = GetColorsRef(swatchLabelType);
                float num2      = 0f;
                if (LabelInterval > 0 && ShowEndLabels)
                {
                    firstCaptionSize        = g.MeasureString(GetLabelCaption(0, getFromValue: true, swatchLabelType), Font, absoluteRectangle.Size, StringFormat.GenericTypographic);
                    firstCaptionSize.Width += TrimmingProtector;
                    lastCaptionSize         = g.MeasureString(GetLabelCaption(Colors.Count - 1, getFromValue: false, swatchLabelType), Font, absoluteRectangle.Size, StringFormat.GenericTypographic);
                    lastCaptionSize.Width  += TrimmingProtector;
                    num2 = Math.Max(firstCaptionSize.Width, lastCaptionSize.Width);
                }
                bool       flag2           = !string.IsNullOrEmpty(Title);
                RectangleF layoutRectangle = absoluteRectangle;
                if (flag2)
                {
                    float num4 = layoutRectangle.Height = Math.Min(absoluteRectangle.Height, g.MeasureString(Title, TitleFont, layoutRectangle.Size, StringFormat.GenericTypographic).Height + (float)TitleSeparatorSize);
                    absoluteRectangle.Y      += num4;
                    absoluteRectangle.Height -= num4;
                    titlePosition             = layoutRectangle;
                }
                RectangleF colorBarBounds = CalculateMaxColorBarBounds(g, absoluteRectangle, num2, colorsRef.Length, swatchLabelType);
                float      num5           = 0f;
                float      num6           = 0f;
                if (LabelInterval > 0)
                {
                    num5 = GetLabelMaxSize(g, absoluteRectangle.Size, swatchLabelType).Height;
                    num6 = TickMarkLength + TickMarkLabelGapSize;
                }
                float val = Math.Max(3f, (absoluteRectangle.Height - num6) / 5f);
                colorBoxSize.Height   = Math.Max(val, absoluteRectangle.Height - (float)num * (num6 + num5));
                colorBoxSize.Width    = colorBarBounds.Width / (float)colorsRef.Length;
                colorBarBounds.Height = colorBoxSize.Height;
                labelBoxSize.Height   = Math.Max(0f, absoluteRectangle.Height - colorBoxSize.Height) / (float)num - num6;
                labelBoxSize.Width    = colorBoxSize.Width * (float)LabelInterval * (float)num;
                if (LabelAlignment == LabelAlignment.Top || LabelAlignment == LabelAlignment.Alternate)
                {
                    colorBarBounds.Y += labelBoxSize.Height + num6;
                }
                AntiAliasing antiAliasing = g.AntiAliasing;
                try
                {
                    g.AntiAliasing = AntiAliasing.None;
                    CreateColorBarPath(absoluteRectangle, colorBarBounds, colorsRef, swatchLabelType, out GraphicsPath outlinePath, out GraphicsPath fillPath);
                    GraphicsPathIterator graphicsPathIterator = new GraphicsPathIterator(fillPath);
                    GraphicsPath         graphicsPath         = new GraphicsPath();
                    Pen pen = new Pen(OutlineColor);
                    try
                    {
                        int[] array = colorsRef;
                        foreach (int colorIndex in array)
                        {
                            graphicsPath.Reset();
                            graphicsPathIterator.NextSubpath(graphicsPath, out bool isClosed);
                            if (isClosed)
                            {
                                using (Brush brush = CreateColorBoxBrush(g, graphicsPath.GetBounds(), colorIndex))
                                {
                                    g.FillPath(brush, graphicsPath);
                                }
                            }
                        }
                        g.DrawPath(pen, outlinePath);
                    }
                    finally
                    {
                        outlinePath.Dispose();
                        fillPath.Dispose();
                        graphicsPathIterator.Dispose();
                        graphicsPath.Dispose();
                        pen.Dispose();
                    }
                }
                finally
                {
                    g.AntiAliasing = antiAliasing;
                }
                if (flag2)
                {
                    using (Brush brush2 = new SolidBrush(TitleColor))
                    {
                        using (StringFormat stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone())
                        {
                            stringFormat.Alignment     = TitleAlignment;
                            stringFormat.LineAlignment = StringAlignment.Near;
                            stringFormat.Trimming      = StringTrimming.EllipsisCharacter;
                            stringFormat.FormatFlags   = StringFormatFlags.NoWrap;
                            g.DrawString(Title, TitleFont, brush2, layoutRectangle, stringFormat);
                        }
                    }
                }
                if (Colors.Count == 0 || LabelInterval == 0)
                {
                    return;
                }
                using (StringFormat stringFormat2 = (StringFormat)StringFormat.GenericTypographic.Clone())
                {
                    stringFormat2.Alignment     = StringAlignment.Center;
                    stringFormat2.LineAlignment = StringAlignment.Near;
                    stringFormat2.Trimming      = StringTrimming.EllipsisCharacter;
                    stringFormat2.FormatFlags   = StringFormatFlags.NoWrap;
                    using (Brush brush3 = new SolidBrush(LabelColor))
                    {
                        bool flag3 = LabelAlignment != LabelAlignment.Top;
                        if (swatchLabelType == SwatchLabelType.ShowMiddleValue)
                        {
                            for (int j = 0; j < colorsRef.Length; j++)
                            {
                                if (!MustPrintLabel(colorsRef, j, isFromValue: true, swatchLabelType))
                                {
                                    continue;
                                }
                                StringAlignment horizontalAlignemnt;
                                RectangleF      labelBounds  = GetLabelBounds(j, colorsRef, absoluteRectangle, colorBarBounds, labelBoxSize, colorBoxSize, num2, getFromValue: true, swatchLabelType, flag3, firstCaptionSize, lastCaptionSize, out horizontalAlignemnt);
                                string          labelCaption = GetLabelCaption(j, getFromValue: true, swatchLabelType);
                                if (labelBounds.Width > 1f && labelBounds.Height > 1f)
                                {
                                    if (flag3)
                                    {
                                        labelBounds.Offset(0f, 1f);
                                    }
                                    stringFormat2.Alignment = horizontalAlignemnt;
                                    g.DrawString(labelCaption, Font, brush3, labelBounds, stringFormat2);
                                }
                                flag3 = ((LabelAlignment == LabelAlignment.Alternate) ? (!flag3) : flag3);
                            }
                            return;
                        }
                        for (int k = 0; k < colorsRef.Length; k++)
                        {
                            RectangleF labelBounds2;
                            string     labelCaption2;
                            if (MustPrintLabel(colorsRef, k, isFromValue: true, swatchLabelType))
                            {
                                labelBounds2  = GetLabelBounds(colorsRef[k], colorsRef, absoluteRectangle, colorBarBounds, labelBoxSize, colorBoxSize, num2, getFromValue: true, swatchLabelType, flag3, firstCaptionSize, lastCaptionSize, out StringAlignment horizontalAlignemnt2);
                                labelCaption2 = GetLabelCaption(colorsRef[k], getFromValue: true, swatchLabelType);
                                if (labelBounds2.Width > 1f && labelBounds2.Height > 1f)
                                {
                                    if (flag3)
                                    {
                                        labelBounds2.Offset(0f, 1f);
                                    }
                                    stringFormat2.Alignment = horizontalAlignemnt2;
                                    g.DrawString(labelCaption2, Font, brush3, labelBounds2, stringFormat2);
                                }
                                flag3 = ((LabelAlignment == LabelAlignment.Alternate) ? (!flag3) : flag3);
                            }
                            if (!MustPrintLabel(colorsRef, k, isFromValue: false, swatchLabelType))
                            {
                                continue;
                            }
                            labelBounds2  = GetLabelBounds(colorsRef[k], colorsRef, absoluteRectangle, colorBarBounds, labelBoxSize, colorBoxSize, num2, getFromValue: false, swatchLabelType, flag3, firstCaptionSize, lastCaptionSize, out StringAlignment horizontalAlignemnt3);
                            labelCaption2 = GetLabelCaption(colorsRef[k], getFromValue: false, swatchLabelType);
                            if (labelBounds2.Width > 1f && labelBounds2.Height > 1f)
                            {
                                if (flag3)
                                {
                                    labelBounds2.Offset(0f, 1f);
                                }
                                stringFormat2.Alignment = horizontalAlignemnt3;
                                g.DrawString(labelCaption2, Font, brush3, labelBounds2, stringFormat2);
                            }
                            flag3 = ((LabelAlignment == LabelAlignment.Alternate) ? (!flag3) : flag3);
                        }
                    }
                }
            }
            finally
            {
                if (flag)
                {
                    Colors.Clear();
                }
            }
        }