diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 10b057b..0000000 --- a/.editorconfig +++ /dev/null @@ -1,43 +0,0 @@ -[*.cs] - -# IDE0022: 使用方法的程序块主体 -csharp_style_expression_bodied_methods = true - -# IDE0008: 使用显式类型 -csharp_style_var_elsewhere = true - -# IDE0008: 使用显式类型 -csharp_style_var_for_built_in_types = true - -# IDE0008: 使用显式类型 -csharp_style_var_when_type_is_apparent = true - -# IDE0058: 永远不会使用表达式值 -csharp_style_unused_value_expression_statement_preference = unused_local_variable - -# IDE0058: 永远不会使用表达式值 -dotnet_diagnostic.IDE0058.severity = none - -# IDE0011: 添加大括号 -csharp_prefer_braces = when_multiline - -# CA1816: Dispose 方法应调用 SuppressFinalize -dotnet_diagnostic.CA1816.severity = none - -############################### -# Core EditorConfig Options # -############################### - -insert_final_newline = true - -############################### -# .NET Coding Conventions # -############################### - -# Organize usings -dotnet_sort_system_directives_first = true - - -# Editor Guidelines extension -[*.cs] -guidelines = 120 diff --git a/.gitignore b/.gitignore index 8fc32d6..c32152f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,347 +1,8 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore - -# User-specific files -*.rsuser -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015/2017 cache/options directory .vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_h.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*_wpftmp.csproj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!?*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser -*- Backup*.rdl - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Visual Studio Code local config folder .vscode/ +bin/ +obj/ -# Remove launchSettings.json -launchSettings.json - -# Folder info on Mac -.DS_Store +*.user +LEConfig.xml +launchSettings.json \ No newline at end of file diff --git a/ErogeHelper.AssistiveTouch/App.xaml b/ErogeHelper.AssistiveTouch/App.xaml new file mode 100644 index 0000000..68e28ab --- /dev/null +++ b/ErogeHelper.AssistiveTouch/App.xaml @@ -0,0 +1,16 @@ + + + + + + + + + Segoe MDL2 Assets + + + diff --git a/ErogeHelper.AssistiveTouch/App.xaml.cs b/ErogeHelper.AssistiveTouch/App.xaml.cs new file mode 100644 index 0000000..cbfe6d8 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/App.xaml.cs @@ -0,0 +1,37 @@ +using System.Diagnostics; +using System.IO.Pipes; +using System.Windows; +using ErogeHelper.AssistiveTouch.Helper; + +namespace ErogeHelper.AssistiveTouch +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + public static Process GameProcess { get; private set; } = null!; + + public static IntPtr GameWindowHandle { get; private set; } = IntPtr.Zero; + + protected override void OnStartup(StartupEventArgs e) + { + if (e.Args.Length > 0) + { + var _pipeClient = new AnonymousPipeClientStream(PipeDirection.Out, e.Args[0]); + new IpcRenderer(_pipeClient); + + GameProcess = Process.GetProcessById(int.Parse(e.Args[1])); + + if (GameProcess is null) + { + Environment.Exit(-1); + return; + } + + GameWindowHandle = HwndTools.FindMainWindowHandle(GameProcess); + //GameWindowHandle = GameProcess.MainWindowHandle; + } + } + } +} diff --git a/ErogeHelper.AssistiveTouch/ErogeHelper.AssistiveTouch.csproj b/ErogeHelper.AssistiveTouch/ErogeHelper.AssistiveTouch.csproj new file mode 100644 index 0000000..dcc8832 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/ErogeHelper.AssistiveTouch.csproj @@ -0,0 +1,31 @@ + + + + WinExe + net8.0-windows;net472 + latest + enable + enable + true + + + + ..\app.manifest + ..\bin + None + False + + + + + + + + + + + + + + + diff --git a/ErogeHelper.AssistiveTouch/Helper/AnimationTool.cs b/ErogeHelper.AssistiveTouch/Helper/AnimationTool.cs new file mode 100644 index 0000000..7968ac5 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Helper/AnimationTool.cs @@ -0,0 +1,73 @@ +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Animation; + +namespace ErogeHelper.AssistiveTouch.Helper; + +internal static class AnimationTool +{ + private static TimeSpan TransformDuration => TouchButton.MenuTransistDuration; + + // Use with storyboard and no TransformGroup + public static readonly PropertyPath XProperty = new("(UIElement.RenderTransform).(TranslateTransform.X)"); + public static readonly PropertyPath YProperty = new("(UIElement.RenderTransform).(TranslateTransform.Y)"); + + public static DoubleAnimation FadeOutAnimation => new() + { + From = 1.0, + To = 0.0, + Duration = TransformDuration, + FillBehavior = FillBehavior.Stop, + }; + public static DoubleAnimation FadeInAnimation => new() + { + From = 0.0, + To = 1.0, + Duration = TransformDuration, + FillBehavior = FillBehavior.Stop, + }; + + // The status of menu item at animation's beginning + public static TranslateTransform ZeroTransform => new(0, 0); + public static TranslateTransform LeftOneTransform(double distance) => new(distance, 0); + public static TranslateTransform LeftTwoTransform(double distance) => new(distance * 2, 0); + public static TranslateTransform RightOneTransform(double distance) => new(-distance, 0); + public static TranslateTransform RightTwoTransform(double distance) => new(-distance * 2, 0); + public static TranslateTransform BottomOneTransform(double distance) => new(0, -distance); + public static TranslateTransform BottomTwoTransform(double distance) => new(0, -distance * 2); + + public static TranslateTransform LeftOneBottomOneTransform(double distance) => new(distance, -distance); + public static TranslateTransform LeftOneBottomTwoTransform(double distance) => new(distance, -distance * 2); + public static TranslateTransform LeftOneTopOneTransform(double distance) => new(distance, distance); + public static TranslateTransform RightOneTopOneTransform(double distance) => new(-distance, distance); + public static TranslateTransform RightOneBottomOneTransform(double distance) => new(-distance, -distance); + public static TranslateTransform RightOneBottomTwoTransform(double distance) => new(-distance, -distance * 2); + public static TranslateTransform RightTwoTopOneTransform(double distance) => new(-distance * 2, distance); + + /// + /// Used by menu items + /// + public static DoubleAnimation TransformMoveToZeroAnimation => new() + { + To = 0.0, + Duration = TransformDuration, + FillBehavior = FillBehavior.Stop, + }; + + /// + /// Binding animations in storyboard + /// + public static void BindingAnimation( + Storyboard storyboard, + AnimationTimeline animation, + DependencyObject target, + PropertyPath path, + bool freeze = false) + { + Storyboard.SetTarget(animation, target); + Storyboard.SetTargetProperty(animation, path); + if (freeze) + animation.Freeze(); + storyboard.Children.Add(animation); + } +} diff --git a/ErogeHelper.AssistiveTouch/Helper/Fullscreen.cs b/ErogeHelper.AssistiveTouch/Helper/Fullscreen.cs new file mode 100644 index 0000000..af1043d --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Helper/Fullscreen.cs @@ -0,0 +1,16 @@ +using ErogeHelper.Share; + +namespace ErogeHelper.AssistiveTouch.Helper +{ + internal class Fullscreen + { + // See: http://www.msghelp.net/showthread.php?tid=67047&pid=740345 + public static bool IsWindowFullscreen(IntPtr hwnd) + { + User32.GetWindowRect(hwnd, out var rect); + return rect.left < 50 && rect.top < 50 && + rect.Width >= User32.GetSystemMetrics(User32.SystemMetric.SM_CXSCREEN) && + rect.Height >= User32.GetSystemMetrics(User32.SystemMetric.SM_CYSCREEN); + } + } +} diff --git a/ErogeHelper.AssistiveTouch/Helper/GameWindowHooker.cs b/ErogeHelper.AssistiveTouch/Helper/GameWindowHooker.cs new file mode 100644 index 0000000..66e7c82 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Helper/GameWindowHooker.cs @@ -0,0 +1,90 @@ +using ErogeHelper.Share; +using System.Runtime.InteropServices; + +namespace ErogeHelper.AssistiveTouch.Helper; + +internal class GameWindowHooker : IDisposable +{ + public event EventHandler? SizeChanged; + + private readonly User32.HWINEVENTHOOK _windowsEventHook; + + private readonly GCHandle _gcSafetyHandle; + + public GameWindowHooker() + { + var targetThreadId = User32.GetWindowThreadProcessId(App.GameWindowHandle, out var pid); + + User32.WinEventProc winEventDelegate = WinEventCallback; + _gcSafetyHandle = GCHandle.Alloc(winEventDelegate); + + _windowsEventHook = User32.SetWinEventHook( + EventObjectLocationChange, EventObjectLocationChange, + IntPtr.Zero, winEventDelegate, pid, targetThreadId, + WinEventHookInternalFlags); + + _throttle = new(300, rectClient => + { + _rev = !_rev; + User32.SetWindowPos(MainWindow.Handle, IntPtr.Zero, 0, 0, rectClient.Width + (_rev ? 1 : -1), rectClient.Height, User32.SetWindowPosFlags.SWP_NOZORDER | User32.SetWindowPosFlags.SWP_NOMOVE); + }); + } + + // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwineventhook + private const User32.WINEVENT WinEventHookInternalFlags = User32.WINEVENT.WINEVENT_INCONTEXT | + User32.WINEVENT.WINEVENT_SKIPOWNPROCESS; //TODO test + private const uint EventObjectLocationChange = 0x800B; + private const long SWEH_CHILDID_SELF = 0; + private const int OBJID_WINDOW = 0; + + /// + /// Running in UI thread + /// + private void WinEventCallback( + User32.HWINEVENTHOOK hWinEventHook, + uint eventType, + HWND hWnd, + int idObject, + int idChild, + uint dwEventThread, + uint dwmsEventTime) + { + if (eventType == EventObjectLocationChange && + hWnd == App.GameWindowHandle && + idObject == OBJID_WINDOW && idChild == SWEH_CHILDID_SELF) + { + User32.GetClientRect(hWnd, out var rectClient); + + if (rectClient.Size != _lastGameWindowSize) + { + User32.SetWindowPos(MainWindow.Handle, IntPtr.Zero, 0, 0, rectClient.Width, rectClient.Height, User32.SetWindowPosFlags.SWP_NOZORDER | User32.SetWindowPosFlags.SWP_NOMOVE); + _lastGameWindowSize = rectClient.Size; + SizeChanged?.Invoke(this, new()); + } + else + { + // https://bugreports.qt.io/browse/QTBUG-64116?focusedCommentId=377425&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel + // HACK: Hack way to fix touch position + _throttle.Signal(rectClient); + } + + var p = new POINT(); + User32.MapWindowPoints(MainWindow.Handle, hWnd, ref p); + if (p.X != 0 || p.Y != 0) + { + User32.SetWindowPos(MainWindow.Handle, IntPtr.Zero, 0, 0, 0, 0, User32.SetWindowPosFlags.SWP_NOZORDER | User32.SetWindowPosFlags.SWP_NOSIZE); + } + } + } + + private readonly Throttle _throttle; + private bool _rev; + private System.Drawing.Size _lastGameWindowSize; + + public void Dispose() + { + _gcSafetyHandle.Free(); + // May produce EventObjectDestroy + User32.UnhookWinEvent(_windowsEventHook); + } +} diff --git a/ErogeHelper.AssistiveTouch/Helper/HwndTools.cs b/ErogeHelper.AssistiveTouch/Helper/HwndTools.cs new file mode 100644 index 0000000..d36bfa3 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Helper/HwndTools.cs @@ -0,0 +1,142 @@ +using System.Diagnostics; +using System.Runtime.InteropServices; +using ErogeHelper.Share; + +namespace ErogeHelper.AssistiveTouch.Helper; + +public static class HwndTools +{ + public static void HideWindowInAltTab(nint windowHandle) + { + if (windowHandle == IntPtr.Zero) + return; + + const int wsExToolWindow = 0x00000080; + + var exStyle = User32.GetWindowLong(windowHandle, + User32.WindowLongFlags.GWL_EXSTYLE); + exStyle |= wsExToolWindow; + _ = User32.SetWindowLong(windowHandle, User32.WindowLongFlags.GWL_EXSTYLE, exStyle); + } + + public static void WindowLostFocus(nint windowHandle, bool loseFocus) + { + if (windowHandle == IntPtr.Zero) + return; + + var exStyle = User32.GetWindowLong(windowHandle, User32.WindowLongFlags.GWL_EXSTYLE); + if (loseFocus) + { + User32.SetWindowLong(windowHandle, + User32.WindowLongFlags.GWL_EXSTYLE, + exStyle | (int)User32.WindowStylesEx.WS_EX_NOACTIVATE); + } + else + { + User32.SetWindowLong(windowHandle, + User32.WindowLongFlags.GWL_EXSTYLE, + exStyle & ~(int)User32.WindowStylesEx.WS_EX_NOACTIVATE); + } + } + + public static void RemovePopupAddChildStyle(IntPtr handle) + { + var style = (uint)User32.GetWindowLong(handle, User32.WindowLongFlags.GWL_STYLE); + style = style & ~(uint)User32.WindowStyles.WS_POPUP | (uint)User32.WindowStyles.WS_CHILD; + User32.SetWindowLong(handle, User32.WindowLongFlags.GWL_STYLE, (int)style); + } + + /// Bring game to front + public static IntPtr FindMainWindowHandle(Process proc, bool activeGame = true) + { + const int WaitGameStartTimeout = 20000; + const int UIMinimumResponseTime = 50; + + proc.WaitForInputIdle(WaitGameStartTimeout); + proc.Refresh(); + // Might be zero at first + var gameHwnd = proc.MainWindowHandle; + + if (activeGame && User32.IsIconic(proc.MainWindowHandle)) + { + User32.ShowWindow(proc.MainWindowHandle, ShowWindowCommand.SW_RESTORE); + } + + User32.GetClientRect(gameHwnd, out var clientRect); + + if (clientRect.bottom > GoodWindowHeight && + clientRect.right > GoodWindowWidth) + { + return gameHwnd; + } + else + { + var spendTime = new Stopwatch(); + spendTime.Start(); + while (spendTime.Elapsed.TotalMilliseconds < WaitGameStartTimeout) + { + if (proc.HasExited) + return IntPtr.Zero; + + // Process.MainGameHandle should included in handles + var handles = GetRootWindowsOfProcess(proc.Id); + foreach (var handle in handles) + { + User32.GetClientRect(handle, out clientRect); + if (clientRect.bottom > GoodWindowHeight && + clientRect.right > GoodWindowWidth) + { + return handle.DangerousGetHandle(); + } + } + Thread.Sleep(UIMinimumResponseTime); + } + throw new ArgumentException("Find window handle failed"); + } + } + + // private const int VNRWindowWidth = 160; + // private const int VNRWindowHeight = 120; + // private const int MinWindowSize = 12; + private const int GoodWindowWidth = 500; + private const int GoodWindowHeight = 320; + + private static IEnumerable GetRootWindowsOfProcess(int pid) + { + var rootWindows = GetChildWindows(IntPtr.Zero); + var dsProcRootWindows = new List(); + foreach (var hWnd in rootWindows) + { + _ = User32.GetWindowThreadProcessId(hWnd, out var lpdwProcessId); + if (lpdwProcessId == pid) + dsProcRootWindows.Add(hWnd); + } + return dsProcRootWindows; + } + + private static IEnumerable GetChildWindows(HWND parent) + { + List result = new(); + var listHandle = GCHandle.Alloc(result); + try + { + static bool ChildProc(HWND handle, IntPtr pointer) + { + var gch = GCHandle.FromIntPtr(pointer); + if (gch.Target is not List list) + { + throw new InvalidCastException("GCHandle Target could not be cast as List"); + } + list.Add(handle); + return true; + } + User32.EnumChildWindows(parent, ChildProc, GCHandle.ToIntPtr(listHandle)); + } + finally + { + if (listHandle.IsAllocated) + listHandle.Free(); + } + return result; + } +} diff --git a/ErogeHelper.AssistiveTouch/Helper/Symbol.cs b/ErogeHelper.AssistiveTouch/Helper/Symbol.cs new file mode 100644 index 0000000..85e62f7 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Helper/Symbol.cs @@ -0,0 +1,37 @@ +namespace ErogeHelper.AssistiveTouch.Helper +{ + /// + /// Defines constants that specify a glyph from the **Segoe MDL2 Assets** font to + /// use as the content of a SymbolIcon. + /// + public enum Symbol + { + Emoji = 0xE11D, + Tablet = 0xE70A, + Brightness = 0xE706, + Setting = 0xE713, + Attach = 0xE723, + Back = 0xE72B, + BackToWindow = 0xE73F, + FullScreen = 0xE740, + KeyboardClassic = 0xE765, + Volume = 0xE767, + Trim = 0xE78A, + TaskView = 0xE7C4, + TouchPointer = 0xE7C9, + Game = 0xE7FC, + Picture = 0xE8B9, + ChromeClose = 0xE8BB, + DockRight = 0xE90D, + Repair = 0xE90F, + Info = 0xE946, + Volume1 = 0xE993, + Cloud = 0xE753, + DictionaryCloud = 0xEBC3, + LowerBrightness = 0xEC8A, + Speech = 0xEFA9, + + SettingSolid = 0xF8B0, + TBD = 0xFFFF + } +} diff --git a/ErogeHelper.AssistiveTouch/Helper/Throttle.cs b/ErogeHelper.AssistiveTouch/Helper/Throttle.cs new file mode 100644 index 0000000..dc89c19 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Helper/Throttle.cs @@ -0,0 +1,101 @@ +// CODE FROM https://qiita.com/matarillo/items/9958b90ab04de5c2234e +namespace ErogeHelper.AssistiveTouch.Helper +{ + public sealed class Throttle : IDisposable + { + private readonly AutoResetEvent producer = new AutoResetEvent(true); + private readonly AutoResetEvent consumer = new AutoResetEvent(false); + private Tuple? value; + + private readonly int millisec; + private readonly Action action; + private volatile bool disposed = false; + private int producers = 0; + + public Throttle(int millisec, Action action) + { + this.millisec = millisec; + this.action = action; + Task.Run(() => WaitAndFire()); + } + + private void WaitAndFire() + { + Thread.CurrentThread.Name = "Throttle.cs"; + try + { + while (true) + { + producer.Set(); + consumer.WaitOne(); + if (disposed) return; + + while (true) + { + producer.Set(); + var timedOut = !consumer.WaitOne(millisec); + if (disposed) return; + if (timedOut) break; + } + // !!Enforce not null to avoid warning + Fire(action, value!.Item1, value.Item2); + value = null; + } + } + catch (ObjectDisposedException) + { + // ignore and exit + } + } + + private static void Fire(Action action, T input, SynchronizationContext? context) + { + if (context != null) + { + // !!Enforce not null to avoid warning + context.Post(state => action((T)state!), input); + } + else + { + Task.Run(() => action(input)); + } + } + + public void Signal(T input) + { + if (disposed) return; + try + { + Interlocked.Increment(ref producers); + producer.WaitOne(); + if (disposed) return; + // !!Enforce not null to avoid warning + value = Tuple.Create(input, SynchronizationContext.Current)!; + consumer.Set(); + } + catch (ObjectDisposedException) + { + // ignore and exit + } + finally + { + Interlocked.Decrement(ref producers); + } + } + + public void Dispose() + { + if (!disposed) + { + disposed = true; + while (Interlocked.CompareExchange(ref producers, 0, 0) > 0) + { + producer.Set(); + } + consumer.Set(); + producer.Dispose(); + consumer.Dispose(); + } + } + } +} diff --git a/ErogeHelper.AssistiveTouch/Helper/ToggleTouchMenuItem.xaml b/ErogeHelper.AssistiveTouch/Helper/ToggleTouchMenuItem.xaml new file mode 100644 index 0000000..8a9ba9c --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Helper/ToggleTouchMenuItem.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ErogeHelper.AssistiveTouch/Helper/ToggleTouchMenuItem.xaml.cs b/ErogeHelper.AssistiveTouch/Helper/ToggleTouchMenuItem.xaml.cs new file mode 100644 index 0000000..46381ca --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Helper/ToggleTouchMenuItem.xaml.cs @@ -0,0 +1,116 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; + +namespace ErogeHelper.AssistiveTouch.Helper +{ + public partial class ToggleTouchMenuItem : UserControl + { + #region Symbol DependencyProperty + /// Identifies the dependency property. + public static readonly DependencyProperty SymbolProperty = DependencyProperty.Register( + nameof(Symbol), + typeof(Symbol), + typeof(ToggleTouchMenuItem), + new PropertyMetadata(Symbol.Emoji, (d, e) => ((ToggleTouchMenuItem)d).OnSymbolChanged(e))); + + /// + /// Gets or sets the Segoe MDL2 Assets glyph used as the icon content. + /// + public Symbol Symbol + { + get => (Symbol)GetValue(SymbolProperty); + set => SetValue(SymbolProperty, value); + } + + protected void OnSymbolChanged(DependencyPropertyChangedEventArgs e) => + ItemIcon.SetCurrentValue(TextBlock.TextProperty, char.ConvertFromUtf32((int)e.NewValue)); + #endregion + + #region Text DependencyProperty + /// Identifies the dependency property. + public static readonly DependencyProperty TextProperty = DependencyProperty.Register( + nameof(Text), + typeof(string), + typeof(ToggleTouchMenuItem), + new PropertyMetadata(string.Empty, (d, e) => ((ToggleTouchMenuItem)d).OnTextChanged(e))); + + public string Text + { + get => (string)GetValue(TextProperty); + set => SetValue(TextProperty, value); + } + + protected void OnTextChanged(DependencyPropertyChangedEventArgs e) => + ItemText.SetCurrentValue(TextBlock.TextProperty, (string)e.NewValue); + #endregion + + #region IsOn DependencyProperty + /// Identifies the dependency property. + public static readonly DependencyProperty IsOnProperty = DependencyProperty.Register( + nameof(IsOn), + typeof(bool), + typeof(ToggleTouchMenuItem), + new PropertyMetadata(false, (d, e) => ((ToggleTouchMenuItem)d).OnIsOnChanged(e))); + + public bool IsOn + { + get => (bool)GetValue(IsOnProperty); + set => SetValue(IsOnProperty, value); + } + + protected void OnIsOnChanged(DependencyPropertyChangedEventArgs e) + { + SetItemForegroundColor((bool)e.NewValue ? ItemPressedColor : Brushes.White); + Toggled?.Invoke(this, new()); + } + #endregion + + public event EventHandler? Toggled; + + public ToggleTouchMenuItem() + { + InitializeComponent(); + } + + private static readonly Brush ItemPressedColor = new SolidColorBrush(Color.FromArgb(255, 111, 196, 241)); + + private bool _buttonPressed; + + private void ItemOnPreviewMouseLeftButtonDown(object sender, InputEventArgs e) + { + if (!TouchMenuItem.ClickLocked) + { + _buttonPressed = true; + SetItemForegroundColor(IsOn ? Brushes.DeepSkyBlue : Brushes.Gray); + } + } + + private void ItemOnPreviewMouseLeave(object sender, InputEventArgs e) + { + _buttonPressed = false; + SetItemForegroundColor(IsOn ? ItemPressedColor : Brushes.White); + } + + private void ItemOnPreviewMouseLeftButtonUp(object sender, InputEventArgs e) + { + if (_buttonPressed) + { + SetCurrentValue(IsOnProperty, !IsOn); + _buttonPressed = false; + } + } + + private void ItemOnTouchUp(object sender, TouchEventArgs e) + { + if (_buttonPressed) + { + SetCurrentValue(IsOnProperty, !IsOn); + _buttonPressed = false; + } + } + + private void SetItemForegroundColor(Brush color) => ItemIcon.Foreground = ItemText.Foreground = color; + } +} diff --git a/ErogeHelper.AssistiveTouch/Helper/TouchConversionHooker.cs b/ErogeHelper.AssistiveTouch/Helper/TouchConversionHooker.cs new file mode 100644 index 0000000..7ff6c33 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Helper/TouchConversionHooker.cs @@ -0,0 +1,76 @@ +using ErogeHelper.Share; +using System.ComponentModel; +using System.Runtime.InteropServices; + +namespace ErogeHelper.AssistiveTouch.Helper +{ + public static class TouchConversionHooker + { + // User32.MOUSEEVENTF.MOUSEEVENTF_FROMTOUCH + private const uint MOUSEEVENTF_FROMTOUCH = 0xFF515700; + + private static User32.SafeHHOOK? _hookId; + public static void Install() + { + var moduleHandle = Kernel32.GetModuleHandle(); + + _hookId = User32.SetWindowsHookEx(User32.HookType.WH_MOUSE_LL, Hook, moduleHandle, 0); + if (_hookId == IntPtr.Zero) + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + + public static void UnInstall() => _hookId?.Close(); + + private static IntPtr Hook(int nCode, IntPtr wParam, IntPtr lParam) + { + if (nCode < 0) + return User32.CallNextHookEx(_hookId, nCode, wParam, lParam); + + var obj = Marshal.PtrToStructure(lParam, typeof(User32.MSLLHOOKSTRUCT)); + if (obj is not User32.MSLLHOOKSTRUCT info) + return User32.CallNextHookEx(_hookId, nCode, wParam, lParam); + + var extraInfo = (uint)info.dwExtraInfo; + if ((extraInfo & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) + { + var isGameWindow = User32.GetForegroundWindow() == App.GameWindowHandle; + if (!isGameWindow) + return User32.CallNextHookEx(_hookId, nCode, wParam, lParam); + + switch ((int)wParam) + { + case 0x202: + Task.Run(() => + { + var (x, y) = GetCursorPosition(); + User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN, x, y, 0, IntPtr.Zero); + Thread.Sleep(UserTimerMinimum); + User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTUP, x, y, 0, IntPtr.Zero); + }); + break; + case 0x205: + Task.Run(() => + { + var (x, y) = GetCursorPosition(); + User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTDOWN, x, y, 0, IntPtr.Zero); + Thread.Sleep(UserTimerMinimum); + User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTUP, x, y, 0, IntPtr.Zero); + }); + break; + } + } + + return User32.CallNextHookEx(_hookId, nCode, wParam, lParam); + } + + private const int UserTimerMinimum = 0x0000000A; + + private static (int X, int Y) GetCursorPosition() + { + var gotPoint = User32.GetCursorPos(out var currentMousePoint); + if (!gotPoint) + currentMousePoint = new POINT(0, 0); + return (currentMousePoint.X, currentMousePoint.Y); + } + } +} diff --git a/ErogeHelper.AssistiveTouch/Helper/TouchMenuItem.xaml b/ErogeHelper.AssistiveTouch/Helper/TouchMenuItem.xaml new file mode 100644 index 0000000..16909a7 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Helper/TouchMenuItem.xaml @@ -0,0 +1,28 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ErogeHelper.AssistiveTouch/Helper/TouchMenuItem.xaml.cs b/ErogeHelper.AssistiveTouch/Helper/TouchMenuItem.xaml.cs new file mode 100644 index 0000000..eea1f1a --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Helper/TouchMenuItem.xaml.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace ErogeHelper.AssistiveTouch.Helper +{ + public partial class TouchMenuItem : UserControl + { + #region Symbol DependencyProperty + /// Identifies the dependency property. + public static readonly DependencyProperty SymbolProperty = DependencyProperty.Register( + nameof(Symbol), + typeof(Symbol), + typeof(TouchMenuItem), + new PropertyMetadata(Symbol.Emoji, (d, e) => ((TouchMenuItem)d).OnSymbolChanged(e))); + + /// + /// Gets or sets the Segoe MDL2 Assets glyph used as the icon content. + /// + public Symbol Symbol + { + get => (Symbol)GetValue(SymbolProperty); + set => SetValue(SymbolProperty, value); + } + + protected void OnSymbolChanged(DependencyPropertyChangedEventArgs e) => + ItemIcon.SetCurrentValue(TextBlock.TextProperty, char.ConvertFromUtf32((int)e.NewValue)); + #endregion + + #region Text DependencyProperty + /// Identifies the dependency property. + public static readonly DependencyProperty TextProperty = DependencyProperty.Register( + nameof(Text), + typeof(string), + typeof(TouchMenuItem), + new PropertyMetadata(string.Empty, (d, e) => ((TouchMenuItem)d).OnTextChanged(e))); + + public string Text + { + get => (string)GetValue(TextProperty); + set => SetValue(TextProperty, value); + } + + protected void OnTextChanged(DependencyPropertyChangedEventArgs e) => + ItemText.SetCurrentValue(TextBlock.TextProperty, (string)e.NewValue); + #endregion + + public event EventHandler? Click; + + public static bool ClickLocked { get; set; } + + public TouchMenuItem() + { + InitializeComponent(); + } + + private static readonly Brush ItemPressedColor = new SolidColorBrush(Color.FromArgb(255, 111, 196, 241)); + + private void ItemOnPreviewMouseLeftButtonDown(object sender, InputEventArgs e) + { + if (!ClickLocked) SetItemForegroundColor(ItemPressedColor); + } + + private void ItemOnPreviewMouseLeave(object sender, InputEventArgs e) => + SetItemForegroundColor(Brushes.White); + + private void ItemOnPreviewMouseLeftButtonUp(object sender, InputEventArgs e) + { + if (ItemIcon.Foreground != Brushes.White && !ClickLocked) + { + SetItemForegroundColor(Brushes.White); + + Click?.Invoke(this, e); + } + } + + private void ItemOnTouchUp(object sender, TouchEventArgs e) + { + if (!ClickLocked) Click?.Invoke(this, e); + } + + private void SetItemForegroundColor(Brush color) => ItemIcon.Foreground = ItemText.Foreground = color; + } +} diff --git a/ErogeHelper.AssistiveTouch/Helper/XamlResource.cs b/ErogeHelper.AssistiveTouch/Helper/XamlResource.cs new file mode 100644 index 0000000..e7a9214 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Helper/XamlResource.cs @@ -0,0 +1,40 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; + +namespace ErogeHelper.AssistiveTouch.Helper; + +internal class XamlResource +{ + public static double AssistiveTouchSize + { + get => (double)Application.Current.Resources["AssistiveTouchSize"]; + set => Application.Current.Resources["AssistiveTouchSize"] = value; + } + + public static ControlTemplate AssistiveTouchTemplate => + (ControlTemplate)Application.Current.Resources["AssistiveTouchTemplate"]; + + public static SolidColorBrush AssistiveTouchBackground => + (SolidColorBrush)Application.Current.Resources["AssistiveTouchBackground"]; + public static Thickness AssistiveTouchMenuPadding => + (Thickness)Application.Current.Resources["AssistiveTouchMenuPadding"]; + + public static void SetAssistiveTouchSize(double value) => + Application.Current.Resources["AssistiveTouchSize"] = value; + public static void SetAssistiveTouchCornerRadius(CornerRadius value) => + Application.Current.Resources["AssistiveTouchCornerRadius"] = value; + public static void SetAssistiveTouchCircleLinear(Thickness value) => + Application.Current.Resources["AssistiveTouchCircleLinear"] = value; + public static void SetAssistiveTouchLayerOneMargin(Thickness value) => + Application.Current.Resources["AssistiveTouchLayerOneMargin"] = value; + public static void SetAssistiveTouchLayerTwoMargin(Thickness value) => + Application.Current.Resources["AssistiveTouchLayerTwoMargin"] = value; + public static void SetAssistiveTouchLayerThreeMargin(Thickness value) => + Application.Current.Resources["AssistiveTouchLayerThreeMargin"] = value; + + public static void SetAssistiveTouchItemSize(double value) => + Application.Current.Resources["AssistiveTouchItemSize"] = value; + public static void SetAssistiveTouchItemBackground(SolidColorBrush value) => + Application.Current.Resources["AssistiveTouchItemBackground"] = value; +} diff --git a/ErogeHelper.AssistiveTouch/IpcRenderer.cs b/ErogeHelper.AssistiveTouch/IpcRenderer.cs new file mode 100644 index 0000000..80b8b0a --- /dev/null +++ b/ErogeHelper.AssistiveTouch/IpcRenderer.cs @@ -0,0 +1,23 @@ +using ErogeHelper.Share; +using System.IO; +using System.IO.Pipes; + +namespace ErogeHelper.AssistiveTouch +{ + internal class IpcRenderer + { + private static AnonymousPipeClientStream PipeClient = null!; + + public IpcRenderer(AnonymousPipeClientStream pipeClient) + { + PipeClient = pipeClient; + } + + public static void Send(IpcTypes channel) + { + using var sw = new StreamWriter(PipeClient); + sw.AutoFlush = true; + sw.WriteLine(channel); + } + } +} diff --git a/ErogeHelper.AssistiveTouch/MainWindow.xaml b/ErogeHelper.AssistiveTouch/MainWindow.xaml new file mode 100644 index 0000000..4b3633b --- /dev/null +++ b/ErogeHelper.AssistiveTouch/MainWindow.xaml @@ -0,0 +1,14 @@ + + + + + + diff --git a/ErogeHelper.AssistiveTouch/MainWindow.xaml.cs b/ErogeHelper.AssistiveTouch/MainWindow.xaml.cs new file mode 100644 index 0000000..0a1b6a8 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/MainWindow.xaml.cs @@ -0,0 +1,64 @@ +using ErogeHelper.AssistiveTouch.Helper; +using ErogeHelper.Share; +using System.Windows; +using System.Windows.Input; +using System.Windows.Interop; +using System.Windows.Threading; + +namespace ErogeHelper.AssistiveTouch +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public static IntPtr Handle { get; private set; } + + public MainWindow() + { + InitializeComponent(); + Handle = new WindowInteropHelper(this).EnsureHandle(); + + ContentRendered += (_, _) => IpcRenderer.Send(IpcTypes.Loaded); + + HwndTools.RemovePopupAddChildStyle(Handle); + User32.SetParent(Handle, App.GameWindowHandle); + User32.GetClientRect(App.GameWindowHandle, out var rectClient); + User32.SetWindowPos(Handle, IntPtr.Zero, 0, 0, rectClient.Width, rectClient.Height, User32.SetWindowPosFlags.SWP_NOZORDER); + + var hooker = new GameWindowHooker(); + } + + + // Use EnableTouchPointer instead but wait until DisableTouchFeedback get fixed + #region Disable Touch White Point + + protected override void OnPreviewTouchDown(TouchEventArgs e) + { + base.OnPreviewTouchDown(e); + Cursor = Cursors.None; + } + + protected override void OnPreviewTouchMove(TouchEventArgs e) + { + base.OnPreviewTouchMove(e); + Cursor = Cursors.None; + } + + protected override void OnGotMouseCapture(MouseEventArgs e) + { + base.OnGotMouseCapture(e); + Cursor = Cursors.Arrow; + } + + protected override void OnPreviewMouseMove(MouseEventArgs e) + { + base.OnPreviewMouseMove(e); + + if (e.StylusDevice == null) + Cursor = Cursors.Arrow; + } + + #endregion + } +} diff --git a/ErogeHelper.AssistiveTouch/Menu/DevicePage.xaml b/ErogeHelper.AssistiveTouch/Menu/DevicePage.xaml new file mode 100644 index 0000000..0f6595c --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Menu/DevicePage.xaml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ErogeHelper.AssistiveTouch/Menu/DevicePage.xaml.cs b/ErogeHelper.AssistiveTouch/Menu/DevicePage.xaml.cs new file mode 100644 index 0000000..d39488d --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Menu/DevicePage.xaml.cs @@ -0,0 +1,142 @@ +using ErogeHelper.AssistiveTouch.Helper; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using WindowsInput.Events; +using static System.Runtime.CompilerServices.RuntimeHelpers; + +namespace ErogeHelper.AssistiveTouch.Menu +{ + /// + public partial class DevicePage : Page, ITouchMenuPage + { + public event EventHandler? PageChanged; + + public DevicePage() + { + InitializeComponent(); + InitializeAnimation(); + } + + public void Show(double moveDistance) + { + SetCurrentValue(VisibilityProperty, Visibility.Visible); + + XamlResource.SetAssistiveTouchItemBackground(Brushes.Transparent); + + var volumeDownTransform = AnimationTool.LeftOneTransform(moveDistance); + var screenshotTransform = AnimationTool.RightOneTransform(moveDistance); + var backTransform = AnimationTool.BottomOneTransform(moveDistance); + var taskviewTransform = AnimationTool.LeftOneBottomOneTransform(moveDistance); + var dockrightTransform = AnimationTool.RightOneBottomOneTransform(moveDistance); + VolumeDown.SetCurrentValue(RenderTransformProperty, volumeDownTransform); + ScreenShot.SetCurrentValue(RenderTransformProperty, screenshotTransform); + Back.SetCurrentValue(RenderTransformProperty, backTransform); + TaskView.SetCurrentValue(RenderTransformProperty, taskviewTransform); + DockRight.SetCurrentValue(RenderTransformProperty, dockrightTransform); + + _volumeDownMoveAnimation.SetCurrentValue(DoubleAnimation.FromProperty, volumeDownTransform.X); + _screenshotMoveXAnimation.SetCurrentValue(DoubleAnimation.FromProperty, screenshotTransform.X); + _backMoveAnimation.SetCurrentValue(DoubleAnimation.FromProperty, backTransform.Y); + _taskviewMoveXAnimation.SetCurrentValue(DoubleAnimation.FromProperty, taskviewTransform.X); + _taskviewMoveYAnimation.SetCurrentValue(DoubleAnimation.FromProperty, taskviewTransform.Y); + _dockrightMoveXAnimation.SetCurrentValue(DoubleAnimation.FromProperty, dockrightTransform.X); + _dockrightMoveYAnimation.SetCurrentValue(DoubleAnimation.FromProperty, dockrightTransform.Y); + + _transitionInStoryboard.Begin(); + } + + public void Close() + { + XamlResource.SetAssistiveTouchItemBackground(Brushes.Transparent); + _transitionInStoryboard.SetCurrentValue(Timeline.AutoReverseProperty, true); + _transitionInStoryboard.Begin(); + _transitionInStoryboard.Seek(TouchButton.MenuTransistDuration); + } + + private void BackOnClickEvent(object sender, EventArgs e) => PageChanged?.Invoke(this, new(TouchMenuPageTag.DeviceBack)); + + private readonly Storyboard _transitionInStoryboard = new(); + private readonly DoubleAnimation _volumeDownMoveAnimation = AnimationTool.TransformMoveToZeroAnimation; + private readonly DoubleAnimation _screenshotMoveXAnimation = AnimationTool.TransformMoveToZeroAnimation; + private readonly DoubleAnimation _backMoveAnimation = AnimationTool.TransformMoveToZeroAnimation; + private readonly DoubleAnimation _taskviewMoveXAnimation = AnimationTool.TransformMoveToZeroAnimation; + private readonly DoubleAnimation _taskviewMoveYAnimation = AnimationTool.TransformMoveToZeroAnimation; + private readonly DoubleAnimation _dockrightMoveXAnimation = AnimationTool.TransformMoveToZeroAnimation; + private readonly DoubleAnimation _dockrightMoveYAnimation = AnimationTool.TransformMoveToZeroAnimation; + + private void InitializeAnimation() + { + AnimationTool.BindingAnimation(_transitionInStoryboard, AnimationTool.FadeInAnimation, this, new(OpacityProperty), true); + + AnimationTool.BindingAnimation(_transitionInStoryboard, _volumeDownMoveAnimation, VolumeDown, AnimationTool.XProperty); + AnimationTool.BindingAnimation(_transitionInStoryboard, _backMoveAnimation, Back, AnimationTool.YProperty); + AnimationTool.BindingAnimation(_transitionInStoryboard, _taskviewMoveXAnimation, TaskView, AnimationTool.XProperty); + AnimationTool.BindingAnimation(_transitionInStoryboard, _taskviewMoveYAnimation, TaskView, AnimationTool.YProperty); + AnimationTool.BindingAnimation(_transitionInStoryboard, _dockrightMoveXAnimation, DockRight, AnimationTool.XProperty); + AnimationTool.BindingAnimation(_transitionInStoryboard, _dockrightMoveYAnimation, DockRight, AnimationTool.YProperty); + AnimationTool.BindingAnimation(_transitionInStoryboard, _screenshotMoveXAnimation, ScreenShot, AnimationTool.XProperty); + + _transitionInStoryboard.Completed += (_, _) => + { + XamlResource.SetAssistiveTouchItemBackground(XamlResource.AssistiveTouchBackground); + + if (!_transitionInStoryboard.AutoReverse) + { + VolumeDown.SetCurrentValue(RenderTransformProperty, AnimationTool.ZeroTransform); + ScreenShot.SetCurrentValue(RenderTransformProperty, AnimationTool.ZeroTransform); + TaskView.SetCurrentValue(RenderTransformProperty, AnimationTool.ZeroTransform); + Back.SetCurrentValue(RenderTransformProperty, AnimationTool.ZeroTransform); + DockRight.SetCurrentValue(RenderTransformProperty, AnimationTool.ZeroTransform); + } + else + { + _transitionInStoryboard.SetCurrentValue(Timeline.AutoReverseProperty, false); + SetCurrentValue(VisibilityProperty, Visibility.Collapsed); + TouchMenuItem.ClickLocked = false; + } + }; + } + private async void VolumeDownOnClickEvent(object sender, EventArgs e) => + await WindowsInput.Simulate.Events() + .Click(KeyCode.VolumeDown) + .Invoke().ConfigureAwait(false); + + private async void VolumeUpOnClickEvent(object sender, EventArgs e) => + await WindowsInput.Simulate.Events() + .Click(KeyCode.VolumeUp) + .Invoke().ConfigureAwait(false); + private async void ActionCenterOnClickEvent(object sender, EventArgs e) => + await WindowsInput.Simulate.Events() + .ClickChord(KeyCode.LWin, KeyCode.A) + .Invoke().ConfigureAwait(false); + private async void TaskViewOnClickEvent(object sender, EventArgs e) => + await WindowsInput.Simulate.Events() + .ClickChord(KeyCode.LWin, KeyCode.Tab) + .Invoke().ConfigureAwait(false); + + private async void ScreenShotOnClickEvent(object sender, EventArgs e) + { + ((MainWindow)Application.Current.MainWindow).Menu.ManualClose(); + await Task.Delay(500); + await WindowsInput.Simulate.Events() + .Click(KeyCode.PrintScreen) + .Invoke().ConfigureAwait(false); + //await WindowsInput.Simulate.Events() + // .ClickChord(KeyCode.LWin, KeyCode.Shift, KeyCode.S) + // .Invoke().ConfigureAwait(false); + } + } +} diff --git a/ErogeHelper.AssistiveTouch/Menu/GamePage.xaml b/ErogeHelper.AssistiveTouch/Menu/GamePage.xaml new file mode 100644 index 0000000..0688072 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Menu/GamePage.xaml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ErogeHelper.AssistiveTouch/Menu/GamePage.xaml.cs b/ErogeHelper.AssistiveTouch/Menu/GamePage.xaml.cs new file mode 100644 index 0000000..fc480c5 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Menu/GamePage.xaml.cs @@ -0,0 +1,120 @@ +using ErogeHelper.AssistiveTouch.Helper; +using ErogeHelper.Share; +using ErogeHelper.Share.Languages; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Media.Animation; +using WindowsInput.Events; + +namespace ErogeHelper.AssistiveTouch.Menu +{ + public partial class GamePage : Page, ITouchMenuPage + { + public event EventHandler? PageChanged; + + public GamePage() + { + InitializeComponent(); + InitializeAnimation(); + + var inFullscreen = Fullscreen.IsWindowFullscreen(App.GameWindowHandle); + (FullScreenSwitcher.Symbol, FullScreenSwitcher.Text) = inFullscreen ? + (Symbol.BackToWindow, Strings.AssistiveTouch_Window) : + (Symbol.FullScreen, Strings.AssistiveTouch_FullScreen); + + TouchToMouse.Toggled += (_, _) => + { + if (TouchToMouse.IsOn) TouchConversionHooker.Install(); + else TouchConversionHooker.UnInstall(); + }; + } + + public void Show(double moveDistance) + { + SetCurrentValue(VisibilityProperty, Visibility.Visible); + + XamlResource.SetAssistiveTouchItemBackground(Brushes.Transparent); + + var fullscreenTransform = AnimationTool.RightOneTopOneTransform(moveDistance); + var backTransform = AnimationTool.RightOneTransform(moveDistance); + var closeGameTransform = AnimationTool.RightTwoTransform(moveDistance); + + FullScreenSwitcher.SetCurrentValue(RenderTransformProperty, fullscreenTransform); + Back.SetCurrentValue(RenderTransformProperty, backTransform); + CloseGame.SetCurrentValue(RenderTransformProperty, closeGameTransform); + + _fullscreenMoveXAnimation.SetCurrentValue(DoubleAnimation.FromProperty, fullscreenTransform.X); + _fullscreenMoveYAnimation.SetCurrentValue(DoubleAnimation.FromProperty, fullscreenTransform.Y); + _backMoveAnimation.SetCurrentValue(DoubleAnimation.FromProperty, backTransform.X); + _closeGameMoveAnimation.SetCurrentValue(DoubleAnimation.FromProperty, closeGameTransform.X); + + _transitionInStoryboard.Begin(); + } + + public void Close() + { + XamlResource.SetAssistiveTouchItemBackground(Brushes.Transparent); + _transitionInStoryboard.SetCurrentValue(Timeline.AutoReverseProperty, true); + _transitionInStoryboard.Begin(); + _transitionInStoryboard.Seek(TouchButton.MenuTransistDuration); + } + + private readonly Storyboard _transitionInStoryboard = new(); + private readonly DoubleAnimation _fullscreenMoveXAnimation = AnimationTool.TransformMoveToZeroAnimation; + private readonly DoubleAnimation _fullscreenMoveYAnimation = AnimationTool.TransformMoveToZeroAnimation; + private readonly DoubleAnimation _backMoveAnimation = AnimationTool.TransformMoveToZeroAnimation; + private readonly DoubleAnimation _closeGameMoveAnimation = AnimationTool.TransformMoveToZeroAnimation; + + private void InitializeAnimation() + { + AnimationTool.BindingAnimation(_transitionInStoryboard, AnimationTool.FadeInAnimation, this, new(OpacityProperty), true); + + AnimationTool.BindingAnimation(_transitionInStoryboard, _fullscreenMoveXAnimation, FullScreenSwitcher, AnimationTool.XProperty); + AnimationTool.BindingAnimation(_transitionInStoryboard, _fullscreenMoveYAnimation, FullScreenSwitcher, AnimationTool.YProperty); + AnimationTool.BindingAnimation(_transitionInStoryboard, _backMoveAnimation, Back, AnimationTool.XProperty); + AnimationTool.BindingAnimation(_transitionInStoryboard, _closeGameMoveAnimation, CloseGame, AnimationTool.XProperty); + + _transitionInStoryboard.Completed += (_, _) => + { + XamlResource.SetAssistiveTouchItemBackground(XamlResource.AssistiveTouchBackground); + + if (!_transitionInStoryboard.AutoReverse) + { + FullScreenSwitcher.SetCurrentValue(RenderTransformProperty, AnimationTool.ZeroTransform); + Back.SetCurrentValue(RenderTransformProperty, AnimationTool.ZeroTransform); + CloseGame.SetCurrentValue(RenderTransformProperty, AnimationTool.ZeroTransform); + } + else + { + _transitionInStoryboard.SetCurrentValue(Timeline.AutoReverseProperty, false); + SetCurrentValue(VisibilityProperty, Visibility.Collapsed); + TouchMenuItem.ClickLocked = false; + } + }; + } + + private const int UIMinimumResponseTime = 50; + private async void FullScreenSwitcherOnClickEvent(object sender, EventArgs e) + { + await WindowsInput.Simulate.Events() + .Hold(KeyCode.Alt) + .Hold(KeyCode.Enter) + .Wait(UIMinimumResponseTime) + .Release(KeyCode.Enter) + .Release(KeyCode.Alt) + .Invoke().ConfigureAwait(false); + } + + private void BackOnClick(object sender, EventArgs e) => PageChanged?.Invoke(this, new(TouchMenuPageTag.GameBack)); + + private void CloseGameOnClick(object sender, EventArgs e) + { + User32.PostMessage( + App.GameProcess.MainWindowHandle, + (uint)User32.WindowMessage.WM_SYSCOMMAND, + (IntPtr)User32.SysCommand.SC_CLOSE); + ((MainWindow)Application.Current.MainWindow).Menu.ManualClose(); + } + } +} diff --git a/ErogeHelper.AssistiveTouch/Menu/ITouchMenuPage.cs b/ErogeHelper.AssistiveTouch/Menu/ITouchMenuPage.cs new file mode 100644 index 0000000..768729d --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Menu/ITouchMenuPage.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ErogeHelper.AssistiveTouch.Menu +{ + interface ITouchMenuPage + { + event EventHandler? PageChanged; + + void Show(double distance); + + void Close(); + + Visibility Visibility { set; } + } + + public static class PreferencePageTag + { + public const string General = "general"; + public const string About = "about"; + public const string MeCab = "mecab"; + public const string Danmaku = "danmaku"; + public const string Trans = "trans"; + public const string TTS = "tts"; + } + + public enum TouchMenuPageTag + { + None, + Game, + GameBack, + Device, + DeviceBack, + Function, + FunctionBack + } + + public class PageEventArgs : EventArgs + { + public TouchMenuPageTag Tag { get; } + + public PageEventArgs(TouchMenuPageTag tag) + { + Tag = tag; + } + } +} + diff --git a/ErogeHelper.AssistiveTouch/Menu/MainPage.xaml b/ErogeHelper.AssistiveTouch/Menu/MainPage.xaml new file mode 100644 index 0000000..a12f516 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Menu/MainPage.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/ErogeHelper.AssistiveTouch/Menu/MainPage.xaml.cs b/ErogeHelper.AssistiveTouch/Menu/MainPage.xaml.cs new file mode 100644 index 0000000..ebb1cee --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Menu/MainPage.xaml.cs @@ -0,0 +1,42 @@ +using ErogeHelper.AssistiveTouch.Helper; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media.Animation; + +namespace ErogeHelper.AssistiveTouch.Menu +{ + public partial class MainPage : Page, ITouchMenuPage + { + private readonly DoubleAnimation _fadeOutAnimation = AnimationTool.FadeOutAnimation; + private readonly DoubleAnimation _fadeInAnimation = AnimationTool.FadeInAnimation; + + public event EventHandler? PageChanged; + + public MainPage() + { + InitializeComponent(); + _fadeOutAnimation.Completed += (_, _) => + { + Visibility = Visibility.Hidden; + TouchMenuItem.ClickLocked = false; + }; + _fadeOutAnimation.Freeze(); + _fadeInAnimation.Freeze(); + } + + public void Close() => BeginAnimation(OpacityProperty, _fadeOutAnimation); + + public void Show(double _) + { + Visibility = Visibility.Visible; + BeginAnimation(OpacityProperty, _fadeInAnimation); + } + + private void GameOnClick(object sender, EventArgs e) => PageChanged?.Invoke(this, new(TouchMenuPageTag.Game)); + + private void DeviceOnClick(object sender, EventArgs e) => PageChanged?.Invoke(this, new(TouchMenuPageTag.Device)); + + private void FunctionOnClick(object sender, EventArgs e) => PageChanged?.Invoke(this, new(TouchMenuPageTag.Function)); + + } +} diff --git a/ErogeHelper.AssistiveTouch/Properties/AssistiveTouchResource.xaml b/ErogeHelper.AssistiveTouch/Properties/AssistiveTouchResource.xaml new file mode 100644 index 0000000..201b6a0 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/Properties/AssistiveTouchResource.xaml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + 12 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ErogeHelper.AssistiveTouch/TouchButton.xaml b/ErogeHelper.AssistiveTouch/TouchButton.xaml new file mode 100644 index 0000000..f602bcf --- /dev/null +++ b/ErogeHelper.AssistiveTouch/TouchButton.xaml @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/ErogeHelper.AssistiveTouch/TouchButton.xaml.cs b/ErogeHelper.AssistiveTouch/TouchButton.xaml.cs new file mode 100644 index 0000000..2604040 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/TouchButton.xaml.cs @@ -0,0 +1,349 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using ErogeHelper.AssistiveTouch.Helper; + +namespace ErogeHelper.AssistiveTouch; + +public partial class TouchButton +{ + public static TimeSpan MenuTransistDuration { get; } = TimeSpan.FromMilliseconds(200); + + public bool IsTouchMenuOpend { get; set; } + public event EventHandler? TouchMenuClosed; + public void RaiseMenuClosedEvent(object sender) => TouchMenuClosed?.Invoke(sender, new()); + public event EventHandler? Clicked; + + // iPhone iPad 200ms, but 300ms more suit for eh + private static readonly TimeSpan TouchReleaseToEdgeDuration = TimeSpan.FromMilliseconds(300); + private static readonly TimeSpan OpacityFadeInDuration = TimeSpan.FromMilliseconds(100); + private static readonly TimeSpan OpacityTransformDuration = TimeSpan.FromMilliseconds(400); + private const int OpacityChangeDuration = 4000; + + private const double OpacityHalf = 0.4; + private const double OpacityFull = 1; + private const double ButtonSpace = 2; + + // The diameter of button use for mouse releasing + public const double TouchSize = 75; // 60, 100 + private double _distance; + private double _halfDistance; + private double _oneThirdDistance; + private double _twoThirdDistance; + + public TouchButton() + { + InitializeComponent(); + + SetAssistiveTouchProperties(); + + var mainWindow = Application.Current.MainWindow; + mainWindow.Loaded += (_, _) => SetTouchPosition(); + mainWindow.SizeChanged += (_, _) => SetTouchPosition(); + + + #region Core Logic of Moving + + var lastPosRealTime = new Point(TouchPosTransform.X, TouchPosTransform.Y); + bool isDraging = false; + bool isMoving = false; + Point relativeMousePos = default; + Point pointWhenMouseDown = default; + Point pointWhenMouseUp = default; + + PreviewMouseLeftButtonDown += (_, evt) => + { + if (isMoving) + return; + + isDraging = true; + relativeMousePos = evt.GetPosition(this); + pointWhenMouseDown = evt.GetPosition(mainWindow); + }; + + PreviewMouseMove += (_, evt) => + { + if (!isDraging) + return; + + isMoving = true; + // Max mouse event message frequency: 125 fps, dirty react 250 (2*fps) + var newPos = (Point)(evt.GetPosition(mainWindow) - relativeMousePos); + + TouchPosTransform.SetCurrentValue(TranslateTransform.XProperty, newPos.X); + TouchPosTransform.SetCurrentValue(TranslateTransform.YProperty, newPos.Y); + + lastPosRealTime = newPos; + + // if mouse go out of the edge + if (newPos.X < -_oneThirdDistance || newPos.Y < -_oneThirdDistance || + newPos.X > mainWindow.ActualWidth - _twoThirdDistance || + newPos.Y > mainWindow.ActualHeight - _twoThirdDistance) + { + RaiseMouseReleasedEventInCode(this); + } + }; + + PreviewMouseUp += (_, evt) => + { + isDraging = false; + pointWhenMouseUp = evt.GetPosition(mainWindow); + + if (isMoving && pointWhenMouseUp != pointWhenMouseDown) + { + WhenMouseReleased(mainWindow, TouchPosTransform.X, TouchPosTransform.Y); + } + }; + + PreviewMouseUp += (_, _) => { if (pointWhenMouseUp == pointWhenMouseDown) isMoving = false; }; + TranslateTouchStoryboard.Completed += (_, _) => isMoving = false; + TouchMenuClosed += (_, _) => isDraging = isMoving = false; + + #endregion Core Logic of Moving + + #region Opacity Adjust + // Fade in + PreviewMouseLeftButtonDown += (_, _) => + { + if (!isMoving && Opacity != OpacityFull) + { + BeginAnimation(OpacityProperty, FadeInOpacityAnimation); + } + }; + + // Fade out + var throttle = new Throttle(OpacityChangeDuration, (_) => + { + if (isMoving == false && IsTouchMenuOpend == false) + { + BeginAnimation(OpacityProperty, FadeOpacityAnimation); + } + }); + mainWindow.Loaded += (_, _) => throttle.Signal(default); + TranslateTouchStoryboard.Completed += (_, _) => throttle.Signal(default); + PreviewMouseUp += (_, _) => { if (pointWhenMouseUp == pointWhenMouseDown) throttle.Signal(default); }; + TouchMenuClosed += (_, _) => throttle.Signal(default); + #endregion + + FadeInOpacityAnimation.Completed += (_, _) => + { + if (pointWhenMouseUp == pointWhenMouseDown) + { + Clicked?.Invoke(this, EventArgs.Empty); + } + }; + + PreviewMouseUp += (s, e) => + { + if (pointWhenMouseUp == pointWhenMouseDown && + Opacity != OpacityHalf) + { + Clicked?.Invoke(s, e); + } + }; + + + FadeOpacityAnimation.Freeze(); + FadeInOpacityAnimation.Freeze(); + AnimationTool.BindingAnimation(TranslateTouchStoryboard, TranslateXAnimation, this, AnimationTool.XProperty); + AnimationTool.BindingAnimation(TranslateTouchStoryboard, TranslateYAnimation, this, AnimationTool.YProperty); + TranslateTouchStoryboard.Begin(); + TranslateTouchStoryboard.Stop(); + } + + private AssistiveTouchPosition TouchPosition { get; set; } = new AssistiveTouchPosition(TouchButtonCorner.Left, 0.5); + + private void SetAssistiveTouchProperties() + { + XamlResource.AssistiveTouchSize = TouchSize; + XamlResource.SetAssistiveTouchCornerRadius(new(TouchSize / 4)); + XamlResource.SetAssistiveTouchCircleLinear(new(TouchSize >= 100 ? 2 : 1.5)); + XamlResource.SetAssistiveTouchLayerOneMargin(new(TouchSize / 8)); + XamlResource.SetAssistiveTouchLayerTwoMargin(new(TouchSize * 3 / 16)); + XamlResource.SetAssistiveTouchLayerThreeMargin(new(TouchSize / 4)); + + _distance = TouchSize; + _halfDistance = _distance / 2; + _oneThirdDistance = _distance / 3; + _twoThirdDistance = _oneThirdDistance * 2; + } + private void SetTouchPosition() + { + var pos = CalculateTouchMargin(TouchSize, TouchPosition, Application.Current.MainWindow); + TouchPosTransform.SetCurrentValue(TranslateTransform.XProperty, pos.Item1); + TouchPosTransform.SetCurrentValue(TranslateTransform.YProperty, pos.Item2); + } + + private void WhenMouseReleased(FrameworkElement parent, double left, double top) + { + var parentActualHeight = parent.ActualHeight; + var parentActualWidth = parent.ActualWidth; + + // distance of button and rifht edge + var right = parentActualWidth - left - TouchSize; + // distance of button and bottom edge + var bottom = parentActualHeight - top - TouchSize; + var verticalMiddleLine = parentActualWidth / 2; + + // determinate the position where button should be with animation + if (left < _halfDistance && top < _twoThirdDistance) // top-left + { + // when the distance of button and top-left less equal than distance + left = ButtonSpace; + top = ButtonSpace; + TouchPosition = AssistiveTouchPosition.UpperLeft; + } + else if (left < _halfDistance && bottom < _twoThirdDistance) // bottom-left + { + left = ButtonSpace; + top = parentActualHeight - TouchSize - ButtonSpace; + TouchPosition = AssistiveTouchPosition.LowerLeft; + } + else if (right < _halfDistance && top < _twoThirdDistance) // top-right + { + left = parentActualWidth - TouchSize - ButtonSpace; + top = ButtonSpace; + TouchPosition = AssistiveTouchPosition.UpperRight; + } + else if (right < _halfDistance && bottom < _twoThirdDistance) // bottom-right + { + left = parentActualWidth - TouchSize - ButtonSpace; + top = parentActualHeight - TouchSize - ButtonSpace; + TouchPosition = AssistiveTouchPosition.LowerRight; + } + else if (top < _twoThirdDistance) // top + { + top = ButtonSpace; + TouchPosition = new() + { + Corner = TouchButtonCorner.Top, + Scale = (left + ButtonSpace + (TouchSize / 2)) / parentActualWidth + }; + } + else if (bottom < _twoThirdDistance) // bottom + { + top = parentActualHeight - TouchSize - ButtonSpace; + TouchPosition = new() + { + Corner = TouchButtonCorner.Bottom, + Scale = (left + ButtonSpace + (TouchSize / 2)) / parentActualWidth + }; + } + else if (left + (TouchSize / 2) < verticalMiddleLine) // left + { + left = ButtonSpace; + TouchPosition = new() + { + Corner = TouchButtonCorner.Left, + Scale = (top + ButtonSpace + (TouchSize / 2)) / parentActualHeight + }; + } + else // right + { + left = parentActualWidth - TouchSize - ButtonSpace; + TouchPosition = new() + { + Corner = TouchButtonCorner.Right, + Scale = (top + ButtonSpace + TouchSize / 2) / parentActualHeight + }; + } + + SmoothMoveAnimation(left, top); + } + + private static readonly DoubleAnimation FadeOpacityAnimation = new() + { + From = OpacityFull, + To = OpacityHalf, + Duration = OpacityTransformDuration, + }; + private static readonly DoubleAnimation FadeInOpacityAnimation = new() + { + From = OpacityHalf, + To = OpacityFull, + Duration = OpacityFadeInDuration, + }; + + private static readonly Storyboard TranslateTouchStoryboard = new(); + + private static readonly DoubleAnimation TranslateXAnimation = new() { Duration = TouchReleaseToEdgeDuration }; + private static readonly DoubleAnimation TranslateYAnimation = new() { Duration = TouchReleaseToEdgeDuration }; + + private static void RaiseMouseReleasedEventInCode(Button touch) + { + var timestamp = new TimeSpan(DateTime.Now.Ticks).Milliseconds; + + var mouseUpEvent = new MouseButtonEventArgs(Mouse.PrimaryDevice, timestamp, MouseButton.Left) + { + RoutedEvent = PreviewMouseUpEvent, + Source = touch, + }; + + touch.RaiseEvent(mouseUpEvent); + } + + private static void SmoothMoveAnimation(double left, double top) + { + if (TranslateXAnimation.To == left) + { + TranslateYAnimation.To = top; + } + else if (TranslateYAnimation.To == top) + { + TranslateXAnimation.To = left; + } + else + { + TranslateXAnimation.To = left; + TranslateYAnimation.To = top; + } + TranslateTouchStoryboard.Begin(); + } + + /// + /// Get current AsisitiveTouch margin where it should be. + /// + private static (double, double) CalculateTouchMargin( + double buttonSize, AssistiveTouchPosition touchPos, FrameworkElement parent) + { + var rightLineMargin = parent.ActualWidth - buttonSize - ButtonSpace; + var bottomLineMargin = parent.ActualHeight - buttonSize - ButtonSpace; + var verticalScaleMargin = (touchPos.Scale * parent.ActualHeight) - (buttonSize / 2) - ButtonSpace; + var horizontalScaleMargin = (touchPos.Scale * parent.ActualWidth) - buttonSize / 2 - ButtonSpace; + return touchPos.Corner switch + { + TouchButtonCorner.UpperLeft => (ButtonSpace, ButtonSpace), + TouchButtonCorner.UpperRight => (rightLineMargin, ButtonSpace), + TouchButtonCorner.LowerLeft => (ButtonSpace, bottomLineMargin), + TouchButtonCorner.LowerRight => (rightLineMargin, bottomLineMargin), + TouchButtonCorner.Left => (ButtonSpace, verticalScaleMargin), + TouchButtonCorner.Top => (horizontalScaleMargin, ButtonSpace), + TouchButtonCorner.Right => (rightLineMargin, verticalScaleMargin), + TouchButtonCorner.Bottom => (horizontalScaleMargin, bottomLineMargin), + _ => default, + }; + } +} + +public record struct AssistiveTouchPosition(TouchButtonCorner Corner, double Scale = 0) +{ + public static readonly AssistiveTouchPosition Default = new(default, 0.5); + public static readonly AssistiveTouchPosition UpperLeft = new(TouchButtonCorner.UpperLeft); + public static readonly AssistiveTouchPosition LowerLeft = new(TouchButtonCorner.LowerLeft); + public static readonly AssistiveTouchPosition UpperRight = new(TouchButtonCorner.UpperRight); + public static readonly AssistiveTouchPosition LowerRight = new(TouchButtonCorner.LowerRight); +} + +public enum TouchButtonCorner +{ + Left, + Top, + Right, + Bottom, + UpperLeft, + UpperRight, + LowerLeft, + LowerRight +} \ No newline at end of file diff --git a/ErogeHelper.AssistiveTouch/TouchMenu.xaml b/ErogeHelper.AssistiveTouch/TouchMenu.xaml new file mode 100644 index 0000000..c1ca1c4 --- /dev/null +++ b/ErogeHelper.AssistiveTouch/TouchMenu.xaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ErogeHelper.AssistiveTouch/TouchMenu.xaml.cs b/ErogeHelper.AssistiveTouch/TouchMenu.xaml.cs new file mode 100644 index 0000000..7b4271f --- /dev/null +++ b/ErogeHelper.AssistiveTouch/TouchMenu.xaml.cs @@ -0,0 +1,228 @@ +using ErogeHelper.AssistiveTouch.Helper; +using ErogeHelper.AssistiveTouch.Menu; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media.Animation; + +namespace ErogeHelper.AssistiveTouch +{ + public partial class TouchMenu : Border + { + public static TimeSpan MenuTransistDuration { get; } = TimeSpan.FromMilliseconds(200); + + private readonly ITouchMenuPage _menuMainPage = new MainPage(); + private readonly ITouchMenuPage _menuDevicePage = new DevicePage(); + private readonly ITouchMenuPage _menuGamePage = new GamePage(); + + public TouchMenu() + { + InitializeComponent(); + XamlResource.SetAssistiveTouchItemBackground(XamlResource.AssistiveTouchBackground); + + MainMenu.Navigate(_menuMainPage); + GameMenu.Navigate(_menuGamePage); + DeviceMenu.Navigate(_menuDevicePage); + + _menuMainPage.PageChanged += (s, e) => PageNavigation(e.Tag); + _menuGamePage.PageChanged += (s, e) => PageNavigation(e.Tag); + _menuDevicePage.PageChanged += (s, e) => PageNavigation(e.Tag); + + var mainWindow = (MainWindow)Application.Current.MainWindow; + + Loaded += (_, _) => UpdateProperties(TouchButton.TouchSize); + + Loaded += (_, _) => mainWindow.SizeChanged += (_, e) => + { + if (e.HeightChanged && e.NewSize.Height > EndureEdgeHeight) + { + UpdateMenuSize(e.NewSize.Height); + } + }; + + #region Move Logic + var isOpen = false; + var isAnimating = false; + + mainWindow.Touch.Clicked += (_, _) => + { + TouchMenuItem.ClickLocked = true; + Visibility = Visibility.Visible; + mainWindow.Touch.Visibility = Visibility.Hidden; + mainWindow.Touch.IsTouchMenuOpend = isOpen = isAnimating = true; + + _menuMainPage.Visibility = Visibility.Visible; + _menuGamePage.Visibility = Visibility.Collapsed; + _menuDevicePage.Visibility = Visibility.Collapsed; + + var relativeBeginX = mainWindow.Width / 2 - mainWindow.Touch.ActualWidth / 2; + var relativeBeginY = mainWindow.Height / 2 - mainWindow.Touch.ActualWidth / 2; + + TransformXAnimation.From = mainWindow.Touch.TouchPosTransform.X - relativeBeginX; + TransformYAnimation.From = mainWindow.Touch.TouchPosTransform.Y - relativeBeginY; + MovementStoryboard.Begin(); + }; + + void CloseMenuInternel() + { + if (!isAnimating) + { + isAnimating = true; + FakeWhitePoint.Visibility = Visibility.Visible; + MovementStoryboard.AutoReverse = true; + MovementStoryboard.Begin(); + MovementStoryboard.Seek(MenuTransistDuration); + } + } + // TODO Nonuse change + mainWindow.Deactivated += (_, _) => { if (isOpen == true) CloseMenuInternel(); }; + PreviewMouseLeftButtonUp += (_, e) => { if (e.OriginalSource is TouchMenu && !TouchMenuItem.ClickLocked) CloseMenuInternel(); }; + + // Mene opend + MovementStoryboard.Completed += (_, _) => + { + if (MovementStoryboard.AutoReverse == false) + { + isAnimating = false; + TouchMenuItem.ClickLocked = false; + FakeWhitePoint.Visibility = Visibility.Hidden; + } + }; + + // Menu closed + MovementStoryboard.Completed += (_, _) => + { + // FIXEME: after window size change the touch position + if (MovementStoryboard.AutoReverse == true) + { + mainWindow.Touch.IsTouchMenuOpend = isOpen = isAnimating = false; + MovementStoryboard.AutoReverse = false; + mainWindow.Touch.Visibility = Visibility.Visible; + mainWindow.Touch.RaiseMenuClosedEvent(this); + Visibility = Visibility.Hidden; + } + }; + + // Initialize animations + var fakePointAnimation = AnimationTool.FadeOutAnimation; + fakePointAnimation.FillBehavior = FillBehavior.HoldEnd; + fakePointAnimation.EasingFunction = UnifiedPowerFunction; + AnimationTool.BindingAnimation(MovementStoryboard, fakePointAnimation, FakeWhitePoint, new(OpacityProperty), true); + AnimationTool.BindingAnimation(MovementStoryboard, AnimationTool.FadeInAnimation, MenuArea, new(OpacityProperty), true); + AnimationTool.BindingAnimation(MovementStoryboard, TransformXAnimation, this, AnimationTool.XProperty); + AnimationTool.BindingAnimation(MovementStoryboard, TransformYAnimation, this, AnimationTool.YProperty); + #endregion + } + + public void ManualClose() + { + FakeWhitePoint.Visibility = Visibility.Visible; + MovementStoryboard.AutoReverse = true; + MovementStoryboard.Begin(); + MovementStoryboard.Seek(MenuTransistDuration); + } + + /// + /// Must initialize first after MainWindow loaded + /// + private void UpdateProperties(double touchSize) + { + MaxHeight = MaxWidth = touchSize * 5; + EndureEdgeHeight = MaxHeight / 10; + XamlResource.SetAssistiveTouchItemSize(touchSize / 2); + UpdateMenuSize(Application.Current.MainWindow.Height); + + // Update width height animation + UpdateMenuSizeAnimation(touchSize); + } + + /// + /// The minimal distance between window top to menu edge + /// + private double EndureEdgeHeight { get; set; } + + #region X Y Width Height Animations + private static readonly PowerEase UnifiedPowerFunction = new() { EasingMode = EasingMode.EaseInOut }; + private static readonly Storyboard MovementStoryboard = new(); + private static readonly DoubleAnimation TransformXAnimation = new() + { + Duration = MenuTransistDuration, + EasingFunction = UnifiedPowerFunction + }; + private static readonly DoubleAnimation TransformYAnimation = new() + { + Duration = MenuTransistDuration, + EasingFunction = UnifiedPowerFunction + }; + private static DoubleAnimation? _widthAnimation; + private static DoubleAnimation? _heightAnimation; + + /// + /// Called when menu size changed. + /// + /// Dependent on touch button size + private void UpdateMenuSizeAnimation(double touchSize) + { + MovementStoryboard.Children.Remove(_widthAnimation); + MovementStoryboard.Children.Remove(_heightAnimation); + + _widthAnimation = new() + { + From = touchSize, + Duration = MenuTransistDuration, + EasingFunction = UnifiedPowerFunction + }; + _heightAnimation = new() + { + From = touchSize, + Duration = MenuTransistDuration, + EasingFunction = UnifiedPowerFunction + }; + + AnimationTool.BindingAnimation(MovementStoryboard, _widthAnimation, this, new(WidthProperty), true); + AnimationTool.BindingAnimation(MovementStoryboard, _heightAnimation, this, new(HeightProperty), true); + } + #endregion + + /// + /// When game window height changed, update this menu size. + /// + private void UpdateMenuSize(double newGameWindowHeight) + { + // The normal size of menu + if (newGameWindowHeight > EndureEdgeHeight + MaxHeight) + { + Height = Width = MaxHeight; + } + // Small scaled size of menu + else + { + var newSize = newGameWindowHeight - EndureEdgeHeight; + Height = Width = newSize > 0 ? newSize : 0; + } + } + + private void PageNavigation(TouchMenuPageTag nav) + { + TouchMenuItem.ClickLocked = true; + switch (nav) + { + case TouchMenuPageTag.Game: + _menuMainPage.Close(); + _menuGamePage.Show(Height / 3); + break; + case TouchMenuPageTag.GameBack: + _menuMainPage.Show(0); + _menuGamePage.Close(); + break; + case TouchMenuPageTag.Device: + _menuMainPage.Close(); + _menuDevicePage.Show(Height / 3); + break; + case TouchMenuPageTag.DeviceBack: + _menuMainPage.Show(0); + _menuDevicePage.Close(); + break; + } + } + } +} diff --git a/ErogeHelper.Installer/App.xaml b/ErogeHelper.Installer/App.xaml deleted file mode 100644 index d6a00be..0000000 --- a/ErogeHelper.Installer/App.xaml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/ErogeHelper.Installer/App.xaml.cs b/ErogeHelper.Installer/App.xaml.cs deleted file mode 100644 index a20a966..0000000 --- a/ErogeHelper.Installer/App.xaml.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; -using System.Windows; - -namespace ErogeHelper.Installer -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App - { - public App() - { - SingleInstanceWatcher(); - var currentDirectory = Path.GetDirectoryName(AppContext.BaseDirectory); - Directory.SetCurrentDirectory(currentDirectory ?? - throw new ArgumentNullException(nameof(currentDirectory))); - } - - private const string UniqueEventName = "{2d0ccd54-f861-46be-9804-43aff3775111}"; - private EventWaitHandle _eventWaitHandle = null!; - - private void SingleInstanceWatcher() - { - try - { - _eventWaitHandle = EventWaitHandle.OpenExisting(UniqueEventName); - _eventWaitHandle.Set(); - Shutdown(); - } - catch (WaitHandleCannotBeOpenedException) - { - _eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, UniqueEventName); - } - - new Task(() => - { - while (_eventWaitHandle.WaitOne()) - { - Current.Dispatcher.Invoke(() => - { - if (Current.MainWindow is not null) - { - var mainWindow = Current.MainWindow; - - if (mainWindow.WindowState == WindowState.Minimized || mainWindow.Visibility != Visibility.Visible) - { - mainWindow.Show(); - mainWindow.WindowState = WindowState.Normal; - } - - mainWindow.Activate(); - mainWindow.Topmost = true; - mainWindow.Topmost = false; - mainWindow.Focus(); - } - }); - } - }) - .Start(); - } - } -} diff --git a/ErogeHelper.Installer/AssemblyInfo.cs b/ErogeHelper.Installer/AssemblyInfo.cs deleted file mode 100644 index 8b5504e..0000000 --- a/ErogeHelper.Installer/AssemblyInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Windows; - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] diff --git a/ErogeHelper.Installer/ErogeHelper.Installer.csproj b/ErogeHelper.Installer/ErogeHelper.Installer.csproj deleted file mode 100644 index d3f134b..0000000 --- a/ErogeHelper.Installer/ErogeHelper.Installer.csproj +++ /dev/null @@ -1,32 +0,0 @@ - - - - WinExe - net6.0-windows10.0.19041.0 - enable - true - 1.0.0 - k1mlka - app.manifest - app.ico - ..\bin\$(Configuration) - false - true - AnyCPU;x86 - - - - - PreserveNewest - - - - - - - - - - - - diff --git a/ErogeHelper.Installer/ExplorerHelper.cs b/ErogeHelper.Installer/ExplorerHelper.cs deleted file mode 100644 index 0e740e4..0000000 --- a/ErogeHelper.Installer/ExplorerHelper.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Text; - -namespace ErogeHelper.Installer -{ - internal static class ExplorerHelper - { - public static List GetOpenedDirectories() => new OpenedDirectoryGenerator().Paths; - - public static void KillExplorer() - { - var processes = Process.GetProcessesByName("explorer"); - - foreach (var process in processes) - { - process.Kill(); - } - } - - public static void OpenDirectories(List directories) - { - foreach (var dir in directories) - { - Process.Start("explorer", dir); - } - } - - private class OpenedDirectoryGenerator - { - public OpenedDirectoryGenerator() => _ = EnumWindows(Report, 0); - - public List Paths { get; private set; } = new(); - - #region Win32 Apis - private delegate bool CallBack(int hWnd, int y); - - [DllImport("user32.dll")] - private static extern int EnumWindows(CallBack x, int y); - - [DllImport("user32.dll", CharSet = CharSet.Unicode)] - private static extern int GetWindowText(int hWnd, StringBuilder lPtrString, int nMaxCount); - - [DllImport("user32.dll")] - private static extern int GetParent(int hWnd); - - [DllImport("user32.dll")] - private static extern bool IsWindowVisible(int hWnd); - - [DllImport("user32.Dll", CharSet = CharSet.Unicode)] - private static extern void GetClassName(IntPtr hWnd, StringBuilder s, int nMaxCount); - - [DllImport("user32.dll", CharSet = CharSet.Unicode)] - private static extern IntPtr FindWindowEx(IntPtr parent, IntPtr child, string strClass, string? frmText); - - private static IntPtr FindWindowEx(IntPtr parent, string strClass) - => FindWindowEx(parent, IntPtr.Zero, strClass, null); - - private static string GetFormClassName(IntPtr ptr) - { - var nameBuilder = new StringBuilder(255); - GetClassName(ptr, nameBuilder, 255); - return nameBuilder.ToString(); - } - - private static string GetFormTitle(IntPtr ptr) - { - var titleBuilder = new StringBuilder(255); - _ = GetWindowText((int)ptr, titleBuilder, 255); - return titleBuilder.ToString(); - } - - private bool Report(int hWnd, int lParam) - { - var pHWnd = GetParent(hWnd); - if (pHWnd == 0 && IsWindowVisible(hWnd)) - { - var cabinetWClassIntPtr = new IntPtr(hWnd); - var cabinetWClassName = GetFormClassName(cabinetWClassIntPtr); - if (cabinetWClassName.Equals("CabinetWClass", StringComparison.OrdinalIgnoreCase)) - { - var workerWIntPtr = FindWindowEx(cabinetWClassIntPtr, "WorkerW"); - var reBarWindow32IntPtr = FindWindowEx(workerWIntPtr, "ReBarWindow32"); - var addressBandRootIntPtr = FindWindowEx(reBarWindow32IntPtr, "Address Band Root"); - var msctlsProgress32IntPtr = FindWindowEx(addressBandRootIntPtr, "msctls_progress32"); - var breadcrumbParentIntPtr = FindWindowEx(msctlsProgress32IntPtr, "Breadcrumb Parent"); - var toolbarWindow32IntPtr = FindWindowEx(breadcrumbParentIntPtr, "ToolbarWindow32"); - - var title = GetFormTitle(toolbarWindow32IntPtr); - - var index = title.IndexOf(':') + 1; - Paths.Add(title[index..]); - } - } - return true; - } - #endregion - } - } -} diff --git a/ErogeHelper.Installer/MainWindow.xaml b/ErogeHelper.Installer/MainWindow.xaml deleted file mode 100644 index 2007e2f..0000000 --- a/ErogeHelper.Installer/MainWindow.xaml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/ErogeHelper/View/Controllers/AssistiveTouch.xaml.cs b/ErogeHelper/View/Controllers/AssistiveTouch.xaml.cs deleted file mode 100644 index d2b03a6..0000000 --- a/ErogeHelper/View/Controllers/AssistiveTouch.xaml.cs +++ /dev/null @@ -1,417 +0,0 @@ -using System.IO; -using System.Reactive; -using System.Reactive.Disposables; -using System.Reactive.Linq; -using System.Reactive.Subjects; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using System.Windows.Media.Animation; -using ErogeHelper.Functions; -using ErogeHelper.Shared; -using ErogeHelper.Shared.Contracts; -using ErogeHelper.Shared.Entities; -using ErogeHelper.ViewModel.Controllers; -using ErogeHelper.ViewModel.Windows; -using ModernWpf.Controls; -using ModernWpf.Controls.Primitives; -using ReactiveMarbles.ObservableEvents; -using ReactiveUI; -using Splat; -using WindowsInput.Events; - -namespace ErogeHelper.View.Controllers; - -public partial class AssistiveTouch : IEnableLogger -{ - private const double OpacityValue = 0.4; - private const double OpacityNormal = 1; - private const double ButtonSpace = 2; - - // The diameter of button use for mouse releasing - private double _distance; - private double _halfDistance; - private double _oneThirdDistance; - private double _twoThirdDistance; - - private double _buttonSize; - - public AssistiveTouch() - { - InitializeComponent(); - - ViewModel ??= DependencyResolver.GetService(); - - var touchPosition = ViewModel!.AssistiveTouchPosition; - var isTouchBigSize = ViewModel!.IsTouchBigSize; - - - FrameworkElement? parent = null; - CompositeDisposable disposables = new(); - - AssistiveButton.Loaded += (_, _) => - { - parent ??= Parent is not FrameworkElement reactiveViewModelViewHost - ? throw new InvalidOperationException("Control's parent must be FrameworkElement type") - : reactiveViewModelViewHost; - - UpdateButtonDiameterProperties(isTouchBigSize, touchPosition, parent); - - parent.Events().SizeChanged - .Subscribe(_ => AssistiveButton.Margin = GetButtonEdgeMargin(_buttonSize, touchPosition, parent)) - .DisposeWith(disposables); - }; - - #region Opacity Adjust - Point lastPos; - var isMoving = false; - BehaviorSubject tryTransparentizeSubj = new(true); - tryTransparentizeSubj - .Throttle(TimeSpan.FromMilliseconds(ConstantValue.AssistiveTouchOpacityChangedTime)) - .ObserveOn(RxApp.MainThreadScheduler) - .Where(on => on && isMoving == false && AssistiveTouchFlyout.IsOpen == false) - .Subscribe(_ => AssistiveButton.Opacity = OpacityValue); - - AssistiveTouchFlyout.Events().Closed - .Subscribe(_ => tryTransparentizeSubj.OnNext(true)) - .DisposeWith(disposables); - #endregion - - #region Core Logic of Moving - - var updateStatusWhenMouseDown = AssistiveButton.Events().PreviewMouseLeftButtonDown; - var mouseMoveAndCheckEdge = this.Events().PreviewMouseMove; - var mouseRelease = this.Events().PreviewMouseUp; - - updateStatusWhenMouseDown.Subscribe(evt => - { - AssistiveButton.Opacity = OpacityNormal; - isMoving = true; - tryTransparentizeSubj.OnNext(true); - lastPos = evt.GetPosition(parent); - _oldPos = lastPos; - }); - - mouseMoveAndCheckEdge.Subscribe(evt => - { - if (!isMoving || parent is null) - return; - - var pos = evt.GetPosition(parent); - // 相对左上坐标 + 新位置与旧位置的差值 = 新坐标 - var left = AssistiveButton.Margin.Left + pos.X - lastPos.X; - var top = AssistiveButton.Margin.Top + pos.Y - lastPos.Y; - - // dummy problem UserControl would clip if Button get out of the bottom of window - var workaround = 0.0; - var outerBounds = top + _buttonSize; - if (outerBounds > parent.ActualHeight) - { - workaround = parent.ActualHeight - outerBounds; - } - - AssistiveButton.Margin = new Thickness(left, top, 0, workaround); - - lastPos = pos; - - // When mouse out the edge - if (left < -_oneThirdDistance || top < -_oneThirdDistance || - left > parent.ActualWidth - _twoThirdDistance || top > parent.ActualHeight - _twoThirdDistance) - { - RaiseMouseUpEventInCode(AssistiveButton, this); - } - }); - - mouseRelease.Subscribe(evt => - { - if (!isMoving || parent is null) - return; - - double parentActualWidth; - double parentActualHeight; - double curMarginLeft; - double curMarginTop; - - var pos = evt.GetPosition(parent); - _newPos = pos; - parentActualHeight = parent.ActualHeight; - parentActualWidth = parent.ActualWidth; - curMarginLeft = AssistiveButton.Margin.Left; - curMarginTop = AssistiveButton.Margin.Top; - - var left = curMarginLeft + _newPos.X - lastPos.X; - var top = curMarginTop + _newPos.Y - lastPos.Y; - // button 距离右边缘距离 - var right = parentActualWidth - left - _buttonSize; - // button 距离下边缘距离 - var bottom = parentActualHeight - top - _buttonSize; - var verticalMiddleLine = parentActualWidth / 2; - - // 根据button所处屏幕位置来确定button之后应该动画移动到的位置 - if (left < _halfDistance && top < _twoThirdDistance) // button 距离左上角边距同时小于 distance - { - left = ButtonSpace; - top = ButtonSpace; - touchPosition = AssistiveTouchPosition.UpperLeft; - } - else if (left < _halfDistance && bottom < _twoThirdDistance) // bottom-left - { - left = ButtonSpace; - top = parentActualHeight - _buttonSize - ButtonSpace; - touchPosition = AssistiveTouchPosition.LowerLeft; - } - else if (right < _halfDistance && top < _twoThirdDistance) // top-right - { - left = parentActualWidth - _buttonSize - ButtonSpace; - top = ButtonSpace; - touchPosition = AssistiveTouchPosition.UpperRight; - } - else if (right < _halfDistance && bottom < _twoThirdDistance) // bottom-right - { - left = parentActualWidth - _buttonSize - ButtonSpace; - top = parentActualHeight - _buttonSize - ButtonSpace; - touchPosition = AssistiveTouchPosition.LowerRight; - } - else if (top < _twoThirdDistance) // top - { - left = curMarginLeft; - top = ButtonSpace; - var scale = (curMarginLeft + ButtonSpace + (_buttonSize / 2)) / parentActualWidth; - touchPosition.Corner = TouchButtonCorner.Top; - touchPosition.Scale = scale; - } - else if (bottom < _twoThirdDistance) // bottom - { - left = curMarginLeft; - top = parentActualHeight - _buttonSize - ButtonSpace; - var scale = (curMarginLeft + ButtonSpace + (_buttonSize / 2)) / parentActualWidth; - touchPosition.Corner = TouchButtonCorner.Bottom; - touchPosition.Scale = scale; - } - else if (left + (_buttonSize / 2) < verticalMiddleLine) // left - { - left = ButtonSpace; - top = curMarginTop; - var scale = (curMarginTop + ButtonSpace + (_buttonSize / 2)) / parentActualHeight; - touchPosition.Corner = TouchButtonCorner.Left; - touchPosition.Scale = scale; - } - else // right - { - left = parentActualWidth - _buttonSize - ButtonSpace; - top = curMarginTop; - var scale = (curMarginTop + ButtonSpace + _buttonSize / 2) / parentActualHeight; - touchPosition.Corner = TouchButtonCorner.Right; - touchPosition.Scale = scale; - } - - SmoothMoveAnimation(AssistiveButton, left, top); - isMoving = false; - tryTransparentizeSubj.OnNext(true); - AssistiveTouchFlyout.Placement = GetFlyoutPlacement(touchPosition); - ViewModel.AssistiveTouchPositionChanged.OnNext(touchPosition); - }); - - #endregion Core Logic of Moving - - this.WhenActivated(d => - { - disposables.DisposeWith(d); - ViewModel.DisposeWith(d); - - this.WhenAnyObservable(x => x.ViewModel!.UseBigSize) - .Subscribe(isBigSize => - UpdateButtonDiameterProperties(isBigSize, touchPosition, parent!)).DisposeWith(d); - - var backToWindowIcon = new SymbolIcon { Symbol = Symbol.BackToWindow }; - var fullScreenIcon = new SymbolIcon { Symbol = Symbol.FullScreen }; - this.OneWayBind(ViewModel, - vm => vm.SwitchFullScreenIcon, - v => v.FullScreenSwitcher.Icon, - iconEnum => iconEnum switch - { - SymbolName.BackToWindow => backToWindowIcon, - SymbolName.FullScreen => fullScreenIcon, - _ => throw new InvalidCastException(), - }).DisposeWith(d); - this.OneWayBind(ViewModel, - vm => vm.SwitchFullScreenToolTip, - v => v.FullScreenSwitcher.ToolTip).DisposeWith(d); - - this.Bind(ViewModel, - vm => vm.LoseFocusEnable, - v => v.LoseFocusToggle.IsChecked).DisposeWith(d); - - this.Bind(ViewModel, - vm => vm.TouchBoxEnable, - v => v.TouchBoxToggle.IsChecked).DisposeWith(d); - this.Bind(ViewModel, - vm => vm.TouchBoxSwitcherVisible, - v => v.TouchBoxToggle.Visibility, - on => on ? Visibility.Visible : Visibility.Collapsed, - visible => visible == Visibility.Visible).DisposeWith(d); - - this.Bind(ViewModel, - vm => vm.IsTouchToMouse, - v => v.TouchConversionToggle.IsChecked).DisposeWith(d); - - // Custom apearrence: ButtonSpace, square to circle, size of the square - }); - } - - private static readonly double AssistiveTouchSize = - (double)Application.Current.Resources["AssistiveTouchSize"]; - private static readonly double AssistiveTouchBigSize = - (double)Application.Current.Resources["BigAssistiveTouchSize"]; - - private void UpdateButtonDiameterProperties - (bool isBigSize, AssistiveTouchPosition touchPosition, FrameworkElement parent) - { - AssistiveButton.Template = GetAssistiveTouchStyle(isBigSize); - _buttonSize = isBigSize ? AssistiveTouchBigSize : AssistiveTouchSize; - _distance = _buttonSize; - _halfDistance = _distance / 2; - _oneThirdDistance = _distance / 3; - _twoThirdDistance = _oneThirdDistance * 2; - - AssistiveButton.Margin = GetButtonEdgeMargin(_buttonSize, touchPosition, parent); - AssistiveTouchFlyout.Placement = GetFlyoutPlacement(touchPosition); - } - - private static ControlTemplate GetAssistiveTouchStyle(bool useBigSize) => - useBigSize ? Application.Current.Resources["BigAssistiveTouchTemplate"] - as ControlTemplate - ?? throw new IOException("Cannot locate resource 'BigAssistiveTouchTemplate'") - : Application.Current.Resources["NormalAssistiveTouchTemplate"] - as ControlTemplate - ?? throw new IOException("Cannot locate resource 'NormalAssistiveTouchTemplate'"); - - private static void RaiseMouseUpEventInCode(Button button, UIElement father) - { - var timestamp = new TimeSpan(DateTime.Now.Ticks).Milliseconds; - - var mouseUpEvent = new MouseButtonEventArgs(Mouse.PrimaryDevice, timestamp, MouseButton.Left) - { - RoutedEvent = PreviewMouseUpEvent, - Source = button, - }; - - father.RaiseEvent(mouseUpEvent); - } - - private static void SmoothMoveAnimation(Button button, double left, double top) - { - var marginAnimation = new ThicknessAnimation - { - From = button.Margin, - To = new Thickness(left, top, 0, 0), - Duration = TimeSpan.FromMilliseconds(300) - }; - - Storyboard story = new() - { - FillBehavior = FillBehavior.Stop - }; - story.Children.Add(marginAnimation); - Storyboard.SetTargetName(marginAnimation, nameof(AssistiveButton)); - Storyboard.SetTargetProperty(marginAnimation, new PropertyPath("(0)", MarginProperty)); - - story.Begin(button); - - button.Margin = new Thickness(left, top, 0, 0); - } - - private static Thickness GetButtonEdgeMargin( - double buttonSize, AssistiveTouchPosition pos, FrameworkElement parent) - { - var rightLineMargin = parent.ActualWidth - buttonSize - ButtonSpace; - var bottomLineMargin = parent.ActualHeight - buttonSize - ButtonSpace; - var verticalScaleMargin = (pos.Scale * parent.ActualHeight) - (buttonSize / 2) - ButtonSpace; - var horizontalScaleMargin = (pos.Scale * parent.ActualWidth) - buttonSize / 2 - ButtonSpace; - return pos.Corner switch - { - TouchButtonCorner.UpperLeft => new Thickness(ButtonSpace, ButtonSpace, 0, 0), - TouchButtonCorner.UpperRight => new Thickness(rightLineMargin, ButtonSpace, 0, 0), - TouchButtonCorner.LowerLeft => new Thickness(ButtonSpace, bottomLineMargin, 0, 0), - TouchButtonCorner.LowerRight => new Thickness(rightLineMargin, bottomLineMargin, 0, 0), - TouchButtonCorner.Left => new Thickness(ButtonSpace, verticalScaleMargin, 0, 0), - TouchButtonCorner.Top => new Thickness(horizontalScaleMargin, ButtonSpace, 0, 0), - TouchButtonCorner.Right => new Thickness(rightLineMargin, verticalScaleMargin, 0, 0), - TouchButtonCorner.Bottom => new Thickness(horizontalScaleMargin, bottomLineMargin, 0, 0), - _ => throw new InvalidOperationException(), - }; - } - - private static FlyoutPlacementMode GetFlyoutPlacement(AssistiveTouchPosition touchPosition) => - touchPosition.Corner is - TouchButtonCorner.Right or TouchButtonCorner.UpperRight or TouchButtonCorner.LowerRight - ? FlyoutPlacementMode.LeftEdgeAlignedTop - : ((touchPosition.Corner == TouchButtonCorner.Top && touchPosition.Scale > 0.5) || - (touchPosition.Corner == TouchButtonCorner.Bottom && touchPosition.Scale > 0.5)) - ? FlyoutPlacementMode.LeftEdgeAlignedTop - : FlyoutPlacementMode.RightEdgeAlignedTop; - - private Point _newPos; // The position of the button after the left mouse button is released - private Point _oldPos; // The position of the button - - // NOTE: The OnButtonClick() in FlyoutService is happend between this delegate and lambda expression - private void DisableFlyoutPopup(object _, RoutedEventArgs e) - { - if (!_newPos.Equals(_oldPos) && e is not null) - { - e.Handled = true; - } - } - - private async void VolumeDownOnClick(object sender, RoutedEventArgs e) => - await WindowsInput.Simulate.Events() - .Click(KeyCode.VolumeDown) - .Invoke().ConfigureAwait(false); - - private async void VolumeUpOnClick(object sender, RoutedEventArgs e) => - await WindowsInput.Simulate.Events() - .Click(KeyCode.VolumeUp) - .Invoke().ConfigureAwait(false); - - private async void FullScreenSwitcherOnClick(object sender, RoutedEventArgs e) - { - // アインシュタイン not work - ViewModel!.SwitchFullScreen.Execute(Unit.Default).Subscribe(); - await WindowsInput.Simulate.Events() - .ClickChord(KeyCode.Alt, KeyCode.Enter) - .Invoke().ConfigureAwait(false); - } - - private async void ActionCenterOnClick(object sender, RoutedEventArgs e) => - await WindowsInput.Simulate.Events() - .ClickChord(KeyCode.LWin, KeyCode.A) - .Invoke().ConfigureAwait(false); - - private async void TaskViewOnClick(object sender, RoutedEventArgs e) => - await WindowsInput.Simulate.Events() - .ClickChord(KeyCode.LWin, KeyCode.Tab) - .Invoke().ConfigureAwait(false); - - private async void ScreenShotOnClick(object sender, RoutedEventArgs e) - { - AssistiveTouchFlyout.Hide(); - Visibility = Visibility.Collapsed; - - await WindowsInput.Simulate.Events() - .ClickChord(KeyCode.LWin, KeyCode.Shift, KeyCode.S) - .Invoke().ConfigureAwait(false); - - await Task.Delay(ConstantValue.ScreenShotHideButtonTime).ConfigureAwait(true); - - Visibility = Visibility.Visible; - } - - private void HookSettingOnClick(object sender, RoutedEventArgs e) - { - AssistiveTouchFlyout.Hide(); - DI.ShowView(); - } - - private void PreferenceOnClick(object sender, RoutedEventArgs e) => - DI.ShowView(); -} diff --git a/ErogeHelper/View/Controllers/TouchToolBox.xaml b/ErogeHelper/View/Controllers/TouchToolBox.xaml deleted file mode 100644 index 5be9316..0000000 --- a/ErogeHelper/View/Controllers/TouchToolBox.xaml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ErogeHelper/View/Windows/TextWindow.xaml.cs b/ErogeHelper/View/Windows/TextWindow.xaml.cs deleted file mode 100644 index 08c6ba9..0000000 --- a/ErogeHelper/View/Windows/TextWindow.xaml.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System.Reactive; -using System.Reactive.Disposables; -using System.Reactive.Linq; -using System.Windows; -using System.Windows.Input; -using ErogeHelper.Platform; -using ErogeHelper.Shared; -using ErogeHelper.ViewModel; -using ErogeHelper.ViewModel.Windows; -using ReactiveMarbles.ObservableEvents; -using ReactiveUI; -using Splat; - -namespace ErogeHelper.View.Windows; - -public partial class TextWindow : IEnableLogger -{ - public TextWindow(TextViewModel? textViewModel = null) - { - InitializeComponent(); - - var handle = WpfHelper.GetWpfWindowHandle(this); - HwndTools.HideWindowInAltTab(handle); - - ViewModel = textViewModel ?? DependencyResolver.GetService(); - ViewModel.SetWindowHandle(handle); - Width = ViewModel.WindowWidth; - - var disposables = new CompositeDisposable(); - this.WhenAnyObservable(x => x.ViewModel!.Show) - .Subscribe(_ => Show()) - .DisposeWith(disposables); - - this.WhenAnyObservable(x => x.ViewModel!.Hide) - .Subscribe(_ => Hide()) - .DisposeWith(disposables); - - this.Events().Loaded - .Select(_ => Unit.Default) - .InvokeCommand(this, x => x.ViewModel!.Loaded) - .DisposeWith(disposables); - - MouseEnter += (_, _) => DragBar.Visibility = Visibility.Visible; - MouseLeave += (_, _) => DragBar.Visibility = Visibility.Hidden; - ControlCenterFlyout.Opened += (_, _) => DragBar.Visibility = Visibility.Visible; - ControlCenterFlyout.Events().Closed - .Where(_ => !IsMouseOver) - .Subscribe(_ => DragBar.Visibility = Visibility.Hidden) - .DisposeWith(disposables); - BlurSwitch.Toggled += (_, args) => - { - if (BlurSwitch.IsOn) - { - OpacitySlider.Minimum = 0.02; - if (OpacitySlider.Value < OpacitySlider.Minimum) - { - ViewModel.WindowOpacityChanged.Execute(OpacitySlider.Minimum).Subscribe(); - } - } - else - { - OpacitySlider.Minimum = 0; - if (OpacitySlider.Value == 0.02) - { - ViewModel.WindowOpacityChanged.Execute(OpacitySlider.Minimum).Subscribe(); - } - } - }; - - - this.WhenActivated(d => - { - ViewModel.DisposeWith(d); - disposables.DisposeWith(d); - - this.OneWayBind(ViewModel, - vm => vm.WindowWidth, - v => v.Width).DisposeWith(d); - this.Bind(ViewModel, - vm => vm.Left, - v => v.Left).DisposeWith(d); - this.Bind(ViewModel, - vm => vm.Top, - v => v.Top).DisposeWith(d); - - - this.OneWayBind(ViewModel, - vm => vm.WindowWidth, - v => v.WidthSlider.Value).DisposeWith(d); - WidthSlider.Events().ValueChanged - .Select(arg => arg.NewValue) - .InvokeCommand(this, x => x.ViewModel!.WindowWidthChanged).DisposeWith(d); - this.OneWayBind(ViewModel, - vm => vm.WindowOpacity, - v => v.OpacitySlider.Value).DisposeWith(d); - this.OneWayBind(ViewModel, - vm => vm.WindowOpacity, - v => v.BackgroundOpacity.Opacity).DisposeWith(d); - OpacitySlider.Events().ValueChanged - .Select(arg => arg.NewValue) - .InvokeCommand(this, x => x.ViewModel!.WindowOpacityChanged).DisposeWith(d); - - this.BindCommand(ViewModel, - vm => vm.Pronounce, - v => v.PronounceButton).DisposeWith(d); - - this.Bind(ViewModel, - vm => vm.EnableBlurBackground, - v => v.BlurSwitch.IsOn).DisposeWith(d); - - this.OneWayBind(ViewModel, - vm => vm.TextControlViewModel, - v => v.TextItemsControl.ItemsSource).DisposeWith(d); - }); - } - - private void DragBarOnLeftButtonDown(object sender, RoutedEventArgs args) => DragMove(); - - private void DragBarOnPreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e) - => ControlCenterFlyout.ShowAt(sender as FrameworkElement); -} diff --git a/ErogeHelper/XamlTool/Behaviors/ScrollToEndBehavior.cs b/ErogeHelper/XamlTool/Behaviors/ScrollToEndBehavior.cs deleted file mode 100644 index 69362ab..0000000 --- a/ErogeHelper/XamlTool/Behaviors/ScrollToEndBehavior.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Windows; -using System.Windows.Controls; - -namespace ErogeHelper.XamlTool.Behaviors; - -public class ScrollToEndBehavior -{ - public static readonly DependencyProperty OnTextChangedProperty = - DependencyProperty.RegisterAttached( - "OnTextChanged", - typeof(bool), - typeof(ScrollToEndBehavior), - new UIPropertyMetadata(false, OnTextChanged) - ); - - public static bool GetOnTextChanged(DependencyObject dependencyObject) - { - return (bool)dependencyObject.GetValue(OnTextChangedProperty); - } - - public static void SetOnTextChanged(DependencyObject dependencyObject, bool value) - { - dependencyObject.SetValue(OnTextChangedProperty, value); - } - - private static void OnTextChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) - { - var newValue = (bool)e.NewValue; - - if (dependencyObject is not TextBox textBox || (bool)e.OldValue == newValue) - return; - - static void Handler(object sender, TextChangedEventArgs _) => ((TextBox)sender).ScrollToEnd(); - - if (newValue) - textBox.TextChanged += Handler; - else - { - textBox.TextChanged -= Handler; - } - } -} diff --git a/ErogeHelper/XamlTool/Behaviors/ValidationBehavior.cs b/ErogeHelper/XamlTool/Behaviors/ValidationBehavior.cs deleted file mode 100644 index dcc8821..0000000 --- a/ErogeHelper/XamlTool/Behaviors/ValidationBehavior.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System.ComponentModel; -using System.Windows; -using System.Windows.Data; - -namespace ErogeHelper.XamlTool.Behaviors; - -public class ValidationBehavior -{ - #region Attached Properties - - public static readonly DependencyProperty HasErrorProperty = DependencyProperty.RegisterAttached( - "HasError", - typeof(bool), - typeof(ValidationBehavior), - new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, null, - CoerceHasError)); - - private static readonly DependencyProperty HasErrorDescriptorProperty = DependencyProperty.RegisterAttached( - "HasErrorDescriptor", - typeof(DependencyPropertyDescriptor), - typeof(ValidationBehavior)); - - #endregion - - // - // MEMORY LEAK! - private static DependencyPropertyDescriptor? GetHasErrorDescriptor(DependencyObject d) - { - return d.GetValue(HasErrorDescriptorProperty) as DependencyPropertyDescriptor; - } - - private static void SetHasErrorDescriptor(DependencyObject d, DependencyPropertyDescriptor? value) - { - d.SetValue(HasErrorDescriptorProperty, value); - } - - #region Attached Property Getters and setters - - public static bool GetHasError(DependencyObject d) - { - return (bool)d.GetValue(HasErrorProperty); - } - - public static void SetHasError(DependencyObject d, bool value) - { - d.SetValue(HasErrorProperty, value); - } - - #endregion - - #region CallBacks - - private static object CoerceHasError(DependencyObject d, object baseValue) - { - var result = (bool)baseValue; - if (BindingOperations.IsDataBound(d, HasErrorProperty)) - { - if (GetHasErrorDescriptor(d) is null) - { - var desc = DependencyPropertyDescriptor.FromProperty(System.Windows.Controls.Validation.HasErrorProperty, d.GetType()); - desc.AddValueChanged(d, OnHasErrorChanged); - SetHasErrorDescriptor(d, desc); - result = System.Windows.Controls.Validation.GetHasError(d); - } - } - else - { - var desc = GetHasErrorDescriptor(d); - if (desc is not null) - { - desc.RemoveValueChanged(d, OnHasErrorChanged); - SetHasErrorDescriptor(d, null); - } - } - return result; - } - private static void OnHasErrorChanged(object? sender, EventArgs e) - { - if (sender is DependencyObject d) - d.SetValue(HasErrorProperty, d.GetValue(System.Windows.Controls.Validation.HasErrorProperty)); - } - - #endregion -} diff --git a/ErogeHelper/XamlTool/Converters/ColorConverter.cs b/ErogeHelper/XamlTool/Converters/ColorConverter.cs deleted file mode 100644 index 1877113..0000000 --- a/ErogeHelper/XamlTool/Converters/ColorConverter.cs +++ /dev/null @@ -1,10 +0,0 @@ -using ReactiveUI; - -namespace ErogeHelper.XamlTool.Converters; - -// https://github.com/reactiveui/ReactiveUI/blob/b31fabf3e99b5e61370dd007a243166d7c1fed8e/src/ReactiveUI.Uwp/Common/BooleanToVisibilityTypeConverter.cs -internal class ColorConverter : IBindingTypeConverter -{ - public int GetAffinityForObjects(Type fromType, Type toType) => throw new NotImplementedException(); - public bool TryConvert(object? from, Type toType, object? conversionHint, out object? result) => throw new NotImplementedException(); -} diff --git a/ErogeHelper/XamlTool/Converters/FontSizeHalfConverter.cs b/ErogeHelper/XamlTool/Converters/FontSizeHalfConverter.cs deleted file mode 100644 index cbd5712..0000000 --- a/ErogeHelper/XamlTool/Converters/FontSizeHalfConverter.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Globalization; -using System.Windows.Data; -using System.Windows.Markup; - -namespace ErogeHelper.XamlTool.Converters; - -public class FontSizeHalfConverter : MarkupExtension, IValueConverter -{ - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - return (double)value / 2 + 5; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new InvalidOperationException(); - } - - private static FontSizeHalfConverter? _converter; - - public override object ProvideValue(IServiceProvider serviceProvider) - { - return _converter ??= new FontSizeHalfConverter(); - } -} diff --git a/ErogeHelper/XamlTool/Converters/IsLessThanConverter.cs b/ErogeHelper/XamlTool/Converters/IsLessThanConverter.cs deleted file mode 100644 index e814ba0..0000000 --- a/ErogeHelper/XamlTool/Converters/IsLessThanConverter.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Globalization; -using System.Windows.Data; - -namespace ErogeHelper.XamlTool.Converters; - -public class IsLessThanConverter : IValueConverter -{ - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value is null || parameter is null) - return false; - - if (!int.TryParse(parameter.ToString(), out var threshold)) - throw new InvalidOperationException("The parameter could not be converted to an integer"); - - if (value is double d) - return d < threshold; - else if (value is float f) - { - return f < threshold; - } - else if (value is ulong ul) - { - return ul < (ulong)threshold; - } - else if (value is long l) - { - return l < threshold; - } - else if (value is uint ui) - { - return ui < threshold; - } - else if (value is int i) - { - return i < threshold; - } - else if (value is ushort us) - { - return us < threshold; - } - else if (value is short s) - { - return s < threshold; - } - else - { - return false; - } - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } -} diff --git a/ErogeHelper/XamlTool/Converters/TextEvaluateConverter.cs b/ErogeHelper/XamlTool/Converters/TextEvaluateConverter.cs deleted file mode 100644 index fb7a3c9..0000000 --- a/ErogeHelper/XamlTool/Converters/TextEvaluateConverter.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Globalization; -using System.Security; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Media; - -namespace ErogeHelper.XamlTool.Converters; - -public class TextEvaluateConverter : IValueConverter -{ - public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value is string input) - { - var textBlock = new TextBlock - { - TextWrapping = TextWrapping.Wrap - }; - - var escapedXml = SecurityElement.Escape(input); - - while (escapedXml?.IndexOf("|~S~|") != -1) - { - //up to |~S~| is normal - textBlock.Inlines.Add(new Run(escapedXml?[..escapedXml.IndexOf("|~S~|", StringComparison.Ordinal)])); - - //between |~S~| and |~E~| is highlighted - textBlock.Inlines.Add(new Run(escapedXml?[ - (escapedXml.IndexOf("|~S~|", StringComparison.Ordinal) + 5)..escapedXml.IndexOf("|~E~|", StringComparison.Ordinal)]) - { - TextDecorations = TextDecorations.Strikethrough, - Background = Brushes.Red - }); - - //the rest of the string (after the |~E~|) - escapedXml = escapedXml?[(escapedXml.IndexOf("|~E~|", StringComparison.Ordinal) + 5)..]; - } - - if (escapedXml.Length > 0) - textBlock.Inlines.Add(new Run(escapedXml)); - return textBlock; - } - - return null; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new InvalidOperationException("This converter cannot be used in two-way binding."); - } -} diff --git a/ErogeHelper/XamlTool/StaticXamlBitmapImage.cs b/ErogeHelper/XamlTool/StaticXamlBitmapImage.cs deleted file mode 100644 index 003fd45..0000000 --- a/ErogeHelper/XamlTool/StaticXamlBitmapImage.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Drawing; -using System.Reflection; -using System.Windows.Media.Imaging; - -namespace ErogeHelper.XamlTool; - -public static class StaticXamlBitmapImage -{ - public static readonly BitmapImage TransparentImage = - LoadBitmapFromResource("assets/text_background/transparent.png"); - public static readonly BitmapImage AquaGreenImage = - LoadBitmapFromResource("assets/text_background/aqua_green.png"); - public static readonly BitmapImage GreenImage = - LoadBitmapFromResource("assets/text_background/green.png"); - public static readonly BitmapImage PinkImage = - LoadBitmapFromResource("assets/text_background/pink.png"); - - /// - /// Load a resource WPF-BitmapImage (png, bmp, ...) from embedded resource defined as 'Resource' not as - /// 'Embedded resource'. - /// - /// Path without starting slash - /// Usually 'Assembly.GetExecutingAssembly()'. If not mentioned, I will use the calling - /// assembly - /// - public static BitmapImage LoadBitmapFromResource(string pathInApplication, Assembly? assembly = null) - { - assembly ??= Assembly.GetCallingAssembly(); - if (pathInApplication[0] == '/') - pathInApplication = pathInApplication[1..]; - - try - { - var uri = new Uri( - @"pack://application:,,,/" + assembly.GetName().Name + ";component/" + pathInApplication, - UriKind.Absolute); - return new BitmapImage(uri); - } - catch (UriFormatException) - { - // Running in unit test - return new BitmapImage(); - } - } - - private static readonly int LightGreen = Color.LightGreen.ToArgb(); - private static readonly int Green = Color.Green.ToArgb(); - private static readonly int Pink = Color.Pink.ToArgb(); - private static readonly int Transparent = Color.Transparent.ToArgb(); - - public static BitmapImage ToBitmapImage(this Color color) - { - var argbValuve = color.ToArgb(); - return argbValuve == LightGreen ? AquaGreenImage : - argbValuve == Green ? GreenImage : - argbValuve == Pink ? PinkImage : - TransparentImage; - } -} diff --git a/ErogeHelper/XamlTool/Validations/RegExpValidationRule.cs b/ErogeHelper/XamlTool/Validations/RegExpValidationRule.cs deleted file mode 100644 index e1a8003..0000000 --- a/ErogeHelper/XamlTool/Validations/RegExpValidationRule.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Globalization; -using System.Text.RegularExpressions; -using System.Windows.Controls; -using Splat; - -namespace ErogeHelper.XamlTool.Validations; - -public class RegExpValidationRule : ValidationRule, IEnableLogger -{ - public override ValidationResult Validate(object value, CultureInfo cultureInfo) - { - var pattern = value as string; - if (string.IsNullOrWhiteSpace(pattern)) - return ValidationResult.ValidResult; - if (pattern[^1] == '|') - return new ValidationResult(false, $"Invalid RegExp. '|'"); - - const RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Compiled; - - try - { - var optionRegex = new Regex(pattern, options); - } - catch (ArgumentException ex) - { - this.Log().Debug("Checking RegExp format, it's fine exception"); - return new ValidationResult(false, $"Invalid RegExp. {ex.Message}"); - } - - return ValidationResult.ValidResult; - } -} diff --git a/ErogeHelper/assets/app.ico b/ErogeHelper/assets/app.ico deleted file mode 100644 index c23210a..0000000 Binary files a/ErogeHelper/assets/app.ico and /dev/null differ diff --git a/ErogeHelper/assets/app.manifest b/ErogeHelper/assets/app.manifest deleted file mode 100644 index c7632e7..0000000 --- a/ErogeHelper/assets/app.manifest +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - PerMonitorV2 - true - - - - diff --git a/ErogeHelper/assets/app.png b/ErogeHelper/assets/app.png deleted file mode 100644 index 8c197af..0000000 Binary files a/ErogeHelper/assets/app.png and /dev/null differ diff --git a/ErogeHelper/assets/image/yunyi-logo2.png b/ErogeHelper/assets/image/yunyi-logo2.png deleted file mode 100644 index 31aed60..0000000 Binary files a/ErogeHelper/assets/image/yunyi-logo2.png and /dev/null differ diff --git a/ErogeHelper/assets/klee.png b/ErogeHelper/assets/klee.png new file mode 100644 index 0000000..6b16cb0 Binary files /dev/null and b/ErogeHelper/assets/klee.png differ diff --git a/ErogeHelper/assets/site_icon/baidu.com.ico b/ErogeHelper/assets/site_icon/baidu.com.ico deleted file mode 100644 index fe319d3..0000000 Binary files a/ErogeHelper/assets/site_icon/baidu.com.ico and /dev/null differ diff --git a/ErogeHelper/assets/site_icon/caiyunapp.com.ico b/ErogeHelper/assets/site_icon/caiyunapp.com.ico deleted file mode 100644 index 4196f49..0000000 Binary files a/ErogeHelper/assets/site_icon/caiyunapp.com.ico and /dev/null differ diff --git a/ErogeHelper/assets/site_icon/google.cn.ico b/ErogeHelper/assets/site_icon/google.cn.ico deleted file mode 100644 index 82339b3..0000000 Binary files a/ErogeHelper/assets/site_icon/google.cn.ico and /dev/null differ diff --git a/ErogeHelper/assets/site_icon/jisho.org.png b/ErogeHelper/assets/site_icon/jisho.org.png deleted file mode 100644 index 27d716f..0000000 Binary files a/ErogeHelper/assets/site_icon/jisho.org.png and /dev/null differ diff --git a/ErogeHelper/assets/site_icon/mojidict.com.ico b/ErogeHelper/assets/site_icon/mojidict.com.ico deleted file mode 100644 index f798b8c..0000000 Binary files a/ErogeHelper/assets/site_icon/mojidict.com.ico and /dev/null differ diff --git a/ErogeHelper/assets/site_icon/niutrans.com.ico b/ErogeHelper/assets/site_icon/niutrans.com.ico deleted file mode 100644 index 0ae138e..0000000 Binary files a/ErogeHelper/assets/site_icon/niutrans.com.ico and /dev/null differ diff --git a/ErogeHelper/assets/site_icon/tencent.com.ico b/ErogeHelper/assets/site_icon/tencent.com.ico deleted file mode 100644 index 1e94a78..0000000 Binary files a/ErogeHelper/assets/site_icon/tencent.com.ico and /dev/null differ diff --git a/ErogeHelper/assets/site_icon/translate.google.cn.ico b/ErogeHelper/assets/site_icon/translate.google.cn.ico deleted file mode 100644 index 04790c2..0000000 Binary files a/ErogeHelper/assets/site_icon/translate.google.cn.ico and /dev/null differ diff --git a/ErogeHelper/assets/site_icon/yeekit.com.ico b/ErogeHelper/assets/site_icon/yeekit.com.ico deleted file mode 100644 index 7beb503..0000000 Binary files a/ErogeHelper/assets/site_icon/yeekit.com.ico and /dev/null differ diff --git a/ErogeHelper/assets/site_icon/youdao.com.ico b/ErogeHelper/assets/site_icon/youdao.com.ico deleted file mode 100644 index 9c9dd7e..0000000 Binary files a/ErogeHelper/assets/site_icon/youdao.com.ico and /dev/null differ diff --git a/ErogeHelper/assets/text_background/aqua_green.png b/ErogeHelper/assets/text_background/aqua_green.png deleted file mode 100644 index 6e38e87..0000000 Binary files a/ErogeHelper/assets/text_background/aqua_green.png and /dev/null differ diff --git a/ErogeHelper/assets/text_background/green.png b/ErogeHelper/assets/text_background/green.png deleted file mode 100644 index 8f13e29..0000000 Binary files a/ErogeHelper/assets/text_background/green.png and /dev/null differ diff --git a/ErogeHelper/assets/text_background/pink.png b/ErogeHelper/assets/text_background/pink.png deleted file mode 100644 index a84f265..0000000 Binary files a/ErogeHelper/assets/text_background/pink.png and /dev/null differ diff --git a/ErogeHelper/assets/text_background/transparent.png b/ErogeHelper/assets/text_background/transparent.png deleted file mode 100644 index de5274d..0000000 Binary files a/ErogeHelper/assets/text_background/transparent.png and /dev/null differ diff --git a/ErogeHelper/libs/texthost.dll b/ErogeHelper/libs/texthost.dll deleted file mode 100644 index 42ddba1..0000000 Binary files a/ErogeHelper/libs/texthost.dll and /dev/null differ diff --git a/ErogeHelper/libs/texthost_x86.dll b/ErogeHelper/libs/texthost_x86.dll deleted file mode 100644 index 3fbe528..0000000 Binary files a/ErogeHelper/libs/texthost_x86.dll and /dev/null differ diff --git a/ErogeHelper/libs/x64/cli/TextractorCLI.exe b/ErogeHelper/libs/x64/cli/TextractorCLI.exe deleted file mode 100644 index f219453..0000000 Binary files a/ErogeHelper/libs/x64/cli/TextractorCLI.exe and /dev/null differ diff --git a/ErogeHelper/libs/x64/cli/texthook.dll b/ErogeHelper/libs/x64/cli/texthook.dll deleted file mode 100644 index 8439991..0000000 Binary files a/ErogeHelper/libs/x64/cli/texthook.dll and /dev/null differ diff --git a/ErogeHelper/libs/x64/texthook.dll b/ErogeHelper/libs/x64/texthook.dll deleted file mode 100644 index 6ecca92..0000000 Binary files a/ErogeHelper/libs/x64/texthook.dll and /dev/null differ diff --git a/ErogeHelper/libs/x86/LECommonLibrary.dll b/ErogeHelper/libs/x86/LECommonLibrary.dll deleted file mode 100644 index 541b9b5..0000000 Binary files a/ErogeHelper/libs/x86/LECommonLibrary.dll and /dev/null differ diff --git a/ErogeHelper/libs/x86/LEConfig.xml b/ErogeHelper/libs/x86/LEConfig.xml deleted file mode 100644 index 84063c1..0000000 --- a/ErogeHelper/libs/x86/LEConfig.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - ja-JP - Tokyo Standard Time - false - true - false - false - - - - ja-JP - Tokyo Standard Time - true - true - false - false - - - \ No newline at end of file diff --git a/ErogeHelper/libs/x86/LEProc.exe b/ErogeHelper/libs/x86/LEProc.exe deleted file mode 100644 index 2ad6b5a..0000000 Binary files a/ErogeHelper/libs/x86/LEProc.exe and /dev/null differ diff --git a/ErogeHelper/libs/x86/LoaderDll.dll b/ErogeHelper/libs/x86/LoaderDll.dll deleted file mode 100644 index 7a440d9..0000000 Binary files a/ErogeHelper/libs/x86/LoaderDll.dll and /dev/null differ diff --git a/ErogeHelper/libs/x86/LocaleEmulator.dll b/ErogeHelper/libs/x86/LocaleEmulator.dll deleted file mode 100644 index b3d668a..0000000 Binary files a/ErogeHelper/libs/x86/LocaleEmulator.dll and /dev/null differ diff --git a/ErogeHelper/libs/x86/cli/TextractorCLI.exe b/ErogeHelper/libs/x86/cli/TextractorCLI.exe deleted file mode 100644 index ba75799..0000000 Binary files a/ErogeHelper/libs/x86/cli/TextractorCLI.exe and /dev/null differ diff --git a/ErogeHelper/libs/x86/cli/texthook.dll b/ErogeHelper/libs/x86/cli/texthook.dll deleted file mode 100644 index 48c0698..0000000 Binary files a/ErogeHelper/libs/x86/cli/texthook.dll and /dev/null differ diff --git a/ErogeHelper/libs/x86/texthook.dll b/ErogeHelper/libs/x86/texthook.dll deleted file mode 100644 index 09cbdb2..0000000 Binary files a/ErogeHelper/libs/x86/texthook.dll and /dev/null differ diff --git a/LICENSE b/LICENSE deleted file mode 100644 index f288702..0000000 --- a/LICENSE +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - 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. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/README.md b/README.md deleted file mode 100644 index 790ea4c..0000000 --- a/README.md +++ /dev/null @@ -1,11 +0,0 @@ -[简体中文](https://github.com/ErogeHelper/ErogeHelper/blob/main/README_zh-cn.md) - -# TEMPORAEY READ ONLY - -### Download - -See [release page](https://github.com/ErogeHelper/ErogeHelper/releases) - -### Install - -For users please run ErogeHelper.Installer.exe to register ErogeHelper in windows context menu (aka right click menu). diff --git a/README_zh-cn.md b/README_zh-cn.md deleted file mode 100644 index 05a50a1..0000000 --- a/README_zh-cn.md +++ /dev/null @@ -1,55 +0,0 @@ -

- EH -
- Eroge Helper -

-

- it's eroge helper! -
-
-

- -EH 是一个现代的多功能黄油帮助器!可以帮忙日语学习者轻松阅读不认识的汉字读音,以及查询游戏中的单词!现仅支持在线的Moji辞书。 - -Eroge Helper 面向用户友好进行开发。 - -### 下载 - -见 [Release](https://github.com/ErogeHelper/ErogeHelper/releases) 页面,选择最新的latest版本下载。 - -### 安装(用户) - -对于用户来说建议使用ErogeHelper.Installer.exe 将EH注册到游戏程序的上下文菜单(也叫右键菜单),这是EH设计的初衷——像LE一样便于使用。你也可以直接运行没有图标的ErogeHelper.exe 来载入正在运行的游戏。 - ---- - -##### 目前的功能 - -- 借助Mecab阅读不认识的日文汉字(并不能保证分词与标注的汉字读音准确性,请勿以EH为准) -- 使用Moji辞书或Jisho查单词 -- 下载DeepL windows客户端,EH可以把提取到的文本传递到DeepL上翻译!(可能需要在DeepL中按Tab键使焦点聚集在源文本框中) -- 一些机器翻译的聚合 - -##### 支持的操作系统 - -EH支持 windows 7 sp1 至最新版本的 windows 10 系统 - -初次运行EH很可能会遇上一个红框,提醒先安装 **.Net 5 运行时**,请跟随微软的提示,下载 .Net 5 Desktop Runtime x64 字眼的运行库。 - -- win 7 - - windows 7 sp1 安装.Net 5 运行时之后,如果双击运行程序没有反应,可能还需要 KB2533623 KB2999226 等安全更新补丁[提取密码:gben](https://wws.lanzous.com/ihMiulenk6j)。在成功运行软件后若图标显示不正常需要安装 Segoe UI 字体文件 [提取密码:1p43](https://wws.lanzous.com/isjBWlenkqj)。 - -> win 10 1909 (os version 18363.1049) 可能会遇上窗口渲染错误,启动EH后导致其他窗口变成高对比度,截图显示正常,重启计算机可以恢复。 - -欢迎到上方issue 反馈问题。 - -### 构建生成(开发者) - -见 [Wiki](https://github.com/ErogeHelper/ErogeHelper/wiki/Build-and-Publish) - -stable 版本的EH项目在分支 [Caliburn.Micro-Archive](https://github.com/ErogeHelper/ErogeHelper/tree/Caliburn.Micro-Archive) 中 - -当前仓库main分支即 Preview 版本去掉了核心功能,使用 ReactiveUI 完全重构。以及最新 Commit 在 dev 分支中。 - -**EH的开发离不开许多三方开源项目,希望将来能够有余力去支援EH依赖的项目** diff --git a/Settings.XamlStyler b/Settings.XamlStyler deleted file mode 100644 index 7200a98..0000000 --- a/Settings.XamlStyler +++ /dev/null @@ -1,46 +0,0 @@ -{ - "AttributesTolerance": 3, // Max attributes in one line without line break - "KeepFirstAttributeOnSameLine": false, // this will make attributes align to first one - "MaxAttributeCharactersPerLine": 80, - "MaxAttributesPerLine": 4, - "NewlineExemptionElements": "RadialGradientBrush, GradientStop, LinearGradientBrush, ScaleTransform, SkewTransform, RotateTransform, TranslateTransform, Trigger, Condition, Setter", - "SeparateByGroups": true, - "AttributeIndentation": 0, // default 0 same as 4 - "RemoveDesignTimeReferences": false, - "EnableAttributeReordering": true, - "AttributeOrderingRuleGroups": [ - "x:Class", - "x:TypeArguments", - "xmlns", - "xmlns:x", - "xmlns:d, xmlns:mc", - "xmlns:ui, xmlns:rxui", - "xmlns:*", - "mc:Ignorable, d:DataContext, d:IsDataSource, d:LayoutOverrides, d:IsStaticText", - "x:Key, Key, x:Name, Name, x:Uid, Uid, mc:Ignorable", - "Grid.Row, Grid.RowSpan, Grid.Column, Grid.ColumnSpan, Canvas.Left, Canvas.Top, Canvas.Right, Canvas.Bottom", - "Left, Top, Width, Height", - "MinWidth, MinHeight, MaxWidth, MaxHeight", - "Title", - "Margin, Padding, HorizontalAlignment, VerticalAlignment, HorizontalContentAlignment, VerticalContentAlignment, Panel.ZIndex", - "*:*, *", - "PageSource, PageIndex, Offset, Color, TargetName, Property, Value, StartPoint, EndPoint", - "Storyboard.*, From, To, Duration" - ], - "FirstLineAttributes": "x:Name", - "OrderAttributesByName": true, - "PutEndingBracketOnNewLine": false, - "RemoveEndingTagOfEmptyElement": true, - "SpaceBeforeClosingSlash": true, - "RootElementLineBreakRule": 0, - "ReorderVSM": 2, - "ReorderGridChildren": false, - "ReorderCanvasChildren": false, - "ReorderSetters": 0, - "FormatMarkupExtension": true, - "NoNewLineMarkupExtensions": "x:Bind, Binding", - "ThicknessSeparator": 2, - "ThicknessAttributes": "Margin, Padding, BorderThickness, ThumbnailClipMargin", - "FormatOnSave": true, - "CommentPadding": 2 -} diff --git a/app.manifest b/app.manifest new file mode 100644 index 0000000..39b4b87 --- /dev/null +++ b/app.manifest @@ -0,0 +1,32 @@ + + + + + + + + SegmentHeap + + + + + + true/pm + PerMonitorV2 + + + + + + + + + + \ No newline at end of file