117 lines
2.2 KiB
JavaScript
117 lines
2.2 KiB
JavaScript
|
/**
|
||
|
* GUI component
|
||
|
* @param guiRuntime
|
||
|
* @param apiGUI
|
||
|
* @constructor
|
||
|
*/
|
||
|
R3.GUI = function(
|
||
|
guiRuntime,
|
||
|
apiGUI
|
||
|
) {
|
||
|
this.guiRuntime = guiRuntime;
|
||
|
this.guiRuntime.isNotDatGuiThrow();
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(apiGUI)) {
|
||
|
apiGUI = {};
|
||
|
}
|
||
|
|
||
|
R3.API.GUI.call(
|
||
|
this,
|
||
|
apiGUI.id,
|
||
|
apiGUI.name,
|
||
|
apiGUI.domElement,
|
||
|
apiGUI.parentEntity
|
||
|
);
|
||
|
|
||
|
R3.Component.call(
|
||
|
this,
|
||
|
{
|
||
|
'domElement': R3.DomElement
|
||
|
}
|
||
|
);
|
||
|
};
|
||
|
|
||
|
R3.GUI.prototype = Object.create(R3.Component.prototype);
|
||
|
R3.GUI.prototype.constructor = R3.GUI;
|
||
|
|
||
|
/**
|
||
|
* Creates a helper instance
|
||
|
*/
|
||
|
R3.GUI.prototype.createInstance = function() {
|
||
|
this.instance = new this.guiRuntime.instance( { autoPlace: false } );
|
||
|
R3.Component.prototype.createInstance.call(this);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Updates the instance with the current state
|
||
|
*/
|
||
|
R3.GUI.prototype.updateInstance = function(property) {
|
||
|
console.log('todo: implement gui update instance:' + property);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Converts a R3.GUI to a new R3.API.GUI
|
||
|
* @returns {R3.API.GUI}
|
||
|
*/
|
||
|
R3.GUI.prototype.toApiObject = function() {
|
||
|
|
||
|
return new R3.API.GUI(
|
||
|
this.id,
|
||
|
this.name,
|
||
|
R3.Utils.IdOrNull(this.domElement),
|
||
|
R3.Utils.IdOrNull(this.parentEntity)
|
||
|
);
|
||
|
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Converts from an Object GUI to a R3.GUI
|
||
|
* @param guiRuntime R3.GUIRuntime
|
||
|
* @param objectGUI Object
|
||
|
* @returns {R3.GUI}
|
||
|
* @constructor
|
||
|
*/
|
||
|
R3.GUI.FromObject = function(guiRuntime, objectGUI) {
|
||
|
|
||
|
var apiGUI = R3.API.GUI.FromObject(objectGUI);
|
||
|
|
||
|
return new R3.GUI(
|
||
|
guiRuntime,
|
||
|
apiGUI
|
||
|
);
|
||
|
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Removes empty folders from instance
|
||
|
*/
|
||
|
R3.GUI.prototype.removeEmtpyFolders = function() {
|
||
|
this.instance.removeEmptyFolders();
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Remove all folders from instance
|
||
|
*/
|
||
|
R3.GUI.prototype.removeAllFolders = function() {
|
||
|
this.instance.removeAllFolders();
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Adds a folder to instance
|
||
|
* @param folderName
|
||
|
* @returns {*}
|
||
|
*/
|
||
|
R3.GUI.prototype.addFolder = function(folderName) {
|
||
|
try {
|
||
|
return this.instance.addFolder(folderName);
|
||
|
} catch (e) {
|
||
|
try {
|
||
|
folderName += ' duplicate (' + R3.Utils.RandomId() + ')';
|
||
|
return this.instance.addFolder(folderName);
|
||
|
} catch (e) {
|
||
|
console.log(e.message);
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
};
|