cheese r731 - in trunk: . src



Author: jhaitsma
Date: Sun May 25 08:54:40 2008
New Revision: 731
URL: http://svn.gnome.org/viewvc/cheese?rev=731&view=rev

Log:
Forgot to add cheese-flash.[ch] to SVN


Added:
   trunk/src/cheese-flash.c
   trunk/src/cheese-flash.h
Modified:
   trunk/ChangeLog

Added: trunk/src/cheese-flash.c
==============================================================================
--- (empty file)
+++ trunk/src/cheese-flash.c	Sun May 25 08:54:40 2008
@@ -0,0 +1,187 @@
+/*
+ * Copyright  2008 Alexander âweejâ Jones <alex weej com>
+ * Copyright  2008 Thomas Perl <thp perli net>
+ * 
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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 2 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/>.
+ */
+
+/* This is a "flash" object that you can create and invoke a method "flash" on to 
+   flood the screen with white temporarily */
+
+#include <gtk/gtk.h>
+
+#include "cheese-flash.h"
+#include "cheese-webcam.h"
+
+/* How long to hold the flash for */
+#define FLASH_DURATION 250
+
+/* The factor which defines how much the flash fades per frame */
+#define FLASH_FADE_FACTOR 0.95
+
+/* How many frames per second */
+#define FLASH_ANIMATION_RATE 50
+
+/* When to consider the flash finished so we can stop fading */
+#define FLASH_LOW_THRESHOLD 0.01
+
+G_DEFINE_TYPE (CheeseFlash, cheese_flash, G_TYPE_OBJECT);
+
+#define CHEESE_FLASH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_FLASH, CheeseFlashPrivate))
+
+typedef struct
+{
+  GtkWindow* window;
+  guint flash_timeout_tag;
+  guint fade_timeout_tag;
+} CheeseFlashPrivate;
+
+static gboolean
+cheese_flash_window_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
+{
+  cairo_t *cr;
+
+  cr = gdk_cairo_create (widget->window);
+  cairo_set_source_rgb (cr, 1, 1, 1);
+  cairo_rectangle (cr, event->area.x, event->area.y, event->area.width, event->area.height);
+  cairo_fill (cr);
+  cairo_destroy (cr);
+
+  return TRUE;
+}
+
+static void
+cheese_flash_init (CheeseFlash *self)
+{
+  CheeseFlashPrivate* priv = CHEESE_FLASH_GET_PRIVATE (self);
+  GtkWindow* window;
+
+  priv->flash_timeout_tag = 0;
+  priv->fade_timeout_tag = 0;
+
+  window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL));
+
+  /* make it so it doesn't look like a window on the desktop (+fullscreen) */
+  gtk_window_set_decorated (window, FALSE);  
+  gtk_window_set_skip_taskbar_hint (window, TRUE);
+  gtk_window_set_skip_pager_hint (window, TRUE);
+  gtk_window_fullscreen (window);
+  gtk_window_set_keep_above (window, TRUE);
+    
+  /* Don't take focus */
+  gtk_window_set_accept_focus (window, FALSE);
+
+  /* Don't consume input */
+  gtk_widget_realize (GTK_WIDGET (window));
+  GdkRegion* input_region;
+  input_region = gdk_region_new ();
+  gdk_window_input_shape_combine_region (GTK_WIDGET (window)->window, input_region, 0, 0);
+  gdk_region_destroy (input_region);
+
+  g_signal_connect (G_OBJECT (window), "expose-event", G_CALLBACK (cheese_flash_window_expose_event_cb), NULL);
+  priv->window = window;
+}
+
+static void
+cheese_flash_dispose (GObject *object)
+{
+  CheeseFlashPrivate* priv = CHEESE_FLASH_GET_PRIVATE (object);
+  g_object_unref (priv->window);
+
+  if (G_OBJECT_CLASS (cheese_flash_parent_class)->dispose)
+    G_OBJECT_CLASS (cheese_flash_parent_class)->dispose (object);
+}
+
+static void
+cheese_flash_finalize (GObject *object)
+{
+  if (G_OBJECT_CLASS (cheese_flash_parent_class)->finalize)
+    G_OBJECT_CLASS (cheese_flash_parent_class)->finalize (object);
+}
+
+static void
+cheese_flash_class_init (CheeseFlashClass *klass)
+{
+  GObjectClass* object_class = G_OBJECT_CLASS (klass);
+  GObjectClass* parent_class = G_OBJECT_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (CheeseFlashPrivate));
+
+  object_class->dispose = cheese_flash_dispose;
+  object_class->finalize = cheese_flash_finalize;
+}
+
+static gboolean
+cheese_flash_opacity_fade (gpointer data)
+{
+  CheeseFlash* flash = data;
+  CheeseFlashPrivate* flash_priv = CHEESE_FLASH_GET_PRIVATE (flash);
+  GtkWindow* flash_window = flash_priv->window;
+  double opacity = gtk_window_get_opacity (flash_window);
+
+  /* exponentially decrease */
+  gtk_window_set_opacity (flash_window, opacity * FLASH_FADE_FACTOR);
+    
+  if (opacity <= FLASH_LOW_THRESHOLD) 
+  {
+    /* the flasher has finished when we reach the quit value */
+    gtk_widget_hide (GTK_WIDGET (flash_window));
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
+static gboolean
+cheese_flash_start_fade (gpointer data)
+{
+  CheeseFlash* flash = data;
+  CheeseFlashPrivate* flash_priv = CHEESE_FLASH_GET_PRIVATE (flash);
+  GtkWindow* flash_window = flash_priv->window;
+    
+  /* If the screen is non-composited, just hide and finish up */
+  if (!gdk_screen_is_composited (gtk_window_get_screen (flash_window))) 
+  {
+    gtk_widget_hide (GTK_WIDGET (flash_window));
+    return FALSE;
+  }
+
+  flash_priv->fade_timeout_tag = g_timeout_add (1000.0 / FLASH_ANIMATION_RATE, cheese_flash_opacity_fade, data);
+  return FALSE;
+}
+
+void
+cheese_flash_fire (CheeseFlash* flash)
+{
+  CheeseFlashPrivate* flash_priv = CHEESE_FLASH_GET_PRIVATE (flash);
+  GtkWindow* flash_window = flash_priv->window;
+
+  if (flash_priv->flash_timeout_tag > 0)
+    g_source_remove (flash_priv->flash_timeout_tag);
+  if (flash_priv->fade_timeout_tag > 0)
+    g_source_remove (flash_priv->fade_timeout_tag);
+
+  gtk_window_set_opacity (flash_window, 1);
+  gtk_widget_show_all (GTK_WIDGET (flash_window));
+  flash_priv->flash_timeout_tag = g_timeout_add (FLASH_DURATION, cheese_flash_start_fade, (gpointer)flash);
+}
+
+CheeseFlash*
+cheese_flash_new (void)
+{
+  return g_object_new (CHEESE_TYPE_FLASH, NULL);
+}
+

Added: trunk/src/cheese-flash.h
==============================================================================
--- (empty file)
+++ trunk/src/cheese-flash.h	Sun May 25 08:54:40 2008
@@ -0,0 +1,50 @@
+/*
+ * Copyright  2008 Alexander âweejâ Jones <alex weej com>
+ * 
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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 2 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/>.
+ */
+
+#ifndef _CHEESE_FLASH_H_
+#define _CHEESE_FLASH_H_
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define CHEESE_TYPE_FLASH             (cheese_flash_get_type ())
+#define CHEESE_FLASH(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), CHEESE_TYPE_FLASH, CheeseFlash))
+#define CHEESE_FLASH_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), CHEESE_TYPE_FLASH, CheeseFlashClass))
+#define CHEESE_IS_FLASH(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CHEESE_TYPE_FLASH))
+#define CHEESE_IS_FLASH_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), CHEESE_TYPE_FLASH))
+#define CHEESE_FLASH_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), CHEESE_TYPE_FLASH, CheeseFlashClass))
+
+typedef struct
+{
+  GObjectClass parent_class;
+} CheeseFlashClass;
+
+typedef struct 
+{
+  GObject parent_instance;
+} CheeseFlash;
+
+GType cheese_flash_get_type (void) G_GNUC_CONST;
+void cheese_flash_fire (CheeseFlash* flash);
+CheeseFlash* cheese_flash_new (void);
+
+G_END_DECLS
+
+#endif /* _CHEESE_FLASH_H_ */



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