Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linear and Radial Gradients feature on CanvasItems #621

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8d03b07
Added icons for ColorMode buttons
AshishS-1123 Jun 23, 2021
ab71732
Added icons are resources
AshishS-1123 Jun 23, 2021
3b9eb7f
Refactor ColorRow
AshishS-1123 Jun 23, 2021
86689d6
Added ColorMode widget.
AshishS-1123 Jun 23, 2021
d8a1d33
Added GradientEditor widget
AshishS-1123 Jun 23, 2021
ef4dd67
Updated meson.build to build ColorMode and GradientEditor
AshishS-1123 Jun 23, 2021
0f1eece
Added functionality to delete a stop color
AshishS-1123 Jun 23, 2021
508b617
Functionality to move StopColors using cursor
AshishS-1123 Jun 23, 2021
e326245
Bug fixes in moving StopColors
AshishS-1123 Jun 23, 2021
b05d96e
Accessibility fixes when interacting with StopColors
AshishS-1123 Jun 23, 2021
ee86fca
Displaying gradients in CanvasItem
AshishS-1123 Jun 23, 2021
06e30b2
Minor bugfixes related to delete button
AshishS-1123 Jun 23, 2021
5acc76b
Alpha values to StopColors
AshishS-1123 Jun 26, 2021
5051082
Use EventBus signals to change color and gradient
AshishS-1123 Jun 26, 2021
dd179c7
Create DirectionLine class and draw when color mode changes
AshishS-1123 Jun 29, 2021
114595d
Set initial position direction line
AshishS-1123 Jun 29, 2021
e14305c
Dynamic show/hide direction line based on selection
AshishS-1123 Jun 29, 2021
2b28f56
Drag nobs to change gradient direction
AshishS-1123 Jun 30, 2021
6ef1d36
Minor bug fix in Nobs
AshishS-1123 Jul 2, 2021
838b6d9
Disable gradients for borders
AshishS-1123 Jul 2, 2021
5ac7421
Fix Radial gradient positions
AshishS-1123 Jul 2, 2021
bbace66
Disable gradients for Border
AshishS-1123 Jul 2, 2021
3e3c1eb
Select Deselect crash fix
AshishS-1123 Jul 2, 2021
6fc6f70
Set initial position of direction line
AshishS-1123 Jul 2, 2021
7508cd8
Linting related fixes
AshishS-1123 Jul 2, 2021
068c29d
Merge branch 'master' of github.com:AshishS-1123/Akira into gradient_…
AshishS-1123 Jul 3, 2021
d9b9b39
Delete wrongly added hidden file
AshishS-1123 Jul 3, 2021
d0420bb
Load initial color mode from ColorModel
AshishS-1123 Jul 15, 2021
58ab966
Load Cairo.Pattern in ColorModel from Fill property
AshishS-1123 Jul 15, 2021
5b2a84c
Load pattern when item selected after deselection
AshishS-1123 Jul 16, 2021
a298597
Merge branch 'master' of github.com:akiraux/Akira into gradient_widget
AshishS-1123 Jul 16, 2021
7a2db2f
Load gradient direction for previously applied gradients
AshishS-1123 Jul 17, 2021
833835e
Change color picker color when stop color changes
AshishS-1123 Jul 17, 2021
7a27e86
Allow user to modify direction line with color chooser open
AshishS-1123 Jul 17, 2021
241fbce
Hide Gradient Editor based on color modes
AshishS-1123 Jul 18, 2021
cd678bc
Show gradient patterns on ColorButton
AshishS-1123 Jul 18, 2021
1835cb3
Linting fixes
AshishS-1123 Jul 18, 2021
8fcc69d
Merge branch 'master' into gradient_widget
AshishS-1123 Jul 21, 2021
90e9804
Merge branch 'master' into gradient_widget
Alecaddd Jul 25, 2021
999cdaf
Merge branch 'master' into gradient_widget
AshishS-1123 Aug 9, 2021
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
4 changes: 4 additions & 0 deletions data/assets.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@
<file alias="shape-triangle-symbolic.svg">icons/symbolic/shape-triangle-symbolic.svg</file>
<file alias="shape-circle-symbolic.svg">icons/symbolic/shape-circle-symbolic.svg</file>
<file alias="shape-text-symbolic.svg">icons/symbolic/shape-text-symbolic.svg</file>

<file alias="solid-color-button.svg">icons/hicolor/solid-color.svg</file>
<file alias="linear-gradient-button.svg">icons/hicolor/linear-gradient.svg</file>
<file alias="radial-gradient-button.svg">icons/hicolor/radial-gradient.svg</file>
</gresource>
</gresources>
1 change: 1 addition & 0 deletions data/icons/hicolor/linear-gradient.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/icons/hicolor/radial-gradient.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/icons/hicolor/solid-color.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/Lib/Components/Fill.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class Akira.Lib.Components.Fill : Component {
public int id { get; set; }

public Gdk.RGBA color { get; set; }
public Cairo.Pattern gradient_pattern { get; set; }
public string color_mode { get; set; default = "solid"; }

// Store the hexadecimal string version of the color (E.g.: #FF00CC)
public string hex { get; set; }
Expand All @@ -42,6 +44,7 @@ public class Akira.Lib.Components.Fill : Component {
color = init_color;
hex = color.to_string ();
alpha = 255;
gradient_pattern = new Cairo.Pattern.linear (0,0,0,0);

// Listen for changed to the fill attributes to properly trigger the color generation.
this.notify["color"].connect (() => {
Expand All @@ -59,6 +62,11 @@ public class Akira.Lib.Components.Fill : Component {
rgba.alpha = ((double) alpha) / 255;
color = rgba;
});

this.notify["gradient-pattern"].connect (() => {
fills.reload ();
});

}

public void remove () {
Expand Down
21 changes: 20 additions & 1 deletion src/Lib/Components/Fills.vala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Akira.Lib.Components.Fills : Component {
id++;

// Trigger the generation of the fill color.
reload ();
reload ();

return new_fill;
}
Expand All @@ -68,8 +68,10 @@ public class Akira.Lib.Components.Fills : Component {
if (count () == 0) {
if (item is Items.CanvasArtboard) {
((Items.CanvasArtboard) item).background.set ("fill-color-rgba", null);
((Items.CanvasArtboard) item).background.set ("fill-pattern", null);
} else {
item.set ("fill-color-rgba", null);
item.set ("fill-pattern", null);
}
return;
}
Expand All @@ -86,6 +88,23 @@ public class Akira.Lib.Components.Fills : Component {
continue;
}

var stop_colors = 0;
fill.gradient_pattern.get_color_stop_count (out stop_colors);

// if for this fill, either of the gradient modes have been selected,
// the stop_colors value would not be zero.
if (stop_colors != 0 && has_colors == false) {
if (item is Items.CanvasArtboard) {
((Items.CanvasArtboard) item).background.set ("fill-pattern", fill.gradient_pattern);
} else {
item.set ("fill-pattern", fill.gradient_pattern);
double x0, y0, x1, y1;
fill.gradient_pattern.get_linear_points (out x0, out y0, out x1, out y1);
}

// since we dont have the functionality of blending gradients,
return;
}
// Set the new blended color.
rgba_fill = Utils.Color.blend_colors (rgba_fill, fill.color);
has_colors = true;
Expand Down
4 changes: 3 additions & 1 deletion src/Lib/Managers/NobManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public class Akira.Lib.Managers.NobManager : Object {
BOTTOM_CENTER,
BOTTOM_LEFT,
LEFT_CENTER,
ROTATE
ROTATE,
GRADIENT_START,
GRADIENT_END
}

/*
Expand Down
4 changes: 3 additions & 1 deletion src/Lib/Selection/Nob.vala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public class Akira.Lib.Selection.Nob : Goo.CanvasRect {

update_state (Cairo.Matrix.identity (), 0, 0, false);

if (handle_id == Managers.NobManager.Nob.ROTATE) {
if (handle_id == Managers.NobManager.Nob.ROTATE ||
handle_id == Managers.NobManager.Nob.GRADIENT_START ||
handle_id == Managers.NobManager.Nob.GRADIENT_END) {
set ("radius-x", nob_size);
set ("radius-y", nob_size);
}
Expand Down
42 changes: 42 additions & 0 deletions src/Models/ColorModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ public class Akira.Models.ColorModel : GLib.Object {
BORDER
}

public string color_mode {
get {
return type == Type.FILL ? fill.color_mode : "solid";
}
set {
if (type == Type.FILL) {
fill.color_mode = value;
}
}
}

public Cairo.Pattern pattern {
owned get {
return type == Type.FILL ? fill.gradient_pattern : new Cairo.Pattern.linear (0,0,0,0);
}
set {
if (type == Type.FILL) {
fill.set ("gradient-pattern", value);
}
}
}

public string fill_css { get; set; }

public string color {
owned get {
return type == Type.FILL ? fill.color.to_string () : border.color.to_string ();
Expand Down Expand Up @@ -84,9 +108,27 @@ public class Akira.Models.ColorModel : GLib.Object {
}
}

public double width {
get {
double width;
fill.item.size.get ("width", out width);
return width;
}
}

public double height {
get {
double height;
fill.item.get ("height", out height);
return height;
}
}

public ColorModel (Lib.Components.Fill? fill, Lib.Components.Border? border = null) {
type = fill != null ? Type.FILL : Type.BORDER;
this.fill = fill;
this.border = border;

fill_css = "@bg_color";
}
}
7 changes: 7 additions & 0 deletions src/Services/EventBus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public class Akira.Services.EventBus : Object {
public signal void update_snaps_color ();
public signal void update_snap_decorators ();

// this signal will be triggered every time color gets modified
public signal void color_changed (string color, double alpha);
public signal void color_mode_changed (string color_mode);
// this signal is used to change color in ColorChooserWidget when new stop color selected
public signal void change_editor_color (Gdk.RGBA color);
public signal void color_chooser_popdown ();

// Options panel signals.
public signal void align_items (string align_action);
public signal void init_state_coords ();
Expand Down
120 changes: 120 additions & 0 deletions src/Widgets/ColorMode.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Copyright (c) 2021 Alecaddd (https://alecaddd.com)
*
* This file is part of Akira.
*
* Akira is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Akira is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Akira. If not, see <https://www.gnu.org/licenses/>.
*
* Authored by: Ashish Shevale <shevaleashish@gmail.com>
*/
public class Akira.Widgets.ColorMode {
// these buttons will be used to switch between different coloring modes
private Gtk.Button solid_color_button;
private Gtk.Button linear_gradient_button;
private Gtk.Button radial_gradient_button;
// this button will be be used to delete the selected gradient step
private Gtk.Button delete_step_button;

private GradientEditor gradient_editor;
public string color_mode_type;

public Gtk.Grid buttons_grid;
private unowned Models.ColorModel model;
private unowned Window window;

public ColorMode (Models.ColorModel _model, Window _window) {
model = _model;
color_mode_type = model.color_mode;
window = _window;

init_button_ui ();
}

private void init_button_ui () {

solid_color_button = new Gtk.Button.from_icon_name ("solid-color-button", Gtk.IconSize.DND);
solid_color_button.set_tooltip_text (_("Solid Color"));
solid_color_button.can_focus = false;
solid_color_button.valign = Gtk.Align.CENTER;

linear_gradient_button = new Gtk.Button.from_icon_name ("linear-gradient-button", Gtk.IconSize.DND);
linear_gradient_button.set_tooltip_text (_("Linear Gradient"));
linear_gradient_button.can_focus = false;
linear_gradient_button.valign = Gtk.Align.CENTER;

radial_gradient_button = new Gtk.Button.from_icon_name ("radial-gradient-button", Gtk.IconSize.DND);
radial_gradient_button.set_tooltip_text (_("Radial Gradient"));
radial_gradient_button.can_focus = false;
radial_gradient_button.valign = Gtk.Align.CENTER;

delete_step_button = new Gtk.Button.from_icon_name ("user-trash-symbolic");
delete_step_button.set_tooltip_text (_("Delete Gradient Step"));
delete_step_button.can_focus = false;
delete_step_button.valign = Gtk.Align.CENTER;
delete_step_button.halign = Gtk.Align.CENTER;
delete_step_button.margin = 10;

solid_color_button.clicked.connect ( () => mode_button_pressed ("solid"));
linear_gradient_button.clicked.connect ( () => mode_button_pressed ("linear"));
radial_gradient_button.clicked.connect ( () => mode_button_pressed ("radial"));
delete_step_button.clicked.connect (on_delete_button_pressed);

gradient_editor = new GradientEditor (window, model, model.pattern);

mode_button_pressed (color_mode_type);

delete_step_button.size_allocate.connect ( () => {
if (color_mode_type == "solid") {
delete_step_button.visible = false;
}
});
// since color modes on border havent been implmented yet, disable these buttons
if (model.type == Akira.Models.ColorModel.Type.BORDER) {
solid_color_button.sensitive = false;
linear_gradient_button.sensitive = false;
radial_gradient_button.sensitive = false;
delete_step_button.sensitive = false;
}

Gtk.Separator separator = new Gtk.Separator (Gtk.Orientation.VERTICAL);
separator.hexpand = true;

buttons_grid = new Gtk.Grid ();
buttons_grid.attach (solid_color_button, 0, 0);
buttons_grid.attach (linear_gradient_button, 1, 0);
buttons_grid.attach (radial_gradient_button, 2, 0);
buttons_grid.attach (separator, 3, 0);

buttons_grid.attach (gradient_editor, 0, 1, 4, 1);
buttons_grid.attach (delete_step_button, 4, 1);
}

private void mode_button_pressed (string _color_mode_type) {
if (_color_mode_type == "solid") {
delete_step_button.visible = false;
} else {
delete_step_button.visible = true;
}
color_mode_type = _color_mode_type;
model.color_mode = color_mode_type;
window.event_bus.color_mode_changed (color_mode_type);
}

private void on_delete_button_pressed () {
if (color_mode_type != "solid") {
gradient_editor.delete_selected_step ();
}
}

}
Loading