Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1bd3534
Created color control for `SimpleEffectDialog`
Lehonti Jul 10, 2025
fc30ba7
Using Mandelbrot fractal as demo for new controls
Lehonti Jul 10, 2025
f8f7e2c
Revert "Using Mandelbrot fractal as demo for new controls"
Lehonti Jul 10, 2025
cbffea6
Update CHANGELOG.md
Lehonti Jul 10, 2025
3007430
Merge branch 'PintaProject:master' into feature/simpleeffectdialog_color
Lehonti Jul 11, 2025
9629c35
Using `ColorDialogButton`
Lehonti Jul 11, 2025
fb65691
Conversion between unpremultiplied and premultiplied alpha in `Create…
Lehonti Jul 11, 2025
f4d8a95
Button not occupying the whole space
Lehonti Jul 11, 2025
68af25a
New constant
Lehonti Jul 12, 2025
8fdb76a
Revert
Lehonti Jul 12, 2025
69ddc70
Moved color conversions to extension methods
Lehonti Jul 14, 2025
ada6019
Merge branch 'PintaProject:master' into feature/simpleeffectdialog_color
Lehonti Jul 14, 2025
a6067c9
Removed obsolete comment
Lehonti Jul 14, 2025
d633bbb
Merge branch 'PintaProject:master' into feature/simpleeffectdialog_color
Lehonti Jul 15, 2025
3207202
Moved extensions to `GdkExtensions`
Lehonti Jul 15, 2025
030241f
Merge branch 'PintaProject:master' into feature/simpleeffectdialog_color
Lehonti Jul 16, 2025
b821418
Custom color button
Lehonti Jul 17, 2025
1e3ce7c
demo
Lehonti Jul 17, 2025
e83844a
Revert "demo"
Lehonti Jul 17, 2025
890ea1f
Color picker dialog opens with current selection
Lehonti Jul 17, 2025
ba005aa
demo
Lehonti Jul 17, 2025
a5f27df
Revert "demo"
Lehonti Jul 17, 2025
28eb3b8
Used exising transparent pattern creation
Lehonti Jul 20, 2025
4ba7e0f
More concise code for setting source color
Lehonti Jul 20, 2025
47f41d7
Taking into account premultiplied vs. straight alpha
Lehonti Jul 20, 2025
6c9652f
demo
Lehonti Jul 20, 2025
9e4d0c1
Revert "demo"
Lehonti Jul 20, 2025
99f617e
Merge branch 'PintaProject:master' into feature/simpleeffectdialog_color
Lehonti Jul 21, 2025
5a790ae
Removing support for `ColorBgra`
Lehonti Jul 21, 2025
2d32978
demo
Lehonti Jul 21, 2025
06a757c
Revert "demo"
Lehonti Jul 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Thanks to the following contributors who worked on this release:
- Added a right click menu for layers, containing actions that can be applied to the selected layer (#1588)
- The Dithering effect can now use Pinta's current palette in addition to the effect's preset color palettes (#1594)
- Random seed values for effects can now be directly controlled, in addition to use the Reseed button (#1592, #1591)
- Support for color picking in `SimpleEffectDialog`. Useful for add-in developers (#1611)

### Changed
- Updated dependencies to require GTK 4.18+ and libadwaita 1.7+
Expand Down
61 changes: 61 additions & 0 deletions Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Cairo;
using Mono.Addins.Localization;
using Pinta.Core;

Expand Down Expand Up @@ -242,6 +243,8 @@ static IEnumerable<char> GenerateCharacters (string name)
return CreatePointPicker;
else if (memberType == typeof (CenterOffset<double>))
return CreateOffsetPicker;
else if (memberType == typeof (Color))
return CreateCairoColorPicker;
else if (memberType.IsEnum)
return CreateEnumComboBox;
else
Expand All @@ -254,6 +257,64 @@ private delegate Gtk.Widget WidgetFactory (
MemberSettings settings,
IWorkspaceService workspace);

private Gtk.Widget CreateCairoColorPicker (
string caption,
EffectData effectData,
MemberSettings settings,
IWorkspaceService workspace)
{
Color currentColorCairo =
(settings.reflector.GetValue (effectData) is Color c)
? c
: Color.Black;

PintaColorButton colorButton = new () {
DisplayColor = currentColorCairo,
Hexpand = false,
Halign = Gtk.Align.Start,
WidthRequest = 80,
};

colorButton.OnClicked += async (_, _) => {

using ColorPickerDialog dialog = new (
this,
PintaCore.Palette,
new SingleColor (currentColorCairo),
primarySelected: true,
false,
Translations.GetString ("Choose Color"));

try {
Gtk.ResponseType response = await dialog.RunAsync ();

if (response != Gtk.ResponseType.Ok)
return;

var pick = (SingleColor) dialog.Colors;

Color newColorCairo = pick.Color;

colorButton.DisplayColor = newColorCairo;
currentColorCairo = newColorCairo;

SetAndNotify (settings.reflector, effectData, newColorCairo);
} finally {
dialog.Destroy ();
}
};

Gtk.Label label = Gtk.Label.New (caption);
label.Halign = Gtk.Align.Start;
label.AddCssClass (AdwaitaStyles.Title4);

Gtk.Box combinedWidget = Gtk.Box.New (Gtk.Orientation.Vertical, 6);
combinedWidget.Append (label);
combinedWidget.Append (colorButton);

return combinedWidget;
}

private ComboBoxWidget CreateEnumComboBox (
string caption,
EffectData effectData,
Expand Down
48 changes: 48 additions & 0 deletions Pinta.Gui.Widgets/Widgets/PintaColorButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Cairo;
using Pinta.Core;

namespace Pinta.Gui.Widgets;

internal sealed class PintaColorButton : Gtk.Button
{
private Color display_color = Color.Black;
public Color DisplayColor {
get => display_color;
set {
if (display_color == value) return;
display_color = value;
color_drawing_area.QueueDraw ();
}
}

private readonly Gtk.DrawingArea color_drawing_area;
internal PintaColorButton ()
{
Gtk.DrawingArea colorDrawingArea = new () {
Hexpand = true,
Vexpand = true,
};
colorDrawingArea.SetDrawFunc (OnDraw);
SetChild (colorDrawingArea);
color_drawing_area = colorDrawingArea;
}

private void OnDraw (
Gtk.DrawingArea drawingArea,
Context cr,
int width,
int height)
{
const int TILE_SIZE = 16;

using Pattern checkeredPattern =
CairoExtensions.CreateTransparentBackgroundPattern (TILE_SIZE);

cr.SetSource (checkeredPattern);
cr.Paint ();

cr.SetSourceColor (display_color);
cr.Rectangle (0, 0, width, height);
cr.Fill ();
}
}
Loading