PaintBorders() private method

private PaintBorders ( CssBox box, RectangleF rect ) : void
box CssBox
rect PixelFarm.Drawing.RectangleF
return void
Esempio n. 1
0
        /// <summary>
        /// Paints the fragment
        /// </summary>
        /// <param name="g">the device to draw to</param>
        protected override void PaintImp(PaintVisitor p)
        {
#if DEBUG
            p.dbugEnterNewContext(this, PaintVisitor.PaintVisitorContextName.Init);
#endif
            Color bgColorHint = p.CurrentSolidBackgroundColorHint;//save
            var   rect        = new RectangleF(0, 0, this.VisualWidth, this.VisualHeight);
            if (rect.Height > 2 && RenderUtils.IsColorVisible(ActualBackgroundColor))
            {
                p.FillRectangle(ActualBackgroundColor, rect.Left, rect.Top, rect.Width, rect.Height);
            }

            if (rect.Height > 1)
            {
                p.PaintBorders(this, rect);
            }
            else
            {
                p.PaintBorder(this, CssSide.Top, this.BorderTopColor, rect);
            }
            p.CurrentSolidBackgroundColorHint = bgColorHint;//restore

#if DEBUG
            p.dbugExitContext();
#endif
        }
Esempio n. 2
0
        protected virtual void PaintImp(PaintVisitor p)
        {
            //if (this.dbugMark2 == 10 || this.dbugMark2 == 12)
            //{

            //}

            Css.CssDisplay display = this.CssDisplay;
            if (display == Css.CssDisplay.TableCell &&
                this.EmptyCells == Css.CssEmptyCell.Hide &&
                this.IsSpaceOrEmpty)
            {
                return;
            }
#if DEBUG
            p.dbugEnterNewContext(this, PaintVisitor.PaintVisitorContextName.Init);
#endif

            //----------------------------------------------- 
            bool hasPrevClip = false;
            RectangleF prevClip = RectangleF.Empty;
            p.EnterNewLatePaintContext();
            //---------------------------------------------
            //if (display != Css.CssDisplay.Inline ||
            //    this.Position == Css.CssPosition.Absolute ||
            //    this.Position == Css.CssPosition.Fixed)
            if (this._renderBGAndBorder)
            {
                RectangleF bound = new RectangleF(0, 0, this.VisualWidth, this.VisualHeight);
                PaintBackground(p, bound, true, true);
                if (this.HasSomeVisibleBorder)
                {
                    p.PaintBorders(this, bound, true, true);
                }
#if DEBUG
                dbugPaint(p, bound);
#endif
            }

            //---------------------------------------------
            if (this.LineBoxCount > 0)
            {
                float viewport_top = p.ViewportTop;
                float viewport_bottom = p.ViewportBottom;
                int drawState = 0;
                var c_lineNode = this._clientLineBoxes.First;
                while (c_lineNode != null)
                {
                    CssLineBox line = c_lineNode.Value;
                    if (line.CachedLineBottom >= viewport_top &&
                        line.CachedLineTop <= viewport_bottom)
                    {
#if DEBUG
                        dbugCounter.dbugLinePaintCount++;
#endif

                        drawState = 1;//drawing in viewport area
                        int cX = p.CanvasOriginX;
                        int cy = p.CanvasOriginY;
                        p.SetCanvasOrigin(cX, cy + (int)line.CachedLineTop);
                        //1.                                 
                        line.PaintBackgroundAndBorder(p);
                        if (line.SelectionSegment != null)
                        {
                            line.SelectionSegment.PaintSelection(p, line);
                        }
                        //2.                                
                        line.PaintRuns(p);
                        //3. 
                        line.PaintDecoration(p);
#if DEBUG
                        line.dbugPaintRuns(p);
#endif

                        p.SetCanvasOrigin(cX, cy);//back
                    }
                    else if (drawState == 1)
                    {
                        //outof viewport -> break
                        break;
                    }

                    //----------------------------------------
                    c_lineNode = c_lineNode.Next;
                }
            }
            else
            {
                if (this.HasContainingBlockProperty)
                {
                    p.PushContaingBlock(this);
                    int ox = p.CanvasOriginX;
                    int oy = p.CanvasOriginY;
                    var node = this._aa_boxes.GetFirstLinkedNode();
                    while (node != null)
                    {
                        CssBox b = node.Value;
                        if (b.CssDisplay == Css.CssDisplay.None)
                        {
                            node = node.Next;
                            continue;
                        }
                        else if (b.IsOutOfFlowBox)
                        {
                            //
                            p.AddToLatePaintList(b);
                            node = node.Next;
                            continue;
                        }
                        //move to left-top of client box 
                        p.SetCanvasOrigin(ox + (int)b.LocalX, oy + (int)b.LocalY);
                        if (b.decorator != null)
                        {
                            b.decorator.Paint(b, p);
                        }

                        if (b.HasClipArea)
                        {
                            if (p.PushLocalClipArea(b.VisualWidth, b.VisualHeight))
                            {
                                b.Paint(p);
                            }
                            p.PopLocalClipArea();
                        }
                        else
                        {
                            b.Paint(p);
                        }

                        node = node.Next;
                    }
                    p.SetCanvasOrigin(ox, oy);
                    p.PopContainingBlock();
                }
                else
                {
                    //if not
                    int ox = p.CanvasOriginX;
                    int oy = p.CanvasOriginY;
                    var node = this._aa_boxes.GetFirstLinkedNode();
                    while (node != null)
                    {
                        CssBox b = node.Value;
                        if (b.CssDisplay == Css.CssDisplay.None)
                        {
                            node = node.Next;
                            continue;
                        }
                        p.SetCanvasOrigin(ox + (int)b.LocalX, oy + (int)b.LocalY);
                        b.Paint(p);
                        node = node.Next;
                    }
                    p.SetCanvasOrigin(ox, oy);
                }
            }
            //------------------------------------------
            //debug
            //var clientLeft = this.ClientLeft;
            //g.DrawRectangle(Pens.GreenYellow, 0, 0, 5, 10);
            //g.DrawRectangle(Pens.HotPink, this.ClientRight - 5, 0, 5, 10);
            //------------------------------------------   

            if (this.HasAbsoluteLayer)
            {
                p.PushContaingBlock(this);
                int ox = p.CanvasOriginX;
                int oy = p.CanvasOriginY;
                var node = this._absPosLayer.GetFirstLinkedNode();
                while (node != null)
                {
                    CssBox b = node.Value;
                    if (b.CssDisplay == Css.CssDisplay.None)
                    {
                        node = node.Next;
                        continue;
                    }
                    p.SetCanvasOrigin(ox + (int)b.LocalX, oy + (int)b.LocalY);
                    b.Paint(p);
                    node = node.Next;
                }
                p.SetCanvasOrigin(ox, oy);
                p.PopContainingBlock();
            }

            if (p.LatePaintItemCount > 0)
            {
                //late paint -> floatBox 
                Rectangle latestClipRect = p.CurrentClipRect;
                p.PopLocalClipArea(); //temp
                p.PushContaingBlock(this);
                int j = p.LatePaintItemCount;
                int ox = p.CanvasOriginX;
                int oy = p.CanvasOriginY;
                for (int i = 0; i < j; ++i)
                {
                    CssBox box = p.GetLatePaintItem(i);
                    if (box.CssDisplay == Css.CssDisplay.None)
                    {
                        continue;
                    }
                    p.SetCanvasOrigin(ox + (int)box.LocalX, oy + (int)box.LocalY);
                    box.Paint(p);
                    p.SetCanvasOrigin(ox, oy);
                }
                p.PopContainingBlock();
                p.PushLocalClipArea(latestClipRect.Width, latestClipRect.Height);//push back
            }
            p.ExitCurrentLatePaintContext();
            //must! , 
            if (hasPrevClip)
            {
                p.PopLocalClipArea();
            }

#if DEBUG
            p.dbugExitContext();
#endif
        }
Esempio n. 3
0
        protected virtual void PaintImp(PaintVisitor p)
        {
            //if (this.dbugMark2 == 10 || this.dbugMark2 == 12)
            //{

            //}

            Css.CssDisplay display = this.CssDisplay;
            if (display == Css.CssDisplay.TableCell &&
                this.EmptyCells == Css.CssEmptyCell.Hide &&
                this.IsSpaceOrEmpty)
            {
                return;
            }
#if DEBUG
            p.dbugEnterNewContext(this, PaintVisitor.PaintVisitorContextName.Init);
#endif

            //-----------------------------------------------
            bool       hasPrevClip = false;
            RectangleF prevClip    = RectangleF.Empty;
            p.EnterNewLatePaintContext();
            //---------------------------------------------
            //if (display != Css.CssDisplay.Inline ||
            //    this.Position == Css.CssPosition.Absolute ||
            //    this.Position == Css.CssPosition.Fixed)
            if (this._renderBGAndBorder)
            {
                RectangleF bound = new RectangleF(0, 0, this.VisualWidth, this.VisualHeight);
                PaintBackground(p, bound, true, true);
                if (this.HasSomeVisibleBorder)
                {
                    p.PaintBorders(this, bound, true, true);
                }
#if DEBUG
                dbugPaint(p, bound);
#endif
            }

            //---------------------------------------------
            if (this.LineBoxCount > 0)
            {
                float viewport_top    = p.ViewportTop;
                float viewport_bottom = p.ViewportBottom;
                int   drawState       = 0;
                var   c_lineNode      = this._clientLineBoxes.First;
                while (c_lineNode != null)
                {
                    CssLineBox line = c_lineNode.Value;
                    if (line.CachedLineBottom >= viewport_top &&
                        line.CachedLineTop <= viewport_bottom)
                    {
#if DEBUG
                        dbugCounter.dbugLinePaintCount++;
#endif

                        drawState = 1;//drawing in viewport area
                        int cX = p.CanvasOriginX;
                        int cy = p.CanvasOriginY;
                        p.SetCanvasOrigin(cX, cy + (int)line.CachedLineTop);
                        //1.
                        line.PaintBackgroundAndBorder(p);
                        if (line.SelectionSegment != null)
                        {
                            line.SelectionSegment.PaintSelection(p, line);
                        }
                        //2.
                        line.PaintRuns(p);
                        //3.
                        line.PaintDecoration(p);
#if DEBUG
                        line.dbugPaintRuns(p);
#endif

                        p.SetCanvasOrigin(cX, cy);//back
                    }
                    else if (drawState == 1)
                    {
                        //outof viewport -> break
                        break;
                    }

                    //----------------------------------------
                    c_lineNode = c_lineNode.Next;
                }
            }
            else
            {
                if (this.HasContainingBlockProperty)
                {
                    p.PushContaingBlock(this);
                    int ox   = p.CanvasOriginX;
                    int oy   = p.CanvasOriginY;
                    var node = this._aa_boxes.GetFirstLinkedNode();
                    while (node != null)
                    {
                        CssBox b = node.Value;
                        if (b.CssDisplay == Css.CssDisplay.None)
                        {
                            node = node.Next;
                            continue;
                        }
                        else if (b.IsOutOfFlowBox)
                        {
                            //
                            p.AddToLatePaintList(b);
                            node = node.Next;
                            continue;
                        }
                        //move to left-top of client box
                        p.SetCanvasOrigin(ox + (int)b.LocalX, oy + (int)b.LocalY);
                        if (b.decorator != null)
                        {
                            b.decorator.Paint(b, p);
                        }

                        if (b.HasClipArea)
                        {
                            if (p.PushLocalClipArea(b.VisualWidth, b.VisualHeight))
                            {
                                b.Paint(p);
                            }
                            p.PopLocalClipArea();
                        }
                        else
                        {
                            b.Paint(p);
                        }

                        node = node.Next;
                    }
                    p.SetCanvasOrigin(ox, oy);
                    p.PopContainingBlock();
                }
                else
                {
                    //if not
                    int ox   = p.CanvasOriginX;
                    int oy   = p.CanvasOriginY;
                    var node = this._aa_boxes.GetFirstLinkedNode();
                    while (node != null)
                    {
                        CssBox b = node.Value;
                        if (b.CssDisplay == Css.CssDisplay.None)
                        {
                            node = node.Next;
                            continue;
                        }
                        p.SetCanvasOrigin(ox + (int)b.LocalX, oy + (int)b.LocalY);
                        b.Paint(p);
                        node = node.Next;
                    }
                    p.SetCanvasOrigin(ox, oy);
                }
            }
            //------------------------------------------
            //debug
            //var clientLeft = this.ClientLeft;
            //g.DrawRectangle(Pens.GreenYellow, 0, 0, 5, 10);
            //g.DrawRectangle(Pens.HotPink, this.ClientRight - 5, 0, 5, 10);
            //------------------------------------------

            if (this.HasAbsoluteLayer)
            {
                p.PushContaingBlock(this);
                int ox   = p.CanvasOriginX;
                int oy   = p.CanvasOriginY;
                var node = this._absPosLayer.GetFirstLinkedNode();
                while (node != null)
                {
                    CssBox b = node.Value;
                    if (b.CssDisplay == Css.CssDisplay.None)
                    {
                        node = node.Next;
                        continue;
                    }
                    p.SetCanvasOrigin(ox + (int)b.LocalX, oy + (int)b.LocalY);
                    b.Paint(p);
                    node = node.Next;
                }
                p.SetCanvasOrigin(ox, oy);
                p.PopContainingBlock();
            }

            if (p.LatePaintItemCount > 0)
            {
                //late paint -> floatBox
                Rectangle latestClipRect = p.CurrentClipRect;
                p.PopLocalClipArea(); //temp
                p.PushContaingBlock(this);
                int j  = p.LatePaintItemCount;
                int ox = p.CanvasOriginX;
                int oy = p.CanvasOriginY;
                for (int i = 0; i < j; ++i)
                {
                    CssBox box = p.GetLatePaintItem(i);
                    if (box.CssDisplay == Css.CssDisplay.None)
                    {
                        continue;
                    }
                    p.SetCanvasOrigin(ox + (int)box.LocalX, oy + (int)box.LocalY);
                    box.Paint(p);
                    p.SetCanvasOrigin(ox, oy);
                }
                p.PopContainingBlock();
                p.PushLocalClipArea(latestClipRect.Width, latestClipRect.Height);//push back
            }
            p.ExitCurrentLatePaintContext();
            //must! ,
            if (hasPrevClip)
            {
                p.PopLocalClipArea();
            }

#if DEBUG
            p.dbugExitContext();
#endif
        }
Esempio n. 4
0
        /// <summary>
        /// Paints the fragment
        /// </summary>
        /// <param name="g">the device to draw to</param>
        protected override void PaintImp(PaintVisitor p)
        {
#if DEBUG
            p.dbugEnterNewContext(this, PaintVisitor.PaintVisitorContextName.Init);
#endif
            var rect = new RectangleF(0, 0, this.VisualWidth, this.VisualHeight);
            if (rect.Height > 2 && RenderUtils.IsColorVisible(ActualBackgroundColor))
            {
                p.FillRectangle(ActualBackgroundColor, rect.X, rect.Y, rect.Width, rect.Height);
            }

            if (rect.Height > 1)
            {
                p.PaintBorders(this, rect);
            }
            else
            {
                p.PaintBorder(this, CssSide.Top, this.BorderTopColor, rect);
            }
#if DEBUG
            p.dbugExitContext();
#endif
        }
Esempio n. 5
0
        public override void Paint(PaintVisitor p, RectangleF rect)
        {
            PaintBackground(p, rect, true, true);
            if (this.HasSomeVisibleBorder)
            {
                p.PaintBorders(this, rect, true, true);
            }
            //---------------------------------------------------------
            RectangleF r = _imgRun.Rectangle;

            r.Height -= ActualBorderTopWidth + ActualBorderBottomWidth + ActualPaddingTop + ActualPaddingBottom;
            r.Y      += ActualBorderTopWidth + ActualPaddingTop;
            r.X       = (float)Math.Floor(r.X);
            r.Y       = (float)Math.Floor(r.Y);
            bool tryLoadOnce = false;

EVAL_STATE:
            switch (_imgRun.ImageBinder.State)
            {
            case ImageBinderState.Unload:
            {
                //async request image
                if (!tryLoadOnce)
                {
                    p.RequestImageAsync(_imgRun.ImageBinder, this._imgRun, this);
                    //retry again
                    tryLoadOnce = true;
                    goto EVAL_STATE;
                }
            }
            break;

            case ImageBinderState.Loading:
            {
                //RenderUtils.DrawImageLoadingIcon(g, r);
            }
            break;

            case ImageBinderState.Loaded:
            {
                Image img;
                if ((img = (Image)_imgRun.ImageBinder.Image) != null)
                {
                    if (_imgRun.ImageRectangle == Rectangle.Empty)
                    {
                        p.DrawImage(img,
                                    r.Left, r.Top,
                                    img.Width, img.Height);
                    }
                    else
                    {
                        p.DrawImage(img, _imgRun.ImageRectangle);
                    }
                }
                else
                {
                    RenderUtils.DrawImageLoadingIcon(p.InnerCanvas, r);
                    if (r.Width > 19 && r.Height > 19)
                    {
                        p.DrawRectangle(Color.LightGray, r.X, r.Y, r.Width, r.Height);
                    }
                }
            }
            break;

            case ImageBinderState.NoImage:
            {
            }
            break;

            case ImageBinderState.Error:
            {
                RenderUtils.DrawImageErrorIcon(p.InnerCanvas, r);
            }
            break;
            }

            //#if DEBUG
            //            p.FillRectangle(Color.Red, rect.X, rect.Y, rect.Width, rect.Height);
            //#endif
        }
Esempio n. 6
0
        public override void Paint(PaintVisitor p, RectangleF rect)
        {
            PaintBackground(p, rect, true, true);
            if (this.HasSomeVisibleBorder)
            {
                p.PaintBorders(this, rect, true, true);
            }
            //--------------------------------------------------------- 
            RectangleF r = _imgRun.Rectangle;
            r.Height -= ActualBorderTopWidth + ActualBorderBottomWidth + ActualPaddingTop + ActualPaddingBottom;
            r.Y += ActualBorderTopWidth + ActualPaddingTop;
            r.X = (float)Math.Floor(r.X);
            r.Y = (float)Math.Floor(r.Y);
            bool tryLoadOnce = false;
        EVAL_STATE:
            switch (_imgRun.ImageBinder.State)
            {
                case ImageBinderState.Unload:
                    {
                        //async request image
                        if (!tryLoadOnce)
                        {
                            p.RequestImageAsync(_imgRun.ImageBinder, this._imgRun, this);
                            //retry again
                            tryLoadOnce = true;
                            goto EVAL_STATE;
                        }
                    }
                    break;
                case ImageBinderState.Loading:
                    {
                        //RenderUtils.DrawImageLoadingIcon(g, r);
                    }
                    break;
                case ImageBinderState.Loaded:
                    {
                        Image img;
                        if ((img = (Image)_imgRun.ImageBinder.Image) != null)
                        {
                            if (_imgRun.ImageRectangle == Rectangle.Empty)
                            {
                                p.DrawImage(img,
                                      r.Left, r.Top,
                                      img.Width, img.Height);
                            }
                            else
                            {
                                p.DrawImage(img, _imgRun.ImageRectangle);
                            }
                        }
                        else
                        {
                            RenderUtils.DrawImageLoadingIcon(p.InnerCanvas, r);
                            if (r.Width > 19 && r.Height > 19)
                            {
                                p.DrawRectangle(Color.LightGray, r.X, r.Y, r.Width, r.Height);
                            }
                        }
                    }
                    break;
                case ImageBinderState.NoImage:
                    {
                    }
                    break;
                case ImageBinderState.Error:
                    {
                        RenderUtils.DrawImageErrorIcon(p.InnerCanvas, r);
                    }
                    break;
            }

            //#if DEBUG
            //            p.FillRectangle(Color.Red, rect.X, rect.Y, rect.Width, rect.Height);
            //#endif
        }
Esempio n. 7
0
        protected virtual void PaintImp(PaintVisitor p)
        {
#if DEBUG
            //if (__aa_dbugId == 6)
            //{

            //}
            //if (this.dbugMark2 == 10 || this.dbugMark2 == 12)
            //{
            //}
#endif


            Css.CssDisplay display = this.CssDisplay;
            //
            if (display == Css.CssDisplay.TableCell &&
                this.EmptyCells == Css.CssEmptyCell.Hide &&
                this.IsSpaceOrEmpty)
            {
                return;
            }


#if DEBUG
            p.dbugEnterNewContext(this, PaintVisitor.PaintVisitorContextName.Init);
#endif
            Color prevBgColorHint = p.CurrentSolidBackgroundColorHint;
            //-----------------------------------------------
            bool       hasPrevClip = false;
            RectangleF prevClip    = RectangleF.Empty;
            p.EnterNewLatePaintContext();
            //---------------------------------------------
            //if (display != Css.CssDisplay.Inline ||
            //    this.Position == Css.CssPosition.Absolute ||
            //    this.Position == Css.CssPosition.Fixed)
            if (_renderBGAndBorder)
            {
                RectangleF bounds = new RectangleF(0, 0, this.VisualWidth, this.VisualHeight);
                PaintBackground(p, bounds, true, true);
                if (this.HasSomeVisibleBorder)
                {
                    p.PaintBorders(this, bounds, true, true);
                }
#if DEBUG
                dbugPaint(p, bounds);
#endif
            }

            //---------------------------------------------
            if (this.LineBoxCount > 0)
            {
                float viewport_top    = p.ViewportTop;
                float viewport_bottom = p.ViewportBottom;
                int   drawState       = 0;
                var   c_lineNode      = _clientLineBoxes.First;
                while (c_lineNode != null)
                {
                    CssLineBox line = c_lineNode.Value;
                    if (line.CachedLineBottom >= viewport_top &&
                        line.CachedLineTop <= viewport_bottom)
                    {
                        Rectangle currentClipRect = p.CurrentClipRect;
                        drawState = 1;//drawing in viewport area
#if DEBUG
                        //System.Diagnostics.Debug.WriteLine("clip_rect:" + currentClipRect);
                        dbugCounter.dbugLinePaintCount++;
#endif

                        int cX    = p.CanvasOriginX;
                        int cy    = p.CanvasOriginY;
                        int newCy = cy + (int)line.CachedLineTop;

                        if (newCy <= (cy + currentClipRect.Bottom) &&
                            newCy + line.CacheLineHeight >= (cy + currentClipRect.Top))
                        {
                            p.SetCanvasOrigin(cX, newCy);
                            //1.
                            line.PaintBackgroundAndBorder(p);

                            SelectionSegment selSegment = line.SelectionSegment;
                            if (selSegment != null)
                            {
                                switch (selSegment.Kind)
                                {
                                case SelectionSegmentKind.FullLine:
                                {
                                    Color prevColor2 = p.CurrentSolidBackgroundColorHint;        //save2
                                    p.CurrentSolidBackgroundColorHint = p.CssBoxSelectionColor;

                                    selSegment.PaintSelection(p, line);

                                    line.PaintRuns(p);

                                    p.CurrentSolidBackgroundColorHint = prevColor2;         //restore2
                                }
                                break;

                                case SelectionSegmentKind.PartialBegin:
                                case SelectionSegmentKind.SingleLine:
                                case SelectionSegmentKind.PartialEnd:
                                {
                                    //TODO: review here again***
                                    //partial line

                                    //[A]
                                    line.PaintRuns(p);         //normal line
                                                               //-----

                                    //[B]
                                    //selection part with clip rect

                                    Color prevColor2 = p.CurrentSolidBackgroundColorHint;        //save2
                                    //p.CurrentSolidBackgroundColorHint = prevBgColorHint;


                                    int xpos = selSegment.BeginAtPx;
                                    int w    = selSegment.WidthPx;

                                    Rectangle clipRect = p.CurrentClipRect;
                                    p.SetClipArea(xpos, 0, w, (int)line.CacheLineHeight);
                                    selSegment.PaintSelection(p, line);

                                    p.CurrentSolidBackgroundColorHint = p.CssBoxSelectionColor;

                                    line.PaintRuns(p);
                                    p.SetClipArea(clipRect.X, clipRect.Top, clipRect.Width, clipRect.Height); //restore

                                    p.CurrentSolidBackgroundColorHint = prevColor2;                           //restore2
                                }
                                break;
                                }
                            }
                            else
                            {
                                //2.

                                line.PaintRuns(p);
                            }


                            //3.
                            line.PaintDecoration(p);
#if DEBUG
                            line.dbugPaintRuns(p);
#endif

                            p.SetCanvasOrigin(cX, cy);//back
                        }
                    }
                    else if (drawState == 1)
                    {
                        //outof viewport -> break
                        break;
                    }

                    //----------------------------------------
                    c_lineNode = c_lineNode.Next;
                }
            }
            else
            {
                if (this.HasContainingBlockProperty)
                {
                    p.PushContaingBlock(this);
                    int ox   = p.CanvasOriginX;
                    int oy   = p.CanvasOriginY;
                    var node = _aa_boxes.GetFirstLinkedNode();
                    while (node != null)
                    {
                        CssBox b = node.Value;
                        if (b.CssDisplay == Css.CssDisplay.None || b.IsAddedToAbsoluteLayer)
                        {
                            node = node.Next;
                            continue;
                        }
                        else if (b.IsOutOfFlowBox)
                        {
                            //
                            p.AddToLatePaintList(b);
                            node = node.Next;
                            continue;
                        }
                        //move to left-top of client box
                        p.SetCanvasOrigin(ox + (int)b.LocalX, oy + (int)b.LocalY);
                        if (b._decorator != null)
                        {
                            b._decorator.Paint(b, p);
                        }

                        if (b.HasClipArea)
                        {
                            if (p.PushLocalClipArea(b.VisualWidth, b.VisualHeight))
                            {
                                CssBox.Paint(b, p);
                                p.PopLocalClipArea();
                            }
                        }
                        else
                        {
                            CssBox.Paint(b, p);
                        }

                        node = node.Next;
                    }
                    p.SetCanvasOrigin(ox, oy);
                    p.PopContainingBlock();
                }
                else
                {
                    //if not
                    int ox   = p.CanvasOriginX;
                    int oy   = p.CanvasOriginY;
                    var node = _aa_boxes.GetFirstLinkedNode();
                    while (node != null)
                    {
                        CssBox b = node.Value;
                        if (b.CssDisplay == Css.CssDisplay.None || b.IsAddedToAbsoluteLayer)
                        {
                            node = node.Next;
                            continue;
                        }
                        p.SetCanvasOrigin(ox + (int)b.LocalX, oy + (int)b.LocalY);

                        CssBox.Paint(b, p);
                        node = node.Next;
                    }
                    p.SetCanvasOrigin(ox, oy);
                }
            }
            //------------------------------------------
            //debug
            //var clientLeft = this.ClientLeft;
            //g.DrawRectangle(Pens.GreenYellow, 0, 0, 5, 10);
            //g.DrawRectangle(Pens.HotPink, this.ClientRight - 5, 0, 5, 10);
            //------------------------------------------

            if (this.HasAbsoluteLayer)
            {
                p.PushContaingBlock(this);
                int ox = p.CanvasOriginX;
                int oy = p.CanvasOriginY;
                int j  = _absPosLayer.Count;
                for (int i = 0; i < j; ++i)
                {
                    CssBox b = _absPosLayer.GetBox(i);
                    if (b.CssDisplay == Css.CssDisplay.None)
                    {
                        continue;
                    }
                    p.SetCanvasOrigin(ox + (int)b.LocalX, oy + (int)b.LocalY);
                    CssBox.Paint(b, p);
                }
                //var node = _absPosLayer.GetFirstLinkedNode();
                //while (node != null)
                //{
                //    CssBox b = node.Value;
                //    if (b.CssDisplay == Css.CssDisplay.None)
                //    {
                //        node = node.Next;
                //        continue;
                //    }
                //    p.SetCanvasOrigin(ox + (int)b.LocalX, oy + (int)b.LocalY);
                //    b.Paint(p);
                //    node = node.Next;
                //}
                p.SetCanvasOrigin(ox, oy);
                p.PopContainingBlock();
            }

            if (p.LatePaintItemCount > 0)
            {
                //late paint -> floatBox
                Rectangle latestClipRect = p.CurrentClipRect;
                p.PopLocalClipArea(); //temp
                p.PushContaingBlock(this);
                int j  = p.LatePaintItemCount;
                int ox = p.CanvasOriginX;
                int oy = p.CanvasOriginY;
                for (int i = 0; i < j; ++i)
                {
                    CssBox box = p.GetLatePaintItem(i);
                    if (box.CssDisplay == Css.CssDisplay.None)
                    {
                        continue;
                    }
                    p.SetCanvasOrigin(ox + (int)box.LocalX, oy + (int)box.LocalY);
                    CssBox.Paint(box, p);
                    p.SetCanvasOrigin(ox, oy);
                }
                p.PopContainingBlock();
                p.PushLocalClipArea(latestClipRect.Width, latestClipRect.Height);//push back
            }
            p.ExitCurrentLatePaintContext();
            //must! ,
            if (hasPrevClip)
            {
                p.PopLocalClipArea();
            }

            p.CurrentSolidBackgroundColorHint = prevBgColorHint;


#if DEBUG
            p.dbugExitContext();
#endif
        }
Esempio n. 8
0
        public override void Paint(PaintVisitor p, RectangleF rect)
        {
            Color bgColorHint = p.CurrentSolidBackgroundColorHint;//save

            PaintBackground(p, rect, true, true);

            if (this.HasSomeVisibleBorder)
            {
                p.PaintBorders(this, rect, true, true);
            }
            //---------------------------------------------------------
            RectangleF r = _imgRun.Rectangle;

            r.Height  -= ActualBorderTopWidth + ActualBorderBottomWidth + ActualPaddingTop + ActualPaddingBottom;
            r.Location = new PointF((float)Math.Floor(r.Left), (float)Math.Floor(r.Top + ActualBorderTopWidth + ActualPaddingTop));

            bool tryLoadOnce = false;

EVAL_STATE:
            switch (_imgRun.ImageBinder.State)
            {
            case BinderState.Unload:
            {
                if (_tmpTransitionImgBinder != null)
                {
                    DrawWithTempTransitionImage(p, rect);
                }


                //async request image
                if (!tryLoadOnce)
                {
                    p.RequestImageAsync(_imgRun.ImageBinder, _imgRun, this);
                    //retry again
                    tryLoadOnce = true;
                    goto EVAL_STATE;
                }
            }
            break;

            case BinderState.Loading:
            {
                if (_tmpTransitionImgBinder != null)
                {
                    DrawWithTempTransitionImage(p, rect);
                }

                //RenderUtils.DrawImageLoadingIcon(g, r);
            }
            break;

            case BinderState.Loaded:
            {
                if (_tmpTransitionImgBinder != null)
                {
                    //*** clear tmp transition img after new image is loaded
                    _tmpTransitionImgBinder = null;
                }
                Image img;
                if ((img = (Image)_imgRun.ImageBinder.LocalImage) != null)         //assign and test
                {
                    if (this.VisualWidth != 0)
                    {
                        //TODO: review here

                        if (_imgRun.ImageRectangle == Rectangle.Empty)
                        {
                            p.DrawImage(img,
                                        r.Left, r.Top,
                                        this.VisualWidth, this.VisualHeight);
                        }
                        else
                        {
                            p.DrawImage(img, _imgRun.ImageRectangle);
                        }
                    }
                    else
                    {
                        if (_imgRun.ImageRectangle == Rectangle.Empty)
                        {
                            p.DrawImage(img,
                                        r.Left, r.Top,
                                        img.Width, img.Height);
                        }
                        else
                        {
                            p.DrawImage(img, _imgRun.ImageRectangle);
                        }
                    }
                }
                else
                {
                    RenderUtils.DrawImageLoadingIcon(p.InnerDrawBoard, r);
                    if (r.Width > 19 && r.Height > 19)
                    {
                        p.DrawRectangle(KnownColors.LightGray, r.Left, r.Top, r.Width, r.Height);
                    }
                }
            }
            break;

            case BinderState.Blank:
            {
            }
            break;

            case BinderState.Error:
            {
                RenderUtils.DrawImageErrorIcon(p.InnerDrawBoard, r);
            }
            break;
            }

            //#if DEBUG
            //            p.FillRectangle(Color.Red, rect.X, rect.Y, rect.Width, rect.Height);
            //#endif

            p.CurrentSolidBackgroundColorHint = bgColorHint;//restore
        }