示例#1
0
 static extern IntPtr SecCopyErrorMessageString(OSStatus status, IntPtr reserved);
示例#2
0
//		struct CFDictionaryKeyCallBacks {
//			CFIndex version;
//			CFDictionaryRetainCallBack retain;
//			CFDictionaryReleaseCallBack release;
//			CFDictionaryCopyDescriptionCallBack copyDescription;
//			CFDictionaryEqualCallBack equal;
//			CFDictionaryHashCallBack hash;
//		};
//
//		struct CFDictionaryValueCallBacks {
//			CFIndex version;
//			CFDictionaryRetainCallBack retain;
//			CFDictionaryReleaseCallBack release;
//			CFDictionaryCopyDescriptionCallBack copyDescription;
//			CFDictionaryEqualCallBack equal;
//		};

		// use kCFTypeDictionaryKeyCallBacks and kCFTypeDictionaryValueCallBacks

		// CFDictionaryRef CFDictionaryCreate (CFAllocatorRef allocator, const void **keys, const void **values, CFIndex numValues, const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks);
		// CFMutableDictionaryRef CFDictionaryCreateMutable (CFAllocatorRef allocator, CFIndex capacity, const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks);

		// void CFDictionaryAddValue (CFMutableDictionaryRef theDict, const void *key, const void *value);

		#endregion

		static string GetError (OSStatus status)
		{
			IntPtr str = IntPtr.Zero;
			try {
				str = SecCopyErrorMessageString (status, IntPtr.Zero);
				return CFStringGetString (str);
			} catch {
				return status.ToString ();
			} finally {
				if (str != IntPtr.Zero)
					CFRelease (str);
			}
		}
示例#3
0
        static string GetError(OSStatus status)
        {
            CFString str = null;

            try {
                str = new CFString (SecCopyErrorMessageString (status, IntPtr.Zero), true);
                return str.ToString ();
            } catch {
                return status.ToString ();
            } finally {
                if (str != null)
                    str.Dispose ();
            }
        }
示例#4
0
 internal MacOSException(Agl.AglError errorCode, string message)
     : base(message)
 {
     this.errorCode = (OSStatus)errorCode;
 }
示例#5
0
 public MacOSException(OSStatus errorCode)
     : base("Error Code " + ((int)errorCode).ToString() + ": " + errorCode.ToString())
 {
     this.errorCode = errorCode;
 }
示例#6
0
 public static void CheckReturn(OSStatus error )
 {
     if( error != OSStatus.NoError )
         throw new MacOSException( error );
 }
示例#7
0
 public MacOSException(OSStatus errorCode, string message)
     : base(message)
 {
     this.errorCode = errorCode;
 }
示例#8
0
        protected OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            System.Diagnostics.Debug.Assert(evt.EventClass == EventClass.Mouse);
            MouseButton button    = MouseButton.Primary;
            HIPoint     pt        = new HIPoint();
            HIPoint     screenLoc = new HIPoint();

            IntPtr thisEventWindow;

            API.GetEventWindowRef(inEvent, out thisEventWindow);

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

            if (this.windowState == WindowState.Fullscreen)
            {
                pt = screenLoc;
            }
            else if (CursorVisible)
            {
                err   = API.GetEventWindowMouseLocation(inEvent, out pt);
                pt.Y -= mTitlebarHeight;
            }
            else
            {
                err   = API.GetEventMouseDelta(inEvent, out pt);
                pt.X += mouse_rel_x;
                pt.Y += mouse_rel_y;
                pt    = ConfineMouseToWindow(thisEventWindow, pt);
                ResetMouseToWindowCenter();
                mouse_rel_x = pt.X;
                mouse_rel_y = pt.Y;
            }

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

            Point mousePosInClient = new Point((int)pt.X, (int)pt.Y);

            CheckEnterLeaveEvents(thisEventWindow, mousePosInClient);

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

                switch (button)
                {
                case MouseButton.Primary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Left] = pressed;
                    break;

                case MouseButton.Secondary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Right] = pressed;
                    break;

                case MouseButton.Tertiary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Middle] = pressed;
                    break;
                }
                return(OSStatus.NoError);

            case MouseEventKind.WheelMoved:
                float delta = API.GetEventMouseWheelDelta(inEvent);
                InputDriver.Mouse[0].WheelPrecise += delta;
                return(OSStatus.NoError);

            case MouseEventKind.MouseMoved:
            case MouseEventKind.MouseDragged:
                if (this.windowState == WindowState.Fullscreen)
                {
                    if (mousePosInClient.X != InputDriver.Mouse[0].X || mousePosInClient.Y != InputDriver.Mouse[0].Y)
                    {
                        InputDriver.Mouse[0].Position = mousePosInClient;
                    }
                }
                else
                {
                    // ignore clicks in the title bar
                    if (pt.Y < 0)
                    {
                        return(OSStatus.EventNotHandled);
                    }

                    if (mousePosInClient.X != InputDriver.Mouse[0].X || mousePosInClient.Y != InputDriver.Mouse[0].Y)
                    {
                        InputDriver.Mouse[0].Position = mousePosInClient;
                    }
                }
                return(OSStatus.EventNotHandled);

            default:
                Debug.Print("{0}", evt);
                return(OSStatus.EventNotHandled);
            }
        }
示例#9
0
        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:
                mouse.Wheel += API.GetEventMouseWheelDelta(inEvent);
                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);
            }
        }
示例#10
0
        internal static unsafe void SetVolume(AudioStream *pThis, float volume)
        {
            OSStatus status = API.AudioQueueSetParameter(pThis->Queue, AudioQueueParameter.Volume, volume);

            API.CheckStatus(status);
        }
示例#11
0
 static extern IntPtr SecCopyErrorMessageString(OSStatus status, IntPtr reserved);
示例#12
0
        static unsafe void ReadBufferInternal(void *pUserData, AudioQueue *pQueue, AudioQueueBuffer *pBuffer)
        {
            AudioStream *pThis = (AudioStream *)pUserData;

            if (pThis == null)
            {
                Console.WriteLine("ReadBufferProc: pThis is null");
            }

            if (!pThis->IsRunning)
            {
                return;
            }

            if (pQueue == null)
            {
                Console.WriteLine("ReadBufferProc: pQueue is null");
            }

            if (pBuffer == null)
            {
                Console.WriteLine("ReadBufferProc: pBuffer is null");
            }

            if (pBuffer->AudioData == null)
            {
                Console.WriteLine("ReadBufferProc: pBuffer->AudioData is null");
            }

            if (pBuffer->PacketDescriptors == null)
            {
                Console.WriteLine("ReadBufferProc: pBuffer->PacketDescriptors is null");
            }

            if (pThis->AudioFile == null)
            {
                Console.WriteLine("ReadBufferProc: pThis->AudioFile is null");
            }

            int numPacketsReadFromFile = pThis->NumPacketsToRead;
            int numBytesReadFromFile   = 0;

            OSStatus status = API.AudioFileReadPackets(pThis->AudioFile, 0, &numBytesReadFromFile, pBuffer->PacketDescriptors, pThis->CurrentPacket, &numPacketsReadFromFile, pBuffer->AudioData);

            API.CheckStatus(status);

            if (status == 0 &&
                numPacketsReadFromFile == 0 &&
                pThis->Looping)
            {
                // we ran out of packets and they are
                // asking to loop, so try and reset
                pThis->CurrentPacket   = 0;
                numPacketsReadFromFile = pThis->NumPacketsToRead;
                numBytesReadFromFile   = 0;
                status = API.AudioFileReadPackets(pThis->AudioFile, 0, &numBytesReadFromFile, pBuffer->PacketDescriptors, pThis->CurrentPacket, &numPacketsReadFromFile, pBuffer->AudioData);
                API.CheckStatus(status);
            }

            if (numPacketsReadFromFile > 0)
            {
                pBuffer->AudioDataByteSize     = numBytesReadFromFile;
                pBuffer->PacketDescriptorCount = numPacketsReadFromFile;

                status = API.AudioQueueEnqueueBuffer(pThis->Queue, pBuffer, (pBuffer->PacketDescriptors != null ? pBuffer->PacketDescriptorCount : 0), pBuffer->PacketDescriptors);
                API.CheckStatus(status);

                pThis->CurrentPacket += numPacketsReadFromFile;
            }
            else
            {
                status = API.AudioQueueStop(pThis->Queue, 0);
                API.CheckStatus(status);
            }
        }
示例#13
0
 internal MacOSException(Agl.AglError errorCode, string message)
     : base(message)
 {
     this.errorCode = (OSStatus)errorCode;
 }
示例#14
0
 public MacOSException(OSStatus errorCode, string message)
     : base(message)
 {
     this.errorCode = errorCode;
 }
示例#15
0
 public MacOSException(OSStatus errorCode)
     : base("Error Code " + ((int)errorCode).ToString() + ": " + errorCode.ToString())
 {
     this.errorCode = errorCode;
 }
        void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow,
                           IntPtr shareContextRef, bool fullscreen)
        {
            List <int> aglAttributes = new  List <int>();

            Debug.Print("AGL pixel format attributes:");
            Debug.Indent();

            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RGBA);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RED_SIZE, mode.ColorFormat.Red);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_GREEN_SIZE, mode.ColorFormat.Green);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_BLUE_SIZE, mode.ColorFormat.Blue);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ALPHA_SIZE, mode.ColorFormat.Alpha);

            if (mode.Depth > 0)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DEPTH_SIZE, mode.Depth);
            }

            if (mode.Stencil > 0)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_STENCIL_SIZE, mode.Stencil);
            }

            if (mode.AccumulatorFormat.BitsPerPixel > 0)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE, mode.AccumulatorFormat.Red);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
            }

            if (mode.Samples > 1)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLE_BUFFERS_ARB, 1);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLES_ARB, mode.Samples);
            }

            if (fullscreen)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN);
            }
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_NONE);

            Debug.Unindent();

            Debug.Write("Attribute array:  ");
            for (int i = 0; i < aglAttributes.Count; i++)
            {
                Debug.Write(aglAttributes[i].ToString() + "  ");
            }
            Debug.WriteLine("");

            AGLPixelFormat myAGLPixelFormat;

            // Choose a pixel format with the attributes we specified.
            if (fullscreen)
            {
                IntPtr gdevice;
                IntPtr cgdevice = GetQuartzDevice(carbonWindow);

                if (cgdevice == IntPtr.Zero)
                {
                    cgdevice = QuartzDisplayDeviceDriver.MainDisplay;
                }

                OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(
                    cgdevice, out gdevice, false);

                if (status != OSStatus.NoError)
                {
                    throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");
                }

                myAGLPixelFormat = Agl.aglChoosePixelFormat(
                    ref gdevice, 1,
                    aglAttributes.ToArray());

                Agl.AglError err = Agl.GetError();

                if (err == Agl.AglError.BadPixelFormat)
                {
                    Debug.Print("Failed to create full screen pixel format.");
                    Debug.Print("Trying again to create a non-fullscreen pixel format.");

                    CreateContext(mode, carbonWindow, shareContextRef, false);
                    return;
                }
            }
            else
            {
                myAGLPixelFormat = Agl.aglChoosePixelFormat(
                    IntPtr.Zero, 0,
                    aglAttributes.ToArray());

                MyAGLReportError("aglChoosePixelFormat");
            }


            Debug.Print("Creating AGL context.  Sharing with {0}", shareContextRef);

            // create the context and share it with the share reference.
            Handle = new ContextHandle(Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
            MyAGLReportError("aglCreateContext");

            // Free the pixel format from memory.
            Agl.aglDestroyPixelFormat(myAGLPixelFormat);
            MyAGLReportError("aglDestroyPixelFormat");

            Debug.Print("IsControl: {0}", carbonWindow.IsControl);

            SetDrawable(carbonWindow);
            SetBufferRect(carbonWindow);
            Update(carbonWindow);

            MakeCurrent(carbonWindow);

            Debug.Print("context: {0}", Handle.Handle);
        }