source: branches/eraser6/Eraser/ToolBar.cs @ 1017

Revision 1017, 3.1 KB checked in by lowjoel, 5 years ago (diff)

Fixed the padding/margin values in the toolbar such that it looks more organised. Padding now defaults to 0 and margin between items are 10px.

  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 * Copyright 2008 The Eraser Project
4 * Original Author: Joel Low <lowjoel@users.sourceforge.net>
5 * Modified By:
6 *
7 * This file is part of Eraser.
8 *
9 * Eraser is free software: you can redistribute it and/or modify it under the
10 * terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
13 *
14 * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 *
18 * A copy of the GNU General Public License can be found at
19 * <http://www.gnu.org/licenses/>.
20 */
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Data;
26using System.Drawing;
27using System.Text;
28using System.Windows.Forms;
29using System.Runtime.InteropServices;
30using System.Collections.ObjectModel;
31using Eraser.Util;
32
33namespace Eraser
34{
35    public partial class ToolBar : System.Windows.Forms.MenuStrip
36    {
37        public ToolBar()
38        {
39            //Create the base component
40            InitializeComponent();
41            Renderer = new EraserToolStripRenderer();
42        }
43
44        private class EraserToolStripRenderer : ToolStripRenderer
45        {
46            protected override void Initialize(ToolStrip toolStrip)
47            {
48                base.Initialize(toolStrip);
49                owner = toolStrip;
50            }
51
52            protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
53            {
54                //Draw the parent background image. This is not portable in that it will render
55                //this code unreusable, but for the lack of anything better this will have to suffice!
56                e.Graphics.DrawImage(Properties.Resources.BackgroundGradient,
57                    new Point(-owner.Left, -owner.Top));
58            }
59
60            protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
61            {
62                Graphics g = e.Graphics;
63
64                //Draw the actual text
65                Rectangle tempRect = e.TextRectangle;
66                tempRect.Inflate(3, 3);
67                tempRect.Offset(3, 3);
68                e.TextRectangle = tempRect;
69                using (SolidBrush textBrush = new SolidBrush(TextColour))
70                    g.DrawString(e.Text, e.TextFont, textBrush, e.TextRectangle);
71
72                //If the text has got a selection, draw an underline
73                if (e.Item.Selected)
74                {
75                    SizeF textSize = g.MeasureString(e.Text, e.TextFont);
76                    using (Pen underlinePen = new Pen(TextColour))
77                    {
78                        Point underlineStart = e.TextRectangle.Location;
79                        underlineStart.Offset(0, Point.Truncate(textSize.ToPointF()).Y);
80                        Point underlineEnd = underlineStart;
81                        underlineEnd.Offset(e.TextRectangle.Width, 0);
82
83                        g.DrawLine(underlinePen, underlineStart, underlineEnd);
84                    }
85                }
86            }
87
88            /// <summary>
89            /// The margin between a drop-down arrow and the surrounding items.
90            /// </summary>
91            private const int ArrowMargin = 0;
92
93            /// <summary>
94            /// The colour of the menu bar text.
95            /// </summary>
96            private readonly Color TextColour = Color.White;
97
98            /// <summary>
99            /// The toolstrip using this renderer.
100            /// </summary>
101            private ToolStrip owner;
102        }
103    }
104}
Note: See TracBrowser for help on using the repository browser.