Beispiel #1
0
        private void gradientControl1_MouseMove(object sender, MouseEventArgs e)
        {
            if (!bInitialized)
            {
                return;
            }

            if (mSelectedPoint >= 0 && mSelectedPoint < gradientControl1.Gradient.Count - 1)
            {
                double        translatedX = (double)e.X / (double)gradientControl1.ClientRectangle.Width;
                GradientPoint point       = gradientControl1.Gradient[mSelectedPoint];
                point.Alpha = System.Math.Min(System.Math.Max(0, translatedX), 1.0f);

                //-- now clamp the x according to their neighbors
                int leftNeighborIndex = mSelectedPoint - 1;
                if (leftNeighborIndex >= 0 && leftNeighborIndex < gradientControl1.Gradient.Count)
                {
                    double neighborAlpha = gradientControl1.Gradient[leftNeighborIndex].Alpha;
                    point.Alpha = System.Math.Max(neighborAlpha, point.Alpha);
                }

                int rightNeighborIndex = mSelectedPoint + 1;
                if (rightNeighborIndex >= 0 && rightNeighborIndex < gradientControl1.Gradient.Count)
                {
                    double neighborAlpha = gradientControl1.Gradient[rightNeighborIndex].Alpha;
                    point.Alpha = System.Math.Min(neighborAlpha, point.Alpha);
                }

                point.Alpha = System.Math.Round(point.Alpha, 2);

                refreshListBox();
                gradientControl1.Invalidate();
            }
        }
Beispiel #2
0
        public void addPoint(double alpha, Color color)
        {
            if (!bInitialized)
            {
                return;
            }

            if (alpha > 1.0f)
            {
                alpha = 1.0f;
            }

            if (alpha < 0.0f)
            {
                alpha = 0.0f;
            }

            GradientPoint point = new GradientPoint();

            point.Alpha = alpha;
            point.Color = color;

            mPointList.Add(point);
            Invalidate();
        }
Beispiel #3
0
        public GradientPoint clone()
        {
            GradientPoint clone = new GradientPoint();

            clone.Alpha = Alpha;
            clone.Color = Color;
            return(clone);
        }
Beispiel #4
0
        //-- interface
        public void addStage(Color color, double valueVariance, double alpha)
        {
            GradientPoint newStage = new GradientPoint();

            newStage.Color = color;
            newStage.Alpha = alpha;
            mStages.Add(newStage);
        }
Beispiel #5
0
        public void insertStage(int atIndex, Color color, double alpha)
        {
            GradientPoint newStage = new GradientPoint();

            newStage.Color = color;
            newStage.Alpha = alpha;

            Stages.Insert(atIndex, newStage);
        }
Beispiel #6
0
 private void fixupAlphaValues()
 {
     //-- fixup the alpha values
     for (int i = 0; i < mPointList.Count; i++)
     {
         GradientPoint p           = mPointList[i];
         int           numSegments = mPointList.Count - 1;
         p.Alpha = ((double)(i) / (double)numSegments);
     }
 }
Beispiel #7
0
        private void gradientControl1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (!bInitialized)
            {
                return;
            }

            //-- unselect
            mSelectedPoint = -1;

            colorDialog1.FullOpen = true;
            DialogResult result = colorDialog1.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            Rectangle clientRect  = gradientControl1.ClientRectangle;
            double    translatedX = (double)e.X / (double)clientRect.Width;

            for (int i = 0; i < gradientControl1.Gradient.Count; i++)
            {
                GradientPoint point = gradientControl1.Gradient[i];
                if (translatedX < point.Alpha)
                {
                    //-- now clamp the x according to their neighbors
                    int leftNeighborIndex = i - 1;
                    if (leftNeighborIndex >= 0 && leftNeighborIndex < gradientControl1.Gradient.Count)
                    {
                        double neighborAlpha = gradientControl1.Gradient[leftNeighborIndex].Alpha;
                        translatedX = System.Math.Max(neighborAlpha, translatedX);
                    }

                    int rightNeighborIndex = i;
                    if (rightNeighborIndex >= 0 && rightNeighborIndex < gradientControl1.Gradient.Count)
                    {
                        double neighborAlpha = gradientControl1.Gradient[rightNeighborIndex].Alpha;
                        translatedX = System.Math.Min(neighborAlpha, translatedX);
                    }

                    translatedX = System.Math.Round(translatedX, 2);

                    gradientControl1.insertPoint(i, translatedX, colorDialog1.Color);

                    refreshListBox();
                    gradientControl1.Invalidate();
                    break;
                }
            }
        }
Beispiel #8
0
        public void insertPoint(int atIndex, double alpha, Color color)
        {
            if (!bInitialized)
            {
                return;
            }

            GradientPoint point = new GradientPoint();

            point.Color = color;
            point.Alpha = alpha;

            mPointList.Insert(atIndex, point);
        }
Beispiel #9
0
        public void addPoint(Color color)
        {
            if (!bInitialized)
            {
                return;
            }

            GradientPoint point = new GradientPoint();

            point.Alpha = 0.0f;
            point.Color = color;
            mPointList.Add(point);

            fixupAlphaValues();
        }
Beispiel #10
0
        private void GradientControl_Paint(object sender, PaintEventArgs e)
        {
            if (mPointList == null)
            {
                return;
            }

            //-- this should only happen in design view
            if (bInitialized && mPointList.Count < 2)
            {
                clearPoints();
                addPoint(0.0f, Color.Black);
                addPoint(1.0f, Color.White);
                Invalidate();
            }

            Rectangle rect = new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height);

            if (e.ClipRectangle.Width == 0)
            {
                return;
            }

            for (int i = 0; i < mPointList.Count - 1; i++)
            {
                GradientPoint p0 = mPointList[i];
                GradientPoint p1 = mPointList[i + 1];

                int x0 = (int)System.Math.Round(p0.Alpha * (double)e.ClipRectangle.Width, MidpointRounding.AwayFromZero);
                int x1 = (int)System.Math.Round(p1.Alpha * (double)e.ClipRectangle.Width, MidpointRounding.AwayFromZero);

                rect.X     = x0;
                rect.Width = x1 - x0;
                if (rect.Width <= 0)
                {
                    continue;
                }

                drawGradientRegion(p0.Color, p1.Color, rect, e);
                if (i != 0 && i != mPointList.Count - 1)
                {
                    drawMarker(x0, e);
                }
            }
        }
Beispiel #11
0
        public void moveStageDown(int index)
        {
            //-- cannot move the endpoints
            if (index < 0 || index >= mStages.Count)
            {
                return;
            }

            int newIndex = index + 1;

            if (newIndex >= mStages.Count)
            {
                newIndex = mStages.Count - 1;
            }

            //swap members
            GradientPoint tempStage = mStages[newIndex];

            mStages[newIndex].Color = mStages[index].Color;
            mStages[index].Color    = tempStage.Color;
        }
Beispiel #12
0
        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (!bInitialized)
            {
                return;
            }

            e.DrawFocusRectangle();
            int index = e.Index;

            if (index < 0 || index >= gradientControl1.Gradient.Count)
            {
                return;
            }

            int           colorRectWidth        = 40;
            int           itemYAdditionalOffset = 4;
            GradientPoint item = gradientControl1.Gradient[index];
            //-- Draw the Color Rectangle
            Rectangle rect = new Rectangle();

            rect.X      = e.Bounds.X;
            rect.Y      = e.Bounds.Y;
            rect.Width  = colorRectWidth;
            rect.Height = e.Bounds.Height - itemYAdditionalOffset;


            //-- fill the rectangle
            Brush colorBrush = new SolidBrush(item.Color);

            e.Graphics.FillRectangle(colorBrush, rect);
            colorBrush.Dispose();

            //-- Draw the border
            Pen pen = new Pen(Color.Gray, 2);

            pen.Alignment = PenAlignment.Inset;
            pen.DashStyle = DashStyle.Solid;
            pen.LineJoin  = LineJoin.Round;
            e.Graphics.DrawRectangle(pen, rect);
            pen.Dispose();

            Brush brush = Brushes.Black;

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                brush = Brushes.White;
            }

            //-- Draw the back ground
            Brush brushBackground = new SolidBrush(e.BackColor);

            if (listBox1.Enabled == false)
            {
                brush           = Brushes.Gray;
                brushBackground = Brushes.DarkGray;
            }

            e.Graphics.FillRectangle(brushBackground, e.Bounds.X + 45, e.Bounds.Y, e.Bounds.Width - colorRectWidth, e.Bounds.Height - itemYAdditionalOffset);

            e.Graphics.DrawString(item.ToString(), e.Font, brush, e.Bounds.X + 45, e.Bounds.Y);
        }