org.symbian.tools.wrttools.previewer/preview/script/emulator.js
changeset 412 72448215f517
parent 407 c7c8bde493b1
child 423 742a5cb59f9a
--- a/org.symbian.tools.wrttools.previewer/preview/script/emulator.js	Thu Jul 01 09:57:41 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/emulator.js	Thu Jul 01 15:01:44 2010 -0700
@@ -20,6 +20,10 @@
 	DisplayUpwards : "DisplayUpwards",
 	DisplayDownwards : "DisplayDownwards"
 };
+var MODES = {
+	portrait : "portrait",
+	landscape : "landscape"
+};
 
 function Emulator() {
 	this.child = false;
@@ -84,7 +88,7 @@
 
 	if (orientation != this.orientation) {
 		this.orientation = orientation;
-		NOKIA.helper.setPreference("__SYM_DEVICE_ORIENTATION", orientation);
+		NOKIA.helper.setPreference(EmulatorPreferences.ORIENTATION, orientation);
 		NOKIA.emulator.render();
 	}
 
@@ -96,12 +100,38 @@
 
 Emulator.prototype.setAccelerationValues = function(x, y, z) {
 	window.setTimeout(function() {
-		NOKIA.emulator.accelerationChanged(x, y, z);
-		NOKIA.rotationSupport.setAngles(x * 90, y * 90,
-				z * 90);
+		NOKIA.rotationSupport.setAngles(x * 90, y * 90, z * 90);
 	}, 5);
 };
 
+Emulator.prototype.showOrientationAngles = function(orientation) {
+	switch (orientation) {
+	case ORIENTATIONS.DisplayUp:
+		this.setAccelerationValues(0, 0, 0);
+		break;
+	case ORIENTATIONS.DisplayDown:
+		this.setAccelerationValues(2, 0, 0);
+		break;
+	case ORIENTATIONS.DisplayRightUp:
+		this.setAccelerationValues(-1, 0, 0);
+		break;
+	case ORIENTATIONS.DisplayLeftUp:
+		this.setAccelerationValues(1, 0, 0);
+		break;
+	case ORIENTATIONS.DisplayUpwards:
+		this.setAccelerationValues(NOKIA.mode == 'portrait' ? 0 : 1, 0, 1);
+		break;
+	case ORIENTATIONS.DisplayDownwards:
+		this.setAccelerationValues(NOKIA.mode == 'portrait' ? 0 : 1, 0, -1);
+		break;
+	}
+	this.orientation = orientation;
+	NOKIA.helper.setPreference(EmulatorPreferences.ORIENTATION, orientation);
+	window.setTimeout(function() {
+		NOKIA.emulator.render();
+	}, 50);
+};
+
 Emulator.prototype.load = function() {
 	if (this.loaded)
 		return false;
@@ -116,29 +146,10 @@
 	if (mode != null)
 		NOKIA.mode = mode;
 
-	var orientation = NOKIA.helper.getPreference("__SYM_DEVICE_ORIENTATION");
+	var orientation = NOKIA.helper.getPreference(EmulatorPreferences.ORIENTATION);
 	if (orientation != null) {
 		this.orientation = orientation;
-		switch (orientation) {
-		case ORIENTATIONS.DisplayUp:
-			this.setAccelerationValues(0, 0, 0);
-			break;
-		case ORIENTATIONS.DisplayDown:
-			this.setAccelerationValues(2, 0, 0);
-			break;
-		case ORIENTATIONS.DisplayRightUp:
-			this.setAccelerationValues(1, 0, 0);
-			break;
-		case ORIENTATIONS.DisplayLeftUp:
-			this.setAccelerationValues(-1, 0, 0);
-			break;
-		case ORIENTATIONS.DisplayUpwards:
-			this.setAccelerationValues(NOKIA.mode == 'portrait' ? 0 : 1, 0, 1);
-			break;
-		case ORIENTATIONS.DisplayDownwards:
-			this.setAccelerationValues(NOKIA.mode == 'portrait' ? 0 : 1, 0, -1);
-			break;
-		}
+		this.showOrientationAngles(orientation);
 	}
 
 	// SAVE the device DATA
@@ -299,6 +310,58 @@
 			});
 };
 
+Emulator.prototype.turn = function(direction) {
+	var newOrientation = ORIENTATIONS.DisplayUp;
+	if (direction > 0) { // Clockwise
+		switch (this.orientation) {
+		case ORIENTATIONS.DisplayUp:
+			newOrientation = ORIENTATIONS.DisplayLeftUp;
+			break;
+		case ORIENTATIONS.DisplayLeftUp:
+			newOrientation = ORIENTATIONS.DisplayDown;
+			break;
+		case ORIENTATIONS.DisplayDown:
+			newOrientation = ORIENTATIONS.DisplayRightUp;
+			break;
+		case ORIENTATIONS.DisplayRightUp:
+			newOrientation = ORIENTATIONS.DisplayUp;
+			break;
+		default:
+			if (this.mode == MODES.portrait) {
+				newOrientation = ORIENTATIONS.DisplayRightUp;
+			} else {
+				newOrientation = ORIENTATIONS.DisplayUp;
+			}
+			break;
+		}
+	} else {
+		switch (this.orientation) {
+		case ORIENTATIONS.DisplayUp:
+			newOrientation = ORIENTATIONS.DisplayRightUp;
+			break;
+		case ORIENTATIONS.DisplayLeftUp:
+			newOrientation = ORIENTATIONS.DisplayUp;
+			break;
+		case ORIENTATIONS.DisplayDown:
+			newOrientation = ORIENTATIONS.DisplayLeftUp;
+			break;
+		case ORIENTATIONS.DisplayRightUp:
+			newOrientation = ORIENTATIONS.DisplayDown;
+			break;
+		default:
+			if (this.mode == MODES.portrait) {
+				newOrientation = ORIENTATIONS.DisplayRightUp;
+			} else {
+				newOrientation = ORIENTATIONS.DisplayUp;
+			}
+			break;
+		}
+	}
+	this.orientation = newOrientation;
+	this.showOrientationAngles(newOrientation);
+	this.render();
+};
+
 function EmulatorState(x, y, z, orientation) {
 	this.XAxis = x;
 	this.YAxis = y;