Skip to content

Commit 0ec2941

Browse files
committed
Replacing custom logic in Help>Search results to disable icons, with Image constructor call
For the results displayed in Help>Search, Previously, icons for disabled search hits were created by custom pixel-level manipulation using ImageData. This approach, at high zoom levels (e.g., 225%), causes icons to appear slightly distorted, as scaling of ImageData is a destructive operation. This logic has now been replaced by a call to the Image constructor with the flag set to disabled. Contributes to: vi-eclipse/Eclipse-Platform#199
1 parent 53c100e commit 0ec2941

File tree

1 file changed

+3
-37
lines changed

1 file changed

+3
-37
lines changed

ua/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/EngineResultSection.java

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.eclipse.swt.SWT;
3535
import org.eclipse.swt.custom.BusyIndicator;
3636
import org.eclipse.swt.graphics.Image;
37-
import org.eclipse.swt.graphics.ImageData;
3837
import org.eclipse.swt.layout.GridData;
3938
import org.eclipse.swt.layout.GridLayout;
4039
import org.eclipse.swt.widgets.Composite;
@@ -157,9 +156,9 @@ private void createFormText(Composite parent, FormToolkit toolkit) {
157156
searchResults.setImage(ISharedImages.IMG_OBJS_ERROR_TSK, PlatformUI.getWorkbench().getSharedImages()
158157
.getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
159158
searchResults.setImage(desc.getId(), desc.getIconImage());
160-
Image grayedImage = getGrayedImage(desc.getIconImage());
161-
searchResults.setImage(KEY_PREFIX_GRAYED + desc.getId(), grayedImage);
162-
searchResults.addDisposeListener(e -> grayedImage.dispose());
159+
Image disabledImage = new Image(desc.getIconImage().getDevice(), desc.getIconImage(), SWT.IMAGE_GRAY);
160+
searchResults.setImage(desc.getId(), disabledImage);
161+
searchResults.addDisposeListener(e -> disabledImage.dispose());
163162
searchResults.addHyperlinkListener(new IHyperlinkListener() {
164163

165164
@Override
@@ -304,39 +303,6 @@ private ISearchEngineResult[] getResults() {
304303
return results;
305304
}
306305

307-
/**
308-
* Returns a copy of the given image but grayed and half transparent.
309-
* This gives the icon a grayed/disabled look.
310-
*
311-
* @param image the image to gray
312-
* @return the grayed image
313-
*/
314-
private Image getGrayedImage(Image image) {
315-
// first gray the image
316-
Image temp = new Image(image.getDevice(), image, SWT.IMAGE_GRAY);
317-
// then add alpha to blend it 50/50 with the background
318-
ImageData data = temp.getImageData();
319-
ImageData maskData = data.getTransparencyMask();
320-
if (maskData != null) {
321-
for (int y=0;y<maskData.height;++y) {
322-
for (int x=0;x<maskData.width;++x) {
323-
if (maskData.getPixel(x, y) == 0) {
324-
// masked; set to transparent
325-
data.setAlpha(x, y, 0);
326-
}
327-
else {
328-
// not masked; set to translucent
329-
data.setAlpha(x, y, 128);
330-
}
331-
}
332-
}
333-
data.maskData = null;
334-
}
335-
Image grayed = new Image(image.getDevice(), data);
336-
temp.dispose();
337-
return grayed;
338-
}
339-
340306
void updateResults(boolean reflow) {
341307
ISearchEngineResult[] results = getResults();
342308
updateSectionTitle(results.length);

0 commit comments

Comments
 (0)