diff -r 000000000000 -r fb279309251b uidesigner/com.nokia.sdt.test.componentlibrary/components/testing/render_visual.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uidesigner/com.nokia.sdt.test.componentlibrary/components/testing/render_visual.js Fri Apr 03 23:33:03 2009 +0100 @@ -0,0 +1,306 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/* + * Render test + * + * globals available are: + * + * instance (WrappedInstance) + * parent (WrappedInstance) + * children (WrappedInstance[]) + * + * rendering globals: + * graphics (wrapped SWT GC) + * Colors (object from which getColor(r,g,b) is available) + * Fonts (object from which getFont("path") is available) + * Images (object from which newImage(device,w,h) is available) + */ + +include("library.js") + +function Visual() { +} + +function detailedDraw(string, x, y) { + var extent = graphics.stringExtent(string) + var metrics = graphics.getFontMetrics() + var orig = graphics.getForeground() + + var hy = y + metrics.getHeight() + + var origbk = graphics.getBackground() + graphics.setBackground(Colors.getColor(192,192,192)) + graphics.fillRectangle(x, hy-metrics.getAscent(), extent.x, metrics.getAscent()+metrics.getDescent()+metrics.getLeading()) + graphics.setBackground(origbk) + + + java.lang.System.out.println("height="+metrics.getHeight()+ + " descent="+metrics.getDescent()+ + " ascent="+metrics.getAscent()) + graphics.setLineDash(new Array(1,1)) + + // baseline (green) + graphics.setForeground(Colors.getColor(0, 255, 0)) + graphics.drawLine(x, hy, x+extent.x, hy) + + // descent (cyan) + graphics.setForeground(Colors.getColor(0, 255, 255)) + graphics.drawLine(x+1, hy+metrics.getDescent(), x+extent.x, hy+metrics.getDescent()) + + // ascent (yellow) + graphics.setForeground(Colors.getColor(255, 255, 0)) + graphics.drawLine(x, hy-metrics.getAscent(), x+extent.x, hy-metrics.getAscent()) + + // height (red) + graphics.setForeground(Colors.getColor(255, 0, 0)) + graphics.drawLine(x+1, y, x+extent.x, y) + + graphics.setLineDash(null) + + graphics.setForeground(orig) + graphics.drawString(string, x, y) + + + return extent.y +} + +Visual.prototype.getPattern = function(type) { + if (this.image3 == null) { + this.image3 = Images.newImage(graphics.getDevice(), 3, 3) + } + if (this.image4 == null) { + this.image4 = Images.newImage(graphics.getDevice(), 4, 4) + } + + type = Math.floor(type) + var img; + if (type != 8.0 && type != 3.0 && type != 5.0) + img = this.image3 + else + img = this.image4 + + var gc = new GC(graphics.getDevice(), img) + + gc.setBackground(Colors.getColor(255, 255, 255)) + gc.fillRectangle(0, 0, 4, 4); + gc.setBackground(Colors.getColor(255, 255,255)) + gc.setForeground(Colors.getColor(0, 0, 0)) + + switch (type) { + case 1: // solid + default: + gc.setBackground(Colors.getColor(0, 0, 0)) + gc.fillRectangle(0, 0, 5, 5); + break; + case 3: // vertical hatch + gc.drawLine(1, 0, 1, 3); + gc.drawLine(3, 0, 3, 3); + break; + case 4: // forward diagonal hatch + gc.drawLine(0, 2, 2, 0); + break; + case 5: // horizontal hatch + gc.drawLine(0, 1, 3, 1); + gc.drawLine(0, 3, 3, 3); + break; + case 6: // rearward diagonal hatch + gc.drawLine(0, 0, 2, 2); + break; + case 7: // square cross hatch + gc.drawLine(1, 0, 1, 3); + gc.drawLine(0, 1, 3, 1); + break; + case 8: // diamond cross hatch + gc.drawLine(0, 0, 3, 3); + gc.drawLine(2, 0, 0, 2); + break; + } + + gc.dispose() + + return new Pattern(graphics.getDevice(), img) +} + +Visual.prototype.draw = function(instance, laf, graphics) { + var properties = instance.properties + var width = properties["size"].width; + var height = properties.size["height"] + + var base = "data/s60" + //var base = "c:/downloads" + var thickness; + + var r,p,x,y,size,border; + + switch (properties.appearance) { + case 0: + default: + thickness = 1; + graphics.setLineWidth(thickness) + graphics.setForeground(getBlue()) + graphics.setBackground(Colors.getColor(255, 255, 255)) + + graphics.fillGradientRectangle(0, 0, properties.size.width, properties.size.height, true) + break; + case 1: + thickness = 2; + graphics.setLineWidth(thickness) + + r = new Rectangle(width/2, height/2, width/2-4, height/2-4) + + graphics.setForeground(Colors.getColor(48, 64, 64)) + graphics.setLineWidth(2) + graphics.drawRectangle(r) + break; + case 2: + r = new Rectangle(0, 0, width, height) + + graphics.setForeground(Colors.getColor(0, 0, 64)) + graphics.setLineWidth(2) + graphics.drawRectangle(r) + break; + case 3: + // ensure Path is available + p = new Path(graphics.getDevice()) + p.moveTo(width/2, 0) + p.lineTo(0, height) + p.lineTo(width, height/2) + graphics.setClipping(p); + + graphics.setForeground(Colors.getColor(128, 128, 0)) + graphics.setBackground(Colors.getColor(128, 128, 0)) + graphics.setAlpha(64) // note: no effect yet + graphics.setLineWidth(1) + + size = properties.value + if (size <= 0) + size = 1 + + for (y=0; y