2007-06-24 22:53:41 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Text;
|
2007-06-25 06:55:30 +00:00
|
|
|
using System.Windows.Forms;
|
2007-06-24 22:53:41 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-05-29 11:34:01 +00:00
|
|
|
namespace CodeImp.DoomBuilder.Actions
|
2007-06-24 22:53:41 +00:00
|
|
|
{
|
2008-01-02 21:49:43 +00:00
|
|
|
internal class Action
|
2007-06-24 22:53:41 +00:00
|
|
|
{
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Description
|
2007-09-29 15:43:59 +00:00
|
|
|
private string name;
|
2008-01-13 21:23:59 +00:00
|
|
|
private string shortname;
|
2007-06-24 22:53:41 +00:00
|
|
|
private string title;
|
|
|
|
private string description;
|
|
|
|
|
|
|
|
// Shortcut key
|
|
|
|
private int key;
|
2008-04-27 12:07:26 +00:00
|
|
|
private int keymask;
|
2007-06-24 22:53:41 +00:00
|
|
|
|
2007-06-25 19:28:03 +00:00
|
|
|
// Shortcut options
|
|
|
|
private bool allowkeys;
|
|
|
|
private bool allowmouse;
|
|
|
|
private bool allowscroll;
|
2008-04-27 12:07:26 +00:00
|
|
|
private bool disregardshift;
|
|
|
|
private bool repeat;
|
2007-06-25 19:28:03 +00:00
|
|
|
|
2007-06-24 22:53:41 +00:00
|
|
|
// Delegate
|
2008-04-27 12:07:26 +00:00
|
|
|
private List<ActionDelegate> begindelegates;
|
|
|
|
private List<ActionDelegate> enddelegates;
|
2007-06-24 22:53:41 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2007-09-29 15:43:59 +00:00
|
|
|
public string Name { get { return name; } }
|
2008-01-13 21:23:59 +00:00
|
|
|
public string ShortName { get { return shortname; } }
|
2007-06-24 22:53:41 +00:00
|
|
|
public string Title { get { return title; } }
|
|
|
|
public string Description { get { return description; } }
|
|
|
|
public int ShortcutKey { get { return key; } }
|
2008-04-27 12:07:26 +00:00
|
|
|
public int ShortcutMask { get { return keymask; } }
|
2007-06-25 19:28:03 +00:00
|
|
|
public bool AllowKeys { get { return allowkeys; } }
|
|
|
|
public bool AllowMouse { get { return allowmouse; } }
|
|
|
|
public bool AllowScroll { get { return allowscroll; } }
|
2008-04-27 12:07:26 +00:00
|
|
|
public bool DisregardShift { get { return disregardshift; } }
|
|
|
|
public bool Repeat { get { return repeat; } }
|
2008-05-17 08:00:25 +00:00
|
|
|
public bool BeginBound { get { return (begindelegates.Count > 0); } }
|
|
|
|
public bool EndBound { get { return (enddelegates.Count > 0); } }
|
|
|
|
|
2007-06-24 22:53:41 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2008-01-13 21:23:59 +00:00
|
|
|
public Action(string name, string shortname, string title, string description, int key,
|
2008-04-27 12:07:26 +00:00
|
|
|
bool allowkeys, bool allowmouse, bool allowscroll, bool disregardshift, bool repeat)
|
2007-06-24 22:53:41 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
2007-09-29 15:43:59 +00:00
|
|
|
this.name = name;
|
2008-01-13 21:23:59 +00:00
|
|
|
this.shortname = shortname;
|
2007-06-24 22:53:41 +00:00
|
|
|
this.title = title;
|
|
|
|
this.description = description;
|
2008-04-27 12:07:26 +00:00
|
|
|
this.begindelegates = new List<ActionDelegate>();
|
|
|
|
this.enddelegates = new List<ActionDelegate>();
|
2007-06-25 19:28:03 +00:00
|
|
|
this.allowkeys = allowkeys;
|
|
|
|
this.allowmouse = allowmouse;
|
|
|
|
this.allowscroll = allowscroll;
|
2008-04-27 12:07:26 +00:00
|
|
|
this.disregardshift = disregardshift;
|
|
|
|
this.repeat = repeat;
|
|
|
|
|
|
|
|
if(disregardshift)
|
|
|
|
{
|
|
|
|
keymask = (int)Keys.Shift | (int)Keys.Control;
|
|
|
|
keymask = ~keymask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
keymask = ~0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.key = key & keymask;
|
2007-06-24 22:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
~Action()
|
|
|
|
{
|
|
|
|
// Moo.
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-06-25 06:55:30 +00:00
|
|
|
#region ================== Static Methods
|
|
|
|
|
|
|
|
// This returns the shortcut key description for a key
|
|
|
|
public static string GetShortcutKeyDesc(int key)
|
|
|
|
{
|
|
|
|
KeysConverter conv = new KeysConverter();
|
|
|
|
int ctrl, button;
|
|
|
|
string ctrlprefix = "";
|
|
|
|
|
|
|
|
// When key is 0, then return an empty string
|
|
|
|
if(key == 0) return "";
|
|
|
|
|
|
|
|
// Split the key in Control and Button
|
|
|
|
ctrl = key & ((int)Keys.Control | (int)Keys.Shift | (int)Keys.Alt);
|
|
|
|
button = key & ~((int)Keys.Control | (int)Keys.Shift | (int)Keys.Alt);
|
|
|
|
|
2007-09-30 19:37:57 +00:00
|
|
|
// When the button is a control key, then remove the control itsself
|
|
|
|
if((button == (int)Keys.ControlKey) ||
|
|
|
|
(button == (int)Keys.ShiftKey))
|
|
|
|
{
|
|
|
|
ctrl = 0;
|
|
|
|
key = key & ~((int)Keys.Control | (int)Keys.Shift | (int)Keys.Alt);
|
|
|
|
}
|
|
|
|
|
2007-06-25 06:55:30 +00:00
|
|
|
// Determine control prefix
|
|
|
|
if(ctrl != 0) ctrlprefix = conv.ConvertToString(key);
|
|
|
|
|
|
|
|
// Check if button is special
|
|
|
|
switch(button)
|
|
|
|
{
|
|
|
|
// Scroll down
|
|
|
|
case (int)SpecialKeys.MScrollDown:
|
|
|
|
|
|
|
|
// Make string representation
|
|
|
|
return ctrlprefix + "ScrollDown";
|
|
|
|
|
|
|
|
// Scroll up
|
|
|
|
case (int)SpecialKeys.MScrollUp:
|
|
|
|
|
|
|
|
// Make string representation
|
|
|
|
return ctrlprefix + "ScrollUp";
|
|
|
|
|
2008-02-15 12:46:35 +00:00
|
|
|
// Keys that would otherwise have odd names
|
|
|
|
case (int)Keys.Oemtilde: return ctrlprefix + "~";
|
|
|
|
case (int)Keys.OemMinus: return ctrlprefix + "-";
|
|
|
|
case (int)Keys.Oemplus: return ctrlprefix + "+";
|
|
|
|
case (int)Keys.Subtract: return ctrlprefix + "NumPad-";
|
|
|
|
case (int)Keys.Add: return ctrlprefix + "NumPad+";
|
|
|
|
case (int)Keys.Decimal: return ctrlprefix + "NumPad.";
|
|
|
|
case (int)Keys.Multiply: return ctrlprefix + "NumPad*";
|
|
|
|
case (int)Keys.Divide: return ctrlprefix + "NumPad/";
|
|
|
|
case (int)Keys.OemOpenBrackets: return ctrlprefix + "[";
|
|
|
|
case (int)Keys.OemCloseBrackets: return ctrlprefix + "]";
|
|
|
|
case (int)Keys.Oem1: return ctrlprefix + ";";
|
|
|
|
case (int)Keys.Oem7: return ctrlprefix + "'";
|
|
|
|
case (int)Keys.Oemcomma: return ctrlprefix + ",";
|
|
|
|
case (int)Keys.OemPeriod: return ctrlprefix + ".";
|
|
|
|
case (int)Keys.OemQuestion: return ctrlprefix + "?";
|
|
|
|
case (int)Keys.Oem5: return ctrlprefix + "\\";
|
|
|
|
case (int)Keys.Capital: return ctrlprefix + "CapsLock";
|
|
|
|
case (int)Keys.Back: return ctrlprefix + "Backspace";
|
|
|
|
|
2007-06-25 06:55:30 +00:00
|
|
|
default:
|
|
|
|
|
|
|
|
// Use standard key-string conversion
|
|
|
|
return conv.ConvertToString(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-06-24 22:53:41 +00:00
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This sets a new key for the action
|
|
|
|
public void SetShortcutKey(int key)
|
|
|
|
{
|
|
|
|
// Make it so.
|
2008-04-27 12:07:26 +00:00
|
|
|
this.key = key & keymask;
|
2007-06-24 22:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This binds a delegate to this action
|
2008-04-27 12:07:26 +00:00
|
|
|
public void BindBegin(ActionDelegate method)
|
|
|
|
{
|
|
|
|
begindelegates.Add(method);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This removes a delegate from this action
|
|
|
|
public void UnbindBegin(ActionDelegate method)
|
|
|
|
{
|
|
|
|
begindelegates.Remove(method);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This binds a delegate to this action
|
|
|
|
public void BindEnd(ActionDelegate method)
|
2007-06-24 22:53:41 +00:00
|
|
|
{
|
2008-04-27 12:07:26 +00:00
|
|
|
enddelegates.Add(method);
|
2007-06-24 22:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This removes a delegate from this action
|
2008-04-27 12:07:26 +00:00
|
|
|
public void UnbindEnd(ActionDelegate method)
|
2007-06-24 22:53:41 +00:00
|
|
|
{
|
2008-04-27 12:07:26 +00:00
|
|
|
enddelegates.Remove(method);
|
2007-06-24 22:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This raises events for this action
|
2008-04-27 12:07:26 +00:00
|
|
|
public void Begin()
|
2007-06-24 22:53:41 +00:00
|
|
|
{
|
2007-11-07 21:14:27 +00:00
|
|
|
List<ActionDelegate> delegateslist;
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
// Method bound?
|
|
|
|
if(begindelegates.Count > 0)
|
2007-10-05 07:19:57 +00:00
|
|
|
{
|
2008-04-27 12:07:26 +00:00
|
|
|
// Copy delegates list
|
|
|
|
delegateslist = new List<ActionDelegate>(begindelegates);
|
|
|
|
|
|
|
|
// Invoke all the delegates
|
|
|
|
foreach(ActionDelegate ad in delegateslist) ad.Invoke();
|
2007-10-05 07:19:57 +00:00
|
|
|
}
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This raises events for this action
|
|
|
|
public void End()
|
|
|
|
{
|
|
|
|
List<ActionDelegate> delegateslist;
|
|
|
|
|
|
|
|
// Method bound?
|
|
|
|
if(enddelegates.Count > 0)
|
2007-10-05 07:19:57 +00:00
|
|
|
{
|
2007-11-07 21:14:27 +00:00
|
|
|
// Copy delegates list
|
2008-04-27 12:07:26 +00:00
|
|
|
delegateslist = new List<ActionDelegate>(enddelegates);
|
|
|
|
|
2007-10-05 07:19:57 +00:00
|
|
|
// Invoke all the delegates
|
2007-11-07 21:14:27 +00:00
|
|
|
foreach(ActionDelegate ad in delegateslist) ad.Invoke();
|
2007-10-05 07:19:57 +00:00
|
|
|
}
|
2007-06-24 22:53:41 +00:00
|
|
|
}
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
// This checks if the action qualifies for a key combination
|
|
|
|
public bool KeyMatches(int pressedkey)
|
|
|
|
{
|
|
|
|
return (key == (pressedkey & keymask));
|
|
|
|
}
|
|
|
|
|
2007-06-24 22:53:41 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|