Inheritance: MonoBehaviour
Exemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        EditorGUILayout.BeginVertical();
        DrawDefaultInspector();

        TransformMove myScript = (TransformMove)target;

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("记录"))
        {
            myScript.RecordTrans();
        }
        if (GUILayout.Button("增加"))
        {
            myScript.AddTrans();
        }
        if (GUILayout.Button("删除"))
        {
            myScript.DeleteTrans();
        }
        if (GUILayout.Button("修改"))
        {
            myScript.ModifyTrans();
        }
        if (GUILayout.Button("查看"))
        {
            myScript.ReviewTrans();
        }
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
    }
Exemplo n.º 2
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            bool changed   = false;
            int  direction = base.TurnDirection();

            if (mode == SnapModes.Shape)
            {
                // Not used the standard TidyVertices because this would only adjust the first two points.  This is also a problem with some triangles and rectangle/squares
                // but it is not so noticeable is the point which are ignored are usually outnumbered by the active points
                // Instead we will use the full shape snapping functionality in the Move transformation
                TransformMove transform = new TransformMove(0, 0);
                if (transform.Snap(this.GetPointsWhichSnapWhenMoving(), 1, page, this, Centre, Centre))
                {
                    base.ApplyTransformation(transform);
                    changed = true;
                }
            }
            else
            {
                changed = base.TidyVertices(mode, page, 1);
                if (changed)
                {
                    PlacePoints(direction);
                }
            }
            return(changed);
        }
Exemplo n.º 3
0
Arquivo: IRM.cs Projeto: stuart2w/SAW
        /// <summary>Shifts all the existing content on the given page up or down</summary>
        private void TranslateContentsVertically(Page page, float deltaY)
        {
            Transformation transform = new TransformMove(0, deltaY);

            foreach (Shape s in page.Shapes)
            {
                s.ApplyTransformation(transform);
            }
        }
Exemplo n.º 4
0
        private void Nudge(int X, int Y)
        {
            TransformMove transform = new TransformMove(X, Y);

            foreach (Scriptable s in m_Scriptables)
            {
                s.ApplyTransformation(transform);
            }
            Updated();
        }
Exemplo n.º 5
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            if (CurrentPage == null || CurrentPage.SelectedCount < 1)
            {
                return;
            }
            float step;

            // in SAW it defaults to mouse step (1/5/10); but splash always uses grid
            if (pnlView.SnapMode == Shape.SnapModes.Grid)
            {
                step = CurrentPage.Paper.ScalarSnapStep(0);
            }
            else
            {
                step = Globals.Root.CurrentConfig.MouseStep(MouseStep.CurrentStep);
            }
            TransformMove transformation = new TransformMove(X * step, Y * step);

            QuickTransform.DoTransformForVerb(transformation, transaction);
        }
Exemplo n.º 6
0
        private void PasteSplashData(Transaction transaction, EditableView pnlView)
        {
            DataObject data = (DataObject)Clipboard.GetDataObject();

            byte[] buffer = (byte[])data.GetData("Splash data", false);
            // will be nothing if deserialisation failed
            if (buffer == null)
            {
                Debug.Fail("Deserialisation failed");
                return;
            }
            using (MemoryStream stream = new MemoryStream(buffer, false))
                using (DataReader reader = new DataReader(stream, FileMarkers.ShapeList))
                {
                    List <Datum> list = reader.ReadDataList();
                    // cannot insert objects directly as that would mean pasting twice inserted 2 objects with same ID
                    Mapping    hashIDChanges  = new Mapping();
                    DatumList  newList        = new DatumList();
                    RectangleF bounds         = RectangleF.Empty;     // work out existing bounds of list
                    bool       includesShapes = false;
                    foreach (Datum datum in list)
                    {
                        if (datum is Shape)
                        {
                            // assumed that all shapes need to be created into page
                            Shape create = (Shape)datum.Clone(hashIDChanges);
                            transaction.Create(create);
                            newList.Add(create);
                            Geometry.Extend(ref bounds, create.MinimalBounds);                     // minimal makes, for example, the snapping of axes better
                            includesShapes = true;
                        }
                        else if (datum is SharedBase resource)
                        {
                            // no need to clone these as they are effectively invariant
                            if (CurrentDocument.FindExistingSharedResource <Datum>(resource.ID) == null)
                            {
                                transaction.Edit(CurrentDocument);
                                CurrentDocument.AddSharedResource(resource);
                                // if ID exists in this document it is assumed to be same object
                            }
                        }
                        else if (datum is ButtonStyle buttonStyle)
                        {
                            // as Shape, but don't add to page
                            // if IsShared it is not cloned.  Means styles in multi docs will share ID, which is good as further pasting in will reuse existing style
                            // does need to be added to document share
                            ButtonStyle create;
                            if (buttonStyle.IsShared)
                            {
                                create = buttonStyle;
                                if (CurrentDocument.GetButtonStyle(create.ID) == null)
                                {
                                    CurrentDocument.AddButtonStyle(create);                             // is new to this doc - either by cloning, or
                                    transaction.Create(create);
                                }
                            }
                            else
                            {
                                create = (ButtonStyle)buttonStyle.Clone(hashIDChanges);
                                transaction.Create(create);
                            }
                            newList.Add(create);
                        }
                        else
                        {
                            Debug.Fail("Datum not processed by by Paste: " + datum.TypeByte);
                        }
                    }
                    // want to centre shapes within current area, rather than pasting at original position (which leaves them on top of each other and largely invisible)
                    IShapeContainer container = CurrentPage;
                    if (includesShapes)
                    {
                        if (CurrentPage.SelectedCount == 1 && CurrentPage.SelectedShapes.First().AsContainer != null)
                        {
                            container = CurrentPage.SelectedShapes.First().AsContainer;
                            // but in SAW don't paste automatically into an empty container - chances are it's the item which was just copied!
                            // instead paste into that container's parent
                            if (!container.Any())
                            {
                                container = (container as Shape).Container.AsParentContainer;
                            }
                        }
                        PointF target = pnlView.ViewableArea().Centre();
                        // Or use cursor position if better
                        PointF cursor = pnlView.CursorPositionLocal;
                        // Automatically selects the drawing cursor if split cursors are used
                        // or the container
                        if (((Datum)container).TypeByte == (byte)Shape.Shapes.Container)
                        {
                            target = ((Shape)container).Bounds.Centre();
                        }
                        else if (cursor.X > 0 && cursor.Y > 0 && cursor.X < pnlView.Width && cursor.Y < pnlView.Height)
                        {
                            cursor = pnlView.MouseToData(cursor.ToPoint());
                            // And also need to check the cursor is within the page.  the above just checked it was within the control (there may be some dead area displayed)
                            if (cursor.X < pnlView.ViewableArea().Width&& cursor.Y < pnlView.ViewableArea().Height)
                            {
                                target = cursor;
                            }
                        }
                        target.X -= bounds.Width / 2;
                        target.Y -= bounds.Height / 2;                 // where we want the top left to be
                        if (pnlView.SnapMode == Shape.SnapModes.Grid)
                        {
                            target = CurrentPage.Paper.SnapPoint2(target);
                        }
                        var transform = new TransformMove(target.X - bounds.X, target.Y - bounds.Y);
                        transaction.Edit((Datum)container);
                        foreach (Shape shape in newList.Values.OfType <Shape>())                // of type needed in case other stuff was mixed in with it
                        {
                            container.Contents.Add(shape);
                            shape.Parent = container;
                            shape.ApplyTransformation(transform);
                        }
                        container.FinishedModifyingContents(transaction);
                    }
                    foreach (Datum shape in newList.Values)
                    {
                        try
                        {
                            // order changed
                            shape.UpdateReferencesObjectsCreated(CurrentDocument, reader);
                            shape.UpdateReferencesIDsChanged(hashIDChanges, Globals.Root.CurrentDocument);
                        }
                        catch (Exception ex)
                        {
                            Utilities.LogSubError(ex);
                        }
                    }
                    List <Shape> newShapes = newList.Values.OfType <Shape>().ToList();
                    if (newShapes.Count > 0 && container == CurrentPage)             // don't select the shapes when pasting into a container - leaves the container selected, which allows for more pastes
                    {
                        CurrentPage.SelectOnly(newShapes);
                    }
                    pnlView.InvalidateData(CurrentPage.SelectedRefreshBoundary(), StaticView.InvalidationBuffer.All);
                }
        }
Exemplo n.º 7
0
        public void btnAdd_Click(object sender, EventArgs e)
        {
            Transaction        transaction = new Transaction();
            List <ButtonShape> buttons     = m_Page.OfType <ButtonShape>().ToList();
            PointF             pt;
            SizeF sz;

            // Button is positioned to the bottom right of the existing ones; position will actually be ignored if there is a flow
            buttons.Sort((X, Y) =>
            {
                // Sorts into an effectively reading order, but backwards.  First entry will be bottom right
                float result = -(X.Bounds.Bottom - Y.Bounds.Bottom);
                if (Math.Abs(result) < Geometry.NEGLIGIBLE)
                {
                    result = -(X.Bounds.Right - Y.Bounds.Right);
                }
                return(Math.Sign(result));
            });
            if (buttons.Any())
            {
                sz = new SizeF(buttons.Average(x => x.Bounds.Width), buttons.Average(x => x.Bounds.Height));
                pt = buttons.First().Bounds.TopRight() + new SizeF(1, 0);
                if (pt.X + sz.Width > m_Page.Bounds.Width)                 // Has gone off the end of the line, start a new line
                {
                    pt = new PointF(0, pt.Y + sz.Height + 1);
                }
                if (pt.Y + sz.Height * 0.6 > m_Page.Size.Height)                 // off the bottom - Just resets to the top left in this case
                {
                    pt = new PointF(0, -m_Page.Size.Height);
                }
            }
            else
            {
                sz = new SizeF(9, 9);
                pt = new PointF(0, -m_Page.Size.Height);
            }
            ButtonShape create = new ButtonShape();

            transaction.Create(create);
            EditableView.ClickPosition dummyPosition = new EditableView.ClickPosition(pt, m_Page, 1, Shape.SnapModes.Off, Shape.SnapModes.Off, null, EditableView.ClickPosition.Sources.Irrelevant);
            create.Start(dummyPosition);
            create.SetStyleObject(frmButton.GetStyleForNewButton(m_Page));
            dummyPosition.Exact   = dummyPosition.Exact + sz;
            dummyPosition.Snapped = dummyPosition.Exact;
            create.Complete(dummyPosition);
            create.Action = ctrActions.SelectedAction;
            switch (create.Action.Change)
            {
            case Parameters.Action_Character:
                create.Action = new CharAction(m_Key.ToString());
                break;

            case Parameters.Action_Key:
                create.Action = new KeyAction(m_eKey);
                break;

            case Parameters.Action_Text:
                if (string.IsNullOrEmpty((create.Action as TextAction)?.Text))                         // might already be specified by list
                {
                    create.Action = new TextAction(txtText.Text);
                }
                break;
            }
            SharedImage image;
            string      temp;

            ButtonShape.GetDisplayFromAction(create.Action, out temp, out image, transaction);
            create.LabelText = temp;
            if (image != null)
            {
                create.SetImage(image);
            }
            if (m_Page.IsSingleAutoSize)
            {
                IShapeContainer container = (IShapeContainer)m_Page.Shapes.First();
                transaction.Edit((Datum)container);
                container.Contents.Add(create);
                create.Parent = (IShapeParent)container;
                container.FinishedModifyingContents(transaction, null);
                if (create.Bounds.Bottom > m_Page.Bounds.Bottom)                 // Is off the bottom
                {
                    transaction.Edit(m_Page);
                    m_Page.SetSizeExcludingMargin(new SizeF(m_Page.Size.Width, pt.Y + sz.Height - m_Page.Bounds.Top));
                    ((IAutoSize)container).SetBounds(m_Page.Bounds, null);
                    Globals.OnCurrentPageSizeChanged();
                }
            }
            else
            {
                m_Page.AddNew(create, transaction);
                if (pt.Y > m_Page.Bounds.Bottom - 1)                 // Is off the bottom
                {
                    transaction.Edit(m_Page);
                    float         height = pt.Y + sz.Height + m_Page.Margin * 2 - m_Page.Bounds.Top;
                    TransformMove delta  = new TransformMove(0, -(height - m_Page.PhysicalSize.Height));                    // All existing shapes will need to be moved up by this much because the top coordinate of the page will change
                    m_Page.SetSize(new SizeF(m_Page.PhysicalSize.Width, height), m_Page.Margin);
                    foreach (Shape shp in m_Page)
                    {
                        transaction.Edit(shp);
                        shp.ApplyTransformation(delta);
                    }
                    Globals.OnCurrentPageSizeChanged();
                }
            }
            Globals.Root.StoreNewTransaction(transaction, true);
        }