<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: rnmc_stdInput.xml $
$Revision: 888 $

last change: $Date: 2009-01-21 10:58:22 +0300 (Ср, 21 янв 2009) $
             $Author: Pavel $

  Lacerta Project
  version 1.0.0.1
  Copyright (C) 2008 RNMC
-->
<!--
====================================================================================================================
      Визуальный объект 'установка соответствия'
====================================================================================================================
-->
<composition name="rnmc_stdLine">
<!--
<script event="onMouseDown">
  this.onLMouseDown();
</script>
<script event="onMouseUp">
  this.onLMouseUp();
</script>
<script event="onMouseMove">
  this.onMouseMove();
</script>
-->
<script><![CDATA[
  this.type = "rnmc_stdLine";
  
  // Указывает что кнопка нажата
  //this.isLButtonDown = false;
  
  // Массив с текстовыми полями, которые составляют линию
  this.lineDataTxt = new Array();
  
  // начальная точка линии
  this.start_point = null;
  
  // последняя зарегестрированная точка в линии
  this.prev_point = null;
  
  // Цвет линии
  this.color = "#FFFFFFFF";
  
  // Ширина линии
  this.weight = 1;
 
  function initFromNode(srcNode){
    return true;//rnmc_stdMediaGroup_initFromNode(srcNode);
  };
  
/*

  function onLMouseDown(){
    this.isLButtonDown = true;
    
    var pt = this.globalToLocal(Mouse.x, Mouse.y);
    
    this.start_point = null;
    this.start_point = new Object();
    this.start_point.x = pt.x;
    this.start_point.y = pt.y;

    this.prev_point = null;
    this.prev_point = new Object();
    this.prev_point.x = pt.x;
    this.prev_point.y = pt.y;
  }
  
  function onLMouseUp(){
    this.isLButtonDown = false;
  }
  
  function onMouseMove(){
    var pt = this.globalToLocal(Mouse.x, Mouse.y);
    if (this.isLButtonDown && 
        (this.prev_point.x != pt.x || this.prev_point.y != pt.y)){
      this.draw_line(this.start_point.x, this.start_point.y, pt.x, pt.y);
      this.prev_point.x = pt.x;
      this.prev_point.y = pt.y;
    }
  }
*/

  function add_point(_x, _y){
    var newTxt;
    newTxt = new Text();
    newTxt.visible = true;
    newTxt.x = _x;
    newTxt.y = _y;
    newTxt.width = this.weight;
    newTxt.height = this.weight;
    newTxt.depth = this.objectDepth - 1;
    newTxt.bkgColor = this.color;
    newTxt.parent = this;
        
    this.lineDataTxt.push(newTxt);
  }

  function draw_line(x1, y1, x2, y2){
    var delta_y = Math.abs(y1 - y2);
    var delta_x = Math.abs(x1 - x2);
    var now_point = 0;

    if ( delta_y > delta_x ){
      var coef = 0, y_now = y1, x_now = 0;
      
      if (y1 - y2 > 0){
        coef = -1;
      } else {
        coef = 1;
      }

      while ( y_now != y2 ){
        y_now += coef;

        x_now = ( ((y_now - y1)*(x2 - x1)) / (y2 - y1) ) + x1;

        if (this.lineDataTxt != null && now_point < this.lineDataTxt.length){
          this.lineDataTxt[now_point].x = x_now;
          this.lineDataTxt[now_point].y = y_now;
        } else {
          this.add_point(x_now, y_now);
        }
        
        ++now_point;
      }
    } else {
      var coef = 0, y_now = 0, x_now = x1;
      
      if (x1 - x2 > 0){
        coef = -1;
      } else {
        coef = 1;
      }

      while ( x_now != x2 ){
        x_now += coef;

        y_now = ( ((x_now - x1)*(y2 - y1)) / (x2 - x1) ) + y1;

        if (this.lineDataTxt != null && now_point < this.lineDataTxt.length){
          this.lineDataTxt[now_point].x = x_now;
          this.lineDataTxt[now_point].y = y_now;
        } else {
          this.add_point(x_now, y_now);
        }
        
        ++now_point;
      }
    }
    
    if (this.lineDataTxt != null && now_point < this.lineDataTxt.length){
      while (now_point < this.lineDataTxt.length){
        this.lineDataTxt.pop().parent = null;
      }
    }
  }
  
  function updateColor(){
    if (this.lineDataTxt != null && this.lineDataTxt.length > 0){
      for (var i = 0; i < this.lineDataTxt.length; ++i){
        this.lineDataTxt[i].bkgColor = this.color;
      }
    }
  }
]]></script>
</composition>
</rmml>