2007-06-14 23:31:57 +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
|
|
|
|
|
2007-06-13 19:39:38 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Text;
|
|
|
|
using System.Windows.Forms;
|
2007-06-24 22:53:41 +00:00
|
|
|
using CodeImp.DoomBuilder.Controls;
|
2007-06-13 19:39:38 +00:00
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-06-13 19:39:38 +00:00
|
|
|
namespace CodeImp.DoomBuilder.Interface
|
|
|
|
{
|
2007-06-26 08:03:36 +00:00
|
|
|
public partial class MainForm : DelayedForm
|
2007-06-13 19:39:38 +00:00
|
|
|
{
|
2007-06-14 14:44:18 +00:00
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
private const string STATUS_READY_TEXT = "Ready.";
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-06-14 15:35:37 +00:00
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Position/size
|
|
|
|
private Point lastposition;
|
|
|
|
private Size lastsize;
|
2007-06-24 18:56:43 +00:00
|
|
|
private bool displayresized = true;
|
|
|
|
|
2007-06-16 19:53:51 +00:00
|
|
|
// Mouse in display
|
|
|
|
private bool mouseinside;
|
|
|
|
|
2007-06-26 08:03:36 +00:00
|
|
|
// Input
|
|
|
|
private bool shift, ctrl, alt;
|
|
|
|
|
2007-06-14 15:35:37 +00:00
|
|
|
#endregion
|
2007-06-15 10:18:03 +00:00
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2007-06-16 19:53:51 +00:00
|
|
|
public bool MouseInDisplay { get { return mouseinside; } }
|
|
|
|
public Panel Display { get { return display; } }
|
2007-06-15 10:18:03 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-06-14 14:44:18 +00:00
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
2007-06-13 19:39:38 +00:00
|
|
|
// Constructor
|
|
|
|
public MainForm()
|
|
|
|
{
|
|
|
|
// Setup controls
|
|
|
|
InitializeComponent();
|
2007-06-24 22:53:41 +00:00
|
|
|
|
|
|
|
// Apply shortcut keys
|
|
|
|
ApplyShortcutKeys();
|
|
|
|
|
2007-06-14 15:35:37 +00:00
|
|
|
// Keep last position and size
|
|
|
|
lastposition = this.Location;
|
|
|
|
lastsize = this.Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Window
|
|
|
|
|
|
|
|
// Window is loaded
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Position window from configuration settings
|
|
|
|
this.SuspendLayout();
|
|
|
|
this.Location = new Point(General.Settings.ReadSetting("mainwindow.positionx", this.Location.X),
|
|
|
|
General.Settings.ReadSetting("mainwindow.positiony", this.Location.Y));
|
|
|
|
this.Size = new Size(General.Settings.ReadSetting("mainwindow.sizewidth", this.Size.Width),
|
|
|
|
General.Settings.ReadSetting("mainwindow.sizeheight", this.Size.Height));
|
|
|
|
this.WindowState = (FormWindowState)General.Settings.ReadSetting("mainwindow.windowstate", (int)FormWindowState.Maximized);
|
|
|
|
this.ResumeLayout(true);
|
|
|
|
|
|
|
|
// Normal windowstate?
|
|
|
|
if(this.WindowState == FormWindowState.Normal)
|
|
|
|
{
|
|
|
|
// Keep last position and size
|
|
|
|
lastposition = this.Location;
|
|
|
|
lastsize = this.Size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Window is moved
|
|
|
|
private void MainForm_Move(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Normal windowstate?
|
|
|
|
if(this.WindowState == FormWindowState.Normal)
|
|
|
|
{
|
|
|
|
// Keep last position and size
|
|
|
|
lastposition = this.Location;
|
|
|
|
lastsize = this.Size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-24 18:56:43 +00:00
|
|
|
// Window resizes
|
|
|
|
private void MainForm_Resize(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Resizing
|
|
|
|
//this.SuspendLayout();
|
|
|
|
//resized = true;
|
|
|
|
}
|
|
|
|
|
2007-06-14 15:35:37 +00:00
|
|
|
// Window was resized
|
|
|
|
private void MainForm_ResizeEnd(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Normal windowstate?
|
|
|
|
if(this.WindowState == FormWindowState.Normal)
|
|
|
|
{
|
|
|
|
// Keep last position and size
|
|
|
|
lastposition = this.Location;
|
|
|
|
lastsize = this.Size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Window is being closed
|
|
|
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
{
|
|
|
|
int windowstate;
|
|
|
|
|
|
|
|
// Determine window state to save
|
2007-06-24 18:56:43 +00:00
|
|
|
if(this.WindowState != FormWindowState.Minimized)
|
|
|
|
windowstate = (int)this.WindowState;
|
|
|
|
else
|
|
|
|
windowstate = (int)FormWindowState.Normal;
|
2007-06-14 15:35:37 +00:00
|
|
|
|
|
|
|
// Save settings to configuration
|
|
|
|
General.Settings.WriteSetting("mainwindow.positionx", lastposition.X);
|
|
|
|
General.Settings.WriteSetting("mainwindow.positiony", lastposition.Y);
|
|
|
|
General.Settings.WriteSetting("mainwindow.sizewidth", lastsize.Width);
|
|
|
|
General.Settings.WriteSetting("mainwindow.sizeheight", lastsize.Height);
|
|
|
|
General.Settings.WriteSetting("mainwindow.windowstate", windowstate);
|
|
|
|
|
|
|
|
// Terminate the program
|
|
|
|
General.Terminate();
|
2007-06-13 19:39:38 +00:00
|
|
|
}
|
2007-06-14 14:44:18 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Statusbar
|
|
|
|
|
|
|
|
// This changes status text
|
|
|
|
public void DisplayStatus(string status)
|
|
|
|
{
|
|
|
|
// Update status description
|
|
|
|
if(statuslabel.Text != status)
|
|
|
|
statuslabel.Text = status;
|
|
|
|
|
|
|
|
// Refresh if needed
|
|
|
|
statusbar.Invalidate();
|
|
|
|
this.Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This changes status text to Ready
|
|
|
|
public void DisplayReady()
|
|
|
|
{
|
|
|
|
// Display ready status description
|
|
|
|
DisplayStatus(STATUS_READY_TEXT);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2007-06-14 23:31:57 +00:00
|
|
|
|
2007-06-15 10:18:03 +00:00
|
|
|
#region ================== Display
|
|
|
|
|
|
|
|
// This shows the splash screen on display
|
|
|
|
public void ShowSplashDisplay()
|
|
|
|
{
|
|
|
|
// Change display to show splash logo
|
|
|
|
display.BackColor = System.Drawing.SystemColors.AppWorkspace;
|
|
|
|
display.BackgroundImage = global::CodeImp.DoomBuilder.Properties.Resources.Splash2;
|
2007-06-16 19:53:51 +00:00
|
|
|
//display.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
|
2007-06-15 18:30:55 +00:00
|
|
|
this.Update();
|
2007-06-15 10:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This clears the display
|
|
|
|
public void ClearDisplay()
|
|
|
|
{
|
|
|
|
// Clear the display
|
|
|
|
display.BackColor = Color.Black;
|
|
|
|
display.BackgroundImage = null;
|
2007-06-16 19:53:51 +00:00
|
|
|
//display.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Tile;
|
2007-06-15 18:30:55 +00:00
|
|
|
this.Update();
|
2007-06-15 10:18:03 +00:00
|
|
|
}
|
2007-06-15 18:30:55 +00:00
|
|
|
|
2007-06-15 22:38:42 +00:00
|
|
|
// Display needs repainting
|
|
|
|
private void display_Paint(object sender, PaintEventArgs e)
|
|
|
|
{
|
2007-06-24 18:56:43 +00:00
|
|
|
// Request redraw
|
|
|
|
if(!redrawtimer.Enabled) redrawtimer.Enabled = true;
|
2007-06-15 22:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Redraw requested
|
|
|
|
private void redrawtimer_Tick(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Disable timer (only redraw once)
|
|
|
|
redrawtimer.Enabled = false;
|
2007-06-24 18:56:43 +00:00
|
|
|
|
|
|
|
// Resume control layouts
|
|
|
|
if(displayresized) General.LockWindowUpdate(IntPtr.Zero);
|
2007-06-15 22:38:42 +00:00
|
|
|
|
2007-06-24 18:56:43 +00:00
|
|
|
// Map opened?
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
// Display was resized?
|
|
|
|
if(displayresized)
|
|
|
|
{
|
|
|
|
// Reset graphics to match changes
|
|
|
|
General.Map.Graphics.Reset();
|
|
|
|
|
|
|
|
// Make sure control is repainted
|
|
|
|
display.Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redraw now
|
|
|
|
General.Map.Mode.RedrawDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display resize is done
|
|
|
|
displayresized = false;
|
2007-06-15 22:38:42 +00:00
|
|
|
}
|
2007-06-16 19:53:51 +00:00
|
|
|
|
|
|
|
// Display size changes
|
|
|
|
private void display_Resize(object sender, EventArgs e)
|
|
|
|
{
|
2007-06-24 18:56:43 +00:00
|
|
|
// Resizing
|
|
|
|
if(!displayresized) General.LockWindowUpdate(display.Handle);
|
|
|
|
displayresized = true;
|
2007-06-16 19:53:51 +00:00
|
|
|
|
2007-06-24 18:56:43 +00:00
|
|
|
// Request redraw
|
|
|
|
if(!redrawtimer.Enabled) redrawtimer.Enabled = true;
|
2007-06-16 19:53:51 +00:00
|
|
|
}
|
2007-06-15 22:38:42 +00:00
|
|
|
|
2007-06-15 18:30:55 +00:00
|
|
|
// Mouse click
|
|
|
|
private void display_MouseClick(object sender, MouseEventArgs e) { if(General.Map != null) General.Map.Mode.MouseClick(e); }
|
|
|
|
|
|
|
|
// Mouse doubleclick
|
|
|
|
private void display_MouseDoubleClick(object sender, MouseEventArgs e) { if(General.Map != null) General.Map.Mode.MouseDoubleClick(e); }
|
|
|
|
|
|
|
|
// Mouse down
|
|
|
|
private void display_MouseDown(object sender, MouseEventArgs e) { if(General.Map != null) General.Map.Mode.MouseDown(e); }
|
|
|
|
|
|
|
|
// Mouse enters
|
2007-06-16 19:53:51 +00:00
|
|
|
private void display_MouseEnter(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
mouseinside = true;
|
|
|
|
if(General.Map != null) General.Map.Mode.MouseEnter(e);
|
|
|
|
}
|
2007-06-15 18:30:55 +00:00
|
|
|
|
|
|
|
// Mouse leaves
|
2007-06-16 19:53:51 +00:00
|
|
|
private void display_MouseLeave(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
mouseinside = false;
|
|
|
|
if(General.Map != null) General.Map.Mode.MouseLeave(e);
|
|
|
|
}
|
2007-06-15 18:30:55 +00:00
|
|
|
|
|
|
|
// Mouse moves
|
|
|
|
private void display_MouseMove(object sender, MouseEventArgs e) { if(General.Map != null) General.Map.Mode.MouseMove(e); }
|
|
|
|
|
|
|
|
// Mouse up
|
|
|
|
private void display_MouseUp(object sender, MouseEventArgs e) { if(General.Map != null) General.Map.Mode.MouseUp(e); }
|
2007-06-15 10:18:03 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-06-25 19:28:03 +00:00
|
|
|
#region ================== Input
|
|
|
|
|
2007-06-26 08:03:36 +00:00
|
|
|
// When the mouse wheel is changed
|
|
|
|
protected override void OnMouseWheel(MouseEventArgs e)
|
|
|
|
{
|
|
|
|
int mod = 0;
|
|
|
|
|
|
|
|
// Create modifiers
|
|
|
|
if(alt) mod |= (int)Keys.Alt;
|
|
|
|
if(shift) mod |= (int)Keys.Shift;
|
|
|
|
if(ctrl) mod |= (int)Keys.Control;
|
|
|
|
|
|
|
|
// Scrollwheel up?
|
|
|
|
if(e.Delta > 0)
|
|
|
|
{
|
|
|
|
// Invoke actions for scrollwheel
|
|
|
|
General.Actions.InvokeByKey(mod | (int)SpecialKeys.MScrollUp);
|
|
|
|
}
|
|
|
|
// Scrollwheel down?
|
|
|
|
else if(e.Delta < 0)
|
|
|
|
{
|
|
|
|
// Invoke actions for scrollwheel
|
|
|
|
General.Actions.InvokeByKey(mod | (int)SpecialKeys.MScrollDown);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let the base know
|
|
|
|
base.OnMouseWheel(e);
|
|
|
|
}
|
|
|
|
|
2007-06-25 19:28:03 +00:00
|
|
|
// When a key is pressed
|
|
|
|
private void MainForm_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
{
|
2007-06-26 08:03:36 +00:00
|
|
|
// Keep key modifiers
|
|
|
|
alt = e.Alt;
|
|
|
|
shift = e.Shift;
|
|
|
|
ctrl = e.Control;
|
|
|
|
|
2007-06-25 19:28:03 +00:00
|
|
|
// Invoke any actions associated with this key
|
|
|
|
General.Actions.InvokeByKey((int)e.KeyData);
|
|
|
|
}
|
|
|
|
|
2007-06-26 08:03:36 +00:00
|
|
|
// When a key is released
|
|
|
|
private void MainForm_KeyUp(object sender, KeyEventArgs e)
|
|
|
|
{
|
|
|
|
// Keep key modifiers
|
|
|
|
alt = e.Alt;
|
|
|
|
shift = e.Shift;
|
|
|
|
ctrl = e.Control;
|
|
|
|
}
|
|
|
|
|
2007-06-25 19:28:03 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-06-15 10:18:03 +00:00
|
|
|
#region ================== Menus
|
|
|
|
|
2007-06-24 22:53:41 +00:00
|
|
|
// Public method to apply shortcut keys
|
|
|
|
public void ApplyShortcutKeys()
|
|
|
|
{
|
|
|
|
// Apply shortcut keys to menus
|
|
|
|
ApplyShortcutKeys(menumain.Items);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This sets the shortcut keys on menu items
|
|
|
|
private void ApplyShortcutKeys(ToolStripItemCollection items)
|
|
|
|
{
|
|
|
|
ToolStripMenuItem menuitem;
|
|
|
|
string actionname;
|
|
|
|
|
|
|
|
// Go for all controls to find menu items
|
|
|
|
foreach(ToolStripItem item in items)
|
|
|
|
{
|
|
|
|
// This is a menu item?
|
|
|
|
if(item is ToolStripMenuItem)
|
|
|
|
{
|
|
|
|
// Get the item in proper type
|
|
|
|
menuitem = (item as ToolStripMenuItem);
|
|
|
|
|
|
|
|
// Tag set for this item?
|
|
|
|
if(menuitem.Tag != null)
|
|
|
|
{
|
|
|
|
// Get the action name
|
|
|
|
actionname = menuitem.Tag.ToString();
|
|
|
|
|
|
|
|
// Action with this name available?
|
|
|
|
if(General.Actions.Exists(actionname))
|
|
|
|
{
|
|
|
|
// Put the action shortcut key on the menu item
|
2007-06-25 06:55:30 +00:00
|
|
|
menuitem.ShortcutKeyDisplayString = Action.GetShortcutKeyDesc(General.Actions[actionname].ShortcutKey);
|
2007-06-24 22:53:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recursively apply shortcut keys to child menu items as well
|
|
|
|
ApplyShortcutKeys(menuitem.DropDownItems);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-15 10:18:03 +00:00
|
|
|
// This updates all menus for the current status
|
|
|
|
public void UpdateMenus()
|
|
|
|
{
|
|
|
|
// Update them all
|
|
|
|
UpdateFileMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#region ================== File Menu
|
|
|
|
|
|
|
|
// New map clicked
|
2007-06-25 14:42:23 +00:00
|
|
|
private void itemnewmap_Click(object sender, EventArgs e) { General.Actions[Action.NEWMAP].Invoke(); }
|
2007-06-16 19:53:51 +00:00
|
|
|
|
|
|
|
// Open map clicked
|
2007-06-25 14:42:23 +00:00
|
|
|
private void itemopenmap_Click(object sender, EventArgs e) { General.Actions[Action.OPENMAP].Invoke(); }
|
2007-06-14 23:31:57 +00:00
|
|
|
|
2007-06-15 10:18:03 +00:00
|
|
|
// Close map clicked
|
2007-06-25 14:42:23 +00:00
|
|
|
private void itemclosemap_Click(object sender, EventArgs e) { General.Actions[Action.CLOSEMAP].Invoke(); }
|
2007-06-15 10:18:03 +00:00
|
|
|
|
|
|
|
// Exit clicked
|
|
|
|
private void itemexit_Click(object sender, EventArgs e) { this.Close(); }
|
|
|
|
|
|
|
|
// This sets up the file menu
|
|
|
|
private void UpdateFileMenu()
|
|
|
|
{
|
|
|
|
// Enable/disable items
|
|
|
|
itemclosemap.Enabled = (General.Map != null);
|
|
|
|
itemsavemap.Enabled = (General.Map != null);
|
|
|
|
itemsavemapas.Enabled = (General.Map != null);
|
|
|
|
itemsavemapinto.Enabled = (General.Map != null);
|
|
|
|
}
|
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#endregion
|
2007-06-15 22:38:42 +00:00
|
|
|
|
|
|
|
#region ================== Help Menu
|
|
|
|
|
|
|
|
// About clicked
|
|
|
|
private void itemhelpabout_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
AboutForm aboutform;
|
|
|
|
|
|
|
|
// Show about dialog
|
|
|
|
aboutform = new AboutForm();
|
|
|
|
aboutform.ShowDialog(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2007-06-13 19:39:38 +00:00
|
|
|
}
|
|
|
|
}
|