[gnome-devel-docs] webcam demo: ship around bug #599885 on andreasn's computer



commit 40775ce1908b7f5fa105dee0340b50b1d092da40
Author: daniel g. siegel <dgsiegel gnome org>
Date:   Fri Dec 3 19:17:41 2010 +0100

    webcam demo: ship around bug #599885 on andreasn's computer

 demos/webcam/webcam.vala |   61 +++++++++++++++++++++++++++++++++++++--------
 1 files changed, 50 insertions(+), 11 deletions(-)
---
diff --git a/demos/webcam/webcam.vala b/demos/webcam/webcam.vala
index a5b37af..13f1c4f 100644
--- a/demos/webcam/webcam.vala
+++ b/demos/webcam/webcam.vala
@@ -6,54 +6,93 @@
 using Gtk;
 using Gst;
 
-public class Webcam : Window
+public class Webcam : Gtk.Window
 {
   private Gtk.DrawingArea drawing_area;
+  private X.ID xid;
   private Gst.Element camerabin;
   private int counter = 1;
+  private bool playing;
 
   public Webcam ()
   {
-    var vbox = new Gtk.VBox (false, 0);
+    this.set_title ("Press play to start");
     this.destroy.connect (Gtk.main_quit);
+
+    var vbox = new Gtk.VBox (false, 0);
     this.drawing_area = new Gtk.DrawingArea ();
     this.drawing_area.set_size_request (640, 480);
+    this.drawing_area.realize.connect (on_realize);
     vbox.pack_start (this.drawing_area, true, true, 0);
 
+    var play_button = new Button.from_stock (Gtk.STOCK_MEDIA_PLAY);
+    play_button.clicked.connect (on_play);
+    var pause_button = new Button.from_stock (Gtk.STOCK_MEDIA_PAUSE);
+    pause_button.clicked.connect (on_pause);
     var photo_button = new Button.with_label ("Take a picture");
     photo_button.clicked.connect (on_take_picture);
+    var stop_button = new Button.from_stock (Gtk.STOCK_MEDIA_STOP);
+    stop_button.clicked.connect (on_stop);
 
     var button_box = new Gtk.HButtonBox ();
+    button_box.add (play_button);
+    button_box.add (pause_button);
     button_box.add (photo_button);
-    vbox.pack_start (button_box, false, true, 0);
+    button_box.add (stop_button);
+    vbox.pack_start (button_box, false, true, 5);
 
     this.add (vbox);
 
     this.camerabin = Gst.ElementFactory.make ("camerabin", "camera");
     var bus = this.camerabin.get_bus ();
     bus.set_sync_handler (on_bus_callback);
-
-    this.camerabin.set_state (Gst.State.PLAYING);
   }
 
   private Gst.BusSyncReply on_bus_callback (Gst.Bus bus, Gst.Message message)
   {
-
     if (message.get_structure () != null && message.get_structure().has_name("prepare-xwindow-id")) {
       var xoverlay = message.src as Gst.XOverlay;
-      xoverlay.set_xwindow_id (Gdk.x11_drawable_get_xid (this.drawing_area.window));
+      xoverlay.set_xwindow_id (this.xid);
       return Gst.BusSyncReply.DROP;
     }
 
     return Gst.BusSyncReply.PASS;
   }
 
+  private void on_realize ()
+  {
+    this.xid = Gdk.x11_drawable_get_xid (this.drawing_area.window);
+    on_play ();
+  }
+
+  private void on_play ()
+  {
+    this.camerabin.set_state (Gst.State.PLAYING);
+    this.playing = true;
+  }
+
+  private void on_pause ()
+  {
+    this.camerabin.set_state (Gst.State.PAUSED);
+    this.playing = false;
+  }
+
+  private void on_stop ()
+  {
+    this.camerabin.set_state (Gst.State.NULL);
+    this.playing = false;
+  }
+
   private void on_take_picture ()
   {
-    var filename = "photo" + "%d".printf (this.counter) + ".jpg";
-    this.counter++;
-    this.camerabin.set ("filename", filename);
-    GLib.Signal.emit_by_name (this.camerabin, "capture-start");
+    if (this.playing)
+    {
+      var filename = "photo" + "%d".printf (this.counter) + ".jpg";
+      this.set_title ("%d".printf (this.counter) + " photos taken");
+      this.counter++;
+      this.camerabin.set ("filename", filename);
+      GLib.Signal.emit_by_name (this.camerabin, "capture-start");
+    }
   }
 
   public static int main (string[] args)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]