r3-legacy/src/r3-gui.js

170 lines
3.7 KiB
JavaScript

/**
* R3.GUI
*
* This class uses the existing runtime but is not a component - we don't store these to API
* but they do have the capability of changing their runtime implementations
*
* @constructor
*/
R3.GUI = function(options) {
if (R3.Utils.UndefinedOrNull(options)) {
options = {};
}
this.gui = null;
R3.Event.Emit(
R3.Event.GET_RUNTIME,
this,
function(runtime) {
this.gui = runtime.gui;
}.bind(this)
);
if (R3.Utils.UndefinedOrNull(options.id)) {
throw new Error('You need to specify the DOM element ID');
}
this.id = options.id;
this.dom = document.getElementById(this.id);
if (R3.Utils.UndefinedOrNull(options.groups)) {
options.groups = [];
}
this.groups = options.groups;
this.createInstance();
};
R3.GUI.Group = function(options) {
if (R3.Utils.UndefinedOrNull(options)) {
options = {};
}
if (R3.Utils.UndefinedOrNull(options.components)) {
options.components = [];
}
this.options = options.components;
if (R3.Utils.UndefinedOrNull(options.templates)) {
options.templates = [];
}
this.options = options.templates;
};
R3.GUI.Template = function(options) {
if (R3.Utils.UndefinedOrNull(options)) {
options = {};
}
if (R3.Utils.UndefinedOrNull(options.component)) {
options.component = null;
}
this.component = options.component;
if (R3.Utils.UndefinedOrNull(options.affected)) {
options.affected = [];
}
this.affected = options.affected;
};
/**
* Creates a helper instance
*/
R3.GUI.prototype.createInstance = function() {
if (R3.Utils.UndefinedOrNull(this.gui)) {
throw new Error('Need a GUI runtime');
}
this.instance = this.gui.createInstance();
this.dom.appendChild(this.gui.getDomElement(this));
R3.Event.Emit(
R3.Event.GUI_CREATED,
this
)
};
R3.GUI.prototype.dispose = function() {
this.clear();
this.dom.removeChild(this.gui.getDomElement(this));
R3.Event.Emit(
R3.Event.GUI_REMOVED,
this
)
};
R3.GUI.prototype.addPanel = function(component) {
return this.gui.addPanel(this, component);
};
R3.GUI.prototype.addNumber = function(panel, component, property) {
return this.gui.addNumber(this, panel, component, property);
};
R3.GUI.prototype.addString = function(panel, component, property) {
return this.gui.addString(this, panel, component, property);
};
R3.GUI.prototype.addButton = function(panel, component, property) {
return this.gui.addButton(this, panel, component, property);
};
R3.GUI.prototype.addColor = function(panel, component, property) {
return this.gui.addColor(this, panel, component, property);
};
R3.GUI.prototype.addCheckbox = function(panel, component, property) {
return this.gui.addCheckbox(this, panel, component, property);
};
R3.GUI.prototype.addSelect = function(panel, component, property) {
return this.gui.addSelect(this, panel, component, property);
};
R3.GUI.prototype.addComponent = function(component) {
this.gui.addComponent(this, component);
};
/**
* Remove all folders from instance
*/
R3.GUI.prototype.removeComponent = function(component) {
this.gui.removeComponent(this, component);
};
/**
* Adds a group to instance
* @param name
* @returns {*}
*/
R3.GUI.prototype.addGroup = function(panel, name) {
return this.gui.addGroup(this, panel, name);
};
/**
* Remove a group
* @param name
*/
R3.GUI.prototype.removeGroup = function(name) {
this.gui.removeGroup(this, name);
};
R3.GUI.prototype.removeAllGroups = function() {
this.gui.removeAllGroups(this);
};
R3.GUI.prototype.clear = function() {
this.gui.clear(this);
};