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
New Developer
Posts: 3
Registered: ‎04-23-2009
My Device: Not Specified

Does invalidate() also clear screen

Hi,

 

When I call invalidate(), does it also clear the whole screen with 0xffffff ?If it does, is there any workaround?

I implement clear screen in paint() and I just use invalidate() to force a paint() call.

 

Tks,

Developer
Posts: 170
Registered: ‎01-17-2009
My Device: 9630

Re: Does invalidate() also clear screen

invalidate() redraws a field, so if you had a labelfield and you called invalidate on it, it will just repaint it

 

not sure if that answers it 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Does invalidate() also clear screen

As far as I know, invalidate() just schedules a paint for the Field (or areas) that you have marked as invalid.  So it should go through your paint routine again.  It does not actually do anything itself with the screen buffer.
New Developer
Posts: 3
Registered: ‎04-23-2009
My Device: Not Specified

Re: Does invalidate() also clear screen

int count =0; public void paint(Graphics g){ g.setColor(0x000000); g.drawText("The lazy fox",50,count++,0); if (count>200) count=0; } public void run(){ while (true){ UiApplication.getUiApplication().invokeAndWait(new Runnable() { public void run() { invalidate(); } }); } }

The code above draws "The lazy fox" on different positions of screen without clearing screen. But actually, there's only one "The lazy fox" on screen at a time. So I doubt that invalidate() also clear screen?

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Does invalidate() also clear screen

Good test thanks thy3s.

 

For the record, you do not have hold the event lock to call invalidate(), so your while (true) loop could just call invalidate() directly.

New Contributor
Posts: 2
Registered: ‎08-06-2010
My Device: Not Specified

Re: Does invalidate() also clear screen

Yes, invalidate() does clear whatever it is called upon. So if Screen.invalidate() is called, the screen is cleared to the background color before Screen.paint() is called. I see the same thing happening for Field, but I am not sure about other subclasses like Manager.

 

This is annoying for me since I am trying to implement a custom Field with an optimized paint method that only update the regions that need painting. However, invalidate() ruins the entire field.

 

The workaround is to make multiple calls to invalidate(int x, int y, int width, int height) for the regions that need updating. This is a pain, since paint() would need to keep track of when it is supposed to paint the entire field and when it is supposed to paint a subregion. This can be done by keeping additional state variables of what needs to be redrawn.

 

Also making things complicated is that the clipping region given to paint(), as a result of calling invalidate(int x, int y, int width, int height), always has the origin at (0,0). Therefore, coordinate transformations have to be done to reflect its actual position in the Field.