コード例 #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);
        }
        private SimpleMaterial CreateMaterial(TwoDimensionDrawContext drawContext, AgentMarkerType type)
        {
            var types    = type.GetColorAndTextureType();
            var material = Widgets.Utility.CreateMaterial(drawContext, this);

            material.Texture = types.TextureType.GetTexture();
            material.Color  *= types.ColorType.GetColor();
            return(material);
        }
        protected override void OnRender(TwoDimensionContext twoDimensionContext, TwoDimensionDrawContext drawContext)
        {
            base.OnRender(twoDimensionContext, drawContext);

            var size = _agentMarkerSize;

            UpdateDrawObject2D(size, size);
            var materials      = new SimpleMaterial[(int)AgentMarkerType.Count];
            var globalPosition = Widgets.Utility.GetGlobalPosition(this);

            for (int i = 0; i < AgentMakers.CountOfAgentMarkers; ++i)
            {
                var agentMaker = AgentMakers.AgentMarkers[i];
                var type       = agentMaker.AgentMarkerType;
                twoDimensionContext.Draw(globalPosition.x + agentMaker.PositionInWidget.x * ScaledSuggestedWidth / Math.Max(SuggestedWidth, 1) - size * 0.5f, globalPosition.y + agentMaker.PositionInWidget.y * ScaledSuggestedHeight / Math.Max(SuggestedHeight, 1) - size * 0.5f, materials[(int)type] ??= CreateMaterial(drawContext, type), _cachedMesh, type.GetLayer());
            }
        }
コード例 #4
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);
        }