Skip to content

Commit cd750d4

Browse files
committed
GUI: Added min/max to material's opacity.
1 parent 373ae02 commit cd750d4

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

gui/js/UI.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ UI.FloatNumber = function ( position ) {
337337
this.dom.style.fontSize = '12px';
338338
this.dom.style.textDecoration = 'underline';
339339

340+
this.min = - Infinity;
341+
this.max = Infinity;
342+
340343
this.onChangeCallback = null;
341344

342345
var scope = this;
@@ -357,10 +360,12 @@ UI.FloatNumber = function ( position ) {
357360

358361
var onMouseMove = function ( event ) {
359362

360-
var dx = event.screenX - onMouseDownScreenX;
361-
var dy = event.screenY - onMouseDownScreenY;
363+
var distance = ( event.screenX - onMouseDownScreenX ) - ( event.screenY - onMouseDownScreenY );
364+
var amount = event.shiftKey ? 10 : 100;
365+
366+
var number = onMouseDownValue + ( distance / amount );
362367

363-
scope.dom.textContent = ( onMouseDownValue + ( dx - dy ) / ( event.shiftKey ? 10 : 100 ) ).toFixed( 2 );
368+
scope.dom.textContent = Math.min( scope.max, Math.max( scope.min, number ) ).toFixed( 2 );
364369
scope.onChangeCallback();
365370

366371
}
@@ -394,6 +399,20 @@ UI.FloatNumber.prototype.setValue = function ( value ) {
394399

395400
};
396401

402+
UI.FloatNumber.prototype.setMin = function ( value ) {
403+
404+
this.min = value;
405+
return this;
406+
407+
};
408+
409+
UI.FloatNumber.prototype.setMax = function ( value ) {
410+
411+
this.max = value;
412+
return this;
413+
414+
};
415+
397416
UI.FloatNumber.prototype.onChange = function ( callback ) {
398417

399418
this.onChangeCallback = callback;

gui/js/ui/Sidebar.Properties.Material.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ Sidebar.Properties.Material = function ( signals ) {
2727
container.add( new UI.HorizontalRule() );
2828

2929
container.add( new UI.Text().setText( 'Opacity' ).setColor( '#666' ) );
30-
var materialOpacity = new UI.FloatNumber( 'absolute' ).setLeft( '90px' ).setFontSize( '12px' ).onChange( update );
30+
var materialOpacity = new UI.FloatNumber( 'absolute' ).setLeft( '90px' ).setFontSize( '12px' );
31+
materialOpacity.setMin( 0 ).setMax( 1 );
32+
materialOpacity.onChange( update );
3133
container.add( materialOpacity );
3234
container.add( new UI.HorizontalRule() );
3335

0 commit comments

Comments
 (0)