mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-19 04:26:52 -04:00
Implement cursor hiding on Windows to partially address #36. (Will do Linux backend next)
This commit is contained in:
parent
875ec23b5b
commit
4769e7dbbd
@ -94,6 +94,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
if( !textInput.chatInputText.Empty ) {
|
if( !textInput.chatInputText.Empty ) {
|
||||||
|
game.CursorVisible = false;
|
||||||
game.chatInInputBuffer = textInput.chatInputText.ToString();
|
game.chatInInputBuffer = textInput.chatInputText.ToString();
|
||||||
}
|
}
|
||||||
chatFont.Dispose();
|
chatFont.Dispose();
|
||||||
@ -145,6 +146,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OpenTextInputBar( string initialText ) {
|
void OpenTextInputBar( string initialText ) {
|
||||||
|
game.CursorVisible = true;
|
||||||
suppressNextPress = true;
|
suppressNextPress = true;
|
||||||
HandlesAllInput = true;
|
HandlesAllInput = true;
|
||||||
textInput.chatInputText.Clear();
|
textInput.chatInputText.Clear();
|
||||||
@ -158,6 +160,7 @@ namespace ClassicalSharp {
|
|||||||
if( HandlesAllInput ) { // text input bar
|
if( HandlesAllInput ) { // text input bar
|
||||||
if( key == game.Keys[KeyMapping.SendChat] ) {
|
if( key == game.Keys[KeyMapping.SendChat] ) {
|
||||||
HandlesAllInput = false;
|
HandlesAllInput = false;
|
||||||
|
game.CursorVisible = false;
|
||||||
game.Camera.RegrabMouse();
|
game.Camera.RegrabMouse();
|
||||||
textInput.SendTextInBufferAndReset();
|
textInput.SendTextInBufferAndReset();
|
||||||
} else if( key == Key.PageUp ) {
|
} else if( key == Key.PageUp ) {
|
||||||
|
@ -25,12 +25,14 @@ namespace ClassicalSharp {
|
|||||||
playerList.Dispose();
|
playerList.Dispose();
|
||||||
playerList = null;
|
playerList = null;
|
||||||
}
|
}
|
||||||
}
|
graphicsApi.Texturing = false;
|
||||||
|
} else {
|
||||||
graphicsApi.Texturing = false;
|
graphicsApi.Texturing = false;
|
||||||
DrawCrosshairs();
|
DrawCrosshairs();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const int crosshairExtent = 20, crosshairWeight = 2;
|
const int crosshairExtent = 15, crosshairWeight = 2;
|
||||||
void DrawCrosshairs() {
|
void DrawCrosshairs() {
|
||||||
int curCol = 150 + (int)( 50 * Math.Abs( Math.Sin( game.accumulator ) ) );
|
int curCol = 150 + (int)( 50 * Math.Abs( Math.Sin( game.accumulator ) ) );
|
||||||
FastColour col = new FastColour( curCol, curCol, curCol );
|
FastColour col = new FastColour( curCol, curCol, curCol );
|
||||||
@ -48,6 +50,7 @@ namespace ClassicalSharp {
|
|||||||
if( playerList != null ) {
|
if( playerList != null ) {
|
||||||
playerList.Dispose();
|
playerList.Dispose();
|
||||||
}
|
}
|
||||||
|
game.CursorVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
||||||
@ -68,6 +71,7 @@ namespace ClassicalSharp {
|
|||||||
chat.Init();
|
chat.Init();
|
||||||
hotbar = new BlockHotbarWidget( game );
|
hotbar = new BlockHotbarWidget( game );
|
||||||
hotbar.Init();
|
hotbar.Init();
|
||||||
|
game.CursorVisible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandlesAllInput {
|
public override bool HandlesAllInput {
|
||||||
|
@ -111,8 +111,12 @@ namespace OpenTK {
|
|||||||
/// <summary> Gets the available MouseDevice. </summary>
|
/// <summary> Gets the available MouseDevice. </summary>
|
||||||
MouseDevice Mouse { get; }
|
MouseDevice Mouse { get; }
|
||||||
|
|
||||||
|
/// <summary> Gets or sets the cursor position in screen coordinates. </summary>
|
||||||
Point DesktopCursorPos { get; set; }
|
Point DesktopCursorPos { get; set; }
|
||||||
|
|
||||||
|
/// <summary> Sets whether the cursor is visible in the window. </summary>
|
||||||
|
bool CursorVisible { set; }
|
||||||
|
|
||||||
/// <summary> Occurs whenever the window is moved. </summary>
|
/// <summary> Occurs whenever the window is moved. </summary>
|
||||||
event EventHandler<EventArgs> Move;
|
event EventHandler<EventArgs> Move;
|
||||||
|
|
||||||
|
@ -237,7 +237,12 @@ namespace OpenTK {
|
|||||||
get { return implementation.Mouse; }
|
get { return implementation.Mouse; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Gets the primary Mouse device, or null if no Mouse exists. </summary>
|
/// <summary> Sets whether the cursor is visible in the window. </summary>
|
||||||
|
public bool CursorVisible {
|
||||||
|
set { implementation.CursorVisible = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets or sets the cursor position in screen coordinates. </summary>
|
||||||
public Point DesktopCursorPos {
|
public Point DesktopCursorPos {
|
||||||
get { return implementation.DesktopCursorPos; }
|
get { return implementation.DesktopCursorPos; }
|
||||||
set { implementation.DesktopCursorPos = value; }
|
set { implementation.DesktopCursorPos = value; }
|
||||||
|
@ -1066,6 +1066,11 @@ namespace OpenTK.Platform.MacOS
|
|||||||
set { System.Windows.Forms.Cursor.Position = value; }
|
set { System.Windows.Forms.Cursor.Position = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Hide and show cursor
|
||||||
|
public bool CursorVisible {
|
||||||
|
set { }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,10 +154,13 @@ namespace OpenTK.Platform.Windows {
|
|||||||
public static extern bool TrackMouseEvent(ref TrackMouseEventStructure lpEventTrack);
|
public static extern bool TrackMouseEvent(ref TrackMouseEventStructure lpEventTrack);
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
|
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
|
||||||
internal static extern bool GetCursorPos(ref Point point);
|
internal static extern bool GetCursorPos(ref POINT point);
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
|
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
|
||||||
internal static extern bool SetCursorPos(int x, int y);
|
internal static extern bool SetCursorPos(int x, int y);
|
||||||
|
|
||||||
|
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
|
||||||
|
internal static extern bool ShowCursor( int value );
|
||||||
}
|
}
|
||||||
|
|
||||||
internal struct Constants {
|
internal struct Constants {
|
||||||
|
@ -803,15 +803,19 @@ namespace OpenTK.Platform.Windows
|
|||||||
|
|
||||||
public Point DesktopCursorPos {
|
public Point DesktopCursorPos {
|
||||||
get {
|
get {
|
||||||
Point pos = default( Point );
|
POINT pos = default( POINT );
|
||||||
API.GetCursorPos( ref pos );
|
API.GetCursorPos( ref pos );
|
||||||
return pos;
|
return new Point( pos.X, pos.Y );
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
API.SetCursorPos( value.X, value.Y );
|
API.SetCursorPos( value.X, value.Y );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool CursorVisible {
|
||||||
|
set { API.ShowCursor( value ? 1 : 0 ); }
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
|
@ -820,6 +820,11 @@ namespace OpenTK.Platform.X11 {
|
|||||||
set { System.Windows.Forms.Cursor.Position = value; }
|
set { System.Windows.Forms.Cursor.Position = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Hide and show cursor
|
||||||
|
public bool CursorVisible {
|
||||||
|
set { }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Returns true if a render window/context exists. </summary>
|
/// <summary> Returns true if a render window/context exists. </summary>
|
||||||
public bool Exists {
|
public bool Exists {
|
||||||
get { return exists; }
|
get { return exists; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user