예제 #1
0
            public BitmapHistoryMementoData(IrregularSurface undoImage, PdnRegion savedRegion)
            {
                if (undoImage != null && savedRegion != null)
                {
                    throw new ArgumentException("Only one of undoImage or savedRegion may be non-null");
                }

                this.UndoImage   = undoImage;
                this.SavedRegion = savedRegion;
            }
예제 #2
0
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    if (undoImage != null)
                    {
                        undoImage.Dispose();
                        undoImage = null;
                    }

                    if (savedRegion != null)
                    {
                        savedRegion.Dispose();
                        savedRegion = null;
                    }
                }

                base.Dispose(disposing);
            }
예제 #3
0
        public BitmapHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex,
                                    IrregularSurface saved, bool takeOwnershipOfSaved)
            : base(name, image)
        {
            this.historyWorkspace = historyWorkspace;
            this.layerIndex       = layerIndex;

            IrregularSurface iss;

            if (takeOwnershipOfSaved)
            {
                iss = saved;
            }
            else
            {
                iss = (IrregularSurface)saved.Clone();
            }

            BitmapHistoryMementoData data = new BitmapHistoryMementoData(iss, null);

            this.Data = data;
        }
예제 #4
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (!KeyDownShiftOnly() && !KeyDownControlOnly())
            {
                Cursor = cursorMouseUp;
            }

            if (mouseDown)
            {
                this.previewRenderer.Visible = true;

                OnMouseMove(e);

                if (savedSurfaces.Count > 0)
                {
                    PdnRegion saveMeRegion = new PdnRegion();
                    saveMeRegion.MakeEmpty();

                    foreach (PlacedSurface pi1 in savedSurfaces)
                    {
                        saveMeRegion.Union(pi1.Bounds);
                    }

                    PdnRegion simplifiedRegion = Utility.SimplifyAndInflateRegion(saveMeRegion);

                    using (IrregularSurface weDrewThis = new IrregularSurface(renderArgs.Surface, simplifiedRegion))
                    {
                        for (int i = savedSurfaces.Count - 1; i >= 0; --i)
                        {
                            PlacedSurface ps = (PlacedSurface)savedSurfaces[i];
                            ps.Draw(renderArgs.Surface);
                            ps.Dispose();
                        }

                        savedSurfaces.Clear();

                        if (hasDrawn)
                        {
                            HistoryMemento ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace,
                                                                         ActiveLayerIndex, simplifiedRegion);

                            weDrewThis.Draw(bitmapLayer.Surface);
                            HistoryStack.PushNewMemento(ha);
                        }
                    }
                }

                mouseDown    = false;
                modifierDown = 0;
            }

            if (brushRenderArgs != null)
            {
                if (brushRenderArgs.Surface != null)
                {
                    brushRenderArgs.Surface.Dispose();
                }
            }
        }
예제 #5
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (!KeyDownShiftOnly() && !KeyDownControlOnly())
            {
                Cursor = cursorMouseUp;
            }

            if (mouseDown)
            {
                this.previewRenderer.Visible = true;

                OnMouseMove(e);

                if (savedSurfaces.Count > 0)
                {
                    PdnRegion saveMeRegion = new PdnRegion();
                    saveMeRegion.MakeEmpty();

                    foreach (PlacedSurface pi1 in savedSurfaces)
                    {
                        saveMeRegion.Union(pi1.Bounds);
                    }

                    PdnRegion simplifiedRegion = Utility.SimplifyAndInflateRegion(saveMeRegion);

                    using (IrregularSurface weDrewThis = new IrregularSurface(renderArgs.Surface, simplifiedRegion))
                    {
                        for (int i = savedSurfaces.Count - 1; i >= 0; --i)
                        {
                            PlacedSurface ps = (PlacedSurface)savedSurfaces[i];
                            ps.Draw(renderArgs.Surface);
                            ps.Dispose();
                        }

                        savedSurfaces.Clear();

                        if (hasDrawn)
                        {
                            HistoryMemento ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, 
                                ActiveLayerIndex, simplifiedRegion);

                            weDrewThis.Draw(bitmapLayer.Surface);
                            HistoryStack.PushNewMemento(ha);
                        }
                    }
                }

                mouseDown = false;
                modifierDown = 0;
            }

            if (brushRenderArgs != null)
            {
                if (brushRenderArgs.Surface != null)
                {
                    brushRenderArgs.Surface.Dispose();
                }
            }
        }
예제 #6
0
 public BitmapHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace,
                             int layerIndex, IrregularSurface saved)
     : this(name, image, historyWorkspace, layerIndex, saved, false)
 {
 }
예제 #7
0
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    if (undoImage != null)
                    {
                        undoImage.Dispose();
                        undoImage = null;
                    }

                    if (savedRegion != null)
                    {
                        savedRegion.Dispose();
                        savedRegion = null;
                    }
                }

                base.Dispose(disposing);
            }
예제 #8
0
            public BitmapHistoryMementoData(IrregularSurface undoImage, PdnRegion savedRegion)
            {
                if (undoImage != null && savedRegion != null)
                {
                    throw new ArgumentException("Only one of undoImage or savedRegion may be non-null");
                }

                this.undoImage = undoImage;
                this.savedRegion = savedRegion;
            }
예제 #9
0
        public BitmapHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, int layerIndex, 
            IrregularSurface saved, bool takeOwnershipOfSaved)
            : base(name, image)
        {
            this.historyWorkspace = historyWorkspace;
            this.layerIndex = layerIndex;

            IrregularSurface iss;

            if (takeOwnershipOfSaved)
            {
                iss = saved;
            }
            else
            {
                iss = (IrregularSurface)saved.Clone();
            }

            BitmapHistoryMementoData data = new BitmapHistoryMementoData(iss, null);
            this.Data = data;
        }
예제 #10
0
 public BitmapHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace, 
     int layerIndex, IrregularSurface saved)
     : this(name, image, historyWorkspace, layerIndex, saved, false)
 {
 }
예제 #11
0
        private void SaveHistoryMemento()
        {
            pulseEnabled = false;
            RedrawText(false);

            if (saved != null)
            {
                PdnRegion hitTest = Selection.CreateRegion();
                hitTest.Intersect(saved.Region);

                if (!hitTest.IsEmpty())
                {
                    BitmapHistoryMemento bha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace,
                        ActiveLayerIndex, saved);

                    if (this.currentHA == null)
                    {
                        HistoryStack.PushNewMemento(bha);
                    }
                    else
                    {
                        this.currentHA.PushNewAction(bha);
                        this.currentHA = null;
                    }
                }

                hitTest.Dispose();
                saved.Dispose();
                saved = null;
            }
        }
예제 #12
0
        protected override void OnDeactivate()
        {
            PdnBaseForm.UnregisterFormHotKey(Keys.Back, OnBackspaceTyped);

            base.OnDeactivate();

            switch (mode)
            {
                case EditingMode.Editing:
                    SaveHistoryMemento();
                    break;

                case EditingMode.EmptyEdit:
                    RedrawText(false);
                    break;

                case EditingMode.NotEditing:
                    break;

                default:
                    throw new InvalidEnumArgumentException("Invalid Editing Mode");
            }

            if (ra != null)
            {
                ra.Dispose();
                ra = null;
            }

            if (saved != null)
            {
                saved.Dispose();
                saved = null;
            }

            AppEnvironment.BrushInfoChanged -= brushChangedDelegate;
            AppEnvironment.FontInfoChanged -= fontChangedDelegate;
            AppEnvironment.FontSmoothingChanged -= fontSmoothingChangedDelegate;
            AppEnvironment.TextAlignmentChanged -= alignmentChangedDelegate;
            AppEnvironment.AntiAliasingChanged -= antiAliasChangedDelegate;
            AppEnvironment.PrimaryColorChanged -= foreColorChangedDelegate;
            AppEnvironment.SecondaryColorChanged -= new EventHandler(BackColorChangedHandler);
            AppEnvironment.AlphaBlendingChanged -= new EventHandler(AlphaBlendingChangedHandler);

            StopEditing();
            this.threadPool = null;

            this.RendererList.Remove(this.moveNub);
            this.moveNub.Dispose();
            this.moveNub = null;

            if (this.textToolCursor != null)
            {
                this.textToolCursor.Dispose();
                this.textToolCursor = null;
            }
        }
예제 #13
0
        /// <summary>
        /// Redraws the Text on the screen
        /// </summary>
        /// <remarks>
        /// assumes that the <b>font</b> and the <b>alignment</b> are already set
        /// </remarks>
        /// <param name="cursorOn"></param>
        private void RedrawText(bool cursorOn)
        {
            if (this.ignoreRedraw > 0)
            {
                return;
            }

            if (saved != null)
            {
                saved.Draw(ra.Surface);
                ActiveLayer.Invalidate(saved.Region);
                saved.Dispose();
                saved = null;
            }

            // Save the Space behind the lines
            Rectangle[] rects = new Rectangle[lines.Count + 1];
            Point[] localUls = new Point[lines.Count];

            // All Lines
            bool recalcSizes = false;

            if (this.sizes == null)
            {
                recalcSizes = true;
                this.sizes = new Size[lines.Count + 1];
            }

            if (recalcSizes)
            {
                for (int i = 0; i < lines.Count; ++i)
                {
                    this.threadPool.QueueUserWorkItem(new System.Threading.WaitCallback(this.MeasureText),
                        BoxedConstants.GetInt32(i));
                }

                this.threadPool.Drain();
            }

            for (int i = 0; i < lines.Count; ++i)
            {
                Point upperLeft = GetUpperLeft(sizes[i], i);
                localUls[i] = upperLeft;
                Rectangle rect = new Rectangle(upperLeft, sizes[i]);
                rects[i] = rect;
            }

            // The Cursor Line
            string cursorLine = ((string)lines[linePos]).Substring(0, textPos);
            Size cursorLineSize;
            Point cursorUL;
            Rectangle cursorRect;
            bool emptyCursorLineFlag;

            if (cursorLine.Length == 0)
            {
                emptyCursorLineFlag = true;
                Size fullLineSize = sizes[linePos];
                cursorLineSize = new Size(2, (int)(Math.Ceiling(font.GetHeight())));
                cursorUL = GetUpperLeft(fullLineSize, linePos);
                cursorRect = new Rectangle(cursorUL, cursorLineSize);
            }
            else if (cursorLine.Length == ((string)lines[linePos]).Length)
            {
                emptyCursorLineFlag = false;
                cursorLineSize = sizes[linePos];
                cursorUL = localUls[linePos];
                cursorRect = new Rectangle(cursorUL, cursorLineSize);
            }
            else
            {
                emptyCursorLineFlag = false;
                cursorLineSize = StringSize(cursorLine);
                cursorUL = localUls[linePos];
                cursorRect = new Rectangle(cursorUL, cursorLineSize);
            }

            rects[lines.Count] = cursorRect;

            // Account for overhang on italic or fancy fonts
            int offset = (int)this.font.Height;
            for (int i = 0; i < rects.Length; ++i)
            {
                rects[i].X -= offset;
                rects[i].Width += 2 * offset;
            }

            // Set the saved region
            using (PdnRegion reg = Utility.RectanglesToRegion(Utility.InflateRectangles(rects, 3)))
            {
                saved = new IrregularSurface(ra.Surface, reg);
            }

            // Draw the Lines
            this.uls = localUls;

            for (int i = 0; i < lines.Count; i++)
            {
                threadPool.QueueUserWorkItem(new System.Threading.WaitCallback(this.RenderText), BoxedConstants.GetInt32(i));
            }

            threadPool.Drain();

            // Draw the Cursor
            if (cursorOn)
            {
                using (Pen cursorPen = new Pen(Color.FromArgb(255, AppEnvironment.PrimaryColor.ToColor()), 2))
                {
                    if (emptyCursorLineFlag)
                    {
                        ra.Graphics.FillRectangle(cursorPen.Brush, cursorRect);
                    }
                    else
                    {
                        ra.Graphics.DrawLine(cursorPen, new Point(cursorRect.Right, cursorRect.Top), new Point(cursorRect.Right, cursorRect.Bottom));
                    }
                }
            }

            PlaceMoveNub();
            UpdateStatusText();
            ActiveLayer.Invalidate(saved.Region);
            Update();
        }