예제 #1
0
 public Ruler() : base(FactorySource.PerThread)
 {
     this.cursorBrush         = new SolidColorBrush();
     this.lineBrush           = new SolidColorBrush();
     this.textBrush           = new SolidColorBrush();
     this.unitsBoxBrush       = new SolidColorBrush();
     this.measurementUnit     = PaintDotNet.MeasurementUnit.Inch;
     this.dpu                 = 96.0;
     this.scaleFactor         = PaintDotNet.ScaleFactor.OneToOne;
     base.UseHwndRenderTarget = true;
     this.tickLabelFontLazy   = new Lazy <SizedFontProperties>(delegate {
         using (IGdiFontMap map = DirectWriteFactory.Instance.GetGdiFontMapRef(true))
         {
             FontProperties fontProperties;
             try
             {
                 fontProperties = map.GetFontProperties(tickLabelFontNames);
             }
             catch (NoFontException)
             {
                 fontProperties = new FontProperties(string.Empty, string.Empty, FontWeight.Normal, FontStretch.Normal, PaintDotNet.DirectWrite.FontStyle.Normal, TextDecorations.None);
             }
             return(new SizedFontProperties(fontProperties, UIUtil.ScaleHeight((float)10.66667f)));
         }
     }, LazyThreadSafetyMode.PublicationOnly);
     using (ISystemFonts fonts = new PaintDotNet.DirectWrite.SystemFonts())
     {
         this.unitsBoxFont = fonts.Menu;
     }
 }
예제 #2
0
        public SurfaceBox()
        {
            InitializeComponent();
            this.scaleFactor = ScaleFactor.OneToOne;

            this.rendererList = new SurfaceBoxRendererList(this.Size, this.Size);
            this.rendererList.Invalidated += new InvalidateEventHandler(Renderers_Invalidated);
            this.baseRenderer = new SurfaceBoxBaseRenderer(this.rendererList, null);
            this.rendererList.Add(this.baseRenderer, false);
        }
예제 #3
0
 private void OnScaleRatioChanged(object sender, ValueChangedEventArgs <double> e)
 {
     PaintDotNet.ScaleFactor factor = PaintDotNet.ScaleFactor.FromRatio(this.scrollableCanvasControl.CanvasView.ScaleRatio);
     this.topRuler.ScaleFactor  = factor;
     this.leftRuler.ScaleFactor = factor;
     this.UpdateRulerOffsets();
     this.OnScaleFactorChanged();
     this.OnScroll(null);
     this.scrollableCanvasControl.QueueUpdate();
 }
예제 #4
0
 public static ScaleFactor UseIfValid(int numerator, int denominator, ScaleFactor lastResort)
 {
     if (numerator <= 0 || denominator <= 0)
     {
         return lastResort;
     }
     else
     {
         return new ScaleFactor(numerator, denominator);
     }
 }
예제 #5
0
        protected virtual void ZoomToWithCentering(PaintDotNet.ScaleFactor newScaleFactor, Func <PointDouble> anchorPtCanvasFn)
        {
            PaintDotNet.ScaleFactor scaleFactor = this.ScaleFactor;
            PointDouble             num         = anchorPtCanvasFn();

            this.ScaleFactor = newScaleFactor;
            VectorDouble num3 = anchorPtCanvasFn() - num;

            PaintDotNet.Canvas.CanvasView canvasView = this.CanvasView;
            canvasView.ViewportCanvasOffset -= num3;
        }
예제 #6
0
 public PdnStatusBar(AppWorkspace appWorkspace)
 {
     this.appWorkspace = appWorkspace;
     this.PopulateLocalizedUnitsArray();
     this.zoomToWindowImage   = UIUtil.GetScaledImage(PdnResources.GetImageResource("Icons.MenuViewZoomToWindowIcon.png").Reference);
     this.zoomActualSizeImage = UIUtil.GetScaledImage(PdnResources.GetImageResource("Icons.MenuViewActualSizeIcon.png").Reference);
     this.windowText          = EnumLocalizer.GetLocalizedEnumValue(typeof(PaintDotNet.ZoomBasis), PaintDotNet.ZoomBasis.FitToWindow).LocalizedName;
     this.percentageFormat    = PdnResources.GetString("ZoomConfigWidget.Percentage.Format");
     this.InitializeComponent();
     this.imageInfoStatusLabel.Image     = UIUtil.GetScaledImage(PdnResources.GetImageResource("Icons.ImageSizeIcon.png").Reference);
     this.cursorInfoStatusLabel.Image    = UIUtil.GetScaledImage(PdnResources.GetImageResource("Icons.CursorXYIcon.png").Reference);
     this.zoomToWindowToggleButton.Image = this.zoomToWindowImage;
     this.zoomOutButton.Image            = UIUtil.GetScaledImage(PdnResources.GetImageResource("Icons.MenuViewZoomOutIcon.png").Reference);
     this.zoomInButton.Image             = UIUtil.GetScaledImage(PdnResources.GetImageResource("Icons.MenuViewZoomInIcon.png").Reference);
     this.zoomOutButton.ToolTipText      = PdnResources.GetString("ZoomConfigWidget.ZoomOutButton.ToolTipText");
     this.zoomInButton.ToolTipText       = PdnResources.GetString("ZoomConfigWidget.ZoomInButton.ToolTipText");
     this.zoomBasis   = PaintDotNet.ZoomBasis.FitToWindow;
     this.scaleFactor = PaintDotNet.ScaleFactor.OneToOne;
     this.OnZoomBasisChanged();
 }
예제 #7
0
        protected void ZoomViaCurrentMousePosition(PaintDotNet.ScaleFactor newScaleFactor)
        {
            PointDouble center;
            PointInt32  pt = Control.MousePosition.ToPointInt32();
            RectDouble  visibleCanvasBounds = this.CanvasView.GetVisibleCanvasBounds();
            RectDouble  num3 = this.RectangleToScreen(this.DocumentToClient(visibleCanvasBounds));

            if (num3.Contains(pt))
            {
                double x = DoubleUtil.Clamp((double)pt.X, num3.Left, num3.Right);
                center = new PointDouble(x, DoubleUtil.Clamp((double)pt.Y, num3.Top, num3.Bottom));
            }
            else
            {
                center = num3.Center;
            }
            PointDouble clientPt         = this.PointToClient(center);
            PointDouble anchorPtViewport = this.CanvasView.ConvertCanvasToViewport(this.ClientToDocument(clientPt));

            this.ZoomToWithCentering(newScaleFactor, () => this.CanvasView.ConvertViewportToCanvas(anchorPtViewport));
        }
예제 #8
0
        protected override void OnDocumentChanging(Document newDocument)
        {
            base.OnDocumentChanging(newDocument);

            this.savedZb = this.ZoomBasis;
            this.savedSf = ScaleFactor;

            if (this.ActiveLayer != null)
            {
                this.savedAli = ActiveLayerIndex;
            }
            else
            {
                this.savedAli = -1;
            }

            if (newDocument != null)
            {
                UpdateExifTags(newDocument);
            }

            if (this.Document != null)
            {
                foreach (Layer layer in this.Document.Layers)
                {
                    layer.PropertyChanging -= LayerPropertyChangingHandler;
                    layer.PropertyChanged -= LayerPropertyChangedHandler;
                }

                this.Document.Layers.RemovingAt -= LayerRemovingHandler;
                this.Document.Layers.RemovedAt -= LayerRemovedHandler;
                this.Document.Layers.Inserted -= LayerInsertedHandler;
            }
            
            this.staticToolData.Clear();

            PushNullTool(); // matching Pop is in OnDocumetChanged()
            ActiveLayer = null;

            if (this.scratchSurface != null)
            {
                if (this.isScratchSurfaceBorrowed)
                {
                    throw new InvalidOperationException("scratchSurface is currently borrowed: " + this.borrowScratchSurfaceReason);
                }

                if (newDocument == null || newDocument.Size != this.scratchSurface.Size)
                {
                    this.scratchSurface.Dispose();
                    this.scratchSurface = null;
                }
            }

            if (!Selection.IsEmpty)
            {
                Selection.Reset();
            }
        }
예제 #9
0
 public static ScaleFactor Max(ScaleFactor lhs, ScaleFactor rhs)
 {
     if (lhs > rhs)
     {
         return lhs;
     }
     else
     {
         return lhs;
     }
 }
예제 #10
0
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            // This code fixes the size of the surfaceBox as necessary to 
            // maintain the aspect ratio of the surface. Keeping the mouse
            // within 32767 is delegated to the new overflow-checking code
            // in Tool.cs.

            Size mySize = this.Size;
            if (this.Width == MaxSideLength && surface != null)
            { 
                // Windows forms probably clamped this control's width, so we have to fix the height.
                mySize.Height = (int)(((long)(MaxSideLength + 1) * (long)surface.Height) / (long)surface.Width);
            }
            else if (mySize.Width == 0)
            {
                mySize.Width = 1;
            }

            if (this.Width == MaxSideLength && surface != null)
            { 
                // Windows forms probably clamped this control's height, so we have to fix the width.
                mySize.Width = (int)(((long)(MaxSideLength + 1) * (long)surface.Width) / (long)surface.Height);
            }
            else if (mySize.Height == 0) 
            {
                mySize.Height = 1;
            }

            if (mySize != this.Size) 
            {
                this.Size = mySize;
            }
           
            if (surface == null)
            {
                this.scaleFactor = ScaleFactor.OneToOne;
            }
            else
            {
                ScaleFactor newSF = ScaleFactor.Max(this.Width, surface.Width,
                                                    this.Height, surface.Height,
                                                    ScaleFactor.OneToOne);

                this.scaleFactor = newSF;
            }

            this.rendererList.DestinationSize = this.Size;
        }
예제 #11
0
        public void FitToSize(Size fit)
        {
            ScaleFactor newSF = ScaleFactor.Min(fit.Width, surface.Width,
                                                fit.Height, surface.Height,
                                                ScaleFactor.MinValue);

            this.scaleFactor = newSF;
            this.Size = this.scaleFactor.ScaleSize(surface.Size);
        }
예제 #12
0
        private void DrawRuler(PaintEventArgs e, bool highlighted)
        {
            Pen          pen;
            Brush        cursorBrush;
            Brush        textBrush;
            StringFormat textFormat = new StringFormat();
            int          maxPixel;
            Color        cursorColor;

            if (highlighted)
            {
                e.Graphics.Clear(SystemColors.Highlight);
                pen         = SystemPens.HighlightText;
                textBrush   = SystemBrushes.HighlightText;
                cursorColor = SystemColors.Window;
            }
            else
            {
                e.Graphics.Clear(SystemColors.Window);
                pen         = SystemPens.WindowText;
                textBrush   = SystemBrushes.WindowText;
                cursorColor = SystemColors.Highlight;
            }

            cursorColor = Color.FromArgb(128, cursorColor);
            cursorBrush = new SolidBrush(cursorColor);

            if (orientation == Orientation.Horizontal)
            {
                maxPixel                 = ScaleFactor.UnscaleScalar(ClientRectangle.Width);
                textFormat.Alignment     = StringAlignment.Near;
                textFormat.LineAlignment = StringAlignment.Far;
            }
            else // if (orientation == Orientation.Vertical)
            {
                maxPixel                 = ScaleFactor.UnscaleScalar(ClientRectangle.Height);
                textFormat.Alignment     = StringAlignment.Near;
                textFormat.LineAlignment = StringAlignment.Near;
                textFormat.FormatFlags  |= StringFormatFlags.DirectionVertical;
            }

            float majorSkip           = 1;
            int   majorSkipPower      = 0;
            float majorDivisionLength = (float)dpu;
            float majorDivisionPixels = (float)ScaleFactor.ScaleScalar(majorDivisionLength);

            int[] subdivs      = GetSubdivs(measurementUnit);
            float offsetPixels = ScaleFactor.ScaleScalar((float)offset);
            int   startMajor   = (int)(offset / majorDivisionLength) - 1;
            int   endMajor     = (int)((offset + maxPixel) / majorDivisionLength) + 1;

            if (orientation == Orientation.Horizontal)
            {
                // draw Value
                if (!highlighted)
                {
                    PointF pt   = scaleFactor.ScalePointJustX(new PointF(ClientRectangle.Left + Value - Offset, ClientRectangle.Top));
                    SizeF  size = new SizeF(Math.Max(1, scaleFactor.ScaleScalar(1.0f)), ClientRectangle.Height);

                    pt.X -= 0.5f;

                    CompositingMode oldCM = e.Graphics.CompositingMode;
                    e.Graphics.CompositingMode = CompositingMode.SourceOver;
                    e.Graphics.FillRectangle(cursorBrush, new RectangleF(pt, size));
                    e.Graphics.CompositingMode = oldCM;
                }

                // draw border
                e.Graphics.DrawLine(SystemPens.WindowText, new Point(ClientRectangle.Left, ClientRectangle.Bottom - 1),
                                    new Point(ClientRectangle.Right - 1, ClientRectangle.Bottom - 1));
            }
            else if (orientation == Orientation.Vertical)
            {
                // draw Value
                if (!highlighted)
                {
                    PointF pt   = scaleFactor.ScalePointJustY(new PointF(ClientRectangle.Left, ClientRectangle.Top + Value - Offset));
                    SizeF  size = new SizeF(ClientRectangle.Width, Math.Max(1, scaleFactor.ScaleScalar(1.0f)));

                    pt.Y -= 0.5f;

                    CompositingMode oldCM = e.Graphics.CompositingMode;
                    e.Graphics.CompositingMode = CompositingMode.SourceOver;
                    e.Graphics.FillRectangle(cursorBrush, new RectangleF(pt, size));
                    e.Graphics.CompositingMode = oldCM;
                }

                // draw border
                e.Graphics.DrawLine(SystemPens.WindowText, new Point(ClientRectangle.Right - 1, ClientRectangle.Top),
                                    new Point(ClientRectangle.Right - 1, ClientRectangle.Bottom - 1));
            }

            while (majorDivisionPixels * majorSkip < 60)
            {
                majorSkip *= majorDivisors[majorSkipPower % majorDivisors.Length];
                ++majorSkipPower;
            }

            startMajor = (int)(majorSkip * Math.Floor(startMajor / (double)majorSkip));

            for (int major = startMajor; major <= endMajor; major += (int)majorSkip)
            {
                float  majorMarkPos = (major * majorDivisionPixels) - offsetPixels;
                string majorText    = (major).ToString();

                if (orientation == Orientation.Horizontal)
                {
                    SubdivideX(e.Graphics, pen, ClientRectangle.Left + majorMarkPos, majorDivisionPixels * majorSkip, -majorSkipPower, ClientRectangle.Top, ClientRectangle.Height, subdivs);
                    e.Graphics.DrawString(majorText, Font, textBrush, new PointF(ClientRectangle.Left + majorMarkPos, ClientRectangle.Bottom), textFormat);
                }
                else // if (orientation == Orientation.Vertical)
                {
                    SubdivideY(e.Graphics, pen, ClientRectangle.Top + majorMarkPos, majorDivisionPixels * majorSkip, -majorSkipPower, ClientRectangle.Left, ClientRectangle.Width, subdivs);
                    e.Graphics.DrawString(majorText, Font, textBrush, new PointF(ClientRectangle.Left, ClientRectangle.Top + majorMarkPos), textFormat);
                }
            }

            textFormat.Dispose();
        }
예제 #13
0
 public static RectDouble Unscale(this ScaleFactor sf, RectInt32 rect) =>
 new RectDouble(sf.Unscale((double)rect.X), sf.Unscale((double)rect.Y), sf.Unscale((double)rect.Width), sf.Unscale((double)rect.Height));
예제 #14
0
 public static SizeDouble Scale(this ScaleFactor sf, SizeDouble size) =>
 new SizeDouble(sf.Scale(size.Width), sf.Scale(size.Height));
예제 #15
0
 public static PointDouble Unscale(this ScaleFactor sf, PointInt32 p) =>
 new PointDouble(sf.Unscale((double)p.X), sf.Unscale((double)p.Y));
예제 #16
0
 public void ZoomTo(PaintDotNet.ScaleFactor newScaleFactor)
 {
     this.ZoomViaCurrentMousePosition(newScaleFactor);
 }
예제 #17
0
        private void ZoomComboBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            try
            {
                int val = 1;
                e.Cancel = false;

                if (zoomComboBox.Text == this.windowText)
                {
                    ZoomBasis = ZoomBasis.FitToWindow;
                }
                else
                {
                    try
                    {
                        string text = zoomComboBox.Text;

                        if (text.Length == 0)
                        {
                            e.Cancel = true;
                        }
                        else
                        {
                            if (text[text.Length - 1] == '%')
                            {
                                text = text.Substring(0, text.Length - 1);
                            }
                            else if (text[0] == '%')
                            {
                                text = text.Substring(1);
                            }

                            val = (int)Math.Round(double.Parse(text));
                            ZoomBasis = ZoomBasis.ScaleFactor;
                        }
                    }

                    catch (FormatException)
                    {
                        e.Cancel = true;
                    }

                    catch (OverflowException)
                    {
                        e.Cancel = true;
                    }

                    if (e.Cancel)
                    {
                        this.zoomComboBox.BackColor = Color.Red;
                        this.zoomComboBox.ToolTipText = PdnResources.GetString("ZoomConfigWidget.Error.InvalidNumber");
                    }
                    else
                    {
                        if (val < 1)
                        {
                            e.Cancel = true;
                            this.zoomComboBox.BackColor = Color.Red;
                            this.zoomComboBox.ToolTipText = PdnResources.GetString("ZoomConfigWidget.Error.TooSmall");
                        }
                        else if (val > 3200)
                        {
                            e.Cancel = true;
                            this.zoomComboBox.BackColor = Color.Red;
                            this.zoomComboBox.ToolTipText = PdnResources.GetString("ZoomConfigWidget.Error.TooLarge");
                        }
                        else
                        {
                            // Clear the error
                            e.Cancel = false;
                            this.zoomComboBox.ToolTipText = string.Empty;
                            this.zoomComboBox.BackColor = SystemColors.Window;
                            ScaleFactor = new ScaleFactor(val, 100);
                            SuspendEvents();
                            ZoomBasis = ZoomBasis.ScaleFactor;
                            ResumeEvents();
                        }
                    }
                }
            }

            catch (FormatException)
            {
            }
        }
예제 #18
0
 public static double Unscale(this ScaleFactor sf, double x) =>
 ((x * sf.Denominator) / ((double)sf.Numerator));
예제 #19
0
 private void ComputeScaleFactor()
 {
     scaleFactor = new ScaleFactor(this.DestinationSize.Width, this.SourceSize.Width);
 }
예제 #20
0
 public void SetMinDocScaleFactor(PaintDotNet.ScaleFactor sf)
 {
     ((SliderImpl)base.Control).SetMinDocScaleFactor(sf);
 }
예제 #21
0
 public static ScaleFactor Min(int n1, int d1, int n2, int d2, ScaleFactor lastResort)
 {
     ScaleFactor a = UseIfValid(n1, d1, lastResort);
     ScaleFactor b = UseIfValid(n2, d2, lastResort);
     return ScaleFactor.Min(a, b);
 }
예제 #22
0
 public static VectorDouble Unscale(this ScaleFactor sf, VectorDouble vec) =>
 new VectorDouble(sf.Unscale(vec.X), sf.Unscale(vec.Y));
예제 #23
0
 public static ScaleFactor Min(ScaleFactor lhs, ScaleFactor rhs)
 {
     if (lhs < rhs)
     {
         return lhs;
     }
     else
     {
         return rhs;
     }
 }
예제 #24
0
 public static SizeDouble Unscale(this ScaleFactor sf, SizeInt32 size) =>
 new SizeDouble(sf.Unscale((double)size.Width), sf.Unscale((double)size.Height));
예제 #25
0
        public ViewConfigStrip()
        {
            this.SuspendLayout();
            InitializeComponent();

            this.windowText = EnumLocalizer.EnumValueToLocalizedName(typeof(ZoomBasis), ZoomBasis.FitToWindow);
            this.percentageFormat = PdnResources.GetString("ZoomConfigWidget.Percentage.Format");

            double[] zoomValues = ScaleFactor.PresetValues;

            this.zoomComboBox.ComboBox.SuspendLayout();

            string percent100 = null; // ScaleFactor.PresetValues guarantees that 1.0, or "100%" is in the list, but the compiler can't be shown this so we must assign a value here
            for (int i = zoomValues.Length - 1; i >= 0; --i)
            {
                string zoomValueString = (zoomValues[i] * 100.0).ToString();
                string zoomItemString = string.Format(this.percentageFormat, zoomValueString);

                if (zoomValues[i] == 1.0)
                {
                    percent100 = zoomItemString;
                }

                this.zoomComboBox.Items.Add(zoomItemString);
            }

            this.zoomComboBox.Items.Add(this.windowText);
            this.zoomComboBox.ComboBox.ResumeLayout(false);
            this.zoomComboBox.Size = new Size(UI.ScaleWidth(this.zoomComboBox.Width), zoomComboBox.Height);

            this.unitsLabel.Text = PdnResources.GetString("WorkspaceOptionsConfigWidget.UnitsLabel.Text");

            this.zoomComboBox.Text = percent100;
            this.ScaleFactor = ScaleFactor.OneToOne;

            this.zoomOutButton.Image = PdnResources.GetImageResource("Icons.MenuViewZoomOutIcon.png").Reference;
            this.zoomInButton.Image = PdnResources.GetImageResource("Icons.MenuViewZoomInIcon.png").Reference;
            this.gridButton.Image = PdnResources.GetImageResource("Icons.MenuViewGridIcon.png").Reference;
            this.rulersButton.Image = PdnResources.GetImageResource("Icons.MenuViewRulersIcon.png").Reference;

            this.zoomOutButton.ToolTipText = PdnResources.GetString("ZoomConfigWidget.ZoomOutButton.ToolTipText");
            this.zoomInButton.ToolTipText = PdnResources.GetString("ZoomConfigWidget.ZoomInButton.ToolTipText");
            this.gridButton.ToolTipText = PdnResources.GetString("WorkspaceOptionsConfigWidget.DrawGridToggleButton.ToolTipText");
            this.rulersButton.ToolTipText = PdnResources.GetString("WorkspaceOptionsConfigWidget.RulersToggleButton.ToolTipText");

            this.unitsComboBox.Size = new Size(UI.ScaleWidth(this.unitsComboBox.Width), unitsComboBox.Height);

            this.zoomBasis = ZoomBasis.ScaleFactor;
            ScaleFactor = ScaleFactor.OneToOne;

            this.ResumeLayout(false);
        }
예제 #26
0
 public static PointDouble Scale(this ScaleFactor sf, PointDouble p) =>
 new PointDouble(sf.Scale(p.X), sf.Scale(p.Y));
 private void ComputeScaleFactor()
 {
     scaleFactor = new ScaleFactor(this.DestinationSize.Width, this.SourceSize.Width);
 }
예제 #28
0
 public static RectDouble Scale(this ScaleFactor sf, RectDouble rect) =>
 new RectDouble(sf.Scale(rect.X), sf.Scale(rect.Y), sf.Scale(rect.Width), sf.Scale(rect.Height));