summaryrefslogtreecommitdiff
path: root/ManipulationMenu.cs
blob: 0e6696cd211584059c98c388fa59099134fa6a2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// BitmapSpriteEd - Bitmap Sprite Editor
// Copyright (C) 2005  Ian Cowburn
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// $Id$
//
using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;

namespace BitmapSpriteEd
{
	/// <summary>
	/// Implements the Manipulation menu
	/// </summary>
	public class ManipulationMenu
	{
		public enum EMode
		{
			eNothing,
			eMirrorHorizontal,
			eMirrorVertical,
			eRotateLeft,
			eRotateRight,
			eScrollUp,
			eScrollDown,
			eScrollLeft,
			eScrollRight,
			eEdge,
			eDropShadow,
			eReplace,
			eReplaceAll
		};
		
		public ManipulationMenu()
		{
			m_mode=EMode.eNothing;
			
			CreateMenus();
		}
		
		public EMode Mode
		{
			get {return m_mode;}
		}

		public void Show(Control c, int x, int y)
		{
			m_mode=EMode.eNothing;
			m_menu.Show(c, new Point(x,y));
			
			// Kludge warning!
			//
			Application.DoEvents();
		}


		// ------------------------------------------------
		// PRIVATE
		//
		private EMode		m_mode;
		
		private Hashtable	m_modeMap;

		private ContextMenu	m_menu;
		
		private void CreateItem(string text, EMode mode)
		{
			MenuItem i=new MenuItem(text,new EventHandler(OnMenu));
			m_modeMap[i]=mode;
			m_menu.MenuItems.Add(i);
		}

		private void CreateMenus()
		{
			m_menu=new ContextMenu();
			m_modeMap=new Hashtable();
			
			CreateItem("Mirror Horizontal",EMode.eMirrorHorizontal);
			CreateItem("Mirror Vertical",EMode.eMirrorVertical);
			CreateItem("Rotate Left",EMode.eRotateLeft);
			CreateItem("Rotate Right",EMode.eRotateRight);
			CreateItem("Scroll Up",EMode.eScrollUp);
			CreateItem("Scroll Down",EMode.eScrollDown);
			CreateItem("Scroll Left",EMode.eScrollLeft);
			CreateItem("Scroll Right",EMode.eScrollRight);
			CreateItem("Edge",EMode.eEdge);
			CreateItem("Drop Shadow",EMode.eDropShadow);
			CreateItem("Replace Colour",EMode.eReplace);
			CreateItem("Replace all non-zero alpha colours",EMode.eReplaceAll);
		}
		
		private void OnMenu(object sender, System.EventArgs e)
		{
			m_mode=(EMode)m_modeMap[sender];
		}
	}
}