Browse Source

UI.Number: Keep float intact.

Mr.doob 9 years ago
parent
commit
11853e872d
1 changed files with 31 additions and 15 deletions
  1. 31 15
      editor/js/libs/ui.js

+ 31 - 15
editor/js/libs/ui.js

@@ -645,6 +645,8 @@ UI.Number = function ( number ) {
 
 
 	}, false );
 	}, false );
 
 
+	this.value = 0;
+
 	this.min = - Infinity;
 	this.min = - Infinity;
 	this.max = Infinity;
 	this.max = Infinity;
 
 
@@ -652,6 +654,7 @@ UI.Number = function ( number ) {
 	this.step = 1;
 	this.step = 1;
 
 
 	this.dom = dom;
 	this.dom = dom;
+
 	this.setValue( number );
 	this.setValue( number );
 
 
 	var changeEvent = document.createEvent( 'HTMLEvents' );
 	var changeEvent = document.createEvent( 'HTMLEvents' );
@@ -669,7 +672,7 @@ UI.Number = function ( number ) {
 
 
 		distance = 0;
 		distance = 0;
 
 
-		onMouseDownValue = parseFloat( dom.value );
+		onMouseDownValue = scope.value;
 
 
 		prevPointer = [ event.clientX, event.clientY ];
 		prevPointer = [ event.clientX, event.clientY ];
 
 
@@ -680,17 +683,21 @@ UI.Number = function ( number ) {
 
 
 	function onMouseMove( event ) {
 	function onMouseMove( event ) {
 
 
-		var currentValue = dom.value;
+		var currentValue = scope.value;
 
 
 		pointer = [ event.clientX, event.clientY ];
 		pointer = [ event.clientX, event.clientY ];
 
 
 		distance += ( pointer[ 0 ] - prevPointer[ 0 ] ) - ( pointer[ 1 ] - prevPointer[ 1 ] );
 		distance += ( pointer[ 0 ] - prevPointer[ 0 ] ) - ( pointer[ 1 ] - prevPointer[ 1 ] );
 
 
-		var number = onMouseDownValue + ( distance / ( event.shiftKey ? 5 : 50 ) ) * scope.step;
+		var value = onMouseDownValue + ( distance / ( event.shiftKey ? 5 : 50 ) ) * scope.step;
+		value = Math.min( scope.max, Math.max( scope.min, value ) );
 
 
-		dom.value = Math.min( scope.max, Math.max( scope.min, number ) ).toFixed( scope.precision );
+		if ( currentValue !== value ) {
 
 
-		if ( currentValue !== dom.value ) dom.dispatchEvent( changeEvent );
+			scope.setValue( value );
+			dom.dispatchEvent( changeEvent );
+
+		}
 
 
 		prevPointer = [ event.clientX, event.clientY ];
 		prevPointer = [ event.clientX, event.clientY ];
 
 
@@ -724,7 +731,7 @@ UI.Number = function ( number ) {
 
 
 		}
 		}
 
 
-		dom.value = parseFloat( value );
+		scope.setValue( parseFloat( value ) );
 
 
 	}
 	}
 
 
@@ -758,7 +765,7 @@ UI.Number.prototype.constructor = UI.Number;
 
 
 UI.Number.prototype.getValue = function () {
 UI.Number.prototype.getValue = function () {
 
 
-	return parseFloat( this.dom.value );
+	return this.value;
 
 
 };
 };
 
 
@@ -766,6 +773,7 @@ UI.Number.prototype.setValue = function ( value ) {
 
 
 	if ( value !== undefined ) {
 	if ( value !== undefined ) {
 
 
+		this.value = value;
 		this.dom.value = value.toFixed( this.precision );
 		this.dom.value = value.toFixed( this.precision );
 
 
 	}
 	}
@@ -802,7 +810,7 @@ UI.Integer = function ( number ) {
 
 
 	var dom = document.createElement( 'input' );
 	var dom = document.createElement( 'input' );
 	dom.className = 'Number';
 	dom.className = 'Number';
-	dom.value = '0.00';
+	dom.value = '0';
 
 
 	dom.addEventListener( 'keydown', function ( event ) {
 	dom.addEventListener( 'keydown', function ( event ) {
 
 
@@ -810,12 +818,15 @@ UI.Integer = function ( number ) {
 
 
 	}, false );
 	}, false );
 
 
+	this.value = 0;
+
 	this.min = - Infinity;
 	this.min = - Infinity;
 	this.max = Infinity;
 	this.max = Infinity;
 
 
 	this.step = 1;
 	this.step = 1;
 
 
 	this.dom = dom;
 	this.dom = dom;
+
 	this.setValue( number );
 	this.setValue( number );
 
 
 	var changeEvent = document.createEvent( 'HTMLEvents' );
 	var changeEvent = document.createEvent( 'HTMLEvents' );
@@ -833,7 +844,7 @@ UI.Integer = function ( number ) {
 
 
 		distance = 0;
 		distance = 0;
 
 
-		onMouseDownValue = parseFloat( dom.value );
+		onMouseDownValue = scope.value;
 
 
 		prevPointer = [ event.clientX, event.clientY ];
 		prevPointer = [ event.clientX, event.clientY ];
 
 
@@ -844,17 +855,21 @@ UI.Integer = function ( number ) {
 
 
 	function onMouseMove( event ) {
 	function onMouseMove( event ) {
 
 
-		var currentValue = dom.value;
+		var currentValue = scope.value;
 
 
 		pointer = [ event.clientX, event.clientY ];
 		pointer = [ event.clientX, event.clientY ];
 
 
 		distance += ( pointer[ 0 ] - prevPointer[ 0 ] ) - ( pointer[ 1 ] - prevPointer[ 1 ] );
 		distance += ( pointer[ 0 ] - prevPointer[ 0 ] ) - ( pointer[ 1 ] - prevPointer[ 1 ] );
 
 
-		var number = onMouseDownValue + ( distance / ( event.shiftKey ? 5 : 50 ) ) * scope.step;
+		var value = onMouseDownValue + ( distance / ( event.shiftKey ? 5 : 50 ) ) * scope.step;
+		value = Math.min( scope.max, Math.max( scope.min, value ) ) | 0;
 
 
-		dom.value = Math.min( scope.max, Math.max( scope.min, number ) ) | 0;
+		if ( currentValue !== value ) {
 
 
-		if ( currentValue !== dom.value ) dom.dispatchEvent( changeEvent );
+			scope.setValue( value );
+			dom.dispatchEvent( changeEvent );
+
+		}
 
 
 		prevPointer = [ event.clientX, event.clientY ];
 		prevPointer = [ event.clientX, event.clientY ];
 
 
@@ -888,7 +903,7 @@ UI.Integer = function ( number ) {
 
 
 		}
 		}
 
 
-		dom.value = parseInt( value );
+		scope.setValue( value );
 
 
 	}
 	}
 
 
@@ -922,7 +937,7 @@ UI.Integer.prototype.constructor = UI.Integer;
 
 
 UI.Integer.prototype.getValue = function () {
 UI.Integer.prototype.getValue = function () {
 
 
-	return parseInt( this.dom.value );
+	return this.value;
 
 
 };
 };
 
 
@@ -930,6 +945,7 @@ UI.Integer.prototype.setValue = function ( value ) {
 
 
 	if ( value !== undefined ) {
 	if ( value !== undefined ) {
 
 
+		this.value = value | 0;
 		this.dom.value = value | 0;
 		this.dom.value = value | 0;
 
 
 	}
 	}