Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);

                PushButtonState state;

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

                bool drawOutline;

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

                case PushButtonState.Pressed:
                    drawOutline = false;
                    break;

                case PushButtonState.Default:
                case PushButtonState.Disabled:
                case PushButtonState.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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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;

            for (int i = 0; i < this.toolConfigRows.Count; ++i)
            {
                this.toolConfigRows[i].HeaderLabel.Location = new Point(leftMargin, y);
                this.toolConfigRows[i].HeaderLabel.Width    = insetWidth;
                y = this.toolConfigRows[i].HeaderLabel.Bottom + afterHeaderVMargin;

                this.toolConfigRows[i].ToolConfigStrip.Location = new Point(leftMargin + 3, y);
                Size preferredSize = this.toolConfigRows[i].ToolConfigStrip.GetPreferredSize(
                    new Size(this.toolConfigRows[i].ToolConfigStrip.Width, 1));

                this.toolConfigRows[i].ToolConfigStrip.Size = preferredSize;

                maxInsetWidth = Math.Max(maxInsetWidth, this.toolConfigRows[i].ToolConfigStrip.Width);

                y = this.toolConfigRows[i].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);
        }
Exemplo n.º 5
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();
                textBrush = null;
            }

            stringFormat.Dispose();
            stringFormat = null;

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

            return(layoutSize);
        }
Exemplo n.º 6
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);
            clipRegion.Dispose();
        }