|
@@ -1,6 +1,9 @@
|
|
|
import * as React from "react";
|
|
|
import { Observable, Color3 } from "babylonjs";
|
|
|
import { PropertyChangedEvent } from "../../propertyChangedEvent";
|
|
|
+import { NumericInputComponent } from "./numericInputComponent";
|
|
|
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
+import { faMinus, faPlus } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
|
|
export interface IColor3LineComponentProps {
|
|
|
label: string,
|
|
@@ -9,12 +12,12 @@ export interface IColor3LineComponentProps {
|
|
|
onPropertyChangedObservable?: Observable<PropertyChangedEvent>
|
|
|
}
|
|
|
|
|
|
-export class Color3LineComponent extends React.Component<IColor3LineComponentProps, { color: Color3 }> {
|
|
|
+export class Color3LineComponent extends React.Component<IColor3LineComponentProps, { isExpanded: boolean, color: Color3 }> {
|
|
|
private _localChange = false;
|
|
|
constructor(props: IColor3LineComponentProps) {
|
|
|
super(props);
|
|
|
|
|
|
- this.state = { color: this.props.target[this.props.propertyName].clone() };
|
|
|
+ this.state = { isExpanded: false, color: this.props.target[this.props.propertyName].clone() };
|
|
|
}
|
|
|
|
|
|
shouldComponentUpdate(nextProps: IColor3LineComponentProps, nextState: { color: Color3 }) {
|
|
@@ -46,15 +49,86 @@ export class Color3LineComponent extends React.Component<IColor3LineComponentPro
|
|
|
this.setState({ color: newColor });
|
|
|
}
|
|
|
|
|
|
+ switchExpandState() {
|
|
|
+ this._localChange = true;
|
|
|
+ this.setState({ isExpanded: !this.state.isExpanded });
|
|
|
+ }
|
|
|
+
|
|
|
+ raiseOnPropertyChanged(previousValue: Color3) {
|
|
|
+
|
|
|
+ if (!this.props.onPropertyChangedObservable) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.props.onPropertyChangedObservable.notifyObservers({
|
|
|
+ object: this.props.target,
|
|
|
+ property: this.props.propertyName,
|
|
|
+ value: this.state.color,
|
|
|
+ initialValue: previousValue
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ updateStateR(value: number) {
|
|
|
+ this._localChange = true;
|
|
|
+
|
|
|
+ const store = this.state.color.clone();
|
|
|
+ this.props.target[this.props.propertyName].x = value;
|
|
|
+ this.state.color.r = value;
|
|
|
+ this.props.target[this.props.propertyName] = this.state.color;
|
|
|
+ this.setState({ color: this.state.color });
|
|
|
+
|
|
|
+ this.raiseOnPropertyChanged(store);
|
|
|
+ }
|
|
|
+
|
|
|
+ updateStateG(value: number) {
|
|
|
+ this._localChange = true;
|
|
|
+
|
|
|
+ const store = this.state.color.clone();
|
|
|
+ this.props.target[this.props.propertyName].g = value;
|
|
|
+ this.state.color.g = value;
|
|
|
+ this.props.target[this.props.propertyName] = this.state.color;
|
|
|
+ this.setState({ color: this.state.color });
|
|
|
+
|
|
|
+ this.raiseOnPropertyChanged(store);
|
|
|
+ }
|
|
|
+
|
|
|
+ updateStateB(value: number) {
|
|
|
+ this._localChange = true;
|
|
|
+
|
|
|
+ const store = this.state.color.clone();
|
|
|
+ this.props.target[this.props.propertyName].b = value;
|
|
|
+ this.state.color.b = value;
|
|
|
+ this.props.target[this.props.propertyName] = this.state.color;
|
|
|
+ this.setState({ color: this.state.color });
|
|
|
+
|
|
|
+ this.raiseOnPropertyChanged(store);
|
|
|
+ }
|
|
|
+
|
|
|
render() {
|
|
|
+
|
|
|
+ const chevron = this.state.isExpanded ? <FontAwesomeIcon icon={faMinus} /> : <FontAwesomeIcon icon={faPlus} />
|
|
|
+ const colorAsColor3 = this.state.color.getClassName() === "Color3" ? this.state.color : new BABYLON.Color3(this.state.color.r, this.state.color.g, this.state.color.b);
|
|
|
+
|
|
|
return (
|
|
|
<div className="color3Line">
|
|
|
- <div className="label">
|
|
|
- {this.props.label}
|
|
|
- </div>
|
|
|
- <div className="color3">
|
|
|
- <input type="color" value={this.state.color.toHexString()} onChange={(evt) => this.onChange(evt.target.value)} />
|
|
|
+ <div className="firstLine">
|
|
|
+ <div className="label">
|
|
|
+ {this.props.label}
|
|
|
+ </div>
|
|
|
+ <div className="color3">
|
|
|
+ <input type="color" value={colorAsColor3.toHexString()} onChange={(evt) => this.onChange(evt.target.value)} />
|
|
|
+ </div>
|
|
|
+ <div className="expand" onClick={() => this.switchExpandState()}>
|
|
|
+ {chevron}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
+ {
|
|
|
+ this.state.isExpanded &&
|
|
|
+ <div className="secondLine">
|
|
|
+ <NumericInputComponent label="r" value={this.state.color.r} onChange={value => this.updateStateR(value)} />
|
|
|
+ <NumericInputComponent label="g" value={this.state.color.g} onChange={value => this.updateStateG(value)} />
|
|
|
+ <NumericInputComponent label="b" value={this.state.color.b} onChange={value => this.updateStateB(value)} />
|
|
|
+ </div>
|
|
|
+ }
|
|
|
</div>
|
|
|
);
|
|
|
}
|