Пример #1
0
 /// <summary>
 /// Initialize a new instance of the InternalStorage structure.
 /// </summary>
 public InternalStorage()
 {
     // Set to default values
     ContentImageH        = PaletteRelativeAlign.Inherit;
     ContentImageV        = PaletteRelativeAlign.Inherit;
     ContentEffect        = PaletteImageEffect.Inherit;
     ContentImageColorMap = Color.Empty;
     ContentImageColorTo  = Color.Empty;
 }
Пример #2
0
        /// <summary>
        /// Gets the effect applied to drawing of the image.
        /// </summary>
        /// <param name="state">Palette value should be applicable to this state.</param>
        /// <returns>PaletteImageEffect value.</returns>
        public override PaletteImageEffect GetContentImageEffect(PaletteState state)
        {
            if (_apply)
            {
                PaletteImageEffect ret = _primary.GetContentImageEffect(_override ? _state : state);

                if (ret == PaletteImageEffect.Inherit)
                {
                    ret = _backup.GetContentImageEffect(state);
                }

                return(ret);
            }
            else
            {
                return(_backup.GetContentImageEffect(state));
            }
        }
Пример #3
0
        /// <summary>
        /// Gets the effect applied to drawing of the image.
        /// </summary>
        /// <param name="state">Palette value should be applicable to this state.</param>
        /// <returns>PaletteImageEffect value.</returns>
        public virtual PaletteImageEffect GetContentImageEffect(PaletteState state)
        {
            if (Apply)
            {
                PaletteImageEffect ret = _primaryContent.GetContentImageEffect(Override ? OverrideState : state);

                if (ret == PaletteImageEffect.Inherit)
                {
                    ret = _backupContent.GetContentImageEffect(state);
                }

                return(ret);
            }
            else
            {
                return(_backupContent.GetContentImageEffect(state));
            }
        }
Пример #4
0
        /// <summary>
        /// Helper routine to draw an image taking into account various properties.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="image">Image to be drawn.</param>
        /// <param name="remapTransparent">Color that should become transparent.</param>
        /// <param name="imageRect">Destination rectangle.</param>
        /// <param name="orientation">Visual orientation.</param>
        /// <param name="effect">Drawing effect.</param>
        /// <param name="remapColor">Image color to remap.</param>
        /// <param name="remapNew">New color for remap.</param>
        protected static void DrawImageHelper(ViewContext context,
									          Image image,
                                              Color remapTransparent,
									          Rectangle imageRect,
									          VisualOrientation orientation,
									          PaletteImageEffect effect,
                                              Color remapColor,
                                              Color remapNew)
        {
            Debug.Assert(context != null);

            // Prevent problems with multiple threads using the same palette images
            // by only allowing a single thread to draw the provided image at a time
            lock (_threadLock)
            {
                // Validate reference parameter
                if (context == null) throw new ArgumentNullException("context");

                // Use image attributes class to modify image drawing for effects
                ImageAttributes attribs = new ImageAttributes();

                switch (effect)
                {
                    case PaletteImageEffect.Disabled:
                        attribs.SetColorMatrix(CommonHelper.MatrixDisabled);
                        break;
                    case PaletteImageEffect.GrayScale:
                        attribs.SetColorMatrix(_matrixGrayScale, ColorMatrixFlag.SkipGrays);
                        break;
                    case PaletteImageEffect.GrayScaleRed:
                        attribs.SetColorMatrix(_matrixGrayScaleRed, ColorMatrixFlag.SkipGrays);
                        break;
                    case PaletteImageEffect.GrayScaleGreen:
                        attribs.SetColorMatrix(_matrixGrayScaleGreen, ColorMatrixFlag.SkipGrays);
                        break;
                    case PaletteImageEffect.GrayScaleBlue:
                        attribs.SetColorMatrix(_matrixGrayScaleBlue, ColorMatrixFlag.SkipGrays);
                        break;
                    case PaletteImageEffect.Light:
                        attribs.SetColorMatrix(_matrixLight);
                        break;
                    case PaletteImageEffect.LightLight:
                        attribs.SetColorMatrix(_matrixLightLight);
                        break;
                    case PaletteImageEffect.Dark:
                        attribs.SetColorMatrix(_matrixDark);
                        break;
                    case PaletteImageEffect.DarkDark:
                        attribs.SetColorMatrix(_matrixDarkDark);
                        break;
                    case PaletteImageEffect.Inherit:
                        // Should never happen!
                        Debug.Assert(false);
                        break;
                }

                // Do we need to remap a colors in the bitmap?
                if ((remapTransparent != Color.Empty) ||
                    ((remapColor != Color.Empty) && (remapNew != Color.Empty)))
                {
                    List<ColorMap> colorMaps = new List<ColorMap>();

                    // Create remapping for the transparent color
                    if (remapTransparent != Color.Empty)
                    {
                        ColorMap remap = new ColorMap();
                        remap.OldColor = remapTransparent;
                        remap.NewColor = Color.Transparent;
                        colorMaps.Add(remap);
                    }

                    // Create remapping from source to target colors
                    if ((remapColor != Color.Empty) && (remapNew != Color.Empty))
                    {
                        ColorMap remap = new ColorMap();
                        remap.OldColor = remapColor;
                        remap.NewColor = remapNew;
                        colorMaps.Add(remap);
                    }

                    attribs.SetRemapTable(colorMaps.ToArray(), ColorAdjustType.Bitmap);
                }

                int translateX = 0;
                int translateY = 0;
                float rotation = 0f;

                // Perform any transformations needed for orientation
                switch (orientation)
                {
                    case VisualOrientation.Bottom:
                        // Translate to opposite side of origin, so the rotate can
                        // then bring it back to original position but mirror image
                        translateX = imageRect.X * 2 + imageRect.Width;
                        translateY = imageRect.Y * 2 + imageRect.Height;
                        rotation = 180f;
                        break;
                    case VisualOrientation.Left:
                        // Invert the dimensions of the rectangle for drawing upwards
                        imageRect = new Rectangle(imageRect.X, imageRect.Y, imageRect.Height, imageRect.Width);

                        // Translate back from a quarter left turn to the original place
                        translateX = imageRect.X - imageRect.Y;
                        translateY = imageRect.X + imageRect.Y + imageRect.Width;
                        rotation = -90f;
                        break;
                    case VisualOrientation.Right:
                        // Invert the dimensions of the rectangle for drawing upwards
                        imageRect = new Rectangle(imageRect.X, imageRect.Y, imageRect.Height, imageRect.Width);

                        // Translate back from a quarter right turn to the original place
                        translateX = imageRect.X + imageRect.Y + imageRect.Height;
                        translateY = -(imageRect.X - imageRect.Y);
                        rotation = 90f;
                        break;
                }

                // Apply the transforms if we have any to apply
                if ((translateX != 0) || (translateY != 0))
                    context.Graphics.TranslateTransform(translateX, translateY);

                if (rotation != 0f)
                    context.Graphics.RotateTransform(rotation);

                try
                {
                    // Finally, just draw the image and let the transforms do the rest
                    context.Graphics.DrawImage(image, imageRect, 0, 0, imageRect.Width, imageRect.Height, GraphicsUnit.Pixel, attribs);
                }
                catch (ArgumentException)
                {
                }
                finally
                {
                    if (rotation != 0f)
                        context.Graphics.RotateTransform(-rotation);

                    // Remove the applied transforms
                    if ((translateX != 0) | (translateY != 0))
                        context.Graphics.TranslateTransform(-translateX, -translateY);
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Initialize a new instance of the InternalStorage structure.
 /// </summary>
 public InternalStorage()
 {
     // Set to default values
     ContentImageH = PaletteRelativeAlign.Inherit;
     ContentImageV = PaletteRelativeAlign.Inherit;
     ContentEffect = PaletteImageEffect.Inherit;
     ContentImageColorMap = Color.Empty;
     ContentImageColorTo = Color.Empty;
 }