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
Berrysoft
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified
Accepted Solution

How to get BitMapField repainted on screen invalidate()

Mark et. al at RIM:

 

If you have a an interface:

 

public interface Placeable { public abstract int X(); public abstract int Y(); }

 

 

 which is used to create a BitMapfield that implements that interface and is contained in a screen with a delegate manager:

 

 

 

import net.berrysoft.dib.interfaces.Placeable; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.Manager; public class GameManager extends Manager { public GameManager() { super(Manager.NO_HORIZONTAL_SCROLL | Manager.NO_VERTICAL_SCROLL); } protected void sublayout(int width, int height) { Placeable field; // Loop through all the fields contained with the layout manager for(int i = 0; i < getFieldCount(); i++) { field = (Placeable)getField(i); // Get a field (the board) // Set the position of the field based on field's coordinates setPositionChild((Field) field, field.X(), field.Y()); layoutChild((Field) field, width, height); // Layout the field } setExtent(width, height); // Set the manager's dimensions } }

 

 why does invalidating the screen, the screen's layout, or even both NOT result in the BitMapField being repainted at a new position (when it's coordinates were in facted changed by other code)????

 

Here is relevant code from the abstract base class of an extended BitMapField:

 

 

public abstract class Block extends BitmapField implements Placeable { public boolean isSelected( ) { return selected; } public void setSelected( boolean selected ) { this.selected = selected; } public String Name() { return name; } Block(String name, int x, int y, int left, int top, int width, int height) { this.name = name; // Extract the bitmap for this block bitmap = new Bitmap(width, height); Graphics g = new Graphics(bitmap); g.drawBitmap(0, 0, width, height, Bitmap.getBitmapResource("blocks.png"), left, top); setBitmap(bitmap); this.x = (x * Game.BLOCKSIZE) + Game.getBoard( ).X( ) + Game.BOARDER_SIZE; this.y = (y * Game.BLOCKSIZE) + Game.getBoard( ).Y( ) + Game.BOARDER_SIZE; x1 = x; // Save starting location for new game reset y1 = y; } public void click( ) { selected = !selected; } public void move(int d) { if( !isSelected( ) ) return; // Move the block switch(d) { case Move.LEFT: this.x = x - Game.BLOCKSIZE; break; case Move.RIGHT: this.x = x + Game.BLOCKSIZE; break; case Move.UP: this.y = y - Game.BLOCKSIZE; break; case Move.DOWN: this.y = y + Game.BLOCKSIZE; break; } } public void reset( ) { x = x1; y = y1; } public boolean isFocusable() { return true; } // Placeable Interface public int X() { return x; } public int Y() { return y; } // PRIVATE IMPLEMENTATION private static int dotSize = 8; private String name; // Family member private int x, y; private int x1, y1; // Initial coordinates private Bitmap bitmap; protected boolean selected; // True if selected for movement protected void drawFocus(Graphics g, boolean on) { if( selected ) { // Draw selection marker g.setColor(Color.GREEN); g.fillArc(getWidth()/2 - dotSize/2, getHeight()/2 - dotSize/2, dotSize, dotSize, 0, 360); } else { // Draw focus marker g.setColor(Color.YELLOW); g.fillArc(getWidth()/2 - dotSize/2, getHeight()/2 - dotSize/2, dotSize, dotSize, 0, 360); } invalidate( ); } }

 

 It seems that one should be able to simply invalidate the screen when a block has moved, and that this would then re-layout the screen via it's delegate manager, which would in turn ask each block to layout and then paint, but instead, no matter the blocks coordinates, it is displayed in the same spot and does NOT move.

 

Is this a bug in the API???  How do I properly invalidate the screen and have it repainted?  (Meaning using the API as it was designed to be used)

 

When an object is invalidated, does the framework call the layout(), then paint()??  What is the sequence of events in the framework please.

 

Patrick

 

 

 

Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: How to get BitMapField repainted on screen invalidate()

[ Edited ]

When the position of a Field changes, you need to call updateLayout().

 

updateLayout() will call layout/sublayout on the fields and then invalidate().

invalidate() just calls the paint() methods.

Message Edited by mreed on 01-06-2009 10:26 AM
Please use plain text.
Developer
Berrysoft
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to get BitMapField repainted on screen invalidate()

I'll give this a whirl, thanks.

 

Patrick

 

Please use plain text.