Skip to content

Commit

Permalink
Move all the adjustments to a separate assembly. Move most of the wid…
Browse files Browse the repository at this point in the history
…gets to Pinta.Gui.Widgets.
  • Loading branch information
jpobst committed May 14, 2010
1 parent cc759e0 commit 191078d
Show file tree
Hide file tree
Showing 50 changed files with 2,684 additions and 2,896 deletions.
164 changes: 3 additions & 161 deletions Pinta.Core/Actions/AdjustmentsActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,175 +33,17 @@ namespace Pinta.Core
{
public class AdjustmentsActions
{
public Gtk.Action AutoLevel { get; private set; }
public Gtk.Action BlackAndWhite { get; private set; }
public Gtk.Action BrightnessContrast { get; private set; }
public Gtk.Action Curves { get; private set; }
public Gtk.Action HueSaturation { get; private set; }
public Gtk.Action InvertColors { get; private set; }
public Gtk.Action Levels { get; private set; }
public Gtk.Action Posterize { get; private set; }
public Gtk.Action Sepia { get; private set; }

public List<Gtk.Action> Actions { get; private set; }

public AdjustmentsActions ()
{
Gtk.IconFactory fact = new Gtk.IconFactory ();
fact.Add ("Menu.Adjustments.AutoLevel.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("Menu.Adjustments.AutoLevel.png")));
fact.Add ("Menu.Adjustments.BlackAndWhite.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("Menu.Adjustments.BlackAndWhite.png")));
fact.Add ("Menu.Adjustments.BrightnessAndContrast.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("Menu.Adjustments.BrightnessAndContrast.png")));
fact.Add ("Menu.Adjustments.Curves.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("Menu.Adjustments.Curves.png")));
fact.Add ("Menu.Adjustments.HueAndSaturation.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("Menu.Adjustments.HueAndSaturation.png")));
fact.Add ("Menu.Adjustments.InvertColors.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("Menu.Adjustments.InvertColors.png")));
fact.Add ("Menu.Adjustments.Levels.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("Menu.Adjustments.Levels.png")));
fact.Add ("Menu.Adjustments.Posterize.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("Menu.Adjustments.Posterize.png")));
fact.Add ("Menu.Adjustments.Sepia.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("Menu.Adjustments.Sepia.png")));
fact.AddDefault ();

AutoLevel = new Gtk.Action ("AutoLevel", Mono.Unix.Catalog.GetString ("Auto Level"), null, "Menu.Adjustments.AutoLevel.png");
BlackAndWhite = new Gtk.Action ("BlackAndWhite", Mono.Unix.Catalog.GetString ("Black and White"), null, "Menu.Adjustments.BlackAndWhite.png");
BrightnessContrast = new Gtk.Action ("BrightnessContrast", Mono.Unix.Catalog.GetString ("Brightness / Contrast..."), null, "Menu.Adjustments.BrightnessAndContrast.png");
Curves = new Gtk.Action ("Curves", Mono.Unix.Catalog.GetString ("Curves..."), null, "Menu.Adjustments.Curves.png");
HueSaturation = new Gtk.Action ("HueSaturation", Mono.Unix.Catalog.GetString ("Hue / Saturation..."), null, "Menu.Adjustments.HueAndSaturation.png");
InvertColors = new Gtk.Action ("InvertColors", Mono.Unix.Catalog.GetString ("Invert Colors"), null, "Menu.Adjustments.InvertColors.png");
Levels = new Gtk.Action ("Levels", Mono.Unix.Catalog.GetString ("Levels..."), null, "Menu.Adjustments.Levels.png");
Posterize = new Gtk.Action ("Posterize", Mono.Unix.Catalog.GetString ("Posterize..."), null, "Menu.Adjustments.Posterize.png");
Sepia = new Gtk.Action ("Sepia", Mono.Unix.Catalog.GetString ("Sepia"), null, "Menu.Adjustments.Sepia.png");
Actions = new List<Gtk.Action> ();
}

#region Initialization
public void CreateMainMenu (Gtk.Menu menu)
{
menu.Remove (menu.Children[1]);

menu.Append (AutoLevel.CreateAcceleratedMenuItem (Gdk.Key.L, Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask));
menu.Append (BlackAndWhite.CreateAcceleratedMenuItem (Gdk.Key.G, Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask));
menu.Append (BrightnessContrast.CreateAcceleratedMenuItem (Gdk.Key.C, Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask));
menu.Append (Curves.CreateAcceleratedMenuItem (Gdk.Key.M, Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask));
menu.Append (HueSaturation.CreateAcceleratedMenuItem (Gdk.Key.U, Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask));
menu.Append (InvertColors.CreateAcceleratedMenuItem (Gdk.Key.I, Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask));
menu.Append (Levels.CreateAcceleratedMenuItem (Gdk.Key.L, Gdk.ModifierType.ControlMask));
menu.Append (Posterize.CreateAcceleratedMenuItem (Gdk.Key.P, Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask));
menu.Append (Sepia.CreateAcceleratedMenuItem (Gdk.Key.E, Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask));
}

public void RegisterHandlers ()
{
Sepia.Activated += HandleAdjustmentActivated <SepiaEffect>;
InvertColors.Activated += HandleAdjustmentActivated <InvertColorsEffect>;
BlackAndWhite.Activated += HandleAdjustmentActivated <BlackAndWhiteEffect>;
AutoLevel.Activated += HandleAdjustmentActivated <AutoLevelEffect>;
}
#endregion

#region Action Handlers
private void HandleAdjustmentActivated<T> (object sender, EventArgs e)
where T : BaseEffect, new ()
{
var effect = new T ();
PintaCore.LivePreview.Start (effect);
}
#endregion

#region Public Methods
public bool PerformEffect (BaseEffect effect)
{
PintaCore.Layers.FinishSelection ();

if (effect.IsConfigurable) {
bool result = effect.LaunchConfiguration ();

if (!result)
return false;
}

SimpleHistoryItem hist = new SimpleHistoryItem (effect.Icon, effect.Text);
hist.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayerIndex);

// Use the existing ToolLayer instead of creating a new temp layer
Layer tmp_layer = PintaCore.Layers.ToolLayer;
tmp_layer.Clear ();

ImageSurface dest = tmp_layer.Surface;

Gdk.Rectangle roi = PintaCore.Layers.SelectionPath.GetBounds ();
roi = PintaCore.Workspace.ClampToImageSize (roi);

if (PintaCore.System.RenderThreads <= 1) {
effect.RenderEffect (PintaCore.Layers.CurrentLayer.Surface, dest, new Gdk.Rectangle[] { roi });
} else {
List<Thread> threads = new List<Thread> ();

foreach (Gdk.Rectangle rect in SplitRectangle (roi, PintaCore.System.RenderThreads)) {
Thread t = new Thread (new ParameterizedThreadStart (ParallelRender));
t.Start (new StateInfo (PintaCore.Layers.CurrentLayer.Surface, dest, effect, rect));
threads.Add (t);
}

foreach (Thread t in threads)
t.Join ();
}

using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) {
g.AppendPath (PintaCore.Layers.SelectionPath);
g.FillRule = FillRule.EvenOdd;
g.Clip ();

g.SetSource (dest);
g.Paint ();
}

PintaCore.Workspace.Invalidate ();
PintaCore.History.PushNewItem (hist);

return true;
}
#endregion

#region Private Methods
private void ParallelRender (object stateInfo)
{
StateInfo si = (StateInfo)stateInfo;
si.Effect.RenderEffect (si.Source, si.Destination, new Gdk.Rectangle[] { si.Area });
}

// Split region of interest rectangle into multiple rectangles
// to facilitate multi-threaded effects. We use horizontal rectangles
// for linear memory access
private Gdk.Rectangle[] SplitRectangle (Gdk.Rectangle roi, int num)
{
if (num < 2)
return new Gdk.Rectangle[] { roi };

List<Gdk.Rectangle> rects = new List<Gdk.Rectangle> ();

int height = roi.Height / num;
int total_height = roi.Height;

for (int i = 0; i < num - 1; i++) {
rects.Add (new Gdk.Rectangle (roi.X, i * height + roi.Top, roi.Width, height));
total_height -= height;
}

// Add any remaining height to the last rectangle
rects.Add (new Gdk.Rectangle (roi.X, (num - 1) * height + roi.Top, roi.Width, total_height));

return rects.ToArray ();
}

private class StateInfo
{
public ImageSurface Source { get; set; }
public ImageSurface Destination { get; set; }
public BaseEffect Effect { get; set; }
public Gdk.Rectangle Area { get; set; }

public StateInfo (ImageSurface src, ImageSurface dest, BaseEffect effect, Gdk.Rectangle roi)
{
Source = src;
Destination = dest;
Effect = effect;
Area = roi;
}
}
#endregion
}
Expand Down
4 changes: 4 additions & 0 deletions Pinta.Core/Effects/BaseEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public abstract class BaseEffect
public abstract string Text { get; }
public virtual bool IsConfigurable { get { return false; } }
public EffectData EffectData { get; protected set; }
public virtual EffectAdjustment EffectOrAdjustment { get { return EffectAdjustment.Effect; } }
public virtual int Priority { get { return 50; } }
public virtual Gdk.Key AdjustmentMenuKey { get { return Gdk.Key.Escape; } }
public virtual Gdk.ModifierType AdjustmentMenuKeyModifiers { get { return Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask; } }

// Return true to perform effect, false to cancel effect
public virtual bool LaunchConfiguration ()
Expand Down
36 changes: 36 additions & 0 deletions Pinta.Core/Enumerations/EffectAdjustment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// EffectAdjustment.cs
//
// Author:
// Jonathan Pobst <[email protected]>
//
// Copyright (c) 2010 Jonathan Pobst
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;

namespace Pinta.Core
{
public enum EffectAdjustment
{
Effect,
Adjustment
}
}
31 changes: 27 additions & 4 deletions Pinta.Core/Enumerations/GradientColorMode.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//
// GradientColorMode.cs
//
// Author:
// Jonathan Pobst <[email protected]>
//
// Copyright (c) 2010 Jonathan Pobst
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;

namespace Pinta.Core
{
Expand Down
1 change: 0 additions & 1 deletion Pinta.Core/Managers/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public void RegisterHandlers ()
Image.RegisterHandlers ();
Layers.RegisterHandlers ();
View.RegisterHandlers ();
Adjustments.RegisterHandlers ();
Help.RegisterHandlers ();
}
}
Expand Down
5 changes: 1 addition & 4 deletions Pinta.Core/Pinta.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,19 @@
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Classes\Anchor.cs" />
<Compile Include="Classes\ScaleFactor.cs" />
<Compile Include="Effects\AutoLevelEffect.cs" />
<Compile Include="Effects\BaseEffect.cs" />
<Compile Include="Effects\BinaryPixelOp.cs" />
<Compile Include="Effects\BitVector2DSurfaceAdapter.cs" />
<Compile Include="Effects\BlackAndWhiteEffect.cs" />
<Compile Include="Effects\Histogram.cs" />
<Compile Include="Effects\HistogramRGB.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Effects\IBitVector2D.cs" />
<Compile Include="Effects\InvertColorsEffect.cs" />
<Compile Include="Effects\Scanline.cs" />
<Compile Include="Effects\SepiaEffect.cs" />
<Compile Include="Effects\UserBlendOp.cs" />
<Compile Include="Effects\UserBlendOps.cs" />
<Compile Include="Effects\UserBlendOps.Generated.cs" />
<Compile Include="Enumerations\EffectAdjustment.cs" />
<Compile Include="Enumerations\GradientColorMode.cs" />
<Compile Include="EventArgs\CanvasInvalidatedEventArgs.cs" />
<Compile Include="EventArgs\HistoryItemAddedEventArgs.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

using System;
using Cairo;
using Pinta.Core;

namespace Pinta.Core
namespace Pinta.Effects
{
[System.ComponentModel.Composition.Export (typeof (BaseEffect))]
public class AutoLevelEffect : BaseEffect
{
UnaryPixelOps.Level op;
Expand All @@ -24,6 +26,18 @@ public override string Text {
get { return Mono.Unix.Catalog.GetString ("Auto Level"); }
}

public override EffectAdjustment EffectOrAdjustment {
get { return EffectAdjustment.Adjustment; }
}

public override int Priority {
get { return 5; }
}

public override Gdk.Key AdjustmentMenuKey {
get { return Gdk.Key.L; }
}

public override void RenderEffect (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
{
HistogramRgb histogram = new HistogramRgb ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

using System;
using Cairo;
using Pinta.Core;

namespace Pinta.Core
namespace Pinta.Effects
{
[System.ComponentModel.Composition.Export (typeof (BaseEffect))]
public class BlackAndWhiteEffect : BaseEffect
{
UnaryPixelOp op = new UnaryPixelOps.Desaturate ();
Expand All @@ -23,6 +25,18 @@ public override string Icon {
public override string Text {
get { return Mono.Unix.Catalog.GetString ("Black and White"); }
}

public override EffectAdjustment EffectOrAdjustment {
get { return EffectAdjustment.Adjustment; }
}

public override int Priority {
get { return 10; }
}

public override Gdk.Key AdjustmentMenuKey {
get { return Gdk.Key.L; }
}

public override void RenderEffect (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
using System;
using Cairo;
using Pinta.Gui.Widgets;
using Pinta.Core;

namespace Pinta.Core
namespace Pinta.Effects
{
[System.ComponentModel.Composition.Export (typeof (BaseEffect))]
public class BrightnessContrastEffect : BaseEffect
{
private int multiply;
Expand All @@ -31,6 +33,18 @@ public override bool IsConfigurable {
get { return true; }
}

public override EffectAdjustment EffectOrAdjustment {
get { return EffectAdjustment.Adjustment; }
}

public override int Priority {
get { return 15; }
}

public override Gdk.Key AdjustmentMenuKey {
get { return Gdk.Key.C; }
}

public BrightnessContrastData Data { get { return EffectData as BrightnessContrastData; } }

public BrightnessContrastEffect ()
Expand Down
Loading

0 comments on commit 191078d

Please sign in to comment.