Exemplo n.º 1
0
        // Holding the mouse button and dragging the mouse changes the "roll" angle (y-axis) and the direction from which sunlight is coming (x-axis).
        public override void MouseDown(NSEvent theEvent)
        {
            bool   dragging = true;
            PointF windowPoint;
            PointF lastWindowPoint = theEvent.LocationInWindow;

            float dx, dy;
            bool  wasAnimating = isAnimating;

            if (wasAnimating)
            {
                stopAnimation();
            }

            while (dragging)
            {
                theEvent    = openGLView.Window.NextEventMatchingMask(NSEventMask.LeftMouseUp | NSEventMask.LeftMouseDragged);
                windowPoint = theEvent.LocationInWindow;

                switch (theEvent.Type)
                {
                case NSEventType.LeftMouseUp:
                    dragging = false;
                    break;

                case NSEventType.LeftMouseDragged:
                    dx              = windowPoint.X - lastWindowPoint.X;
                    dy              = windowPoint.Y - lastWindowPoint.Y;
                    Scene.SunAngle  = Scene.SunAngle - 1 * dx;
                    Scene.RollAngle = Scene.RollAngle - 0.5f * dy;
                    lastWindowPoint = windowPoint;

                    if (isInFullScreenMode)
                    {
                        fullScreenView.Display();
                    }
                    else
                    {
                        openGLView.Display();
                    }
                    break;

                default:
                    break;
                }
            }

            if (wasAnimating)
            {
                startAnimation();
                RenderTime = DateTime.Now.TimeOfDay.TotalMilliseconds;
            }
        }