Longkong.ColorPicker.Controls.ColorSwatchPanel.OnMouseUp C# (CSharp) Method

OnMouseUp() protected method

protected OnMouseUp ( MouseEventArgs e ) : void
e MouseEventArgs
return void
        protected override void OnMouseUp(MouseEventArgs e)
        {
            int width = m_swatchOuterRegionWidth - ( 2 * OUTER_PADDING );
            int height = m_swatchOuterRegionHeight - ( 2 * OUTER_PADDING );
            int x = e.X - OUTER_PADDING;
            int y = e.Y - OUTER_PADDING;

            Rectangle r = new Rectangle( m_startX, m_startY, width, height );
            Rectangle c = new Rectangle( e.X, e.Y, 1, 1 );

            if ( c.IntersectsWith( r ) ) {

                int swatchColumnIndex = ( x / ( SWATCH_WIDTH + PADDING ) );
                int swatchRowIndex = ( y / ( SWATCH_HEIGHT + PADDING ) );

                ColorSwatch potentialSwatch = m_swatchArray[ swatchColumnIndex, swatchRowIndex ];
                Rectangle potentialSwatchRectangle = new Rectangle( potentialSwatch.Location, potentialSwatch.Size );
                Point cursorPoint = new Point( e.X, e.Y );
                Rectangle cursorRectangle = new Rectangle( cursorPoint, new Size( 1, 1 ) );

                if ( cursorRectangle.IntersectsWith( potentialSwatchRectangle ) ) {

                    if ( ColorSwatchSelected != null ) {
                        ColorSwatchSelected( this, new ColorSelectedEventArgs( potentialSwatch.Color ) );
                    }

                }

            }
        }