Beispiel #1
0
        /*!
         * Routes a mouse event from this window to Vixen.
         * Any Vixen objects which observe Event.MOUSE will get these events.
         * If DispatchMouseEvents is false, this functionality is disabled.
         * @see DispatchMouseEvents
         */
        private void DispatchMouse(MouseEventArgs e)
        {
            int         buttons   = 0;
            Keys        modifiers = Control.ModifierKeys;
            SharedWorld world     = SharedWorld.Get();
            Scene       scene     = SharedWorld.MainScene;

            if ((scene == null) || (world == null) || !world.IsRunning())
            {
                return;
            }
            if (!DispatchMouseEvents)
            {
                return;
            }
            if ((e.Button & MouseButtons.Left) != 0)
            {
                buttons |= MouseEvent.LEFT;
            }
            if ((e.Button & MouseButtons.Right) != 0)
            {
                buttons |= MouseEvent.RIGHT;
            }
            if ((e.Button & MouseButtons.Middle) != 0)
            {
                buttons |= MouseEvent.MIDDLE;
            }
            if ((modifiers & Keys.Control) != 0)
            {
                buttons |= MouseEvent.CONTROL;
            }
            if ((modifiers & Keys.Shift) != 0)
            {
                buttons |= MouseEvent.SHIFT;
            }
            world.OnMouse(e.X, e.Y, buttons, 0);
            OnMouse((float)e.X, (float)e.Y, buttons, 0);
        }
Beispiel #2
0
        /*!
         * Routes a mouse event from this window to Vixen.
         * Any Vixen objects which observe Event.MOUSE will get these events.
         * If DispatchMouseEvents is false, this functionality is disabled.
         * @see DispatchMouseEvents
         */
        protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            const int WM_LBUTTONDBLCLK = 0x203;
            const int WM_RBUTTONDBLCLK = 0x206;
            const int WM_MBUTTONDBLCLK = 0x209;
            const int WM_MOUSEMOVE     = 0x0200;
            const int WM_LBUTTONDOWN   = 0x0201;
            const int WM_LBUTTONUP     = 0x0202;
            const int WM_RBUTTONDOWN   = 0x0204;
            const int WM_RBUTTONUP     = 0x0205;
            const int WM_MBUTTONDOWN   = 0x0207;
            const int WM_MBUTTONUP     = 0x0208;
            const int WM_MOVE          = 0x0003;
            const int WM_SIZE          = 0x0005;
            const int WM_DISPLAYCHANGE = 0x007E;
            const int WM_ERASEBKGND    = 0x0014;

            int x, y;
            int buttons = (int)wParam & 0X1F;

            if ((_world == null) || !_world.IsRunning())
            {
                return(IntPtr.Zero);
            }
            switch (msg)
            {
            case WM_ERASEBKGND:
                handled = true;
                return(IntPtr.Zero);

            case WM_MOVE:
            case WM_SIZE:
                if (_scene == null)
                {
                    _scene = _world.GetScene();
                    if (_scene == null)
                    {
                        return(IntPtr.Zero);
                    }
                }
                _scene.Suspend();
                _scene.OnResize();
                _scene.Resume();
                handled = true;
                return(IntPtr.Zero);

            case WM_LBUTTONDBLCLK:
            case WM_RBUTTONDBLCLK:
            case WM_MBUTTONDBLCLK:
                buttons |= MouseEvent.DOUBLE;
                break;

            case WM_RBUTTONDOWN:
            case WM_RBUTTONUP:
            case WM_LBUTTONDOWN:
            case WM_LBUTTONUP:
            case WM_MBUTTONDOWN:
            case WM_MBUTTONUP:
            case WM_MOUSEMOVE:
                break;

            default:
                handled = false;
                return(IntPtr.Zero);
            }
            x = (int)((long)lParam & (long)0x0000ffff);             // LOWORD = x
            y = (int)((long)lParam >> 16);                          // HIWORD = y
            _world.OnMouse(x, y, buttons, 0.0f);
            OnMouse(x, y, buttons, 0);
            handled = true;
            return(IntPtr.Zero);
        }
Beispiel #3
0
        /*!
         * Start up Vixen 3D display and event processing.
         * This function should not be called until the
         * underlying Window has been created and the
         * OS window handle is available. Vixen will display
         * the 3D content in this window.
         */
        public virtual bool RunVixen()
        {
            SharedWorld world        = SharedWorld.Get();
            IntPtr      windowHandle = Handle;
            Scene       scene        = null;

            try
            {
                if (windowHandle == null)
                {
                    LogError("Cannot get window handle for parent window");
                    return(false);
                }
                if ((world != null) && world.IsRunning())
                {
                    return(false);
                }
                //world.SetDebugLevel(1);
                world.Run((uint)windowHandle);
            }
            catch (Exception ex)
            {
                LogError("exception starting 3D  " + ex.Message);
            }
            if (world.IsRunning())
            {
                ThreadStart eventloop = new ThreadStart(EventLoop);
                Thread      thread    = new Thread(eventloop);
                bool        loadasync = World.DoAsyncLoad;

                if (MediaDir != null)
                {
                    world.SetMediaDir(MediaDir);
                }
                if (ContentFile != null)
                {
                    world.FileName = GetMediaPath(ContentFile);
                }
                else
                {
                    loadasync = false;
                }
                thread.Start();
                if (!loadasync)
                {
                    try
                    {
                        scene = MakeScene();
                        if (scene != null)
                        {
                            world.SetScene(scene);
                        }
                    }
                    catch (Exception ex)
                    {
                        SharedWorld.LogError("exception making initial scene " + ex.Message);
                    }
                }
                scene = world.GetScene();
                if (scene != null)
                {
                    scene.OnResize();
                }
                return(true);
            }
            return(false);
        }