2009-04-19 18:07:22 +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.Windows.Forms;
|
2014-10-22 13:07:17 +00:00
|
|
|
using CodeImp.DoomBuilder.Actions;
|
|
|
|
using Action = CodeImp.DoomBuilder.Actions.Action;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
// This Form is a workaround for the slow drawing of the .NET Forms.
|
|
|
|
// By showing the Form at 0% Opacity it allows the .NET framework to complete
|
|
|
|
// drawing the Form first, then we set it to 100% Opacity to actually show it.
|
|
|
|
// To use this class properly, set the initial Opacity of your Form to 0.
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Windows
|
|
|
|
{
|
|
|
|
public class DelayedForm : Form
|
|
|
|
{
|
|
|
|
// Variables
|
|
|
|
private Timer formshowtimer;
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public DelayedForm()
|
|
|
|
{
|
2014-10-22 13:07:17 +00:00
|
|
|
this.Opacity = 0; //mxd
|
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
//mxd. And now, let's hope this doesn't horribly break anything...
|
|
|
|
if(!(this is MainForm))
|
|
|
|
{
|
|
|
|
this.KeyPreview = true;
|
|
|
|
this.KeyUp += OnKeyUp;
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Create a timer that we need to show the form
|
|
|
|
formshowtimer = new Timer();
|
|
|
|
formshowtimer.Interval = 1;
|
2014-02-21 14:42:12 +00:00
|
|
|
formshowtimer.Tick += formshowtimer_Tick;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// When form is shown
|
|
|
|
protected override void OnShown(EventArgs e)
|
|
|
|
{
|
|
|
|
// Let the base class know
|
|
|
|
base.OnShown(e);
|
|
|
|
|
|
|
|
// Start the timer to show the form
|
|
|
|
formshowtimer.Enabled = true;
|
2014-10-22 13:07:17 +00:00
|
|
|
|
|
|
|
// Bind any methods (mxd)
|
|
|
|
if(!DesignMode) General.Actions.BindMethods(this);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// When the form is to be shown
|
|
|
|
private void formshowtimer_Tick(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Get rid of the timer
|
|
|
|
formshowtimer.Dispose();
|
|
|
|
formshowtimer = null;
|
|
|
|
|
|
|
|
if(!this.IsDisposed)
|
|
|
|
{
|
|
|
|
// Make the form visible
|
|
|
|
this.Opacity = 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
//mxd. Special handling to call "save screenshot" actions from any form,
|
|
|
|
//which inherits form DelayedForm and either doesn't override OnKeyUp, or calls base.OnKeyUp
|
|
|
|
private void OnKeyUp(object sender, KeyEventArgs e)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-12-03 09:06:05 +00:00
|
|
|
e.Handled = (Form.ActiveForm == this && ProcessSaveScreenshotAction((int)e.KeyData));
|
|
|
|
if(e.Handled) e.SuppressKeyPress = true;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2014-10-22 13:07:17 +00:00
|
|
|
|
|
|
|
// mxd. Handle screenshot saving from any form
|
|
|
|
internal static bool ProcessSaveScreenshotAction(int key)
|
|
|
|
{
|
|
|
|
Action[] actions = General.Actions.GetActionsByKey(key);
|
|
|
|
foreach(Action action in actions)
|
|
|
|
{
|
2014-10-31 09:52:07 +00:00
|
|
|
if(action.ShortName == "savescreenshot" || action.ShortName == "saveeditareascreenshot")
|
|
|
|
{
|
2014-10-22 13:07:17 +00:00
|
|
|
General.Actions.InvokeAction(action.Name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd
|
2014-12-03 09:06:05 +00:00
|
|
|
[EndAction("savescreenshot", BaseAction = true)]
|
2014-10-22 13:07:17 +00:00
|
|
|
internal void SaveScreenshot()
|
|
|
|
{
|
2014-10-31 09:52:07 +00:00
|
|
|
if(Form.ActiveForm == this) General.MainWindow.SaveScreenshot(false);
|
2014-10-22 13:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//mxd
|
2014-12-03 09:06:05 +00:00
|
|
|
[EndAction("saveeditareascreenshot", BaseAction = true)]
|
2014-10-22 13:07:17 +00:00
|
|
|
internal void SaveEditAreaScreenshot()
|
|
|
|
{
|
2014-10-31 09:52:07 +00:00
|
|
|
if(Form.ActiveForm == this) General.MainWindow.SaveScreenshot(true);
|
2014-10-22 13:07:17 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|