Community
Participate
Working Groups
I am trying to paint something that looks like a Native Scrollbar. If you look at a Windows Scrollbar, it has a small checkerboard pattern of White and System.ControlColor. To achieve this in SWT, we would need some type of pattern (I believe this is called a Brush) that can be set and will affect all GC operations afterwards. Windows, I believe, supports an 8x8 bit pattern, maybe other sizes as well. There are many other uses for patterns, including drawing an approximation of a drop shadow, since transparent colors currently are not supported in SWT. NOTES: CM (11/23/00 3:43:57 PM) You currently can't do a pattern paint. The work-around is to use an Image. For your example of a scrollbar, the following example code may be close to what you want: package test; import com.ibm.swt.*; import com.ibm.swt.graphics.*; import com.ibm.swt.widgets.*; public class _GraphicsScrapbook { public static void main(String[] args) { Shell shell = new Shell(); Display display = shell.getDisplay(); Color white = display.getSystemColor(SWT.COLOR_WHITE); Color shadow = display.getSystemColor (SWT.COLOR_WIDGET_BACKGROUND); PaletteData palette = new PaletteData(new RGB[] { new RGB(white.getRed(), white.getGreen(), white.getBlue ()), new RGB(shadow.getRed(), shadow.getGreen(), shadow.getBlue())}); int width = 18; // your scrollbar width int height = 200; // your scrollbar height ImageData imageData = new ImageData(width, height, 1, palette); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if ((x + y) % 2 == 0) { imageData.setPixel(x, y, 1); } else { imageData.setPixel(x, y, 0); } } } shell.setSize(width + 20, height); shell.setBackground(white); // to see the image more easily shell.open(); Image image = new Image(display, imageData); GC gc = new GC(shell); gc.drawImage(image, 10, 0); gc.dispose(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); } } TRH (11/27/2000 11:02:32 AM) I have a question about this workaround. Is ImageData Platform Specific? I was hesitant to create Palettes and ImageData since it might not work on all platforms. Maybe Indexed Images (above) ARE cross-platform. What about True- color, RGB vs. GBR, etc. Also, I would probably statically cache this Image rather than create it and dispose it. Are there any problems doing that? TRH (1/17/2001 9:16:42 AM) We will need the ability to Tile an Image in a GC. The region for tiling may be Non-rectangular: <HTML> <B bgImage = "tile.gif"> Some text <BR> Some more text </B> </HTML> This is one of Many features that is required to properly render HTML. Another would be transparency. CM (2/5/01 9:50:00 PM) ImageData and PaletteData are NOT platform-specific. They are device- independent data classes. Transparency is supported in ImageData. SN (2/5/01 6:39:16 PM) No plans to do this at this time. TRH (4/19/2001 10:12:39 AM) Sorry for getting off the subject of 8x8 brush patterns. By transparency in HTML, I meant transparency of a layer, which can contain HTML. While transparency is supported for Image, we would need it for drawString(), drawLine(), etc.
PRODUCT VERSION: SWT all versions.
To be revisited as part of a rework of the SWT graphics support.
Moving from Later.
Could this be done with a region and copyArea()? In any case, moving to SSQ.
Fixed in HEAD. See GC.setBackgroundPattern().