[ease] [editor] Added gradient angle support.
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease] [editor] Added gradient angle support.
- Date: Tue, 27 Jul 2010 01:54:40 +0000 (UTC)
commit 89ce738c24541cfce9ef9d5a508a3f933f1138d2
Author: Nate Stedman <natesm gmail com>
Date: Mon Jul 26 21:54:20 2010 -0400
[editor] Added gradient angle support.
data/ui/inspector-slide.ui | 3 ++-
src/ease-gradient.vala | 23 ++++++++++++++++-------
src/ease-inspector-slide-pane.vala | 21 +++++++++++++++++++++
3 files changed, 39 insertions(+), 8 deletions(-)
---
diff --git a/data/ui/inspector-slide.ui b/data/ui/inspector-slide.ui
index cf0a756..92efe38 100644
--- a/data/ui/inspector-slide.ui
+++ b/data/ui/inspector-slide.ui
@@ -239,8 +239,10 @@
<object class="GtkHScale" id="hscale-angle">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="update_policy">discontinuous</property>
<property name="adjustment">adjustment-angle</property>
<property name="draw_value">False</property>
+ <signal name="value_changed" handler="ease_inspector_slide_pane_on_set_angle"/>
</object>
<packing>
<property name="position">1</property>
@@ -310,6 +312,5 @@
<property name="upper">6.2800000000000002</property>
<property name="step_increment">0.10000000000000001</property>
<property name="page_increment">1</property>
- <property name="page_size">1</property>
</object>
</interface>
diff --git a/src/ease-gradient.vala b/src/ease-gradient.vala
index 3ddb1aa..4395e37 100644
--- a/src/ease-gradient.vala
+++ b/src/ease-gradient.vala
@@ -23,7 +23,7 @@ public class Ease.Gradient : GLib.Object
/**
* The format string for converting gradients to strings.
*/
- private const string STR = "%s%s%s%s%s%s";
+ private const string STR = "%s|%s|%s|%f";
/**
* The string placed between each color in a string representation.
@@ -153,10 +153,8 @@ public class Ease.Gradient : GLib.Object
*/
public string to_string()
{
- return STR.printf(start.to_string(), SPLIT,
- end.to_string(), SPLIT,
- mode.to_string(), SPLIT,
- angle.to_string());
+ return STR.printf(start.to_string(), end.to_string(),
+ mode.to_string(), angle);
}
/**
@@ -192,18 +190,29 @@ public class Ease.Gradient : GLib.Object
cr.save();
cr.rectangle(0, 0, width, height);
+ var x_orig = width / 2;
+ var y_orig = height / 2;
+ var dist_x = (int)(Math.cos(angle + Math.PI / 2) * y_orig);
+ var dist_y = (int)(Math.sin(angle + Math.PI / 2) * y_orig);
+
Cairo.Pattern pattern;
switch (mode)
{
case GradientType.LINEAR:
- pattern = new Cairo.Pattern.linear(0, 0, 0, height);
+ pattern = new Cairo.Pattern.linear(x_orig - dist_x,
+ y_orig - dist_y,
+ x_orig + dist_x,
+ y_orig + dist_y);
pattern.add_color_stop_rgba(0, start.red, start.green,
start.blue, start.alpha);
pattern.add_color_stop_rgba(1, end.red, end.green,
end.blue, end.alpha);
break;
case GradientType.LINEAR_MIRRORED:
- pattern = new Cairo.Pattern.linear(0, 0, 0, height);
+ pattern = new Cairo.Pattern.linear(x_orig - dist_x,
+ y_orig - dist_y,
+ x_orig + dist_x,
+ y_orig + dist_y);
pattern.add_color_stop_rgba(0, start.red, start.green,
start.blue, start.alpha);
pattern.add_color_stop_rgba(0.5, end.red, end.green,
diff --git a/src/ease-inspector-slide-pane.vala b/src/ease-inspector-slide-pane.vala
index 188f77f..abb333b 100644
--- a/src/ease-inspector-slide-pane.vala
+++ b/src/ease-inspector-slide-pane.vala
@@ -30,6 +30,7 @@ public class Ease.InspectorSlidePane : InspectorPane
private Gtk.VBox box_color;
private Gtk.VBox box_gradient;
private Gtk.VBox box_image;
+ private Gtk.HScale grad_angle;
private Gtk.ColorButton bg_color;
private Gtk.ColorButton grad_color1;
@@ -70,6 +71,7 @@ public class Ease.InspectorSlidePane : InspectorPane
builder.get_object("button-image") as Gtk.FileChooserButton;
gradient_type =
builder.get_object("combo-gradient") as Gtk.ComboBox;
+ grad_angle = builder.get_object("hscale-angle") as Gtk.HScale;
// set up the gradient type combobox
gradient_type.model = grad_store;
@@ -268,6 +270,23 @@ public class Ease.InspectorSlidePane : InspectorPane
emit_undo(action);
}
+ [CCode (instance_pos = -1)]
+ public void on_set_angle(Gtk.Widget? sender)
+ {
+ var action = new UndoAction(slide.background_gradient, "angle");
+ slide.background_gradient.angle =
+ (sender as Gtk.HScale).adjustment.value;
+ undo(action);
+
+ slide.changed(slide);
+
+ var local = slide;
+ action.applied.connect((a) => {
+ local.changed(local);
+ if (local == slide) display_bg_ui(slide.background_type);
+ });
+ }
+
protected override void slide_updated()
{
silence_undo = true;
@@ -323,6 +342,8 @@ public class Ease.InspectorSlidePane : InspectorPane
grad_color1.set_color(slide.background_gradient.start.gdk);
grad_color2.set_color(slide.background_gradient.end.gdk);
+ grad_angle.adjustment.value = slide.background_gradient.angle;
+
slide.changed(slide);
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]