mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -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() {
|
||||
if( !textInput.chatInputText.Empty ) {
|
||||
game.CursorVisible = false;
|
||||
game.chatInInputBuffer = textInput.chatInputText.ToString();
|
||||
}
|
||||
chatFont.Dispose();
|
||||
@ -145,6 +146,7 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
void OpenTextInputBar( string initialText ) {
|
||||
game.CursorVisible = true;
|
||||
suppressNextPress = true;
|
||||
HandlesAllInput = true;
|
||||
textInput.chatInputText.Clear();
|
||||
@ -158,6 +160,7 @@ namespace ClassicalSharp {
|
||||
if( HandlesAllInput ) { // text input bar
|
||||
if( key == game.Keys[KeyMapping.SendChat] ) {
|
||||
HandlesAllInput = false;
|
||||
game.CursorVisible = false;
|
||||
game.Camera.RegrabMouse();
|
||||
textInput.SendTextInBufferAndReset();
|
||||
} else if( key == Key.PageUp ) {
|
||||
|
@ -25,12 +25,14 @@ namespace ClassicalSharp {
|
||||
playerList.Dispose();
|
||||
playerList = null;
|
||||
}
|
||||
graphicsApi.Texturing = false;
|
||||
} else {
|
||||
graphicsApi.Texturing = false;
|
||||
DrawCrosshairs();
|
||||
}
|
||||
graphicsApi.Texturing = false;
|
||||
DrawCrosshairs();
|
||||
}
|
||||
|
||||
const int crosshairExtent = 20, crosshairWeight = 2;
|
||||
const int crosshairExtent = 15, crosshairWeight = 2;
|
||||
void DrawCrosshairs() {
|
||||
int curCol = 150 + (int)( 50 * Math.Abs( Math.Sin( game.accumulator ) ) );
|
||||
FastColour col = new FastColour( curCol, curCol, curCol );
|
||||
@ -48,6 +50,7 @@ namespace ClassicalSharp {
|
||||
if( playerList != null ) {
|
||||
playerList.Dispose();
|
||||
}
|
||||
game.CursorVisible = true;
|
||||
}
|
||||
|
||||
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
||||
@ -68,6 +71,7 @@ namespace ClassicalSharp {
|
||||
chat.Init();
|
||||
hotbar = new BlockHotbarWidget( game );
|
||||
hotbar.Init();
|
||||
game.CursorVisible = false;
|
||||
}
|
||||
|
||||
public override bool HandlesAllInput {
|
||||
|
@ -111,7 +111,11 @@ namespace OpenTK {
|
||||
/// <summary> Gets the available MouseDevice. </summary>
|
||||
MouseDevice Mouse { get; }
|
||||
|
||||
/// <summary> Gets or sets the cursor position in screen coordinates. </summary>
|
||||
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>
|
||||
event EventHandler<EventArgs> Move;
|
||||
|
@ -237,7 +237,12 @@ namespace OpenTK {
|
||||
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 {
|
||||
get { return implementation.DesktopCursorPos; }
|
||||
set { implementation.DesktopCursorPos = value; }
|
||||
|
@ -1066,6 +1066,11 @@ namespace OpenTK.Platform.MacOS
|
||||
set { System.Windows.Forms.Cursor.Position = value; }
|
||||
}
|
||||
|
||||
// TODO: Hide and show cursor
|
||||
public bool CursorVisible {
|
||||
set { }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -154,10 +154,13 @@ namespace OpenTK.Platform.Windows {
|
||||
public static extern bool TrackMouseEvent(ref TrackMouseEventStructure lpEventTrack);
|
||||
|
||||
[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]
|
||||
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 {
|
||||
|
@ -803,14 +803,18 @@ namespace OpenTK.Platform.Windows
|
||||
|
||||
public Point DesktopCursorPos {
|
||||
get {
|
||||
Point pos = default( Point );
|
||||
POINT pos = default( POINT );
|
||||
API.GetCursorPos( ref pos );
|
||||
return pos;
|
||||
return new Point( pos.X, pos.Y );
|
||||
}
|
||||
set {
|
||||
API.SetCursorPos( value.X, value.Y );
|
||||
}
|
||||
}
|
||||
|
||||
public bool CursorVisible {
|
||||
set { API.ShowCursor( value ? 1 : 0 ); }
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
|
@ -820,6 +820,11 @@ namespace OpenTK.Platform.X11 {
|
||||
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>
|
||||
public bool Exists {
|
||||
get { return exists; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user