public static Border CreateBlockBox(FrameworkElement child, double width, double height, double x, double y, Color backgroundColor)
        {
            var border = new Border()
            {
                BorderThickness = new Thickness(1, 1, 1, 1),
                BorderBrush = Brushes.Silver,
                Background = new SolidColorBrush(backgroundColor),

                Width = width,
                Height = height,
                Margin = new Thickness(x, y, 0, 0),
                Child = child
            };

            border.MouseEnter += (s, e) =>
            {
                border.Width = Math.Max(width, child.ActualWidth);
                border.Height = Math.Max(height, child.ActualHeight);
                Panel parent = (Panel)border.Parent;
                border.TopMost();
            };

            border.MouseLeave += (s, e) =>
            {
                border.Width = width;
                border.Height = height;
            };

            return border;
        }
Example #2
0
 public CleanCodeRank(Color color, string name)
 {
     Color = new SolidColorBrush(color);
     Name = "  " + name;
     Principles = new ObservableCollection<CleanCodePrinciple>();
     Practices = new ObservableCollection<CleanCodePractice>();
 }
Example #3
0
 public static IZ1BrushSequence DualBrushes(Color positiveColor, Color negativeColor, int steps)
 {
     return new Z1BrushSequence(
         positiveBrushes: positiveColor.FadingSpread(steps + 1).ToBrushes(),
         negativeBrushes: negativeColor.FadingSpread(steps + 1).ToBrushes()
     );
 }
 public AddLogFileDefinitionCommand(string path, Color color, string timestampPattern, LogOffset offset)
 {
     Path = path;
     Color = color;
     TimestampPattern = timestampPattern;
     Offset = offset;
 }
        public BgEditorControl(MainWindow mainWindow)
        {
            _mainWindow = mainWindow;
            InitializeComponent();
            _orgColor = SolidColorPicker.SelectedColor ?? Colors.White;

            var color = Settings.Default.Get("dcolor", System.Drawing.Color.WhiteSmoke);
            SolidColorPicker.SelectedColor = color.ToMediaColor();

            ColorAccentButton.Content = LanguageLibrary.Language.Default.accet_color_button;
            ApplyChangesButton.Content = LanguageLibrary.Language.Default.apply_changes_button;
            ImageScalingLabel.Text = LanguageLibrary.Language.Default.image_scale;
            RestoreDefaultButton.Content = LanguageLibrary.Language.Default.restore_defaults_button;
            RestoreDefaultArea.Header = LanguageLibrary.Language.Default.group_restore_default;
            textBlock.Text = LanguageLibrary.Language.Default.or;
            SharebackgroundButton.Content = LanguageLibrary.Language.Default.share_bg;
            MyResolutionOption.Content = LanguageLibrary.Language.Default.image_scale_Resolution;
            NoneOption.Content = LanguageLibrary.Language.Default.scale_none_opt;

            TextBoxHelper.SetWatermark(SelectedFile, LanguageLibrary.Language.Default.select_img);

            TextBoxHelper.SetButtonCommandParameter(SelectedFile, "Hello World");
            TextBoxHelper.SetButtonCommand(SelectedFile, new SelectImageCommand(this, _mainWindow));
            ColorPickerButton.Content = LanguageLibrary.Language.Default.color_picker_button;
            SolidColorPicker.ToolTip = LanguageLibrary.Language.Default.solid_color_picker_tooltip;
            SolidColorPicker.StandardButtonHeader = LanguageLibrary.Language.Default.solid_color_standard;
            SolidColorPicker.AdvancedButtonHeader = LanguageLibrary.Language.Default.solid_color_advanced;
            SolidColorPicker.StandardColorsHeader = LanguageLibrary.Language.Default.solid_color_standard_colors;
            SolidColorPicker.AvailableColorsHeader = LanguageLibrary.Language.Default.solid_color_available_colors;
            PixelateImageLabel.Text = LanguageLibrary.Language.Default.image_pixelate;
        }
Example #6
0
 public void SetModel(Color clr, string name)
 {
     laserArrow.Fill = new SolidColorBrush(clr);
     userLines.BorderBrush = new SolidColorBrush(clr);
     //txtName.Foreground = new SolidColorBrush(clr);
     txtName.Text = name;
 }
        /// <summary>Creates a gradient brush with the given colors flowing in the specified direction.</summary>
        /// <param name="direction">The direction of the gradient.</param>
        /// <param name="start">The starting color.</param>
        /// <param name="end">The ending color.</param>
        public static LinearGradientBrush ToGradient(this Direction direction, Color start, Color end)
        {
            // Create the brush.
            var brush = new LinearGradientBrush();
            switch (direction)
            {
                case Direction.Down:
                case Direction.Up:
                    brush.StartPoint = new Point(0.5, 0);
                    brush.EndPoint = new Point(0.5, 1);
                    break;
                case Direction.Right:
                case Direction.Left:
                    brush.StartPoint = new Point(0, 0.5);
                    brush.EndPoint = new Point(1, 0.5);
                    break;
            }

            // Configure colors.
            var gradientStart = new GradientStop { Color = start };
            var gradientEnd = new GradientStop { Color = end };

            gradientStart.Offset = direction == Direction.Up || direction == Direction.Left ? 1 : 0;
            gradientEnd.Offset = direction == Direction.Down || direction == Direction.Right ? 1 : 0;

            // Insert colors.
            brush.GradientStops.Add(gradientStart);
            brush.GradientStops.Add(gradientEnd);

            // Finish up.
            return brush;
            
        }
 public SearchOptions(string searchText, Color foreground, Color background, bool alert)
 {
     SearchText = searchText;
     Foreground = foreground;
     Background = background;
     Alert = alert;
 }
 public CustomStartEndLineStyle(PointSymbolType startType, Color startColor, int startSize,
                                PointSymbolType endType, Color endColor, int endSize,
                                Color lineColor, float lineSize)
     : this(new PointStyle(startType, new GeoSolidBrush(GeoColor.FromArgb(startColor.A, startColor.R, startColor.G, startColor.B)), startSize),
            new PointStyle(endType, new GeoSolidBrush(GeoColor.FromArgb(endColor.A, endColor.R, endColor.G, endColor.B)), endSize),
            new LineStyle(new GeoPen(GeoColor.FromArgb(lineColor.A, lineColor.R, lineColor.G, lineColor.B), lineSize)))
 { }
 public DbColor(Color color)
 {
     Alpha = color.A;
     Red = color.R;
     Green = color.G;
     Blue = color.B;
 }
 public AdministrationViewModel(ICustomAppearanceManager appearanceManager, IAppSettings appSettings)
 {
     this.appearanceManager = appearanceManager;
     this.appSettings = appSettings;
     selectedAccentColor = appearanceManager.AccentColor;
     selectedTextColor = appearanceManager.TextColor;
 }
 public TileProperty(int id, string name, Color color, bool isFramed = false)
 {
     _color = color;
     _id = id;
     _name = name;
     _isFramed = isFramed;
 }
Example #13
0
 public LogFile(string path, Color color, string timestampPattern, LogOffset offset)
 {
     Path = path;
     Color = color;
     TimestampPattern = timestampPattern;
     Offset = offset;
 }
Example #14
0
 public Prim(Color init, Color edgefinal, Color edgetemp, Color nodefinal)
 {
     initColor = new SolidColorBrush(init);
     edgeFinalColor = new SolidColorBrush(edgefinal);
     edgeTempColor = new SolidColorBrush(edgetemp);
     nodeFinalColor = new SolidColorBrush(nodefinal);
 }
Example #15
0
        public AlternatingListBoxBackground(Color color1, Color color2)
        {
            var setter = new Setter();
            setter.Property = ListBoxItem.BackgroundProperty;
            setter.Value = new SolidColorBrush(color1);

            var trigger = new Trigger();
            trigger.Property = ItemsControl.AlternationIndexProperty;
            trigger.Value = 0;
            trigger.Setters.Add(setter);

            var setter2 = new Setter();
            setter2.Property = ListBoxItem.BackgroundProperty;
            setter2.Value = new SolidColorBrush(color2);

            var trigger2 = new Trigger();
            trigger2.Property = ItemsControl.AlternationIndexProperty;
            trigger2.Value = 1;
            trigger2.Setters.Add(setter2);

            var listBoxStyle = new Style(typeof(ListBoxItem));
            listBoxStyle.Triggers.Add(trigger);
            listBoxStyle.Triggers.Add(trigger2);

            _listBoxStyle = listBoxStyle;
        }
 public MaterialExtension(Color color)
 {
     this.color = color;
     SpecularPower = 100;
     SpecularIntensity = 1;
     Opacity = 1;
 }
        public void ReplaceColors_ReplacesBackgroundColorsCorrectly()
        {
            // Arrange
            var oldColor = new Color {A = 255, R = 255, G = 0, B = 0};
            var newColor = new Color {A = 255, R = 0, G = 255, B = 100};

            var testInputReplaceColors = new ReplaceColorsParameterSet
            {
                OldBackgroundColor = oldColor,
                NewBackgroundColor = newColor,
                ReplaceBackgroundColor = true
            };

            var testInputBlock1 = new ItemFilterBlock();
            testInputBlock1.BlockItems.Add(new BackgroundColorBlockItem(new Color {A = 255, R = 255, G = 0, B = 0}));
            var testInputBlock2 = new ItemFilterBlock();
            testInputBlock2.BlockItems.Add(new BackgroundColorBlockItem(new Color { A = 255, R = 255, G = 1, B = 0 }));
            var testInputBlock3 = new ItemFilterBlock();
            testInputBlock3.BlockItems.Add(new BackgroundColorBlockItem(new Color { A = 255, R = 255, G = 0, B = 0 }));

            var script = new ItemFilterScript();

            script.ItemFilterBlocks.Add(testInputBlock1);
            script.ItemFilterBlocks.Add(testInputBlock2);
            script.ItemFilterBlocks.Add(testInputBlock3);

            // Act
            script.ReplaceColors(testInputReplaceColors);

            // Assert
            Assert.AreEqual(newColor, testInputBlock1.BlockItems.OfType<BackgroundColorBlockItem>().First().Color);
            Assert.AreNotEqual(newColor, testInputBlock2.BlockItems.OfType<BackgroundColorBlockItem>().First().Color);
            Assert.AreEqual(newColor, testInputBlock3.BlockItems.OfType<BackgroundColorBlockItem>().First().Color);
        }
Example #18
0
        protected MapItem()
        {
            _points = new List<Point>();
            _pointsInFigures = new List<int>();

            _visible = true;
            _syncronized = false;
            _type = FigureType.Point;
            _opacity = 1.0;
            _outlineVisible = false;
            _color = Colors.Black;
            _borderColor = Colors.Black;
            _borderOpacity = 1.0;
            _size = 0.25;
            _lineWidth = 1;
            _outlineWidth = 1;

            _style = new SymbolStyle
            {
                Symbol = _imageSuorce == null ? null : new Bitmap { Data = _imageSuorce },
                Line = new Pen(GetColor(_color, _opacity), (float)_lineWidth),
                Outline = new Pen(_outlineVisible ? GetColor(_borderColor, _opacity) : System.Drawing.Color.Transparent, OutlineVisible ? 1 : 0),
                Fill = new SolidBrush(GetColor(_color, _opacity)),
                SymbolScale = _size,
            };
        }
Example #19
0
 public static Pen CreateErrorPen(Color color)
 {
     var geometry = new StreamGeometry();
     using (var context = geometry.Open())
     {
         context.BeginFigure(new Point(-1, 0), false, false);
         context.PolyLineTo(new[] {
                 new Point(-0.5, 0.4),
                 new Point(0, 0),
                 new Point(0.5, -0.4),
                 new Point(1, 0),
             }, true, true);
     }
     var brushPattern = new GeometryDrawing
     {
         Pen = new Pen(new SolidColorBrush(color), 0.4),
         Geometry = geometry
     };
     var brush = new DrawingBrush(brushPattern)
     {
         TileMode = TileMode.Tile,
         Viewport = new Rect(-1, -1, 2, 2),
         ViewportUnits = BrushMappingMode.Absolute,
         Viewbox = new Rect(-1, -1, 2, 2),
         ViewboxUnits = BrushMappingMode.Absolute,
     };
     var pen = new Pen(brush, 3.0);
     pen.Freeze();
     return pen;
 }
		private static Color LightenColor(Color color, float lightFactor)
		{
			float fFactor = lightFactor;
			if ((double)fFactor > 1.0)
				--fFactor;
			return Color.FromRgb(LightenColorExtension.LightenColorComponent(color.R, fFactor), LightenColorExtension.LightenColorComponent(color.G, fFactor), LightenColorExtension.LightenColorComponent(color.B, fFactor));
		}
 public LinearGradientBrushTool(Color ca, Color cb, double a, double o = 1) : this()
 {
     ColorA = ca;
     ColorB = cb;
     Angle = a;
     Opacity = o;
 }
Example #22
0
        /// <summary>
        /// Bilinear interpolation of ARGB values.
        /// </summary>
        /// <param name="x">The X interpolation parameter 0..1</param>
        /// <param name="y">The y interpolation parameter 0..1</param>
        /// <param name="nw"></param>
        /// <param name="ne"></param>
        /// <param name="sw"></param>
        /// <param name="se"></param>
        /// <returns>The interpolated value.</returns>
        public static Color BilinearInterpolate(double x, double y, Color nw, Color ne, Color sw, Color se)
        {
            double cx = 1.0 - x;
            double cy = 1.0 - y;

            //nw = ColorUtility.PreMultiplyAlpha(nw);
            //ne = ColorUtility.PreMultiplyAlpha(ne);
            //sw = ColorUtility.PreMultiplyAlpha(sw);
            //se = ColorUtility.PreMultiplyAlpha(se);

            double m0 = cx * nw.A + x * ne.A;
            double m1 = cx * sw.A + x * se.A;
            byte a = (byte)(cy * m0 + y * m1);

            m0 = cx * nw.R + x * ne.R;
            m1 = cx * sw.R + x * se.R;
            byte r = (byte)(cy * m0 + y * m1);

            m0 = cx * nw.G + x * ne.G;
            m1 = cx * sw.G + x * se.G;
            byte g = (byte)(cy * m0 + y * m1);

            m0 = cx * nw.B + x * ne.B;
            m1 = cx * sw.B + x * se.B;
            byte b = (byte)(cy * m0 + y * m1);

            Color result = Color.FromArgb(a, r, g, b);
            //result = ColorUtility.UnPreMultiplyAlpha(result);
            return result;
        }
Example #23
0
 public Dijkstra(Color main, Color temp, Color search, Color next)
 {
     mainColor=new SolidColorBrush(main);
     tempColor=new SolidColorBrush(temp);
     nextColor=new SolidColorBrush(next);
     searchColor=new SolidColorBrush(search);
 }
Example #24
0
    } // DrawingToMediaColor()

    /// <summary>
    /// Converts a System.Windows.Media.Color value to a
    /// System.Drawing.Color value.
    /// </summary>
    /// <param name="color">A System.Windows.Media.Color value.</param>
    /// <returns>A System.Drawing.Color value.</returns>
    public static System.Drawing.Color MediaToDrawingColor(Color color)
    {
      System.Drawing.Color colorNew = System.Drawing.Color.FromArgb(
        color.A, color.R, color.G, color.B);
      
      return colorNew;
    } // MediaToDrawingColor()
Example #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Color"/> class.
 /// </summary>
 /// <param name="mediaColor">The color.</param>
 /// <param name="invariantName">The culture-insensitive name of the color. (Optional.)</param>
 /// <param name="name">The localized friendly name of the color. (Optional.)</param>
 /// <param name="isBuiltIn">A value indicating whether this color is defined in the assembly. (Optional.)</param>
 public Color(System.Windows.Media.Color mediaColor, string invariantName = null, string name = null, bool isBuiltIn = false)
 {
     this.name = name;
     this.identifier = isBuiltIn ? ("resource:" + invariantName) : ("color:" + mediaColor);
     this.isBuiltIn = isBuiltIn;
     this.mediaColor = mediaColor;
 }
Example #26
0
 public ErrorTextMarker(int startOffset, int length, string message, Color markerColor)
 {
     StartOffset = startOffset;
     Length = length;
     Message = message;
     MarkerColor = markerColor;
 }
Example #27
0
 public override TileStyle GetStyle(Color tileColor, Color fontColor)
 {
     var style = GetDefaultStyle();
     style.Font.Color = new SolidColorBrush(fontColor);
     style.Shape.Fill = new SolidColorBrush(tileColor);
     return style;
 }
Example #28
0
 public ColorRange(Color lowColor, Color highColor, float lowHeight, float highHeight)
 {
     LowColor = lowColor;
     HighColor = highColor;
     LowHeight = lowHeight;
     HighHeight = highHeight;
 }
 public CellColorActionViewModel(string name, string description, char code, Color backgroundColor)
 {
     Name = name;
     Description = description;
     Code = code;
     BackgroundBrush = new SolidColorBrush(backgroundColor);
 }
Example #30
0
 public static IColorSequence Dipolar(Color negativeColor, Color positiveColor, int halfStepCount)
 {
     return new Ir1ColorSequence(
             new ColorSequenceImpl(positiveColor.LessFadingSpread(halfStepCount)),
             new ColorSequenceImpl(negativeColor.LessFadingSpread(halfStepCount))
         );
 }
Example #31
0
 public bool IsColorIn(Color color)
 {
     return((color.R >= _redLowBound && color.R <= _redHighBound) &&
            (color.G >= _greenLowBound && color.G <= _greenHighBound) &&
            (color.B >= _blueLowBound && color.B <= _blueHighBound));
 }
Example #32
0
 public void set(int x, int y, System.Windows.Media.Color color)
 {
     bytes[x, y] = color;
 }
Example #33
0
        public static void WriteElementColor(this System.Xml.Linq.XElement element, string elementName, System.Windows.Media.Color color)
        {
            XElement elemColor = new XElement("Color");

            elemColor.Add(new XAttribute("Name", elementName));
            elemColor.Add(new XAttribute("R", color.R.ToString()));
            elemColor.Add(new XAttribute("G", color.G.ToString()));
            elemColor.Add(new XAttribute("B", color.B.ToString()));

            element.Add(elemColor);
        }
Example #34
0
        private static System.Windows.Media.Color HsbToRgb(HsbColor hsbColor)
        {
            // Initialize
            var rgbColor = new System.Windows.Media.Color();

            /* Gray (zero saturation) is a special case.We simply
            * set RGB values to HSB Brightness value and exit. */

            // Gray: Set RGB and return
            if (hsbColor.S == 0.0)
            {
                rgbColor.R = Convert.ToByte(hsbColor.B * 255);
                rgbColor.G = Convert.ToByte(hsbColor.B * 255);
                rgbColor.B = Convert.ToByte(hsbColor.B * 255);
                return(rgbColor);
            }

            /* Now we process the normal case. */

            var h = (hsbColor.H == 360) ? 0 : hsbColor.H / 60;
            var i = Convert.ToInt32(Math.Truncate(h));
            var f = h - i;

            var p = hsbColor.B * (1.0 - hsbColor.S);
            var q = hsbColor.B * (1.0 - (hsbColor.S * f));
            var t = hsbColor.B * (1.0 - (hsbColor.S * (1.0 - f)));

            double r, g, b;

            switch (i)
            {
            case 0:
                r = hsbColor.B;
                g = t;
                b = p;
                break;

            case 1:
                r = q;
                g = hsbColor.B;
                b = p;
                break;

            case 2:
                r = p;
                g = hsbColor.B;
                b = t;
                break;

            case 3:
                r = p;
                g = q;
                b = hsbColor.B;
                break;

            case 4:
                r = t;
                g = p;
                b = hsbColor.B;
                break;

            default:
                r = hsbColor.B;
                g = p;
                b = q;
                break;
            }

            // Set WPF Color object
            rgbColor.R = Convert.ToByte(r * 255);
            rgbColor.G = Convert.ToByte(g * 255);
            rgbColor.B = Convert.ToByte(b * 255);

            // Set return value
            return(rgbColor);
        }
Example #35
0
 //Set up the gradiant
 private static void SetGradient(LinearGradientBrush brush, System.Windows.Media.Color s, System.Windows.Media.Color m, System.Windows.Media.Color e)
 {
     brush.StartPoint = new System.Windows.Point(0.5, 0);
     brush.EndPoint   = new System.Windows.Point(0.5, 1);
     brush.GradientStops.Add(new GradientStop {
         Offset = 0.0, Color = s
     });
     brush.GradientStops.Add(new GradientStop {
         Offset = 0.2, Color = m
     });
     brush.GradientStops.Add(new GradientStop {
         Offset = 0.7, Color = e
     });
 }
Example #36
0
 public HeightMinMaxTool(Color color, bool isEditable)
 {
     ToolColor  = color;
     IsEditable = isEditable;
     Init();
 }
Example #37
0
 public HeightMinMaxTool(Color color)
 {
     ToolColor  = color;
     IsEditable = true;
     Init();
 }
Example #38
0
 public HeightMinMaxTool()
 {
     ToolColor  = Colors.Orange;
     IsEditable = true;
     Init();
 }
Example #39
0
 private void ColorVerticalSlider_ColorChanged(object sender, System.Windows.Media.Color color)
 {
     ColorSliderVerticalFromEvent.Fill = new SolidColorBrush(color);
     ColorSliderVerticalClone.Color    = color;
 }
Example #40
0
        static ColorHls RgbToHls(System.Windows.Media.Color rgbColor)
        {
            // Initialize result
            var hlsColor = new ColorHls();

            // Convert RGB values to percentages
            double r = (double)rgbColor.R / 255;
            var    g = (double)rgbColor.G / 255;
            var    b = (double)rgbColor.B / 255;
            var    a = (double)rgbColor.A / 255;

            // Find min and max RGB values
            var min   = Math.Min(r, Math.Min(g, b));
            var max   = Math.Max(r, Math.Max(g, b));
            var delta = max - min;

            /* If max and min are equal, that means we are dealing with
             * a shade of gray. So we set H and S to zero, and L to either
             * max or min (it doesn't matter which), and  then we exit. */

            //Special case: Gray
            if (max == min)
            {
                hlsColor.H = 0;
                hlsColor.S = 0;
                hlsColor.L = max;
                return(hlsColor);
            }

            /* If we get to this point, we know we don't have a shade of gray. */

            // Set L
            hlsColor.L = (min + max) / 2;

            // Set S
            if (hlsColor.L < 0.5)
            {
                hlsColor.S = delta / (max + min);
            }
            else
            {
                hlsColor.S = delta / (2.0 - max - min);
            }

            // Set H
            if (r == max)
            {
                hlsColor.H = (g - b) / delta;
            }
            if (g == max)
            {
                hlsColor.H = 2.0 + (b - r) / delta;
            }
            if (b == max)
            {
                hlsColor.H = 4.0 + (r - g) / delta;
            }
            hlsColor.H *= 60;
            if (hlsColor.H < 0)
            {
                hlsColor.H += 360;
            }

            // Set A
            hlsColor.A = a;

            // Set return value
            return(hlsColor);
        }
Example #41
0
 private SolidColorBrush ConvertColorStringToBrush(string colorStr)
 {
     System.Windows.Media.Color customColor = (System.Windows.Media.Color)ColorConverter.ConvertFromString(colorStr);
     return(new SolidColorBrush(customColor));
 }
Example #42
0
 private void ColorHorizontalSlider_ColorChanged(object sender, System.Windows.Media.Color color)
 {
     ColorSliderHorizontalFromEvent.Fill = new SolidColorBrush(color);
     ColorSliderSetViaEvent.Color        = color;
 }
Example #43
0
        public static ImageSource ThemeImage(DependencyObject owner, BitmapSource source)
        {
            Color background = ImageThemingUtilities.GetImageBackgroundColor(owner);

            return(ImageThemingUtilities.GetOrCreateThemedBitmapSource(source, background, true, Colors.Black, false));
        }
        private void rctSelectColor_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Forms.ColorDialog dialog       = new System.Windows.Forms.ColorDialog();
            System.Windows.Media.Color       currentColor = ((SolidColorBrush)((System.Windows.Shapes.Rectangle)sender).Fill).Color;
            System.Drawing.Color             initColor    = System.Drawing.Color.FromArgb(255, currentColor.R, currentColor.G, currentColor.B);

            List <Int32> baseColors = new List <Int32>()
            {
                -32640,
                -128,
                -8323200,
                -16711808,
                -8323073,
                -16744193,
                -32576,
                -32513,

                -65536,
                -256,
                -8323328,
                -16711872,
                -16711681,
                -16744256,
                -8355648,
                -65281,

                -8372160,
                -32704,
                -16711936,
                -16744320,
                -16760704,
                -8355585,
                -8388544,
                -65408,

                -8388608,
                -32768,
                -16744448,
                -16744384,
                -16776961,
                -16777056,
                -8388480,
                -8388353,

                -12582912,
                -32768,
                -16744448,
                -16744384,
                -16776961,
                -16777056,
                -8388480,
                -8388353,

                -12582912,
                -8372224,
                -16760832,
                -16760768,
                -16777088,
                -16777152,
                -12582848,
                -12582784,

                -16777216,
                -8355840,
                -8355776,
                -8355712,
                -12550016,
                -4144960,
                -12582848,
                -1
            };

            Int32 initColorString = initColor.ToArgb();

            if (baseColors.Contains(initColorString))
            {
                dialog.Color = initColor;
            }

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ((System.Windows.Shapes.Rectangle)sender).Fill = new SolidColorBrush(Color.FromRgb(dialog.Color.R, dialog.Color.G, dialog.Color.B));
                //LayerProvider.UseCustomColors = true;

                Int32 colValue = dialog.Color.ToArgb();

                // LayerProvider.CustomColorsDictionary.Add(((System.Windows.Shapes.Rectangle)sender).Name, Color.FromRgb(dialog.Color.R, dialog.Color.G, dialog.Color.B));

                ((SolidColorBrush)((System.Windows.Shapes.Rectangle)sender).Fill).Color = Color.FromRgb(dialog.Color.R, dialog.Color.G, dialog.Color.B);


                if (((System.Windows.Shapes.Rectangle)sender).Tag is String && ((String)((System.Windows.Shapes.Rectangle)sender).Tag) == "Reset_Legend")
                {
                    //Reset_Legend();
                }
            }
        }
Example #45
0
        public static BitmapImage Icon(System.Windows.Media.Color color)
        {
            /*
             * <?xml version="1.0" encoding="utf-8"?>
             * <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_graph_bar" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
             *      <Path Width="42" Height="38" Canvas.Left="17" Canvas.Top="19" Stretch="Fill" Fill="#FF000000" Data="F1 M 22,52L 22,35L 30,35L 30,52L 22,52 Z M 32,52L 32,22L 39,22L 39,52L 32,52 Z M 41,52L 41,41L 49,41L 49,52L 41,52 Z M 51,52L 51,29L 59,29L 59,52L 51,52 Z M 17,19L 20,19L 20,54L 59,54L 59,57L 17,57L 17,19 Z "/>
             * </Canvas>
             *
             *
             * http://modernuiicons.com/
             *
             * <?xml version="1.0" encoding="utf-8"?>
             * <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_social_aws" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
             *      <Path Width="37.9996" Height="36.7333" Canvas.Left="19.025" Canvas.Top="20.0616" Stretch="Fill" Fill="#FF000000" Data="F1 M 38.0081,29.8002L 53.5133,24.7558L 38.0081,20.0616L 22.1469,24.7558M 40.077,56.795L 57.0245,51.0045L 57.0245,27.2965L 40.1327,32.5388M 19.025,27.1398L 35.9134,32.617L 35.9134,56.7162L 19.1348,51.0045"/>
             * </Canvas>
             *
             * <?xml version="1.0" encoding="utf-8"?>
             * <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_tiles_add" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
             *      <Path Width="40" Height="40" Canvas.Left="18" Canvas.Top="18" Stretch="Fill" Fill="#FF000000" Data="F1 M 18,40L 36,40L 36,58L 18,58L 18,40 Z M 40,58L 40,40L 58,40L 58,58L 40,58 Z M 40,36L 40,18L 58,18L 58,36L 40,36 Z M 29,36L 25,36L 25,29L 18,29L 18,25L 25,25L 25,18L 29,18L 29,25L 36,25L 36,29L 29,29L 29,36 Z "/>
             * </Canvas>
             */

            var canvas = new Canvas
            {
                Width      = 36,
                Height     = 36,
                Background = new SolidColorBrush(Colors.Transparent)
            };
            //var canvas = new Canvas
            //{
            //    Width = 24,
            //    Height = 24,
            //    Background = new SolidColorBrush(Colors.Transparent)
            //};

            //var path = new System.Windows.Shapes.Path()
            //{
            //    //Data = Geometry.Parse("F1 M 22,52L 22,35L 30,35L 30,52L 22,52 Z M 32,52L 32,22L 39,22L 39,52L 32,52 Z M 41,52L 41,41L 49,41L 49,52L 41,52 Z M 51,52L 51,29L 59,29L 59,52L 51,52 Z M 17,19L 20,19L 20,54L 59,54L 59,57L 17,57L 17,19 Z "),
            //    //Data = Geometry.Parse("F1 M 38.0081,29.8002L 53.5133,24.7558L 38.0081,20.0616L 22.1469,24.7558M 40.077,56.795L 57.0245,51.0045L 57.0245,27.2965L 40.1327,32.5388M 19.025,27.1398L 35.9134,32.617L 35.9134,56.7162L 19.1348,51.0045"),
            //    Data = Geometry.Parse("F1 M 18,40L 36,40L 36,58L 18,58L 18,40 Z M 40,58L 40,40L 58,40L 58,58L 40,58 Z M 40,36L 40,18L 58,18L 58,36L 40,36 Z M 29,36L 25,36L 25,29L 18,29L 18,25L 25,25L 25,18L 29,18L 29,25L 36,25L 36,29L 29,29L 29,36 Z "),
            //    Stretch = Stretch.Fill,
            //    Fill = new SolidColorBrush(color),
            //    Width = 36,
            //    Height = 36,
            //};
            var path = new System.Windows.Shapes.Path()
            {
                //Data = Geometry.Parse("F1 M 22,52L 22,35L 30,35L 30,52L 22,52 Z M 32,52L 32,22L 39,22L 39,52L 32,52 Z M 41,52L 41,41L 49,41L 49,52L 41,52 Z M 51,52L 51,29L 59,29L 59,52L 51,52 Z M 17,19L 20,19L 20,54L 59,54L 59,57L 17,57L 17,19 Z "),
                //Data = Geometry.Parse("F1 M 38.0081,29.8002L 53.5133,24.7558L 38.0081,20.0616L 22.1469,24.7558M 40.077,56.795L 57.0245,51.0045L 57.0245,27.2965L 40.1327,32.5388M 19.025,27.1398L 35.9134,32.617L 35.9134,56.7162L 19.1348,51.0045"),
                //Data = Geometry.Parse("F1 M 18,40L 36,40L 36,58L 18,58L 18,40 Z M 40,58L 40,40L 58,40L 58,58L 40,58 Z M 40,36L 40,18L 58,18L 58,36L 40,36 Z M 29,36L 25,36L 25,29L 18,29L 18,25L 25,25L 25,18L 29,18L 29,25L 36,25L 36,29L 29,29L 29,36 Z "),
                Data    = Geometry.Parse("M4,3C2.89,3 2,3.89 2,5V15A2,2 0 0,0 4,17H12V22L15,19L18,22V17H20A2,2 0 0,0 22,15V8L22,6V5A2,2 0 0,0 20,3H16V3H4M12,5L15,7L18,5V8.5L21,10L18,11.5V15L15,13L12,15V11.5L9,10L12,8.5V5M4,5H9V7H4V5M4,9H7V11H4V9M4,13H9V15H4V13Z"),
                Stretch = Stretch.Fill,
                Fill    = new SolidColorBrush(color),
                Width   = 36,
                Height  = 36,
            };

            canvas.Children.Add(path);

            var size = new System.Windows.Size(36, 36);

            canvas.Measure(size);
            canvas.Arrange(new Rect(size));

            var rtb = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);

            rtb.Render(canvas);

            var png = new PngBitmapEncoder();

            png.Frames.Add(BitmapFrame.Create(rtb));

            using (var memory = new MemoryStream())
            {
                png.Save(memory);
                memory.Position = 0;

                var bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = memory;
                bitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                bitmapImage.EndInit();

                return(bitmapImage);
            }
        }
Example #46
0
 public void SetShapesColor(System.Windows.Media.Color color, bool doRandom)
 {
     this.doRandomColors = doRandom;
     this.baseColor      = color;
 }
Example #47
0
 public static string ConvertColor(Color current)
 {
     return($"#{current.R:X2}{current.G:X2}{current.B:X2}");
 }
Example #48
0
        public void Init(Syscalls syscalls, Core core, Runtime runtime)
        {
            PhoneApplicationFrame frame = (PhoneApplicationFrame)Application.Current.RootVisual;
            double screenWidth          = System.Windows.Application.Current.Host.Content.ActualWidth;
            double screenHeight         = System.Windows.Application.Current.Host.Content.ActualHeight;

            if ((int)screenHeight == 0)
            {
                throw new Exception("screenHeight");
            }
            PhoneApplicationPage mainPage = (PhoneApplicationPage)frame.Content;

            mMainImage = new Image();


            mainPage.Width    = screenWidth;
            mainPage.Height   = screenHeight;
            mMainImage.Width  = screenWidth;
            mMainImage.Height = screenHeight;
            mainPage.Content  = mMainImage;

            mClipRect.X      = 0.0;
            mClipRect.Y      = 0.0;
            mClipRect.Width  = screenWidth;
            mClipRect.Height = screenHeight;

            // no apparent effect on memory leaks.
            runtime.RegisterCleaner(delegate()
            {
                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    mainPage.Content = null;
                });
            });

            mBackBuffer = new WriteableBitmap(
                (int)screenWidth,
                (int)screenHeight);
            mFrontBuffer = new WriteableBitmap(
                (int)screenWidth,
                (int)screenHeight);

            mMainImage.Source = mFrontBuffer;

            // clear front and backbuffer.
            for (int i = 0; i < mFrontBuffer.PixelWidth * mFrontBuffer.PixelHeight; i++)
            {
                mBackBuffer.Pixels[i] = mBackBuffer.Pixels[i] = (int)(0xff << 24);
            }

            mCurrentDrawTarget = mBackBuffer;

            mCurrentWindowsColor = System.Windows.Media.Color.FromArgb(0xff,
                                                                       (byte)(mCurrentColor >> 16),
                                                                       (byte)(mCurrentColor >> 8),
                                                                       (byte)(mCurrentColor));

            syscalls.maSetColor = delegate(int rgb)
            {
                int oldColor = (int)mCurrentColor;
                mCurrentColor        = 0xff000000 | (uint)(rgb & 0xffffff);
                mCurrentWindowsColor = System.Windows.Media.Color.FromArgb(0xff,
                                                                           (byte)(mCurrentColor >> 16),
                                                                           (byte)(mCurrentColor >> 8),
                                                                           (byte)(mCurrentColor));
                return(oldColor & 0xffffff);
            };

            syscalls.maSetClipRect = delegate(int x, int y, int w, int h)
            {
                MoSync.GraphicsUtil.ClipRectangle(
                    x, y, w, h,
                    0, 0, mCurrentDrawTarget.PixelWidth, mCurrentDrawTarget.PixelHeight,
                    out x, out y, out w, out h);

                mClipRect.X      = x;
                mClipRect.Y      = y;
                mClipRect.Width  = w;
                mClipRect.Height = h;
            };

            syscalls.maGetClipRect = delegate(int cliprect)
            {
                Memory mem = core.GetDataMemory();
                mem.WriteInt32(cliprect + MoSync.Struct.MARect.left, (int)mClipRect.X);
                mem.WriteInt32(cliprect + MoSync.Struct.MARect.top, (int)mClipRect.Y);
                mem.WriteInt32(cliprect + MoSync.Struct.MARect.width, (int)mClipRect.Width);
                mem.WriteInt32(cliprect + MoSync.Struct.MARect.height, (int)mClipRect.Height);
            };

            syscalls.maPlot = delegate(int x, int y)
            {
                mCurrentDrawTarget.SetPixel(x, y, (int)mCurrentColor);
            };

            syscalls.maUpdateScreen = delegate()
            {
                //System.Array.Copy(mBackBuffer.Pixels, mFrontBuffer.Pixels, mFrontBuffer.PixelWidth * mFrontBuffer.PixelHeight);
                System.Buffer.BlockCopy(mBackBuffer.Pixels, 0, mFrontBuffer.Pixels, 0, mFrontBuffer.PixelWidth * mFrontBuffer.PixelHeight * 4);
                InvalidateWriteableBitmapOnMainThread(mFrontBuffer);
            };

            syscalls.maFillRect = delegate(int x, int y, int w, int h)
            {
                // this function has a bug (it only fills one pixel less than the image.)
                //mCurrentDrawTarget.FillRectangle(x, y, x + w, y + h, (int)mCurrentColor);

                MoSync.GraphicsUtil.ClipRectangle(
                    x, y, w, h,
                    0, 0, mCurrentDrawTarget.PixelWidth, mCurrentDrawTarget.PixelHeight,
                    out x, out y, out w, out h);

                MoSync.GraphicsUtil.ClipRectangle(
                    x, y, w, h,
                    (int)mClipRect.X, (int)mClipRect.Y, (int)mClipRect.Width, (int)mClipRect.Height,
                    out x, out y, out w, out h);

                if (w <= 0 || h <= 0)
                {
                    return;
                }

                int index = x + y * mCurrentDrawTarget.PixelWidth;
                while (h-- != 0)
                {
                    int width = w;
                    while (width-- != 0)
                    {
                        mCurrentDrawTarget.Pixels[index] = (int)mCurrentColor;
                        index++;
                    }
                    index += -w + mCurrentDrawTarget.PixelWidth;
                }
            };

            syscalls.maLine = delegate(int x1, int y1, int x2, int y2)
            {
                GraphicsUtil.Point p1 = new GraphicsUtil.Point(x1, y1);
                GraphicsUtil.Point p2 = new GraphicsUtil.Point(x2, y2);
                if (!GraphicsUtil.ClipLine(p1, p2, (int)mClipRect.X, (int)(mClipRect.X + mClipRect.Width),
                                           (int)mClipRect.Y, (int)(mClipRect.Y + mClipRect.Height)))
                {
                    return;
                }

                mCurrentDrawTarget.DrawLine((int)p1.x, (int)p1.y, (int)p2.x, (int)p2.y, (int)mCurrentColor);
            };

            textBlock.FontSize = mCurrentFontSize;

            syscalls.maDrawText = delegate(int left, int top, int str)
            {
                String text = core.GetDataMemory().ReadStringAtAddress(str);
                if (text.Length == 0)
                {
                    return;
                }
                DrawText(text, left, top);
            };

            syscalls.maGetTextSize = delegate(int str)
            {
                String text       = core.GetDataMemory().ReadStringAtAddress(str);
                int    textWidth  = 0;
                int    textHeight = 0;
                GetTextSize(text, out textWidth, out textHeight);
                return(MoSync.Util.CreateExtent(textWidth, textHeight));
            };

            syscalls.maDrawTextW = delegate(int left, int top, int str)
            {
                String text = core.GetDataMemory().ReadWStringAtAddress(str);
                if (text.Length == 0)
                {
                    return;
                }

                DrawText(text, left, top);
            };

            syscalls.maGetTextSizeW = delegate(int str)
            {
                String text       = core.GetDataMemory().ReadWStringAtAddress(str);
                int    textWidth  = 0;
                int    textHeight = 0;
                GetTextSize(text, out textWidth, out textHeight);
                return(MoSync.Util.CreateExtent(textWidth, textHeight));
            };

            syscalls.maFillTriangleFan = delegate(int points, int count)
            {
                int[] newPoints = new int[count * 2 + 2];
                for (int i = 0; i < count; i++)
                {
                    newPoints[i * 2 + 0] = core.GetDataMemory().ReadInt32(points + i * 8 + MoSync.Struct.MAPoint2d.x);
                    newPoints[i * 2 + 1] = core.GetDataMemory().ReadInt32(points + i * 8 + MoSync.Struct.MAPoint2d.y);
                }
                newPoints[count * 2 + 0] = core.GetDataMemory().ReadInt32(points + MoSync.Struct.MAPoint2d.x);
                newPoints[count * 2 + 1] = core.GetDataMemory().ReadInt32(points + MoSync.Struct.MAPoint2d.y);
                mCurrentDrawTarget.FillPolygon(newPoints, (int)mCurrentColor);
            };

            syscalls.maFillTriangleStrip = delegate(int points, int count)
            {
                int[] xcoords = new int[count];
                int[] ycoords = new int[count];

                for (int i = 0; i < count; i++)
                {
                    xcoords[i] = core.GetDataMemory().ReadInt32(points + i * 8 + MoSync.Struct.MAPoint2d.x);
                    ycoords[i] = core.GetDataMemory().ReadInt32(points + i * 8 + MoSync.Struct.MAPoint2d.y);
                }

                for (int i = 2; i < count; i++)
                {
                    mCurrentDrawTarget.FillTriangle(
                        xcoords[i - 2], ycoords[i - 2],
                        xcoords[i - 1], ycoords[i - 1],
                        xcoords[i - 0], ycoords[i - 0],
                        (int)mCurrentColor);
                }
            };

            syscalls.maSetDrawTarget = delegate(int drawTarget)
            {
                int oldDrawTarget = mCurrentDrawTargetIndex;
                if (drawTarget == mCurrentDrawTargetIndex)
                {
                    return(oldDrawTarget);
                }
                if (drawTarget == MoSync.Constants.HANDLE_SCREEN)
                {
                    mCurrentDrawTarget      = mBackBuffer;
                    mCurrentDrawTargetIndex = drawTarget;
                    return(oldDrawTarget);
                }

                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, drawTarget);
                mCurrentDrawTarget      = (WriteableBitmap)res.GetInternalObject();
                mCurrentDrawTargetIndex = drawTarget;
                return(oldDrawTarget);
            };

            syscalls.maGetScrSize = delegate()
            {
                return(MoSync.Util.CreateExtent(mBackBuffer.PixelWidth, mBackBuffer.PixelHeight));
            };

            syscalls.maGetImageSize = delegate(int handle)
            {
                Resource     res = runtime.GetResource(MoSync.Constants.RT_IMAGE, handle);
                BitmapSource src = (BitmapSource)res.GetInternalObject();
                if (src == null)
                {
                    MoSync.Util.CriticalError("maGetImageSize used with an invalid image resource.");
                }
                int w = 0, h = 0;

                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    w = src.PixelWidth;
                    h = src.PixelHeight;
                });

                return(MoSync.Util.CreateExtent(w, h));
            };

            syscalls.maDrawImage = delegate(int image, int left, int top)
            {
                Resource        res     = runtime.GetResource(MoSync.Constants.RT_IMAGE, image);
                WriteableBitmap src     = (WriteableBitmap)res.GetInternalObject();
                Rect            srcRect = new Rect(0, 0, src.PixelWidth, src.PixelHeight);
                Rect            dstRect = new Rect(left, top, src.PixelWidth, src.PixelHeight);
                mCurrentDrawTarget.Blit(dstRect, src, srcRect, WriteableBitmapExtensions.BlendMode.Alpha);
            };

            syscalls.maDrawImageRegion = delegate(int image, int srcRectPtr, int dstPointPtr, int transformMode)
            {
                Resource        res = runtime.GetResource(MoSync.Constants.RT_IMAGE, image);
                WriteableBitmap src = (WriteableBitmap)res.GetInternalObject();

                Memory dataMemory = core.GetDataMemory();
                int    srcRectX   = dataMemory.ReadInt32(srcRectPtr + MoSync.Struct.MARect.left);
                int    srcRectY   = dataMemory.ReadInt32(srcRectPtr + MoSync.Struct.MARect.top);
                int    srcRectW   = dataMemory.ReadInt32(srcRectPtr + MoSync.Struct.MARect.width);
                int    srcRectH   = dataMemory.ReadInt32(srcRectPtr + MoSync.Struct.MARect.height);
                int    dstPointX  = dataMemory.ReadInt32(dstPointPtr + MoSync.Struct.MAPoint2d.x);
                int    dstPointY  = dataMemory.ReadInt32(dstPointPtr + MoSync.Struct.MAPoint2d.y);

                Rect srcRect = new Rect(srcRectX, srcRectY, srcRectW, srcRectH);
                Rect dstRect = new Rect(dstPointX, dstPointY, srcRectW, srcRectH);

                GraphicsUtil.DrawImageRegion(mCurrentDrawTarget, dstPointX, dstPointY, srcRect, src, transformMode, mClipRect);
            };

            syscalls.maCreateDrawableImage = delegate(int placeholder, int width, int height)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_PLACEHOLDER, placeholder);
                res.SetResourceType(MoSync.Constants.RT_IMAGE);
                WriteableBitmap bitmap = null;

                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    bitmap = new WriteableBitmap(width, height);

                    for (int i = 0; i < bitmap.PixelWidth * bitmap.PixelHeight; i++)
                    {
                        bitmap.Pixels[i] = (int)(0xff << 24);
                    }
                });

                if (bitmap == null)
                {
                    return(MoSync.Constants.RES_OUT_OF_MEMORY);
                }
                res.SetInternalObject(bitmap);
                return(MoSync.Constants.RES_OK);
            };

            syscalls.maCreateImageRaw = delegate(int _placeholder, int _src, int _size, int _alpha)
            {
                int width  = MoSync.Util.ExtentX(_size);
                int height = MoSync.Util.ExtentY(_size);

                WriteableBitmap bitmap = null;
                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    bitmap = new WriteableBitmap(width, height);
                });

                //core.GetDataMemory().ReadIntegers(bitmap.Pixels, _src, width * height);
                bitmap.FromByteArray(core.GetDataMemory().GetData(), _src, width * height * 4);
                if (_alpha == 0)
                {
                    int[] pixels    = bitmap.Pixels;
                    int   numPixels = width * height;
                    for (int i = 0; i < numPixels; i++)
                    {
                        pixels[i] = (int)((uint)pixels[i] | 0xff000000);
                    }
                }

                Resource res = runtime.GetResource(MoSync.Constants.RT_PLACEHOLDER, _placeholder);
                res.SetInternalObject(bitmap);
                res.SetResourceType(MoSync.Constants.RT_IMAGE);
                return(MoSync.Constants.RES_OK);
            };

            syscalls.maDrawRGB = delegate(int _dstPoint, int _src, int _srcRect, int _scanlength)
            {
                Memory dataMemory = core.GetDataMemory();
                int    dstX       = dataMemory.ReadInt32(_dstPoint + MoSync.Struct.MAPoint2d.x);
                int    dstY       = dataMemory.ReadInt32(_dstPoint + MoSync.Struct.MAPoint2d.y);
                int    srcRectX   = dataMemory.ReadInt32(_srcRect + MoSync.Struct.MARect.left);
                int    srcRectY   = dataMemory.ReadInt32(_srcRect + MoSync.Struct.MARect.top);
                int    srcRectW   = dataMemory.ReadInt32(_srcRect + MoSync.Struct.MARect.width);
                int    srcRectH   = dataMemory.ReadInt32(_srcRect + MoSync.Struct.MARect.height);
                int[]  pixels     = mCurrentDrawTarget.Pixels;
                // todo: clipRect

                _scanlength *= 4;                 // sizeof(int)

                for (int h = 0; h < srcRectH; h++)
                {
                    int pixelIndex = dstY * mCurrentDrawTarget.PixelWidth + dstX;
                    int address    = _src + (srcRectY + h) * _scanlength;
                    for (int w = 0; w < srcRectW; w++)
                    {
                        uint srcPixel = dataMemory.ReadUInt32(address);
                        uint dstPixel = (uint)pixels[pixelIndex];

                        uint srcPixelR = (srcPixel & 0x00ff0000) >> 16;
                        uint srcPixelG = (srcPixel & 0x0000ff00) >> 8;
                        uint srcPixelB = (srcPixel & 0x000000ff) >> 0;
                        uint srcPixelA = (srcPixel & 0xff000000) >> 24;
                        uint dstPixelR = (dstPixel & 0x00ff0000) >> 16;
                        uint dstPixelG = (dstPixel & 0x0000ff00) >> 8;
                        uint dstPixelB = (dstPixel & 0x000000ff) >> 0;
                        uint dstPixelA = (dstPixel & 0xff000000) >> 24;

                        dstPixelR += ((srcPixelR - dstPixelR) * srcPixelA) / 255;
                        dstPixelG += ((srcPixelG - dstPixelG) * srcPixelA) / 255;
                        dstPixelB += ((srcPixelB - dstPixelB) * srcPixelA) / 255;

                        dstPixel           = (dstPixelA << 24) | (dstPixelR << 16) | (dstPixelG << 8) | (dstPixelB);
                        pixels[pixelIndex] = (int)dstPixel;

                        address += 4;
                        pixelIndex++;
                    }

                    dstY++;
                }
            };

            syscalls.maGetImageData = delegate(int _image, int _dst, int _srcRect, int _scanlength)
            {
                Resource        res        = runtime.GetResource(MoSync.Constants.RT_IMAGE, _image);
                WriteableBitmap src        = (WriteableBitmap)res.GetInternalObject();
                Memory          dataMemory = core.GetDataMemory();
                int             srcRectX   = dataMemory.ReadInt32(_srcRect + MoSync.Struct.MARect.left);
                int             srcRectY   = dataMemory.ReadInt32(_srcRect + MoSync.Struct.MARect.top);
                int             srcRectW   = dataMemory.ReadInt32(_srcRect + MoSync.Struct.MARect.width);
                int             srcRectH   = dataMemory.ReadInt32(_srcRect + MoSync.Struct.MARect.height);
                int             lineDst    = _dst;
                byte[]          data       = src.ToByteArray(srcRectY * src.PixelWidth,
                                                             srcRectH * src.PixelWidth); // BlockCopy?
                byte[] coreArray = dataMemory.GetData();
                for (int y = 0; y < srcRectH; y++)
                {
                    System.Array.Copy(data, y * src.PixelWidth * 4, coreArray,
                                      lineDst, src.PixelWidth * 4);
                    lineDst += _scanlength * 4;
                }
            };

            syscalls.maCreateImageFromData = delegate(int _placeholder, int _data, int _offset, int _size)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                if (res == null)
                {
                    return(MoSync.Constants.RES_BAD_INPUT);
                }
                Stream bin = (Stream)res.GetInternalObject();
                if (bin == null)
                {
                    return(MoSync.Constants.RES_BAD_INPUT);
                }
                BoundedStream   s      = new BoundedStream(bin, _offset, _size);
                WriteableBitmap bitmap = MoSync.Util.CreateWriteableBitmapFromStream(s);
                s.Close();

                if (bitmap == null)
                {
                    return(MoSync.Constants.RES_BAD_INPUT);
                }

                Resource imageRes = runtime.GetResource(MoSync.Constants.RT_PLACEHOLDER, _placeholder);
                imageRes.SetInternalObject(bitmap);
                imageRes.SetResourceType(MoSync.Constants.RT_IMAGE);
                return(MoSync.Constants.RES_OK);
            };
        }
Example #49
0
 public override int Value(System.Windows.Media.Color color)
 {
     return(Convert.ToInt32(sModel.LComponent(color)));
 }
Example #50
0
 public static Color ConvertColor(string hexstr, Color current)
 {
     return(TryConvertColor(hexstr) ?? current);
 }
 /// <summary>
 /// Draw a highlight around the element with the given settings.
 /// </summary>
 /// <param name="blocking">Flag to indicate if further execution waits until the highlight is removed.</param>
 /// <param name="color">The color to draw the highlight.</param>
 /// <param name="duration">The duration (im ms) how long the highlight is shown.</param>
 /// <remarks>Override for winforms color.</remarks>
 public AutomationElement DrawHighlight(bool blocking, GdiColor color, TimeSpan duration)
 {
     return(this.DrawHighlight(blocking, WpfColor.FromArgb(color.A, color.R, color.G, color.B), duration));
 }
Example #52
0
        public override void UpdateNormalBitmap(System.Windows.Media.Imaging.WriteableBitmap bitmap, System.Windows.Media.Color color)
        {
            unsafe {
                bitmap.Lock();
                int    currentPixel = -1;
                byte * pStart       = (byte *)(void *)bitmap.BackBuffer;
                double iRowUnit     = (double)100 / 256;
                double iRowCurrent  = 100;
                double a            = sModel.AComponent(color);
                double b            = sModel.BComponent(color);
                for (int iRow = 0; iRow < bitmap.PixelHeight; iRow++)
                {
                    Color lightness = sModel.Color(iRowCurrent, a, b);
                    for (int iCol = 0; iCol < bitmap.PixelWidth; iCol++)
                    {
                        currentPixel++;
                        *(pStart + currentPixel * 3 + 0) = lightness.B;                         //Blue
                        *(pStart + currentPixel * 3 + 1) = lightness.G;                         //Green
                        *(pStart + currentPixel * 3 + 2) = lightness.R;                         //red
                    }

                    iRowCurrent -= iRowUnit;
                }

                bitmap.AddDirtyRect(new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight));
                bitmap.Unlock();
            }
        }
 public static System.Drawing.Color ToSystemDrawing(this System.Windows.Media.Color c)
 {
     return(System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B));
 }
 /// <summary>
 /// Draws a manually colored highlight around the element.
 /// </summary>
 public AutomationElement DrawHighlight(WpfColor color)
 {
     return(this.DrawHighlight(blocking: true, color: color, duration: TimeSpan.FromMilliseconds(2000)));
 }
Example #55
0
 public static System.Windows.Media.Color makeColorN(string HexString)
 {
     System.Windows.Media.Color color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(HexString);
     return(color);
 }
        private void UpdateUIColors()
        {
            var defaultBackground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
            var defaultForeground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey);

            System.Drawing.Color c = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);

            SolidColorBrush backgroundCol = new SolidColorBrush(ThemeHelper.ToMediaColor(defaultBackground));

            switch (ThemeHelper.GetTheme())
            {
            case ThemeHelper.eVSTheme.kDark:
                foregroundColor        = Color.FromRgb(255, 255, 255);
                subOptionsColor        = Color.FromRgb(130, 203, 247);
                explainOptColor        = Color.FromRgb(255, 255, 255);
                WindowTitle.Foreground = new SolidColorBrush(Color.FromRgb(186, 255, 171));
                WindowTitle.Background = new SolidColorBrush(ThemeHelper.ToMediaColor(defaultBackground));
                Background             = backgroundCol;
                //listView.Background = backgroundCol;
                break;

            case ThemeHelper.eVSTheme.kBlue:
                foregroundColor        = Color.FromRgb(0, 0, 0);
                subOptionsColor        = Color.FromRgb(100, 106, 106);
                explainOptColor        = Color.FromRgb(0, 0, 0);
                WindowTitle.Foreground = new SolidColorBrush(Color.FromRgb(83, 114, 76));
                WindowTitle.Background = new SolidColorBrush(ThemeHelper.ToMediaColor(defaultBackground));
                Background             = backgroundCol;
                //.Background = backgroundCol;
                break;

            case ThemeHelper.eVSTheme.kLight:
                foregroundColor        = Color.FromRgb(0, 0, 0);
                subOptionsColor        = Color.FromRgb(100, 106, 106);
                explainOptColor        = Color.FromRgb(0, 0, 0);
                WindowTitle.Foreground = new SolidColorBrush(Color.FromRgb(83, 114, 76));
                WindowTitle.Background = backgroundCol;
                Background             = backgroundCol;
                //listView.Background = backgroundCol;
                break;

            case ThemeHelper.eVSTheme.kUnknown:
            //break;
            default:
                byte a = defaultForeground.A;
                byte r = defaultForeground.R;
                byte g = defaultForeground.G;
                byte b = defaultForeground.B;
                foregroundColor        = Color.FromArgb(a, r, g, b);
                subOptionsColor        = Color.FromArgb(a, r, g, b);
                explainOptColor        = Color.FromArgb(a, r, g, b);
                WindowTitle.Foreground = new SolidColorBrush(foregroundColor);
                WindowTitle.Background = new SolidColorBrush(ThemeHelper.ToMediaColor(defaultBackground));
                Dispatcher.BeginInvoke(new System.Action(() => MessageBox.Show("Spotify extension couldn't detect color scheme. \nWould you be so kind to file a bug report?")));
                break;
            }
            //SetListViewColors(foregroundColor);
            UpdateSettingsTitles(foregroundColor);
            UpdateSettingsSubOptions(subOptionsColor);
            UpdateExplainationSettings(explainOptColor);
        }
Example #57
0
 public static System.Drawing.Color ToNet2Color(this System.Windows.Media.Color color)
 {
     return(System.Drawing.Color.FromArgb(color.R, color.G, color.B));
 }
Example #58
0
 protected override byte QuantizePixel(Color pixel)
 {
     return(MapColor(pixel.B, pixel.G, pixel.R));
 }
 private void Refresh_IC_BackColor()
 {
     System.Windows.Media.Color windowColor = (this.Background as SolidColorBrush).Color;
     IC_Control.BackColor = System.Drawing.Color.FromArgb(windowColor.A, windowColor.R, windowColor.G, windowColor.B);
     Host.Background      = new SolidColorBrush(windowColor);
 }
Example #60
0
 public static void WriteElementColor(this System.Xml.XmlWriter writer, string elementName, System.Windows.Media.Color color)
 {
     writer.WriteStartElement("Color");
     writer.WriteAttributeString("Name", elementName);
     writer.WriteAttributeString("R", color.R.ToString());
     writer.WriteAttributeString("G", color.G.ToString());
     writer.WriteAttributeString("B", color.B.ToString());
     writer.WriteEndElement();
 }