public void repaint()
 {
     try
     {
         previewObject.UpdateObjCache();
     }
     catch (Exception)
     {
     }
     editZone.Invalidate(true);
     previewBox.Invalidate(true);
     if (mustRepaintObjects != null)
     {
         mustRepaintObjects();
     }
 }
Ejemplo n.º 2
0
        public override void MouseDrag(int x, int y)
        {
            //Resize the new object that was created by right-clicking.
            if (CreateObj && newObj != null)
            {
                Rectangle r = newObj.getRectangle();
                x = Math.Max(0, x / 16);
                y = Math.Max(0, y / 16);
                if (x == lx && y == ly)
                {
                    return;
                }
                lx            = x;
                ly            = y;
                newObj.X      = Math.Min(lx, dx);
                newObj.Y      = Math.Min(ly, dy);
                newObj.Width  = Math.Abs(lx - dx) + 1;
                newObj.Height = Math.Abs(ly - dy) + 1;
                newObj.UpdateObjCache();
                r = Rectangle.Union(r, newObj.getRectangle());
                Level.repaintTilemap(r.X, r.Y, r.Width, r.Height);
                EdControl.repaint();
                return;
            }

            if (lx == x && ly == y) // don't clone objects if there is no visible movement
            {
                return;
            }

            if (SelectMode)
            {
                findSelectedObjects(x, y, dx, dy, false, true);
                lx = x;
                ly = y;
            }
            else
            {
                UpdateSelectionBounds();
                if (CloneMode)
                {
                    List <LevelItem> newObjects = CloneList(SelectedObjects);
                    EdControl.UndoManager.Do(new AddLvlItemAction(newObjects));

                    CloneMode     = false;
                    mouseAct.vert = ResizeType.ResizeNone;
                    mouseAct.hor  = ResizeType.ResizeNone;

                    SelectedObjects = newObjects;
                }

                if (mouseAct.hor == ResizeType.ResizeNone && mouseAct.vert == ResizeType.ResizeNone)
                {
                    int xDelta = x - lx;
                    int yDelta = y - ly;
                    if (xDelta < -minBoundX)
                    {
                        xDelta = -minBoundX;
                    }
                    if (yDelta < -minBoundY)
                    {
                        yDelta = -minBoundY;
                    }
                    xDelta &= ~(selectionSnap - 1);
                    yDelta &= ~(selectionSnap - 1);
                    if (xDelta == 0 && yDelta == 0)
                    {
                        return;
                    }
                    minBoundX += xDelta;
                    minBoundY += yDelta;
                    EdControl.UndoManager.Do(new MoveResizeLvlItemAction(SelectedObjects, xDelta, yDelta));
                    lx += xDelta;
                    ly += yDelta;

                    //Force align =D
                    //Only done when ONE object because you'll probably NOT want multiple objects
                    //moving relative to each other.
                    if (SelectedObjects.Count == 1)
                    {
                        foreach (LevelItem o in SelectedObjects)
                        {
                            if (o.rx % selectionSnap != 0 || o.ry % selectionSnap != 0 || o.rwidth % selectionSnap != 0 || o.rheight % selectionSnap != 0)
                            {
                                EdControl.UndoManager.Do(new MoveResizeLvlItemAction(UndoManager.ObjToList(o), -o.rx % selectionSnap, -o.ry % selectionSnap, -o.rwidth % selectionSnap, -o.rheight % selectionSnap));
                            }
                        }
                    }
                }
                else
                {
                    int xDelta = x - lx;
                    int yDelta = y - ly;

                    int xMoveDelta   = 0;
                    int xResizeDelta = 0;
                    int yMoveDelta   = 0;
                    int yResizeDelta = 0;

                    xDelta &= ~(selectionSnap - 1);
                    yDelta &= ~(selectionSnap - 1);
                    if (xDelta == 0 && yDelta == 0)
                    {
                        return;
                    }

                    if (mouseAct.hor == ResizeType.ResizeBegin)
                    {
                        if (-xDelta <= -minSizeX + selectionSnap)
                        {
                            xDelta = -(-minSizeX + selectionSnap);
                        }
                        if (xDelta < -minBoundX)
                        {
                            xDelta = -minBoundX;
                        }
                        xMoveDelta   = xDelta;
                        xResizeDelta = -xDelta;
                    }
                    if (mouseAct.vert == ResizeType.ResizeBegin)
                    {
                        if (-yDelta <= -minSizeY + selectionSnap)
                        {
                            yDelta = -(-minSizeY + selectionSnap);
                        }
                        if (yDelta < -minBoundY)
                        {
                            yDelta = -minBoundY;
                        }
                        yMoveDelta   = yDelta;
                        yResizeDelta = -yDelta;
                    }
                    if (mouseAct.hor == ResizeType.ResizeEnd)
                    {
                        if (xDelta <= -minSizeX + selectionSnap)
                        {
                            xDelta = -minSizeX + selectionSnap;
                        }
                        xResizeDelta = xDelta;
                    }
                    if (mouseAct.vert == ResizeType.ResizeEnd)
                    {
                        if (yDelta <= -minSizeY + selectionSnap)
                        {
                            yDelta = -minSizeY + selectionSnap;
                        }
                        yResizeDelta = yDelta;
                    }
                    if (xMoveDelta == 0 && yMoveDelta == 0 && xResizeDelta == 0 && yResizeDelta == 0)
                    {
                        return;
                    }

                    minBoundX += xMoveDelta;
                    minBoundY += yMoveDelta;
                    minSizeX  += xResizeDelta;
                    minSizeY  += yResizeDelta;
                    EdControl.UndoManager.Do(new MoveResizeLvlItemAction(SelectedObjects, xMoveDelta, yMoveDelta, xResizeDelta, yResizeDelta));
                    lx += xDelta;
                    ly += yDelta;
                }
            }
        }