cadencii.windows.forms.RebarBand.drawChevronMenuItem C# (CSharp) Method

drawChevronMenuItem() private method

private drawChevronMenuItem ( object sender, DrawItemEventArgs e ) : void
sender object
e System.Windows.Forms.DrawItemEventArgs
return void
        private void drawChevronMenuItem( object sender, DrawItemEventArgs e ) {
            Brush brush_back = ((e.State & DrawItemState.Selected) != 0) ?
                    SystemBrushes.Highlight :  // 選択時の背景色
                    SystemBrushes.Menu;       // 非選択時の背景色
            e.Graphics.FillRectangle( brush_back, e.Bounds );
            
            if ( !(sender is MenuItem) ) return;
            MenuItem menu = (MenuItem)sender;
            if( menu.Tag == null ) return;
            if( !(menu.Tag is ToolBarButton) ) return;
            ToolBarButton button = (ToolBarButton)menu.Tag;
            int x = 0;
            if ( button.Parent != null && button.Parent.ImageList != null ) {
                if ( 0 <= button.ImageIndex && button.ImageIndex < button.Parent.ImageList.Images.Count ) {
                    Image img = button.Parent.ImageList.Images[button.ImageIndex];
                    if( img != null ){
                        int image_offset = (e.Bounds.Height - img.Height) / 2;
                        if ( !button.Enabled ) {
                            const float R = 0.298912f;
                            const float G = 0.586611f;
                            const float B = 0.114478f;

                            System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(
                                new float[][]{
                                    new float[]{ R, R, R, 0, 0}, 
                                    new float[]{ G, G, G, 0, 0}, 
                                    new float[]{ B, B, B, 0, 0}, 
                                    new float[]{ 0, 0, 0, 1, 0}, 
                                    new float[]{ 0, 0, 0, 0, 1} } );
                            System.Drawing.Imaging.ImageAttributes atr = new System.Drawing.Imaging.ImageAttributes();
                            atr.SetColorMatrix( cm );
                            e.Graphics.DrawImage( 
                                img, 
                                new Rectangle( 
                                    e.Bounds.X + SPACE_CHEVRON_MENU,
                                    e.Bounds.Y + image_offset,
                                    img.Width,
                                    img.Height ),
                                0, 0, img.Width, img.Height,
                                GraphicsUnit.Pixel,
                                atr );
                        } else {
                            button.Parent.ImageList.Draw(
                                e.Graphics,
                                e.Bounds.X + SPACE_CHEVRON_MENU,
                                e.Bounds.Y + image_offset,
                                button.ImageIndex );
                            x += button.Parent.ImageList.Images[button.ImageIndex].Width;
                        }
                    }
                }
            }
            SizeF text_size = e.Graphics.MeasureString( menu.Text, e.Font );
            int text_offset = (int)(e.Bounds.Height - text_size.Height) / 2;
            e.Graphics.DrawString( menu.Text, e.Font, Brushes.Black, e.Bounds.X + x + SPACE_CHEVRON_MENU, e.Bounds.Y + text_offset );
        }