示例#1
0
        /// <summary>
        /// Called when a mouse button has been released
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mRenderPanel_MouseUp(object sender, MouseEventArgs e)
        {
            mPointArea = PointArea.None;
            if (e.Button == MouseButtons.Left)
            {
                // We just finished placing a control - override frame 0 with the 
                // control's new layout, without interfering with the command manager's undo/redo
                if (mAddControlCommand != null)
                {
                    Otter.UI.Animation.GUIAnimation onActivate = mAddControlCommand.Controls[0].ParentView.Animations["OnActivate"];
                    if (onActivate != null)
                        onActivate.CreateKeyFrame(mAddControlCommand.Controls[0], 0);
                    mAddControlCommand = null;
                }
                else if (PrimaryControl != null)
                {
                    if (mControlStartPos != PrimaryControl.Location)
                        mCommandManager.AddCommand(new MoveControlCommand(SelectedControls, new PointF(PrimaryControl.Location.X - mControlStartPos.X, PrimaryControl.Location.Y - mControlStartPos.Y)), false);

                    if (mControlStartSize != PrimaryControl.Size || mControlStartCenter != PrimaryControl.Center)
                    {
                        mCommandManager.AddCommand(new ResizeControlCommand(PrimaryControl, mControlStartCenter, mControlStartSize, PrimaryControl.Center, PrimaryControl.Size), false);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// User clicked on the render panel.  See if we selected any controls.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mRenderPanel_MouseDown(object sender, MouseEventArgs e)
        {
            PointF hitLocation = ClientToViewport(e.Location);
            mLastMousePos = hitLocation;
            mMouseMoveStartPos = hitLocation;

            if (ActiveView == null)
                return;

            if (e.Button == MouseButtons.Left)
            {
                mPointArea = PointArea.None;

                if (CreateControlType != null)
                {
                    System.Reflection.ConstructorInfo constructorInfo = CreateControlType.GetConstructor(System.Type.EmptyTypes);
                    GUIControl control = constructorInfo.Invoke(null) as GUIControl;
                    control.AnchorFlags = Otter.Editor.Properties.Settings.Default.AnchorFlags;

                    if (control != null)
                    {
                        control.Location = new PointF(hitLocation.X, hitLocation.Y);
                        control.ID = mActiveView.NextControlID++;
                        control.Scene = ActiveView.Scene;
                        control.Name = GetUniqueControlName(control);

                        // Label Specific
                        if (control is GUILabel && GUIProject.CurrentProject.Fonts.Count > 0)
                        {
                            ((GUILabel)control).FontID = GUIProject.CurrentProject.Fonts[0].ID;
                        }

                        // Slider Specific
                        if (control is GUISlider)
                        {
                            ((GUISlider)control).StartTexture = GetTexture("Textures/Slider_Start.png", "Otter.Editor.res.ControlTextures.Slider_Start.png");
                            ((GUISlider)control).MiddleTexture = GetTexture("Textures/Slider_Middle.png", "Otter.Editor.res.ControlTextures.Slider_Middle.png");
                            ((GUISlider)control).EndTexture = GetTexture("Textures/Slider_End.png", "Otter.Editor.res.ControlTextures.Slider_End.png"); ;
                            ((GUISlider)control).ThumbTexture = GetTexture("Textures/Slider_Thumb.png", "Otter.Editor.res.ControlTextures.Slider_Thumb.png"); ;
                        }

                        // Toggle Specific
                        if (control is GUIToggle)
                        {
                            ((GUIToggle)control).OnTexture = GetTexture("Textures/Toggle_On.png", "Otter.Editor.res.ControlTextures.Toggle_On.png");
                            ((GUIToggle)control).OffTexture = GetTexture("Textures/Toggle_Off.png", "Otter.Editor.res.ControlTextures.Toggle_Off.png");
                        }

                        mAddControlCommand = new AddControlCommand(ActiveView, null, control);
                        mCommandManager.AddCommand(mAddControlCommand, true);

                        SelectedControls.Clear();
                        SelectedControls.Add(control);
                        mPointArea = PointArea.Bottom | PointArea.Right;
                    }
    
                    CreateControlType = null;
                }
                // Hit test the selected controls
                else
                {
                    // Check to see if we've hit any of our selected controls in the body (only).
                    // If so, move the control to the front of the list and apply the point area accordingly.
                    foreach (GUIControl control in SelectedControls)
                    {
                        PointF localPoint = ViewportToControl(hitLocation, control);
                        mPointArea = control.GetPointArea(localPoint);

                        if (mPointArea == PointArea.Body)
                        {
                            PrimaryControl = control;

                            Vector4 absPos = Vector4.Transform(new Vector4(control.Center.X, control.Center.Y, 0.0f, 1.0f), control.FullTransform);
                            mLocationOffset = new PointF(hitLocation.X - absPos.X, hitLocation.Y - absPos.Y);
                            
                            break;
                        }
                    }

                    if (SelectedControls.Count > 1 && mPointArea != PointArea.Body)
                        mPointArea = PointArea.None;
                }

                // If we clicked outside of the control select a new one if possible.
                // Uncomment the PointArea.Body to select a new control if the body was hit
                if (mPointArea == PointArea.None) // || mPointArea == PointArea.Body)
                {
                    GUIControl control = ActiveView.HitTest(hitLocation);
                    control = (control is GUIView) ? null : control;    // Make sure we don't select the view

                    if (!(control is GUIView) && !SelectedControls.Contains(control))
                    {
                        if (Control.ModifierKeys != Keys.Control)
                            SelectedControls.Clear();

                        if(control != null)
                            SelectedControls.Add(control);

                        PrimaryControl = control;

                        mPointArea = PointArea.None;

                        // TODO : The below if-else is a copy-paste from above.  FIX IT.
                        foreach (GUIControl selectedControl in SelectedControls)
                        {
                            PointF localPoint = ViewportToControl(hitLocation, selectedControl);
                            mPointArea = selectedControl.GetPointArea(localPoint);

                            if (mPointArea == PointArea.Body)
                            {
                                Vector4 absPos = Vector4.Transform(new Vector4(control.Center.X, control.Center.Y, 0.0f, 1.0f), PrimaryControl.FullTransform);
                                mLocationOffset = new PointF(hitLocation.X - absPos.X, hitLocation.Y - absPos.Y);
                            
                                break;
                            }
                        }

                        if (SelectedControls.Count > 1 && mPointArea != PointArea.Body)
                            mPointArea = PointArea.None;
                    }
                }

                if (PrimaryControl != null)
                {
                    mControlStartPos = PrimaryControl.Location;
                    mControlStartCenter = PrimaryControl.Center;
                    mControlStartSize = PrimaryControl.Size;
                }

                RefreshRenderPanel();
            }
        }