From 2fe433991d727e70fe43a03735f929188384fbad Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 15 Aug 2024 17:05:19 -0400 Subject: [PATCH] Rename ColorPicker to HSVAColorPicker --- colorpicker.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/colorpicker.go b/colorpicker.go index 084be29..7fc0206 100644 --- a/colorpicker.go +++ b/colorpicker.go @@ -8,13 +8,13 @@ import "git.tebibyte.media/tomo/tomo/canvas" import "git.tebibyte.media/tomo/objects/layouts" 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. -type ColorPicker struct { +type HSVAColorPicker struct { tomo.ContainerBox value internal.HSVA - pickerMap *colorPickerMap + pickerMap *hsvaColorPickerMap hueSlider *Slider alphaSlider *Slider @@ -23,14 +23,14 @@ type ColorPicker struct { } } -// NewColorPicker creates a new color picker with the specified color. -func NewColorPicker (value color.Color) *ColorPicker { - picker := &ColorPicker { +// NewHSVAColorPicker creates a new color picker with the specified color. +func NewHSVAColorPicker (value color.Color) *HSVAColorPicker { + picker := &HSVAColorPicker { ContainerBox: tomo.NewContainerBox(), } picker.SetRole(tomo.R("objects", "ColorPicker")) picker.SetAttr(tomo.ALayout(layouts.Row { true, false, false })) - picker.pickerMap = newColorPickerMap(picker) + picker.pickerMap = newHsvaColorPickerMap(picker) picker.Add(picker.pickerMap) picker.hueSlider = NewVerticalSlider(0.0) @@ -55,12 +55,12 @@ func NewColorPicker (value color.Color) *ColorPicker { } // Value returns the color of the picker. -func (this *ColorPicker) Value () color.Color { +func (this *HSVAColorPicker) Value () color.Color { return this.value } // 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 } this.value = internal.HSVAModel.Convert(value).(internal.HSVA) 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 // 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) } // 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() } -type colorPickerMap struct { +type hsvaColorPickerMap struct { tomo.CanvasBox dragging bool - parent *ColorPicker + parent *HSVAColorPicker } -func newColorPickerMap (parent *ColorPicker) *colorPickerMap { - picker := &colorPickerMap { +func newHsvaColorPickerMap (parent *HSVAColorPicker) *hsvaColorPickerMap { + picker := &hsvaColorPickerMap { CanvasBox: tomo.NewCanvasBox(), parent: parent, } @@ -97,26 +97,26 @@ func newColorPickerMap (parent *ColorPicker) *colorPickerMap { return picker } -func (this *colorPickerMap) handleButtonDown (button input.Button) bool { +func (this *hsvaColorPickerMap) handleButtonDown (button input.Button) bool { if button != input.ButtonLeft { return false } this.dragging = true this.drag() return true } -func (this *colorPickerMap) handleButtonUp (button input.Button) bool { +func (this *hsvaColorPickerMap) handleButtonUp (button input.Button) bool { if button != input.ButtonLeft { return false } this.dragging = false return true } -func (this *colorPickerMap) handleMouseMove () bool { +func (this *hsvaColorPickerMap) handleMouseMove () bool { if !this.dragging { return false } this.drag() return true } -func (this *colorPickerMap) drag () { +func (this *hsvaColorPickerMap) drag () { pointer := this.Window().MousePosition() bounds := this.InnerBounds() this.parent.value.S = float64(pointer.X - bounds.Min.X) / float64(bounds.Dx()) @@ -126,7 +126,7 @@ func (this *colorPickerMap) drag () { this.Invalidate() } -func (this *colorPickerMap) Draw (can canvas.Canvas) { +func (this *hsvaColorPickerMap) Draw (can canvas.Canvas) { bounds := can.Bounds() for y := bounds.Min.Y; y < bounds.Max.Y; y ++ { for x := bounds.Min.X; x < bounds.Max.X; x ++ {