Example #1
0
/** Please be sure to call this should you ever
 * override the default Draw() method.
 */
void Window::DrawViews( Rect frame )
{
    /// \todo Only update the requested frame.
    lock();
    for ( int i = 0; i < CountChildren(); i++ )
    {
        View *view = ChildAt(i);
        view->Draw( view->Bounds() );
        view->DrawChildren( view->Bounds() );
    }
    unlock();
}
Example #2
0
void View::DrawChildren( Rect rect )
{
   if ( GetWindow() == NULL ) return;

   lock();
   for ( int i = 0; i < CountChildren(); i++ ) 
   {
     View *child = ChildAt(i);
           child->Draw( rect );
		   child->DrawChildren( rect );
   }
   unlock();
}
Example #3
0
void
View::Draw(DrawingEngine* drawingEngine, BRegion* effectiveClipping,
           BRegion* windowContentClipping, bool deep)
{
    if (!fVisible) {
        // child views cannot be visible either
        return;
    }

    if (fViewBitmap != NULL || fViewColor != B_TRANSPARENT_COLOR) {
        // we can only draw within our own area
        BRegion* redraw;
        if ((fFlags & B_DRAW_ON_CHILDREN) != 0) {
            // The client may actually want to prevent the background to
            // be painted outside the user clipping.
            redraw = fWindow->GetRegion(
                         ScreenAndUserClipping(windowContentClipping));
        } else {
            // Ignore user clipping as in BeOS for painting the background.
            redraw = fWindow->GetRegion(
                         _ScreenClipping(windowContentClipping));
        }
        if (!redraw)
            return;
        // add the current clipping
        redraw->IntersectWith(effectiveClipping);

        Overlay* overlayCookie = _Overlay();

        if (fViewBitmap != NULL && overlayCookie == NULL) {
            // draw view bitmap
            // TODO: support other options!
            BRect rect = fBitmapDestination;
            ConvertToScreenForDrawing(&rect);

            align_rect_to_pixels(&rect);

            if (fBitmapOptions & B_TILE_BITMAP_Y) {
                // move rect up as much as needed
                while (rect.top > redraw->Frame().top)
                    rect.OffsetBy(0.0, -(rect.Height() + 1));
            }
            if (fBitmapOptions & B_TILE_BITMAP_X) {
                // move rect left as much as needed
                while (rect.left > redraw->Frame().left)
                    rect.OffsetBy(-(rect.Width() + 1), 0.0);
            }

// XXX: locking removed because the Window keeps the engine locked
// because it keeps track of syncing right now

            // lock the drawing engine for as long as we need the clipping
            // to be valid
            if (rect.IsValid()/* && drawingEngine->Lock()*/) {
                drawingEngine->ConstrainClippingRegion(redraw);

                drawing_mode oldMode;
                drawingEngine->SetDrawingMode(B_OP_COPY, oldMode);

                if (fBitmapOptions & B_TILE_BITMAP) {
                    // tile across entire view

                    float start = rect.left;
                    while (rect.top < redraw->Frame().bottom) {
                        while (rect.left < redraw->Frame().right) {
                            drawingEngine->DrawBitmap(fViewBitmap,
                                                      fBitmapSource, rect, fBitmapOptions);
                            rect.OffsetBy(rect.Width() + 1, 0.0);
                        }
                        rect.OffsetBy(start - rect.left, rect.Height() + 1);
                    }
                    // nothing left to be drawn
                    redraw->MakeEmpty();
                } else if (fBitmapOptions & B_TILE_BITMAP_X) {
                    // tile in x direction

                    while (rect.left < redraw->Frame().right) {
                        drawingEngine->DrawBitmap(fViewBitmap, fBitmapSource,
                                                  rect, fBitmapOptions);
                        rect.OffsetBy(rect.Width() + 1, 0.0);
                    }
                    // remove horizontal stripe from clipping
                    rect.left = redraw->Frame().left;
                    rect.right = redraw->Frame().right;
                    redraw->Exclude(rect);
                } else if (fBitmapOptions & B_TILE_BITMAP_Y) {
                    // tile in y direction

                    while (rect.top < redraw->Frame().bottom) {
                        drawingEngine->DrawBitmap(fViewBitmap, fBitmapSource,
                                                  rect, fBitmapOptions);
                        rect.OffsetBy(0.0, rect.Height() + 1);
                    }
                    // remove vertical stripe from clipping
                    rect.top = redraw->Frame().top;
                    rect.bottom = redraw->Frame().bottom;
                    redraw->Exclude(rect);
                } else {
                    // no tiling at all

                    drawingEngine->DrawBitmap(fViewBitmap, fBitmapSource,
                                              rect, fBitmapOptions);
                    redraw->Exclude(rect);
                }

                drawingEngine->SetDrawingMode(oldMode);

                // NOTE: It is ok not to reset the clipping, that
                // would only waste time
//				drawingEngine->Unlock();
            }

        }

        if (fViewColor != B_TRANSPARENT_COLOR) {
            // fill visible region with view color,
            // this version of FillRegion ignores any
            // clipping, that's why "redraw" needs to
            // be correct
// see #634
//			if (redraw->Frame().left < 0 || redraw->Frame().top < 0) {
//				char message[1024];
//				BRect c = effectiveClipping->Frame();
//				BRect w = windowContentClipping->Frame();
//				BRect r = redraw->Frame();
//				sprintf(message, "invalid background: current clipping: (%d, %d)->(%d, %d), "
//					"window content: (%d, %d)->(%d, %d), redraw: (%d, %d)->(%d, %d)",
//					(int)c.left, (int)c.top, (int)c.right, (int)c.bottom,
//					(int)w.left, (int)w.top, (int)w.right, (int)w.bottom,
//					(int)r.left, (int)r.top, (int)r.right, (int)r.bottom);
//				debugger(message);
//			}

            drawingEngine->FillRegion(*redraw, overlayCookie != NULL
                                      ? overlayCookie->Color() : fViewColor);
        }

        fWindow->RecycleRegion(redraw);
    }

    fBackgroundDirty = false;

    // let children draw
    if (deep) {
        for (View* child = FirstChild(); child; child = child->NextSibling()) {
            child->Draw(drawingEngine, effectiveClipping,
                        windowContentClipping, deep);
        }
    }
}