region.intersect(clipping);
void drawBackground(GC gc, int[] shape, boolean selected) {	Point size = getSize();	int height = tabHeight + HIGHLIGHT_HEADER; 	int y = onBottom ? size.y - borderBottom - height : borderTop;	int x = 0;	int width = size.x;	if (borderLeft > 0) {		x += 1; width -= 2;	}		Region clipping = new Region();	gc.getClipping(clipping);	Region region = new Region();	region.add(shape);	gc.setClipping(region);		Color defaultBackground = selected ? selectionBackground : getBackground();	Image image = selected ? selectionBgImage : bgImage;	Color[] colors = selected ? selectionGradientColors : gradientColors;	boolean vertical = selected ? selectionGradientVertical : gradientVertical;	int[] percents = selected ? selectionGradientPercents : gradientPercents;		if (image != null) {		// draw the background image in shape		gc.setBackground(defaultBackground);		gc.fillRectangle(x, y, width, height);		Rectangle imageRect = image.getBounds();		gc.drawImage(image, imageRect.x, imageRect.y, imageRect.width, imageRect.height, x, y, width, height);	} else if (colors != null) {		// draw gradient		if (colors.length == 1) {			Color background = colors[0] != null ? colors[0] : defaultBackground;			gc.setBackground(background);			gc.fillRectangle(x, y, width, height);		} else {			if (vertical) {				if (onBottom) {					int pos = 0;					if (percents[percents.length - 1] < 100) {						pos = percents[percents.length - 1] * height / 100;						gc.setBackground(defaultBackground);						gc.fillRectangle(x, y, width, pos);					}					Color lastColor = colors[colors.length-1];					if (lastColor == null) lastColor = defaultBackground;					for (int i = percents.length-1; i >= 0; i--) {						gc.setForeground(lastColor);						lastColor = colors[i];						if (lastColor == null) lastColor = defaultBackground;						gc.setBackground(lastColor);						int gradientHeight = percents[i] * height / 100;						gc.fillGradientRectangle(x, y+pos, width, gradientHeight, true);						pos += gradientHeight;					}				} else {					Color lastColor = colors[0];					if (lastColor == null) lastColor = defaultBackground;					int pos = 0;					for (int i = 0; i < percents.length; i++) {						gc.setForeground(lastColor);						lastColor = colors[i + 1];						if (lastColor == null) lastColor = defaultBackground;						gc.setBackground(lastColor);						int gradientHeight = percents[i] * height / 100;						gc.fillGradientRectangle(x, y+pos, width, gradientHeight, true);						pos += gradientHeight;					}					if (pos < height) {						gc.setBackground(defaultBackground);						gc.fillRectangle(x, pos, width, height-pos);					}				}			} else { //horizontal gradient				Color lastColor = colors[0];				if (lastColor == null) lastColor = defaultBackground;				int pos = 0;				for (int i = 0; i < percents.length; ++i) {					gc.setForeground(lastColor);					lastColor = colors[i + 1];					if (lastColor == null) lastColor = defaultBackground;					gc.setBackground(lastColor);					int gradientWidth = (percents[i] * width / 100) - pos;					gc.fillGradientRectangle(x+pos, y, gradientWidth, height, false);					pos += gradientWidth;				}				if (pos < width) {					gc.setBackground(defaultBackground);					gc.fillRectangle(x+pos, y, width-pos, height);				}			}		}	} else {		// draw a solid background using default background in shape		gc.setBackground(defaultBackground);		gc.fillRectangle(x, y, width, height);	}	gc.setClipping(clipping);	clipping.dispose();	region.dispose();}