<?xml version="1.0" encoding="utf-8"?>
<rmml>
  <!--
$RCSfile: rnmc_common.xml,v $
$Revision: 744 $
$State: Exp $
$Locker:  $

last change: $Date: 2008-09-15 14:35:58 +0400 (Пн, 15 сен 2008) $
             $Author: toha $

  Lacerta Project
  Copyright (C) 2007 RNMC
-->

<composition name="rnmc_stdCalculator" class="rnmc_stdMediaGroup">
	<script><![CDATA[
	
		this.skinPath = "\\DATA\\skin\\calculator\\";
		this.bgSrc = this.skinPath + "calc_bg.png";
		this.smBtnSrc = this.skinPath + "calc_smbtn.png";
		this.smBtnPrSrc = this.skinPath + "calc_smbtnpr.png";
		this.bigBtnSrc = this.skinPath + "calc_bigbtn.png";
		this.bigBtnPrSrc = this.skinPath + "calc_bigbtnpr.png";
		this.btnNames = new Array("btnAdd","btnSub","btnMul","btnDiv","btnRes","btnC","btnCE","btnPM",
		  "btnCalc1","btnCalc2","btnCalc3","btnCalc4","btnCalc5","btnCalc6","btnCalc7","btnCalc8","btnCalc9","btnCalc0","btnCalcP");

		<!-- Редактируемые параметры калькулятора -->  
		this.btnCaptions = new Array("+","-","&#215;",":","=","C","CE","&#177;",
		  "1","2","3","4","5","6","7","8","9","0",".");
		this.btnSize = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0);
		this.btnX = new Array(117,117,152,152,117,117,152,152,  6, 41, 76,  6, 41, 76,  6, 41, 76,  6, 76);
		this.btnY = new Array(100,135,100,135,170, 65, 65,170,135,135,135,100,100,100, 65, 65, 65,170,170);
		this.smTextDim = new Array(0,6,32,30);
		this.bigTextDim = new Array(0,6,68,30);
		this.resTextDim = new Array(15,26,155,23);
		this.btnTextStyle = "calculatorBtn";
		this.resTextStyle = "calculatorRes";
		<!-- =============================== -->

		this.bg = null;
		this.btns = new Array(null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
		this.btnTexts = new Array(null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
		this.resultText = null;
		this.reg1 = 0;
		this.reg2 = 0;
		this.regRes = 0;
		this.operCode = 0;
		this.showRes = true;
		
		function initFromNode(srcNode)
		{
			trace("----------------------------")
			rnmc_stdMediaGroup_initFromNode(srcNode);
			
			this.bg = new Image();
			this.bg.parent = this;
			this.bg.visible = true;
			this.bg.src = this.bgSrc;
			
			for(var i = 0; i < this.btnNames.length; i++){
				this.btns[i] = new Composition();
				this.btns[i]._class = "rnmc_stdButton";
				this.btns[i].parent = this;
				this.btns[i].id = this.btnNames[i];
				this.btns[i].visible = true;
				this.btns[i].enabled = true;
				this.btns[i].buttonType = BUTTON_TYPE_IMAGE;
				if (this.btnSize[i]){
					this.btns[i].buttonNormalImageSrc = this.bigBtnSrc;
					this.btns[i].buttonActiveImageSrc = this.bigBtnSrc;
					this.btns[i].buttonPressedImageSrc = this.bigBtnPrSrc;
				} else {
					this.btns[i].buttonNormalImageSrc = this.smBtnSrc;
					this.btns[i].buttonActiveImageSrc = this.smBtnSrc;
					this.btns[i].buttonPressedImageSrc = this.smBtnPrSrc;
				}
				this.btns[i].x = this.btnX[i];
				this.btns[i].y = this.btnY[i];
				this.btns[i].depth = -5;
				this.btns[i].createObject();
				this.btns[i].setPressCallBack(this, this.buttonPressDispatcher);
				this.btns[i].setReleaseCallBack(this, this.buttonReleaseDispatcher);
				this.btns[i].showObject();
				
				this.btnTexts[i] = new Composition();
				this.btnTexts[i]._class = "rnmc_stdText";
				this.btnTexts[i].parent = this;
				this.btnTexts[i].id = this.btnNames[i]+"Text";
				this.btnTexts[i].visible = true;
				if (this.btnSize[i]){
					this.btnTexts[i].objectX = this.btnX[i]+this.bigTextDim[0];
					this.btnTexts[i].objectY = this.btnY[i]+this.bigTextDim[1];
					this.btnTexts[i].objectWidth = this.bigTextDim[2];
					this.btnTexts[i].objectHeight = this.bigTextDim[3];
				} else {
					this.btnTexts[i].objectX = this.btnX[i]+this.smTextDim[0];
					this.btnTexts[i].objectY = this.btnY[i]+this.smTextDim[1];
					this.btnTexts[i].objectWidth = this.smTextDim[2];
					this.btnTexts[i].objectHeight = this.smTextDim[3];
				}
				this.btnTexts[i].objectStyle = this.btnTextStyle;
				this.btnTexts[i].objectHitArea = "[0,0,0,0]"
				this.btnTexts[i].depth = -10;
				this.btnTexts[i].setTextValue(this.btnCaptions[i]);
				this.btnTexts[i].showObject();
			}
    
			this.resultText = new Composition();
			this.resultText._class = "rnmc_stdText";
			this.resultText.parent = this;
			this.resultText.id = "result";
			this.resultText.visible = true;
			this.resultText.objectX = this.resTextDim[0];
			this.resultText.objectY = this.resTextDim[1];
			this.resultText.objectWidth = this.resTextDim[2];
			this.resultText.objectHeight = this.resTextDim[3];
			this.resultText.objectStyle = this.resTextStyle;
			this.resultText.depth = -10;
			this.resultText.setTextValue("0");
			<!-- 
			this.resultText.attachedControl = scene.ControlManager.getControl(this.resultText.controlStyle, this.resultText);
			this.resultText.attachedControl.visible = false;
			this.resultText.attachedControl.x = this.controlX;
			this.resultText.attachedControl.y = this.controlY;
			this.resultText.attachedControl.depth = this.controlDepth;
			this.resultText.attachedControl.setDispatcher(this.resultText, this.resultText.buttonDispatcher);
			this.resultText.attachedControl.showChildControl("copy");
			this.resultText.attachedControl.showObject();
			-->
			this.resultText.showObject();

			return true;
		}

		function buttonPressDispatcher(btnId){
			for(var i = 0; i < this.btnNames.length; i++){
				if (btnId == this.btnNames[i]) {
					this.btnTexts[i].objectX += 2;
					this.btnTexts[i].objectY += 2;
					this.btnTexts[i].showObject();
				}
			}
		}

		function buttonReleaseDispatcher(btnId){
			for(var i = 0; i < this.btnNames.length; i++){
				if (btnId == this.btnNames[i]) {
					this.btnTexts[i].objectX -= 2;
					this.btnTexts[i].objectY -= 2;
					this.btnTexts[i].showObject();
				}
			}
			switch(btnId){
			case "btnAdd":
				if(!this.showRes){
					this.reg2 = Number(this.resultText.objectValue);
					switch(this.operCode) {
					case 0:
						this.regRes = this.reg1 + this.reg2;
						break;
					case 1:
						this.regRes = this.reg1 - this.reg2;
						break;
					break;
					case 2:
						this.regRes = this.reg1 * this.reg2;
						break;
					break;
					case 3:
						this.regRes = this.reg1 / this.reg2;
						break;
					break;
					}
					this.reg1 = this.regRes;
					this.resultText.setTextValue(String(this.regRes));
				}
				else {
					this.reg1 = this.regRes;
				}
				this.operCode = 0;
				this.showRes = true;
				break;
			case "btnSub":
				if(!this.showRes){
					this.reg2 = Number(this.resultText.objectValue);
					switch(this.operCode) {
					case 0:
						this.regRes = this.reg1 + this.reg2;
						break;
					case 1:
						this.regRes = this.reg1 - this.reg2;
						break;
					break;
					case 2:
						this.regRes = this.reg1 * this.reg2;
						break;
					break;
					case 3:
						this.regRes = this.reg1 / this.reg2;
						break;
					break;
					}
					this.reg1 = this.regRes;
					this.resultText.setTextValue(String(this.regRes));
				}
				else {
					this.reg1 = this.regRes;
				}
				this.operCode = 1;
				this.showRes = true;
				break;
			case "btnMul":
				if(!this.showRes){
					this.reg2 = Number(this.resultText.objectValue);
					switch(this.operCode) {
					case 0:
						this.regRes = this.reg1 + this.reg2;
						break;
					case 1:
						this.regRes = this.reg1 - this.reg2;
						break;
					break;
					case 2:
						this.regRes = this.reg1 * this.reg2;
						break;
					break;
					case 3:
						this.regRes = this.reg1 / this.reg2;
						break;
					break;
					}
					this.reg1 = this.regRes;
					this.resultText.setTextValue(String(this.regRes));
				}
				else {
					this.reg1 = this.regRes;
				}
				this.operCode = 2;
				this.showRes = true;
				break;
			case "btnDiv":
				if(!this.showRes){
					this.reg2 = Number(this.resultText.objectValue);
					switch(this.operCode) {
					case 0:
						this.regRes = this.reg1 + this.reg2;
						break;
					case 1:
						this.regRes = this.reg1 - this.reg2;
						break;
					break;
					case 2:
						this.regRes = this.reg1 * this.reg2;
						break;
					break;
					case 3:
						this.regRes = this.reg1 / this.reg2;
						break;
					break;
					}
					this.reg1 = this.regRes;
					this.resultText.setTextValue(String(this.regRes));
				}
				else {
					this.reg1 = this.regRes;
				}
				this.operCode = 3;
				this.showRes = true;
				break;
			case "btnRes":
				if(!this.showRes){
					this.reg2 = Number(this.resultText.objectValue);
					switch(this.operCode) {
					case 0:
						this.regRes = this.reg1 + this.reg2;
						break;
					case 1:
						this.regRes = this.reg1 - this.reg2;
						break;
					break;
					case 2:
						this.regRes = this.reg1 * this.reg2;
						break;
					break;
					case 3:
						this.regRes = this.reg1 / this.reg2;
						break;
					break;
					}
					this.reg1 = 0;
					this.reg2 = 0;
					this.resultText.setTextValue(String(this.regRes));
					this.operCode = 0;
				}
				this.showRes = true;
				break;
			case "btnC":
				this.resultText.setTextValue("0");
				this.reg1 = 0;
				this.reg2 = 0;
				this.regRes = 0;
				this.showRes = true;
				break;
			case "btnCE":
				this.resultText.setTextValue("0");
				this.showRes = true;
				break;
			case "btnPM":
				this.resultText.setTextValue(String(-Number(this.resultText.objectValue)))
				break;
			case "btnCalc1":
				if (this.showRes) {
					this.resultText.setTextValue("1");
					this.showRes = false;
				}
				else {
					this.resultText.setTextValue(this.resultText.objectValue+"1");
				}
				this.resultText.setTextValue(String(Number(this.resultText.objectValue)));
				break;
			case "btnCalc2":
				if (this.showRes) {
					this.resultText.setTextValue("2");
					this.showRes = false;
				}
				else {
					this.resultText.setTextValue(this.resultText.objectValue+"2");
				}
				this.resultText.setTextValue(String(Number(this.resultText.objectValue)));
				break;
			case "btnCalc3":
				if (this.showRes) {
					this.resultText.setTextValue("3");
					this.showRes = false;
				}
				else {
					this.resultText.setTextValue(this.resultText.objectValue+"3");
				}
				this.resultText.setTextValue(String(Number(this.resultText.objectValue)));
				break;
			case "btnCalc4":
				if (this.showRes) {
					this.resultText.setTextValue("4");
					this.showRes = false;
				}
				else {
					this.resultText.setTextValue(this.resultText.objectValue+"4");
				}
				this.resultText.setTextValue(String(Number(this.resultText.objectValue)));
				break;
			case "btnCalc5":
				if (this.showRes) {
					this.resultText.setTextValue("5");
					this.showRes = false;
				}
				else {
					this.resultText.setTextValue(this.resultText.objectValue+"5");
				}
				this.resultText.setTextValue(String(Number(this.resultText.objectValue)));
				break;
			case "btnCalc6":
				if (this.showRes) {
					this.resultText.setTextValue("6");
					this.showRes = false;
				}
				else {
					this.resultText.setTextValue(this.resultText.objectValue+"6");
				}
				this.resultText.setTextValue(String(Number(this.resultText.objectValue)));
				break;
			case "btnCalc7":
				if (this.showRes) {
					this.resultText.setTextValue("7");
					this.showRes = false;
				}
				else {
					this.resultText.setTextValue(this.resultText.objectValue+"7");
				}
				this.resultText.setTextValue(String(Number(this.resultText.objectValue)));
				break;
			case "btnCalc8":
				if (this.showRes) {
					this.resultText.setTextValue("8");
					this.showRes = false;
				}
				else {
					this.resultText.setTextValue(this.resultText.objectValue+"8");
				}
				this.resultText.setTextValue(String(Number(this.resultText.objectValue)));
				break;
			case "btnCalc9":
				if (this.showRes) {
					this.resultText.setTextValue("9");
					this.showRes = false;
				}
				else {
					this.resultText.setTextValue(this.resultText.objectValue+"9");
				}
				this.resultText.setTextValue(String(Number(this.resultText.objectValue)));
				break;
			case "btnCalc0":
				if (this.showRes) {
					this.resultText.setTextValue("0");
					this.showRes = false;
				}
				else {
					this.resultText.setTextValue(this.resultText.objectValue+"0");
				}
				if (this.resultText.objectValue.indexOf(".") == -1) {
					this.resultText.setTextValue(String(Number(this.resultText.objectValue)))
				};
				break;
			case "btnCalcP":
				if (this.showRes) {
					this.resultText.setTextValue("0.");
					this.showRes = false;
				}
				else {
					if (this.resultText.objectValue.indexOf(".") == -1) {
						this.resultText.setTextValue(this.resultText.objectValue+".")
					}
				}
				break;
			default:
				trace("RNMC_Calculator: UNKNOWN BUTTON ID: " + btnId);
				break;
			}
			this.resultText.objectContent.copyToClipboard();
		}

	]]></script>
</composition>
 
</rmml>
