Пример #1
0
        public static SimpleMaterial CreateMaterial(TwoDimensionDrawContext drawContext, BrushWidget widget)
        {
            SimpleMaterial simpleMaterial = drawContext.CreateSimpleMaterial();
            Brush          brush          = widget.Brush;
            StyleLayer     styleLayer;

            if (brush == null)
            {
                styleLayer = null;
            }
            else
            {
                Dictionary <string, StyleLayer> .ValueCollection layers = brush.GetStyleOrDefault(widget.CurrentState).Layers;
                styleLayer = layers?.FirstOrDefault();
            }
            simpleMaterial.OverlayEnabled         = false;
            simpleMaterial.CircularMaskingEnabled = false;
            simpleMaterial.AlphaFactor            = (styleLayer?.AlphaFactor ?? 1f) * widget.Brush.GlobalAlphaFactor * widget.Context.ContextAlpha;
            simpleMaterial.ColorFactor            = (styleLayer?.ColorFactor ?? 1f) * widget.Brush.GlobalColorFactor;
            simpleMaterial.HueFactor        = styleLayer?.HueFactor ?? 0.0f;
            simpleMaterial.SaturationFactor = styleLayer?.SaturationFactor ?? 0.0f;
            simpleMaterial.ValueFactor      = styleLayer?.ValueFactor ?? 0.0f;
            simpleMaterial.Color            = (styleLayer?.Color ?? Color.White) * widget.Brush.GlobalColor;
            return(simpleMaterial);
        }
Пример #2
0
        protected override void OnRender(TwoDimensionContext twoDimensionContext, TwoDimensionDrawContext drawContext)
        {
            base.OnRender(twoDimensionContext, drawContext);


            SimpleMaterial simpleMaterial = drawContext.CreateSimpleMaterial();
            Brush          brush          = Brush;
            StyleLayer     styleLayer;

            if (brush == null)
            {
                styleLayer = null;
            }
            else
            {
                Dictionary <string, StyleLayer> .ValueCollection layers = brush.GetStyleOrDefault(CurrentState).Layers;
                styleLayer = layers?.FirstOrDefault();
            }
            simpleMaterial.OverlayEnabled         = false;
            simpleMaterial.CircularMaskingEnabled = false;
            simpleMaterial.Texture          = Texture;
            simpleMaterial.AlphaFactor      = (styleLayer?.AlphaFactor ?? 1f) * Brush.GlobalAlphaFactor * Context.ContextAlpha;
            simpleMaterial.ColorFactor      = (styleLayer?.ColorFactor ?? 1f) * Brush.GlobalColorFactor;
            simpleMaterial.HueFactor        = styleLayer?.HueFactor ?? 0.0f;
            simpleMaterial.SaturationFactor = styleLayer?.SaturationFactor ?? 0.0f;
            simpleMaterial.ValueFactor      = styleLayer?.ValueFactor ?? 0.0f;
            simpleMaterial.Color            = (styleLayer?.Color ?? Color.White) * Brush.GlobalColor;
            if (CachedMesh == null || Math.Abs(CachedMesh.Width - Size.X) > 0.01f && Math.Abs(CachedMesh.Height - Size.Y) > 0.01f)
            {
                UpdateDrawObject2D();
            }
            if (drawContext.CircularMaskEnabled)
            {
                simpleMaterial.CircularMaskingEnabled         = true;
                simpleMaterial.CircularMaskingCenter          = drawContext.CircularMaskCenter;
                simpleMaterial.CircularMaskingRadius          = drawContext.CircularMaskRadius;
                simpleMaterial.CircularMaskingSmoothingRadius = drawContext.CircularMaskSmoothingRadius;
            }
            //drawContext.Draw(GlobalPosition.X, GlobalPosition.Y, simpleMaterial, CachedMesh, Size.X, Size.Y);
            twoDimensionContext.Draw(GlobalPosition.X, GlobalPosition.Y, simpleMaterial, CachedMesh, Layer);
        }