Color pickers for SimpleEffectDialog#1611
Conversation
cameronwhite
left a comment
There was a problem hiding this comment.
IMO we really should be using the same color picker dialog here - what are the issues blocking that from being doable? From what I recall it can be launched to edit a single color, like when you middle-click on a palette color
| ? c | ||
| : ColorBgra.FromBgra (0, 0, 0, 255); | ||
|
|
||
| Gdk.RGBA initialColorGdk = new () { |
There was a problem hiding this comment.
Gdk.RGBA is unpremultiplied alpha, like Cairo.Color, so these conversions aren't correct if the ColorBgra has premultiplied alpha (which it should - see also #1553)
| Alpha = initialColor.A / 255f, | ||
| }; | ||
|
|
||
| Gtk.ColorButton colorButton = Gtk.ColorButton.NewWithRgba (initialColorGdk); |
There was a problem hiding this comment.
I'd be interested to see how it looks with some maximum width, so that it doesn't stretch across the entire dialog.
| }; | ||
|
|
||
| Gtk.ColorButton colorButton = Gtk.ColorButton.NewWithRgba (initialColorGdk); | ||
| colorButton.OnColorSet += (_, _) => { |
There was a problem hiding this comment.
One other note is that Gtk.ColorButton was deprecated in GTK 4.10, with Gtk.ColorDialogButton as its replacement. Although, I'm not sure if either can be used to launch our own color picker dialog
Instead of deprecated `ColorButton`
|
@cameronwhite I tried to address your concerns in the last three commits. As for your question about the color picker dialog, I haven't checked in detail (it's a very long piece of code and haven't found the time), but the palette service gets passed to the constructor, and events get hooked to it, and that makes me think the dialog is tightly coupled to the palette. I might be wrong, though. Part of the longer-term vision of my cumulative refactorings is to make it obvious if some component is safe to use or not. As for using |
|
Thanks, I think my only additional suggestion would be putting the ColorBgra -> Gdk.RGBA conversion functions as methods on those types, so that we don't reinvent the code if it's needed elsewhere in the future. Re: color picker dialog, I'm pretty sure those event handlers are only set up when the live palette mode is being used, so I suspect it wouldn't be a large project to make that more clear with some refactoring. |
|
Thanks @cameronwhite. I just moved the conversions to extension methods. I will look into using our color picker dialog as soon as I can find the time. |
|
Thanks! |
|
Yeah, |
|
I just checked, and I think it's unlikely that we can use the GTK The methods that convert to An issue (that should go away with time and refactoring) is that |
|
|
||
| ImageSurface tileSurface = new (Format.Rgb24, TILE_SIZE, TILE_SIZE); | ||
|
|
||
| using (Context sc = new (tileSurface)) { |
There was a problem hiding this comment.
Could this use CairoExtensions.CreateTransparentBackgroundPattern?
| cr.SetSource (checkeredPattern); | ||
| cr.Paint (); | ||
|
|
||
| cr.SetSourceRgba ( |
There was a problem hiding this comment.
cr.setSourceColor(display_color) should work here to be a bit more concise
| ? c | ||
| : ColorBgra.Black; | ||
|
|
||
| Color currentColorCairo = currentColorBgra.ToCairoColor (); |
There was a problem hiding this comment.
I think this also needs to convert the alpha :)
For now it's fine to just do currentColorBgra.ToStraightAlpha().ToCairoColor() and the inverse afterwards - as part of #1553 we'll fix ToCairoColor() to always convert
instead of rolling my own
This reverts commit 6c9652f.
|
I tried to address each of your points in their own commit @cameronwhite. I haven't had a lot of time to check, but isn't considerable precision lost when doing this conversion? ColorBgra newColorBgra =
newColorCairo
.ToColorBgra ()
.ToPremultipliedAlpha (); |
|
Thanks! Will do some more testing later Re: premultiplied alpha, that's correct that less precision is available for the channels when alpha goes toward zero |
|
Thinking about this more, perhaps we should only support It's pretty easy for an effect to convert to ColorBgra, and isn't any different from how e.g. the palette colors are stored |
in `SimpleEffectDialog`
This reverts commit 2d32978.
|
I just removed the handling of I'm thinking that, longer-term, we would probably be able to re-add it if no conversions need to take place, but for that to happen lots of refactoring still need to take place, of course |
|
Thanks! I think the conversion is inevitable though - since we want the user to select a color using straight alpha in the color dialog, the setting should also be stored in straight alpha and only converted to premultiplied alpha when going into the Cairo surface |
Could close #1501 , or should we wait for further milestones?
It is using a
Gtk.ColorButton, which opens the standard (and quite limited) Gtk color selection dialog. In the future, we might want to use Pinta's amazing color picker dialog. The main stopper is that it still needs a lot of refactoring to be viableThe first commit is the change itself.
The second commit is the demo.
The third commit is the reversal of the demo.