| 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 | |
|---|
| 22 | using System; |
|---|
| 23 | using System.Collections.Generic; |
|---|
| 24 | using System.ComponentModel; |
|---|
| 25 | using System.Data; |
|---|
| 26 | using System.Drawing; |
|---|
| 27 | using System.Text; |
|---|
| 28 | using System.Windows.Forms; |
|---|
| 29 | using System.Runtime.InteropServices; |
|---|
| 30 | using System.Collections.ObjectModel; |
|---|
| 31 | using Eraser.Util; |
|---|
| 32 | |
|---|
| 33 | namespace 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 | } |
|---|