// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // This class represent the UI for Thread drawing filter. // class ThreadUI extends HTMLElement { constructor() { super(); } connectedCallback() { this.innerHTML = `
Edit Thread Draw Options
Action
Override filters opacity Draw with filter color and opacity
`; this.setUpButtons_(); // Event listener to check if custom color selected // to automatically select override button document.getElementById('threadColor').addEventListener("change", () => { document.getElementById('threadOverride').checked = true; }); } setUpButtons_() { const saveButton = this.querySelector('#saveThreadOptions'); saveButton.addEventListener('click', () => { const threadOptions = { override: false }; let input = this.querySelector('input[name="dowhat"]:checked'); if (input.value === 'threadOverridesFilters') { threadOptions.color = this.querySelector('input[name="drawcolor"]').value; threadOptions.alpha = this.querySelector('input[name="fillalpha"]').value; threadOptions.override = true; } this.dispatchEvent(new CustomEvent('saveThreadOptionsEvent', { detail: threadOptions })); }); } }; window.customElements.define('thread-ui', ThreadUI); function createThreadChip(thread) { const chip = document.createElement('div'); chip.className = "mdc-chip"; chip.setAttribute("role", "row"); chip.style.margin = '5px'; chip.style.borderRadius = '0px'; if (thread.enabled_) { chip.style.border = thread.drawColor_ ? `2px solid ${thread.drawColor_}` : `1px solid black`; if (thread.fillAlpha_ > 0) { var alpha = Math.min(.6, parseFloat(thread.fillAlpha_) / 100); var rgba = thread.drawColor_ + DrawCall.alphaFloatToHex(alpha); chip.style.backgroundColor = rgba; chip.style.fontWeight = 'bold'; } else { chip.style.backgroundColor = `white`; } } else { chip.style.border = `1px dashed grey`; chip.style.backgroundColor = `white`; } chip.innerHTML = ` edit `; chip.querySelector('#thread-name').innerHTML = ("~ " + thread.threadName_); const check = chip.querySelector('input'); check.addEventListener('change', () => { Thread.getThread(thread.threadName_).toggleEnableThread(); Player.instance.refresh(); }); return chip; } function showEditThreadPopup(item) { var chip = item.closest(".mdc-chip"); // Slice thread name from HTML so that we exclude the "~ ". const threadName = chip.querySelector('#thread-name').innerHTML.slice(2); const thread = Thread.getThread(threadName); const threadUi = document.createElement('thread-ui'); threadUi.addEventListener('saveThreadOptionsEvent', (event) => { if (event.detail.color && event.detail.alpha) { thread.drawColor_ = event.detail.color; thread.fillAlpha_ = event.detail.alpha; const newThreadChip = createThreadChip(thread); const threadFilters = document.querySelector('#threads'); threadFilters.appendChild(newThreadChip); chip.replaceWith(newThreadChip); } thread.overrideFilters_ = event.detail.override; hideModal(); Player.instance.refresh(); }); threadUi.style.position = 'absolute'; threadUi.style.top = (chip.offsetTop + chip.offsetHeight) + 'px'; threadUi.style.left = (chip.offsetLeft + 20) + 'px'; threadUi.style.zIndex = maxZIndex; showModal(threadUi); var actionform = threadUi.querySelector('#actionform'); actionform.dowhat.value = thread.overrideFilters_ ? 'threadOverridesFilters' : 'drawWithFilterOptions'; actionform.drawcolor.value = thread.drawColor_; actionform.fillalpha.value = thread.fillAlpha_; }