Allowing user to choose gradients from different sources, and allowing CloudsEffect to make use of custom gradients#683
Conversation
CloudsEffect to make use of custom gradients
CloudsEffect to make use of custom gradientsCloudsEffect to make use of custom gradients
| return CreateColorGradient (colorScheme); | ||
| case ColorSchemeSource.SelectedColors: | ||
| return ColorGradient.Create ( | ||
| PintaCore.Palette.PrimaryColor.ToColorBgra (), |
There was a problem hiding this comment.
Rather than accessing PintaCore.Palette, the caller should provide an IPaletteService.
For unit tests, this avoids initializing a ton of things in Pinta.Core that end up failing (this is one of the reasons why the clouds effect didn't have a unit test already)
Instead of accessing `PintaCore.Palette`
|
Thanks for the feedback. I've now changed it so that an |
…bal palette is removed
|
Also, I added |
… the global palette is removed" This reverts commit 71fc127.
We should remove that dependency so we can test them :) |
|
I removed the |
… should be now be testable)
|
These effects are now being passed an (We should probably pass |
| public CloudsData Data => (CloudsData) EffectData!; // NRT - Set in constructor | ||
|
|
||
| public CloudsEffect () | ||
| public IPaletteService palette { get; } |
There was a problem hiding this comment.
Should this have been private?
There was a problem hiding this comment.
Yes, it should have been private. Thanks for catching it. It has been corrected now
|
|
||
| public enum ColorSchemeSource | ||
| { | ||
| [Caption ("Predefined Gradient")] |
There was a problem hiding this comment.
I'd prefer Preset Gradient as the label for the user here
There was a problem hiding this comment.
No problem. The label has been changed
| internal sealed class MockPalette : IPaletteService | ||
| { | ||
| public Color PrimaryColor { get; set; } = new (0, 0, 0); // Black | ||
| public Color SecondaryColor { get; set; } = new (255, 255, 255); // White |
There was a problem hiding this comment.
I think this is incorrect since Cairo.Color is floating point, so the 255's should be just 1 (look at the ToColorBgra method)
You could also just do ColorBgra.White.ToCairoColor()
There was a problem hiding this comment.
You are right. For a moment I forgot that in Cairo the color channels go from 0 to 1. It's corrected now
| public Color PrimaryColor { get; set; } = new (0, 0, 0); // Black | ||
| public Color SecondaryColor { get; set; } = new (255, 255, 255); // White | ||
|
|
||
| public void SetColor (bool setPrimary, Color color, bool addToRecent = true) |
There was a problem hiding this comment.
Because the Utilities class is creating a singleton palette, this could be a future source of bugs - if tests try to set the color then this might cause the changes to affect other test runs. (And tests are executed in parallel)
I'd maybe lean towards not caching the mock service manager for now since it's currently very cheap to construct
There was a problem hiding this comment.
Understood. It's now creating an instance every time
| mock_services = CreateMockServices (); | ||
| } | ||
|
|
||
| private static IServiceManager CreateMockServices () |
There was a problem hiding this comment.
I haven't tried running the benchmarks with these changes, but will it cause any runtime errors if there isn't a palette provided now?
There was a problem hiding this comment.
No, it shouldn't cause any runtime errors. This was added because the constructors of those effects now receive an IServiceManager, but I was careful so that the default behaviors have the exact same result as before the changes.
If the code path that was being followed before did not access the palette, it doesn't access the palette now, either.
There was a problem hiding this comment.
I get the following from running dotnet run --project tests/PintaBenchmarks -c Release -- -f \*JuliaFractalEffect
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.ApplicationException: Could not resolve service type Pinta.Core.IPaletteService
at Pinta.Core.ServiceManager.GetService[T]() in /Users/cameron/code/Pinta/Pinta.Core/Managers/ServiceManager.cs:line 55
at Pinta.Effects.JuliaFractalEffect..ctor(IServiceManager services) in /Users/cameron/code/Pinta/Pinta.Effects/Effects/JuliaFractalEffect.cs:line 35
at PintaBenchmarks.EffectsBenchmarks.JuliaFractalEffect() in /Users/cameron/code/Pinta/tests/PintaBenchmarks/EffectsBenchmarks.cs:line 96
There was a problem hiding this comment.
You are right...The mock palette should be created and added to the service manager first. I just added it; this error you got shouldn't happen again
Besides the pre-defined ones, the user can choose to get them from the colors that are currently selected (like it's done in
CloudsEffector to randomize the colors and the stops).Also, modified
CloudsEffectto be able to use custom gradients. Here's a rendering of clouds with theElectriccolor scheme:...but at the same time the defaults should make it behave the same way it always has.