Example #1
0
        /// <summary>
        /// Draws the slider arrows on both sides of the control.
        /// </summary>
        /// <param name="position">position value of the slider, lowest being at the bottom.  The range
        /// is between 0 and the controls height-9.  The values will be adjusted if too large/small</param>
        /// <param name="Unconditional">If Unconditional is true, the slider is drawn, otherwise some logic
        /// is performed to determine is drawing is really neccessary.</param>
        private void DrawSlider(Gdk.Window g, int position, bool Unconditional)
        {
            if (position < 0)
            {
                position = 0;
            }
            if (position > this.Allocation.Height - 9)
            {
                position = this.Allocation.Height - 9;
            }

            if (m_iMarker_Start_Y == position && !Unconditional)                //	If the marker position hasn't changed
            {
                return;                                                         //	since the last time it was drawn and we don't HAVE to redraw
            }
            //	then exit procedure

            m_iMarker_Start_Y = position;               //	Update the controls marker position

            this.ClearSlider(g);                        //	Remove old slider

            Gdk.GC gcfill = new Gdk.GC(g);
            //	Same gray color Photoshop uses
            gcfill.RgbFgColor = GraphUtil.gdkColorFromWinForms(Color.FromArgb(116, 114, 106));


            Gdk.GC gcborder = new Gdk.GC(g);
            gcfill.RgbFgColor = GraphUtil.gdkColorFromWinForms(Color.White);
            //	Same gray color Photoshop uses
            //Console.WriteLine( "position="+position );

            Gdk.Point[] arrow = new Gdk.Point[7];               //	 GGG
            arrow[0] = new Gdk.Point(1, position);              //	G   G
            arrow[1] = new Gdk.Point(3, position);              //	G    G
            arrow[2] = new Gdk.Point(7, position + 4);          //	G     G
            arrow[3] = new Gdk.Point(3, position + 8);          //	G      G
            arrow[4] = new Gdk.Point(1, position + 8);          //	G     G
            arrow[5] = new Gdk.Point(0, position + 7);          //	G    G
            arrow[6] = new Gdk.Point(0, position + 1);          //	G   G
            //	 GGG
            g.DrawPolygon(gcfill, true, arrow);                 //	Fill left arrow with white
            g.DrawPolygon(gcborder, false, arrow);              //	Draw left arrow border with gray

            //	    GGG
            arrow[0] = new Gdk.Point(this.Allocation.Width - 2, position);                      //	   G   G
            arrow[1] = new Gdk.Point(this.Allocation.Width - 4, position);                      //	  G    G
            arrow[2] = new Gdk.Point(this.Allocation.Width - 8, position + 4);                  //	 G     G
            arrow[3] = new Gdk.Point(this.Allocation.Width - 4, position + 8);                  //	G      G
            arrow[4] = new Gdk.Point(this.Allocation.Width - 2, position + 8);                  //	 G     G
            arrow[5] = new Gdk.Point(this.Allocation.Width - 1, position + 7);                  //	  G    G
            arrow[6] = new Gdk.Point(this.Allocation.Width - 1, position + 1);                  //	   G   G
            //	    GGG

            g.DrawPolygon(gcfill, true, arrow);                 //	Fill right arrow with white
            g.DrawPolygon(gcborder, false, arrow);              //	Draw right arrow border with gray
        }
Example #2
0
        /// <summary>
        /// Fills in the content of the control showing all values of Red (0 to 255) for the given
        /// Green and Blue.
        /// </summary>
        private void Draw_Style_Red(Gdk.Window g)
        {
            for (int i = 0; i < this.Allocation.Height - 8; i++)                       //	i represents the current line of pixels we want to draw horizontally
            {
                int red = 255 - Round(255 * (double)i / (this.Allocation.Height - 8)); //	red is based on the current vertical position
                //	Get the Color for this line

                Color c = Color.FromArgb(red, m_rgb.G, m_rgb.B);

                Gdk.GC gc = new Gdk.GC(g);
                gc.RgbFgColor = GraphUtil.gdkColorFromWinForms(c);
                g.DrawLine(gc, 11, i + 4, this.Allocation.Width - 11, i + 4);                                   //	Draw the line and loop back for next line
            }
        }
Example #3
0
        /// <summary>
        /// Fills in the content of the control showing all values of Luminance (0 to 100%) for the given
        /// Hue and Saturation.
        /// </summary>
        private void Draw_Style_Luminance(Gdk.Window g)
        {
            GraphUtil.HSL _hsl = new GraphUtil.HSL();
            _hsl.H = m_hsl.H;                   //	Use the H and S values of the current color (m_hsl)
            _hsl.S = m_hsl.S;

            for (int i = 0; i < this.Allocation.Height - 8; i++)               //	i represents the current line of pixels we want to draw horizontally
            {
                _hsl.L = 1.0 - (double)i / (this.Allocation.Height - 8);       //	L (Luminance) is based on the current vertical position
                //	Get the Color for this line
                Color c = GraphUtil.HSL_to_RGB(_hsl);

                Gdk.GC gc = new Gdk.GC(g);
                gc.RgbFgColor = GraphUtil.gdkColorFromWinForms(c);
                g.DrawLine(gc, 11, i + 4, this.Allocation.Width - 11, i + 4);                  //	Draw the line and loop back for next line
            }
        }
Example #4
0
        //	The following functions do the real work of the control, drawing the primary content (the area between the slider)
        //

        /// <summary>
        /// Fills in the content of the control showing all values of Hue (from 0 to 360)
        /// </summary>
        private void Draw_Style_Hue(Gdk.Window g)
        {
            GraphUtil.HSL _hsl = new GraphUtil.HSL();
            _hsl.S = 1.0;                       //	S and L will both be at 100% for this DrawStyle
            _hsl.L = 1.0;

            for (int i = 0; i < this.Allocation.Height - 8; i++)                        //	i represents the current line of pixels we want to draw horizontally
            {
                _hsl.H = 1.0 - (double)i / (this.Allocation.Height - 8);                //	H (hue) is based on the current vertical position
                Color c = GraphUtil.HSL_to_RGB(_hsl);

                Gdk.GC gc = new Gdk.GC(g);
                gc.RgbFgColor = GraphUtil.gdkColorFromWinForms(c);

                g.DrawLine(gc, 11, i + 4, this.Allocation.Width - 11, i + 4);                         //	Draw the line and loop back for next line
            }
        }
Example #5
0
        /// <summary>
        /// Draws the border around the control.
        /// </summary>
        private void DrawBorder(Gdk.Window g)
        {
            //	To make the control look like Adobe Photoshop's the border around the control will be a gray line
            //	on the top and left side, a white line on the bottom and right side, and a black rectangle (line)
            //	inside the gray/white rectangle

            Gdk.GC gc = new Gdk.GC(g);
            gc.RgbFgColor = GraphUtil.gdkColorFromWinForms(Color.FromArgb(172, 168, 153)); //	The same gray color used by Photoshop
            g.DrawLine(gc, this.Allocation.Width - 2, 0, 0, 0);                            //	Draw top line
            g.DrawLine(gc, 0, 0, 0, this.Allocation.Height - 2);                           //	Draw left hand line

            gc.RgbFgColor = GraphUtil.gdkColorFromWinForms(Color.White);
            g.DrawLine(gc, this.Allocation.Width - 1, 0, this.Allocation.Width - 1, this.Allocation.Height - 1);                //	Draw right hand line
            g.DrawLine(gc, this.Allocation.Width - 1, this.Allocation.Height - 1, 0, this.Allocation.Height - 1);               //	Draw bottome line

            gc.RgbFgColor = GraphUtil.gdkColorFromWinForms(Color.Black);
            g.DrawRectangle(gc, false, 1, 1, this.Allocation.Width - 3, this.Allocation.Height - 3);                    //	Draw inner black rectangle
        }
        private void UpdatePreview()
        {
            //hsb
            TxtH.Value = Math.Round(ColorWell.HSL.H * 360);
            TxtS.Value = Math.Round(ColorWell.HSL.S * 100);
            TxtB.Value = Math.Round(ColorWell.HSL.L * 100);
            //rgb
            TxtRed.Value   = ColorWell.RGB.R;
            TxtBlue.Value  = ColorWell.RGB.B;
            TxtGreen.Value = ColorWell.RGB.G;
            //cmyk
            GraphUtil.CMYK cmyk = GraphUtil.RGB_to_CMYK(ColorWell.RGB);
            TxtC.Value = Math.Round(cmyk.C * 100);
            TxtM.Value = Math.Round(cmyk.M * 100);
            TxtY.Value = Math.Round(cmyk.Y * 100);
            TxtK.Value = Math.Round(cmyk.K * 100);
            //hex
            TxtHexa.Text = GraphUtil.Color2Hex(ColorWell.RGB);

            Preview.ModifyBg(Preview.State, GraphUtil.gdkColorFromWinForms(ColorWell.RGB));
        }
Example #7
0
        /// <summary>
        /// Draws the marker (circle) inside the box
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="Unconditional"></param>
        private void DrawMarker(Gdk.Window win, int x, int y, bool Unconditional)                               //	   *****
        {                                                                                                       //	  *  |  *
            if (x < 0)
            {
                x = 0;                                                                                                                  //	 *   |   *
            }
            if (x > this.Allocation.Width - 4)
            {
                x = this.Allocation.Width - 4;                                                                                  //	*    |    *
            }
            if (y < 0)
            {
                y = 0;                                                                                                                  //	*    |    *
            }
            if (y > this.Allocation.Height - 4)
            {
                y = this.Allocation.Height - 4;                                                                                 //	*----X----*
            }
            //	*    |    *
            if (m_iMarker_Y == y && m_iMarker_X == x && !Unconditional)                 //	*    |    *
            {
                return;                                                                 //	 *   |   *
            }
            //	  *  |  *
            ClearMarker(win);                                                                                                                   //	   *****

            m_iMarker_X = x;
            m_iMarker_Y = y;

            //Graphics g = Gtk.DotNet.Graphics.FromDrawable( win );

            //Pen pen;
            GraphUtil.HSL _hsl = GetColor(x, y);                //	The selected color determines the color of the marker drawn over
            //	it (black or white)
            Color color = Color.White;

            if (_hsl.L < (double)200 / 255)
            {
                color = Color.White;                                                                                    //	White marker if selected color is dark
            }
            else if (_hsl.H < (double)26 / 360 || _hsl.H > (double)200 / 360)
            {
                if (_hsl.S > (double)70 / 255)
                {
                    color = Color.White;
                }
                else
                {
                    color = Color.Black;                                                                                //	Else use a black marker for lighter colors
                }
            }
            else
            {
                color = Color.Black;
            }

            Gdk.GC gc = new Gdk.GC(win);
            gc.RgbFgColor = GraphUtil.gdkColorFromWinForms(color);
            win.DrawArc(gc, false, x - 3, y - 3, 10, 10, 0 * 64, 360 * 64);



            //DrawBorder(win);		//	Force the border to be redrawn, just in case the marker has been drawn over it.
        }