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
Developer
cristisor
Posts: 48
Registered: ‎07-15-2009
Accepted Solution

pushRegion, pushContext and popContext - how do they work?

I'm trying to port an application from J2ME to the Blackberry API. I tried to use pushRegion to replace setClip from J2ME but it seems that these two methods behave different. I have an image with 7 buttons, one on top of another, each of them having a fixed height of 13 pixels, and the only different thing is their collor, each one is lighter than the previous one. I want to set the clip to draw a certain button, but the way that I use pushRegion is not correct and only a small piece is drawn sometimes, sometimes nothing is drawn. If I make pushRegion for the whole screen than all the image is drawn. Here is my code:

 

 

graphics.pushRegion(new XYRect(0, positionY, screenWidth, buttonHeight)); graphics.drawBitmap((screenWidth - buttonImage.getWidth()) / 2, positionY - buttonFrame[i] * buttonHeight, buttonImage.getWidth(), buttonImage.getHeight(), buttonImage, 0, 0); graphics.popContext();

 

 

 Should I use pushContext instead of pushRegion

And one more problem: after several drawings ( I make the drawing in a for loop) I get "out of memory" error on the emulator, I suppose it's because of the pushRegion and popContext because I don't create other objects.

 

Please use plain text.
Developer
cristisor
Posts: 48
Registered: ‎07-15-2009

Re: pushRegion, pushContext and popContext - how do they work?

I had to use pushContext instead of pushRegion and everything is ok. But maybe someone can tell me the difference between these two methods.
Please use plain text.
Regular Contributor
lyhoanghai
Posts: 71
Registered: ‎03-24-2010
My Carrier: Vodaphone

Re: pushRegion, pushContext and popContext - how do they work?

[ Edited ]

Wrap-up:

(1) pushContext(r,xOffset,yOffset)

(2) pushRegion(r)

(3) pushRegion(r,xScroll,yScroll)

 

1. Similarity:
- Both of them update the clipping regions:
  The clipping region is updated by intersecting with the previous clipping region.

- Use popContext() for both of them.

 

2. Different:

- (1) The orgin of coordinate ORG is set to (xOffset,yOffset)

- (2) ORG is set to (left,top) of r

- (3) ORG is set to (left,top) of r and then set traslation of coordinate to (xScroll,yScroll)
   In order to understand, imaging that you want to change the clipping region to an area (for example a Manager of object with VERTICAL_SCROLL | HORIZONTAL_SCROLL style) and this area has been scrolled (in our example the virtual extent of manager is larger than the physical extent and user has call setVerticalExtent/setHorizontalExtnet). In this case, use SHOULD use (3).

 

You can find an example at

http://docs.blackberry.com/en/developers/deliverables/7693/Manage_a_drawing_area_508101_11.jsp

Please use plain text.
Developer
Kenjkelly01
Posts: 64
Registered: ‎01-12-2009
My Carrier: Verizon

Re: pushRegion, pushContext and popContext - how do they work?

[ Edited ]

I actually found "Manage_a_drawing_area_508101_11.jsp" pretty useless because it contained no diagrams to show you what was happening. It does give code examples for using the two and uses about the same verbage given in the API spec, which led me to search for a clearer definition and diagrams..

 

  After my ump-teenth reading of that document I still don't know when to use pushRegion and when to use pushContext.  I always end up trying one and then trying the other if it didn't do what I needed. A few pictures of the results would help.

 

Here I am again...

 

Ken J Kelly
Please use plain text.