示例#1
0
        static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData)
        {
            EventInfo evt = new EventInfo(inEvent);
            switch (evt.EventClass)
            {
                case EventClass.Application:
                    switch (evt.AppEventKind)
                    {
                        default:
                            return OSStatus.EventNotHandled;
                    }

                case EventClass.AppleEvent:
                    // only event here is the apple event.
                    Debug.Print("Processing apple event.");
                    API.ProcessAppleEvent(inEvent);
                    break;
                case EventClass.Keyboard:
                case EventClass.Mouse:
                    if (WindowEventHandler != null)
                    {
                        return WindowEventHandler.DispatchEvent(inCaller, inEvent, evt, userData);
                    }
                    break;
            }

            return OSStatus.EventNotHandled;
        }
        private OSStatus ProcessWindowEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            switch ((WindowEventKind)evt.EventKind)
            {
                case WindowEventKind.WindowClose:
                    CancelEventArgs cancel = new CancelEventArgs();
                    OnClosing(cancel);

                    if (cancel.Cancel)
                        return OSStatus.NoError;
                    else
                        return OSStatus.EventNotHandled;

                case WindowEventKind.WindowClosed:
                    mExists = false;
                    OnClosed();

                    return OSStatus.NoError;

                case WindowEventKind.WindowBoundsChanged:
                    int thisWidth = Width;
                    int thisHeight = Height;

                    LoadSize();

                    if (thisWidth != Width || thisHeight != Height)
                        OnResize();

                    return OSStatus.EventNotHandled;

                case WindowEventKind.WindowActivate:
                    OnActivate();
                    return OSStatus.EventNotHandled;

                case WindowEventKind.WindowDeactivate:
                    OnDeactivate();
                    return OSStatus.EventNotHandled;

                default:
                    Debug.Print("{0}", evt);

                    return OSStatus.EventNotHandled;
            }
        }
        OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            MacOSMouseButton button;
            HIPoint pt = new HIPoint();
            HIPoint screenLoc =  new HIPoint();

            OSStatus err = API.GetEventMouseLocation(inEvent, out screenLoc);

            if (this.windowState == WindowState.Fullscreen)
            {
                pt = screenLoc;
            }
            else
            {
                err = API.GetEventWindowMouseLocation(inEvent, out pt);
            }

            if (err != OSStatus.NoError)
            {
                // this error comes up from the application event handler.
                if (err != OSStatus.EventParameterNotFound)
                {
                    throw new MacOSException(err);
                }
            }

            Point mousePosInClient = new Point((int)pt.X, (int)pt.Y);
            if (this.windowState != WindowState.Fullscreen)
            {
                mousePosInClient.Y -= mTitlebarHeight;
            }

            // check for enter/leave events
            IntPtr thisEventWindow;
            API.GetEventWindowRef(inEvent, out thisEventWindow);
            CheckEnterLeaveEvents(thisEventWindow, mousePosInClient);

            switch ((MouseEventKind)evt.EventKind)
            {
                case MouseEventKind.MouseDown:
                    button = API.GetEventMouseButton(inEvent);

                    switch (button)
                    {
                        case MacOSMouseButton.Primary:
                            mouse[MouseButton.Left] = true;
                            break;

                        case MacOSMouseButton.Secondary:
                            mouse[MouseButton.Right] = true;
                            break;

                        case MacOSMouseButton.Tertiary:
                            mouse[MouseButton.Middle] = true;
                            break;
                    }
                    return OSStatus.NoError;

                case MouseEventKind.MouseUp:
                    button = API.GetEventMouseButton(inEvent);

                    switch (button)
                    {
                        case MacOSMouseButton.Primary:
                            mouse[MouseButton.Left] = false;
                            break;

                        case MacOSMouseButton.Secondary:
                            mouse[MouseButton.Right] = false;
                            break;

                        case MacOSMouseButton.Tertiary:
                            mouse[MouseButton.Middle] = false;
                            break;
                    }
                    button = API.GetEventMouseButton(inEvent);
                    return OSStatus.NoError;

                case MouseEventKind.WheelMoved:

                    int delta = API.GetEventMouseWheelDelta(inEvent) / 3;
                    mouse.Wheel += delta;
                    return OSStatus.NoError;

                case MouseEventKind.MouseMoved:
                case MouseEventKind.MouseDragged:

                    //Debug.Print("Mouse Location: {0}, {1}", pt.X, pt.Y);

                    if (windowState == WindowState.Fullscreen) {
                        if (mousePosInClient.X != mouse.X || mousePosInClient.Y != mouse.Y) {
                            mouse.Position = mousePosInClient;
                        }
                    } else {
                        // ignore clicks in the title bar
                        if (pt.Y < 0)
                            return OSStatus.EventNotHandled;

                        if (mousePosInClient.X != mouse.X || mousePosInClient.Y != mouse.Y) {
                            mouse.Position = mousePosInClient;
                        }
                    }
                    return OSStatus.EventNotHandled;

                default:
                    Debug.Print("{0}", evt);
                    return OSStatus.EventNotHandled;
            }
        }
        private OSStatus ProcessKeyboardEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            MacOSKeyCode code = (MacOSKeyCode)0;
            char charCode = '\0';

            //Debug.Print("Processing keyboard event {0}", evt.KeyboardEventKind);

            switch ((KeyboardEventKind)evt.EventKind)
            {
                case KeyboardEventKind.RawKeyDown:
                case KeyboardEventKind.RawKeyRepeat:
                case KeyboardEventKind.RawKeyUp:
                    GetCharCodes(inEvent, out code, out charCode);
                    mKeyPressArgs.KeyChar = charCode;
                    break;
            }

            if( !Keymap.ContainsKey( code ) ) {
                Debug.Print( "{0} not mapped, ignoring press.", code );
                return OSStatus.NoError;
            }

            switch ((KeyboardEventKind)evt.EventKind)
            {
                case KeyboardEventKind.RawKeyRepeat:
                    keyboard.KeyRepeat = true;
                    goto case KeyboardEventKind.RawKeyDown;

                case KeyboardEventKind.RawKeyDown:
                    OnKeyPress(mKeyPressArgs);
                    keyboard[Keymap[code]] = true;
                    return OSStatus.NoError;

                case KeyboardEventKind.RawKeyUp:
                    keyboard[Keymap[code]] = false;
                    return OSStatus.NoError;

                case KeyboardEventKind.RawKeyModifiersChanged:
                    ProcessModifierKey(inEvent);
                    return OSStatus.NoError;

                default:
                    return OSStatus.EventNotHandled;
            }
        }
        protected static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData)
        {
            // bail out if the window passed in is not actually our window.
            // I think this happens if using winforms with a GameWindow sometimes.
            if (!mWindows.ContainsKey(userData))
                return OSStatus.EventNotHandled;

            WeakReference reference = mWindows[userData];

            // bail out if the CarbonGLNative window has been garbage collected.
            if (!reference.IsAlive) {
                mWindows.Remove(userData);
                return OSStatus.EventNotHandled;
            }

            CarbonGLNative window = (CarbonGLNative)reference.Target;
            //Debug.Print("Processing {0} event for {1}.", evt, window.window);
            if (window == null) {
                Debug.Print("Window for event not found.");
                return OSStatus.EventNotHandled;
            }
            EventInfo evt = new EventInfo(inEvent);
            return window.DispatchEvent(inCaller, inEvent, evt, userData);
        }
        internal OSStatus DispatchEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            switch (evt.EventClass)
            {
                case EventClass.Window:
                    return ProcessWindowEvent(inCaller, inEvent, evt, userData);

                case EventClass.Mouse:
                    return ProcessMouseEvent(inCaller, inEvent, evt, userData);

                case EventClass.Keyboard:
                    return ProcessKeyboardEvent(inCaller, inEvent, evt, userData);

                default:
                    return OSStatus.EventNotHandled;
            }
        }
示例#7
0
 protected OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
 {
   HIPoint pt1 = new HIPoint();
   HIPoint pt2 = new HIPoint();
   IntPtr windowRef;
   int num = (int) API.GetEventWindowRef(inEvent, out windowRef);
   OSStatus errorCode = API.GetEventMouseLocation(inEvent, out pt2);
   if (this.windowState == WindowState.Fullscreen)
     pt1 = pt2;
   else if (this.CursorVisible)
   {
     errorCode = API.GetEventWindowMouseLocation(inEvent, out pt1);
     pt1.Y -= (float) this.mTitlebarHeight;
   }
   else
   {
     errorCode = API.GetEventMouseDelta(inEvent, out pt1);
     pt1.X += this.mouse_rel_x;
     pt1.Y += this.mouse_rel_y;
     pt1 = this.ConfineMouseToWindow(windowRef, pt1);
     this.ResetMouseToWindowCenter();
     this.mouse_rel_x = pt1.X;
     this.mouse_rel_y = pt1.Y;
   }
   if (errorCode != OSStatus.NoError && errorCode != OSStatus.EventParameterNotFound)
     throw new MacOSException(errorCode);
   Point pt3 = new Point((int) pt1.X, (int) pt1.Y);
   this.CheckEnterLeaveEvents(windowRef, pt3);
   switch (evt.MouseEventKind)
   {
     case MouseEventKind.MouseDown:
     case MouseEventKind.MouseUp:
       OpenTK.Platform.MacOS.Carbon.MouseButton eventMouseButton = API.GetEventMouseButton(inEvent);
       bool flag = evt.MouseEventKind == MouseEventKind.MouseDown;
       switch (eventMouseButton)
       {
         case OpenTK.Platform.MacOS.Carbon.MouseButton.Primary:
           this.InputDriver.Mouse[0][OpenTK.Input.MouseButton.Left] = flag;
           break;
         case OpenTK.Platform.MacOS.Carbon.MouseButton.Secondary:
           this.InputDriver.Mouse[0][OpenTK.Input.MouseButton.Right] = flag;
           break;
         case OpenTK.Platform.MacOS.Carbon.MouseButton.Tertiary:
           this.InputDriver.Mouse[0][OpenTK.Input.MouseButton.Middle] = flag;
           break;
       }
       return OSStatus.NoError;
     case MouseEventKind.MouseMoved:
     case MouseEventKind.MouseDragged:
       if (this.windowState == WindowState.Fullscreen)
       {
         if (pt3.X != this.InputDriver.Mouse[0].X || pt3.Y != this.InputDriver.Mouse[0].Y)
           this.InputDriver.Mouse[0].Position = pt3;
       }
       else
       {
         if ((double) pt1.Y < 0.0 || pt3.X == this.InputDriver.Mouse[0].X && pt3.Y == this.InputDriver.Mouse[0].Y)
           return OSStatus.EventNotHandled;
         this.InputDriver.Mouse[0].Position = pt3;
       }
       return OSStatus.EventNotHandled;
     case MouseEventKind.WheelMoved:
       this.InputDriver.Mouse[0].WheelPrecise += (float) API.GetEventMouseWheelDelta(inEvent);
       return OSStatus.NoError;
     default:
       return OSStatus.EventNotHandled;
   }
 }
示例#8
0
 private OSStatus ProcessWindowEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
 {
   switch (evt.WindowEventKind)
   {
     case WindowEventKind.WindowActivate:
       this.OnActivate();
       return OSStatus.EventNotHandled;
     case WindowEventKind.WindowDeactivate:
       this.OnDeactivate();
       return OSStatus.EventNotHandled;
     case WindowEventKind.WindowBoundsChanged:
       int width = this.Width;
       int height = this.Height;
       int x = this.X;
       int y = this.Y;
       this.LoadSize();
       if (x != this.X || y != this.Y)
         this.Move((object) this, EventArgs.Empty);
       if (width != this.Width || height != this.Height)
         this.Resize((object) this, EventArgs.Empty);
       return OSStatus.EventNotHandled;
     case WindowEventKind.WindowClose:
       CancelEventArgs e = new CancelEventArgs();
       this.OnClosing(e);
       return e.Cancel ? OSStatus.NoError : OSStatus.EventNotHandled;
     case WindowEventKind.WindowClosed:
       this.mExists = false;
       this.OnClosed();
       return OSStatus.NoError;
     default:
       return OSStatus.EventNotHandled;
   }
 }
示例#9
0
 private OSStatus ProcessKeyboardEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
 {
   MacOSKeyCode code = MacOSKeyCode.A;
   char charCode = char.MinValue;
   switch (evt.KeyboardEventKind)
   {
     case KeyboardEventKind.RawKeyDown:
     case KeyboardEventKind.RawKeyRepeat:
     case KeyboardEventKind.RawKeyUp:
       CarbonGLNative.GetCharCodes(inEvent, out code, out charCode);
       this.mKeyPressArgs.KeyChar = charCode;
       break;
   }
   switch (evt.KeyboardEventKind)
   {
     case KeyboardEventKind.RawKeyDown:
       Key index1;
       if (CarbonGLNative.Keymap.TryGetValue(code, out index1))
       {
         this.InputDriver.Keyboard[0][index1] = true;
         this.OnKeyPress(this.mKeyPressArgs);
       }
       return OSStatus.NoError;
     case KeyboardEventKind.RawKeyRepeat:
       if (!this.InputDriver.Keyboard[0].KeyRepeat)
         break;
       else
         goto case KeyboardEventKind.RawKeyDown;
     case KeyboardEventKind.RawKeyUp:
       Key index2;
       if (CarbonGLNative.Keymap.TryGetValue(code, out index2))
         this.InputDriver.Keyboard[0][index2] = false;
       return OSStatus.NoError;
     case KeyboardEventKind.RawKeyModifiersChanged:
       this.ProcessModifierKey(inEvent);
       return OSStatus.NoError;
   }
   return OSStatus.EventNotHandled;
 }
示例#10
0
 protected static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData)
 {
   if (!CarbonGLNative.mWindows.ContainsKey(userData))
     return OSStatus.EventNotHandled;
   WeakReference weakReference = CarbonGLNative.mWindows[userData];
   if (!weakReference.IsAlive)
   {
     CarbonGLNative.mWindows.Remove(userData);
     return OSStatus.EventNotHandled;
   }
   else
   {
     CarbonGLNative carbonGlNative = (CarbonGLNative) weakReference.Target;
     if (carbonGlNative == null)
       return OSStatus.EventNotHandled;
     EventInfo evt = new EventInfo(inEvent);
     return carbonGlNative.DispatchEvent(inCaller, inEvent, evt, userData);
   }
 }
示例#11
0
 private static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData)
 {
     EventInfo evt = new EventInfo(inEvent);
       switch (evt.EventClass)
       {
     case EventClass.Keyboard:
     case EventClass.Mouse:
       if (Application.WindowEventHandler != null)
     return Application.WindowEventHandler.DispatchEvent(inCaller, inEvent, evt, userData);
       else
     break;
     case EventClass.Application:
       int num = (int) evt.AppEventKind;
       return OSStatus.EventNotHandled;
     case EventClass.AppleEvent:
       API.ProcessAppleEvent(inEvent);
       break;
       }
       return OSStatus.EventNotHandled;
 }