Rename ColorPicker to HSVAColorPicker
This commit is contained in:
parent
acec0f6222
commit
2fe433991d
@ -8,13 +8,13 @@ import "git.tebibyte.media/tomo/tomo/canvas"
|
|||||||
import "git.tebibyte.media/tomo/objects/layouts"
|
import "git.tebibyte.media/tomo/objects/layouts"
|
||||||
import "git.tebibyte.media/tomo/objects/internal"
|
import "git.tebibyte.media/tomo/objects/internal"
|
||||||
|
|
||||||
// ColorPicker allows the user to pick a color by controlling its HSBA
|
// HSVAColorPicker allows the user to pick a color by controlling its HSVA
|
||||||
// parameters.
|
// parameters.
|
||||||
type ColorPicker struct {
|
type HSVAColorPicker struct {
|
||||||
tomo.ContainerBox
|
tomo.ContainerBox
|
||||||
value internal.HSVA
|
value internal.HSVA
|
||||||
|
|
||||||
pickerMap *colorPickerMap
|
pickerMap *hsvaColorPickerMap
|
||||||
hueSlider *Slider
|
hueSlider *Slider
|
||||||
alphaSlider *Slider
|
alphaSlider *Slider
|
||||||
|
|
||||||
@ -23,14 +23,14 @@ type ColorPicker struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewColorPicker creates a new color picker with the specified color.
|
// NewHSVAColorPicker creates a new color picker with the specified color.
|
||||||
func NewColorPicker (value color.Color) *ColorPicker {
|
func NewHSVAColorPicker (value color.Color) *HSVAColorPicker {
|
||||||
picker := &ColorPicker {
|
picker := &HSVAColorPicker {
|
||||||
ContainerBox: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
}
|
}
|
||||||
picker.SetRole(tomo.R("objects", "ColorPicker"))
|
picker.SetRole(tomo.R("objects", "ColorPicker"))
|
||||||
picker.SetAttr(tomo.ALayout(layouts.Row { true, false, false }))
|
picker.SetAttr(tomo.ALayout(layouts.Row { true, false, false }))
|
||||||
picker.pickerMap = newColorPickerMap(picker)
|
picker.pickerMap = newHsvaColorPickerMap(picker)
|
||||||
picker.Add(picker.pickerMap)
|
picker.Add(picker.pickerMap)
|
||||||
|
|
||||||
picker.hueSlider = NewVerticalSlider(0.0)
|
picker.hueSlider = NewVerticalSlider(0.0)
|
||||||
@ -55,12 +55,12 @@ func NewColorPicker (value color.Color) *ColorPicker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Value returns the color of the picker.
|
// Value returns the color of the picker.
|
||||||
func (this *ColorPicker) Value () color.Color {
|
func (this *HSVAColorPicker) Value () color.Color {
|
||||||
return this.value
|
return this.value
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetValue sets the color of the picker.
|
// SetValue sets the color of the picker.
|
||||||
func (this *ColorPicker) SetValue (value color.Color) {
|
func (this *HSVAColorPicker) SetValue (value color.Color) {
|
||||||
if value == nil { value = color.Transparent }
|
if value == nil { value = color.Transparent }
|
||||||
this.value = internal.HSVAModel.Convert(value).(internal.HSVA)
|
this.value = internal.HSVAModel.Convert(value).(internal.HSVA)
|
||||||
this.hueSlider.SetValue(this.value.H)
|
this.hueSlider.SetValue(this.value.H)
|
||||||
@ -69,23 +69,23 @@ func (this *ColorPicker) SetValue (value color.Color) {
|
|||||||
|
|
||||||
// OnValueChange specifies a function to be called when the user changes the
|
// OnValueChange specifies a function to be called when the user changes the
|
||||||
// swatch's color.
|
// swatch's color.
|
||||||
func (this *ColorPicker) OnValueChange (callback func ()) event.Cookie {
|
func (this *HSVAColorPicker) OnValueChange (callback func ()) event.Cookie {
|
||||||
return this.on.valueChange.Connect(callback)
|
return this.on.valueChange.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RGBA satisfies the color.Color interface
|
// RGBA satisfies the color.Color interface
|
||||||
func (this *ColorPicker) RGBA () (r, g, b, a uint32) {
|
func (this *HSVAColorPicker) RGBA () (r, g, b, a uint32) {
|
||||||
return this.value.RGBA()
|
return this.value.RGBA()
|
||||||
}
|
}
|
||||||
|
|
||||||
type colorPickerMap struct {
|
type hsvaColorPickerMap struct {
|
||||||
tomo.CanvasBox
|
tomo.CanvasBox
|
||||||
dragging bool
|
dragging bool
|
||||||
parent *ColorPicker
|
parent *HSVAColorPicker
|
||||||
}
|
}
|
||||||
|
|
||||||
func newColorPickerMap (parent *ColorPicker) *colorPickerMap {
|
func newHsvaColorPickerMap (parent *HSVAColorPicker) *hsvaColorPickerMap {
|
||||||
picker := &colorPickerMap {
|
picker := &hsvaColorPickerMap {
|
||||||
CanvasBox: tomo.NewCanvasBox(),
|
CanvasBox: tomo.NewCanvasBox(),
|
||||||
parent: parent,
|
parent: parent,
|
||||||
}
|
}
|
||||||
@ -97,26 +97,26 @@ func newColorPickerMap (parent *ColorPicker) *colorPickerMap {
|
|||||||
return picker
|
return picker
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *colorPickerMap) handleButtonDown (button input.Button) bool {
|
func (this *hsvaColorPickerMap) handleButtonDown (button input.Button) bool {
|
||||||
if button != input.ButtonLeft { return false }
|
if button != input.ButtonLeft { return false }
|
||||||
this.dragging = true
|
this.dragging = true
|
||||||
this.drag()
|
this.drag()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *colorPickerMap) handleButtonUp (button input.Button) bool {
|
func (this *hsvaColorPickerMap) handleButtonUp (button input.Button) bool {
|
||||||
if button != input.ButtonLeft { return false }
|
if button != input.ButtonLeft { return false }
|
||||||
this.dragging = false
|
this.dragging = false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *colorPickerMap) handleMouseMove () bool {
|
func (this *hsvaColorPickerMap) handleMouseMove () bool {
|
||||||
if !this.dragging { return false }
|
if !this.dragging { return false }
|
||||||
this.drag()
|
this.drag()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *colorPickerMap) drag () {
|
func (this *hsvaColorPickerMap) drag () {
|
||||||
pointer := this.Window().MousePosition()
|
pointer := this.Window().MousePosition()
|
||||||
bounds := this.InnerBounds()
|
bounds := this.InnerBounds()
|
||||||
this.parent.value.S = float64(pointer.X - bounds.Min.X) / float64(bounds.Dx())
|
this.parent.value.S = float64(pointer.X - bounds.Min.X) / float64(bounds.Dx())
|
||||||
@ -126,7 +126,7 @@ func (this *colorPickerMap) drag () {
|
|||||||
this.Invalidate()
|
this.Invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *colorPickerMap) Draw (can canvas.Canvas) {
|
func (this *hsvaColorPickerMap) Draw (can canvas.Canvas) {
|
||||||
bounds := can.Bounds()
|
bounds := can.Bounds()
|
||||||
for y := bounds.Min.Y; y < bounds.Max.Y; y ++ {
|
for y := bounds.Min.Y; y < bounds.Max.Y; y ++ {
|
||||||
for x := bounds.Min.X; x < bounds.Max.X; x ++ {
|
for x := bounds.Min.X; x < bounds.Max.X; x ++ {
|
||||||
|
Loading…
Reference in New Issue
Block a user