-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DX XNA (WinForms base) Only OGL UGL (SDL base) are not support Signed-off-by: 舰队的偶像-岛风酱! <[email protected]>
- Loading branch information
Showing
6 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
|
||
using Microsoft.Xna.Framework; | ||
|
||
using Rampastring.XNAUI.Input; | ||
using Rampastring.XNAUI.XNAControls; | ||
|
||
namespace ClientCore.IME; | ||
|
||
public abstract class IMEHandler : IIMEHandler | ||
{ | ||
private string _composition = string.Empty; | ||
|
||
public abstract bool Enabled { get; protected set; } | ||
|
||
public XNAControl IMEFocus { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
|
||
public string Composition | ||
{ | ||
get => _composition; | ||
set | ||
{ | ||
string old = _composition; | ||
_composition = value; | ||
CompositionChanged?.Invoke(null, new(old, value)); | ||
} | ||
} | ||
|
||
public virtual int CompositionCursorPosition { get; set; } | ||
|
||
public event EventHandler<CharacterEventArgs> CharInput; | ||
public event EventHandler<CompositionChangedEventArgs> CompositionChanged; | ||
public static IMEHandler Create(Game game) | ||
{ | ||
#if !GL | ||
return new WinFormsIMEHandler(game); | ||
#else | ||
return new SdlIMEHandler(game); | ||
#endif | ||
} | ||
|
||
public virtual void SetTextInputRectangle(Rectangle rectangle) | ||
{ | ||
} | ||
|
||
public abstract void StartTextComposition(); | ||
|
||
public abstract void StopTextComposition(); | ||
|
||
protected virtual void OnTextInput(char character) | ||
=> CharInput?.Invoke(this, new(character)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Microsoft.Xna.Framework; | ||
|
||
namespace ClientCore.IME; | ||
|
||
/// <summary> | ||
/// Integrate IME to DesktopGL(SDL2) platform. | ||
/// </summary> | ||
/// <remarks> | ||
/// Note: We were unable to provide reliable input method support for | ||
/// SDL2 due to the lack of a way to be able to stabilize hooks for | ||
/// the SDL2 main loop.<br/> | ||
/// Perhaps this requires some changes in Monogame. | ||
/// </remarks> | ||
internal sealed class SdlIMEHandler(Game game) : IMEHandler | ||
Check warning on line 14 in ClientCore/IME/SdlIMEHandler.cs GitHub Actions / build-clients (Ares)
Check warning on line 14 in ClientCore/IME/SdlIMEHandler.cs GitHub Actions / build-clients (TS)
|
||
{ | ||
public override bool Enabled { get => false; protected set => _ = value; } | ||
|
||
public override void StartTextComposition() | ||
{ | ||
} | ||
|
||
public override void StopTextComposition() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using ImeSharp; | ||
|
||
using Microsoft.Xna.Framework; | ||
|
||
namespace ClientCore.IME; | ||
|
||
/// <summary> | ||
/// Integrate IME to XNA framework. | ||
/// </summary> | ||
internal class WinFormsIMEHandler : IMEHandler | ||
{ | ||
public override bool Enabled | ||
{ | ||
get => InputMethod.Enabled; | ||
protected set => InputMethod.Enabled = value; | ||
} | ||
|
||
public WinFormsIMEHandler(Game game) | ||
{ | ||
InputMethod.Initialize(game.Window.Handle); | ||
InputMethod.TextInputCallback = OnTextInput; | ||
InputMethod.TextCompositionCallback = (compositionText, cursorPosition) => | ||
{ | ||
Composition = compositionText.ToString(); | ||
CompositionCursorPosition = cursorPosition; | ||
}; | ||
} | ||
|
||
|
||
public override void StartTextComposition() | ||
=> Enabled = true; | ||
|
||
|
||
public override void StopTextComposition() | ||
=> Enabled = false; | ||
|
||
|
||
public override void SetTextInputRectangle(Rectangle rect) | ||
=> InputMethod.SetTextInputRect(rect.X, rect.Y, rect.Width, rect.Height); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters