Ejemplo n.º 1
0
        public static TaskButton Show(
            IWin32Window owner,
            Icon formIcon,
            string formTitle,
            Image taskImage,
            bool scaleTaskImageWithDpi,
            string introText,
            TaskButton[] taskButtons,
            TaskButton acceptTaskButton,
            TaskButton cancelTaskButton,
            int pixelWidth96Dpi)
        {
            using (TaskDialogForm form = new TaskDialogForm())
            {
                form.Icon                  = formIcon;
                form.IntroText             = introText;
                form.Text                  = formTitle;
                form.TaskImage             = taskImage;
                form.ScaleTaskImageWithDpi = scaleTaskImageWithDpi;
                form.TaskButtons           = taskButtons;
                form.AcceptTaskButton      = acceptTaskButton;
                form.CancelTaskButton      = cancelTaskButton;

                int pixelWidth = UI.ScaleWidth(pixelWidth96Dpi);
                form.ClientSize = new Size(pixelWidth, form.ClientSize.Height);

                DialogResult dr     = form.ShowDialog(owner);
                TaskButton   result = form.DialogResult;

                return(result);
            }
        }
Ejemplo n.º 2
0
        public override void RenderToGraphics(Graphics g, Point offset)
        {
            // We round these values to the nearest integer to avoid an interesting rendering
            // anomaly (or bug? what a surprise ... GDI+) where the nub appears to rotate
            // off-center, or the 'screw-line' is off-center
            float centerX = this.Location.X * (float)OwnerList.ScaleFactor.Ratio;
            float centerY = this.Location.Y * (float)OwnerList.ScaleFactor.Ratio;
            Point center  = new Point((int)Math.Round(centerX), (int)Math.Round(centerY));

            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.TranslateTransform(-center.X, -center.Y, MatrixOrder.Append);
            g.RotateTransform(this.angle, MatrixOrder.Append);
            g.TranslateTransform(center.X - offset.X, center.Y - offset.Y, MatrixOrder.Append);

            float ourSize = UI.ScaleWidth(size);

            using (Pen white = new Pen(Color.FromArgb(128, Color.White), -1.0f),
                   black = new Pen(Color.FromArgb(128, Color.Black), -1.0f))
            {
                RectangleF rectF = new RectangleF(center, new SizeF(0, 0));
                rectF.Inflate(ourSize - 3, ourSize - 3);

                g.DrawEllipse(white, Rectangle.Truncate(rectF));
                rectF.Inflate(1, 1);
                g.DrawEllipse(black, Rectangle.Truncate(rectF));
                rectF.Inflate(1, 1);
                g.DrawEllipse(white, Rectangle.Truncate(rectF));

                rectF.Inflate(-2, -2);
                g.DrawLine(white, rectF.X + rectF.Width / 2.0f - 1.0f, rectF.Top, rectF.X + rectF.Width / 2.0f - 1.0f, rectF.Bottom);
                g.DrawLine(white, rectF.X + rectF.Width / 2.0f + 1.0f, rectF.Top, rectF.X + rectF.Width / 2.0f + 1.0f, rectF.Bottom);
                g.DrawLine(black, rectF.X + rectF.Width / 2.0f, rectF.Top, rectF.X + rectF.Width / 2.0f, rectF.Bottom);
            }
        }
Ejemplo n.º 3
0
        private RectangleF GetOurRectangle()
        {
            RectangleF rectF   = new RectangleF(this.Location, new SizeF(0, 0));
            float      ratio   = 1.0f / (float)OwnerList.ScaleFactor.Ratio;
            float      ourSize = UI.ScaleWidth(size);

            rectF.Inflate(ratio * ourSize, ratio * ourSize);
            return(rectF);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            int ulX = (this.ClientRectangle.Width - UI.ScaleWidth(this.DefaultSize.Width)) / 2;
            int ulY = (this.ClientRectangle.Height - UI.ScaleHeight(this.DefaultSize.Height)) / 2;

            this.primaryColorRectangle.Location   = new System.Drawing.Point(UI.ScaleWidth(ulX + 2), UI.ScaleHeight(ulY + 2));
            this.secondaryColorRectangle.Location = new System.Drawing.Point(UI.ScaleWidth(ulX + 18), UI.ScaleHeight(ulY + 18));
            this.swapIconBox.Location             = new System.Drawing.Point(UI.ScaleWidth(ulX + 30), UI.ScaleHeight(ulY + 2));
            this.blackAndWhiteIconBox.Location    = new System.Drawing.Point(UI.ScaleWidth(ulX + 2), UI.ScaleHeight(ulY + 31));

            base.OnLayout(levent);
        }
Ejemplo n.º 6
0
        public ImageListMenu()
        {
            UI.InitScaling(this);
            InitializeComponent();

            this.imageXInset     = UI.ScaleWidth(2);
            this.imageYInset     = UI.ScaleHeight(4);
            this.textLeftMargin  = UI.ScaleWidth(4);
            this.textRightMargin = UI.ScaleWidth(16);
            this.textVMargin     = UI.ScaleHeight(2);

            this.stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone();
        }
Ejemplo n.º 7
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            this.groupBox.Location  = new Point(-8 + UI.ScaleWidth(leftMargin), 0);
            this.groupBox.Size      = new Size(this.ClientRectangle.Width + 16, this.ClientRectangle.Height + 16);
            this.leftMask.Location  = new Point(-1, 0);
            this.leftMask.Size      = new Size(1 + leftMargin, this.ClientRectangle.Height);
            this.rightMask.Location = new Point(this.ClientRectangle.Width - rightMargin, 0);
            this.rightMask.Size     = new Size(1 + rightMargin, this.ClientRectangle.Height);

            this.leftMask.Visible = false;

            base.OnLayout(levent);
        }
Ejemplo n.º 8
0
 private void InitializeComponent()
 {
     this.contextStatusLabel      = new ToolStripStatusLabel();
     this.progressStatusSeparator = new ToolStripSeparator();
     this.progressStatusBar       = new ToolStripProgressBar();
     this.imageInfoStatusLabel    = new ToolStripStatusLabel();
     this.cursorInfoStatusLabel   = new ToolStripStatusLabel();
     SuspendLayout();
     //
     // contextStatusLabel
     //
     this.contextStatusLabel.Name       = "contextStatusLabel";
     this.contextStatusLabel.Width      = UI.ScaleWidth(436);
     this.contextStatusLabel.Spring     = true;
     this.contextStatusLabel.TextAlign  = ContentAlignment.MiddleLeft;
     this.contextStatusLabel.ImageAlign = ContentAlignment.MiddleLeft;
     //
     // progressStatusBar
     //
     this.progressStatusBar.Name     = "progressStatusBar";
     this.progressStatusBar.Width    = 130;
     this.progressStatusBar.AutoSize = false;
     //
     // imageInfoStatusLabel
     //
     this.imageInfoStatusLabel.Name       = "imageInfoStatusLabel";
     this.imageInfoStatusLabel.Width      = UI.ScaleWidth(130);
     this.imageInfoStatusLabel.TextAlign  = ContentAlignment.MiddleLeft;
     this.imageInfoStatusLabel.ImageAlign = ContentAlignment.MiddleLeft;
     this.imageInfoStatusLabel.AutoSize   = false;
     //
     // cursorInfoStatusLabel
     //
     this.cursorInfoStatusLabel.Name       = "cursorInfoStatusLabel";
     this.cursorInfoStatusLabel.Width      = UI.ScaleWidth(130);
     this.cursorInfoStatusLabel.TextAlign  = ContentAlignment.MiddleLeft;
     this.cursorInfoStatusLabel.ImageAlign = ContentAlignment.MiddleLeft;
     this.cursorInfoStatusLabel.AutoSize   = false;
     //
     // PdnStatusBar
     //
     this.Name = "PdnStatusBar";
     this.Items.Add(this.contextStatusLabel);
     this.Items.Add(this.progressStatusSeparator);
     this.Items.Add(this.progressStatusBar);
     this.Items.Add(new ToolStripSeparator());
     this.Items.Add(this.imageInfoStatusLabel);
     this.Items.Add(new ToolStripSeparator());
     this.Items.Add(this.cursorInfoStatusLabel);
     ResumeLayout(false);
 }
Ejemplo n.º 9
0
        private void MeasureItemPartRectangles(
            Item item,
            out Rectangle itemRect,
            out Rectangle imageRect,
            out Rectangle imageInsetRect,
            out Rectangle closeButtonRect,
            out Rectangle dirtyOverlayRect)
        {
            MeasureItemPartRectangles(out itemRect, out imageRect);

            Rectangle imageInsetRectMax = new Rectangle(
                imageRect.Left + imagePadding,
                imageRect.Top + imagePadding,
                imageRect.Width - imagePadding * 2,
                imageRect.Height - imagePadding * 2);

            Size imageInsetSize;

            if (item.Image == null)
            {
                imageInsetSize = imageRect.Size;
            }
            else
            {
                imageInsetSize = Utility.ComputeThumbnailSize(item.Image.Size, imageInsetRectMax.Width);
            }

            int scaledCloseButtonLength  = UI.ScaleWidth(closeButtonLength);
            int scaledCloseButtonPadding = UI.ScaleWidth(closeButtonPadding);

            imageInsetRect = new Rectangle(
                imageInsetRectMax.Left + (imageInsetRectMax.Width - imageInsetSize.Width) / 2,
                imageInsetRectMax.Bottom - imageInsetSize.Height,
                imageInsetSize.Width,
                imageInsetSize.Height);

            closeButtonRect = new Rectangle(
                imageInsetRectMax.Right - scaledCloseButtonLength - scaledCloseButtonPadding,
                imageInsetRectMax.Top + scaledCloseButtonPadding,
                scaledCloseButtonLength,
                scaledCloseButtonLength);

            dirtyOverlayRect = new Rectangle(
                imageInsetRectMax.Left + scaledCloseButtonPadding,
                imageInsetRectMax.Top + scaledCloseButtonPadding,
                scaledCloseButtonLength,
                scaledCloseButtonLength);
        }
Ejemplo n.º 10
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            int leftMargin                     = UI.ScaleWidth(8);
            int rightMargin                    = UI.ScaleWidth(8);
            int topMargin                      = UI.ScaleHeight(8);
            int bottomMargin                   = UI.ScaleHeight(8);
            int afterInfoLabelVMargin          = UI.ScaleHeight(8);
            int afterDocumentListHeaderVMargin = UI.ScaleHeight(8);
            int afterDocumentListVMargin       = UI.ScaleHeight(8);
            int commandLinkVMargin             = UI.ScaleHeight(8);
            int insetWidth                     = ClientSize.Width - leftMargin - rightMargin;

            int y = topMargin;

            this.infoLabel.Location = new Point(leftMargin, y);
            this.infoLabel.Width    = insetWidth;
            this.infoLabel.Height   = this.infoLabel.GetPreferredSize(new Size(this.infoLabel.Width, 0)).Height;
            y += this.infoLabel.Height + afterInfoLabelVMargin;

            this.documentListHeader.Location = new Point(leftMargin, y);
            this.documentListHeader.Width    = insetWidth;
            y += this.documentListHeader.Height + afterDocumentListHeaderVMargin;

            this.documentStrip.Location = new Point(leftMargin, y);
            this.documentStrip.Size     = new Size(insetWidth, UI.ScaleHeight(72));
            this.hScrollBar.Location    = new Point(leftMargin, this.documentStrip.Bottom);
            this.hScrollBar.Width       = insetWidth;
            y += this.documentStrip.Height + hScrollBar.Height + afterDocumentListVMargin;

            this.saveButton.Location = new Point(leftMargin, y);
            this.saveButton.Width    = insetWidth;
            this.saveButton.PerformLayout();
            y += this.saveButton.Height + commandLinkVMargin;

            this.dontSaveButton.Location = new Point(leftMargin, y);
            this.dontSaveButton.Width    = insetWidth;
            this.dontSaveButton.PerformLayout();
            y += this.dontSaveButton.Height + commandLinkVMargin;

            this.cancelButton.Location = new Point(leftMargin, y);
            this.cancelButton.Width    = insetWidth;
            this.cancelButton.PerformLayout();
            y += this.cancelButton.Height + commandLinkVMargin;

            this.ClientSize = new Size(ClientSize.Width, y);
            base.OnLayout(levent);
        }
Ejemplo n.º 11
0
        private int MouseXYToColorIndex(int x, int y)
        {
            if (x < 0 || y < 0 || x >= ClientSize.Width || y >= ClientSize.Height)
            {
                return(-1);
            }

            int scaledSwatchSize = UI.ScaleWidth(this.unscaledSwatchSize);
            int swatchColumns    = this.ClientSize.Width / scaledSwatchSize;
            int row   = y / scaledSwatchSize;
            int col   = x / scaledSwatchSize;
            int index = col + (row * swatchColumns);

            // Make sure they aren't on the last item of a row that actually got clipped off
            if (col == swatchColumns)
            {
                index = -1;
            }

            return(index);
        }
Ejemplo n.º 12
0
        private RectangleF GetOurRectangle()
        {
            PointF[] ptFs = new PointF[1] {
                this.Location
            };
            this.transform.TransformPoints(ptFs);
            float ratio = (float)Math.Ceiling(1.0 / OwnerList.ScaleFactor.Ratio);

            float ourWidth  = UI.ScaleWidth(this.Size.Width);
            float ourHeight = UI.ScaleHeight(this.Size.Height);

            if (!Single.IsNaN(ratio))
            {
                RectangleF rectF = new RectangleF(ptFs[0], new SizeF(0, 0));
                rectF.Inflate(ratio * ourWidth, ratio * ourHeight);
                return(rectF);
            }
            else
            {
                return(RectangleF.Empty);
            }
        }
Ejemplo n.º 13
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            int arrowWidth = UI.ScaleWidth(16);

            ScrollOffset = Utility.Clamp(this.scrollOffset, MinScrollOffset, MaxScrollOffset);

            // Determine arrow visibility / position
            this.leftScrollButton.Size     = new Size(arrowWidth, ClientSize.Height);
            this.leftScrollButton.Location = new Point(0, 0);

            this.rightScrollButton.Size     = new Size(arrowWidth, ClientSize.Height);
            this.rightScrollButton.Location = new Point(ClientSize.Width - this.rightScrollButton.Width, 0);

            bool showEitherButton = this.showScrollButtons && (this.ViewRectangle.Width > ClientRectangle.Width);
            bool showRightButton  = (this.scrollOffset < MaxScrollOffset) && showEitherButton;
            bool showLeftButton   = (this.scrollOffset > MinScrollOffset) && showEitherButton;

            this.rightScrollButton.Enabled = showRightButton;
            this.rightScrollButton.Visible = showRightButton;
            this.leftScrollButton.Enabled  = showLeftButton;
            this.leftScrollButton.Visible  = showLeftButton;

            base.OnLayout(levent);
        }
Ejemplo n.º 14
0
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.CompositingMode = CompositingMode.SourceOver;
            int scaledSwatchSize = UI.ScaleWidth(this.unscaledSwatchSize);
            int swatchColumns    = this.ClientSize.Width / scaledSwatchSize;

            Point mousePt = Control.MousePosition;

            mousePt = PointToClient(mousePt);
            int activeIndex = MouseXYToColorIndex(mousePt.X, mousePt.Y);

            for (int i = 0; i < this.colors.Count; ++i)
            {
                ColorBgra c = this.colors[i];

                int swatchX = i % swatchColumns;
                int swatchY = i / swatchColumns;

                Rectangle swatchRect = new Rectangle(
                    swatchX * scaledSwatchSize,
                    swatchY * scaledSwatchSize,
                    scaledSwatchSize,
                    scaledSwatchSize);

                UI.ButtonState state;

                if (this.mouseDown)
                {
                    if (i == this.mouseDownIndex)
                    {
                        state = UI.ButtonState.Pressed;
                    }
                    else
                    {
                        state = UI.ButtonState.Normal;
                    }
                }
                else if (i == activeIndex)
                {
                    state = UI.ButtonState.Hot;
                }
                else
                {
                    state = UI.ButtonState.Normal;
                }

                bool drawOutline;

                switch (state)
                {
                case UI.ButtonState.Hot:
                    drawOutline = true;
                    break;

                case UI.ButtonState.Pressed:
                    drawOutline = false;
                    break;

                case UI.ButtonState.Disabled:
                case UI.ButtonState.Normal:
                    drawOutline = false;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
                }

                Utility.DrawColorRectangle(e.Graphics, swatchRect, c.ToColor(), drawOutline);
            }

            if (this.blinkHighlight)
            {
                int   period = (Math.Abs(Environment.TickCount) / blinkInterval) % 2;
                Color color;

                switch (period)
                {
                case 0:
                    color = SystemColors.Window;
                    break;

                case 1:
                    color = SystemColors.Highlight;
                    break;

                default:
                    throw new InvalidOperationException();
                }

                using (Pen pen = new Pen(color))
                {
                    e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, Width - 1, Height - 1));
                }
            }

            base.OnPaint(e);
        }
Ejemplo n.º 15
0
        protected virtual void DrawItemDirtyOverlay(
            Graphics g,
            Item item,
            Rectangle itemRect,
            Rectangle dirtyOverlayRect)
        {
            Color outerPenColor = Color.White;
            Color innerPenColor = Color.Orange;

            const int xInset       = 2;
            int       scaledXInset = UI.ScaleWidth(xInset);

            const float outerPenWidth = 4.0f;
            const float innerPenWidth = 2.0f;

            float scaledOuterPenWidth = UI.ScaleWidth(outerPenWidth);
            float scaledInnerPenWidth = UI.ScaleWidth(innerPenWidth);

            SmoothingMode oldSM = g.SmoothingMode;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            int left   = dirtyOverlayRect.Left + scaledXInset;
            int top    = dirtyOverlayRect.Top + scaledXInset;
            int right  = dirtyOverlayRect.Right - scaledXInset;
            int bottom = dirtyOverlayRect.Bottom - scaledXInset;

            float r = Math.Min((right - left) / 2.0f, (bottom - top) / 2.0f);

            PointF centerPt   = new PointF((left + right) / 2.0f, (top + bottom) / 2.0f);
            float  twoPiOver5 = (float)(Math.PI * 0.4);

            PointF a = new PointF(centerPt.X + r * (float)Math.Sin(twoPiOver5), centerPt.Y - r * (float)Math.Cos(twoPiOver5));
            PointF b = new PointF(centerPt.X + r * (float)Math.Sin(2 * twoPiOver5), centerPt.Y - r * (float)Math.Cos(2 * twoPiOver5));
            PointF c = new PointF(centerPt.X + r * (float)Math.Sin(3 * twoPiOver5), centerPt.Y - r * (float)Math.Cos(3 * twoPiOver5));
            PointF d = new PointF(centerPt.X + r * (float)Math.Sin(4 * twoPiOver5), centerPt.Y - r * (float)Math.Cos(4 * twoPiOver5));
            PointF e = new PointF(centerPt.X + r * (float)Math.Sin(5 * twoPiOver5), centerPt.Y - r * (float)Math.Cos(5 * twoPiOver5));

            PointF[] lines =
                new PointF[]
            {
                centerPt, a,
                centerPt, b,
                centerPt, c,
                centerPt, d,
                centerPt, e
            };

            using (Pen outerPen = new Pen(outerPenColor, scaledOuterPenWidth))
            {
                for (int i = 0; i < lines.Length; i += 2)
                {
                    g.DrawLine(outerPen, lines[i], lines[i + 1]);
                }
            }

            using (Pen innerPen = new Pen(innerPenColor, scaledInnerPenWidth))
            {
                for (int i = 0; i < lines.Length; i += 2)
                {
                    g.DrawLine(innerPen, lines[i], lines[i + 1]);
                }
            }

            g.SmoothingMode = oldSM;
        }
Ejemplo n.º 16
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            int leftMargin            = UI.ScaleWidth(8);
            int rightMargin           = UI.ScaleWidth(8);
            int topMargin             = UI.ScaleHeight(8);
            int bottomMargin          = UI.ScaleHeight(8);
            int buttonHMargin         = UI.ScaleWidth(7);
            int afterIntroTextVMargin = UI.ScaleHeight(16);
            int afterHeaderVMargin    = UI.ScaleHeight(3);
            int hMargin    = UI.ScaleWidth(7);
            int vMargin    = UI.ScaleHeight(7);
            int insetWidth = ClientSize.Width - leftMargin - rightMargin;

            this.introText.Location = new Point(leftMargin, topMargin);
            this.introText.Width    = insetWidth;
            this.introText.Height   = this.introText.GetPreferredSize(this.introText.Size).Height;

            this.defaultToolText.Location = new Point(
                leftMargin,
                this.introText.Bottom + afterIntroTextVMargin);

            this.toolChooserStrip.Location = new Point(
                this.defaultToolText.Right + hMargin,
                this.defaultToolText.Top + (this.defaultToolText.Height - this.toolChooserStrip.Height) / 2);

            int y             = vMargin + Math.Max(this.defaultToolText.Bottom, this.toolChooserStrip.Bottom);
            int maxInsetWidth = insetWidth;

            foreach (ToolConfigRow toolConfigRow in this.toolConfigRows)
            {
                if (!string.IsNullOrEmpty(toolConfigRow.HeaderLabel.Text))
                {
                    toolConfigRow.HeaderLabel.Location = new Point(leftMargin, y);
                    toolConfigRow.HeaderLabel.Width    = insetWidth;
                    y = toolConfigRow.HeaderLabel.Bottom + afterHeaderVMargin;
                }

                toolConfigRow.ToolConfigStrip.Location = new Point(leftMargin + 3, y);
                Size preferredSize = toolConfigRow.ToolConfigStrip.GetPreferredSize(
                    new Size(maxInsetWidth, 1));

                toolConfigRow.ToolConfigStrip.Size = preferredSize;

                maxInsetWidth = Math.Max(maxInsetWidth, toolConfigRow.ToolConfigStrip.Width);

                y = toolConfigRow.ToolConfigStrip.Bottom + vMargin;
            }

            y += vMargin;

            this.bottomSeparator.Location = new Point(leftMargin, y);
            this.bottomSeparator.Width    = insetWidth;
            this.bottomSeparator.Visible  = false;

            y += this.bottomSeparator.Height;

            this.cancelButton.Location = new Point(ClientSize.Width - rightMargin - this.cancelButton.Width, y);

            this.saveButton.Location = new Point(
                this.cancelButton.Left - buttonHMargin - this.saveButton.Width,
                this.cancelButton.Top);

            this.resetButton.Location = new Point(leftMargin, this.saveButton.Top);

            this.loadFromToolBarButton.Location = new Point(this.resetButton.Right + buttonHMargin, this.resetButton.Top);

            y = this.resetButton.Bottom + bottomMargin;

            this.ClientSize = new Size(leftMargin + maxInsetWidth + rightMargin, y);

            if (IsHandleCreated && maxInsetWidth > insetWidth)
            {
                BeginInvoke(new Procedure(PerformLayout), null);
            }

            base.OnLayout(levent);
        }
Ejemplo n.º 17
0
        protected override void OnRender(Graphics g, Point offset)
        {
            lock (this)
            {
                float ourSize = UI.ScaleWidth(Math.Min(Width, Height));
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.TranslateTransform(-offset.X, -offset.Y, MatrixOrder.Append);

                PointF ptF = (PointF)this.Location;

                ptF = Utility.TransformOnePoint(this.transform, ptF);

                ptF.X *= (float)OwnerList.ScaleFactor.Ratio;
                ptF.Y *= (float)OwnerList.ScaleFactor.Ratio;

                PointF[] pts = new PointF[8]
                {
                    new PointF(-1, -1),                          // up+left
                    new PointF(+1, -1),                          // up+right
                    new PointF(+1, +1),                          // down+right
                    new PointF(-1, +1),                          // down+left

                    new PointF(-1, 0),                           // left
                    new PointF(+1, 0),                           // right
                    new PointF(0, -1),                           // up
                    new PointF(0, +1)                            // down
                };

                Utility.RotateVectors(pts, this.transformAngle);
                Utility.NormalizeVectors(pts);

                using (Pen white = new Pen(Color.FromArgb(this.alpha, Color.White), -1.0f),
                       black = new Pen(Color.FromArgb(this.alpha, Color.Black), -1.0f))
                {
                    PixelOffsetMode oldPOM = g.PixelOffsetMode;
                    g.PixelOffsetMode = PixelOffsetMode.None;

                    if (this.shape != MoveNubShape.Circle)
                    {
                        PointF[] outer = new PointF[4]
                        {
                            Utility.AddVectors(ptF, Utility.MultiplyVector(pts[0], ourSize)),
                            Utility.AddVectors(ptF, Utility.MultiplyVector(pts[1], ourSize)),
                            Utility.AddVectors(ptF, Utility.MultiplyVector(pts[2], ourSize)),
                            Utility.AddVectors(ptF, Utility.MultiplyVector(pts[3], ourSize))
                        };

                        PointF[] middle = new PointF[4]
                        {
                            Utility.AddVectors(ptF, Utility.MultiplyVector(pts[0], ourSize - 1)),
                            Utility.AddVectors(ptF, Utility.MultiplyVector(pts[1], ourSize - 1)),
                            Utility.AddVectors(ptF, Utility.MultiplyVector(pts[2], ourSize - 1)),
                            Utility.AddVectors(ptF, Utility.MultiplyVector(pts[3], ourSize - 1))
                        };

                        PointF[] inner = new PointF[4]
                        {
                            Utility.AddVectors(ptF, Utility.MultiplyVector(pts[0], ourSize - 2)),
                            Utility.AddVectors(ptF, Utility.MultiplyVector(pts[1], ourSize - 2)),
                            Utility.AddVectors(ptF, Utility.MultiplyVector(pts[2], ourSize - 2)),
                            Utility.AddVectors(ptF, Utility.MultiplyVector(pts[3], ourSize - 2))
                        };

                        g.DrawPolygon(white, outer);
                        g.DrawPolygon(black, middle);
                        g.DrawPolygon(white, inner);
                    }
                    else if (this.shape == MoveNubShape.Circle)
                    {
                        RectangleF rect = new RectangleF(ptF, new SizeF(0, 0));
                        rect.Inflate(ourSize - 1, ourSize - 1);
                        g.DrawEllipse(white, rect);
                        rect.Inflate(-1.0f, -1.0f);
                        g.DrawEllipse(black, rect);
                        rect.Inflate(-1.0f, -1.0f);
                        g.DrawEllipse(white, rect);
                    }

                    if (this.shape == MoveNubShape.Compass)
                    {
                        black.SetLineCap(LineCap.Round, LineCap.DiamondAnchor, DashCap.Flat);
                        black.EndCap   = LineCap.ArrowAnchor;
                        black.StartCap = LineCap.ArrowAnchor;
                        white.SetLineCap(LineCap.Round, LineCap.DiamondAnchor, DashCap.Flat);
                        white.EndCap   = LineCap.ArrowAnchor;
                        white.StartCap = LineCap.ArrowAnchor;

                        PointF ul = Utility.AddVectors(ptF, Utility.MultiplyVector(pts[0], ourSize - 1));
                        PointF ur = Utility.AddVectors(ptF, Utility.MultiplyVector(pts[1], ourSize - 1));
                        PointF lr = Utility.AddVectors(ptF, Utility.MultiplyVector(pts[2], ourSize - 1));
                        PointF ll = Utility.AddVectors(ptF, Utility.MultiplyVector(pts[3], ourSize - 1));

                        PointF top    = Utility.MultiplyVector(Utility.AddVectors(ul, ur), 0.5f);
                        PointF left   = Utility.MultiplyVector(Utility.AddVectors(ul, ll), 0.5f);
                        PointF right  = Utility.MultiplyVector(Utility.AddVectors(ur, lr), 0.5f);
                        PointF bottom = Utility.MultiplyVector(Utility.AddVectors(ll, lr), 0.5f);

                        using (SolidBrush whiteBrush = new SolidBrush(white.Color))
                        {
                            PointF[] poly = new PointF[] { ul, ur, lr, ll };
                            g.FillPolygon(whiteBrush, poly, FillMode.Winding);
                        }

                        g.DrawLine(black, top, bottom);
                        g.DrawLine(black, left, right);
                    }

                    g.PixelOffsetMode = oldPOM;
                }
            }
        }
Ejemplo n.º 18
0
        public void ShowImageList(Item[] items)
        {
            HideImageList();

            this.comboBox.Items.AddRange(items);

            using (Graphics g = CreateGraphics())
            {
                DetermineMaxItemSize(g, items, out this.itemSize, out this.maxImageSize);
            }

            this.comboBox.ItemHeight    = this.itemSize.Height;
            this.comboBox.DropDownWidth = this.itemSize.Width + SystemInformation.VerticalScrollBarWidth + UI.ScaleWidth(2);

            // Determine the max drop down height so that we don't cover up the button
            Screen ourScreen             = Screen.FromControl(this);
            Point  screenLocation        = PointToScreen(new Point(this.comboBox.Left, this.comboBox.Bottom));
            int    comboBoxToFloorHeight = ourScreen.WorkingArea.Height - screenLocation.Y;

            // make sure it is an integral multiple of itemSize.Height
            comboBoxToFloorHeight = this.itemSize.Height * (comboBoxToFloorHeight / this.itemSize.Height);
            // add 2 pixels for border
            comboBoxToFloorHeight += 2;

            // But make sure it can hold at least 3 items
            int minDropDownHeight = 2 + itemSize.Height * 3; // +2 for combobox's border

            int dropDownHeight = Math.Max(comboBoxToFloorHeight, minDropDownHeight);

            this.comboBox.DropDownHeight = dropDownHeight;

            int selectedIndex = Array.FindIndex(
                items,
                delegate(Item item)
            {
                return(item.Selected);
            });

            this.comboBox.SelectedIndex = selectedIndex;

            // Make sure the combobox does not spill past the right edge of the screen
            int left = PointToScreen(new Point(0, Height)).X;

            if (left + this.comboBox.DropDownWidth > ourScreen.WorkingArea.Right)
            {
                left = ourScreen.WorkingArea.Right - this.comboBox.DropDownWidth;
            }

            Point clientPt = PointToClient(new Point(left, screenLocation.Y));

            SuspendLayout();
            this.comboBox.Left = clientPt.X;
            ResumeLayout(false);

            // Set focus to it so it can get mouse wheel events, and then show it!
            this.comboBox.Focus();
            UI.ShowComboBox(this.comboBox, true);
        }
Ejemplo n.º 19
0
        protected override void OnLayout(LayoutEventArgs e)
        {
            bool plentyWidthBefore =
                (this.MainMenu.Width >= this.MainMenu.PreferredSize.Width) &&
                (this.CommonActionsStrip.Width >= this.CommonActionsStrip.PreferredSize.Width) &&
                (this.ViewConfigStrip.Width >= this.ViewConfigStrip.PreferredSize.Width) &&
                (this.ToolChooserStrip.Width >= this.ToolChooserStrip.PreferredSize.Width) &&
                (this.ToolConfigStrip.Width >= this.ToolConfigStrip.PreferredSize.Width);

            if (!plentyWidthBefore)
            {
                UI.SuspendControlPainting(this);
            }
            else
            {
                // if we don't do this then we get some terrible flickering of the right scroll arrow
                UI.SuspendControlPainting(this.documentStrip);
            }

            this.MainMenu.Location           = new Point(0, 0);
            this.MainMenu.Height             = this.MainMenu.PreferredSize.Height;
            this.ToolStripContainer.Location = new Point(0, this.MainMenu.Bottom);

            this.ToolStripContainer.RowMargin = new Padding(0);
            this.MainMenu.Padding             = new Padding(0, this.MainMenu.Padding.Top, 0, this.MainMenu.Padding.Bottom);

            this.CommonActionsStrip.Width = this.CommonActionsStrip.PreferredSize.Width;
            this.ViewConfigStrip.Width    = this.ViewConfigStrip.PreferredSize.Width;
            this.ToolChooserStrip.Width   = this.ToolChooserStrip.PreferredSize.Width;
            this.ToolConfigStrip.Width    = this.ToolConfigStrip.PreferredSize.Width;

            if (!this.computedMaxRowHeight)
            {
                ToolBarConfigItems oldTbci = this.ToolConfigStrip.ToolBarConfigItems;
                this.ToolConfigStrip.ToolBarConfigItems = ToolBarConfigItems.All;
                this.ToolConfigStrip.PerformLayout();

                this.maxRowHeight =
                    Math.Max(this.CommonActionsStrip.PreferredSize.Height,
                             Math.Max(this.ViewConfigStrip.PreferredSize.Height,
                                      Math.Max(this.ToolChooserStrip.PreferredSize.Height, this.ToolConfigStrip.PreferredSize.Height)));

                this.ToolConfigStrip.ToolBarConfigItems = oldTbci;
                this.ToolConfigStrip.PerformLayout();

                this.computedMaxRowHeight = true;
            }

            this.CommonActionsStrip.Height = this.maxRowHeight;
            this.ViewConfigStrip.Height    = this.maxRowHeight;
            this.ToolChooserStrip.Height   = this.maxRowHeight;
            this.ToolConfigStrip.Height    = this.maxRowHeight;

            this.CommonActionsStrip.Location = new Point(0, 0);
            this.ViewConfigStrip.Location    = new Point(this.CommonActionsStrip.Right, this.CommonActionsStrip.Top);
            this.ToolChooserStrip.Location   = new Point(0, this.ViewConfigStrip.Bottom);
            this.ToolConfigStrip.Location    = new Point(this.ToolChooserStrip.Right, this.ToolChooserStrip.Top);

            this.ToolStripContainer.Height =
                Math.Max(this.CommonActionsStrip.Bottom,
                         Math.Max(this.ViewConfigStrip.Bottom,
                                  Math.Max(this.ToolChooserStrip.Bottom,
                                           this.ToolConfigStrip.Visible ? this.ToolConfigStrip.Bottom : this.ToolChooserStrip.Bottom)));

            // Compute how wide the toolStripContainer would like to be
            int widthRow1 =
                this.CommonActionsStrip.Left + this.CommonActionsStrip.PreferredSize.Width + this.CommonActionsStrip.Margin.Horizontal +
                this.ViewConfigStrip.PreferredSize.Width + this.ViewConfigStrip.Margin.Horizontal;

            int widthRow2 =
                this.ToolChooserStrip.Left + this.ToolChooserStrip.PreferredSize.Width + this.ToolChooserStrip.Margin.Horizontal +
                this.ToolConfigStrip.PreferredSize.Width + this.ToolConfigStrip.Margin.Horizontal;

            int preferredMinTscWidth = Math.Max(widthRow1, widthRow2);

            // Throw in the documentListButton if necessary
            bool showDlb = this.documentStrip.DocumentCount > 0;

            this.documentListButton.Visible = showDlb;
            this.documentListButton.Enabled = showDlb;

            if (showDlb)
            {
                int documentListButtonWidth = UI.ScaleWidth(15);
                this.documentListButton.Width = documentListButtonWidth;
            }
            else
            {
                this.documentListButton.Width = 0;
            }

            // Figure out the DocumentStrip's size -- we actually make two passes at setting its Width
            // so that we can toss in the documentListButton if necessary
            if (this.documentStrip.DocumentCount == 0)
            {
                this.documentStrip.Width = 0;
            }
            else
            {
                this.documentStrip.Width = Math.Max(
                    this.documentStrip.PreferredMinClientWidth,
                    Math.Min(this.documentStrip.PreferredSize.Width,
                             ClientSize.Width - preferredMinTscWidth - this.documentListButton.Width));
            }

            this.documentStrip.Location      = new Point(ClientSize.Width - this.documentStrip.Width, 0);
            this.documentListButton.Location = new Point(this.documentStrip.Left - this.documentListButton.Width, 0);

            this.imageListMenu.Location = new Point(this.documentListButton.Left, this.documentListButton.Bottom - 1);
            this.imageListMenu.Width    = this.documentListButton.Width;
            this.imageListMenu.Height   = 0;

            this.documentListButton.Visible = showDlb;
            this.documentListButton.Enabled = showDlb;

            // Finish setting up widths and heights
            int oldDsHeight = this.documentStrip.Height;

            this.documentStrip.Height      = this.ToolStripContainer.Bottom;
            this.documentListButton.Height = this.documentStrip.Height;

            int tsWidth = ClientSize.Width - (this.documentStrip.Width + this.documentListButton.Width);

            this.MainMenu.Width           = tsWidth;
            this.ToolStripContainer.Width = tsWidth;

            this.Height = this.ToolStripContainer.Bottom;

            // Now get stuff to paint right
            this.documentStrip.PerformLayout();

            if (!plentyWidthBefore)
            {
                UI.ResumeControlPainting(this);
                Invalidate(true);
            }
            else
            {
                UI.ResumeControlPainting(this.documentStrip);
                this.documentStrip.Invalidate(true);
            }

            if (this.documentStrip.Width == 0)
            {
                this.MainMenu.Invalidate();
            }

            if (oldDsHeight != this.documentStrip.Height)
            {
                this.documentStrip.RefreshAllThumbnails();
            }

            base.OnLayout(e);
        }
Ejemplo n.º 20
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (this.historyStack != null)
            {
                using (SolidBrush backBrush = new SolidBrush(BackColor))
                {
                    e.Graphics.FillRectangle(backBrush, e.ClipRectangle);
                }

                e.Graphics.TranslateTransform(0, -this.scrollOffset);

                int afterImageHMargin = UI.ScaleWidth(1);

                StringFormat stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone();
                stringFormat.LineAlignment = StringAlignment.Center;
                stringFormat.Trimming      = StringTrimming.EllipsisCharacter;

                Rectangle visibleViewRectangle = ClientRectangleToViewRectangle(ClientRectangle);

                // Fill in the background for the undo items
                Rectangle undoRect = UndoViewRectangle;
                e.Graphics.FillRectangle(SystemBrushes.Window, undoRect);

                // We only want to draw what's visible, so figure out the first and last
                // undo items that are actually visible and only draw them.
                Rectangle visibleUndoRect = Rectangle.Intersect(visibleViewRectangle, undoRect);

                int beginUndoIndex;
                int endUndoIndex;
                if (visibleUndoRect.Width > 0 && visibleUndoRect.Height > 0)
                {
                    ItemType itemType;
                    ViewPointToStackIndex(visibleUndoRect.Location, out itemType, out beginUndoIndex);
                    ViewPointToStackIndex(new Point(visibleUndoRect.Left, visibleUndoRect.Bottom - 1), out itemType, out endUndoIndex);
                }
                else
                {
                    beginUndoIndex = 0;
                    endUndoIndex   = -1;
                }

                // Draw undo items
                for (int i = beginUndoIndex; i <= endUndoIndex; ++i)
                {
                    Image         image;
                    ImageResource imageResource = this.historyStack.UndoStack[i].Image;

                    if (imageResource != null)
                    {
                        image = imageResource.Reference;
                    }
                    else
                    {
                        image = null;
                    }

                    int drawWidth;
                    if (image != null)
                    {
                        drawWidth = (image.Width * this.itemHeight) / image.Height;
                    }
                    else
                    {
                        drawWidth = this.itemHeight;
                    }

                    Brush textBrush;

                    if (i == this.undoItemHighlight)
                    {
                        Rectangle itemRect = new Rectangle(
                            0,
                            i * this.itemHeight,
                            ViewWidth,
                            this.itemHeight);

                        e.Graphics.FillRectangle(SystemBrushes.Highlight, itemRect);
                        textBrush = SystemBrushes.HighlightText;
                    }
                    else
                    {
                        textBrush = SystemBrushes.WindowText;
                    }

                    if (image != null)
                    {
                        e.Graphics.DrawImage(
                            image,
                            new Rectangle(0, i * this.itemHeight, drawWidth, this.itemHeight),
                            new Rectangle(0, 0, image.Width, image.Height),
                            GraphicsUnit.Pixel);
                    }

                    int textX = drawWidth + afterImageHMargin;

                    Rectangle textRect = new Rectangle(
                        textX,
                        i * this.itemHeight,
                        ViewWidth - textX,
                        this.itemHeight);

                    e.Graphics.DrawString(
                        this.historyStack.UndoStack[i].Name,
                        Font,
                        textBrush,
                        textRect,
                        stringFormat);
                }

                // Fill in the background for the redo items
                Rectangle redoRect = RedoViewRectangle;
                e.Graphics.FillRectangle(Brushes.SlateGray, redoRect);

                Font redoFont = new Font(Font, Font.Style | FontStyle.Italic);

                // We only want to draw what's visible, so figure out the first and last
                // redo items that are actually visible and only draw them.
                Rectangle visibleRedoRect = Rectangle.Intersect(visibleViewRectangle, redoRect);

                int beginRedoIndex;
                int endRedoIndex;
                if (visibleRedoRect.Width > 0 && visibleRedoRect.Height > 0)
                {
                    ItemType itemType;
                    ViewPointToStackIndex(visibleRedoRect.Location, out itemType, out beginRedoIndex);
                    ViewPointToStackIndex(new Point(visibleRedoRect.Left, visibleRedoRect.Bottom - 1), out itemType, out endRedoIndex);
                }
                else
                {
                    beginRedoIndex = 0;
                    endRedoIndex   = -1;
                }

                // Draw redo items
                for (int i = beginRedoIndex; i <= endRedoIndex; ++i)
                {
                    Image         image;
                    ImageResource imageResource = this.historyStack.RedoStack[i].Image;

                    if (imageResource != null)
                    {
                        image = imageResource.Reference;
                    }
                    else
                    {
                        image = null;
                    }

                    int drawWidth;

                    if (image != null)
                    {
                        drawWidth = (image.Width * this.itemHeight) / image.Height;
                    }
                    else
                    {
                        drawWidth = this.itemHeight;
                    }

                    int y = redoRect.Top + i * this.itemHeight;

                    Brush textBrush;
                    if (i == this.redoItemHighlight)
                    {
                        Rectangle itemRect = new Rectangle(
                            0,
                            y,
                            ViewWidth,
                            this.itemHeight);

                        e.Graphics.FillRectangle(SystemBrushes.Highlight, itemRect);
                        textBrush = SystemBrushes.HighlightText;
                    }
                    else
                    {
                        textBrush = SystemBrushes.InactiveCaptionText;
                    }

                    if (image != null)
                    {
                        e.Graphics.DrawImage(
                            image,
                            new Rectangle(0, y, drawWidth, this.itemHeight),
                            new Rectangle(0, 0, image.Width, image.Height),
                            GraphicsUnit.Pixel);
                    }

                    int textX = drawWidth + afterImageHMargin;

                    Rectangle textRect = new Rectangle(
                        textX,
                        y,
                        ViewWidth - textX,
                        this.itemHeight);

                    e.Graphics.DrawString(
                        this.historyStack.RedoStack[i].Name,
                        redoFont,
                        textBrush,
                        textRect,
                        stringFormat);
                }

                redoFont.Dispose();
                redoFont = null;

                stringFormat.Dispose();
                stringFormat = null;

                e.Graphics.TranslateTransform(0, this.scrollOffset);
            }

            base.OnPaint(e);
        }
Ejemplo n.º 21
0
            protected override void OnLayout(LayoutEventArgs levent)
            {
                int leftMargin                 = UI.ScaleWidth(8);
                int rightMargin                = UI.ScaleWidth(8);
                int topMargin                  = UI.ScaleHeight(8);
                int bottomMargin               = UI.ScaleHeight(8);
                int imageToIntroHMargin        = UI.ScaleWidth(8);
                int topSectionToLinksVMargin   = UI.ScaleHeight(8);
                int commandButtonVMargin       = UI.ScaleHeight(0);
                int afterCommandButtonsVMargin = UI.ScaleHeight(8);
                int insetWidth                 = ClientSize.Width - leftMargin - rightMargin;

                if (this.taskImagePB.Image == null)
                {
                    this.taskImagePB.Location = new Point(0, topMargin);
                    this.taskImagePB.Size     = new Size(0, 0);
                    this.taskImagePB.Visible  = false;
                }
                else
                {
                    this.taskImagePB.Location = new Point(leftMargin, topMargin);

                    if (this.scaleTaskImageWithDpi)
                    {
                        this.taskImagePB.Size = UI.ScaleSize(this.taskImagePB.Image.Size);
                    }
                    else
                    {
                        this.taskImagePB.Size = this.taskImagePB.Image.Size;
                    }

                    this.taskImagePB.Visible = true;
                }

                this.introTextLabel.Location = new Point(this.taskImagePB.Right + imageToIntroHMargin, this.taskImagePB.Top);
                this.introTextLabel.Width    = ClientSize.Width - this.introTextLabel.Left - rightMargin;
                this.introTextLabel.Height   = this.introTextLabel.GetPreferredSize(new Size(this.introTextLabel.Width, 1)).Height;

                int y = Math.Max(this.taskImagePB.Bottom, this.introTextLabel.Bottom);

                y += topSectionToLinksVMargin;

                if (!string.IsNullOrEmpty(this.auxButton.Text))
                {
                    this.auxButton.Visible  = true;
                    this.auxButton.Location = new Point(leftMargin, y);
                    this.auxButton.PerformLayout();
                    y += this.auxButton.Height;
                    y += topSectionToLinksVMargin;
                }
                else
                {
                    this.auxButton.Visible = false;
                }

                if (this.commandButtons != null)
                {
                    this.separator.Location = new Point(leftMargin, y);
                    this.separator.Width    = insetWidth;
                    y += this.separator.Height;

                    for (int i = 0; i < this.commandButtons.Length; ++i)
                    {
                        this.commandButtons[i].Location = new Point(leftMargin, y);
                        this.commandButtons[i].Width    = insetWidth;
                        this.commandButtons[i].PerformLayout();
                        y += this.commandButtons[i].Height + commandButtonVMargin;
                    }

                    y += afterCommandButtonsVMargin;
                }

                this.ClientSize = new Size(ClientSize.Width, y);
                base.OnLayout(levent);
            }
Ejemplo n.º 22
0
        protected override void OnPaint(PaintEventArgs e)
        {
            float valueStart       = this.scaleFactor.ScaleScalar(this.rulerValue - offset);
            float valueEnd         = this.scaleFactor.ScaleScalar(this.rulerValue + 1.0f - offset);
            float highlightStartPx = this.scaleFactor.ScaleScalar(this.highlightStart - offset);
            float highlightEndPx   = this.scaleFactor.ScaleScalar(this.highlightStart + this.highlightLength - offset);

            RectangleF highlightRect;
            RectangleF valueRect;

            if (this.orientation == Orientation.Horizontal)
            {
                valueRect     = new RectangleF(valueStart, this.ClientRectangle.Top, valueEnd - valueStart, this.ClientRectangle.Height);
                highlightRect = new RectangleF(highlightStartPx, this.ClientRectangle.Top, highlightEndPx - highlightStartPx, this.ClientRectangle.Height);
            }
            else // if (this.orientation == Orientation.Vertical)
            {
                valueRect     = new RectangleF(this.ClientRectangle.Left, valueStart, this.ClientRectangle.Width, valueEnd - valueStart);
                highlightRect = new RectangleF(this.ClientRectangle.Left, highlightStartPx, this.ClientRectangle.Width, highlightEndPx - highlightStartPx);
            }

            if (!this.highlightEnabled)
            {
                highlightRect = RectangleF.Empty;
            }

            if (this.orientation == Orientation.Horizontal)
            {
                e.Graphics.DrawLine(
                    SystemPens.WindowText,
                    UI.ScaleWidth(15),
                    ClientRectangle.Top,
                    UI.ScaleWidth(15),
                    ClientRectangle.Bottom);

                string abbStringName = "MeasurementUnit." + this.MeasurementUnit.ToString() + ".Abbreviation";
                string abbString     = PdnResources.GetString(abbStringName);
                e.Graphics.DrawString(abbString, Font, SystemBrushes.WindowText, UI.ScaleWidth(-2), 0);
            }

            Region clipRegion = new Region(highlightRect);

            clipRegion.Xor(valueRect);

            if (this.orientation == Orientation.Horizontal)
            {
                clipRegion.Exclude(new Rectangle(0, 0, UI.ScaleWidth(16), ClientRectangle.Height));
            }

            e.Graphics.SetClip(clipRegion, CombineMode.Replace);
            DrawRuler(e, true);

            clipRegion.Xor(this.ClientRectangle);

            if (this.orientation == Orientation.Horizontal)
            {
                clipRegion.Exclude(new Rectangle(0, 0, UI.ScaleWidth(16), ClientRectangle.Height - 1));
            }

            e.Graphics.SetClip(clipRegion, CombineMode.Replace);
            DrawRuler(e, false);
        }
Ejemplo n.º 23
0
        protected virtual void DrawItemCloseButton(
            Graphics g,
            Item item,
            Rectangle itemRect,
            Rectangle closeButtonRect)
        {
            if (item.Checked && item.Selected)
            {
                Color xInnerColor;
                Color xOuterColor;
                Color outlineColor;

                switch (item.CloseRenderState)
                {
                case UI.ButtonState.Disabled:
                    xInnerColor  = Color.LightGray;
                    xOuterColor  = Color.LightGray;
                    outlineColor = Color.Transparent;
                    break;

                case UI.ButtonState.Hot:
                    xInnerColor  = Color.Red;
                    xOuterColor  = Color.White;
                    outlineColor = Color.Gray;
                    break;

                case UI.ButtonState.Normal:
                    xInnerColor  = Color.Black;
                    xOuterColor  = Color.White;
                    outlineColor = Color.Transparent;
                    break;

                case UI.ButtonState.Pressed:
                    xInnerColor  = Color.DarkRed;
                    xOuterColor  = Color.White;
                    outlineColor = Color.Gray;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
                }

                const int xInset       = 2;
                int       scaledXInset = UI.ScaleWidth(xInset);

                const float outerPenWidth = 4.0f;
                const float innerPenWidth = 2.0f;

                float scaledOuterPenWidth = UI.ScaleWidth(outerPenWidth);
                float scaledInnerPenWidth = UI.ScaleWidth(innerPenWidth);

                using (Pen xPen = new Pen(xOuterColor, scaledOuterPenWidth))
                {
                    SmoothingMode oldSM = g.SmoothingMode;
                    g.SmoothingMode = SmoothingMode.AntiAlias;

                    int left   = closeButtonRect.Left + scaledXInset;
                    int top    = closeButtonRect.Top + scaledXInset;
                    int right  = closeButtonRect.Right - (scaledXInset * 2) + 1;
                    int bottom = closeButtonRect.Bottom - (scaledXInset * 2) + 1;

                    g.DrawLine(xPen, left, top, right, bottom);
                    g.DrawLine(xPen, left, bottom, right, top);

                    xPen.Width = scaledInnerPenWidth;
                    xPen.Color = xInnerColor;

                    g.DrawLine(xPen, left, top, right, bottom);
                    g.DrawLine(xPen, left, bottom, right, top);

                    g.SmoothingMode = oldSM;
                }
            }
        }
Ejemplo n.º 24
0
        private Size MeasureAndDraw(Graphics g, bool enableDrawing, PushButtonState state, bool drawFocusCues, bool drawKeyboardCues)
        {
            if (enableDrawing)
            {
                g.PixelOffsetMode   = PixelOffsetMode.Half;
                g.CompositingMode   = CompositingMode.SourceOver;
                g.InterpolationMode = InterpolationMode.Bilinear;
            }

            int marginX       = UI.ScaleWidth(9);
            int marginYTop    = UI.ScaleHeight(8);
            int marginYBottom = UI.ScaleHeight(9);
            int paddingX      = UI.ScaleWidth(8);
            int paddingY      = UI.ScaleHeight(3);
            int offsetX       = 0;
            int offsetY       = 0;

            bool drawAsDefault = (state == PushButtonState.Default);

            if (enableDrawing)
            {
                using (Brush backBrush = new SolidBrush(this.BackColor))
                {
                    CompositingMode oldCM = g.CompositingMode;
                    g.CompositingMode = CompositingMode.SourceCopy;
                    g.FillRectangle(backBrush, ClientRectangle);
                    g.CompositingMode = oldCM;
                }

                Rectangle ourRect = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height);

                if (state == PushButtonState.Pressed)
                {
                    offsetX = 1;
                    offsetY = 1;
                }

                UI.DrawCommandButton(g, state, ourRect, BackColor, this);
            }

            Rectangle actionImageRect;

            Brush textBrush = new SolidBrush(SystemColors.WindowText);

            if (this.actionImage == null)
            {
                actionImageRect = new Rectangle(offsetX, offsetY + marginYTop, 0, 0);
            }
            else
            {
                actionImageRect = new Rectangle(offsetX + marginX, offsetY + marginYTop,
                                                UI.ScaleWidth(this.actionImage.Width), UI.ScaleHeight(this.actionImage.Height));

                Rectangle srcRect = new Rectangle(0, 0, this.actionImage.Width, this.actionImage.Height);

                if (enableDrawing)
                {
                    Image drawMe = Enabled ? this.actionImage : this.actionImageDisabled;

                    if (Enabled)
                    {
                        actionImageRect.Y += 3;
                        actionImageRect.X += 1;
                        g.DrawImage(this.actionImageDisabled, actionImageRect, srcRect, GraphicsUnit.Pixel);
                        actionImageRect.X -= 1;
                        actionImageRect.Y -= 3;
                    }

                    actionImageRect.Y += 2;
                    g.DrawImage(drawMe, actionImageRect, srcRect, GraphicsUnit.Pixel);
                    actionImageRect.Y -= 2;
                }
            }

            int actionTextX     = actionImageRect.Right + paddingX;
            int actionTextY     = actionImageRect.Top;
            int actionTextWidth = ClientSize.Width - actionTextX - marginX + offsetX;

            StringFormat stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone();

            stringFormat.HotkeyPrefix = drawKeyboardCues ? HotkeyPrefix.Show : HotkeyPrefix.Hide;

            SizeF actionTextSize = g.MeasureString(this.actionText, this.actionTextFont, actionTextWidth, stringFormat);

            Rectangle actionTextRect = new Rectangle(actionTextX, actionTextY,
                                                     actionTextWidth, (int)Math.Ceiling(actionTextSize.Height));

            if (enableDrawing)
            {
                if (state == PushButtonState.Disabled)
                {
                    ControlPaint.DrawStringDisabled(g, this.actionText, this.actionTextFont, this.BackColor, actionTextRect, stringFormat);
                }
                else
                {
                    g.DrawString(this.actionText, this.actionTextFont, textBrush, actionTextRect, stringFormat);
                }
            }

            int descriptionTextX     = actionTextX;
            int descriptionTextY     = actionTextRect.Bottom + paddingY;
            int descriptionTextWidth = actionTextWidth;

            SizeF descriptionTextSize = g.MeasureString(this.explanationText, this.explanationTextFont,
                                                        descriptionTextWidth, stringFormat);

            Rectangle descriptionTextRect = new Rectangle(descriptionTextX, descriptionTextY,
                                                          descriptionTextWidth, (int)Math.Ceiling(descriptionTextSize.Height));

            if (enableDrawing)
            {
                if (state == PushButtonState.Disabled)
                {
                    ControlPaint.DrawStringDisabled(g, this.explanationText, this.explanationTextFont, this.BackColor, descriptionTextRect, stringFormat);
                }
                else
                {
                    g.DrawString(this.explanationText, this.explanationTextFont, textBrush, descriptionTextRect, stringFormat);
                }
            }

            if (enableDrawing)
            {
                if (drawFocusCues)
                {
                    ControlPaint.DrawFocusRectangle(g, new Rectangle(3, 3, ClientSize.Width - 5, ClientSize.Height - 5));
                }
            }

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

            stringFormat.Dispose();
            Size layoutSize = new Size(ClientSize.Width, descriptionTextRect.Bottom + marginYBottom);

            return(layoutSize);
        }
Ejemplo n.º 25
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            // Bottom-right Buttons
            int buttonsBottomMargin = UI.ScaleHeight(8);
            int buttonsRightMargin  = UI.ScaleWidth(8);
            int buttonsHMargin      = UI.ScaleWidth(8);

            this.baseCancelButton.Location = new Point(
                ClientSize.Width - this.baseOkButton.Width - buttonsRightMargin,
                ClientSize.Height - buttonsBottomMargin - this.baseCancelButton.Height);

            this.baseOkButton.Location = new Point(
                this.baseCancelButton.Left - buttonsHMargin - this.baseOkButton.Width,
                ClientSize.Height - buttonsBottomMargin - this.baseOkButton.Height);

            int previewBottomMargin = UI.ScaleHeight(8);

            // Set up layout properties
            int topMargin               = UI.ScaleHeight(6);
            int leftMargin              = UI.ScaleWidth(8);
            int leftColumWidth          = UI.ScaleWidth(200);
            int columHMargin            = UI.ScaleWidth(8);
            int rightMargin             = UI.ScaleWidth(8);
            int vMargin                 = UI.ScaleHeight(4);
            int rightColumnX            = leftMargin + leftColumWidth + columHMargin;
            int rightColumnWidth        = ClientSize.Width - rightColumnX - rightMargin;
            int defaultsButtonTopMargin = UI.ScaleHeight(12);
            int headerXAdjustment       = -3;

            // Left column
            this.settingsHeader.Location = new Point(leftMargin + headerXAdjustment, topMargin);
            this.settingsHeader.Width    = leftColumWidth - headerXAdjustment;
            this.settingsHeader.PerformLayout();

            this.saveConfigPanel.Location = new Point(leftMargin, this.settingsHeader.Bottom + vMargin);
            this.saveConfigPanel.Width    = leftColumWidth;
            this.saveConfigPanel.PerformLayout();

            //this.saveConfigWidget.Location = new Point(0, 0);
            this.saveConfigWidget.Width = this.saveConfigPanel.Width - SystemInformation.VerticalScrollBarWidth;

            // Right column
            this.previewHeader.Location = new Point(rightColumnX + headerXAdjustment, topMargin);
            this.previewHeader.Width    = rightColumnWidth - headerXAdjustment;
            this.previewHeader.PerformLayout();

            this.documentView.Location = new Point(rightColumnX, this.previewHeader.Bottom + vMargin);
            this.documentView.Size     = new Size(
                rightColumnWidth,
                this.baseCancelButton.Top - previewBottomMargin - this.documentView.Top);

            // Finish up setting the height on the left side
            this.saveConfigPanel.Height = this.documentView.Bottom - this.saveConfigPanel.Top -
                                          this.defaultsButton.Height - defaultsButtonTopMargin;

            this.saveConfigWidget.PerformLayout();

            int saveConfigHeight = Math.Min(this.saveConfigPanel.Height, this.saveConfigWidget.Height);

            this.defaultsButton.PerformLayout();

            this.defaultsButton.Location = new Point(
                leftMargin + (leftColumWidth - this.defaultsButton.Width) / 2,
                this.saveConfigPanel.Top + saveConfigHeight + defaultsButtonTopMargin);

            MinimumSize = UI.ScaleSize(unscaledMinSize);

            base.OnLayout(levent);
        }