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 on main branch #718

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
aab5b74
Create Pattern component to represent different fill types
AshishS-1123 Apr 18, 2022
d944b2a
Refactor existing code to use Pattern instead of component
AshishS-1123 Apr 18, 2022
0300364
Basic widgets for Editing gradients
AshishS-1123 Apr 18, 2022
11efd54
Use Cairo.Pattern for painting
AshishS-1123 Apr 19, 2022
1147247
Create Utility methods for handling patterns:
AshishS-1123 Apr 19, 2022
765b91a
Implement gradient editor. Modify pattern when mode is changed
AshishS-1123 Apr 20, 2022
bb29431
Refactor PatternTypeChooser
AshishS-1123 Apr 21, 2022
e6fef5e
Paint patterns on Canvas
AshishS-1123 Apr 21, 2022
56e653a
Draw nobs on canvas for gradients
AshishS-1123 Apr 23, 2022
61ef623
Fix position of gradients on canvas
AshishS-1123 Apr 23, 2022
938d48f
Move gradients and nobs and update corressponsing pattern
AshishS-1123 Apr 24, 2022
887a59b
Use selected pattern to draw the color button
AshishS-1123 Apr 25, 2022
7c84698
Use gradient editor to move stop colors on pattern component
AshishS-1123 Apr 25, 2022
9545486
Modify gradient stop color using color chooser
AshishS-1123 Apr 25, 2022
96f7f1e
Merge branch 'main' of github.com:AshishS-1123/Akira into gradient2_t…
AshishS-1123 Apr 25, 2022
705c24e
Use gradients for border of canvas item:
AshishS-1123 Apr 27, 2022
658c1ea
Prevent fill pattern from changing when border pattern modified.
AshishS-1123 Apr 27, 2022
5d52c22
Implement radial gradient
AshishS-1123 Apr 27, 2022
d42cb08
Save and load patterns from global colors
AshishS-1123 Apr 30, 2022
c55876a
Prvent weird color popover bug
AshishS-1123 Apr 30, 2022
df0fae0
Fix minor bug in gradient nobs
AshishS-1123 May 1, 2022
168a716
Fix some more silly mistakes
AshishS-1123 May 1, 2022
8a26b25
Merge branch 'main' of github.com:AshishS-1123/Akira into gradient2_t…
AshishS-1123 Aug 5, 2022
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
Prev Previous commit
Next Next commit
Prevent fill pattern from changing when border pattern modified.
  • Loading branch information
AshishS-1123 committed Apr 27, 2022
commit 658c1ea1d8578ac11786ae33b55df3df2d844330
8 changes: 1 addition & 7 deletions src/Layouts/BordersList/BorderItemModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class Akira.Layouts.BordersList.BorderItemModel : Models.ColorModel {
private unowned Lib.ViewCanvas _view_canvas;

private Lib.Items.ModelInstance _cached_instance;
// private Lib.Items.ModelInstance _cached_instance;

public int border_id;

Expand All @@ -39,12 +39,6 @@ public class Akira.Layouts.BordersList.BorderItemModel : Models.ColorModel {
var node = im.item_model.node_from_id (_cached_instance.id);
assert (node != null);

// var new_color = Lib.Components.Color.from_rgba (color, hidden);
// var new_borders = node.instance.components.borders.copy ();
// new_borders.replace (Lib.Components.Borders.Border (border_id, new_color));
// node.instance.components.borders = new_borders;

print("Pattern type %s\n", pattern.type.to_string ());
var new_pattern = pattern.copy ();
var new_borders = node.instance.components.borders.copy ();
var new_border = new_borders.border_from_id (border_id).with_replaced_pattern (new_pattern);
Expand Down
35 changes: 1 addition & 34 deletions src/Layouts/FillsList/FillItemModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class Akira.Layouts.FillsList.FillItemModel : Models.ColorModel {
private unowned Akira.Lib.ViewCanvas _view_canvas;

private Lib.Items.ModelInstance _cached_instance;
// private Lib.Items.ModelInstance _cached_instance;

public int fill_id;

Expand Down Expand Up @@ -62,39 +62,6 @@ public class Akira.Layouts.FillsList.FillItemModel : Models.ColorModel {
im.compile_model ();
}

public void move_pattern_position_by_delta (Utils.Nobs.Nob nob, Geometry.Point delta) {
Geometry.Point percent_delta = Geometry.Point (
delta.x * 100.0 / _cached_instance.components.size.width,
delta.y * 100.0 / _cached_instance.components.size.height
);

switch (nob) {
case Utils.Nobs.Nob.GRADIENT_START:
pattern.start = Geometry.Point (
pattern.start.x - percent_delta.x,
pattern.start.y - percent_delta.y
);
break;
case Utils.Nobs.Nob.GRADIENT_END:
pattern.end = Geometry.Point (
pattern.end.x - percent_delta.x,
pattern.end.y - percent_delta.y
);
break;
case Utils.Nobs.Nob.GRADIENT_RADIUS_START:
pattern.radius_start = pattern.radius_start + percent_delta.x;
break;
case Utils.Nobs.Nob.GRADIENT_RADIUS_END:
pattern.radius_end = pattern.radius_end + percent_delta.x;
break;
default:
break;
}

on_value_changed ();
value_changed ();
}

public FillItemModel (Lib.ViewCanvas view_canvas, Lib.Items.ModelNode node, int fill_id) {
update_node (node, fill_id);
_view_canvas = view_canvas;
Expand Down
1 change: 1 addition & 0 deletions src/Lib/Components/CompiledBorder.vala
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class Akira.Lib.Components.CompiledBorder : Copyable<CompiledBorder> {

// Set the new blended color.
// rgba_border = Utils.Color.blend_colors (rgba_border, borders.data[i].pattern.get_first_color ());
border_size = borders.data[i].size;
pattern_border = Utils.Pattern.create_pattern_with_converted_positions (borders.data[i].pattern, size, center);
has_colors = true;

Expand Down
34 changes: 34 additions & 0 deletions src/Models/ColorModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class Akira.Models.ColorModel : GLib.Object {
}

protected int block_signal = 0;
protected Lib.Items.ModelInstance _cached_instance;

// All three types of patterns will be stored here.
// Based on which type is active, update it.
Expand Down Expand Up @@ -127,6 +128,39 @@ public class Akira.Models.ColorModel : GLib.Object {
}
}

public void move_pattern_position_by_delta (Utils.Nobs.Nob nob, Geometry.Point delta) {
Geometry.Point percent_delta = Geometry.Point (
delta.x * 100.0 / _cached_instance.components.size.width,
delta.y * 100.0 / _cached_instance.components.size.height
);

switch (nob) {
case Utils.Nobs.Nob.GRADIENT_START:
pattern.start = Geometry.Point (
pattern.start.x - percent_delta.x,
pattern.start.y - percent_delta.y
);
break;
case Utils.Nobs.Nob.GRADIENT_END:
pattern.end = Geometry.Point (
pattern.end.x - percent_delta.x,
pattern.end.y - percent_delta.y
);
break;
case Utils.Nobs.Nob.GRADIENT_RADIUS_START:
pattern.radius_start = pattern.radius_start + percent_delta.x;
break;
case Utils.Nobs.Nob.GRADIENT_RADIUS_END:
pattern.radius_end = pattern.radius_end + percent_delta.x;
break;
default:
break;
}

on_value_changed ();
value_changed ();
}

public virtual void on_value_changed () {}
public virtual void delete () {}
}
15 changes: 7 additions & 8 deletions src/Widgets/PatternTypeChooser.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,24 @@ public class Akira.Widgets.PatternTypeChooser : Granite.Widgets.ModeButton {

// Connect signals.
this.mode_changed.connect ((window) => {
print("Mode changed\n");
var active_mode = (Lib.Components.Pattern.PatternType) this.selected;
print("Got active mode as %s\n", active_mode.to_string ());
print("Active pattern type is %s\n", model.active_pattern_type.to_string ());

model.active_pattern_type = active_mode;
print("Change active mode to %s\n", active_mode.to_string ());
pattern_changed (model.pattern);
print("Done signal\n");


handle_pattern_changed ();
print("Handled signal\n");
});

this.canvas = window.main_window.main_view_canvas.canvas;

window.event_bus.translate_gradient_nob_by_delta.connect ((nob, delta) => {
((Layouts.FillsList.FillItemModel) model).move_pattern_position_by_delta (nob, delta);
// This condition checks if this widget is currently open as there can be multiple instances
// if PatternTypeChooser present. And we don't want all of them to handle this signal.
if (!is_drawable ()) {
return;
}

model.move_pattern_position_by_delta (nob, delta);
handle_pattern_changed ();
});
}
Expand Down