private IrregularSurface(IrregularSurface cloneMe)
        {
            this.placedSurfaces = new ArrayList(cloneMe.placedSurfaces.Count);

            foreach (PlacedSurface ps in cloneMe.placedSurfaces)
            {
                this.placedSurfaces.Add(ps.Clone());
            }

            this.region = (PdnRegion)cloneMe.Region.Clone();
        }
        private IrregularSurface(IrregularSurface cloneMe)
        {
            this.placedSurfaces = new ArrayList(cloneMe.placedSurfaces.Count);

            foreach (PlacedSurface ps in cloneMe.placedSurfaces)
            {
                this.placedSurfaces.Add(ps.Clone());
            }

            this.region = (PdnRegion)cloneMe.Region.Clone();
        }
Example #3
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;
            }
        }
Example #4
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();
        }
Example #5
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;
            }
        }