Пример #1
0
        public BlendFillEditorUI(IWindowsFormsEditorService in_svc, BlendFill in_blendFill, bool in_reverse) : base()
        {
            //This call is required by the Windows Form Designer.
            InitializeComponent();

            //Add any initialization after the InitializeComponent() call

            this.m_svc = in_svc;

            //
            // Save out the values we were given.
            //
            this.m_direction   = in_blendFill.Style;
            this.m_startColor  = in_blendFill.StartColor;
            this.m_finishColor = in_blendFill.FinishColor;
            this.m_reverse     = in_reverse;

            //
            // Populate and select values in the appropriate list boxes.
            //
            System.Resources.ResourceManager rm;
            rm = new System.Resources.ResourceManager(typeof(BlendFillEditorUI));
            populateDirectionListBox(rm);
            populateAndSelectColorList(this.startColorList, this.m_startColor, rm);
            populateAndSelectColorList(this.finishColorList, this.m_finishColor, rm);
        }
Пример #2
0
    public static Color Blend(Color a, Color b, BlendStyle style)
    {
        Color output = Colors.White;

        switch (style)
        {
        case BlendStyle.Multiply:
            output = Multiply(a, b);
            break;

        case BlendStyle.Screen:
            output = Screen(a, b);
            break;

        case BlendStyle.Overlay:
            output = Overlay(a, b);
            break;

        case BlendStyle.Difference:
            output = Difference(a, b);
            break;

        case BlendStyle.Average:
            output = Average(a, b);
            break;

        case BlendStyle.Negation:
            output = Negation(a, b);
            break;
        }
        return(output);
    }
Пример #3
0
 //=------------------------------------------------------------------=
 // directionComboBox_SelectedIndexChanged
 //=------------------------------------------------------------------=
 /// <summary>
 ///   Update the sample panel with the new selection.
 /// </summary>
 ///
 private void directionComboBox_SelectedIndexChanged
 (
     object sender,
     System.EventArgs e
 )
 {
     this.m_direction = (BlendStyle)this.directionComboBox.SelectedIndex;
     this.blendSamplePanel.Refresh();
 }
Пример #4
0
        //=------------------------------------------------------------------=
        //=------------------------------------------------------------------=
        //=------------------------------------------------------------------=
        //=------------------------------------------------------------------=
        //                     Public Methods/Properties/etc
        //=------------------------------------------------------------------=
        //=------------------------------------------------------------------=
        //=------------------------------------------------------------------=
        //=------------------------------------------------------------------=


        //=------------------------------------------------------------------=
        // Constructor
        //=------------------------------------------------------------------=
        //
        /// <summary>
        ///   Initializes a new instance of this class.  Requires the blend
        ///   style, as well as the start and finish color.
        /// </summary>
        ///
        /// <param name="in_blendStyle">
        ///   Style of blending we'll use.
        /// </param>
        ///
        /// <param name="in_startColor">
        ///   Color with which to begin blend.
        /// </param>
        ///
        /// <param name="in_finishColor">
        ///   Color with which to finish blend.
        /// </param>
        ///
        public BlendFill
        (
            BlendStyle in_blendStyle,
            Color in_startColor,
            Color in_finishColor
        )
        {
            this.m_startColor  = in_startColor;
            this.m_finishColor = in_finishColor;
            this.m_style       = in_blendStyle;
        }
Пример #5
0
        //=------------------------------------------------------------------=
        //=------------------------------------------------------------------=
        //=------------------------------------------------------------------=
        //=------------------------------------------------------------------=
        //                   Private Methods/Properties/Subs
        //=------------------------------------------------------------------=
        //=------------------------------------------------------------------=
        //=------------------------------------------------------------------=
        //=------------------------------------------------------------------=

        //=------------------------------------------------------------------=
        // getAngle
        //=------------------------------------------------------------------=
        /// <summary>
        ///   Returns an angle for a LinearGradientBrush given a
        ///   direction/style.
        /// </summary>
        ///
        /// <param name="in_direction">
        ///   The BlendStyle or Direction of painting.
        /// </param>
        ///
        /// <param name="in_reverseForRTL">
        ///   Indicates wheter we should reverse for RightToLeftReading.
        /// </param>
        ///
        /// <returns>
        ///   Returns the Angle that should be used in drawing.
        /// </returns>
        ///
        private static float getAngle
        (
            BlendStyle in_direction,
            bool in_reverseForRTL
        )
        {
            switch (in_direction)
            {
            case BlendStyle.Horizontal:
                if (in_reverseForRTL)
                {
                    return(180);
                }
                else
                {
                    return(0);
                }

            case BlendStyle.Vertical:
                return(90);

            case BlendStyle.ForwardDiagonal:
                if (in_reverseForRTL)
                {
                    return(135);
                }
                else
                {
                    return(45);
                }

            case BlendStyle.BackwardDiagonal:
                if (in_reverseForRTL)
                {
                    return(45);
                }
                else
                {
                    return(135);
                }

            default:
                System.Diagnostics.Debug.Fail("Bogus Direction");
                return(0);
            }
        }
Пример #6
0
        //=------------------------------------------------------------------=
        // blendSamplePanel_MouseUp
        //=------------------------------------------------------------------=
        /// <summary>
        ///   They've clicked on the sample panel.  Update the selection if
        ///   necessary.
        /// </summary>
        ///
        private void blendSamplePanel_MouseUp
        (
            object sender,
            System.Windows.Forms.MouseEventArgs e
        )
        {
            Rectangle[] rects;

            rects = getPanelRects();

            for (int x = 0; x < rects.Length; x++)
            {
                if (rects[x].Contains(e.X, e.Y))
                {
                    this.m_direction = (BlendStyle)x;
                    this.blendSamplePanel.Refresh();
                    this.directionComboBox.SelectedIndex = x;
                }
            }
        }
Пример #7
0
        /// <summary>
        /// 创建画刷,渲染背景和边框使用
        /// </summary>
        /// <param name="rect">画刷区域</param>
        /// <param name="baseColor">基色</param>
        /// <param name="pos1">基色位置1</param>
        /// <param name="pos2">基色位置2</param>
        /// <param name="reverse">是否反转</param>
        /// <param name="mode">渐变模式</param>
        /// <param name="style">样式</param>
        /// <returns>画刷</returns>
        public static Brush CreateBrush(Rectangle rect, Color baseColor, float pos1, float pos2, bool reverse, LinearGradientMode mode, BlendStyle style)
        {
            Brush brush = null;

            RectangleEx.MakeNotEmpty(ref rect);
            switch (style)
            {
            case BlendStyle.Solid:
            {
                SolidBrush brushTmp = new SolidBrush(baseColor);
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.Gradient:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(rect, Color.Empty, Color.Empty, mode);
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosGradient(baseColor, pos1, pos2, reverse, false, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeIn:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(rect, Color.Empty, Color.Empty, mode);
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeIn(baseColor, pos1, pos2, reverse, false, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeOut:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(rect, Color.Empty, Color.Empty, mode);
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeOut(baseColor, pos1, pos2, reverse, false, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeInFadeOut:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(rect, Color.Empty, Color.Empty, mode);
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeInFadeOut(baseColor, pos1, pos2, reverse, false, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            default:
                break;
            }
            return(brush);
        }
Пример #8
0
        /// <summary>
        /// 创建画刷,渲染线段使用
        /// </summary>
        /// <param name="pt1">起点</param>
        /// <param name="pt2">终点</param>
        /// <param name="baseColor">基色</param>
        /// <param name="style">样式</param>
        /// <returns>画刷</returns>
        public static Brush CreateBrush(Point pt1, Point pt2, Color baseColor, BlendStyle style)
        {
            Brush brush = null;

            switch (style)
            {
            case BlendStyle.Solid:
            {
                SolidBrush brushTmp = new SolidBrush(baseColor);
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.Gradient:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(GetLineRect(pt1, pt2), Color.Empty, Color.Empty, GetLineDegrees(pt1, pt2));
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosGradient(baseColor, float.NaN, float.NaN, false, true, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeIn:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(GetLineRect(pt1, pt2), Color.Empty, Color.Empty, GetLineDegrees(pt1, pt2));
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeIn(baseColor, float.NaN, float.NaN, false, true, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeOut:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(GetLineRect(pt1, pt2), Color.Empty, Color.Empty, GetLineDegrees(pt1, pt2));
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeOut(baseColor, float.NaN, float.NaN, false, true, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeInFadeOut:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(GetLineRect(pt1, pt2), Color.Empty, Color.Empty, GetLineDegrees(pt1, pt2));
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeInFadeOut(baseColor, float.NaN, float.NaN, false, true, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            default:
                break;
            }
            return(brush);
        }