-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a528004
commit e987945
Showing
8 changed files
with
317 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
#color-panel { | ||
display: flex; | ||
flex-direction: column; | ||
|
||
background-color: $bcg-primary; | ||
|
||
padding: 0px 6px 12px 6px; | ||
} | ||
|
||
.color-row{ | ||
height: 32px; | ||
line-height: 32px; | ||
width: 100%; | ||
display: flex; | ||
flex-direction: row; | ||
flex-grow: 1; | ||
align-items: center; | ||
} | ||
|
||
.color-label{ | ||
width: 70px; | ||
flex-shrink: 0; | ||
flex-grow: 0; | ||
margin: 0px; | ||
} | ||
|
||
.color-expand { | ||
flex-grow: 1; | ||
} | ||
|
||
$height: 22px; | ||
|
||
#color-panel > div > div.pcui-vector-input { | ||
margin: 0px; | ||
gap: 10px; | ||
height: $height; | ||
} | ||
|
||
#color-panel > div > div.pcui-numeric-input { | ||
margin: 0px; | ||
height: $height; | ||
line-height: $height; | ||
|
||
& > input { | ||
padding: 0px; | ||
margin: 0px 0px 0px 4px; | ||
height: $height; | ||
} | ||
} | ||
|
||
#color-panel > div > div > div.pcui-numeric-input { | ||
margin: 0px; | ||
height: $height; | ||
line-height: $height; | ||
|
||
& > input { | ||
padding: 0px; | ||
margin: 0px 0px 0px 4px; | ||
height: $height; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import { Container, ContainerArgs, Label, NumericInput } from 'pcui'; | ||
import { Events } from '../events'; | ||
import { Splat } from '../splat'; | ||
import { EntityColorAdjustmentOp } from '../edit-ops'; | ||
import { localize } from './localization'; | ||
|
||
class ColorPanel extends Container { | ||
constructor(events: Events, args: ContainerArgs = {}) { | ||
args = { | ||
...args, | ||
id: 'color-panel' | ||
}; | ||
|
||
super(args); | ||
|
||
const brightness = new Container({ | ||
class: 'color-row' | ||
}); | ||
|
||
const brightnessLabel = new Label({ | ||
class: 'color-label', | ||
text: localize('color.brightness') | ||
}); | ||
|
||
const brightnessInput = new NumericInput({ | ||
class: 'color-expand', | ||
precision: 2, | ||
value: 1.0, | ||
min: 0.0, | ||
max: 10.0, | ||
enabled: false | ||
}); | ||
|
||
brightness.append(brightnessLabel); | ||
brightness.append(brightnessInput); | ||
|
||
const temperature = new Container({ | ||
class: 'color-row' | ||
}); | ||
|
||
const temperatureLabel = new Label({ | ||
class: 'color-label', | ||
text: localize('color.temperature') | ||
}); | ||
|
||
const temperatureInput = new NumericInput({ | ||
class: 'color-expand', | ||
precision: 2, | ||
value: 0, | ||
min: -0.5, | ||
max: 0.5, | ||
enabled: false | ||
}); | ||
|
||
temperature.append(temperatureLabel); | ||
temperature.append(temperatureInput); | ||
|
||
const tint = new Container({ | ||
class: 'color-row' | ||
}); | ||
|
||
const tintLabel = new Label({ | ||
class: 'color-label', | ||
text: localize('color.tint') | ||
}); | ||
|
||
const tintInput = new NumericInput({ | ||
class: 'color-expand', | ||
precision: 2, | ||
value: 0, | ||
max: 0.5, | ||
min: -0.5, | ||
enabled: false | ||
}); | ||
|
||
tint.append(tintLabel); | ||
tint.append(tintInput); | ||
|
||
this.append(brightness); | ||
this.append(temperature); | ||
this.append(tint); | ||
|
||
let selection: Splat | null = null; | ||
|
||
let uiUpdating = false; | ||
|
||
const updateUI = () => { | ||
uiUpdating = true; | ||
brightnessInput.value = selection.colorAdjustment.brightness; | ||
temperatureInput.value = selection.colorAdjustment.temperature; | ||
tintInput.value = selection.colorAdjustment.tint; | ||
uiUpdating = false; | ||
}; | ||
|
||
events.on('selection.changed', (splat) => { | ||
selection = splat; | ||
|
||
if (selection) { | ||
// enable inputs | ||
updateUI(); | ||
temperatureInput.enabled = tintInput.enabled = brightnessInput.enabled = true; | ||
} else { | ||
// disable inputs | ||
temperatureInput.enabled = tintInput.enabled = brightnessInput.enabled = false; | ||
} | ||
}); | ||
|
||
let op: EntityColorAdjustmentOp | null = null; | ||
|
||
const createOp = () => { | ||
op = new EntityColorAdjustmentOp({ | ||
splat: selection, | ||
oldAdj: selection.colorAdjustment, | ||
newAdj: selection.colorAdjustment | ||
}); | ||
}; | ||
|
||
const updateOp = () => { | ||
op.newAdj = { | ||
brightness: brightnessInput.value, | ||
temperature: temperatureInput.value, | ||
tint: tintInput.value | ||
}; | ||
|
||
op.do(); | ||
}; | ||
|
||
const submitOp = () => { | ||
events.fire('edit.add', op); | ||
op = null; | ||
}; | ||
|
||
const change = () => { | ||
if (!uiUpdating) { | ||
if (op) { | ||
updateOp(); | ||
} else { | ||
createOp(); | ||
updateOp(); | ||
submitOp(); | ||
} | ||
} | ||
}; | ||
|
||
const mousedown = () => { | ||
createOp(); | ||
}; | ||
|
||
const mouseup = () => { | ||
updateOp(); | ||
submitOp(); | ||
}; | ||
|
||
[brightnessInput, temperatureInput, tintInput].forEach((input) => { | ||
input.on('change', change); | ||
input.on('slider:mousedown', mousedown); | ||
input.on('slider:mouseup', mouseup); | ||
}); | ||
} | ||
} | ||
|
||
export { ColorPanel }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.