Skip to main content
summaryrefslogtreecommitdiffstats
blob: 10002e9bba3432ce6308de890b04310e943dd80d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*******************************************************************************
 * Copyright (c) 2000, 2006 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *******************************************************************************/

package org.eclipse.cdt.debug.internal.ui;

import java.util.Arrays;

import org.eclipse.jface.resource.CompositeImageDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;

public class OverlayImageDescriptor extends CompositeImageDescriptor {

	static final int DEFAULT_WIDTH = 16;
	static final int DEFAULT_HEIGHT = 16;

	public static final int TOP_LEFT = 0;
	public static final int TOP_RIGHT = 1;
	public static final int BOTTOM_LEFT = 2;
	public static final int BOTTOM_RIGHT = 3;

	// the base image
	private Image fBase;

	// the overlay images
	private ImageDescriptor[] fOverlays;

	// the size
	private Point fSize;

	public OverlayImageDescriptor( Image base, ImageDescriptor[] overlays ) {
		this( base, overlays, new Point( DEFAULT_WIDTH, DEFAULT_HEIGHT ) );
	}

	public OverlayImageDescriptor( Image base, ImageDescriptor[] overlays, Point size ) {
		setBase( base );
		setOverlays( overlays );
		setSize( size );
	}

	/**
	 * Draw the fOverlays for the reciever.
	 */
	protected void drawOverlays(ImageDescriptor[] overlays) {
		Point size = getSize();

		for ( int i = 0; i < overlays.length; i++ ) {
			ImageDescriptor overlay = overlays[i];
			if ( overlay == null )
				continue;
			ImageData overlayData = overlay.getImageData();
			//Use the missing descriptor if it is not there.
			if ( overlayData == null )
				overlayData = ImageDescriptor.getMissingImageDescriptor().getImageData();
			switch( i ) {
				case TOP_LEFT:
					drawImage( overlayData, 0, 0 );
					break;
				case TOP_RIGHT:
					drawImage( overlayData, size.x - overlayData.width, 0 );
					break;
				case BOTTOM_LEFT:
					drawImage( overlayData, 0, size.y - overlayData.height );
					break;
				case BOTTOM_RIGHT:
					drawImage( overlayData, size.x - overlayData.width, size.y - overlayData.height );
					break;
			}
		}
	}

	public boolean equals( Object o ) {
		if ( !(o instanceof OverlayImageDescriptor) )
			return false;
		OverlayImageDescriptor other = (OverlayImageDescriptor)o;
		return getBase().equals( other.getBase() ) && Arrays.equals( getOverlays(), other.getOverlays() );
	}

	public int hashCode() {
		int code = getBase().hashCode();
		for (int i = 0; i < getOverlays().length; i++) {
			if ( getOverlays()[i] != null )
				code ^= getOverlays()[i].hashCode();
		}
		return code;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int,
	 *      int)
	 */
	protected void drawCompositeImage( int width, int height ) {
		drawImage( getBase().getImageData(), 0, 0 );
		drawOverlays( getOverlays() );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.resource.CompositeImageDescriptor#getSize()
	 */
	protected Point getSize() {
		return this.fSize;
	}

	private Image getBase() {
		return this.fBase;
	}

	private void setBase( Image base ) {
		this.fBase = base;
	}

	private ImageDescriptor[] getOverlays() {
		return this.fOverlays;
	}

	private void setOverlays( ImageDescriptor[] overlays ) {
		this.fOverlays = overlays;
	}

	private void setSize( Point size ) {
		this.fSize = size;
	}
}

Back to the top