Skip to content

Commit

Permalink
CODE: simplified code for coloring parameters/methods
Browse files Browse the repository at this point in the history
  • Loading branch information
arose committed Aug 7, 2015
1 parent 7735aff commit bdec9b1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 163 deletions.
52 changes: 2 additions & 50 deletions js/lib/ui/ui.ngl.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,6 @@ UI.ColorPopupMenu = function(){
var changeEvent = document.createEvent( 'Event' );
changeEvent.initEvent( 'change', true, true );

NGL.ColorMakerRegistry.signals.typesChanged.add( function(){

this.schemeSelector.setOptions( NGL.ColorMakerRegistry.getTypes() );

}, this );

this.schemeSelector = new UI.Select()
.setColor( '#444' )
.setWidth( "" )
.setOptions( NGL.ColorMakerRegistry.getTypes() )
.onChange( function(){

scope.setScheme( scope.schemeSelector.getValue() );
if( scope.schemeSelector.getValue() !== "color" ){
scope.menu.setMenuDisplay( "none" );
}
scope.dom.dispatchEvent( changeEvent );

} );

this.colorInput = new UI.Input()
.onChange( function(){

Expand All @@ -64,14 +44,12 @@ UI.ColorPopupMenu = function(){
.setDisplay( "inline-block" )
.onChange( function( e ){

scope.setScheme( "color" );
scope.setColor( scope.colorPicker.getValue() );
scope.dom.dispatchEvent( changeEvent );

} );

this.menu
.addEntry( "Scheme", this.schemeSelector )
.addEntry( "Input", this.colorInput )
.addEntry( "Picker", this.colorPicker );

Expand All @@ -86,27 +64,6 @@ UI.ColorPopupMenu = function(){

UI.ColorPopupMenu.prototype = Object.create( UI.Panel.prototype );

UI.ColorPopupMenu.prototype.setScheme = function( value ){

value = value || "";

this.iconText.setValue( value.charAt( 0 ).toUpperCase() );
this.schemeSelector.setValue( value );

if( value !== "color" ){
this.setColor( "#888888" );
}

return this;

};

UI.ColorPopupMenu.prototype.getScheme = function(){

return this.schemeSelector.getValue();

};

UI.ColorPopupMenu.prototype.setColor = function(){

var c = new THREE.Color();
Expand Down Expand Up @@ -153,18 +110,13 @@ UI.ColorPopupMenu.prototype.getColor = function(){

UI.ColorPopupMenu.prototype.getValue = function(){

return this.colorInput.getValue();
return this.getColor();

};

UI.ColorPopupMenu.prototype.setValue = function( value ){

if( parseInt( value ) === value ){
this.setColor( value );
this.setScheme( "color" );
}else{
this.setScheme( value );
}
this.setColor( value );

return this;

Expand Down
82 changes: 8 additions & 74 deletions js/ngl/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1570,12 +1570,6 @@ NGL.RepresentationComponentWidget = function( component, stage ){

} );

signals.colorChanged.add( function( value ){

colorWidget.setValue( value );

} );

signals.nameChanged.add( function( value ){

name.setValue( NGL.unicodeHelper( value ) );
Expand All @@ -1585,15 +1579,14 @@ NGL.RepresentationComponentWidget = function( component, stage ){
signals.disposed.add( function(){

menu.dispose();
colorWidget.dispose();
container.dispose();

} );

// Name

var name = new UI.EllipsisText( NGL.unicodeHelper( component.name ) )
.setWidth( "80px" );
.setWidth( "103px" );

// Actions

Expand All @@ -1615,42 +1608,10 @@ NGL.RepresentationComponentWidget = function( component, stage ){

} );

var colorWidget = new UI.ColorPopupMenu()
.setMarginLeft( "10px" )
.setValue( component.repr.color )
.onChange( (function(){

var c = new THREE.Color();
return function( e ){

var scheme = colorWidget.getScheme();
if( scheme === "color" ){
c.setStyle( colorWidget.getColor() );
component.setColor( c.getHex() );
}else{
component.setColor( scheme );
}
component.viewer.requestRender();

}

})() );

if( component.parent instanceof NGL.SurfaceComponent ){

colorWidget.schemeSelector.setOptions( {
"": "",
"value": "value",
"color": "color",
} );

}

container
.addStatic( name )
.addStatic( toggle )
.addStatic( disposeIcon )
.addStatic( colorWidget );
.addStatic( disposeIcon );

// Selection

Expand Down Expand Up @@ -1697,7 +1658,6 @@ NGL.RepresentationComponentWidget = function( component, stage ){

input.setRange( p.min, p.max )


}else if( p.type === "boolean" ){

input = new UI.Checkbox( repr[ name ] );
Expand Down Expand Up @@ -1748,40 +1708,14 @@ NGL.RepresentationComponentWidget = function( component, stage ){

} );

if( p.type === "color" ){

input.onChange( (function(){

var c = new THREE.Color();
return function( e ){

var po = {};
var scheme = input.getScheme();
if( scheme === "color" ){
c.setStyle( input.getColor() );
po[ name ] = c.getHex();
}else{
po[ name ] = scheme;
}
component.setParameters( po );
repr.viewer.requestRender();

}
input.onChange( function(){

})() );
var po = {};
po[ name ] = input.getValue();
component.setParameters( po );
repr.viewer.requestRender();

}else{

input.onChange( function(){

var po = {};
po[ name ] = input.getValue();
component.setParameters( po );
repr.viewer.requestRender();

} );

}
} );

menu.addEntry( name, input );

Expand Down
31 changes: 8 additions & 23 deletions js/ngl/representation.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,6 @@ NGL.Representation.prototype = {

},

setColor: function( type ){

if( type && type !== this.color ){

this.color = type;

this.update( { "color": true } );

this.viewer.requestRender();

}

return this;

},

getColorParams: function(){

return {
Expand Down Expand Up @@ -4388,8 +4372,8 @@ NGL.MolecularSurfaceRepresentation.prototype = NGL.createObject(
init: function( params ){

var p = params || {};

p.color = p.color !== undefined ? p.color : 0xDDDDDD;
p.colorScheme = p.colorScheme || "uniform";
p.colorValue = p.colorValue !== undefined ? p.colorValue : 0xDDDDDD;

this.surfaceType = p.surfaceType !== undefined ? p.surfaceType : "ms";
this.probeRadius = p.probeRadius !== undefined ? p.probeRadius : 1.4;
Expand Down Expand Up @@ -4435,7 +4419,7 @@ NGL.MolecularSurfaceRepresentation.prototype = NGL.createObject(
if( this.atomSet.atomCount === 0 ) return;

var position = this.molsurf.getPosition();
var color = this.molsurf.getColor( this.color );
var color = this.molsurf.getColor( this.colorValue );
var normal = this.molsurf.getNormal();
var index = this.molsurf.getIndex();

Expand Down Expand Up @@ -4517,7 +4501,7 @@ NGL.MolecularSurfaceRepresentation.prototype = NGL.createObject(

if( what[ "color" ] ){

surfaceData[ "color" ] = this.molsurf.getColor( this.color );
surfaceData[ "color" ] = this.molsurf.getColor( this.colorValue );

}

Expand Down Expand Up @@ -5158,8 +5142,9 @@ NGL.SurfaceRepresentation.prototype = NGL.createObject(
init: function( params ){

var p = params || {};
p.colorScheme = p.colorScheme || "uniform";
p.colorValue = p.colorValue !== undefined ? p.colorValue : 0xDDDDDD;

this.color = p.color || 0xDDDDDD;
this.isolevelType = p.isolevelType !== undefined ? p.isolevelType : "sigma";
this.isolevel = p.isolevel !== undefined ? p.isolevel : 2.0;
this.smooth = p.smooth !== undefined ? p.smooth : 0;
Expand Down Expand Up @@ -5220,7 +5205,7 @@ NGL.SurfaceRepresentation.prototype = NGL.createObject(
create: function(){

var position = this.surface.getPosition();
var color = this.surface.getColor( this.color );
var color = this.surface.getColor( this.colorValue );
var normal = this.surface.getNormal();
var index = this.surface.getIndex();

Expand Down Expand Up @@ -5294,7 +5279,7 @@ NGL.SurfaceRepresentation.prototype = NGL.createObject(

if( what[ "color" ] ){

surfaceData[ "color" ] = this.surface.getColor( this.color );
surfaceData[ "color" ] = this.surface.getColor( this.colorValue );

}

Expand Down
16 changes: 0 additions & 16 deletions js/ngl/stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,6 @@ NGL.RepresentationComponent.prototype = NGL.createObject(

signals: Object.assign( {

colorChanged: null,
parametersChanged: null,

}, NGL.Component.prototype.signals ),
Expand Down Expand Up @@ -1584,15 +1583,6 @@ NGL.RepresentationComponent.prototype = NGL.createObject(

},

setColor: function( value ){

this.repr.setColor( value );
this.signals.colorChanged.dispatch( this.repr.color );

return this;

},

getCenter: function(){}

} );
Expand Down Expand Up @@ -1730,12 +1720,6 @@ NGL.RepresentationCollection.prototype = NGL.createObject(

return this._invoke( "setParameters", [ params ] );

},

setColor: function( color ){

return this._invoke( "setColor", [ color ] );

}

} );

0 comments on commit bdec9b1

Please sign in to comment.