test events for button / ui binding

This commit is contained in:
Stewart Allen 2021-12-09 23:12:35 -05:00
commit a1539d9ae7
3 changed files with 115 additions and 123 deletions

View file

@ -449,7 +449,7 @@
showDevices(); showDevices();
break; break;
case cca('w'): // scale case cca('w'): // scale
UI.tool.next(); API.event.emit("tool.next");
break; break;
case cca('o'): // tools case cca('o'): // tools
showTools(); showTools();
@ -1429,10 +1429,12 @@
// MAIN INITIALIZATION FUNCTION // MAIN INITIALIZATION FUNCTION
function init_one() { function init_one() {
API.event.emit('init.one'); let { event, conf, view, show } = API;
event.emit('init.one');
// ensure we have settings from last session // ensure we have settings from last session
API.conf.restore(); conf.restore();
let container = $('container'), let container = $('container'),
welcome = $('welcome'), welcome = $('welcome'),
@ -1443,43 +1445,44 @@
UC.setHoverPop(false); UC.setHoverPop(false);
WIN.addEventListener("resize", () => { WIN.addEventListener("resize", () => {
API.event.emit('resize'); event.emit('resize');
}); });
API.event.on('resize', () => { event.on('resize', () => {
if (WIN.innerHeight < 800) { if (WIN.innerHeight < 800) {
UI.modalBox.classList.add('mh85'); UI.modalBox.classList.add('mh85');
} else { } else {
UI.modalBox.classList.remove('mh85'); UI.modalBox.classList.remove('mh85');
} }
API.view.update_slider(); view.update_slider();
}); });
SPACE.showSkyGrid(false); SPACE.showSkyGrid(false);
SPACE.setSkyColor(controller.dark ? 0 : 0xffffff); SPACE.setSkyColor(controller.dark ? 0 : 0xffffff);
SPACE.init(container, function (delta) { SPACE.init(container, function (delta) {
if (API.var.layer_max === 0 || !delta) return; let vars = API.var;
if (vars.layer_max === 0 || !delta) return;
if (controller.reverseZoom) delta = -delta; if (controller.reverseZoom) delta = -delta;
let same = API.var.layer_hi === API.var.layer_lo; let same = vars.layer_hi === vars.layer_lo;
let track = API.var.layer_lo > 0; let track = vars.layer_lo > 0;
if (delta > 0) { if (delta > 0) {
API.var.layer_hi = Math.max(same ? 0 : API.var.layer_lo, API.var.layer_hi - 1); vars.layer_hi = Math.max(same ? 0 : vars.layer_lo, vars.layer_hi - 1);
if (track) { if (track) {
API.var.layer_lo = Math.max(0, API.var.layer_lo - 1); vars.layer_lo = Math.max(0, vars.layer_lo - 1);
} }
} else if (delta < 0) { } else if (delta < 0) {
API.var.layer_hi = Math.min(API.var.layer_max, API.var.layer_hi + 1); vars.layer_hi = Math.min(vars.layer_max, vars.layer_hi + 1);
if (track) { if (track) {
API.var.layer_lo = Math.min(API.var.layer_hi, API.var.layer_lo + 1); vars.layer_lo = Math.min(vars.layer_hi, vars.layer_lo + 1);
} }
} }
if (same) { if (same) {
API.var.layer_lo = API.var.layer_hi; vars.layer_lo = vars.layer_hi;
} }
API.view.update_slider(); view.update_slider();
API.show.slices(); show.slices();
}, controller.ortho); }, controller.ortho);
SPACE.platform.onMove(API.conf.save); SPACE.platform.onMove(conf.save);
SPACE.platform.setRound(true); SPACE.platform.setRound(true);
SPACE.useDefaultKeys(API.feature.on_key === undefined || API.feature.on_key_defaults); SPACE.useDefaultKeys(API.feature.on_key === undefined || API.feature.on_key_defaults);
@ -1511,12 +1514,6 @@
search: $('dev-search'), search: $('dev-search'),
filter: $('dev-filter') filter: $('dev-filter')
}, },
tool: {
rotate: () => { UI.tool.show('ft-rotate') },
scale: () => { UI.tool.show('ft-scale') },
mesh: () => { UI.tool.show('ft-mesh') },
select: () => { UI.tool.show('ft-select') },
},
mesh: { mesh: {
name: $('mesh-name'), name: $('mesh-name'),
points: $('mesh-points'), points: $('mesh-points'),
@ -2740,25 +2737,29 @@
}; };
}; };
}); });
// bind tool show buttons
UI.tool.show = function(tictac) { // bind tool buttons
{
let { event } = API;
let next = 0;
let list = ['rotate','scale','mesh','select'];
event.on("tool.next", () => {
event.emit("tool.show", list[next++ % 4]);
});
event.on("tool.show", tictac => {
if (typeof(tictac) === 'string') { if (typeof(tictac) === 'string') {
nextool = listool.indexOf(tictac)+1; next = list.indexOf(tictac)+1;
tictac = $(tictac); tictac = $(`ft-${tictac}`);
} }
let mover = parentWithClass(tictac.control, 'movable'); let mover = parentWithClass(tictac.control, 'movable');
mover.style.display = 'flex'; mover.style.display = 'flex';
tictac.control.onclick(); tictac.control.onclick();
});
$('tool-rotate').onclick = event.bind("tool.show", "rotate");
$('tool-scale').onclick = event.bind("tool.show", "scale");
$('tool-mesh').onclick = event.bind("tool.show", "mesh");
$('tool-selector').onclick = event.bind("tool.show", "select");
} }
let nextool = 0;
let listool = ['ft-rotate','ft-scale','ft-mesh','ft-select'];
UI.tool.next = function() {
UI.tool.show(listool[nextool++ % 4]);
};
$('tool-rotate').onclick = () => { UI.tool.show('ft-rotate') };
$('tool-scale').onclick = () => { UI.tool.show('ft-scale') };
$('tool-mesh').onclick = () => { UI.tool.show('ft-mesh') };
$('tool-selector').onclick = () => { UI.tool.show('ft-select') };
// warn users they are running a beta release // warn users they are running a beta release
if (KIRI.beta && KIRI.beta > 0 && SDB.kiri_beta != KIRI.beta) { if (KIRI.beta && KIRI.beta > 0 && SDB.kiri_beta != KIRI.beta) {

View file

@ -307,8 +307,9 @@
file: showHelpFile file: showHelpFile
}, },
event: { event: {
on: addOnEvent, on: (t,l) => { EVENT.subscribe(t,l) },
emit: sendOnEvent, emit: (t,m,o) => { EVENT.publish(t,m,o) },
bind: (t,m,o) => { return EVENT.bind(t,m,o) },
import: loadFile, import: loadFile,
alerts: updateAlerts, alerts: updateAlerts,
settings: triggerSettingsEvent settings: triggerSettingsEvent
@ -585,8 +586,7 @@
******************************************************************* */ ******************************************************************* */
function unitScale() { function unitScale() {
return MODE === MODES.CAM && return MODE === MODES.CAM && settings.controller.units === 'in' ? 25.4 : 1;
settings.controller.units === 'in' ? 25.4 : 1;
} }
function alert2(message, time) { function alert2(message, time) {
@ -654,15 +654,6 @@
return showFavorites; return showFavorites;
} }
function sendOnEvent(name, data, options) {
EVENT.publish(name, data, options);
}
function addOnEvent(name, handler) {
EVENT.subscribe(name, handler);
return API.event;
}
function triggerSettingsEvent() { function triggerSettingsEvent() {
API.event.emit('settings', settings); API.event.emit('settings', settings);
} }

View file

@ -50,8 +50,8 @@ class Broker {
// return function bound to a topic // return function bound to a topic
bind(topic, message, options) { bind(topic, message, options) {
let broker = this; let broker = this;
return function(msg = message, opt = options) { return function(msg, opt) {
broker.publish(topic, msg, opt); broker.publish(topic, message || msg, options || opt);
} }
} }
} }