UltimateZoneBuilder/Source/Core/Actions/MouseInput.cs
MaxED 592887a086 Configurations: increased game configuration loading speed (in previous builds it took ~650 ms. to load a single game configuration, now it takes ~120 ms. to load all 64 of them). As a side effect, New\Open Map Options, Map Options and Game Configurations windows are now opened noticeably faster. The editor starts up a bit faster as well.
Configurations: all 64 game configuration are now available by default.
Game Configurations window: game configurations can now be disabled. This setting is mostly cosmetic. When a game configuration is disabled, it won't be shown in "game configuration" dropdowns in New\Open Map Options and Map Options windows. If a map's .dbs file specifies a disabled configuration, it will be picked as a map configuration anyway.
Linedefs mode: vertex insert preview logic used Highlight range instead of Stitch range (which is used when draw mode engages).
Visual mode: double-sided middle textures were not selected when using "Select" action with "with same texture" modifier.
Textures: some optimizations in patch blending code.
ZDoom ACS script configuration: added definitions for StrLeft, StrMid and StrRight functions.
2014-02-18 14:04:14 +00:00

139 lines
3 KiB
C#

#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;
using SlimDX;
using SlimDX.DirectInput;
using CodeImp.DoomBuilder.Geometry;
#endregion
namespace CodeImp.DoomBuilder.Actions
{
internal class MouseInput : IDisposable
{
#region ================== Variables
// Mouse input
private DirectInput dinput;
private Mouse mouse;
// Disposing
private bool isdisposed;
#endregion
#region ================== Properties
public bool IsDisposed { get { return isdisposed; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public MouseInput(Control source)
{
// Initialize
dinput = new DirectInput();
// Start mouse input
mouse = new Mouse(dinput);
if(mouse == null) throw new Exception("No mouse device found.");
// Set mouse input settings
mouse.Properties.AxisMode = DeviceAxisMode.Relative;
// Set cooperative level
mouse.SetCooperativeLevel(source,
CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
// Aquire device
try { mouse.Acquire(); }
catch(Exception) { }
// We have no destructor
GC.SuppressFinalize(this);
}
// Disposer
public void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Dispose
mouse.Unacquire();
mouse.Dispose();
dinput.Dispose();
// Clean up
mouse = null;
dinput = null;
// Done
isdisposed = true;
}
}
#endregion
#region ================== Methods
#endregion
#region ================== Processing
// This processes the input
public Vector2D Process()
{
// Poll the device
try
{
Result result = mouse.Poll();
if(result.IsSuccess)
{
// Get the changes since previous poll
MouseState ms = mouse.GetCurrentState();
// Calculate changes depending on sensitivity
float changex = ms.X * General.Settings.VisualMouseSensX * General.Settings.MouseSpeed * 0.01f;
float changey = ms.Y * General.Settings.VisualMouseSensY * General.Settings.MouseSpeed * 0.01f;
// Return changes
return new Vector2D(changex, changey);
}
// Reaquire device
try { mouse.Acquire(); }
catch(Exception) { }
return new Vector2D();
}
catch(DirectInputException)
{
// Reaquire device
try { mouse.Acquire(); }
catch(Exception) { }
return new Vector2D();
}
}
#endregion
}
}