Ejemplo n.º 1
0
 static void Thd()
 {
     while (enabled)
     {
         Thread.Sleep(ConsoleBase.TIME_WAIT);
         //Movement
         NativeClass.GetCursorPos(ref pos);
         delta = pos;
         NativeClass.SetCursorPos(cur_center.X, cur_center.Y);;
         if (delta.X != delta2.X || delta.Y != delta2.Y)
         {
             DrawBuff();
             delta2.X = delta.X - delta2.X;
             if (delta2.X > 0)
             {
                 x += 1;
             }
             else if (delta2.X < 0)
             {
                 x -= 1;
             }
             delta2.Y = delta.Y - delta2.Y;
             if (delta2.Y > 0)
             {
                 y += 1;
             }
             else if (delta2.Y < 0)
             {
                 y -= 1;
             }
             if (x < 0)
             {
                 x = 0;
             }
             else if (x > ConsoleBase.width - 1)
             {
                 x = ConsoleBase.width - 1;
             }
             if (y < 0)
             {
                 y = 0;
             }
             else if (y > ConsoleBase.height - 2)
             {
                 y = ConsoleBase.height - 2;
             }
             DrawCur();
             NativeClass.GetCursorPos(ref pos);
             delta = pos;
             ConsoleBase.ReDraw();
         }
         delta2 = delta;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Enables/Disables the mouse cursor
        /// </summary>
        /// <param name="input"></param>
        public static void SetCursorState(bool input)
        {
            if (enabled == input)
            {
                return;
            }

            enabled = input;
            if (buf == null)
            {
                buf = new ConsoleBuffer();
            }
            if (enabled)
            {
                thd = new Thread(Thd);
                thd.Start();
                //Trap mouse
                NativeClass.GetWindowRect(NativeClass.winhndl, ref clip);
                clip.Left   += 32;
                clip.Top    += 32;
                clip.Right  -= 32;
                clip.Bottom -= 32;
                NativeClass.ClipCursor(ref clip);
                cur_center.X = clip.Left + (clip.Right - clip.Left) / 2;
                cur_center.Y = clip.Top + (clip.Bottom - clip.Top) / 2;
                NativeClass.SetCursorPos(cur_center.X, cur_center.Y);
                NativeClass.GetCursorPos(ref pos);
                delta = delta2 = pos;
                DrawCur();
                ConsoleBase.ReDraw();
            }
            else
            {
                NativeClass.NullThread(ref thd);
                DrawBuff();
                ConsoleBase.ReDraw();
                clip.Left   = -1;
                clip.Top    = -1;
                clip.Right  = -1;
                clip.Bottom = -1;
                NativeClass.ClipCursor(ref clip);
            }
        }