2
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
/*
|
|
19 |
* Render test
|
|
20 |
*
|
|
21 |
* globals available are:
|
|
22 |
*
|
|
23 |
* instance (WrappedInstance)
|
|
24 |
* parent (WrappedInstance)
|
|
25 |
* children (WrappedInstance[])
|
|
26 |
*
|
|
27 |
* rendering globals:
|
|
28 |
* graphics (wrapped SWT GC)
|
|
29 |
* Colors (object from which getColor(r,g,b) is available)
|
|
30 |
* Fonts (object from which getFont("path") is available)
|
|
31 |
* Images (object from which newImage(device,w,h) is available)
|
|
32 |
*/
|
|
33 |
|
|
34 |
include("library.js")
|
|
35 |
|
|
36 |
function Visual() {
|
|
37 |
}
|
|
38 |
|
|
39 |
function detailedDraw(string, x, y) {
|
|
40 |
var extent = graphics.stringExtent(string)
|
|
41 |
var metrics = graphics.getFontMetrics()
|
|
42 |
var orig = graphics.getForeground()
|
|
43 |
|
|
44 |
var hy = y + metrics.getHeight()
|
|
45 |
|
|
46 |
var origbk = graphics.getBackground()
|
|
47 |
graphics.setBackground(Colors.getColor(192,192,192))
|
|
48 |
graphics.fillRectangle(x, hy-metrics.getAscent(), extent.x, metrics.getAscent()+metrics.getDescent()+metrics.getLeading())
|
|
49 |
graphics.setBackground(origbk)
|
|
50 |
|
|
51 |
|
|
52 |
java.lang.System.out.println("height="+metrics.getHeight()+
|
|
53 |
" descent="+metrics.getDescent()+
|
|
54 |
" ascent="+metrics.getAscent())
|
|
55 |
graphics.setLineDash(new Array(1,1))
|
|
56 |
|
|
57 |
// baseline (green)
|
|
58 |
graphics.setForeground(Colors.getColor(0, 255, 0))
|
|
59 |
graphics.drawLine(x, hy, x+extent.x, hy)
|
|
60 |
|
|
61 |
// descent (cyan)
|
|
62 |
graphics.setForeground(Colors.getColor(0, 255, 255))
|
|
63 |
graphics.drawLine(x+1, hy+metrics.getDescent(), x+extent.x, hy+metrics.getDescent())
|
|
64 |
|
|
65 |
// ascent (yellow)
|
|
66 |
graphics.setForeground(Colors.getColor(255, 255, 0))
|
|
67 |
graphics.drawLine(x, hy-metrics.getAscent(), x+extent.x, hy-metrics.getAscent())
|
|
68 |
|
|
69 |
// height (red)
|
|
70 |
graphics.setForeground(Colors.getColor(255, 0, 0))
|
|
71 |
graphics.drawLine(x+1, y, x+extent.x, y)
|
|
72 |
|
|
73 |
graphics.setLineDash(null)
|
|
74 |
|
|
75 |
graphics.setForeground(orig)
|
|
76 |
graphics.drawString(string, x, y)
|
|
77 |
|
|
78 |
|
|
79 |
return extent.y
|
|
80 |
}
|
|
81 |
|
|
82 |
Visual.prototype.getPattern = function(type) {
|
|
83 |
if (this.image3 == null) {
|
|
84 |
this.image3 = Images.newImage(graphics.getDevice(), 3, 3)
|
|
85 |
}
|
|
86 |
if (this.image4 == null) {
|
|
87 |
this.image4 = Images.newImage(graphics.getDevice(), 4, 4)
|
|
88 |
}
|
|
89 |
|
|
90 |
type = Math.floor(type)
|
|
91 |
var img;
|
|
92 |
if (type != 8.0 && type != 3.0 && type != 5.0)
|
|
93 |
img = this.image3
|
|
94 |
else
|
|
95 |
img = this.image4
|
|
96 |
|
|
97 |
var gc = new GC(graphics.getDevice(), img)
|
|
98 |
|
|
99 |
gc.setBackground(Colors.getColor(255, 255, 255))
|
|
100 |
gc.fillRectangle(0, 0, 4, 4);
|
|
101 |
gc.setBackground(Colors.getColor(255, 255,255))
|
|
102 |
gc.setForeground(Colors.getColor(0, 0, 0))
|
|
103 |
|
|
104 |
switch (type) {
|
|
105 |
case 1: // solid
|
|
106 |
default:
|
|
107 |
gc.setBackground(Colors.getColor(0, 0, 0))
|
|
108 |
gc.fillRectangle(0, 0, 5, 5);
|
|
109 |
break;
|
|
110 |
case 3: // vertical hatch
|
|
111 |
gc.drawLine(1, 0, 1, 3);
|
|
112 |
gc.drawLine(3, 0, 3, 3);
|
|
113 |
break;
|
|
114 |
case 4: // forward diagonal hatch
|
|
115 |
gc.drawLine(0, 2, 2, 0);
|
|
116 |
break;
|
|
117 |
case 5: // horizontal hatch
|
|
118 |
gc.drawLine(0, 1, 3, 1);
|
|
119 |
gc.drawLine(0, 3, 3, 3);
|
|
120 |
break;
|
|
121 |
case 6: // rearward diagonal hatch
|
|
122 |
gc.drawLine(0, 0, 2, 2);
|
|
123 |
break;
|
|
124 |
case 7: // square cross hatch
|
|
125 |
gc.drawLine(1, 0, 1, 3);
|
|
126 |
gc.drawLine(0, 1, 3, 1);
|
|
127 |
break;
|
|
128 |
case 8: // diamond cross hatch
|
|
129 |
gc.drawLine(0, 0, 3, 3);
|
|
130 |
gc.drawLine(2, 0, 0, 2);
|
|
131 |
break;
|
|
132 |
}
|
|
133 |
|
|
134 |
gc.dispose()
|
|
135 |
|
|
136 |
return new Pattern(graphics.getDevice(), img)
|
|
137 |
}
|
|
138 |
|
|
139 |
Visual.prototype.draw = function(instance, laf, graphics) {
|
|
140 |
var properties = instance.properties
|
|
141 |
var width = properties["size"].width;
|
|
142 |
var height = properties.size["height"]
|
|
143 |
|
|
144 |
var base = "data/s60"
|
|
145 |
//var base = "c:/downloads"
|
|
146 |
var thickness;
|
|
147 |
|
|
148 |
var r,p,x,y,size,border;
|
|
149 |
|
|
150 |
switch (properties.appearance) {
|
|
151 |
case 0:
|
|
152 |
default:
|
|
153 |
thickness = 1;
|
|
154 |
graphics.setLineWidth(thickness)
|
|
155 |
graphics.setForeground(getBlue())
|
|
156 |
graphics.setBackground(Colors.getColor(255, 255, 255))
|
|
157 |
|
|
158 |
graphics.fillGradientRectangle(0, 0, properties.size.width, properties.size.height, true)
|
|
159 |
break;
|
|
160 |
case 1:
|
|
161 |
thickness = 2;
|
|
162 |
graphics.setLineWidth(thickness)
|
|
163 |
|
|
164 |
r = new Rectangle(width/2, height/2, width/2-4, height/2-4)
|
|
165 |
|
|
166 |
graphics.setForeground(Colors.getColor(48, 64, 64))
|
|
167 |
graphics.setLineWidth(2)
|
|
168 |
graphics.drawRectangle(r)
|
|
169 |
break;
|
|
170 |
case 2:
|
|
171 |
r = new Rectangle(0, 0, width, height)
|
|
172 |
|
|
173 |
graphics.setForeground(Colors.getColor(0, 0, 64))
|
|
174 |
graphics.setLineWidth(2)
|
|
175 |
graphics.drawRectangle(r)
|
|
176 |
break;
|
|
177 |
case 3:
|
|
178 |
// ensure Path is available
|
|
179 |
p = new Path(graphics.getDevice())
|
|
180 |
p.moveTo(width/2, 0)
|
|
181 |
p.lineTo(0, height)
|
|
182 |
p.lineTo(width, height/2)
|
|
183 |
graphics.setClipping(p);
|
|
184 |
|
|
185 |
graphics.setForeground(Colors.getColor(128, 128, 0))
|
|
186 |
graphics.setBackground(Colors.getColor(128, 128, 0))
|
|
187 |
graphics.setAlpha(64) // note: no effect yet
|
|
188 |
graphics.setLineWidth(1)
|
|
189 |
|
|
190 |
size = properties.value
|
|
191 |
if (size <= 0)
|
|
192 |
size = 1
|
|
193 |
|
|
194 |
for (y=0; y<height; y+=size)
|
|
195 |
for (x=size*(((y/size)&1)^1); x<width; x+=size*2)
|
|
196 |
graphics.fillRectangle(x, y, size, size)
|
|
197 |
|
|
198 |
graphics.setForeground(Colors.getColor(0, 128, 128))
|
|
199 |
graphics.setBackground(Colors.getColor(0, 128, 128))
|
|
200 |
graphics.setAlpha(128) // note: no effect yet
|
|
201 |
for (y=0; y<height; y+=size)
|
|
202 |
for (x=size*((y/size)&1); x<width; x+=size*2)
|
|
203 |
graphics.fillRectangle(x, y, size, size)
|
|
204 |
break;
|
|
205 |
|
|
206 |
case 4:
|
|
207 |
r = new Rectangle(0, 0, width, height)
|
|
208 |
graphics.setLineWidth(1)
|
|
209 |
graphics.drawRectangle(r)
|
|
210 |
|
|
211 |
r = new Rectangle(4, height/2, width-8, height/2-4)
|
|
212 |
|
|
213 |
graphics.drawRectangle(r)
|
|
214 |
graphics.setFont(Fonts.getGlobalFont(base+"/fonts/Alp17.14.ttf", 14))
|
|
215 |
|
|
216 |
graphics.setForeground(Colors.getColor(0, 0, 0))
|
|
217 |
//detailedDraw("Hello", r.x, r.y)
|
|
218 |
graphics.drawFormattedString("\"Hello Sedona!\" says a wrapped box.\nFoo,\nbar.",
|
|
219 |
r,
|
|
220 |
Font.WRAPPING_ENABLED+Font.DRAW_TRANSPARENT+Font.ALIGN_CENTER);
|
|
221 |
break;
|
|
222 |
|
|
223 |
case 5:
|
|
224 |
graphics.setFont(Fonts.getGlobalFont(base+"/fonts/Alb13.10.ttf", 10))
|
|
225 |
h = graphics.getFontMetrics().getHeight()
|
|
226 |
r = new Rectangle(4, height/4, width-8, height/4*3-8)
|
|
227 |
graphics.drawFormattedString("First", r, 0)
|
|
228 |
r.y += h
|
|
229 |
graphics.drawFormattedString("Second", r, Font.OPTIONS_STRIKETHROUGH)
|
|
230 |
r.y += h
|
|
231 |
graphics.drawFormattedString("Third", r, Font.OPTIONS_UNDERLINE)
|
|
232 |
break;
|
|
233 |
|
|
234 |
case 6:
|
|
235 |
r = 32
|
|
236 |
str="!xpEdant \u011E \u52a3\u554f\u6C55"
|
|
237 |
graphics.setFont(Fonts.getGlobalFont(base+"/fonts/Alb19.15.ttf", 15))
|
|
238 |
r += detailedDraw(str, 4, r)
|
|
239 |
graphics.setFont(Fonts.getGlobalFont(base+"/fonts/Alp17.14.ttf", 14))
|
|
240 |
r += detailedDraw(str, 4, r)
|
|
241 |
graphics.setFont(Fonts.getGlobalFont(base+"/fonts/Alpi17.14.ttf", 14))
|
|
242 |
r += detailedDraw(str, 4, r)
|
|
243 |
graphics.setFont(Fonts.getGlobalFont(base+"/fonts/Albi17b.14.ttf", 14))
|
|
244 |
r += detailedDraw(str, 4, r)
|
|
245 |
graphics.setFont(Fonts.getGlobalFont(base+"/fonts/Alb12.9.ttf", 9))
|
|
246 |
r += detailedDraw(str, 4, r)
|
|
247 |
graphics.setFont(Fonts.getGlobalFont(base+"/fonts/Alb17.14.ttf", 14))
|
|
248 |
r += detailedDraw(str, 4, r)
|
|
249 |
graphics.setFont(Fonts.getGlobalFont(base+"/fonts/Aco21.16.ttf", 16))
|
|
250 |
r += detailedDraw("|=+-\u00d7\u00f7", 4, r)
|
|
251 |
graphics.setFont(Fonts.getGlobalFont(base+"/fonts/JapanPlain12.12.ttf", 12))
|
|
252 |
r += detailedDraw(str, 4, r)
|
|
253 |
graphics.setFont(Fonts.getGlobalFont(base+"/fonts/JapanPlain16.17.ttf", 17))
|
|
254 |
r += detailedDraw(str, 4, r)
|
|
255 |
//graphics.setFont(Fonts.getGlobalFont("c:/winnt/fonts/Arial.ttf", 12))
|
|
256 |
//r += detailedDraw(str, 4, r)
|
|
257 |
//graphics.setFont(Fonts.getGlobalFont("c:/winnt/fonts/ArialUni.ttf", 12))
|
|
258 |
//r += detailedDraw(str, 4, r)
|
|
259 |
break;
|
|
260 |
|
|
261 |
case 7:
|
|
262 |
graphics.setBackground(Colors.getColor(64,160,160))
|
|
263 |
graphics.fillRectangle(0, 0, width, height)
|
|
264 |
|
|
265 |
border = width/8
|
|
266 |
// ensure Pattern works
|
|
267 |
p = new Path(graphics.getDevice())
|
|
268 |
p.moveTo(border, height/2)
|
|
269 |
p.quadTo(border, border, width/2-border, border*2)
|
|
270 |
p.quadTo(width-border, border, width-border, height/2-border)
|
|
271 |
p.quadTo(width-border, height-border, width/2-border, height-border)
|
|
272 |
p.quadTo(border, height-border, border, height/2-border)
|
|
273 |
graphics.setClipping(p);
|
|
274 |
|
|
275 |
pattern = this.getPattern(properties.value)
|
|
276 |
graphics.setBackgroundPattern(pattern)
|
|
277 |
graphics.setForegroundPattern(pattern)
|
|
278 |
|
|
279 |
// graphics.setBackground(Colors.getColor(255, 128, 64))
|
|
280 |
graphics.setForeground(Colors.getColor(0, 0, 0))
|
|
281 |
graphics.fillRectangle(0, 0, width, height)
|
|
282 |
|
|
283 |
break;
|
|
284 |
|
|
285 |
|
|
286 |
}
|
|
287 |
|
|
288 |
// draw a label on top identifying this
|
|
289 |
full = new Rectangle(0, 0, width, height)
|
|
290 |
graphics.setClipping(full)
|
|
291 |
graphics.setForeground(Colors.getColor(0, 0, 128))
|
|
292 |
graphics.setBackground(Colors.getColor(128, 128, 128))
|
|
293 |
//java.lang.System.out.println("1")
|
|
294 |
graphics.setFont(Fonts.getGlobalFont(base+"/fonts/Alpi12.9.ttf", 9))
|
|
295 |
|
|
296 |
s = '(name='+properties.name+'; appearance='+properties.appearance+')';
|
|
297 |
r = graphics.formattedStringExtent(s, full, Font.WRAPPING_ENABLED)
|
|
298 |
//java.lang.System.out.println("r="+r)
|
|
299 |
graphics.drawFormattedString(s, r,
|
|
300 |
Font.WRAPPING_ENABLED+Font.DRAW_OPAQUE);
|
|
301 |
}
|
|
302 |
|
|
303 |
Visual.prototype.getPreferredSize = function(wHint, hHint) {
|
|
304 |
return null; // needs implementation
|
|
305 |
}
|
|
306 |
|