Bug 461664 - [Cocoa] Control.getForeground() does not honor alpha channel of color
Summary: [Cocoa] Control.getForeground() does not honor alpha channel of color
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.5   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: 4.5 M6   Edit
Assignee: Niraj Modi CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 435384
  Show dependency tree
 
Reported: 2015-03-08 13:36 EDT by Stefan Winkler CLA
Modified: 2015-05-04 08:15 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Winkler CLA 2015-03-08 13:36:01 EDT
The following test code fails on Mac OS X:

	@Test 
	public void testTransparentForeground()
	{
		Label label = createTestLabel(); // create display, shell and label
		Color transparent = Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT);
		label.setForeground(transparent);
		
		int expected = transparent.getRGBA().alpha;
		int actual = label.getForeground().getRGBA().alpha;
		
		assertEquals(expected, actual);
	}


Culprit is this piece of code 

Color getForegroundColor () {
	return foreground != null ? Color.cocoa_new (display, foreground) : defaultForeground ();
}

which calls this one

public static Color cocoa_new(Device device, double /*float*/ [] handle) {
	return cocoa_new(device, handle, 255);
}

As can be seen, the last parameter (alpha) is set to the constant 255 instead of taking it from the handle[] array which contains the alpha channel at position 3.
Comment 1 Niraj Modi CLA 2015-03-16 06:26:30 EDT
Updated the constructor call in Cocoa Color class to honor the alpha channel from the handle array, via below git patch:
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=3fa10aec500a4081c70ceb9a57998af702891944