Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 41
Registered: ‎04-24-2012
My Device: storm
My Carrier: blackberry

pushRegion/pushContext Question

what im trying to do now is that I need to draw example a few rectangles and clip its region so that anything out of its region will not get draw or will be clipped. the problem is after I draw my stuff and clip its region nothing seems to happen below is a example of what I want to do.  Tnx in advance

 

protected void paint(Graphics graphics) {
        graphics.fillRect(10, 10, 100, 100);
        graphics.fillRect(50, 50, 100, 100);
        graphics.fillRect(100, 100, 100, 100);
        graphics.fillRect(150, 150, 100, 100);
        graphics.fillRect(200, 200, 100, 100);
        graphics.fillRect(250, 250, 100, 100);
        graphics.fillRect(300, 300, 100, 100);
        XYRect rec = new XYRect(0,0,230,230);
        graphics.pushRegion(rec);
        graphics.popContext();
      
    }

Contributor
Posts: 41
Registered: ‎04-24-2012
My Device: storm
My Carrier: blackberry

Re: pushRegion/pushContext Question

can anyone help me with this. Is my way of doing it wrong? may aim is to draw some stuff first and clip anything that is not in that region I cant seem to find a way to do this or is there any alternative path on doing it?

Contributor
Posts: 41
Registered: ‎04-24-2012
My Device: storm
My Carrier: blackberry

Re: pushRegion/pushContext Question

Is this way of painting way of not possible here in blackberry java? Because if its not possible I think I need to redo may code in painting I hope someone replies
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: pushRegion/pushContext Question

Simply pushing a context does not do anything. It simply affects all subsequent operations on that Graphics object. If you use g.clear() after you push region or push context, you will fill the pushed area with the background color, for example, without affecting the rest of the screen. Then you can pop the context.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 41
Registered: ‎04-24-2012
My Device: storm
My Carrier: blackberry

Re: pushRegion/pushContext Question

I've tried to g.clear after pushing the context but what happend is it cleared the region that I want to appear. What I need is to do is clear the drawings that are not in the region. Tnx for your advice

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: pushRegion/pushContext Question

Oh, I must have misunderstood. I this case, g.clear first, then push region and draw there - the region will clip the drawn shapes.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 41
Registered: ‎04-24-2012
My Device: storm
My Carrier: blackberry

Re: pushRegion/pushContext Question

but what im trying to do is I need to draw stuff first and after drawing is to clip example a rectangle because thats our design is it possible to do it this way?

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: pushRegion/pushContext Question

Do you mean that the user needs to see the full picture and then the clipped one?

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Highlighted
Contributor
Posts: 41
Registered: ‎04-24-2012
My Device: storm
My Carrier: blackberry

Re: pushRegion/pushContext Question

yeah for example I drew a rectangle after drawing the rectangle what I want to do is to clip the middle part of the rectangle. The design of our code is like this so the pushregion draw pop style of clipping cannot be achived