Exemple #1
0
        private static void InitColors(Type tConsole)
        {
            const BindingFlags BINDING_FLAGS = BindingFlags.Public | BindingFlags.Static;

            var sfc = tConsole.GetMethod("set_ForegroundColor", BINDING_FLAGS);
            var sbc = tConsole.GetMethod("set_BackgroundColor", BINDING_FLAGS);
            var gfc = tConsole.GetMethod("get_ForegroundColor", BINDING_FLAGS);
            var gbc = tConsole.GetMethod("get_BackgroundColor", BINDING_FLAGS);

            _setForegroundColor = sfc != null
                                      ? (SetColorDelegate)Delegate.CreateDelegate(typeof(SetColorDelegate), sfc)
                                      : (value => {});

            _setBackgroundColor = sbc != null
                                      ? (SetColorDelegate)Delegate.CreateDelegate(typeof(SetColorDelegate), sbc)
                                      : (value => {});

            _getForegroundColor = gfc != null
                                      ? (GetColorDelegate)Delegate.CreateDelegate(typeof(GetColorDelegate), gfc)
                                      : (() => ConsoleColor.Gray);

            _getBackgroundColor = gbc != null
                                      ? (GetColorDelegate)Delegate.CreateDelegate(typeof(GetColorDelegate), gbc)
                                      : (() => ConsoleColor.Black);
        }
Exemple #2
0
 void SetupDelegates()
 {
     updateServerLogDelegate        = new UpdateServerLogDelegate(UpdateServerLog);
     updateConnectionLabelsDelegate = new UpdateConnectionLabelsDelegate(UpdateConnectionLabels);
     closeFormDelegate = new CloseFormDelegate(CloseForm);
     getNameDelegate   = new GetNameDelegate(GetName);
     getColorDelegate  = new GetColorDelegate(GetColor);
 }
        /// <summary>
        /// Walks up the element's parent tree to find the color attached to the element.
        /// </summary>
        /// <param name="getter"></param>
        /// <param name="element"></param>
        /// <returns></returns>
        private static string LookupColor(GetColorDelegate getter, IHTMLElement2 element)
        {
            string color = getter(element);

            if (color == "transparent" && ((IHTMLElement)element).parentElement != null)
            {
                return(LookupColor(getter, (IHTMLElement2)((IHTMLElement)element).parentElement));
            }
            return(color);
        }
Exemple #4
0
        private Color GetForeColor()
        {
            if (!InvokeRequired)
            {
                return(base.ForeColor);
            }
            GetColorDelegate del = GetForeColor;

            return(Invoke(del) is Color ? (Color)Invoke(del) : new Color());
        }
Exemple #5
0
        private Color GetForeColor()
        {
            if (Parent == null || !Parent.InvokeRequired)
            {
                return(base.ForeColor);
            }
            GetColorDelegate del = GetForeColor;

            return(Parent.Invoke(del) is Color ? (Color)Parent.Invoke(del) : new Color());
        }
Exemple #6
0
        /// ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Standard ctor for everyone else.
        /// </summary>
        /// <param name="back">Delegate to provide a background color</param>
        /// <param name="fore">Delegate to provide a foreground color</param>
        /// <param name="font">Delegate to provide a font</param>
        public CustomCheckedListBox(GetColorDelegate back = null, GetColorDelegate fore = null, GetFontDelegate font = null)
        {
            GetForeColor = fore;
            GetBackColor = back;
            GetFont      = font;

            //******************************************************************
            // If you want to set the item height to a specific value that can
            // be independent of the font size, this is the place to do it.
            //******************************************************************
            ItemHeight = 14;
        }
        private static Color GetElementColor(GetColorDelegate getter, IHTMLElement element, Color defaultColor)
        {
            string colorString = LookupColor(getter, (IHTMLElement2)element);

            if (colorString != null)
            {
                string textColorHex = ParseColorToHex(colorString);
                Color  color        = GetColorFromHexColor(textColorHex, defaultColor);
                return(color);
            }
            return(defaultColor);
        }
        /// <summary>
        /// Creates texture atlas image from a given texture atlas
        /// </summary>
        /// <param name="atlasTextureLayout">Input texture atlas</param>
        /// <param name="srgb">True if the texture atlas should be generated to a SRgb texture</param>
        /// <returns></returns>
        public static Image CreateTextureAtlas(AtlasTextureLayout atlasTextureLayout, bool srgb)
        {
            var atlasTexture = Image.New2D(atlasTextureLayout.Width, atlasTextureLayout.Height, 1, srgb ? PixelFormat.R8G8B8A8_UNorm_SRgb : PixelFormat.R8G8B8A8_UNorm);

            unsafe
            {
                var ptr = (Color *)atlasTexture.DataPointer;

                // Clean the data
                for (var i = 0; i < atlasTexture.PixelBuffer[0].Height * atlasTexture.PixelBuffer[0].Width; ++i)
                {
                    ptr[i] = Color.Zero;
                }
            }

            // Fill in textureData from AtlasTextureLayout
            foreach (var element in atlasTextureLayout.Textures)
            {
                var isSourceRotated      = element.SourceRegion.IsRotated;
                var isDestinationRotated = element.DestinationRegion.IsRotated;
                var sourceTexture        = element.Texture;
                var sourceTextureWidth   = sourceTexture.Description.Width;

                var addressModeU = element.BorderModeU;
                var addressModeV = element.BorderModeV;
                var borderColor  = element.BorderColor;

                // calculate the source region guaranteed to be in the source texture.
                var sourceSize       = new Int2(sourceTexture.Description.Width, sourceTexture.Description.Height);
                var safeSourceRegion = new Rectangle
                {
                    X      = Math.Max(0, element.SourceRegion.X),
                    Y      = Math.Max(0, element.SourceRegion.Y),
                    Width  = Math.Min(sourceSize.X, element.SourceRegion.Right),
                    Height = Math.Min(sourceSize.Y, element.SourceRegion.Bottom),
                };
                safeSourceRegion.Width  -= safeSourceRegion.X;
                safeSourceRegion.Height -= safeSourceRegion.Y;

                // calculate the size of the source region and the starting offsets taking into account the rotation
                var sourceRegionSize   = new Int2(safeSourceRegion.Width, safeSourceRegion.Height);
                var destRegionSize     = new Int2(element.DestinationRegion.Width, element.DestinationRegion.Height);
                var sourceStartOffsets = new Int2(Math.Min(0, element.SourceRegion.X), Math.Min(0, element.SourceRegion.Y));
                if (isDestinationRotated)
                {
                    var oldSourceStartOffsetX = sourceStartOffsets.X;
                    if (isSourceRotated)
                    {
                        sourceStartOffsets.X = sourceStartOffsets.Y;
                        sourceStartOffsets.Y = sourceRegionSize.X - sourceStartOffsets.X - destRegionSize.Y + 2 * element.BorderSize;
                    }
                    else
                    {
                        sourceStartOffsets.X = sourceRegionSize.Y - sourceStartOffsets.Y - destRegionSize.X + 2 * element.BorderSize;
                        sourceStartOffsets.Y = oldSourceStartOffsetX;
                    }

                    Core.Utilities.Swap(ref sourceRegionSize.X, ref sourceRegionSize.Y);
                }

                {
                    var format = sourceTexture.Description.Format;
                    GetColorDelegate getPixel = GetColorBlack;
                    if (format == PixelFormat.R8G8B8A8_UNorm_SRgb || format == PixelFormat.R8G8B8A8_UNorm)
                    {
                        getPixel = GetColorRGBA;
                    }
                    if (format == PixelFormat.A8_UNorm || format == PixelFormat.R8_UNorm)
                    {
                        getPixel = GetColorRRR1;
                    }
                    if (format == PixelFormat.R8G8_UNorm)
                    {
                        getPixel = GetColorRG01;
                    }

                    for (var y = 0; y < element.DestinationRegion.Height; ++y)
                    {
                        for (var x = 0; x < element.DestinationRegion.Width; ++x)
                        {
                            // Get index of source image, if it's the border at this point sourceIndexX and sourceIndexY will be -1
                            var sourceCoordinateX = GetSourceTextureCoordinate(x - element.BorderSize + sourceStartOffsets.X, sourceRegionSize.X, addressModeU);
                            var sourceCoordinateY = GetSourceTextureCoordinate(y - element.BorderSize + sourceStartOffsets.Y, sourceRegionSize.Y, addressModeV);

                            // Check if this image uses border mode, and is in the border area
                            var isBorderMode = sourceCoordinateX < 0 || sourceCoordinateY < 0;

                            if (isDestinationRotated)
                            {
                                // Modify index for rotating
                                var tmp = sourceCoordinateY;

                                if (isSourceRotated)
                                {
                                    // Since intemediateTexture.DestinationRegion contains the border, we need to delete the border out
                                    sourceCoordinateY = sourceCoordinateX;
                                    sourceCoordinateX = safeSourceRegion.Width - 1 - tmp;
                                }
                                else
                                {
                                    // Since intemediateTexture.DestinationRegion contains the border, we need to delete the border out
                                    sourceCoordinateY = safeSourceRegion.Height - 1 - sourceCoordinateX;
                                    sourceCoordinateX = tmp;
                                }
                            }

                            // Add offset from the region
                            sourceCoordinateX += safeSourceRegion.X;
                            sourceCoordinateY += safeSourceRegion.Y;
                            var readFromIndex = sourceCoordinateY * sourceTextureWidth + sourceCoordinateX; // read index from source image

                            // Prepare writeToIndex
                            var targetCoordinateX = element.DestinationRegion.X + x;
                            var targetCoordinateY = element.DestinationRegion.Y + y;
                            var writeToIndex      = targetCoordinateY * atlasTextureLayout.Width + targetCoordinateX; // write index to atlas buffer

                            SetPixel(atlasTexture.DataPointer, writeToIndex, isBorderMode ? borderColor : getPixel(sourceTexture.DataPointer, readFromIndex));
                        }
                    }
                }
            }

            return(atlasTexture);
        }
Exemple #9
0
 public void testColorDelegate()
 {
     var d = new GetColorDelegate(Target);
 }
 /// <summary>
 /// Walks up the element's parent tree to find the color attached to the element.
 /// </summary>
 /// <param name="getter"></param>
 /// <param name="element"></param>
 /// <returns></returns>
 private static string LookupColor(GetColorDelegate getter, IHTMLElement2 element)
 {
     string color = getter(element);
     if (color == "transparent" && ((IHTMLElement)element).parentElement != null)
     {
         return LookupColor(getter, (IHTMLElement2)((IHTMLElement)element).parentElement);
     }
     return color;
 }
 private static Color GetElementColor(GetColorDelegate getter, IHTMLElement element, Color defaultColor)
 {
     string colorString = LookupColor(getter, (IHTMLElement2)element);
     if (colorString != null)
     {
         string textColorHex = ParseColorToHex(colorString);
         Color color = GetColorFromHexColor(textColorHex, defaultColor);
         return color;
     }
     return defaultColor;
 }
Exemple #12
0
 public void testColorDelegate()
 {
     var d = new GetColorDelegate(Target);
 }