Example #1
0
        public static Color GetOpaqueRGBMaxColorForIntents(IIntentStates states)
        {
            byte R = 0;
            byte G = 0;
            byte B = 0;

            foreach (IIntentState intentState in states.AsList())
            {
                if (intentState is IIntentState <LightingValue> state)
                {
                    var lv = state.GetValue();
                    if (lv.Intensity > 0)
                    {
                        Color intentColor = lv.FullColor;
                        R = Math.Max(R, intentColor.R);
                        G = Math.Max(G, intentColor.G);
                        B = Math.Max(B, intentColor.B);
                    }
                }
                else if (intentState is IIntentState <RGBValue> rgbState)
                {
                    var rv = rgbState.GetValue();
                    R = Math.Max(R, rv.R);
                    G = Math.Max(G, rv.G);
                    B = Math.Max(B, rv.B);
                }
            }

            return(Color.FromArgb(R, G, B));
        }
        /// <summary>
        /// Given one or more intent states, this will calculate a Color that is the combination of them all, in a 'max
        /// RGB component' fashion (ie. max of R, max of G, max of B).
        /// </summary>
        public static Color GetOpaqueRGBMaxColorForIntents(IIntentStates states)
        {
            byte R = 0;
            byte G = 0;
            byte B = 0;

            foreach (IIntentState intentState in states)
            {
                object value = intentState.GetValue();

                if (value is LightingValue)
                {
                    LightingValue lv = (LightingValue)value;
                    if (lv.Intensity > 0)
                    {
                        Color intentColor = lv.FullColor;
                        R = Math.Max(R, intentColor.R);
                        G = Math.Max(G, intentColor.G);
                        B = Math.Max(B, intentColor.B);
                    }
                }
                else if (value is RGBValue)
                {
                    RGBValue rv = (RGBValue)value;
                    R = Math.Max(R, rv.R);
                    G = Math.Max(G, rv.G);
                    B = Math.Max(B, rv.B);
                }
            }

            return(Color.FromArgb(R, G, B));
        }
Example #3
0
        /// <summary>
        /// Given one or more intent states, this will calculate a Color that is the combination of them all, in a 'max
        /// RGB component' fashion (ie. max of R, max of G, max of B).
        /// </summary>
        public static Color GetOpaqueRGBMaxColorForIntents(IIntentStates states)
        {
            byte R = 0;
            byte G = 0;
            byte B = 0;

            foreach (IIntentState intentState in states) {
                object value = intentState.GetValue();

                if (value is LightingValue) {
                    LightingValue lv = (LightingValue)value;
                    if (lv.Intensity > 0) {
                        Color intentColor = lv.FullColor;
                        R = Math.Max(R, intentColor.R);
                        G = Math.Max(G, intentColor.G);
                        B = Math.Max(B, intentColor.B);
                    }
                } else if (value is RGBValue) {
                    RGBValue rv = (RGBValue)value;
                    R = Math.Max(R, rv.R);
                    G = Math.Max(G, rv.G);
                    B = Math.Max(B, rv.B);
                }
            }

            return Color.FromArgb(R, G, B);
        }
Example #4
0
        public List <Color> GetDiscreteColors(IIntentStates states)
        {
            // Get states for each color
            List <Color> colors = _discreteHandler.GetAlphaAffectedColor(states);

            return(colors);
        }
Example #5
0
 internal Element(Guid id, string name)
 {
     Id          = id;
     Name        = name;
     _dataSource = new ElementContextSource(Id);
     _state      = new IntentStateList();
 }
Example #6
0
        private void CreateDiscreteColorPoints(int referenceHeight)
        {
            List <Color>  colors = _emptyColors;
            Guid          nodeId = Guid.Empty;
            IIntentStates state  = null;

            foreach (PreviewPixel previewPixel in _pixelCache)
            {
                if (previewPixel.NodeId != nodeId)
                {
                    nodeId = previewPixel.NodeId;
                    state  = previewPixel.Node.Element.State;
                    colors = previewPixel.GetDiscreteColors(state);
                }

                if (state?.Count > 0)
                {
                    //All points are the same in standard discrete
                    int     col = 1;
                    Vector2 xy;
                    if (_isHighPrecision)
                    {
                        xy = new Vector2((float)previewPixel.Location.X, (float)previewPixel.Location.Y);
                    }
                    else
                    {
                        xy = new Vector2(previewPixel.X, previewPixel.Y);
                    }
                    foreach (Color c in colors)
                    {
                        if (c.A > 0)
                        {
                            _points.Add(xy.X);
                            _points.Add(referenceHeight - xy.Y);
                            _points.Add(previewPixel.Z);
                            _points.Add(c.R);
                            _points.Add(c.G);
                            _points.Add(c.B);
                            _points.Add(c.A);
                            _points.Add(previewPixel.PixelSize);

                            if (col % 2 == 0)
                            {
                                xy.Y += previewPixel.PixelSize;
                                //xy.X = xy.X;
                            }
                            else
                            {
                                xy.X = xy.X + previewPixel.PixelSize;
                            }

                            col++;
                        }
                    }
                }
            }
        }
Example #7
0
        public Color GetFullColor(IIntentStates states)
        {
            var state = states[0];

            if (state != null)
            {
                return(_fullColorHandler.GetFullColor(state));
            }
            return(Color.Empty);
        }
Example #8
0
        public static Color GetAlphaRGBMaxColorForIntents(IIntentStates states)
        {
            Color result = GetOpaqueRGBMaxColorForIntents(states);

            // have calculated the desired hue/saturation from combining the color components above (in a
            // 'highest-wins in each of R/G/B' fashion). Now we need to figure out the appropriate alpha channel
            // value for the given color. To do that, convert the RGB color to HSV, get the V value to use as
            // our intensity, and apply that to the alpha channel.
            result = Color.FromArgb((byte)(HSV.VFromRgb(result) * Byte.MaxValue), result.R, result.G, result.B);
            return(result);
        }
Example #9
0
        /// <summary>
        /// Given one or more intent states, this will calculate a Color that is the combination of them all, with an
        /// alpha channel calculated from the 'brightness' of the color. The combination will occur in the RGB space,
        /// and will take the maximum component of each color as the resulting color (ie. max of R, max of G, max of B).
        /// </summary>
        public static Color GetAlphaRGBMaxColorForIntents(IIntentStates states)
        {
            Color result = GetOpaqueRGBMaxColorForIntents(states);

            // have calculated the desired hue/saturation from combining the color components above (in a
            // 'highest-wins in each of R/G/B' fashion). Now we need to figure out the appropriate alpha channel
            // value for the given color. To do that, convert the RGB color to HSV, get the V value to use as
            // our intensity, and apply that to the alpha channel.
            HSV hsv = HSV.FromRGB(result);
            result = Color.FromArgb((byte)(hsv.V * Byte.MaxValue), result.R, result.G, result.B);
            return result;
        }
Example #10
0
        public List <Color> GetAlphaAffectedColor(IIntentStates states)
        {
            _colorMap.Clear();
            _colors.Clear();
            foreach (var intentState in states.AsList())
            {
                intentState.Dispatch(this);
            }
            foreach (var d in _colorMap)
            {
                var c = d.Key;
                _colors.Add(Color.FromArgb((byte)(d.Value * 255), c.R, c.G, c.B));
            }

            return(_colors);
        }
Example #11
0
        public List<Color> GetAlphaAffectedColor(IIntentStates states)
        {
            _colorMap.Clear();
            _colors.Clear();
            foreach (var intentState in states.AsList())
            {
                intentState.Dispatch(this);
            }
            foreach (var d in _colorMap)
            {
                var c = d.Key;
                _colors.Add(Color.FromArgb((byte)(d.Value * 255), c.R, c.G, c.B));
            }

            return _colors;
        }
Example #12
0
        public void Draw(FastPixel.FastPixel fp, IIntentStates states, double zoomLevel)
        {
            if (_isDiscreteColored)
            {
                int       col      = 1;
                int       zoomedX  = (int)(Bounds.X * zoomLevel);
                Rectangle drawRect = new Rectangle(zoomedX, (int)(Bounds.Y * zoomLevel), Bounds.Width, Bounds.Height);
                // Get states for each color
                List <Color> colors = _discreteHandler.GetAlphaAffectedColor(states);
                foreach (Color c in colors)
                {
                    if (c != Color.Transparent && c.A > byte.MinValue)
                    {
                        fp.DrawCircle(drawRect, c);

                        if (col % 2 == 0)
                        {
                            drawRect.Y += PixelSize;
                            drawRect.X  = zoomedX;
                        }
                        else
                        {
                            drawRect.X = zoomedX + PixelSize;
                        }

                        col++;
                    }
                }
            }
            else
            {
                var state = states.FirstOrDefault();
                if (state != null)
                {
                    Color intentColor = _fullColorHandler.GetFullColor(state);
                    if (intentColor.A > 0)
                    {
                        Rectangle drawRect = zoomLevel != 1?new Rectangle((int)(Bounds.X * zoomLevel), (int)(Bounds.Y * zoomLevel), Bounds.Width, Bounds.Height):Bounds;
                        fp.DrawCircle(drawRect, intentColor);
                    }
                }
            }
        }
Example #13
0
        public void Draw(FastPixel.FastPixel fp, IIntentStates states)
        {
            if (_isDiscreteColored)
            {
                int       col      = 1;
                Rectangle drawRect = new Rectangle(drawArea.X, drawArea.Y, drawArea.Width, drawArea.Height);
                // Get states for each color
                List <Color> colors = _discreteHandler.GetAlphaAffectedColor(states);
                foreach (Color c in colors)
                {
                    if (c != Color.Transparent && c.A > byte.MinValue)
                    {
                        fp.DrawCircle(drawRect, c);

                        if (col % 2 == 0)
                        {
                            drawRect.Y += PixelSize;
                            drawRect.X  = drawArea.X;
                        }
                        else
                        {
                            drawRect.X = drawArea.X + PixelSize;
                        }

                        col++;
                    }
                }
            }
            else
            {
                var state = states.FirstOrDefault();
                if (state != null)
                {
                    Color intentColor = _fullColorHandler.GetFullColor(state);
                    if (intentColor.A > 0)
                    {
                        fp.DrawCircle(drawArea, intentColor);
                    }
                }
            }
        }
        /// <summary>
        /// Returns a list of alpha affected distinct colors from the states, combined so that the brightest of each color is returned
        /// </summary>
        public static IEnumerable <Color> GetAlphaAffectedDiscreteColorsForIntents(IIntentStates states)
        {
            List <Color> colors = new List <Color>();

            IEnumerable <IGrouping <Color, IIntentState> > colorStates = states.GroupBy(
                (x =>
            {
                if (x is IntentState <LightingValue> )
                {
                    return((x as IntentState <LightingValue>).GetValue().HueSaturationOnlyColor);
                }
                if (x is IntentState <RGBValue> )
                {
                    return((x as IntentState <RGBValue>).GetValue().Color);
                }
                return(Color.Empty);
            }
                ));

            foreach (IGrouping <Color, IIntentState> grouping in colorStates)
            {
                double intensity = grouping.Max(x =>
                {
                    if (x is IntentState <LightingValue> )
                    {
                        return((x as IntentState <LightingValue>).GetValue().Intensity);
                    }
                    if (x is IntentState <RGBValue> )
                    {
                        return((x as IntentState <RGBValue>).GetValue().Intensity);
                    }
                    return(0);
                });

                Color brightest = Color.FromArgb((byte)(intensity * byte.MaxValue), grouping.Key.R, grouping.Key.G, grouping.Key.B);
                colors.Add(brightest);
            }

            return(colors);
        }
Example #15
0
        public void Draw(FastPixel.FastPixel fp, IIntentStates states)
        {
            if (_isDiscreteColored)
            {
                int       col      = 1;
                Rectangle drawRect = new Rectangle(drawArea.X, drawArea.Y, drawArea.Width, drawArea.Height);
                // Get states for each color
                IEnumerable <Color> colors = IntentHelpers.GetAlphaAffectedDiscreteColorsForIntents(states);
                foreach (Color c in colors)
                {
                    if (c != Color.Transparent && c.A > byte.MinValue)
                    {
                        fp.DrawCircle(drawRect, c);

                        if (col % 2 == 0)
                        {
                            drawRect.Y += PixelSize;
                            drawRect.X  = drawArea.X;
                        }
                        else
                        {
                            drawRect.X = drawArea.X + PixelSize;
                        }

                        col++;
                    }
                }
            }
            else
            {
                Color intentColor = IntentHelpers.GetAlphaRGBMaxColorForIntents(states);
                if (intentColor != Color.Transparent && intentColor.A > 0)
                {
                    fp.DrawCircle(drawArea, intentColor);
                }
            }
        }
Example #16
0
        /// <summary>
        /// Returns a list of alpha affected distinct colors from the states, combined so that the brightest of each color is returned
        /// </summary>
        public static IEnumerable<Color> GetAlphaAffectedDiscreteColorsForIntents(IIntentStates states)
        {
            List<Color> colors = new List<Color>();

            IEnumerable<IGrouping<Color, IIntentState>> colorStates = states.GroupBy(
                (x =>
                    {
                        if (x is IntentState<LightingValue>) {
                            return (x as IntentState<LightingValue>).GetValue().HueSaturationOnlyColor;
                        }
                        if (x is IntentState<RGBValue>) {
                            return (x as IntentState<RGBValue>).GetValue().Color;
                        }
                        return Color.Empty;
                    }
                ));

            foreach (IGrouping<Color, IIntentState> grouping in colorStates) {

                double intensity = grouping.Max(x =>
                    {
                        if (x is IntentState<LightingValue>) {
                            return (x as IntentState<LightingValue>).GetValue().Intensity;
                        }
                        if (x is IntentState<RGBValue>) {
                            return (x as IntentState<RGBValue>).GetValue().Intensity;
                        }
                        return 0;
                    });

                Color brightest = Color.FromArgb((byte)(intensity * byte.MaxValue), grouping.Key.R, grouping.Key.G, grouping.Key.B);
                colors.Add(brightest);
            }

            return colors;
        }
Example #17
0
        public void Draw(FastPixel.FastPixel fp, IIntentStates states)
        {
            if(_isDiscreteColored)
            {
                int col = 1;
                Rectangle drawRect = new Rectangle(drawArea.X, drawArea.Y, drawArea.Width, drawArea.Height);
                // Get states for each color
                List<Color> colors = _discreteHandler.GetAlphaAffectedColor(states);
                foreach (Color c in colors)
                {
                    if (c != Color.Transparent && c.A > byte.MinValue)
                    {
                        fp.DrawCircle(drawRect, c);

                        if (col % 2 == 0)
                        {
                            drawRect.Y += PixelSize;
                            drawRect.X = drawArea.X;
                        } else
                        {
                            drawRect.X = drawArea.X + PixelSize;
                        }

                        col++;
                    }
                }
            }
            else
            {
                var state = states.FirstOrDefault();
                if (state != null)
                {
                    Color intentColor = _fullColorHandler.GetFullColor(state);
                    if (intentColor.A > 0)
                    {
                        fp.DrawCircle(drawArea, intentColor);
                    }

                }

            }
        }
Example #18
0
 public void ClearStates()
 {
     _state = new IntentStateList();
 }
Example #19
0
 public void Update()
 {
     _state = _AggregateStateFromContexts();
 }
Example #20
0
 internal Element(Guid id, string name)
 {
     Id     = id;
     Name   = name;
     _state = EmptyState;
 }
Example #21
0
 public void ClearStates()
 {
     _state = EmptyState;
 }
Example #22
0
        public void Draw(FastPixel.FastPixel fp, IIntentStates states)
        {
			
			if(_isDiscreteColored)
			{
				int col = 1;
				Rectangle drawRect = new Rectangle(drawArea.X, drawArea.Y, drawArea.Width, drawArea.Height);
				// Get states for each color
				IEnumerable<Color> colors = IntentHelpers.GetAlphaAffectedDiscreteColorsForIntents(states);
				foreach (Color c in colors)
				{
					if (c != Color.Transparent && c.A > byte.MinValue)
					{
						fp.DrawCircle(drawRect, c);

						if (col % 2 == 0)
						{
							drawRect.Y += PixelSize;
							drawRect.X = drawArea.X;
						} else
						{
							drawRect.X = drawArea.X + PixelSize;
						}

						col++;
					}
				}
			}
			else
			{
				Color intentColor = IntentHelpers.GetAlphaRGBMaxColorForIntents(states);
				if (intentColor != Color.Transparent && intentColor.A > 0)
				{
					fp.DrawCircle(drawArea, intentColor);
				}
			}
        }
Example #23
0
        public static Dictionary<Color, DiscreteValue> GetAlphaDiscreteColorsForIntents(IIntentStates states)
        {
            Dictionary<Color, DiscreteValue> colors = new Dictionary<Color, DiscreteValue>();

            IEnumerable<IGrouping<Color, IIntentState>> colorStates = states.GroupBy(
                (x =>
                {
                    var state = x as IntentState<DiscreteValue>;
                    if (state != null)
                    {
                        return state.GetValue().Color;
                    }

                    return Color.Empty;
                }
                ));

            foreach (IGrouping<Color, IIntentState> grouping in colorStates)
            {

                double intensity = grouping.Max(x =>
                {
                    var state = x as IntentState<DiscreteValue>;
                    if (state != null)
                    {
                        return state.GetValue().Intensity;
                    }

                    return 0;
                });

                Color brightest = Color.FromArgb(grouping.Key.R, grouping.Key.G, grouping.Key.B);
                colors.Add(brightest, new DiscreteValue(brightest, intensity));
            }

            return colors;
        }
Example #24
0
        public static Dictionary <Color, DiscreteValue> GetAlphaDiscreteColorsForIntents(IIntentStates states)
        {
            Dictionary <Color, DiscreteValue> colors = new Dictionary <Color, DiscreteValue>();

            IEnumerable <IGrouping <Color, IIntentState> > colorStates = states.GroupBy(
                (x =>
            {
                var state = x as IntentState <DiscreteValue>;
                if (state != null)
                {
                    return(state.GetValue().Color);
                }

                return(Color.Empty);
            }
                ));

            foreach (IGrouping <Color, IIntentState> grouping in colorStates)
            {
                double intensity = grouping.Max(x =>
                {
                    var state = x as IntentState <DiscreteValue>;
                    if (state != null)
                    {
                        return(state.GetValue().Intensity);
                    }

                    return(0);
                });

                Color brightest = Color.FromArgb(grouping.Key.R, grouping.Key.G, grouping.Key.B);
                colors.Add(brightest, new DiscreteValue(brightest, intensity));
            }

            return(colors);
        }
Example #25
0
 private List <IIntentState> GetCombinedState(IIntentStates states)
 {
     return(_stateCombinator.Combine(states.AsList()));
 }