uidesigner/com.nokia.sdt.symbian.tests/data/images/components/testRenderLibrary.js
changeset 0 fb279309251b
equal deleted inserted replaced
-1:000000000000 0:fb279309251b
       
     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 	// Turn a color property value string into
       
    19 	// a color. The value is expected to either
       
    20 	// be a comma delimited RGB or a system color
       
    21 	
       
    22 function colorFromString(laf, colorStr) {
       
    23 	if (colorStr == null || colorStr == "")
       
    24 		return null;
       
    25 
       
    26 	var result = null;
       
    27 	var elements = colorStr.split(",");
       
    28 	if (elements.length == 3) {
       
    29 		var valid = true;
       
    30 		for (var i in elements) {
       
    31 			var num = parseInt(elements[i]);
       
    32 			if (isNaN(num))
       
    33 				valid = false;
       
    34 		}
       
    35 		if (valid)
       
    36 			result = Colors.getColor(elements[0], elements[1], elements[2]);
       
    37 	}
       
    38 	else {
       
    39 		result = laf.getColor(colorStr);
       
    40 	}
       
    41 	return result;
       
    42 }
       
    43 
       
    44 // Get the effective background color, assuming that everything is transparent
       
    45 // until we get to a component with an attribute describing how its
       
    46 // background will be drawn
       
    47 function getBackgroundColor(instance, laf) {
       
    48 	var color = null;
       
    49 	while (instance != null) {
       
    50 		var bgProperty = instance.component.attributes
       
    51 			["container-background-color-property-name"];
       
    52 		if (bgProperty != null) {
       
    53 			color = colorFromString(laf, instance.properties[bgProperty]);
       
    54 			if (color != null) {
       
    55 				//println("used attribute for " + color);
       
    56 				break;
       
    57 			}
       
    58 		}
       
    59 		var bgColor = instance.component.attributes
       
    60 			["container-background-color"];
       
    61 		if (bgColor != null) {
       
    62 			color = laf.getColor(bgColor);
       
    63 			if (color != null) {
       
    64 				//println("used property for " + color);
       
    65 				break;
       
    66 			}
       
    67 		}
       
    68 		instance = instance.parent;
       
    69 	}
       
    70 	if (color == null) {
       
    71 		color = laf.getColor("EEikColorWindowBackground");
       
    72 		//println("using background color " + color);
       
    73 		if (color == null) {
       
    74 			color = Colors.getColor(255, 255, 255);
       
    75 		}
       
    76 	}
       
    77 	return color;
       
    78 }
       
    79 
       
    80 ImageGlobals = getPluginClass("com.nokia.sdt.symbian", "com.nokia.sdt.symbian.images.ImageGlobals")
       
    81 
       
    82 
       
    83 //	Get an image as specified in a com.nokia.sdt.symbian.ImageProperty
       
    84 //	@param instance the instance
       
    85 //	@param imageProperty the property, i.e. instance.properties.image
       
    86 function getImageFromProperty(instance, graphics, imageProperty) {
       
    87 	var info = ImageGlobals.getImageInfo(instance, imageProperty);
       
    88 	return info.getComposedImage(graphics.getDevice())
       
    89 }
       
    90 
       
    91 //	Draw an image as specified in a com.nokia.sdt.symbian.ImageProperty
       
    92 //	into the given rectangle in the gc
       
    93 //	@param instance the instance
       
    94 //	@param imageProperty the property, i.e. instance.properties.image
       
    95 //	@param graphics the GC
       
    96 //	@param rect the rectangle to draw in
       
    97 function drawImageFromProperty(instance, graphics, imageProperty, rect) {
       
    98 	var info = ImageGlobals.getImageInfo(instance, imageProperty);
       
    99 	var image = info.getComposedImage(graphics.getDevice())
       
   100 	if (image) {
       
   101 		var imgRect = image.getBounds()
       
   102 		graphics.drawImage(image, 0, 0, imgRect.width, imgRect.height, 
       
   103 			rect.x, rect.y, rect.width, rect.height);
       
   104 	}
       
   105 }
       
   106 
       
   107 
       
   108