Bug 4537 - DCR Ability to paint with a brush pattern (1G0I8BE)
Summary: DCR Ability to paint with a brush pattern (1G0I8BE)
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.0   Edit
Hardware: All Windows NT
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-10-11 14:18 EDT by Mike Wilson CLA
Modified: 2005-04-12 11:47 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Wilson CLA 2001-10-11 14:18:32 EDT
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.
Comment 1 DJ Houghton CLA 2001-10-29 16:20:10 EST
PRODUCT VERSION:

	SWT all versions.

Comment 2 Mike Wilson CLA 2002-05-23 15:44:55 EDT
To be revisited as part of a rework of the SWT graphics support.
Comment 3 Veronika Irvine CLA 2002-09-11 14:07:51 EDT
Moving from Later.
Comment 4 Steve Northover CLA 2004-10-04 12:56:48 EDT
Could this be done with a region and copyArea()?  In any case, moving to SSQ.
Comment 5 Silenio Quarti CLA 2005-04-12 11:47:47 EDT
Fixed in HEAD. See GC.setBackgroundPattern().