Skip to content

Commit

Permalink
Since dialogs are not blocking in GTK4, use an event to signal when t…
Browse files Browse the repository at this point in the history
…he effect dialog is done.
  • Loading branch information
cameronwhite committed Mar 14, 2023
1 parent 3aac3c5 commit ef0466d
Show file tree
Hide file tree
Showing 38 changed files with 109 additions and 84 deletions.
24 changes: 21 additions & 3 deletions Pinta.Core/Effects/BaseEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,25 @@ public abstract class BaseEffect

/// <summary>
/// Launches the configuration dialog for this effect/adjustment.
/// If IsConfigurable is true, the ConfigDialogResponse event will be invoked when the user accepts or cancels the dialog.
/// </summary>
/// <returns>Whether the user accepted or cancelled the configuration dialog. (true: accept, false: cancel)</returns>
public virtual bool LaunchConfiguration ()
public virtual void LaunchConfiguration ()
{
if (IsConfigurable)
throw new NotImplementedException (string.Format ("{0} is marked as configurable, but has not implemented LaunchConfiguration", this.GetType ()));
}

/// <summary>
/// Emitted when the configuration dialog is accepted or cancelled by the user.
/// </summary>
public event EventHandler<ConfigDialogResponseEventArgs>? ConfigDialogResponse;

return false;
/// <summary>
/// Notify that the configuration dialog was accepted or cancelled by the user.
/// </summary>
public void OnConfigDialogResponse (bool accepted)
{
ConfigDialogResponse?.Invoke (this, new ConfigDialogResponseEventArgs (accepted));
}

#region Overrideable Render Methods
Expand Down Expand Up @@ -160,6 +171,13 @@ public virtual BaseEffect Clone ()

return effect;
}

public class ConfigDialogResponseEventArgs : EventArgs
{
public ConfigDialogResponseEventArgs (bool accepted) { Accepted = accepted; }

public bool Accepted { get; private set; }
}
}

/// <summary>
Expand Down
25 changes: 18 additions & 7 deletions Pinta.Core/Managers/LivePreviewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,24 @@ public void Start (BaseEffect effect)
renderer.Start (effect, layer.Surface, live_preview_surface, render_bounds);

if (effect.IsConfigurable) {
if (!effect.LaunchConfiguration ()) {
PintaCore.Chrome.MainWindowBusy = true;
Cancel ();
} else {
PintaCore.Chrome.MainWindowBusy = true;
Apply ();
}
EventHandler<BaseEffect.ConfigDialogResponseEventArgs>? handler = null;
handler = (_, args) => {
if (!args.Accepted) {
PintaCore.Chrome.MainWindowBusy = true;
Cancel ();
} else {
PintaCore.Chrome.MainWindowBusy = true;
Apply ();
}

// Unsubscribe once we're done.
effect.ConfigDialogResponse -= handler;
};

effect.ConfigDialogResponse += handler;

effect.LaunchConfiguration ();

} else {
PintaCore.Chrome.MainWindowBusy = true;
Apply ();
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Adjustments/BrightnessContrastEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ void HandleEffectDataPropertyChanged (object? sender, System.ComponentModel.Prop
table_calculated = false;
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

public override void Render (ImageSurface src, ImageSurface dest, Core.RectangleI[] rois)
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Adjustments/CurvesEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public CurvesEffect ()
EffectData = new CurvesData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
#if false // TODO-GTK4
using (var dialog = new CurvesDialog (Data)) {
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Adjustments/HueSaturationEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public HueSaturationEffect ()
EffectData = new HueSaturationData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

public override void Render (ImageSurface src, ImageSurface dest, Core.RectangleI[] rois)
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Adjustments/LevelsEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public LevelsEffect ()
EffectData = new LevelsData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
#if false // TODO-GTK4
using (var dialog = new LevelsDialog (Data)) {
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Adjustments/PosterizeEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public PosterizeEffect ()
EffectData = new PosterizeData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
#if false // TODO-GTK4
using (var dialog = new PosterizeDialog ()) {
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/AddNoiseEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public AddNoiseEffect ()
EffectData = new NoiseData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/BulgeEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public BulgeEffect ()
EffectData = new BulgeData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/CloudsEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public CloudsEffect ()
EffectData = new CloudsData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/EdgeDetectEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public EdgeDetectEffect ()
EffectData = new EdgeDetectData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

public override void Render (ImageSurface src, ImageSurface dest, Core.RectangleI[] rois)
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/EmbossEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public EmbossEffect ()
EffectData = new EmbossData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/FragmentEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public FragmentEffect ()
EffectData = new FragmentData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/FrostedGlassEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public FrostedGlassEffect ()
EffectData = new FrostedGlassData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/GaussianBlurEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public GaussianBlurEffect ()
EffectData = new GaussianBlurData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/GlowEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public GlowEffect ()
screenBlendOp = new UserBlendOps.ScreenBlendOp ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/InkSketchEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ static InkSketchEffect ()
conv[4] = new int[] { -1, -1, -5, -1, -1 };
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/JuliaFractalEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public JuliaFractalEffect ()
EffectData = new JuliaFractalData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/MandelbrotFractalEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public MandelbrotFractalEffect ()
EffectData = new MandelbrotFractalData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/MedianEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public MedianEffect ()
EffectData = new MedianData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/MotionBlurEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public MotionBlurEffect ()
EffectData = new MotionBlurData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/OilPaintingEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public OilPaintingEffect ()
EffectData = new OilPaintingData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/OutlineEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public OutlineEffect ()
EffectData = new OutlineData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/PencilSketchEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public PencilSketchEffect ()
colorDodgeOp = new UserBlendOps.ColorDodgeBlendOp ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/PixelateEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public PixelateEffect ()
EffectData = new PixelateData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/RadialBlurEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public RadialBlurEffect ()
EffectData = new RadialBlurData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/RedEyeRemoveEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public RedEyeRemoveEffect ()
EffectData = new RedEyeRemoveData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
#if false // TODO-GTK4
using (var dialog = new SimpleEffectDialog (Name, PintaCore.Resources.GetIcon (Icon), Data, new PintaLocalizer ())) {
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/ReduceNoiseEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public ReduceNoiseEffect ()
EffectData = new ReduceNoiseData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

#region Algorithm Code Ported From PDN
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/ReliefEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public override string EffectMenuCategory {
get { return Translations.GetString ("Stylize"); }
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

public override string Icon {
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Effects/SharpenEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public SharpenEffect ()
EffectData = new SharpenData ();
}

public override bool LaunchConfiguration ()
public override void LaunchConfiguration ()
{
return EffectHelper.LaunchSimpleEffectDialog (this);
EffectHelper.LaunchSimpleEffectDialog (this);
}

public override void Render (ImageSurface src, ImageSurface dest, Core.RectangleI[] rois)
Expand Down
Loading

0 comments on commit ef0466d

Please sign in to comment.