Example #1
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);
        }
Example #2
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);
        }
Example #3
0
        public void ZoomToRectangle(Rectangle selectionBounds)
        {
            PointF selectionCenter = new PointF((selectionBounds.Left + selectionBounds.Right + 1) / 2,
                (selectionBounds.Top + selectionBounds.Bottom + 1) / 2);

            PointF cornerPosition;

            ScaleFactor zoom = ScaleFactor.Min(ClientRectangleMin.Width, selectionBounds.Width + 2,
                                               ClientRectangleMin.Height, selectionBounds.Height + 2,
                                               ScaleFactor.MinValue);

            // Zoom out to fit the image
            ZoomBasis = ZoomBasis.ScaleFactor;
            ScaleFactor = zoom;

            cornerPosition = new PointF(selectionCenter.X - (VisibleDocumentRectangleF.Width / 2),
                selectionCenter.Y - (VisibleDocumentRectangleF.Height / 2));

            DocumentScrollPositionF = cornerPosition;
        }
Example #4
0
        public DocumentWorkspace()
        {
            this.activeLayer = null;
            this.history = new HistoryStack(this);

            InitializeComponent();

            // hook the DocumentWorkspace with its selectedPath ...
            this.selectionRenderer = new SelectionRenderer(this.RendererList, this.Selection, this);
            this.RendererList.Add(this.selectionRenderer, true);
            this.selectionRenderer.EnableOutlineAnimation = true;
            this.selectionRenderer.EnableSelectionTinting = false;
            this.selectionRenderer.EnableSelectionOutline = true;

            this.selection.Changed += new EventHandler(Selection_Changed);

            this.zoomBasis = ZoomBasis.FitToWindow;
        }
Example #5
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();
            }
        }
Example #6
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)
            {
            }
        }
        protected override void OnDocumentChanged()
        {
            // if the ActiveLayer is not in this new document, then
            // we try to set ActiveLayer to the first layer in this
            // new document. But if the document contains no layers,
            // or is null, we just null the ActiveLayer.
            if (this.Document == null)
            {
                this.ActiveLayer = null;
            }
            else
            {
                if (this.activeTool != null)
                {
                    throw new InvalidOperationException("Tool was not deactivated while Document was being changed");
                }

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

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

                this.scratchSurface = new Surface(this.Document.Size);

                this.Selection.ClipRectangle = this.Document.Bounds;

                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;

                if (!this.Document.Layers.Contains(this.ActiveLayer))
                {
                    if (this.Document.Layers.Count > 0)
                    {
                        this.ActiveLayer = (Layer)this.Document.Layers[0];
                    }
                    else
                    {
                        this.ActiveLayer = null;
                    }
                }

                // we invalidate each layer so that the layer previews refresh themselves
                foreach (Layer layer in this.Document.Layers)
                {
                    layer.Invalidate();
                }

                bool oldDirty = this.Document.Dirty;
                this.Document.Invalidate();
                this.Document.Dirty = oldDirty;

                this.ZoomBasis = this.savedZb;
                if (this.savedZb == ZoomBasis.ScaleFactor)
                {
                    ScaleFactor = this.savedSf;
                }
            }

            PopNullTool();
            AutoScrollPosition = new Point(0, 0);

            base.OnDocumentChanged();
        }
 public override void ZoomOut(double factor)
 {
     this.ZoomBasis = ZoomBasis.ScaleFactor;
     base.ZoomOut(factor);
 }
 public override void ZoomOut()
 {
     this.ZoomBasis = ZoomBasis.ScaleFactor;
     base.ZoomOut();
 }