Changeset - 078e6e7ec206
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 20 months ago 2023-06-03 23:02:34
drewp@bigasterisk.com
shorter sliders send fewer events
2 files changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
light9/fade/Light9EffectFader.ts
Show inline comments
 
@@ -62,49 +62,49 @@ function maybeFloatValue(graph: SyncedGr
 
    return undefined;
 
  }
 
}
 

	
 
//////////////////////////////////////
 
class EffectFader {
 
  constructor(public uri: NamedNode) { }
 
  column: string = "unset";
 
  effect?: NamedNode;
 
  effectAttr?: NamedNode; // :strength
 
  setting?: NamedNode; // we assume fader always has exactly one setting
 
  value?: number;
 
}
 

	
 
@customElement("light9-effect-fader")
 
export class Light9EffectFader extends LitElement {
 
  static styles = [
 
    css`
 
      :host {
 
        display: inline-block;
 
        border: 2px gray outset;
 
        background: #272727;
 
      }
 
      light9-fader {
 
        margin: 4px;
 
        margin: 0px;
 
        width: 100%;
 
      }
 
    `,
 
  ];
 
  render() {
 
    if (this.conf === undefined || this.conf.value === undefined) {
 
      return html`...`;
 
    }
 
    return html`
 
      <div><resource-display .uri=${this.uri}></resource-display>
 
      <light9-fader .value=${this.conf.value} @change=${this.onSliderInput}></light9-fader>
 
      <div>${this.conf.value.toPrecision(3)}</div>
 
      <div>effect <edit-choice nounlink .uri=${this.conf.effect} @edited=${this.onEffectChange}></edit-choice></div>
 
      <div>attr <edit-choice nounlink .uri=${this.conf.effectAttr} @edited=${this.onEffectAttrChange}></edit-choice></div>
 
    `;
 
  }
 

	
 
  graph?: SyncedGraph;
 
  ctx: NamedNode = new NamedNode(showRoot + "/fade");
 
  @property() uri!: NamedNode;
 
  @state() conf?: EffectFader; // compiled from graph
 

	
 
  constructor() {
 
    super();
light9/fade/Light9Fader.ts
Show inline comments
 
import debug from "debug";
 
import { css, html, LitElement, PropertyValueMap } from "lit";
 
import { customElement, property, query } from "lit/decorators.js";
 

	
 
import { clamp } from "../web/floating_color_picker";
 
const log = debug("fade");
 

	
 
class Drag {
 
  constructor(public startDragPxY: number, public startDragValue: number) {}
 
}
 

	
 
@customElement("light9-fader")
 
export class Light9Fader extends LitElement {
 
  static styles = [
 
    css`
 
      :host {
 
        display: inline-block;
 
        border: 2px gray inset;
 
        background: #000;
 
        height: 130px;
 
        height: 80px;
 
      }
 
      #handle {
 
        background: gray;
 
        border: 5px gray outset;
 
        position: relative;
 
        left: 0;
 
        right: -25px;
 
      }
 
    `,
 
  ];
 

	
 
  @property() value: number = 0;
 

	
 
  @query("#handle") handleEl!: HTMLElement;
 

	
 
  troughHeight = 130 - 2 - 2 - 5 - 5;
 
  handleHeight = 20;
 
  troughHeight = 80 - 2 - 2 - 5 - 5;
 
  handleHeight = 10;
 

	
 
  drag?: Drag;
 
  unmutedValue: number = 1;
 

	
 
  render() {
 
    return html` <div id="handle"><hr /></div> `;
 
  }
 

	
 
  protected update(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
 
    super.update(changedProperties);
 
    if (changedProperties.has("value")) {
 
      
 
    }
 
  }
 
  valueChangedFromUi() {
 
    this.value= clamp(this.value, 0, 1)
 
    this.dispatchEvent(new CustomEvent("change", { detail: { value: this.value } }));
 
  }
 

	
 
  protected updated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
 
    super.updated(_changedProperties);
 
    const y = this.sliderTopY(this.value);
 
    this.handleEl.style.top = y + "px";
 
  }
 
@@ -73,49 +73,49 @@ export class Light9Fader extends LitElem
 
      if (ev.buttons == 1) {
 
        this.drag = new Drag(ev.clientY, this.value);
 
      } else if (ev.buttons == 2) {
 
        this.onRmb();
 
      }
 
    });
 
    this.addEventListener("mousedown", (ev: MouseEvent) => {
 
      ev.stopPropagation();
 
      if (ev.buttons == 1) {
 
        this.value = this.sliderValue(ev.offsetY);
 
        this.valueChangedFromUi()
 
        this.drag = new Drag(ev.clientY, this.value);
 
      } else if (ev.buttons == 2) {
 
        // RMB in trough
 
        this.onRmb();
 
      }
 
    });
 

	
 
    this.addEventListener("contextmenu", (event) => {
 
      event.preventDefault();
 
    });
 

	
 
    this.addEventListener("wheel", (ev: WheelEvent) => {
 
      ev.preventDefault();
 
      this.value += ev.deltaY / 120 * -.05;
 
      this.value += ev.deltaY / this.troughHeight * -.05;
 
      this.valueChangedFromUi()
 
    });
 

	
 
    const maybeDrag = (ev: MouseEvent) => {
 
      if (ev.buttons != 1) return;
 
      if (this.drag === undefined) return;
 
      ev.stopPropagation();
 
      this.onMouseDrag(ev.clientY - this.drag.startDragPxY!);
 
    };
 
    hand.addEventListener("mousemove", maybeDrag);
 
    this.addEventListener("mousemove", maybeDrag);
 
    window.addEventListener("mousemove", maybeDrag);
 

	
 
    hand.addEventListener("mouseup", this.onMouseUpAnywhere.bind(this));
 
    this.addEventListener("mouseup", this.onMouseUpAnywhere.bind(this));
 
    window.addEventListener("mouseup", this.onMouseUpAnywhere.bind(this));
 
  }
 
  onRmb() {
 
    if (this.value > 0.1) {
 
      // mute
 
      this.unmutedValue = this.value;
 
      this.value = 0;
 
    } else {
 
      // unmute
0 comments (0 inline, 0 general)