Mercurial > projects > dwt-addons
comparison dwtx/ui/internal/forms/widgets/FormImages.d @ 90:7ffeace6c47f
Update 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 06 Jul 2008 23:30:07 +0200 |
parents | 26c6c9dfd13c |
children | 04b47443bb01 |
comparison
equal
deleted
inserted
replaced
89:040da1cb0d76 | 90:7ffeace6c47f |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2007 IBM Corporation and others. | 2 * Copyright (c) 2007, 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
15 //import dwtx.ui.internal.forms.widgets.FormImages; | 15 //import dwtx.ui.internal.forms.widgets.FormImages; |
16 | 16 |
17 import dwt.graphics.Color; | 17 import dwt.graphics.Color; |
18 import dwt.graphics.GC; | 18 import dwt.graphics.GC; |
19 import dwt.graphics.Image; | 19 import dwt.graphics.Image; |
20 import dwt.graphics.RGB; | |
20 import dwt.widgets.Display; | 21 import dwt.widgets.Display; |
21 | 22 |
22 import dwt.dwthelper.utils; | 23 import dwt.dwthelper.utils; |
23 import tango.util.collection.HashMap; | 24 import tango.util.collection.HashMap; |
24 | 25 |
37 private this() { | 38 private this() { |
38 } | 39 } |
39 | 40 |
40 private abstract class ImageIdentifier { | 41 private abstract class ImageIdentifier { |
41 Display fDisplay; | 42 Display fDisplay; |
42 Color[] fColors; | 43 RGB[] fRGBs; |
43 int fLength; | 44 int fLength; |
44 | 45 |
45 this(Display display, Color[] colors, int length) { | 46 this(Display display, Color[] colors, int length) { |
46 fDisplay = display; | 47 fDisplay = display; |
47 fColors = colors; | 48 fRGBs = new RGB[colors.length]; |
49 for (int i = 0; i < colors.length; i++) { | |
50 Color color = colors[i]; | |
51 fRGBs[i] = color is null ? null : color.getRGB(); | |
52 } | |
48 fLength = length; | 53 fLength = length; |
49 } | 54 } |
50 | 55 |
51 public bool equals(Object obj) { | 56 public bool equals(Object obj) { |
52 if (null !is cast(ImageIdentifier)obj ) { | 57 if (null !is cast(ImageIdentifier)obj ) { |
53 ImageIdentifier id = cast(ImageIdentifier)obj; | 58 ImageIdentifier id = cast(ImageIdentifier)obj; |
54 if (id.fColors.length is fColors.length) { | 59 if (id.fRGBs.length is fRGBs.length) { |
55 bool result = id.fDisplay.opEquals(fDisplay) && id.fLength is fLength; | 60 bool result = id.fDisplay.opEquals(fDisplay) && id.fLength is fLength; |
56 for (int i = 0; i < fColors.length && result; i++) { | 61 for (int i = 0; i < fRGBs.length && result; i++) { |
57 result = result && id.fColors[i].opEquals(fColors[i]); | 62 result = result && id.fRGBs[i].opEquals(fRGBs[i]); |
58 } | 63 } |
59 return result; | 64 return result; |
60 } | 65 } |
61 } | 66 } |
62 return false; | 67 return false; |
63 } | 68 } |
64 | 69 |
65 public override hash_t toHash() { | 70 public override hash_t toHash() { |
66 int hash = fDisplay.toHash(); | 71 int hash = fDisplay.toHash(); |
67 for (int i = 0; i < fColors.length; i++) | 72 for (int i = 0; i < fRGBs.length; i++) |
68 hash = hash * 7 + fColors[i].toHash(); | 73 hash = hash * 7 + fRGBs[i].toHash(); |
69 hash = hash * 7 + fLength; | 74 hash = hash * 7 + fLength; |
70 return hash; | 75 return hash; |
71 } | 76 } |
72 } | 77 } |
73 | 78 |
99 return hash; | 104 return hash; |
100 } | 105 } |
101 } | 106 } |
102 | 107 |
103 private class ComplexImageIdentifier : ImageIdentifier { | 108 private class ComplexImageIdentifier : ImageIdentifier { |
104 Color fBg; | 109 RGB fBgRGB; |
105 bool fVertical; | 110 bool fVertical; |
106 int[] fPercents; | 111 int[] fPercents; |
107 | 112 |
108 public this(Display display, Color[] colors, int length, | 113 public this(Display display, Color[] colors, int length, |
109 int[] percents, bool vertical, Color bg) { | 114 int[] percents, bool vertical, Color bg) { |
110 super(display, colors, length); | 115 super(display, colors, length); |
111 fBg = bg; | 116 fBgRGB = bg is null ? null : bg.getRGB(); |
112 fVertical = vertical; | 117 fVertical = vertical; |
113 fPercents = percents; | 118 fPercents = percents; |
114 } | 119 } |
115 | 120 |
116 public bool equals(Object obj) { | 121 public bool equals(Object obj) { |
117 if (null !is cast(ComplexImageIdentifier)obj ) { | 122 if (null !is cast(ComplexImageIdentifier)obj ) { |
118 ComplexImageIdentifier id = cast(ComplexImageIdentifier) obj; | 123 ComplexImageIdentifier id = cast(ComplexImageIdentifier) obj; |
119 if (super.equals(obj) && | 124 if (super.equals(obj) && |
120 id.fVertical is fVertical && ArrayEquals(id.fPercents, fPercents)) { | 125 id.fVertical is fVertical && ArrayEquals(id.fPercents, fPercents)) { |
121 if ((id.fBg is null && fBg is null) || | 126 if ((id.fBgRGB is null && fBgRGB is null) || |
122 (id.fBg !is null && id.fBg.opEquals(fBg))) | 127 (id.fBgRGB !is null && id.fBgRGB.opEquals(fBgRGB))) |
123 return true; | 128 return true; |
124 // if the only thing that isn't the same is the background color | 129 // if the only thing that isn't the same is the background color |
125 // still return true if it does not matter (percents add up to 100) | 130 // still return true if it does not matter (percents add up to 100) |
126 int sum = 0; | 131 int sum = 0; |
127 for (int i = 0; i < fPercents.length; i++) | 132 for (int i = 0; i < fPercents.length; i++) |