Beispiel #1
0
        public void Clipping()
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                // start with a blue background.
                using (var blueBrush = new SolidBrush(Color.Blue))
                {
                    gr.Graphics.FillRectangle(blueBrush, new Rectangle(0, 0, 1000, 1000));

                    // Check that filling with a blue brush worked.
                    Assert.IsTrue(ColorCompare(gr.Bitmap.GetPixel(500, 500), Color.Blue));

                    //
                    // Check that drawing using a VwGraphics works.
                    //

                    vwGraphics.Initialize(gr.Graphics.GetHdc());

                    vwGraphics.PushClipRect(new Utils.Rect(0, 0, 1000, 1000));
                    vwGraphics.BackColor = ConvertToVwGraphicsColor(Color.Red);
                    vwGraphics.DrawRectangle(0, 0, 1000, 1000);

                    vwGraphics.PopClipRect();

                    vwGraphics.ReleaseDC();
                    gr.Graphics.ReleaseHdc();

                    gr.Graphics.Flush();

                    // Check that drawing a red rectangle using the VwGraphics Interface worked
                    Assert.IsTrue(ColorCompare(gr.Bitmap.GetPixel(500, 500), Color.Red));

                    /////
                    // Check that VwGraphics doesn't draw outside its clip rect.
                    /////

                    vwGraphics.Initialize(gr.Graphics.GetHdc());
                    // make the clip rect not include the area we are going to draw to.
                    vwGraphics.PushClipRect(new Utils.Rect(100, 100, 200, 200));

                    // attempt to draw off the clip rect.
                    vwGraphics.BackColor = ConvertToVwGraphicsColor(Color.Green);
                    vwGraphics.DrawRectangle(400, 400, 600, 600);

                    vwGraphics.PopClipRect();

                    vwGraphics.ReleaseDC();
                    gr.Graphics.ReleaseHdc();

                    gr.Graphics.Flush();

                    // Check that the green rectangle didn't appear on screen.
                    Assert.IsTrue(!ColorCompare(gr.Bitmap.GetPixel(500, 500), Color.Green));
                }
            }
        }
Beispiel #2
0
        protected void ProcessInitialize(IEnumerable <string> arguments)
        {
            string handle = arguments.Skip(1).First();


            if (VwGraphicsLookup.Keys.Contains(handle))
            {
                var      bitmap = new Bitmap(1000, 1000);
                Graphics gr     = Graphics.FromImage(bitmap);
                VwGraphicsLookup[handle].Initialize(gr.GetHdc());
                GraphicsLookup[handle] = gr;
                BitmapLookup[handle]   = bitmap;
            }
            else
            {
                IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();
                var      bitmap             = new Bitmap(1000, 1000);
                Graphics gr = Graphics.FromImage(bitmap);
                vwGraphics.Initialize(gr.GetHdc());
                VwGraphicsLookup.Add(handle, vwGraphics);
                GraphicsLookup[handle] = gr;
                BitmapLookup[handle]   = bitmap;

                m_vwGraphics32 = vwGraphics;
            }
        }
Beispiel #3
0
        public void GetTextExtentWithEmptyString()
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                const int areaWidth  = 1000;
                const int areaHeight = 1000;

                vwGraphics.Initialize(gr.Graphics.GetHdc());

                vwGraphics.PushClipRect(new Utils.Rect(0, 0, areaWidth, areaHeight));
                vwGraphics.ForeColor = ConvertToVwGraphicsColor(Color.Black);

                int extentX;
                int extentY;

                vwGraphics.GetTextExtent(0, String.Empty, out extentX, out extentY);

                Assert.That(extentX == 0, "extentX should equal 0");
                Assert.That(extentY > 0, "extentY should be greater than 0");

                vwGraphics.PopClipRect();

                vwGraphics.ReleaseDC();
                gr.Graphics.ReleaseHdc();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Draw the text using the FieldWorks IVwGraphicsWin32 interface.
        /// </summary>
        /// <remarks>Only used with Mono</remarks>
        private void DrawFwText(Graphics graphics, Rectangle cellBounds,
                                string text, DataGridViewCellStyle cellStyle, FwTextBoxColumn col)
        {
            Debug.Assert(Platform.IsMono, "This method is only needed on Mono");
            if (String.IsNullOrEmpty(text))
            {
                return;
            }
            IntPtr           hdc = graphics.GetHdc();
            IVwGraphicsWin32 vg  = VwGraphicsWin32Class.Create();               // actually VwGraphicsCairo

            try
            {
                vg.Initialize(hdc);
                var renderProps = GetRenderProps(cellStyle, col);
                vg.SetupGraphics(ref renderProps);
                int x;
                int y;
                GetLocationForText(cellBounds, (col.TextBoxControl.RightToLeft == RightToLeft.Yes),
                                   vg, text, out x, out y);
                vg.PushClipRect(cellBounds);
                vg.DrawText(x, y, text.Length, text, 0);
                vg.PopClipRect();
            }
            finally
            {
                vg.ReleaseDC();
                graphics.ReleaseHdc(hdc);
            }
        }
        /// <summary>
        /// See C++ documentation
        /// </summary>
        public void DrawTheRootAt(IVwRootBox prootb, IntPtr hdc, Rect rcpDraw, uint bkclr,
                                  bool fDrawSel, IVwGraphics pvg, Rect rcSrc, Rect rcDst, int ysTop, int dysHeight)
        {
            IVwGraphicsWin32 qvg32 = VwGraphicsWin32Class.Create();

            using (Graphics screen = Graphics.FromHdc(hdc))
            {
                Rectangle rcp    = rcpDraw;
                Rectangle rcFill = new Rect(0, 0, rcp.Width, rcp.Height);

                using (var memoryBuffer = new MemoryBuffer(rcp.Width, rcp.Height))
                {
                    memoryBuffer.Graphics.FillRectangle(new SolidBrush(ColorUtil.ConvertBGRtoColor(bkclr)), rcFill);

                    qvg32.Initialize(memoryBuffer.Graphics.GetHdc());
                    qvg32.XUnitsPerInch = rcDst.right - rcDst.left;
                    qvg32.YUnitsPerInch = rcDst.bottom - rcDst.top;

                    try
                    {
                        prootb.DrawRoot2(qvg32, rcSrc, rcDst, fDrawSel, ysTop, dysHeight);
                    }
                    catch (Exception)
                    {
                        qvg32.ReleaseDC();
                        throw;
                    }

                    screen.DrawImageUnscaled(memoryBuffer.Bitmap, rcp);

                    qvg32.ReleaseDC();
                }
            }
        }
Beispiel #6
0
        public void SimpleCreationAndRelease()
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                vwGraphics.Initialize(gr.Graphics.GetHdc());
                vwGraphics.ReleaseDC();
            }
        }
        /// <summary>
        /// Draws the Root into a memory buffer, then rotates it 90deg clockwise while drawing
        /// the memory buffer to the screen.
        /// See C++ documentation for more info.
        /// </summary>
        public void DrawTheRootRotated(IVwRootBox rootb, IntPtr hdc, Rect rcpDraw, uint bkclr,
                                       bool fDrawSel, IVwRootSite vrs, int nHow)
        {
            IVwGraphicsWin32 qvg32  = VwGraphicsWin32Class.Create();
            Rectangle        rcp    = new Rectangle(rcpDraw.top, rcpDraw.left, rcpDraw.bottom, rcpDraw.right);
            Rectangle        rcFill = new Rect(0, 0, rcp.Width, rcp.Height);

            using (Graphics screen = Graphics.FromHdc(hdc))
                using (var memoryBuffer = new MemoryBuffer(rcp.Width, rcp.Height))
                {
                    memoryBuffer.Graphics.FillRectangle(new SolidBrush(ColorUtil.ConvertBGRtoColor(bkclr)), rcFill);
                    qvg32.Initialize(memoryBuffer.Graphics.GetHdc());

                    IVwGraphics qvgDummy = null;
                    try
                    {
                        Rect rcDst, rcSrc;
                        vrs.GetGraphics(rootb, out qvgDummy, out rcSrc, out rcDst);
                        Rectangle temp = rcDst;
                        temp.Offset(-rcp.Left, -rcp.Top);
                        rcDst = temp;

                        qvg32.XUnitsPerInch = qvgDummy.XUnitsPerInch;
                        qvg32.YUnitsPerInch = qvgDummy.YUnitsPerInch;

                        rootb.DrawRoot(qvg32, rcSrc, rcDst, fDrawSel);
                        vrs.ReleaseGraphics(rootb, qvgDummy);
                        qvgDummy = null;
                    }
                    catch (Exception)
                    {
                        if (qvgDummy != null)
                        {
                            vrs.ReleaseGraphics(rootb, qvgDummy);
                        }
                        qvg32.ReleaseDC();
                        throw;
                    }

                    Point[] rgptTransform = new Point[3];
                    rgptTransform[0] = new Point(rcpDraw.right, rcpDraw.top);            // upper left of actual drawing maps to top right of rotated drawing

                    rgptTransform[1] = new Point(rcpDraw.right, rcpDraw.bottom);         // upper right of actual drawing maps to bottom right of rotated drawing.
                    rgptTransform[2] = new Point(rcpDraw.left, rcpDraw.top);             // bottom left of actual drawing maps to top left of rotated drawing.

                    screen.DrawImage((Image)memoryBuffer.Bitmap, rgptTransform, new Rectangle(0, 0, rcp.Width, rcp.Height), GraphicsUnit.Pixel);

                    qvg32.ReleaseDC();
                }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Make sure the graphics object has a DC. If it already has, increment a count,
        /// so we know when to really free the DC.
        /// </summary>
        /// <param name="dpix">The DPI in the x direction.</param>
        /// <param name="dpiy">The DPI in the y direction.</param>
        /// <param name="zoom">The zoom percentage.</param>
        /// ------------------------------------------------------------------------------------
        private void Init(int dpix, int dpiy, float zoom)
        {
            CheckDisposed();

            if (m_cactInitGraphics == 0)
            {
                // We are asking for a VwGraphics but haven't been given a DC. Make one.
                // (ReleaseHdc is called in Uninit!)
                // TODO: we might want a graphics appropriate for our printer.
                m_graphics = m_parent.CreateGraphics();
                if (m_vwGraphics == null)
                {
                    m_vwGraphics = VwGraphicsWin32Class.Create();
                }

                if (m_graphics != null)
                {
                    if (dpix <= 0)
                    {
                        dpix = (int)(m_graphics.DpiX * zoom);
                    }
                    if (dpiy <= 0)
                    {
                        dpiy = (int)(m_graphics.DpiY * zoom);
                    }
                    IntPtr hdc = m_graphics.GetHdc();
                    m_vwGraphics.Initialize(hdc);
                }
                else
                {
                    // we think m_graphics should never be null. But it has happened (see e.g. LTB-708).
                    // So provide a desperate fall-back.
                    if (dpix <= 0)
                    {
                        dpix = 96;
                    }
                    if (dpiy <= 0)
                    {
                        dpiy = 96;
                    }
                    SIL.Utils.Logger.WriteEvent(String.Format("WARNING: failed to create m_graphics in GraphicsManager.Init({0}, {1}, {2})", dpix, dpiy, zoom));
                }
                m_vwGraphics.XUnitsPerInch = dpix;
                m_vwGraphics.YUnitsPerInch = dpiy;
            }
            m_cactInitGraphics++;
        }
Beispiel #9
0
        public void LargeRectangles()
        {
            // EB/2011-02-08: this test is failing for me on Linux. Not sure if it should work
            // or what (see FWNX-449). Test is failing in FillRectangle similar to the failure
            // in the following comment
            // https://www.jira.insitehome.org/browse/FWNX-449?focusedCommentId=108054&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-108054
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            const int width  = 1241;
            const int height = 56080;             // something bigger than MAX_IMAGE_SIZE (32767)

            using (var gr = new GraphicsObjectFromImage(width, height))
            {
                // start with a blue background.
                using (var blueBrush = new SolidBrush(Color.Blue))
                {
                    gr.Graphics.FillRectangle(blueBrush, new Rectangle(0, 0, width, height));

                    // Check that filling with a blue brush worked.
                    Assert.IsTrue(ColorCompare(gr.Bitmap.GetPixel(width - 1, height - 1), Color.Blue));

                    /////
                    // Check that drawing using a VwGraphics works.
                    ////

                    vwGraphics.Initialize(gr.Graphics.GetHdc());

                    vwGraphics.PushClipRect(new Utils.Rect(0, 0, width, height));
                    vwGraphics.BackColor = ConvertToVwGraphicsColor(Color.Red);
                    vwGraphics.DrawRectangle(0, 0, width, height);

                    vwGraphics.PopClipRect();

                    vwGraphics.ReleaseDC();
                    gr.Graphics.ReleaseHdc();

                    gr.Graphics.Flush();

                    // Check that drawing a red rectangle using the VwGraphics Interface worked
                    Assert.IsTrue(ColorCompare(gr.Bitmap.GetPixel(width - 1, height - 1), Color.Red));
                }
            }
        }
Beispiel #10
0
        internal void TestGetTextExtentHelper(string testString)
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                const int areaWidth  = 500;
                const int areaHeight = 500;

                // start with a White background.
                using (var blueBrush = new SolidBrush(Color.White))
                {
                    gr.Graphics.FillRectangle(blueBrush, new Rectangle(0, 0, areaWidth, areaHeight));

                    Assert.AreEqual(-1, SearchForBottomMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight), "Should all be white #1");
                    Assert.AreEqual(-1, SearchForRightMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight), "Should all be white #2");

                    vwGraphics.Initialize(gr.Graphics.GetHdc());

                    vwGraphics.PushClipRect(new Utils.Rect(0, 0, areaWidth, areaHeight));
                    vwGraphics.ForeColor = ConvertToVwGraphicsColor(Color.Black);

                    int extentX;
                    int extentY;

                    vwGraphics.GetTextExtent(testString.Length, testString, out extentX, out extentY);

                    Assert.That(extentX > 0, "extentX should be greater than 0");
                    Assert.That(extentY > 0, "extentY should be greater than 0");

                    vwGraphics.DrawText(0, 0, testString.Length, testString, 0);

                    vwGraphics.PopClipRect();

                    vwGraphics.ReleaseDC();
                    gr.Graphics.ReleaseHdc();
                    gr.Graphics.Flush();

                    Assert.That(SearchForBottomMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight) <= extentY, String.Format("Should be <= {0}", extentY));
                    Assert.That(SearchForRightMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight) <= extentX, String.Format("Should be <= {0}", extentX));
                }
            }
        }
Beispiel #11
0
        public void ComplexClipping()
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                vwGraphics.Initialize(gr.Graphics.GetHdc());

                // Test on a single push
                int left, top, right, bottom;

                vwGraphics.PushClipRect(new Utils.Rect(50, 60, 500, 510));
                vwGraphics.GetClipRect(out left, out top, out right, out bottom);
                Assert.AreEqual(50, left, "Left doesn't match");
                Assert.AreEqual(60, top, "Top doesn't match");
                Assert.AreEqual(500, right, "Right doesn't match");
                Assert.AreEqual(510, bottom, "Bottom doesn't match");

                // Test on a second push
                vwGraphics.PushClipRect(new Utils.Rect(1, 1, 300, 310));
                vwGraphics.GetClipRect(out left, out top, out right, out bottom);
                Assert.AreEqual(50, left, "Left doesn't match");
                Assert.AreEqual(60, top, "Top doesn't match");
                Assert.AreEqual(300, right, "Right doesn't match");
                Assert.AreEqual(310, bottom, "Bottom doesn't match");

                vwGraphics.PopClipRect();
                vwGraphics.GetClipRect(out left, out top, out right, out bottom);
                Assert.AreEqual(50, left, "Left doesn't match");
                Assert.AreEqual(60, top, "Top doesn't match");
                Assert.AreEqual(500, right, "Right doesn't match");
                Assert.AreEqual(510, bottom, "Bottom doesn't match");
                vwGraphics.PopClipRect();
                vwGraphics.GetClipRect(out left, out top, out right, out bottom);
                Assert.AreEqual(0, left, "Left doesn't match");
                Assert.AreEqual(0, top, "Top doesn't match");
                Assert.AreEqual(1000, right, "Right doesn't match");
                Assert.AreEqual(1000, bottom, "Bottom doesn't match");

                vwGraphics.ReleaseDC();
                gr.Graphics.ReleaseHdc();
            }
        }
Beispiel #12
0
        public void TextClipping()
        {
            const string longString = "abcdefghijklmnopqrstuvwzyzabcdefghijklmnopqrstuvwzyzabcdefghijklmnopqrstuvwzyz";

            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                const int areaWidth  = 500;
                const int areaHeight = 500;

                const int clipLeft  = 300;
                const int clipRight = 400;

                // start with a White background.
                using (var blueBrush = new SolidBrush(Color.White))
                {
                    gr.Graphics.FillRectangle(blueBrush, new Rectangle(0, 0, areaWidth, areaHeight));

                    Assert.AreEqual(-1, SearchForBottomMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight), "Should all be white #1");
                    Assert.AreEqual(-1, SearchForRightMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight), "Should all be white #2");

                    vwGraphics.Initialize(gr.Graphics.GetHdc());

                    vwGraphics.PushClipRect(new Utils.Rect(clipLeft, 0, clipRight, areaHeight));
                    vwGraphics.ForeColor = ConvertToVwGraphicsColor(Color.Black);

                    vwGraphics.DrawText(0, 0, longString.Length, longString, 0);

                    vwGraphics.PopClipRect();

                    vwGraphics.ReleaseDC();
                    gr.Graphics.ReleaseHdc();
                    gr.Graphics.Flush();

                    Assert.That(SearchForLeftMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight) >= clipLeft, String.Format("Should be >= {0}", clipLeft));
                    Assert.That(SearchForRightMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight) <= clipRight, String.Format("Should be <= {0}", clipRight));
                }
            }
        }
Beispiel #13
0
        public void SetClipRect()
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                vwGraphics.Initialize(gr.Graphics.GetHdc());

                int left, top, right, bottom;

                var rect = new Utils.Rect(50, 25, 1000, 1000);
                vwGraphics.SetClipRect(ref rect);
                vwGraphics.GetClipRect(out left, out top, out right, out bottom);

                Assert.AreEqual(50, left, "Left doesn't match");
                Assert.AreEqual(25, top, "Top doesn't match");
                Assert.AreEqual(1000, right, "Right doesn't match");
                Assert.AreEqual(1000, bottom, "Bottom doesn't match");
            }
        }
Beispiel #14
0
        public void GetClipRect()
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                vwGraphics.Initialize(gr.Graphics.GetHdc());

                var rect1 = new Utils.Rect(0, 0, 1000, 1000);
                var rect2 = new Utils.Rect(500, 500, 700, 700);

                vwGraphics.PushClipRect(rect1);

                int left, top, right, bottom;
                vwGraphics.GetClipRect(out left, out top, out right, out bottom);

                Assert.IsTrue(left == rect1.left, "First push failed: left");
                Assert.IsTrue(right == rect1.right, "First push failed: right");
                Assert.IsTrue(top == rect1.top, "First push failed: top");
                Assert.IsTrue(bottom == rect1.bottom, "First push failed: bottom");

                // try a second rectangle
                vwGraphics.PushClipRect(rect2);

                vwGraphics.GetClipRect(out left, out top, out right, out bottom);
                Assert.IsTrue(left == rect2.left, "Second push failed: left");
                Assert.IsTrue(right == rect2.right, "Second push failed: right");
                Assert.IsTrue(top == rect2.top, "Second push failed: top");
                Assert.IsTrue(bottom == rect2.bottom, "Second push failed: bottom");

                vwGraphics.PopClipRect();
                vwGraphics.PopClipRect();

                vwGraphics.ReleaseDC();
                gr.Graphics.ReleaseHdc();
            }
        }
Beispiel #15
0
        /// <summary>
        /// Make one with the specified control and Graphics (typically passed in to a Paint method). The Graphics will not be disposed.
        /// </summary>
        public GraphicsManager(Control c, Graphics g)
        {
            m_graphics = g;
            if (g == null)
            {
                m_graphics = c.CreateGraphics();
                m_shouldDisposeGraphics = true;
            }
            m_vwGraphics = VwGraphicsWin32Class.Create();
            double zoom = 1.0;             // eventually an argument, probably

            m_dpiX = m_graphics.DpiX;
            m_dpiY = m_graphics.DpiY;
            int    dpix = (int)(m_dpiX * zoom);
            int    dpiy = (int)(m_dpiY * zoom);
            IntPtr hdc  = m_graphics.GetHdc();

            m_vwGraphics.Initialize(hdc);
            m_vwGraphics.XUnitsPerInch = dpix;
            m_vwGraphics.YUnitsPerInch = dpiy;
            m_vwGraphics.BackColor     = (int)FwTextColor.kclrTransparent;
        }
        /// <summary>
        /// See C++ documentation
        /// </summary>
        public void DrawTheRoot(IVwRootBox prootb, IntPtr hdc, Rect rcpDraw, uint bkclr,
                                bool fDrawSel, IVwRootSite pvrs)
        {
            IVwSynchronizer synchronizer = prootb.Synchronizer;

            if (synchronizer != null)
            {
                try
                {
                    if (synchronizer.IsExpandingLazyItems)
                    {
                        return;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("call to IsExpandingLazyItems caused exceptionException e ={0}", e);
                }
            }

            IVwGraphicsWin32 qvg = VwGraphicsWin32Class.Create();
            Rectangle        rcp = rcpDraw;

            using (Graphics screen = Graphics.FromHdc(hdc))
                using (var memoryBuffer = new MemoryBuffer(rcp.Width, rcp.Height))
                {
                    memoryBuffer.Graphics.FillRectangle(new SolidBrush(ColorUtil.ConvertBGRtoColor(bkclr)), 0, 0,
                                                        rcp.Width, rcp.Height);
                    qvg.Initialize(memoryBuffer.Graphics.GetHdc());
                    VwPrepDrawResult xpdr     = VwPrepDrawResult.kxpdrAdjust;
                    IVwGraphics      qvgDummy = null;

                    try
                    {
                        Rect rcDst, rcSrc;
                        while (xpdr == VwPrepDrawResult.kxpdrAdjust)
                        {
                            pvrs.GetGraphics(prootb, out qvgDummy, out rcSrc, out rcDst);
                            Rectangle temp = rcDst;
                            temp.Offset(-rcp.Left, -rcp.Top);
                            rcDst = temp;

                            qvg.XUnitsPerInch = qvgDummy.XUnitsPerInch;
                            qvg.YUnitsPerInch = qvgDummy.YUnitsPerInch;

                            xpdr = prootb.PrepareToDraw(qvg, rcSrc, rcDst);
                            pvrs.ReleaseGraphics(prootb, qvgDummy);
                            qvgDummy = null;
                        }

                        if (xpdr != VwPrepDrawResult.kxpdrInvalidate)
                        {
                            pvrs.GetGraphics(prootb, out qvgDummy, out rcSrc, out rcDst);

                            Rectangle temp = rcDst;
                            temp.Offset(-rcp.Left, -rcp.Top);
                            rcDst = temp;

                            qvg.XUnitsPerInch = qvgDummy.XUnitsPerInch;
                            qvg.YUnitsPerInch = qvgDummy.YUnitsPerInch;

                            try
                            {
                                prootb.DrawRoot(qvg, rcSrc, rcDst, fDrawSel);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("DrawRoot e = {0} qvg = {1} rcSrc = {2} rcDst = {3} fDrawSel = {4}", e, qvg, rcSrc, rcDst, fDrawSel);
                            }
                            pvrs.ReleaseGraphics(prootb, qvgDummy);
                            qvgDummy = null;
                        }
                    }
                    catch (Exception)
                    {
                        if (qvgDummy != null)
                        {
                            pvrs.ReleaseGraphics(prootb, qvgDummy);
                        }
                        qvg.ReleaseDC();
                        throw;
                    }

                    if (xpdr != VwPrepDrawResult.kxpdrInvalidate)
                    {
                        screen.DrawImageUnscaled(memoryBuffer.Bitmap, rcp.Left, rcp.Top, rcp.Width, rcp.Height);
                    }

                    qvg.ReleaseDC();
                }
        }
Beispiel #17
0
		/// <summary>
		/// Make one with the specified control and Graphics (typically passed in to a Paint method). The Graphics will not be disposed.
		/// </summary>
		public GraphicsManager(Control c, Graphics g)
		{
			m_graphics = g;
			if (g == null)
			{
				m_graphics = c.CreateGraphics();
				m_shouldDisposeGraphics = true;
			}
			m_vwGraphics = VwGraphicsWin32Class.Create();
			double zoom = 1.0; // eventually an argument, probably
			m_dpiX = m_graphics.DpiX;
			m_dpiY = m_graphics.DpiY;
			int dpix = (int)(m_dpiX * zoom);
			int dpiy = (int)(m_dpiY * zoom);
			IntPtr hdc = m_graphics.GetHdc();
			m_vwGraphics.Initialize(hdc);
			m_vwGraphics.XUnitsPerInch = dpix;
			m_vwGraphics.YUnitsPerInch = dpiy;
			m_vwGraphics.BackColor = (int)FwTextColor.kclrTransparent;
		}