Exemple #1
0
        /// <summary>
        /// Returns a quaternion for the rotation implied by the window's cursor position
        /// </summary>
        public static Quaternion GetRotationFromCursor(System.Windows.Forms.Control control, float fTrackBallRadius)
        {
            System.Drawing.Point pt = System.Windows.Forms.Cursor.Position;
            System.Drawing.Rectangle rc = control.ClientRectangle;
            pt = control.PointToClient(pt);
            float xpos = (((2.0f * pt.X) / (rc.Right-rc.Left)) - 1);
            float ypos = (((2.0f * pt.Y) / (rc.Bottom-rc.Top)) - 1);
            float sz;

            if (xpos == 0.0f && ypos == 0.0f)
                return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);

            float d2 = (float)Math.Sqrt(xpos*xpos + ypos*ypos);

            if (d2 < fTrackBallRadius * 0.70710678118654752440) // Inside sphere
                sz = (float)Math.Sqrt(fTrackBallRadius*fTrackBallRadius - d2*d2);
            else                                                 // On hyperbola
                sz = (fTrackBallRadius*fTrackBallRadius) / (2.0f*d2);

            // Get two points on trackball's sphere
            Vector3 p1 = new Vector3(xpos, ypos, sz);
            Vector3 p2 = new Vector3(0.0f, 0.0f, fTrackBallRadius);

            // Get axis of rotation, which is cross product of p1 and p2
            Vector3 axis = Vector3.Cross(p1,p2);

            // Calculate angle for the rotation about that axis
            float t = Vector3.Length(Vector3.Subtract(p2,p1)) / (2.0f*fTrackBallRadius);
            if (t > +1.0f) t = +1.0f;
            if (t < -1.0f) t = -1.0f;
            float fAngle = (float)(2.0f * Math.Asin(t));

            // Convert axis to quaternion
            return Quaternion.RotationAxis(axis, fAngle);
        }
Exemple #2
0
 /// <remarks>
 /// GetCharIndexFromPosition is missing one caret position, as there is one extra caret
 /// position than there are characters (an extra one at the end).
 /// </remarks>
 private int GetCaretIndexFromPoint(System.Windows.Forms.TextBox box, int x, int y)
 {
     Point realPoint = box.PointToClient(new Point(x, y));
     int index = box.GetCharIndexFromPosition(realPoint);
     if (index == box.Text.Length - 1)
     {
         Point caretPoint = box.GetPositionFromCharIndex(index);
         if (realPoint.X > caretPoint.X)
         {
             index += 1;
         }
     }
     return index;
 }
 private static System.Windows.Forms.Control GetNestedChildAtPoint(System.Windows.Forms.Control control, System.Drawing.Point screenPoint)
 {
     System.Windows.Forms.Control control1 = control.GetChildAtPoint(control.PointToClient(screenPoint), System.Windows.Forms.GetChildAtPointSkip.Invisible);
     if (control1 != null)
         return Skybound.VisualTips.VisualTipProvider.GetNestedChildAtPoint(control1, screenPoint);
     return control;
 }
Exemple #4
0
        public void Show(System.Windows.Forms.Control control, Rectangle area, bool center)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }
            SetOwnerItem(control);
            resizableTop = resizableLeft = false;
            Point location = control.PointToScreen(new Point(area.Left, area.Top + area.Height));
            Rectangle screen = Screen.FromControl(control).WorkingArea;
            if (center)
            {
                if (location.X + (area.Width + Size.Width) / 2 > screen.Right)
                {
                    resizableLeft = true;
                    location.X = screen.Right - Size.Width;
                }
                else
                {
                    resizableLeft = true;
                    location.X = location.X - (Size.Width - area.Width) / 2;
                }
            }
            else
            {
                if (location.X + Size.Width > (screen.Left + screen.Width))
                {
                    resizableLeft = true;
                    location.X = (screen.Left + screen.Width) - Size.Width;
                }
            }

            if (location.Y + Size.Height > (screen.Top + screen.Height))
            {
                resizableTop = true;
                location.Y -= Size.Height + area.Height;
            }
            location = control.PointToClient(location);
            Show(control, location, ToolStripDropDownDirection.BelowRight);
        }
        public static void ScreenToAbsolute(int screenX, int screenY, ref float x,
            ref float y, float z, Camera camera, System.Windows.Forms.Control form, bool fullscreen)
        {
            System.Drawing.Point point = new System.Drawing.Point(screenX, screenY);
            point = form.PointToClient(point);
            if (fullscreen)
            {
                // maximized, so scale the position
                point.X = (int)(screenX * form.ClientRectangle.Width /
                    (float)System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Width
                    );
                point.Y = (int)(screenY * form.ClientRectangle.Height /
                    (float)System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Height
                    );
            }

            x = camera.XEdge * (point.X * 2.0f - form.ClientRectangle.Width) / form.ClientRectangle.Width;
            y = -camera.YEdge * (point.Y * 2.0f - form.ClientRectangle.Height) / form.ClientRectangle.Height;
        }