[ease] [general] Added background support to PDF elements
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease] [general] Added background support to PDF elements
- Date: Wed, 25 Aug 2010 18:18:47 +0000 (UTC)
commit 4d24980686ac91e43873028762a83229163f62b8
Author: Nate Stedman <natesm gmail com>
Date: Wed Aug 25 14:17:29 2010 -0400
[general] Added background support to PDF elements
Fixes bug 627806.
Added a method to Background which renders the background to the
given Cairo context (with a specified size and media directory).
data/ui/inspector-element-pdf.ui | 11 ++++++++++-
ease-core/ease-background.vala | 28 ++++++++++++++++++++++++++++
ease-core/ease-pdf-actor.vala | 8 +++++++-
ease-core/ease-pdf-element.vala | 37 ++++++++++++++++++++++++++++++++++++-
ease-core/ease-slide.vala | 8 ++------
5 files changed, 83 insertions(+), 9 deletions(-)
---
diff --git a/data/ui/inspector-element-pdf.ui b/data/ui/inspector-element-pdf.ui
index 8ab4d4a..238e44c 100644
--- a/data/ui/inspector-element-pdf.ui
+++ b/data/ui/inspector-element-pdf.ui
@@ -9,7 +9,7 @@
<property name="left_padding">4</property>
<property name="right_padding">4</property>
<child>
- <object class="GtkVBox" id="vbox1">
+ <object class="GtkVBox" id="root-vbox">
<property name="visible">True</property>
<property name="spacing">8</property>
<child>
@@ -48,6 +48,15 @@
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkHSeparator" id="hseparator1">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/ease-core/ease-background.vala b/ease-core/ease-background.vala
index f2bdc7a..c4fb3ea 100644
--- a/ease-core/ease-background.vala
+++ b/ease-core/ease-background.vala
@@ -73,6 +73,16 @@ public class Ease.Background : GLib.Object
}
/**
+ * Returns a white background.
+ */
+ public Background.white()
+ {
+ color = Color.white;
+ gradient = Gradient.default_background;
+ background_type = BackgroundType.COLOR;
+ }
+
+ /**
* Creates a background from a JSON object.
*/
public Background.from_json(Json.Object obj)
@@ -149,6 +159,24 @@ public class Ease.Background : GLib.Object
}
}
+ /**
+ * Renders this background to a Cairo context at the specified size.
+ *
+ * @param cr The Cairo.Context to draw to.
+ * @param w The width to render at.
+ * @param h The height to render at.
+ * @param path The base path to any possible media files.
+ */
+ public void cairo_render(Cairo.Context cr, int width, int height,
+ string path) throws GLib.Error
+ {
+ cr.save();
+ set_cairo(cr, width, height, path);
+ cr.rectangle(0, 0, width, height);
+ cr.fill();
+ cr.restore();
+ }
+
// TODO: this is a bit hacky, but it works...
internal bool owns_undoitem(UndoItem item)
{
diff --git a/ease-core/ease-pdf-actor.vala b/ease-core/ease-pdf-actor.vala
index fc2c12a..729d3cb 100644
--- a/ease-core/ease-pdf-actor.vala
+++ b/ease-core/ease-pdf-actor.vala
@@ -23,6 +23,7 @@ public class Ease.PdfActor : Actor
private Clutter.CairoTexture texture;
private int current_page;
private Poppler.Document doc;
+ private PdfElement pdf_element;
/**
* Instantiates a new PdfActor from an Element.
@@ -34,6 +35,8 @@ public class Ease.PdfActor : Actor
{
base(e, c);
+ pdf_element = e;
+
contents = new Clutter.Group();
contents.width = e.width;
contents.height = e.height;
@@ -45,7 +48,8 @@ public class Ease.PdfActor : Actor
doc = e.pdf_doc;
draw_page();
- e.notify["default-page"].connect((obj, pspec) => {
+ // redraw when the element is changed
+ e.changed.connect(() => {
current_page = e.default_page;
draw_page();
});
@@ -85,6 +89,8 @@ public class Ease.PdfActor : Actor
// draw the texture
texture.clear();
var cr = texture.create();
+ pdf_element.background.cairo_render(cr, (int)width, (int)height,
+ element.parent.parent.path);
page.render(cr);
}
}
diff --git a/ease-core/ease-pdf-element.vala b/ease-core/ease-pdf-element.vala
index 408d628..f116b06 100644
--- a/ease-core/ease-pdf-element.vala
+++ b/ease-core/ease-pdf-element.vala
@@ -27,6 +27,16 @@ public class Ease.PdfElement : MediaElement
*/
public int default_page { get; set; default = 0; }
+ /**
+ * The background displayed behind the PDF (if it is visible)
+ */
+ internal Background background;
+
+ /**
+ * The background widget controlling { link background}.
+ */
+ private BackgroundWidget bg_widget;
+
internal Poppler.Document pdf_doc;
public PdfElement(string filename)
@@ -34,6 +44,7 @@ public class Ease.PdfElement : MediaElement
pdf_doc = new Poppler.Document.from_file(
Filename.to_uri(filename),
null);
+ background = new Background.white();
signals();
}
@@ -42,6 +53,8 @@ public class Ease.PdfElement : MediaElement
base.from_json(obj);
default_page = obj.get_string_member(Theme.PDF_DEFAULT_PAGE).to_int();
+ background = new Background.from_json(obj);
+
pdf_doc = new Poppler.Document.from_file(
Filename.to_uri(full_filename),
null);
@@ -94,6 +107,10 @@ public class Ease.PdfElement : MediaElement
public override void cairo_render(Cairo.Context context) throws Error
{
+ // render the background
+ background.cairo_render(context, (int)width, (int)height,
+ parent.parent.path);
+
// get the current page
var page = pdf_doc.get_page(default_page);
@@ -102,7 +119,7 @@ public class Ease.PdfElement : MediaElement
page.get_size(out w, out h);
context.scale(width / w, height / h);
- // render
+ // render the PDF
page.render(context);
}
@@ -116,6 +133,7 @@ public class Ease.PdfElement : MediaElement
}
catch (Error e) { error("Error loading UI: %s", e.message); }
+ // get the displayed page slider
var scale = builder.get_object("disp-page") as Gtk.HScale;
scale.adjustment.upper = pdf_doc.get_n_pages();
@@ -135,7 +153,24 @@ public class Ease.PdfElement : MediaElement
undo(action);
});
+ // add a background widget
+ bg_widget = new BackgroundWidget(background, this);
+ (builder.get_object("root-vbox") as Gtk.Box).pack_end(
+ bg_widget, false, true, 0);
+ bg_widget.show();
+
// return the root widget
return builder.get_object("root") as Gtk.Widget;
}
+
+ public override void signals()
+ {
+ base.signals();
+
+ notify["default-page"].connect((o, p) => changed());
+
+ undo.connect((item) => {
+ if (background.owns_undoitem(item)) changed();
+ });
+ }
}
diff --git a/ease-core/ease-slide.vala b/ease-core/ease-slide.vala
index 13fa1f7..d85ccdc 100644
--- a/ease-core/ease-slide.vala
+++ b/ease-core/ease-slide.vala
@@ -599,12 +599,8 @@ public class Ease.Slide : GLib.Object, UndoSource
public void cairo_render_background(Cairo.Context cr,
int w, int h) throws GLib.Error
{
- cr.save();
- background.set_cairo(cr, w, h,
- parent == null ? theme.path : parent.path);
- cr.rectangle(0, 0, w, h);
- cr.fill();
- cr.restore();
+ background.cairo_render(cr, w, h,
+ parent == null ? theme.path : parent.path);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]