MCPcopy Create free account
hub / github.com/devforth/painterro / setActiveTool

Method setActiveTool

js/main.js:1511–1570  ·  view source on GitHub ↗
(b)

Source from the content-addressed store, hash-verified

1509
1510
1511 setActiveTool(b) {
1512 this.activeTool = b;
1513
1514 this.zoomButtonActive = false;
1515 const btnEl = this.getBtnEl(this.activeTool);
1516 if (btnEl) {
1517 btnEl.className += ' ptro-color-active-control';
1518 }
1519 let ctrls = '';
1520 (b.controls || []).forEach((ctl) => {
1521 ctl.id = genId();
1522 if (ctl.title) {
1523 ctrls += `<span class="ptro-tool-ctl-name" title="${tr(ctl.titleFull)}">${tr(ctl.title)}</span>`;
1524 }
1525 if (ctl.type === 'btn') {
1526 ctrls += `<button type="button" ${ctl.hint ? `title="${tr(ctl.hint)}"` : ''} class="ptro-color-control ${ctl.icon ? 'ptro-icon-btn' : 'ptro-named-btn'}" ` +
1527 `id=${ctl.id}>${ctl.icon ? `<i class="ptro-icon ptro-icon-${ctl.icon}"></i>` : ''}` +
1528 `<p>${ctl.name || ''}</p></button>`;
1529 } else if (ctl.type === 'color') {
1530 ctrls += `<button type="button" id=${ctl.id} data-id='${ctl.target}' ` +
1531 `style="background-color: ${this.colorWidgetState[ctl.target].alphaColor}" ` +
1532 'class="color-diwget-btn ptro-color-btn ptro-bordered-btn ptro-color-control"></button>' +
1533 '<span class="ptro-btn-color-checkers-bar"></span>';
1534 } else if (ctl.type === 'int') {
1535 ctrls += `<input id=${ctl.id} class="ptro-input" type="number" min="${ctl.min}" max="${ctl.max}" ` +
1536 `data-id='${ctl.target}'/>`;
1537 } else if (ctl.type === 'bool') {
1538 ctrls += `<button id=${ctl.id} class="ptro-input ptro-check" data-value="false" type="button" ` +
1539 `data-id='${ctl.target}'></button>`;
1540 } else if (ctl.type === 'dropdown') {
1541 let options = '';
1542 ctl.getAvailableValues().forEach((o) => {
1543 options += `<option ${o.extraStyle ? `style='${o.extraStyle}'` : ''}` +
1544 ` value='${o.value}' ${o.title ? `title='${o.title}'` : ''}>${o.name}</option>`;
1545 });
1546 ctrls += `<select id=${ctl.id} class="ptro-input" ` +
1547 `data-id='${ctl.target}'>${options}</select>`;
1548 }
1549 });
1550 this.toolControls.innerHTML = ctrls;
1551 (b.controls || []).forEach((ctl) => {
1552 if (ctl.type === 'int') {
1553 this.getElemByIdSafe(ctl.id).value = ctl.getValue();
1554 if (ctl.options && ctl.options.eventOnChange){
1555 this.getElemByIdSafe(ctl.id).onchange = ctl.action;
1556 } else {
1557 this.getElemByIdSafe(ctl.id).oninput = ctl.action;
1558 }
1559 } else if (ctl.type === 'bool') {
1560 this.getElemByIdSafe(ctl.id).setAttribute('data-value', ctl.getValue() ? 'true' : 'false');
1561 this.getElemByIdSafe(ctl.id).onclick = ctl.action;
1562 } else if (ctl.type === 'dropdown') {
1563 this.getElemByIdSafe(ctl.id).onchange = ctl.action;
1564 this.getElemByIdSafe(ctl.id).value = ctl.getValue();
1565 } else {
1566 this.getElemByIdSafe(ctl.id).onclick = ctl.action;
1567 }
1568 });

Callers 5

constructorMethod · 0.95
closeActiveToolMethod · 0.95
undoStateMethod · 0.80
redoStateMethod · 0.80
placeAtMethod · 0.80

Calls 5

getBtnElMethod · 0.95
genIdFunction · 0.90
trFunction · 0.90
getValueMethod · 0.45
activateMethod · 0.45

Tested by

no test coverage detected