summaryrefslogtreecommitdiff
path: root/CopyMenu.cs
blob: 06cd39b8b3357ed53c2c7088d3d9e0bf924922bb (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// BitmapFontEd
// 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 BitmapFontEd
{
	/// <summary>
	/// Implements the Copy/Paste menu
	/// </summary>
	public class CopyMenu
	{
		public enum EMode
		{
			eNothing,
			eMark,
			ePaste,
			ePasteTransparent
		};
		
		public enum EGravity
		{
			eTopLeft,
			eTopRight,
			eBottomLeft,
			eBottomRight,
			eCentre
		};

		public CopyMenu()
		{
			m_mode=EMode.eNothing;
			m_grav=EGravity.eTopLeft;
			
			CreateMenus();
		}
		
		public bool AllowPaste
		{
			set
			{
				m_paste.Enabled=value;
				m_pasteTrans.Enabled=value;
			}
		}
		
		public EMode Mode
		{
			get {return m_mode;}
			set {m_mode=value;}
		}

		public EGravity Gravity
		{
			get {return m_grav;}
		}
		
		public void Show(Control c, int x, int y)
		{
			m_menu.Show(c, new Point(x,y));
		}


		// ------------------------------------------------
		// PRIVATE
		//
		private EMode		m_mode;
		private EGravity	m_grav;
		
		private Hashtable	m_modeMap;
		private Hashtable	m_gravMap;

		private ContextMenu	m_menu;
		private MenuItem	m_mark;
		private MenuItem	m_paste;
		private MenuItem	m_pasteTrans;
		private MenuItem	m_gravSub;
		private MenuItem	m_topLeft;
		private MenuItem	m_topRight;
		private MenuItem	m_bottomLeft;
		private MenuItem	m_bottomRight;
		private MenuItem	m_centre;

		private void CreateMenus()
		{
			m_menu=new ContextMenu();
			
			m_mark=new MenuItem("Mark and Copy", new EventHandler(OnMenu));
			m_paste=new MenuItem("Paste", new EventHandler(OnMenu));
			m_pasteTrans=new MenuItem("Paste Transparent", new EventHandler(OnMenu));
			
			m_gravSub=new MenuItem("Paste Gravity");
			
			m_topLeft=new MenuItem("Top Left",new EventHandler(OnGravity));
			m_topRight=new MenuItem("Top Right",new EventHandler(OnGravity));
			m_bottomLeft=new MenuItem("Bottom Left",new EventHandler(OnGravity));
			m_bottomRight=new MenuItem("Bottom Right",new EventHandler(OnGravity));
			m_centre=new MenuItem("Centre",new EventHandler(OnGravity));
			
			m_gravSub.MenuItems.Add(m_topLeft);
			m_gravSub.MenuItems.Add(m_topRight);
			m_gravSub.MenuItems.Add(m_bottomLeft);
			m_gravSub.MenuItems.Add(m_bottomRight);
			m_gravSub.MenuItems.Add(m_centre);
			
			m_topLeft.Checked=true;
			
			m_menu.MenuItems.Add(m_mark);
			m_menu.MenuItems.Add(m_gravSub);
			m_menu.MenuItems.Add(m_paste);
			m_menu.MenuItems.Add(m_pasteTrans);
			
			m_modeMap=new Hashtable();
			m_gravMap=new Hashtable();
			
			m_modeMap[m_mark]=EMode.eMark;
			m_modeMap[m_paste]=EMode.ePaste;
			m_modeMap[m_pasteTrans]=EMode.ePasteTransparent;
			
			m_gravMap[m_topLeft]=EGravity.eTopLeft;
			m_gravMap[m_topRight]=EGravity.eTopRight;
			m_gravMap[m_bottomLeft]=EGravity.eBottomLeft;
			m_gravMap[m_bottomRight]=EGravity.eBottomRight;
			m_gravMap[m_centre]=EGravity.eCentre;
		}
		
		private void OnMenu(object sender, System.EventArgs e)
		{
			m_mode=(EMode)m_modeMap[sender];
		}
		
		private void OnGravity(object sender, System.EventArgs e)
		{
			MenuItem i=(MenuItem)sender;
			
			m_grav=(EGravity)m_gravMap[sender];
			
			foreach (MenuItem m in m_gravSub.MenuItems)
			{
				m.Checked=false;
			}
			
			i.Checked=true;
		}
	}
}