[ease] Added color selection for text.
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease] Added color selection for text.
- Date: Thu, 24 Jun 2010 17:33:40 +0000 (UTC)
commit 7c307e4b8ead965d1770ba086e705a50e44247db
Author: Nate Stedman <natesm gmail com>
Date: Thu Jun 24 13:01:59 2010 -0400
Added color selection for text.
Makefile.am | 1 +
src/ease-editor-embed.vala | 14 ++++++++++-
src/ease-editor-window.vala | 54 +++++++++++++++++++++++++++++++++++++++++
src/ease-element.vala | 22 ++++++++++++++++
src/ease-text-actor.vala | 5 ++++
src/ease-text-element.vala | 26 ++++++++++++++++---
src/ease-transformations.vala | 52 +++++++++++++++++++++++++++++++++++++++
7 files changed, 169 insertions(+), 5 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 69d7d78..5a29d2e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -46,6 +46,7 @@ ease_SOURCES = \
src/ease-text-actor.vala \
src/ease-text-element.vala \
src/ease-theme.vala \
+ src/ease-transformations.vala \
src/ease-transition-pane.vala \
src/ease-transitions.vala \
src/ease-undo-actions.vala \
diff --git a/src/ease-editor-embed.vala b/src/ease-editor-embed.vala
index 19dd2a0..6b7e7b5 100644
--- a/src/ease-editor-embed.vala
+++ b/src/ease-editor-embed.vala
@@ -52,7 +52,7 @@ public class Ease.EditorEmbed : ScrollableEmbed
/**
* The currently selected { link Actor}.
*/
- private Actor selected;
+ public Actor selected { get; private set; }
/**
* If the selected { link Actor} is being edited.
@@ -606,5 +606,17 @@ public class Ease.EditorEmbed : ScrollableEmbed
return true;
}
+
+ /**
+ * Sets the color of the currently selected element, if applicable.
+ *
+ * If no element is selected, or the selected element does not have a
+ * "color" property, this property is ignored.
+ */
+ public void set_element_color(Clutter.Color color)
+ {
+ if (selected == null) return;
+ if (!selected.element.set_color(color)) return;
+ }
}
diff --git a/src/ease-editor-window.vala b/src/ease-editor-window.vala
index 99a0c26..79c9799 100644
--- a/src/ease-editor-window.vala
+++ b/src/ease-editor-window.vala
@@ -82,6 +82,17 @@ public class Ease.EditorWindow : Gtk.Window
public bool slides_shown { get; set; }
/**
+ * The color selection dialog for this window.
+ */
+ private Gtk.ColorSelectionDialog color_dialog;
+
+ /**
+ * The color selection dialog's widget.
+ */
+ private Gtk.ColorSelection color_selection;
+
+
+ /**
* The time the document was last saved.
*/
long last_saved = 0;
@@ -241,6 +252,9 @@ public class Ease.EditorWindow : Gtk.Window
document.export_to_html(this);
});
+ // color selection
+ main_toolbar.colors.clicked.connect(show_color_dialog);
+
main_toolbar.pdf.clicked.connect(() => {
PDFExporter.export(document, this);
});
@@ -341,6 +355,46 @@ public class Ease.EditorWindow : Gtk.Window
return true;
}
+ private void show_color_dialog()
+ {
+ if (color_dialog != null)
+ {
+ color_dialog.present();
+ return;
+ }
+
+ color_dialog = new Gtk.ColorSelectionDialog(_("Select Color"));
+ color_selection = color_dialog.color_selection as Gtk.ColorSelection;
+
+ color_selection.color_changed.connect(color_dialog_changed);
+
+ embed.notify["selected"].connect(color_dialog_selection);
+
+ color_dialog.hide.connect(() => {
+ embed.notify["selected"].disconnect(color_dialog_selection);
+ color_selection.color_changed.disconnect(color_dialog_changed);
+ color_dialog.destroy();
+ color_dialog = null;
+ });
+
+ color_dialog.show_all();
+ }
+
+ private void color_dialog_changed(Gtk.ColorSelection sender)
+ {
+ embed.set_element_color(Transformations.gdk_color_to_clutter_color(
+ sender.current_color));
+ }
+
+ private void color_dialog_selection(Object sender, ParamSpec spec)
+ {
+ var color = (sender as EditorEmbed).selected.element.get_color();
+ if (color == null) return;
+
+ color_selection.current_color =
+ Transformations.clutter_color_to_gdk_color(color);
+ }
+
// menu bar creation
private Gtk.MenuBar create_menu_bar()
{
diff --git a/src/ease-element.vala b/src/ease-element.vala
index f711c1e..72c29a6 100644
--- a/src/ease-element.vala
+++ b/src/ease-element.vala
@@ -248,6 +248,28 @@ public abstract class Ease.Element : GLib.Object
}
/**
+ * If applicable, this method sets the color of an Element and returns true.
+ * Otherwise, it returns false. The method should be overridden by
+ * subclasses that provide a "color" property.
+ *
+ * @param c The color to set the element to.
+ */
+ public virtual bool set_color(Clutter.Color c)
+ {
+ return false;
+ }
+
+ /**
+ * If applicable, this method returns the color of an Element. By default,
+ * it returns null. Subclasses that provide a color property should override
+ * this method.
+ */
+ public virtual Clutter.Color? get_color()
+ {
+ return null;
+ }
+
+ /**
* A unique identifier for this Element.
*/
public string ease_name
diff --git a/src/ease-text-actor.vala b/src/ease-text-actor.vala
index 71dd7eb..be4e18f 100644
--- a/src/ease-text-actor.vala
+++ b/src/ease-text-actor.vala
@@ -62,6 +62,11 @@ public class Ease.TextActor : Actor
contents.height = e.height;
x = e.x;
y = e.y;
+
+ // add notify event handlers to update when changes to the element occur
+ e.notify["color"].connect((sender, spec) => {
+ text.color = (sender as TextElement).color;
+ });
}
/**
diff --git a/src/ease-text-element.vala b/src/ease-text-element.vala
index f6344d6..359e7cc 100644
--- a/src/ease-text-element.vala
+++ b/src/ease-text-element.vala
@@ -46,6 +46,26 @@ public class Ease.TextElement : Element
{
return new TextActor(this, c);
}
+
+ /**
+ * This method sets the color of this TextElement, then returns "true".
+ *
+ * @param c The color to set the element to.
+ */
+ public override bool set_color(Clutter.Color c)
+ {
+ color = c;
+ return true;
+ }
+
+ /**
+ * This method returns the color of the TextElement.
+ */
+ public override Clutter.Color? get_color()
+ {
+ return color;
+ }
+
protected override void write_html(ref string html, HTMLExporter exporter)
{
@@ -140,10 +160,8 @@ public class Ease.TextElement : Element
*/
public string font_name
{
- set
- {
- data.set("font_name", value);
- }
+ owned get { return data.get("font_name"); }
+ set { data.set("font_name", value); }
}
/**
diff --git a/src/ease-transformations.vala b/src/ease-transformations.vala
new file mode 100644
index 0000000..e8cfcc6
--- /dev/null
+++ b/src/ease-transformations.vala
@@ -0,0 +1,52 @@
+/* Ease, a GTK presentation application
+ Copyright (C) 2010 Nate Stedman
+
+ This program 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.
+
+ This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * Contains transformation functions, transforming one type into a similar type.
+ */
+namespace Ease.Transformations
+{
+ private const double TO_GDK_COLOR_FACTOR = 65535.0 / 255;
+ private const double TO_CLUTTER_COLOR_FACTOR = 255.0 / 65535;
+ private const uint8 CLUTTER_COLOR_ALPHA = 255;
+
+ /**
+ * Transforms a Clutter.Color into a Gdk.Color.
+ *
+ * @param color The Clutter.Color to transform.
+ */
+ public Gdk.Color clutter_color_to_gdk_color(Clutter.Color color)
+ {
+ return { 0,
+ (uint16)(color.red * TO_GDK_COLOR_FACTOR),
+ (uint16)(color.green * TO_GDK_COLOR_FACTOR),
+ (uint16)(color.blue * TO_GDK_COLOR_FACTOR) };
+ }
+
+ /**
+ * Transforms a Gdk.Color into a Clutter.Color.
+ *
+ * @param color The Gdk.Color to transform.
+ */
+ public Clutter.Color gdk_color_to_clutter_color(Gdk.Color color)
+ {
+ return { (uint8)(color.red * TO_CLUTTER_COLOR_FACTOR),
+ (uint8)(color.green * TO_CLUTTER_COLOR_FACTOR),
+ (uint8)(color.blue * TO_CLUTTER_COLOR_FACTOR),
+ CLUTTER_COLOR_ALPHA };
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]