コード例 #1
0
        public void pnlSoftwarePreview_Paint(object sender, PaintEventArgs e)
        {
            if (Globals.Root == null)
            {
                return;
            }
            RectangleF destination = new RectangleF(0, 0, pnlSoftwarePreview.Width, pnlSoftwarePreview.Height);

            using (NetCanvas canvas = new NetCanvas(e.Graphics))
            {
                switch (m_Style.ImageType)
                {
                case ButtonStyle.ImageTypes.RoundButton:
                    ScalableImage.RoundButton((int)State).Draw(canvas, destination);
                    break;

                case ButtonStyle.ImageTypes.GlassButton:
                    ScalableImage.PaletteButton((int)State).Draw(canvas, destination);
                    break;

                case ButtonStyle.ImageTypes.Windows:
                    ButtonRenderer.DrawButton(e.Graphics, destination.ToRectangle(), false, ButtonStyle.WindowsPushButtonState(State));
                    break;
                }
            }
        }
コード例 #2
0
ファイル: NetCanvas.cs プロジェクト: stuart2w/SAW
        public static readonly NetCanvas MeasurementInstance;         // used by the internal MeasureText, but not returned by the CreateGraphics (in case the caller manipulates it)

        static NetCanvas()
        {
            // must be after SystemDPI set (currently in frmMenu.Load)
            Debug.Assert(GUIUtilities.SystemDPI > 0);
            m_bmp = new Bitmap(1, 1);             //, Imaging.PixelFormat.Format32bppArgb)
            m_bmp.SetResolution(GUIUtilities.SystemDPI, GUIUtilities.SystemDPI);
            MeasurementInstance = new NetCanvas(CreateGraphics(true));
        }
コード例 #3
0
ファイル: PaletteView.cs プロジェクト: stuart2w/SAW
        protected override void View_Paint(object sender, PaintEventArgs e)
        {
            // We don't use the base class logic because the last several bits we don't really want:
            // we don't want the usual page background with a grid.  Helpful to have the grid when editing, but we don't want it to display at runtime
            // There is also no need to draw the outside page area; it's nicer just to extend the background colour is needed
            m_BaseBuffer.InvalidateAll();
            if (this.DesignMode)
            {
                return;
            }
            if (m_Page == null)
            {
                e.Graphics.Clear(Color.Tomato);
                return;
            }
            try
            {
                using (Graphics gr = m_BaseBuffer.PrepareDraw())
                {
                    using (NetCanvas canvas = new NetCanvas(gr))
                    {
                        if (gr != null)
                        {
                            // some redrawing is required
                            PrepareGraphics(gr);
                            gr.Clear(Color.FromKnownColor(KnownColor.Control));
                            //gr.Clear(m_Page.Colour)
                            //m_Page.DrawBackground(gr, m_zoom)' Would also draw grid and (possibly) origin
                            if (!BeingEdited)
                            {
                                m_Page.DrawShapes(canvas, m_Zoom, m_PixelsPerDocumentX, this);
                            }
                            else
                            {
                                using (System.Drawing.Drawing2D.HatchBrush br = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.DiagonalCross, Color.FromArgb(255, 200, 200), Color.Empty))
                                {
                                    gr.FillRectangle(br, m_Page.Bounds);
                                }

                                using (Font objFont = new Font(FontFamily.GenericSansSerif, 14f / (m_Zoom * m_PixelsPerDocumentX), FontStyle.Bold, GraphicsUnit.Point)
                                       )                          // Division is because a scale transform is applied to increase size by this
                                {
                                    gr.DrawString(Strings.Item("Palette_BeingEdited"), objFont, Brushes.DarkGray, m_Page.Bounds, GUIUtilities.StringFormatCentreCentre);
                                }
                            }
                            // Does not draw the outside valid page grey area
                        }
                    }
                }

                // now that the buffers are ready, we can draw it on screen
                e.Graphics.DrawImageUnscaled(m_BaseBuffer.m_bmp, 0, 0);
            }
            catch (Exception ex)
            {
                Utilities.LogSubError(ex.Message);
            }
        }
コード例 #4
0
        //private Preview GetPreviewFromIndex(int index)
        //{// uses panel/button list to  get the settings for this line
        //	return (Preview)m_Previews[index * 2].Tag;
        //}

        private void PreviewPanel_Paint(object sender, PaintEventArgs e)
        {
            Panel     panel  = (Panel)sender;
            Preview   info   = (Preview)(sender as Control).Tag;
            NetCanvas canvas = new NetCanvas(e.Graphics);
            //using (var back = canvas.CreateFill(
            var style = m_Config.ButtonStyle[(int)(info.Style + 2)];

            Shape.DrawResources resources = new Shape.DrawResources(1, 255, 255, false, false, canvas, StaticView.InvalidationBuffer.Base, 1);
            style.PrepareResources(info.State, resources);
            RectangleF rct = new RectangleF(1, 1, panel.Width - 2, panel.Height - 2);

            style.Draw(canvas, resources, rct, info.State);
            using (Brush br = new SolidBrush(style.TextColour[(int)info.State]))
                e.Graphics.DrawString(Strings.Item("SAW_Settings_StyleSample"), panel.Font, br, rct, GUIUtilities.StringFormatCentreCentre);
        }
コード例 #5
0
ファイル: frmPaper.cs プロジェクト: stuart2w/SAW
        public void pnlSample_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(m_Page.Colour);
            using (var canvas = new NetCanvas(e.Graphics))
            {
                // if locking page to image AR, then show the page colour in the correct proportions, with a dead grey area outside
                if (m_Page.BackgroundImage != null && m_Page.BackgroundImageMode == Page.BackgroundImageModes.LockAR)
                {
                    e.Graphics.Clear(Color.Gray);
                    Size imageSize = m_Page.BackgroundImage.GetSize();
                    imageSize.Width *= 100; imageSize.Height *= 100;                      // ensures image is too large, and therefore ScaleDestRect will fill the rectangle in one direction
                    Rectangle bounds = new Rectangle(0, 0, pnlSample.Width, pnlSample.Height);
                    GUIUtilities.CalcDestRect(imageSize, ref bounds);
                    e.Graphics.FillRectangle(new SolidBrush(m_Page.Colour), bounds);
                }

                if (m_Page.BackgroundImage != null)
                {
                    Page.DrawBackgroundImage(canvas, m_Page.BackgroundImage, m_Page.BackgroundImageMode, new RectangleF(0, 0, pnlSample.Width, pnlSample.Height), 1);
                }
                e.Graphics.TranslateTransform(0, pnlSample.Height);
                //e.Graphics.PageUnit = GraphicsUnit.Millimeter
                e.Graphics.ScaleTransform(e.Graphics.DpiX / Geometry.INCH, e.Graphics.DpiY / Geometry.INCH);
                // if the grid is not drawn, just draw it very faintly
                Color colReal = m_Paper.GridColour;
                if (!m_Paper.GridVisible)
                {
                    m_Paper.GridColour = Color.FromArgb(50, m_Paper.GridColour);
                }
                m_Paper.GridVisible = true;
                m_Paper.Dotted      = chkDotted.Checked && chkDraw.Checked;            // dotted is not compatible with transparent
                m_Paper.Draw(canvas, m_Page, 1);

                m_Paper.GridVisible = chkDraw.Checked;
                m_Paper.Dotted      = chkDotted.Checked;
                m_Paper.GridColour  = colReal;
            }
        }
コード例 #6
0
        protected void DrawInternalBackground(PaintEventArgs e, bool actionStyle)
        {
            // should be called as the first statement in OnPaint, or any overridden version of it
            ButtonShape.States state = ButtonShape.States.Normal;
            if (this.DesignMode && GUIUtilities.SystemDPI <= 1)
            {
                GUIUtilities.SystemDPI         = 96;
                GUIUtilities.SystemDPIRelative = 1;                 // NetCanvas requires these, but they are usually set during frmMenu_Load
            }
            using (Shape.DrawResources resources = new Shape.DrawResources(1, 255, 255, false, false, new NetCanvas(e.Graphics), StaticView.InvalidationBuffer.Base, 1))
            {
                if (!Enabled)
                {
                    state = ButtonShape.States.Disabled;
                }
                else if (m_SelectionDisplayFraction == 255 && m_Applicable && Enabled)
                {
                    state = ButtonShape.States.Selected;
                }
                else if (m_Hover || Focused)
                {
                    state = ButtonShape.States.Highlight;
                }
                else if (m_NoUser)
                {
                    resources.FillAlpha = 90;                     // Need to fade quite a lot, because it is only the background which fades.  Even 100 wasnt visible
                    resources.EdgeAlpha = 90;
                }
                ButtonStyle style;
                if (this.DesignMode)
                {
                    style = ButtonStyle.UserDefaultSelectionInstance;
                }
                else
                {
                    style = Config.UserUser.ButtonStyle[actionStyle ? 0 : 1];
                }
                style.PrepareResources(state, resources);
                RectangleF border     = new RectangleF(0, 0, Width, Height);
                var        styleState = state == ButtonShape.States.Disabled ? ButtonShape.States.Normal : state;          // The index for the actual style object used (there isn't one for disabled)
                // For the default backgrounds (only) it is also necessary to scale the graphics to work in (approximately) mm
                if (style.ImageType == ButtonStyle.ImageTypes.None)
                {
                    float scale = e.Graphics.DpiX / Geometry.INCH;
                    border.Width  = (border.Width - 1) / scale;                    // -1 because the graphics need the rectangle to be within the bounds for DrawRectangle
                    border.Height = (border.Height - 1) / scale;
                    // The standard border draws exactly ALONG the rectangle; we need to draw inside!
                    border.Inflate(-style.LineStyle[(int)styleState].Width / 2 - 1, -style.LineStyle[(int)styleState].Width / 2 - 1);
                    e.Graphics.ScaleTransform(scale, scale);
                }
                using (NetCanvas canvas = new NetCanvas(e.Graphics))
                {
                    style.Draw(canvas, resources, border, state);
                    if (m_SelectionDisplayFraction > 0 && m_SelectionDisplayFraction < 255 && m_Applicable && Enabled)
                    {
                        // fading in the selection colour
                        resources.FillAlpha = m_SelectionDisplayFraction;
                        resources.EdgeAlpha = m_SelectionDisplayFraction;
                        style.Draw(canvas, resources, border, ButtonShape.States.Selected);
                    }
                }

                e.Graphics.ResetTransform();
            }
        }
コード例 #7
0
ファイル: StaticView.cs プロジェクト: stuart2w/SAW
        // we need to remember where we have drawn selection boundary because the page itself only requests refreshes of the objects whose selection changes
        // and not the entire selection box

        protected virtual void View_Paint(object sender, PaintEventArgs e)
        {
            if (this.DesignMode)
            {
                return;
            }
            if (m_Page == null || m_Page.IsDisposed)
            {
                e.Graphics.Clear(Color.Tomato);
                return;
            }
            try
            {
                Graphics gr = m_BaseBuffer.PrepareDraw();
                if (gr != null)
                {
                    var canvas = new NetCanvas(gr);
                    try
                    {
                        // some redrawing is required
                        PrepareGraphics(gr);
                        m_Page.DrawBackground(canvas, m_Zoom, true, !(this is RunView), !(this is RunView));                         // grid (and origin) disabled when running
                        if (!Globals.Root.CurrentConfig.Low_Graphics)
                        {
                            gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        }
                        // if the page does not fill the control, then draw a grey area outside page
                        // it is helpful of this is done after drawing the page itself in case anything on the page has fallen off
                        m_Page.DrawShapes(canvas, m_Zoom, m_PixelsPerDocumentX, this);

                        // if the page is too short, then the bottom of the screen contains the actual page
                        gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;                         // AA would blur the pixel boundary between the two, leaving it neither page colour nor outside colour
                        if (Width > m_ClientSize.Width)
                        {
                            gr.FillRectangle(OUTSIDEPAGECOLOUR, m_Page.Size.Width, -10000 / m_Zoom, 10000 / m_Zoom, 11000 / m_Zoom);
                        }
                        gr.PageUnit = GraphicsUnit.Pixel;
                        gr.ResetTransform();
                        if (Height > m_ClientSize.Height)
                        {
                            gr.FillRectangle(OUTSIDEPAGECOLOUR, 0, Convert.ToInt32(m_Page.Size.Height * m_Zoom * m_PixelsPerDocumentY), Width, Height - m_Page.Size.Height * m_Zoom * m_PixelsPerDocumentY);
                        }
                    }
                    finally
                    {
                        gr.Dispose();
                        canvas.Dispose();
                    }
                }
                PaintEditing(e);

                // now that the buffers are ready, we can draw it on screen
                e.Graphics.DrawImageUnscaled(m_BaseBuffer.m_bmp, 0, 0);
                PaintEditingBuffers(e);
            }
            catch (Exception ex) when(!Globals.Root.IsDebug)
            {
                // Leave a breakpoint here for debug mode (multiple assertions can get nasty)
                Utilities.LogSubError(ex.Message);
            }
        }