uidesigner/com.nokia.sdt.symbian.tests/data/images/components/testRenderLibrary.js
author cawthron
Tue, 24 Mar 2009 22:20:21 -0500
changeset 2 d760517a8095
permissions -rw-r--r--
new
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
cawthron
parents:
diff changeset
     1
/*
cawthron
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
cawthron
parents:
diff changeset
     3
* All rights reserved.
cawthron
parents:
diff changeset
     4
* This component and the accompanying materials are made available
cawthron
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
cawthron
parents:
diff changeset
     6
* which accompanies this distribution, and is available
cawthron
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
cawthron
parents:
diff changeset
     8
*
cawthron
parents:
diff changeset
     9
* Initial Contributors:
cawthron
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
cawthron
parents:
diff changeset
    11
*
cawthron
parents:
diff changeset
    12
* Contributors:
cawthron
parents:
diff changeset
    13
*
cawthron
parents:
diff changeset
    14
* Description: 
cawthron
parents:
diff changeset
    15
*
cawthron
parents:
diff changeset
    16
*/
cawthron
parents:
diff changeset
    17
cawthron
parents:
diff changeset
    18
	// Turn a color property value string into
cawthron
parents:
diff changeset
    19
	// a color. The value is expected to either
cawthron
parents:
diff changeset
    20
	// be a comma delimited RGB or a system color
cawthron
parents:
diff changeset
    21
	
cawthron
parents:
diff changeset
    22
function colorFromString(laf, colorStr) {
cawthron
parents:
diff changeset
    23
	if (colorStr == null || colorStr == "")
cawthron
parents:
diff changeset
    24
		return null;
cawthron
parents:
diff changeset
    25
cawthron
parents:
diff changeset
    26
	var result = null;
cawthron
parents:
diff changeset
    27
	var elements = colorStr.split(",");
cawthron
parents:
diff changeset
    28
	if (elements.length == 3) {
cawthron
parents:
diff changeset
    29
		var valid = true;
cawthron
parents:
diff changeset
    30
		for (var i in elements) {
cawthron
parents:
diff changeset
    31
			var num = parseInt(elements[i]);
cawthron
parents:
diff changeset
    32
			if (isNaN(num))
cawthron
parents:
diff changeset
    33
				valid = false;
cawthron
parents:
diff changeset
    34
		}
cawthron
parents:
diff changeset
    35
		if (valid)
cawthron
parents:
diff changeset
    36
			result = Colors.getColor(elements[0], elements[1], elements[2]);
cawthron
parents:
diff changeset
    37
	}
cawthron
parents:
diff changeset
    38
	else {
cawthron
parents:
diff changeset
    39
		result = laf.getColor(colorStr);
cawthron
parents:
diff changeset
    40
	}
cawthron
parents:
diff changeset
    41
	return result;
cawthron
parents:
diff changeset
    42
}
cawthron
parents:
diff changeset
    43
cawthron
parents:
diff changeset
    44
// Get the effective background color, assuming that everything is transparent
cawthron
parents:
diff changeset
    45
// until we get to a component with an attribute describing how its
cawthron
parents:
diff changeset
    46
// background will be drawn
cawthron
parents:
diff changeset
    47
function getBackgroundColor(instance, laf) {
cawthron
parents:
diff changeset
    48
	var color = null;
cawthron
parents:
diff changeset
    49
	while (instance != null) {
cawthron
parents:
diff changeset
    50
		var bgProperty = instance.component.attributes
cawthron
parents:
diff changeset
    51
			["container-background-color-property-name"];
cawthron
parents:
diff changeset
    52
		if (bgProperty != null) {
cawthron
parents:
diff changeset
    53
			color = colorFromString(laf, instance.properties[bgProperty]);
cawthron
parents:
diff changeset
    54
			if (color != null) {
cawthron
parents:
diff changeset
    55
				//println("used attribute for " + color);
cawthron
parents:
diff changeset
    56
				break;
cawthron
parents:
diff changeset
    57
			}
cawthron
parents:
diff changeset
    58
		}
cawthron
parents:
diff changeset
    59
		var bgColor = instance.component.attributes
cawthron
parents:
diff changeset
    60
			["container-background-color"];
cawthron
parents:
diff changeset
    61
		if (bgColor != null) {
cawthron
parents:
diff changeset
    62
			color = laf.getColor(bgColor);
cawthron
parents:
diff changeset
    63
			if (color != null) {
cawthron
parents:
diff changeset
    64
				//println("used property for " + color);
cawthron
parents:
diff changeset
    65
				break;
cawthron
parents:
diff changeset
    66
			}
cawthron
parents:
diff changeset
    67
		}
cawthron
parents:
diff changeset
    68
		instance = instance.parent;
cawthron
parents:
diff changeset
    69
	}
cawthron
parents:
diff changeset
    70
	if (color == null) {
cawthron
parents:
diff changeset
    71
		color = laf.getColor("EEikColorWindowBackground");
cawthron
parents:
diff changeset
    72
		//println("using background color " + color);
cawthron
parents:
diff changeset
    73
		if (color == null) {
cawthron
parents:
diff changeset
    74
			color = Colors.getColor(255, 255, 255);
cawthron
parents:
diff changeset
    75
		}
cawthron
parents:
diff changeset
    76
	}
cawthron
parents:
diff changeset
    77
	return color;
cawthron
parents:
diff changeset
    78
}
cawthron
parents:
diff changeset
    79
cawthron
parents:
diff changeset
    80
ImageGlobals = getPluginClass("com.nokia.sdt.symbian", "com.nokia.sdt.symbian.images.ImageGlobals")
cawthron
parents:
diff changeset
    81
cawthron
parents:
diff changeset
    82
cawthron
parents:
diff changeset
    83
//	Get an image as specified in a com.nokia.sdt.symbian.ImageProperty
cawthron
parents:
diff changeset
    84
//	@param instance the instance
cawthron
parents:
diff changeset
    85
//	@param imageProperty the property, i.e. instance.properties.image
cawthron
parents:
diff changeset
    86
function getImageFromProperty(instance, graphics, imageProperty) {
cawthron
parents:
diff changeset
    87
	var info = ImageGlobals.getImageInfo(instance, imageProperty);
cawthron
parents:
diff changeset
    88
	return info.getComposedImage(graphics.getDevice())
cawthron
parents:
diff changeset
    89
}
cawthron
parents:
diff changeset
    90
cawthron
parents:
diff changeset
    91
//	Draw an image as specified in a com.nokia.sdt.symbian.ImageProperty
cawthron
parents:
diff changeset
    92
//	into the given rectangle in the gc
cawthron
parents:
diff changeset
    93
//	@param instance the instance
cawthron
parents:
diff changeset
    94
//	@param imageProperty the property, i.e. instance.properties.image
cawthron
parents:
diff changeset
    95
//	@param graphics the GC
cawthron
parents:
diff changeset
    96
//	@param rect the rectangle to draw in
cawthron
parents:
diff changeset
    97
function drawImageFromProperty(instance, graphics, imageProperty, rect) {
cawthron
parents:
diff changeset
    98
	var info = ImageGlobals.getImageInfo(instance, imageProperty);
cawthron
parents:
diff changeset
    99
	var image = info.getComposedImage(graphics.getDevice())
cawthron
parents:
diff changeset
   100
	if (image) {
cawthron
parents:
diff changeset
   101
		var imgRect = image.getBounds()
cawthron
parents:
diff changeset
   102
		graphics.drawImage(image, 0, 0, imgRect.width, imgRect.height, 
cawthron
parents:
diff changeset
   103
			rect.x, rect.y, rect.width, rect.height);
cawthron
parents:
diff changeset
   104
	}
cawthron
parents:
diff changeset
   105
}
cawthron
parents:
diff changeset
   106
cawthron
parents:
diff changeset
   107
cawthron
parents:
diff changeset
   108