コード例 #1
0
 public override void CursorPressed(Mogre.Vector2 cursorPos)
 {
     if (IsCursorOver(cursorPos))
     {
         SetState(ButtonState.BS_DOWN);
     }
 }
コード例 #2
0
 public override void CursorReleased(Mogre.Vector2 cursorPos)
 {
     if (mState == ButtonState.BS_DOWN)
     {
         setState(ButtonState.BS_OVER);
     }
 }
コード例 #3
0
        public static bool IsCursorOver(Mogre.OverlayElement element, Mogre.Vector2 cursorPos, float voidBorder)
        {
            if (element == null)
            {
                return(false);
            }
            Mogre.OverlayManager om = Mogre.OverlayManager.Singleton;
            float detrivedLeft      = element._getDerivedLeft();
            float detrivedTop       = element._getDerivedTop();
            float l = detrivedLeft * om.ViewportWidth;
            float t = detrivedTop * om.ViewportHeight;
            float r = 0;
            float b = 0;

            if (element.MetricsMode == GuiMetricsMode.GMM_RELATIVE)
            {
                r = l + element.Width * om.ViewportWidth;
                b = t + element.Height * om.ViewportHeight;
            }
            else if (element.MetricsMode == GuiMetricsMode.GMM_PIXELS)
            {
                r = l + element.Width;
                b = t + element.Height;
            }

            bool b1 = cursorPos.x >= l + voidBorder;
            bool b2 = cursorPos.x <= r - voidBorder;
            bool b3 = cursorPos.y >= t + voidBorder;
            bool b4 = cursorPos.y <= b - voidBorder;

            return(b1 && b2 && b3 && b4);
        }
コード例 #4
0
        public virtual void OnMouseLeftDown(Vector2 point, MouseDevice mouseDevice)
        {
            this.lastMouse       = point;
            this.lastClickPoint  = point;
            this.lastMouseDevice = mouseDevice;

            if (mouseDevice.RightButton == MouseButtonState.Pressed)
            {
                return;
            }

            Mogre.Ray mouseRay;
            GetMouseRay(this.lastMouse, out mouseRay);

            BaseEditor selected = MogitorsRoot.Instance.Selected;

            if (selected != null && selected == GetObjectUnderMouse(mouseRay, true, true))
            {
                SaveEditorStates(mouseRay);

                isEditing = true;
            }
            else
            {
                isEditing = false;
            }
        }
コード例 #5
0
        private void HandleObjOperationNoResize(Mogre.Vector3 objNewPos, Mogre.Vector2 cursorPos)
        {
            if (currentSelectedEnt == null)
            {
                return;
            }
            Mogre.Vector3 currentPos = currentSelectedEnt.ParentNode.Position;
            switch (operation)
            {
            case EditOperation.ChangingObjCoordFllowMouse:
                currentSelectedEnt.ParentNode.Position = objNewPos;
                break;

            case EditOperation.ChangingObjCoord:
                float offsetX = cursorPos.x - lastMousePos.x;
                float offsetZ = cursorPos.y - lastMousePos.y;

                Mogre.Vector3 newPosXZ = new Mogre.Vector3(
                    currentPos.x - offsetX,
                    currentPos.y,
                    currentPos.z - offsetZ);
                currentSelectedEnt.ParentNode.Position = newPosXZ;
                break;

            case EditOperation.ChangingObjHeight:
                Mogre.Vector3 newPosY = new Mogre.Vector3(currentPos.x, objNewPos.y, currentPos.z);
                currentSelectedEnt.ParentNode.Position = newPosY;
                break;
            }
        }
コード例 #6
0
 public virtual void OnMouseRightUp(Vector2 point, MouseDevice mouseDevice)
 {
     this.lastMouse       = point;
     this.lastMouseDevice = mouseDevice;
     MogitorsSystem.Instance.SetMouseCursor(Cursors.Arrow);
     MogitorsSystem.Instance.ShowMouseCursor(true);
 }
コード例 #7
0
ファイル: SliderWidget.cs プロジェクト: lennyhans/OpenMB
 public override void CursorReleased(Mogre.Vector2 cursorPos)
 {
     if (mDragging)
     {
         mDragging    = false;
         mHandle.Left = ((int)((mValue - mMinValue) / (mMaxValue - mMinValue) * (mTrack.Width - mHandle.Width)));
     }
 }
コード例 #8
0
ファイル: SelectMenuWidget.cs プロジェクト: lennyhans/OpenMB
        public override void CursorMoved(Mogre.Vector2 cursorPos)
        {
            Mogre.OverlayManager om = Mogre.OverlayManager.Singleton;

            if (isExpanded)
            {
                if (isDragging)
                {
                    Mogre.Vector2 co            = Widget.CursorOffset(scrollHandleElement, cursorPos);
                    float         newTop        = scrollHandleElement.Top + co.y - dragOffset;
                    float         lowerBoundary = scrollTrackElement.Height - scrollHandleElement.Height;
                    scrollHandleElement.Top = (UIMathHelper.clamp <int>((int)newTop, 0, (int)lowerBoundary));

                    float scrollPercentage = UIMathHelper.clamp <float>(newTop / lowerBoundary, 0f, 1f);
                    int   newIndex         = (int)(scrollPercentage * (Items.Count - itemElements.Count) + 0.5f);
                    if (newIndex != displayIndex)
                    {
                        setDisplayIndex((uint)newIndex);
                    }
                    return;
                }

                float l = itemElements[0]._getDerivedLeft() * om.ViewportWidth + 5f;
                float t = itemElements[0]._getDerivedTop() * om.ViewportHeight + 5f;
                float r = l + itemElements[itemElements.Count - 1].Width - 10f;
                float b = itemElements[itemElements.Count - 1]._getDerivedTop() * om.ViewportHeight + itemElements[itemElements.Count - 1].Height - 5f;

                if (cursorPos.x >= l && cursorPos.x <= r && cursorPos.y >= t && cursorPos.y <= b)
                {
                    int newIndex = (int)(displayIndex + (cursorPos.y - t) / (b - t) * itemElements.Count);
                    if (highlightIndex != newIndex)
                    {
                        highlightIndex = newIndex;
                        setDisplayIndex((uint)displayIndex);
                    }
                }
            }
            else
            {
                if (IsCursorOver(smallBoxElement, cursorPos, 4f))
                {
                    smallBoxElement.MaterialName       = ("SdkTrays/MiniTextBox/Over");
                    smallBoxElement.BorderMaterialName = ("SdkTrays/MiniTextBox/Over");
                    isCursorOver = true;
                }
                else
                {
                    if (isCursorOver)
                    {
                        smallBoxElement.MaterialName       = ("SdkTrays/MiniTextBox");
                        smallBoxElement.BorderMaterialName = ("SdkTrays/MiniTextBox");
                        isCursorOver = false;
                    }
                }
            }
        }
コード例 #9
0
ファイル: UIManager.cs プロジェクト: honghaoli/OpenMB
        public UIEvent InjectMouseUp(MOIS.MouseEvent evt, MOIS.MouseButtonID id)
        {
            if (!cursorLayer.IsVisible || id != MOIS.MouseButtonID.MB_Left)
            {
                return(null);
            }

            Mogre.Vector2 cursorPos = new Mogre.Vector2(cursor.Left, cursor.Top);

            return(CurrentLayer.InjectMouseUp(evt, id, cursorPos));
        }
コード例 #10
0
 public override void CursorPressed(Mogre.Vector2 cursorPos)
 {
     if (IsCursorOver(cursorPos))
     {
         setState(ButtonState.BS_DOWN);
         if (OnClick != null)
         {
             OnClick(this);
         }
     }
 }
コード例 #11
0
ファイル: UIManager.cs プロジェクト: honghaoli/OpenMB
        public UIEvent InjectMouseMove(MouseEvent evt)
        {
            if (!cursorLayer.IsVisible)             // don't process if cursor layer is invisible
            {
                return(null);
            }

            Mogre.Vector2 cursorPos = new Mogre.Vector2(evt.state.X.abs, evt.state.Y.abs);
            cursor.SetPosition(cursorPos.x, cursorPos.y);

            return(CurrentLayer.InjectMouseMove(evt, cursorPos));
        }
コード例 #12
0
ファイル: SliderWidget.cs プロジェクト: lennyhans/OpenMB
        public override void CursorMoved(Mogre.Vector2 cursorPos)
        {
            if (mDragging)
            {
                Mogre.Vector2 co            = Widget.CursorOffset(mHandle, cursorPos);
                float         newLeft       = mHandle.Left + co.x - mDragOffset;
                float         rightBoundary = mTrack.Width - mHandle.Width;

                mHandle.Left = (UIMathHelper.clamp <int>((int)newLeft, 0, (int)rightBoundary));
                setValue(getSnappedValue(newLeft / rightBoundary));
            }
        }
コード例 #13
0
        public override void CursorMoved(Mogre.Vector2 cursorPos)
        {
            if (dragging)
            {
                Vector2 co            = Widget.CursorOffset(scrollHandle, cursorPos);
                float   newTop        = scrollHandle.Top + co.y - dragOffset;
                float   lowerBoundary = scrollTrack.Height - scrollHandle.Height;
                scrollHandle.Top = (UIMathHelper.clamp <int>((int)newTop, 0, (int)lowerBoundary));

                // update text area contents based on new scroll percentage
                scrollPercentage = UIMathHelper.clamp <float>(newTop / lowerBoundary, 0f, 1f);
                filterLines();
            }
        }
コード例 #14
0
        public virtual void OnMouseWheel(Vector2 point, float delta, MouseDevice mouseDevice)
        {
            this.lastMouse       = point;
            this.lastMouseDevice = mouseDevice;

            if (ActiveCamera == null)
            {
                return;
            }
            Mogre.Vector3 vPos = ActiveCamera.DerivedPosition;

            Mogre.Vector3 vDelta = new Mogre.Vector3(0, 0, delta / 16.0f) * CameraSpeed;
            vPos = vPos - (ActiveCamera.DerivedOrientation * vDelta);
            this.newCamPosition = vPos;
        }
コード例 #15
0
        public virtual void OnMouseLeave(Vector2 point, MouseDevice mouseDevice)
        {
            this.lastMouseDevice = null;

            foreach (var it in highLighted)
            {
                it.Value.IsHighLighted = false;
            }
            highLighted.Clear();

            this.lastMouse = new Mogre.Vector2(-1, -1);

            isEditing = false;

            MogitorsSystem.Instance.ShowMouseCursor(true);
        }
コード例 #16
0
 public override void CursorMoved(Mogre.Vector2 cursorPos)
 {
     if (IsCursorOver(cursorPos))
     {
         if (mState == ButtonState.BS_UP)
         {
             setState(ButtonState.BS_OVER);
         }
     }
     else
     {
         if (mState != ButtonState.BS_UP)
         {
             setState(ButtonState.BS_UP);
         }
     }
 }
コード例 #17
0
        public virtual void OnMouseLeftUp(Vector2 point, MouseDevice mouseDevice)
        {
            this.lastMouse       = point;
            this.lastClickPoint  = point;
            this.lastMouseDevice = mouseDevice;

            Mogre.Ray mouseRay;
            GetMouseRay(this.lastMouse, out mouseRay);

            EditorAxis = AxisType.None;

            MogitorsRoot.Instance.HighlightGizmo(AxisType.None);

            if (!isEditing)
            {
                if (editorTool >= EditorTools.Select && editorTool <= EditorTools.Scale)
                {
                    DoSelect(mouseRay);
                }
            }
            isEditing = false;
        }
コード例 #18
0
ファイル: SliderWidget.cs プロジェクト: lennyhans/OpenMB
        public override void CursorPressed(Mogre.Vector2 cursorPos)
        {
            if (!mHandle.IsVisible)
            {
                return;
            }

            Mogre.Vector2 co = Widget.CursorOffset(mHandle, cursorPos);

            if (co.SquaredLength <= 81f)
            {
                mDragging   = true;
                mDragOffset = co.x;
            }
            else if (Widget.IsCursorOver(mTrack, cursorPos))
            {
                float newLeft       = mHandle.Left + co.x;
                float rightBoundary = mTrack.Width - mHandle.Width;

                mHandle.Left = (UIMathHelper.clamp <int>((int)newLeft, 0, (int)rightBoundary));
                setValue(getSnappedValue(newLeft / rightBoundary));
            }
        }
コード例 #19
0
 public virtual void OnMouseMiddleUp(Vector2 point, MouseDevice mouseDevice)
 {
     this.lastMouse       = point;
     this.lastMouseDevice = mouseDevice;
     MogitorsSystem.Instance.ShowMouseCursor(true);
 }
コード例 #20
0
ファイル: ViewportEditor.cs プロジェクト: andyhebear/likeleon
        public virtual void OnMouseLeave(Vector2 point, MouseDevice mouseDevice)
        {
            this.lastMouseDevice = null;

            foreach (var it in highLighted)
            {
                it.Value.IsHighLighted = false;
            }
            highLighted.Clear();

            this.lastMouse = new Mogre.Vector2(-1, -1);

            isEditing = false;

            MogitorsSystem.Instance.ShowMouseCursor(true);
        }
コード例 #21
0
ファイル: ViewportEditor.cs プロジェクト: andyhebear/likeleon
 public virtual void OnMouseMiddleUp(Vector2 point, MouseDevice mouseDevice)
 {
     this.lastMouse = point;
     this.lastMouseDevice = mouseDevice;
     MogitorsSystem.Instance.ShowMouseCursor(true);
 }
コード例 #22
0
ファイル: ViewportEditor.cs プロジェクト: andyhebear/likeleon
        public virtual void OnMouseMove(Vector2 point, MouseDevice mouseDevice, bool imitate)
        {
            this.lastMouseDevice = mouseDevice;

            if (isSettingPos)
            {
                isSettingPos = false;
                this.lastMouse = point;
                return;
            }

            float deltaX = (point.x - lastMouse.x) * 0.5f;
            float deltaY = (point.y - lastMouse.y) * 0.5f;

            MogitorsRoot mogRoot = MogitorsRoot.Instance;
            BaseEditor selected = mogRoot.Selected;

            Ray mouseRay;

            if (!imitate)
            {
                if (mouseDevice.MiddleButton == MouseButtonState.Pressed)
                {
                    Vector3 vPos = ActiveCamera.DerivedPosition;
                    Vector3 vDelta = new Vector3(deltaX * CameraSpeed / 3.0f, -deltaY * CameraSpeed / 3.0f, 0);
                    ActiveCamera.DerivedPosition = (vPos + (ActiveCamera.DerivedOrientation * vDelta));
                    this.newCamPosition = Vector3.ZERO;
                    MogitorsSystem.Instance.ShowMouseCursor(false);

                    point.x -= (deltaX * 2.0f);
                    point.y -= (deltaY * 2.0f);

                    isSettingPos = true;
                    MogitorsSystem.Instance.SetMousePosition(point + new Vector2(this.handle.ActualLeft, this.handle.ActualTop));
                }
                else if (mouseDevice.RightButton == MouseButtonState.Pressed)
                {
                    ActiveCamera.Yaw(new Degree(-deltaX / 4.0f));
                    ActiveCamera.Pitch(new Degree(-deltaY / 4.0f));
                    MogitorsSystem.Instance.ShowMouseCursor(false);

                    point.x -= (deltaX * 2.0f);
                    point.y -= (deltaY * 2.0f);

                    isSettingPos = true;
                    MogitorsSystem.Instance.SetMousePosition(point + new Vector2(this.handle.ActualLeft, this.handle.ActualTop));

                    if (!GetMouseRay(point, out mouseRay))
                        return;

                    if (mogRoot.Selected != null)
                        this.lastUsedPlane = MogitorsRoot.Instance.FindGizmoTranslationPlane(mouseRay, EditorAxis);
                }
            }

            if (!GetMouseRay(point, out mouseRay))
                return;

            if (EditorTool != EditorTools.Rotate || selected == null)
                this.lastMouse = point;

            if (selected != null)
            {
                if (EditorAxis == AxisType.None)
                {
                    AxisType axis = AxisType.None;
                    mogRoot.PickGizmos(mouseRay, ref axis);
                    mogRoot.HighlightGizmo(axis);
                }
                else
                {
                    mogRoot.HighlightGizmo(EditorAxis);
                }
            }

            if (isEditing && selected != null)
            {
                if ((EditorTool == EditorTools.Move) && selected.Supports(EditFlags.CanMove))
                {
                    Vector3 vNewPos = Vector3.ZERO;

                    vNewPos = mogRoot.GetGizmoIntersect(mouseRay, this.lastUsedPlane, EditorAxis, this.lastDerivedPosition);
                    vNewPos = vNewPos - this.last3DDelta + this.lastDerivedPosition;

                    selected.DerivedPosition = vNewPos;
                }
                else if ((EditorTool == EditorTools.Scale) && selected.Supports(EditFlags.CanScale))
                {
                    Vector3 vNewDist = mogRoot.GetGizmoIntersect(mouseRay, this.lastUsedPlane, EditorAxis, this.lastDerivedPosition);
                    Vector3 vScale = this.lastScale;
                    float fNewDist = vNewDist.Length;
                    float fLength = this.last3DDelta.Length;

                    if ((int)(EditorAxis & AxisType.X) != 0)
                        vScale.x *= (fNewDist / fLength);
                    if ((int)(EditorAxis & AxisType.Y) != 0)
                        vScale.y *= (fNewDist / fLength);
                    if ((int)(EditorAxis & AxisType.Z) != 0)
                        vScale.z *= (fNewDist / fLength);

                    PropertyInfo prop = selected.GetType().GetProperty("Scale");
                    if (prop != null)
                        prop.SetValue(selected, vScale, null);
                }
                else if ((EditorTool == EditorTools.Rotate) && selected.Supports(EditFlags.CanRotate))
                {
                    Quaternion q1 = this.lastDerivedOrient;

                    switch (EditorAxis)
                    {
                        case AxisType.X:
                            q1 = q1 * new Quaternion(new Degree(-deltaY), new Vector3(1, 0, 0));
                            break;
                        case AxisType.Y:
                            q1 = q1 * new Quaternion(new Degree(-deltaY), new Vector3(0, 1, 0));
                            break;
                        case AxisType.Z:
                            q1 = q1 * new Quaternion(new Degree(-deltaY), new Vector3(0, 0, 1));
                            break;
                    }

                    selected.DerivedOrientation = q1;
                }
            }

            HighlightObjectAtPosition(mouseRay);
        }
コード例 #23
0
ファイル: ViewportEditor.cs プロジェクト: andyhebear/likeleon
 public virtual void OnMouseRightDown(Vector2 point, MouseDevice mouseDevice)
 {
     this.lastMouse = point;
     this.lastMouseDevice = mouseDevice;
 }
コード例 #24
0
 /// <summary>
 /// Static utility method to check if the cursor is over an overlay element.
 /// </summary>
 /// <returns></returns>
 public static bool IsCursorOver(Mogre.OverlayElement element, Mogre.Vector2 cursorPos)
 {
     return(IsCursorOver(element, cursorPos, 0f));
 }
コード例 #25
0
ファイル: ViewportEditor.cs プロジェクト: andyhebear/likeleon
 public virtual void OnMouseRightUp(Vector2 point, MouseDevice mouseDevice)
 {
     this.lastMouse = point;
     this.lastMouseDevice = mouseDevice;
     MogitorsSystem.Instance.SetMouseCursor(Cursors.Arrow);
     MogitorsSystem.Instance.ShowMouseCursor(true);
 }
コード例 #26
0
ファイル: ViewportEditor.cs プロジェクト: andyhebear/likeleon
        public virtual void OnMouseWheel(Vector2 point, float delta, MouseDevice mouseDevice)
        {
            this.lastMouse = point;
            this.lastMouseDevice = mouseDevice;

            if (ActiveCamera == null)
                return;
            Mogre.Vector3 vPos = ActiveCamera.DerivedPosition;

            Mogre.Vector3 vDelta = new Mogre.Vector3(0, 0, delta / 16.0f) * CameraSpeed;
            vPos = vPos - (ActiveCamera.DerivedOrientation * vDelta);
            this.newCamPosition = vPos;
        }
コード例 #27
0
        public override void ProcessParameters(Mogre.NameValuePairList parameters)
        {
            Mogre.NameValuePairList.Iterator ni;

            if ((ni = parameters.Find("Name")) != parameters.End())
            {
                this.name = ni.Value;
            }

            if ((ni = parameters.Find("Dimensions")) != parameters.End())
            {
                this.dimensions = MogreX.StringConverter.ParseVector4(ni.Value);
            }

            if ((ni = parameters.Find("Skies")) != parameters.End())
            {
                this.skies = Mogre.StringConverter.ParseBool(ni.Value);
            }

            if ((ni = parameters.Find("Shadows")) != parameters.End())
            {
                this.shadows = Mogre.StringConverter.ParseBool(ni.Value);
            }

            if ((ni = parameters.Find("Overlays")) != parameters.End())
            {
                this.overlays = Mogre.StringConverter.ParseBool(ni.Value);
            }

            if ((ni = parameters.Find("CamPosition")) != parameters.End())
            {
                this.camPosition = Mogre.StringConverter.ParseVector3(ni.Value);
            }

            if ((ni = parameters.Find("CamOrientation")) != parameters.End())
            {
                this.camOrientation = Mogre.StringConverter.ParseQuaternion(ni.Value);
            }

            if ((ni = parameters.Find("CamClipDistance")) != parameters.End())
            {
                this.camClipDistance = MogreX.StringConverter.ParseVector2(ni.Value);
            }

            if ((ni = parameters.Find("CamPolyMode")) != parameters.End())
            {
                this.camPolyMode = (Mogre.PolygonMode)Mogre.StringConverter.ParseInt(ni.Value);
                OnPropertyChanged("CamPolyMode");
            }

            if ((ni = parameters.Find("CamFOV")) != parameters.End())
            {
                this.camFOV = Mogre.StringConverter.ParseReal(ni.Value);
            }

            if ((ni = parameters.Find("Colour")) != parameters.End())
            {
                this.colour = Mogre.StringConverter.ParseColourValue(ni.Value);
            }

            this.compositorStorage.Clear();
            for (int cx = 0; cx < 100; ++cx)
            {
                string searchstr = "Compositor" + Mogre.StringConverter.ToString(cx);
                if ((ni = parameters.Find(searchstr + "Name")) != parameters.End())
                {
                    CompositorPush compData = new CompositorPush();
                    compData.Name    = ni.Value;
                    ni               = parameters.Find(searchstr + "Enabled");
                    compData.Enabled = Mogre.StringConverter.ParseBool(ni.Value);
                    this.compositorStorage.Add(compData);
                }
                else
                {
                    break;
                }
            }
        }
コード例 #28
0
        public virtual void OnMouseMove(Vector2 point, MouseDevice mouseDevice, bool imitate)
        {
            this.lastMouseDevice = mouseDevice;

            if (isSettingPos)
            {
                isSettingPos   = false;
                this.lastMouse = point;
                return;
            }

            float deltaX = (point.x - lastMouse.x) * 0.5f;
            float deltaY = (point.y - lastMouse.y) * 0.5f;

            MogitorsRoot mogRoot  = MogitorsRoot.Instance;
            BaseEditor   selected = mogRoot.Selected;

            Ray mouseRay;

            if (!imitate)
            {
                if (mouseDevice.MiddleButton == MouseButtonState.Pressed)
                {
                    Vector3 vPos   = ActiveCamera.DerivedPosition;
                    Vector3 vDelta = new Vector3(deltaX * CameraSpeed / 3.0f, -deltaY * CameraSpeed / 3.0f, 0);
                    ActiveCamera.DerivedPosition = (vPos + (ActiveCamera.DerivedOrientation * vDelta));
                    this.newCamPosition          = Vector3.ZERO;
                    MogitorsSystem.Instance.ShowMouseCursor(false);

                    point.x -= (deltaX * 2.0f);
                    point.y -= (deltaY * 2.0f);

                    isSettingPos = true;
                    MogitorsSystem.Instance.SetMousePosition(point + new Vector2(this.handle.ActualLeft, this.handle.ActualTop));
                }
                else if (mouseDevice.RightButton == MouseButtonState.Pressed)
                {
                    ActiveCamera.Yaw(new Degree(-deltaX / 4.0f));
                    ActiveCamera.Pitch(new Degree(-deltaY / 4.0f));
                    MogitorsSystem.Instance.ShowMouseCursor(false);

                    point.x -= (deltaX * 2.0f);
                    point.y -= (deltaY * 2.0f);

                    isSettingPos = true;
                    MogitorsSystem.Instance.SetMousePosition(point + new Vector2(this.handle.ActualLeft, this.handle.ActualTop));

                    if (!GetMouseRay(point, out mouseRay))
                    {
                        return;
                    }

                    if (mogRoot.Selected != null)
                    {
                        this.lastUsedPlane = MogitorsRoot.Instance.FindGizmoTranslationPlane(mouseRay, EditorAxis);
                    }
                }
            }

            if (!GetMouseRay(point, out mouseRay))
            {
                return;
            }

            if (EditorTool != EditorTools.Rotate || selected == null)
            {
                this.lastMouse = point;
            }

            if (selected != null)
            {
                if (EditorAxis == AxisType.None)
                {
                    AxisType axis = AxisType.None;
                    mogRoot.PickGizmos(mouseRay, ref axis);
                    mogRoot.HighlightGizmo(axis);
                }
                else
                {
                    mogRoot.HighlightGizmo(EditorAxis);
                }
            }

            if (isEditing && selected != null)
            {
                if ((EditorTool == EditorTools.Move) && selected.Supports(EditFlags.CanMove))
                {
                    Vector3 vNewPos = Vector3.ZERO;

                    vNewPos = mogRoot.GetGizmoIntersect(mouseRay, this.lastUsedPlane, EditorAxis, this.lastDerivedPosition);
                    vNewPos = vNewPos - this.last3DDelta + this.lastDerivedPosition;

                    selected.DerivedPosition = vNewPos;
                }
                else if ((EditorTool == EditorTools.Scale) && selected.Supports(EditFlags.CanScale))
                {
                    Vector3 vNewDist = mogRoot.GetGizmoIntersect(mouseRay, this.lastUsedPlane, EditorAxis, this.lastDerivedPosition);
                    Vector3 vScale   = this.lastScale;
                    float   fNewDist = vNewDist.Length;
                    float   fLength  = this.last3DDelta.Length;

                    if ((int)(EditorAxis & AxisType.X) != 0)
                    {
                        vScale.x *= (fNewDist / fLength);
                    }
                    if ((int)(EditorAxis & AxisType.Y) != 0)
                    {
                        vScale.y *= (fNewDist / fLength);
                    }
                    if ((int)(EditorAxis & AxisType.Z) != 0)
                    {
                        vScale.z *= (fNewDist / fLength);
                    }

                    PropertyInfo prop = selected.GetType().GetProperty("Scale");
                    if (prop != null)
                    {
                        prop.SetValue(selected, vScale, null);
                    }
                }
                else if ((EditorTool == EditorTools.Rotate) && selected.Supports(EditFlags.CanRotate))
                {
                    Quaternion q1 = this.lastDerivedOrient;

                    switch (EditorAxis)
                    {
                    case AxisType.X:
                        q1 = q1 * new Quaternion(new Degree(-deltaY), new Vector3(1, 0, 0));
                        break;

                    case AxisType.Y:
                        q1 = q1 * new Quaternion(new Degree(-deltaY), new Vector3(0, 1, 0));
                        break;

                    case AxisType.Z:
                        q1 = q1 * new Quaternion(new Degree(-deltaY), new Vector3(0, 0, 1));
                        break;
                    }

                    selected.DerivedOrientation = q1;
                }
            }

            HighlightObjectAtPosition(mouseRay);
        }
コード例 #29
0
ファイル: StaticText.cs プロジェクト: AlkanV/OpenMB
 public override void _cursorPressed(Mogre.Vector2 cursorPos)
 {
 }
コード例 #30
0
ファイル: ViewportEditor.cs プロジェクト: andyhebear/likeleon
        public virtual void OnMouseLeftDown(Vector2 point, MouseDevice mouseDevice)
        {
            this.lastMouse = point;
            this.lastClickPoint = point;
            this.lastMouseDevice = mouseDevice;

            if (mouseDevice.RightButton == MouseButtonState.Pressed)
                return;

            Mogre.Ray mouseRay;
            GetMouseRay(this.lastMouse, out mouseRay);

            BaseEditor selected = MogitorsRoot.Instance.Selected;

            if (selected != null && selected == GetObjectUnderMouse(mouseRay, true, true))
            {
                SaveEditorStates(mouseRay);

                isEditing = true;
            }
            else
            {
                isEditing = false;
            }
        }
コード例 #31
0
ファイル: SelectMenuWidget.cs プロジェクト: lennyhans/OpenMB
        public override void CursorPressed(Mogre.Vector2 cursorPos)
        {
            Mogre.OverlayManager om = Mogre.OverlayManager.Singleton;

            if (isExpanded)
            {
                if (scrollHandleElement.IsVisible)                 // check for scrolling
                {
                    Mogre.Vector2 co = Widget.CursorOffset(scrollHandleElement, cursorPos);

                    if (co.SquaredLength <= 81f)
                    {
                        isDragging = true;
                        dragOffset = co.y;
                        return;
                    }
                    else if (Widget.IsCursorOver(scrollTrackElement, cursorPos))
                    {
                        float newTop        = scrollHandleElement.Top + co.y;
                        float lowerBoundary = scrollTrackElement.Height - scrollHandleElement.Height;
                        scrollHandleElement.Top = (UIMathHelper.clamp <int>((int)newTop, 0, (int)lowerBoundary));

                        float scrollPercentage = UIMathHelper.clamp <float>(newTop / lowerBoundary, 0f, 1f);
                        setDisplayIndex((uint)(scrollPercentage * (Items.Count - itemElements.Count) + 0.5f));
                        return;
                    }
                }

                if (!IsCursorOver(expandedBoxElement, cursorPos, 3f))
                {
                    retract();
                }
                else
                {
                    float l = itemElements[0]._getDerivedLeft() * om.ViewportWidth + 5f;
                    float t = itemElements[0]._getDerivedTop() * om.ViewportHeight + 5f;
                    float r = l + itemElements[itemElements.Count - 1].Width - 10f;
                    float b = itemElements[itemElements.Count - 1]._getDerivedTop() * om.ViewportHeight + itemElements[itemElements.Count - 1].Height - 5;

                    if (cursorPos.x >= l && cursorPos.x <= r && cursorPos.y >= t && cursorPos.y <= b)
                    {
                        if (highlightIndex != selectionIndex)
                        {
                            SelectItem((uint)highlightIndex);
                        }
                        retract();
                    }
                }
            }
            else
            {
                if (Items.Count < 2)                 // don't waste time showing a menu if there's no choice
                {
                    return;
                }

                if (IsCursorOver(smallBoxElement, cursorPos, 4f))
                {
                    expandedBoxElement.Show();
                    smallBoxElement.Hide();

                    // calculate how much vertical space we need
                    float idealHeight = itemsShown * (smallBoxElement.Height - 8f) + 20f;
                    expandedBoxElement.Height = (idealHeight);
                    scrollTrackElement.Height = (expandedBoxElement.Height - 20f);

                    expandedBoxElement.Left = (smallBoxElement.Left - 4f);

                    // if the expanded menu goes down off the screen, make it go up instead
                    if (smallBoxElement._getDerivedTop() * om.ViewportHeight + idealHeight > om.ViewportHeight)
                    {
                        expandedBoxElement.Top = (smallBoxElement.Top + smallBoxElement.Height - idealHeight + 3f);
                        // if we're in thick style, hide the caption because it will interfere with the expanded menu
                        if (textAreaElement.HorizontalAlignment == GuiHorizontalAlignment.GHA_CENTER)
                        {
                            textAreaElement.Hide();
                        }
                    }
                    else
                    {
                        expandedBoxElement.Top = (smallBoxElement.Top + 3f);
                    }

                    isExpanded     = true;
                    highlightIndex = selectionIndex;
                    setDisplayIndex((uint)highlightIndex);

                    if (itemsShown < Items.Count)                     // update scrollbar position
                    {
                        scrollHandleElement.Show();
                        float lowerBoundary = scrollTrackElement.Height - scrollHandleElement.Height;
                        scrollHandleElement.Top = ((int)(displayIndex * lowerBoundary / (Items.Count - itemElements.Count)));
                    }
                    else
                    {
                        scrollHandleElement.Hide();
                    }
                }
            }
        }
コード例 #32
0
 public virtual void OnMouseRightDown(Vector2 point, MouseDevice mouseDevice)
 {
     this.lastMouse       = point;
     this.lastMouseDevice = mouseDevice;
 }
コード例 #33
0
ファイル: SelectMenuWidget.cs プロジェクト: lennyhans/OpenMB
 public override void CursorReleased(Mogre.Vector2 cursorPos)
 {
     isDragging = false;
 }
コード例 #34
0
ファイル: UIManager.cs プロジェクト: honghaoli/OpenMB
 /// <summary>
 /// Converts a 2D screen coordinate (in pixels) to a 3D ray into the scene.
 /// </summary>
 /// <param name="cam"></param>
 /// <param name="pt"></param>
 /// <returns></returns>
 public static Mogre.Ray ScreenToScene(Mogre.Camera cam, Mogre.Vector2 pt)
 {
     return(cam.GetCameraToViewportRay(pt.x, pt.y));
 }
コード例 #35
0
ファイル: ViewportEditor.cs プロジェクト: andyhebear/likeleon
        public virtual void OnMouseLeftUp(Vector2 point, MouseDevice mouseDevice)
        {
            this.lastMouse = point;
            this.lastClickPoint = point;
            this.lastMouseDevice = mouseDevice;

            Mogre.Ray mouseRay;
            GetMouseRay(this.lastMouse, out mouseRay);

            EditorAxis = AxisType.None;

            MogitorsRoot.Instance.HighlightGizmo(AxisType.None);

            if (!isEditing)
            {
                if (editorTool >= EditorTools.Select && editorTool <= EditorTools.Scale)
                {
                    DoSelect(mouseRay);
                }
            }
            isEditing = false;
        }
コード例 #36
0
 /// <summary>
 /// Static utility method used to get the cursor's offset from the center of an overlay element in pixels.
 /// </summary>
 public static Mogre.Vector2 CursorOffset(Mogre.OverlayElement element, Mogre.Vector2 cursorPos)
 {
     Mogre.OverlayManager om = Mogre.OverlayManager.Singleton;
     return(new Mogre.Vector2(cursorPos.x - (element._getDerivedLeft() * om.ViewportWidth + element.Width / 2), cursorPos.y - (element._getDerivedTop() * om.ViewportHeight + element.Height / 2f)));
 }
コード例 #37
0
ファイル: ViewportEditor.cs プロジェクト: andyhebear/likeleon
        public override void ProcessParameters(Mogre.NameValuePairList parameters)
        {
            Mogre.NameValuePairList.Iterator ni;

            if ((ni = parameters.Find("Name")) != parameters.End())
                this.name = ni.Value;

            if ((ni = parameters.Find("Dimensions")) != parameters.End())
                this.dimensions = MogreX.StringConverter.ParseVector4(ni.Value);

            if ((ni = parameters.Find("Skies")) != parameters.End())
                this.skies = Mogre.StringConverter.ParseBool(ni.Value);

            if ((ni = parameters.Find("Shadows")) != parameters.End())
                this.shadows = Mogre.StringConverter.ParseBool(ni.Value);

            if ((ni = parameters.Find("Overlays")) != parameters.End())
                this.overlays = Mogre.StringConverter.ParseBool(ni.Value);

            if ((ni = parameters.Find("CamPosition")) != parameters.End())
                this.camPosition = Mogre.StringConverter.ParseVector3(ni.Value);

            if ((ni = parameters.Find("CamOrientation")) != parameters.End())
                this.camOrientation = Mogre.StringConverter.ParseQuaternion(ni.Value);

            if ((ni = parameters.Find("CamClipDistance")) != parameters.End())
                this.camClipDistance = MogreX.StringConverter.ParseVector2(ni.Value);

            if ((ni = parameters.Find("CamPolyMode")) != parameters.End())
            {
                this.camPolyMode = (Mogre.PolygonMode)Mogre.StringConverter.ParseInt(ni.Value);
                OnPropertyChanged("CamPolyMode");
            }

            if ((ni = parameters.Find("CamFOV")) != parameters.End())
                this.camFOV = Mogre.StringConverter.ParseReal(ni.Value);

            if ((ni = parameters.Find("Colour")) != parameters.End())
                this.colour = Mogre.StringConverter.ParseColourValue(ni.Value);

            this.compositorStorage.Clear();
            for (int cx = 0; cx < 100; ++cx)
            {
                string searchstr = "Compositor" + Mogre.StringConverter.ToString(cx);
                if ((ni = parameters.Find(searchstr + "Name")) != parameters.End())
                {
                    CompositorPush compData = new CompositorPush();
                    compData.Name = ni.Value;
                    ni = parameters.Find(searchstr + "Enabled");
                    compData.Enabled = Mogre.StringConverter.ParseBool(ni.Value);
                    this.compositorStorage.Add(compData);
                }
                else
                    break;
            }
        }