height--;
// rounded is also responsible for drawing the background
Style s = c.getStyle();
if(s.getBgImage() != null) {
// we need to draw a background image!
Image i = Image.createImage(width, height);
Graphics imageG = i.getGraphics();
imageG.setColor(0);
imageG.fillRoundRect(0, 0, width, height, arcWidth, arcHeight);
int[] rgb = i.getRGB();
int transColor = rgb[0];
int[] imageRGB = s.getBgImage().scaled(width, height).getRGB();
for(int iter = 0 ; iter < rgb.length ; iter++) {
if(rgb[iter] == transColor) {
imageRGB[iter] = 0;
}
}
g.drawImage(new RGBImage(imageRGB, width, height), x, y);
} else {
int foreground = g.getColor();
if(c.hasFocus()) {
g.setColor(s.getBgSelectionColor());
} else {
g.setColor(s.getBgColor());
}
// Its opaque much easier job!
if(s.getBgTransparency() == ((byte)0xff)) {
g.fillRoundRect(x, y , width, height, arcWidth, arcHeight);
} else {
// if its transparent we don't need to do anything, if its
// translucent... well....
if(s.getBgTransparency() != 0) {
Image i = Image.createImage(width, height);
int[] imageRgb;
if(g.getColor() != 0xffffff) {
Graphics imageG = i.getGraphics();
imageG.setColor(g.getColor());
imageG.fillRoundRect(0, 0 , width, height, arcWidth, arcHeight);
imageRgb = i.getRGB();
} else {
// background color is white we need to remove a different color
// black is the only other "reliable" color on the device
Graphics imageG = i.getGraphics();
imageG.setColor(0);
imageG.fillRect(0, 0, width, height);
imageG.setColor(g.getColor());
imageG.fillRoundRect(0, 0 , width, height, arcWidth, arcHeight);
imageRgb = i.getRGB();
}
int removeColor = imageRgb[0];
int size = width * height;
int alphaInt = ((s.getBgTransparency() & 0xff) << 24) & 0xff000000;
for(int iter = 0 ; iter < size ; iter++) {
if(removeColor == imageRgb[iter]) {
imageRgb[iter] = 0;
continue;
}
if((imageRgb[iter] & 0xff000000) != 0) {
imageRgb[iter] = (imageRgb[iter] & 0xffffff) | alphaInt;
}
}
g.drawImage(new RGBImage(imageRgb, width, height), x, y);
}
}
g.setColor(foreground);
}
break;
case TYPE_IMAGE:
int clipX = g.getClipX();
int clipY = g.getClipY();
int clipWidth = g.getClipWidth();
int clipHeight = g.getClipHeight();
Image topLeft = images[4];
Image topRight = images[5];
Image bottomLeft = images[6];
Image center = images[8];
x += topLeft.getWidth();
y += topLeft.getHeight();
height -= (topLeft.getHeight() + bottomLeft.getHeight());
width -= (topLeft.getWidth() + topRight.getWidth());
g.clipRect(x, y, width, height);
int centerWidth = center.getWidth();
int centerHeight = center.getHeight();
for(int xCount = x ; xCount < x + width ; xCount += centerWidth) {
for(int yCount = y ; yCount < y + height ; yCount += centerHeight) {
g.drawImage(center, xCount, yCount);
}
}
Image top = images[0]; Image bottom = images[1];
Image left = images[2]; Image right = images[3];
Image bottomRight = images[7];
g.setClip(clipX, clipY, clipWidth, clipHeight);
x = c.getX();
y = c.getY();
width = c.getWidth();
height = c.getHeight();
g.drawImage(topLeft, x, y);
g.drawImage(bottomLeft, x, y + height - bottomLeft.getHeight());
g.drawImage(topRight, x + width - topRight.getWidth(), y);
g.drawImage(bottomRight, x + width - bottomRight.getWidth(), y + height - bottomRight.getHeight());
g.setClip(clipX, clipY, clipWidth, clipHeight);
drawImageBorderLine(g, topLeft, topRight, top, x, y, width);
g.setClip(clipX, clipY, clipWidth, clipHeight);
drawImageBorderLine(g, bottomLeft, bottomRight, bottom, x, y + height - bottom.getHeight(), width);