Added MultiTap support
This commit is contained in:
@@ -27,13 +27,15 @@ namespace OpenRA
|
|||||||
public MouseButton Button;
|
public MouseButton Button;
|
||||||
public int2 Location;
|
public int2 Location;
|
||||||
public Modifiers Modifiers;
|
public Modifiers Modifiers;
|
||||||
|
public int MultiTapCount;
|
||||||
|
|
||||||
public MouseInput( MouseInputEvent ev, MouseButton button, int2 location, Modifiers mods )
|
public MouseInput( MouseInputEvent ev, MouseButton button, int2 location, Modifiers mods, int multiTapCount )
|
||||||
{
|
{
|
||||||
this.Event = ev;
|
this.Event = ev;
|
||||||
this.Button = button;
|
this.Button = button;
|
||||||
this.Location = location;
|
this.Location = location;
|
||||||
this.Modifiers = mods;
|
this.Modifiers = mods;
|
||||||
|
this.MultiTapCount = multiTapCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,8 +68,26 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
if (world.OrderGenerator is UnitOrderGenerator)
|
if (world.OrderGenerator is UnitOrderGenerator)
|
||||||
{
|
{
|
||||||
var newSelection = SelectActorsInBox(world, dragStart, xy);
|
if (mi.MultiTapCount == 2)
|
||||||
world.Selection.Combine(world, newSelection, mi.Modifiers.HasModifier(Modifiers.Shift), dragStart == xy);
|
{
|
||||||
|
var unit = world.FindUnitsAtMouse(mi.Location).FirstOrDefault();
|
||||||
|
|
||||||
|
Rectangle visibleWorld = Game.viewport.ViewBounds(world);
|
||||||
|
var newSelection = world.FindUnits(Game.viewport.ViewToWorldPx(new int2(visibleWorld.Left, visibleWorld.Top)),
|
||||||
|
Game.viewport.ViewToWorldPx(new int2(visibleWorld.Right, visibleWorld.Bottom)))
|
||||||
|
.Where(a => a.HasTrait<Selectable>()
|
||||||
|
&& a.World.LocalShroud.IsVisible(a)
|
||||||
|
&& unit != null
|
||||||
|
&& a.Info.Name == unit.Info.Name
|
||||||
|
&& a.Owner == unit.Owner);
|
||||||
|
|
||||||
|
world.Selection.Combine(world, newSelection, true, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var newSelection = SelectActorsInBox(world, dragStart, xy);
|
||||||
|
world.Selection.Combine(world, newSelection, mi.Modifiers.HasModifier(Modifiers.Shift), dragStart == xy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
|
|||||||
101
OpenRA.Renderer.SdlCommon/MultiTapDetection.cs
Normal file
101
OpenRA.Renderer.SdlCommon/MultiTapDetection.cs
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Tao.Sdl;
|
||||||
|
using OpenRA;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
|
public static class MultiTapDetection
|
||||||
|
{
|
||||||
|
public static bool MultiTapDetected = false;
|
||||||
|
public static string VirtualKeyNameOfDetectedMultiTap = "";
|
||||||
|
public static int MouseButtonTapsCounted = 1;
|
||||||
|
|
||||||
|
static Cache<string, TapHistory> KeyHistoryCache = new Cache<string, TapHistory>(_ => new TapHistory(DateTime.Now - TimeSpan.FromSeconds(1)));
|
||||||
|
static Cache<byte, TapHistory> ClickHistoryCache = new Cache<byte, TapHistory>(_ => new TapHistory(DateTime.Now - TimeSpan.FromSeconds(1)));
|
||||||
|
|
||||||
|
|
||||||
|
public static void DetectFromMouse(byte MBName, int2 xy)
|
||||||
|
{
|
||||||
|
var clickHistory = ClickHistoryCache[MBName];
|
||||||
|
|
||||||
|
clickHistory.FirstRelease = clickHistory.SecondRelease;
|
||||||
|
clickHistory.SecondRelease = clickHistory.ThirdRelease;
|
||||||
|
clickHistory.ThirdRelease.First = DateTime.Now;
|
||||||
|
clickHistory.ThirdRelease.Second = xy;
|
||||||
|
|
||||||
|
TimeSpan DurationAfterSecondRelease = clickHistory.ThirdRelease.First - clickHistory.SecondRelease.First;
|
||||||
|
TimeSpan DurationAfterFirstRelease = clickHistory.SecondRelease.First - clickHistory.FirstRelease.First;
|
||||||
|
|
||||||
|
if ((DurationAfterSecondRelease.TotalMilliseconds < SystemInformation.DoubleClickTime)
|
||||||
|
&& ((clickHistory.ThirdRelease.Second - clickHistory.SecondRelease.Second).Length < 4)
|
||||||
|
&& ((clickHistory.ThirdRelease.Second - clickHistory.SecondRelease.Second).Length < 4))
|
||||||
|
{
|
||||||
|
MultiTapDetected = true;
|
||||||
|
MouseButtonTapsCounted = 2;
|
||||||
|
|
||||||
|
if ((DurationAfterFirstRelease.TotalMilliseconds < SystemInformation.DoubleClickTime)
|
||||||
|
&& ((clickHistory.SecondRelease.Second - clickHistory.FirstRelease.Second).Length < 4)
|
||||||
|
&& ((clickHistory.SecondRelease.Second - clickHistory.FirstRelease.Second).Length < 4))
|
||||||
|
{
|
||||||
|
MouseButtonTapsCounted = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MultiTapDetected = false;
|
||||||
|
MouseButtonTapsCounted = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DetectFromKeyboard(string KeyName)
|
||||||
|
{
|
||||||
|
var keyHistory = KeyHistoryCache[KeyName];
|
||||||
|
|
||||||
|
keyHistory.FirstRelease = keyHistory.SecondRelease;
|
||||||
|
keyHistory.SecondRelease = keyHistory.ThirdRelease;
|
||||||
|
keyHistory.ThirdRelease.First = DateTime.Now;
|
||||||
|
|
||||||
|
TimeSpan DurationAfterSecondRelease = keyHistory.ThirdRelease.First - keyHistory.SecondRelease.First;
|
||||||
|
TimeSpan DurationAfterFirstRelease = keyHistory.SecondRelease.First - keyHistory.FirstRelease.First;
|
||||||
|
|
||||||
|
if (DurationAfterSecondRelease.TotalMilliseconds < SystemInformation.DoubleClickTime)
|
||||||
|
{
|
||||||
|
MultiTapDetected = true;
|
||||||
|
VirtualKeyNameOfDetectedMultiTap = "DoubleTapOf_" + KeyName;
|
||||||
|
|
||||||
|
if (DurationAfterFirstRelease.TotalMilliseconds < SystemInformation.DoubleClickTime)
|
||||||
|
{
|
||||||
|
VirtualKeyNameOfDetectedMultiTap = "TripleTapOf_" + KeyName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MultiTapDetected = false;
|
||||||
|
VirtualKeyNameOfDetectedMultiTap = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TapHistory
|
||||||
|
{
|
||||||
|
public Pair<DateTime, int2> FirstRelease;
|
||||||
|
public Pair<DateTime, int2> SecondRelease;
|
||||||
|
public Pair<DateTime, int2> ThirdRelease;
|
||||||
|
|
||||||
|
public TapHistory(DateTime now)
|
||||||
|
{
|
||||||
|
this.FirstRelease.First = this.SecondRelease.First = this.ThirdRelease.First = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -32,8 +32,11 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="Tao.OpenGl, Version=2.1.0.12, Culture=neutral, PublicKeyToken=1ca010269a4501ef">
|
<Reference Include="Tao.OpenGl, Version=2.1.0.12, Culture=neutral, PublicKeyToken=1ca010269a4501ef">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\thirdparty\Tao\Tao.OpenGl.dll</HintPath>
|
<HintPath>..\thirdparty\Tao\Tao.OpenGl.dll</HintPath>
|
||||||
@@ -45,6 +48,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ErrorHandler.cs" />
|
<Compile Include="ErrorHandler.cs" />
|
||||||
|
<Compile Include="MultiTapDetection.cs" />
|
||||||
<Compile Include="SdlGraphics.cs" />
|
<Compile Include="SdlGraphics.cs" />
|
||||||
<Compile Include="SdlInput.cs" />
|
<Compile Include="SdlInput.cs" />
|
||||||
<Compile Include="Texture.cs" />
|
<Compile Include="Texture.cs" />
|
||||||
@@ -61,4 +65,4 @@
|
|||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
@@ -70,7 +70,7 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
lastButtonBits |= button;
|
lastButtonBits |= button;
|
||||||
|
|
||||||
inputHandler.OnMouseInput( new MouseInput(
|
inputHandler.OnMouseInput( new MouseInput(
|
||||||
MouseInputEvent.Down, button, new int2( e.button.x, e.button.y ), mods ) );
|
MouseInputEvent.Down, button, new int2( e.button.x, e.button.y ), mods, 1 ) );
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Sdl.SDL_MOUSEBUTTONUP:
|
case Sdl.SDL_MOUSEBUTTONUP:
|
||||||
@@ -84,8 +84,11 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
var button = MakeButton( e.button.button );
|
var button = MakeButton( e.button.button );
|
||||||
lastButtonBits &= ~button;
|
lastButtonBits &= ~button;
|
||||||
|
|
||||||
|
MultiTapDetection.DetectFromMouse( e.button.button, new int2( e.button.x , e.button.y ) );
|
||||||
|
|
||||||
inputHandler.OnMouseInput( new MouseInput(
|
inputHandler.OnMouseInput( new MouseInput(
|
||||||
MouseInputEvent.Up, button, new int2( e.button.x, e.button.y ), mods ) );
|
MouseInputEvent.Up, button, new int2( e.button.x, e.button.y ), mods,
|
||||||
|
MultiTapDetection.MouseButtonTapsCounted ) );
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Sdl.SDL_MOUSEMOTION:
|
case Sdl.SDL_MOUSEMOTION:
|
||||||
@@ -94,7 +97,7 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
MouseInputEvent.Move,
|
MouseInputEvent.Move,
|
||||||
lastButtonBits,
|
lastButtonBits,
|
||||||
new int2( e.motion.x, e.motion.y ),
|
new int2( e.motion.x, e.motion.y ),
|
||||||
mods );
|
mods, 0 );
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Sdl.SDL_KEYDOWN:
|
case Sdl.SDL_KEYDOWN:
|
||||||
@@ -123,6 +126,14 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
VirtKey = e.key.keysym.sym
|
VirtKey = e.key.keysym.sym
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MultiTapDetection.DetectFromKeyboard( Sdl.SDL_GetKeyName( e.key.keysym.sym ) );
|
||||||
|
|
||||||
|
if ( MultiTapDetection.MultiTapDetected )
|
||||||
|
{
|
||||||
|
keyEvent.KeyName = MultiTapDetection.VirtualKeyNameOfDetectedMultiTap;
|
||||||
|
// More info-changes here.
|
||||||
|
}
|
||||||
|
|
||||||
inputHandler.OnKeyInput( keyEvent );
|
inputHandler.OnKeyInput( keyEvent );
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user