Ejemplo n.º 1
0
 /// <summary>
 /// Called by CanvasRenderingContext2D in order to notify parent objects 
 /// that changes were made, so redrawing should be performed if necessary.
 /// </summary>
 public void ReDraw()
 {
     //if this is IE
     if (_paintSite != null)
     {
         var rect = new tagRECT();
         rect.top = 0;
         rect.bottom = height; // + _element.Top;
         rect.left = 0;
         rect.right = width; // + _element.Left;
         _paintSite.InvalidateRect(ref rect);
     }
     // belongs in HTMLCanvasElement?
     // _isChanged = true;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// IE will, in fact, call Draw() more than once in drawing the element, as it paints the element rectangle in successive horizontal bands. 
        /// For this reason, it is best to prepare an off-screen bitmap image before element invalidation, so that successive calls to Draw() 
        /// deal with an unchanging graphic. When IE calls Draw(), the drawing requirements dictated by IE are obtained through GetDrawInfo(), 
        /// and any necessary image transformation and clipping can then be applied before rendering with Graphics.DrawImage().
        /// </summary>
        /// <param name="rcBounds"></param>
        /// <param name="rcUpdate"></param>
        /// <param name="lDrawFlags"></param>
        /// <param name="hdc"></param>
        /// <param name="pvDrawObject"></param>
        // FIXME: Move this to an IE specific HTMLCanvasElement implementation.
        public void Draw(tagRECT rcBounds, tagRECT rcUpdate, int lDrawFlags, IntPtr hdc, IntPtr pvDrawObject)
        {
            // _element.Paint -= _element.HTMLCanvasElement_Paint;

            _graphics = Graphics.FromHdc(hdc);
            _graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

            // Apply any scaling, etc. to the output.
            _HTML_PAINT_DRAW_INFO info;
            _paintSite.GetDrawInfo(
                (int)_HTML_PAINT_DRAW_INFO_FLAGS.HTMLPAINT_DRAWINFO_XFORM |
                (int)_HTML_PAINT_DRAW_INFO_FLAGS.HTMLPAINT_DRAWINFO_UPDATEREGION,
                out info);
            var xform = new System.Drawing.Drawing2D.Matrix(
                info.xform.eM11, info.xform.eM12,
                info.xform.eM21, info.xform.eM22,
                info.xform.eDx - rcBounds.left, info.xform.eDy - rcBounds.top);
            _graphics.Transform = xform;

            // Update clipping region.
            var clip = new Region();
            if (info.hrgnUpdate != IntPtr.Zero)
            {
                Region updateclip = Region.FromHrgn(info.hrgnUpdate);
                clip.Intersect(updateclip);
                clip.Translate(rcBounds.left, rcBounds.top);
            }
            _graphics.SetClip(clip, System.Drawing.Drawing2D.CombineMode.Replace);

            if (init != null) //run only once
            {
                _init.GetType().InvokeMember("", System.Reflection.BindingFlags.InvokeMethod, null, _init,
                                             new object[] { });
                _init = null;
            }

            // _element.Draw(_graphics, rcBounds, rcUpdate);
            _graphics.Dispose();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get necessary part of the whole image and draw it on the specified surface
        /// </summary>
        /// <param name="graphics">surface to draw</param>
        /// <param name="rcBounds">allowed rectangle to draw in</param>
        /// <param name="rcUpdate">rectangle to update</param>
        private void Draw(Graphics graphics, tagRECT rcBounds, tagRECT rcUpdate)
        {
            Bitmap bitmap;
            if (_canvas != null)
            {
                //_canvas.commit();
                bitmap = _canvas.GetBitmap();
                int x = rcUpdate.left;
                int y = rcUpdate.top;
                int x1 = rcUpdate.left - rcBounds.left;
                int y1 = rcUpdate.top - rcBounds.top;
                int width1 = rcUpdate.right - rcUpdate.left;
                int height1 = rcUpdate.bottom - rcUpdate.top;
                if (bitmap.Width < width1)
                {
                    width1 = bitmap.Width;
                }
                if (bitmap.Height < height1)
                {
                    height1 = bitmap.Height;
                }
                var rect = new Rectangle(x1,
                                         y1,
                                         width1,
                                         height1);
                //graphics.DrawRectangle(new Pen(Color.White), rect);

                graphics.DrawImage(bitmap, x, y,
                                   rect,
                                   GraphicsUnit.Pixel);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Called by CanvasRenderingContext2D in order to notify parent objects 
 /// that some changes were made in image, so redrawing should be performed if necessary.
 /// </summary>
 public void ReDraw()
 {
     //if this is IE
     if (_paintSite != null)
     {
         var rect = new tagRECT();
         rect.top = 0;
         //rect.bottom = Top + height;
         rect.bottom = height;
         rect.left = 0;
         rect.right = width;
         //rect.right = Left + width;
         _paintSite.InvalidateRect(ref rect);
     }
     //mark current canvas element as changed
     _isChanged = true;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Get rectagnle area equal to current control's size
 /// </summary>
 /// <returns></returns>
 private tagRECT GetEmptyUpdate()
 {
     var update = new tagRECT();
     update.left = 0;
     update.top = 0;
     update.right = width;
     update.bottom = height;
     return update;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Get zero-initialized rectangle
 /// </summary>
 /// <returns></returns>
 private tagRECT GetEmptyBound()
 {
     var bound = new tagRECT();
     bound.left = 0;
     bound.top = 0;
     return bound;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Get necessary part of the whole image and draw it on the specified surface
        /// </summary>
        /// <param name="graphics">surface to draw</param>
        /// <param name="rcBounds">allowed rectangle to draw in</param>
        /// <param name="rcUpdate">rectangle to update</param>
        private void Draw(Graphics graphics, tagRECT rcBounds, tagRECT rcUpdate)
        {
            Bitmap bitmap;
            if (_canvas != null)
            {
                int x = rcUpdate.left;
                int y = rcUpdate.top;
                int x1 = rcUpdate.left - rcBounds.left;
                int y1 = rcUpdate.top - rcBounds.top;
                int width1 = rcUpdate.right - rcUpdate.left;
                int height1 = rcUpdate.bottom - rcUpdate.top;

                lock (sync)
                {
                    bitmap = _canvas.GetBitmap();
                    if (bitmap.Width < width1)
                    {
                        width1 = bitmap.Width;
                    }
                    if (bitmap.Height < height1)
                    {
                        height1 = bitmap.Height;
                    }
                    var rect = new Rectangle(x1,
                                             y1,
                                             width1,
                                             height1);
                    graphics.DrawImage(bitmap, x, y,
                                       rect,
                                       GraphicsUnit.Pixel);
                    //graphics.DrawString(string.Format("bW = {0}, gW = {1}", bitmap.Width, graphics.VisibleClipBounds.Width), new Font("Arial", 5), new SolidBrush(Color.Black), x1, y1);
                }
            }
        }