Click here to Skip to main content
15,884,648 members
Articles / Desktop Programming / Windows Forms

2D Map Editor

Rate me:
Please Sign up or sign in to vote.
4.89/5 (21 votes)
8 Oct 2009CPOL9 min read 185.5K   6.8K   92  
Create and edit 2D maps using tiles
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace MapEditor
{
	/// <summary>
	/// Just to add a gradient to the toolstrip, make it look nice y'know?
	/// </summary>
	public class CustomToolStripRenderer : ToolStripProfessionalRenderer
	{
		private Color backcolour;
		
		protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
		{
			//I check IsEmpty becuase if the connected area contains
			// values, then the menu has been opened i we need to draw the
			// background for the menu items instead of the actual toolstrip
			if(e.ConnectedArea.IsEmpty)
			{	
				backcolour = e.BackColor;
				Color dark = Darken(e.BackColor, 30);
				LinearGradientBrush myBrush = new LinearGradientBrush(e.AffectedBounds, dark, e.BackColor, LinearGradientMode.Vertical);
				e.Graphics.FillRectangle(myBrush, e.AffectedBounds);
				myBrush.Dispose();
			} else {
				Brush myBrush = new SolidBrush(Color.White);
				e.Graphics.FillRectangle(myBrush, e.AffectedBounds);
				myBrush.Dispose();
			}
		}
		
		protected override void OnRenderImageMargin(ToolStripRenderEventArgs e)
		{
			//When you see a menu with a margin it goes from white-gray, this is going
			// to go gray-white so that it fades across. It just makes it stand out less,
			// especially since i'm noy using any images on the menu
			Rectangle rect = e.AffectedBounds;
			LinearGradientBrush myBrush = new LinearGradientBrush(rect, backcolour, Color.White, LinearGradientMode.Horizontal);
			e.Graphics.FillRectangle(myBrush, rect);
			myBrush.Dispose();
		}
		
		Color Darken(Color baseCol, int darkness)
		{
			//If the ControlPaint.Dark method worked properly i would use it, but
			// i kept on getting strange results
			int r,g,b;
			r = baseCol.R;
			g = baseCol.G;
			b = baseCol.B;
			
			
			r -= darkness; g -= darkness; b -= darkness;
			if(r<0)
				r=0;
			if(g<0)
				g=0;
			if(b<0)
				b=0;
			
			return Color.FromArgb(r,g,b);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
England England
*blip*

Comments and Discussions