2
* Copyright © 2007-2009 daniel g. siegel <dgsiegel@gnome.org>
3
* Copyright © 2007,2008 Jaap Haitsma <jaap@haitsma.org>
5
* Licensed under the GNU General Public License Version 2
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include <cheese-config.h>
27
#include <glib/gi18n.h>
31
#include <cheese-camera.h>
32
#include "cheese-effect-chooser.h"
36
#define NUM_EFFECTS (BOARD_ROWS * BOARD_COLS)
38
#define SHRINK(cr, x) cairo_translate (cr, (1 - (x)) / 2.0, (1 - (x)) / 2.0); cairo_scale (cr, (x), (x))
40
#define CHEESE_EFFECT_CHOOSER_GET_PRIVATE(o) \
41
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_EFFECT_CHOOSER, CheeseEffectChooserPrivate))
43
G_DEFINE_TYPE (CheeseEffectChooser, cheese_effect_chooser, GTK_TYPE_DRAWING_AREA);
47
gboolean selected[NUM_EFFECTS];
48
} CheeseEffectChooserPrivate;
53
CheeseCameraEffect effect;
59
static const GstEffect GST_EFFECT[] = {
60
{CHEESE_CAMERA_EFFECT_NO_EFFECT, N_("No Effect"),
61
PACKAGE_DATADIR "/effects/identity.png", FALSE},
62
{CHEESE_CAMERA_EFFECT_MAUVE, N_("Mauve"),
63
PACKAGE_DATADIR "/effects/Mauve.png", FALSE},
64
{CHEESE_CAMERA_EFFECT_NOIR_BLANC, N_("Noir/Blanc"),
65
PACKAGE_DATADIR "/effects/NoirBlanc.png", FALSE},
66
{CHEESE_CAMERA_EFFECT_SATURATION, N_("Saturation"),
67
PACKAGE_DATADIR "/effects/Saturation.png", FALSE},
68
{CHEESE_CAMERA_EFFECT_HULK, N_("Hulk"),
69
PACKAGE_DATADIR "/effects/Hulk.png", FALSE},
70
{CHEESE_CAMERA_EFFECT_VERTICAL_FLIP, N_("Vertical Flip"),
71
PACKAGE_DATADIR "/effects/videoflip_v.png", FALSE},
72
{CHEESE_CAMERA_EFFECT_HORIZONTAL_FLIP, N_("Horizontal Flip"),
73
PACKAGE_DATADIR "/effects/videoflip_h.png", FALSE},
74
{CHEESE_CAMERA_EFFECT_SHAGADELIC, N_("Shagadelic"),
75
PACKAGE_DATADIR "/effects/shagadelictv.png", FALSE},
76
{CHEESE_CAMERA_EFFECT_VERTIGO, N_("Vertigo"),
77
PACKAGE_DATADIR "/effects/vertigotv.png", FALSE},
78
{CHEESE_CAMERA_EFFECT_EDGE, N_("Edge"),
79
PACKAGE_DATADIR "/effects/edgetv.png", TRUE},
80
{CHEESE_CAMERA_EFFECT_DICE, N_("Dice"),
81
PACKAGE_DATADIR "/effects/dicetv.png", FALSE},
82
{CHEESE_CAMERA_EFFECT_WARP, N_("Warp"),
83
PACKAGE_DATADIR "/effects/warptv.png", FALSE}
88
cheese_cairo_rectangle_round (cairo_t *cr,
90
double width, double height, double radius)
97
if (!width || !height)
99
if (width / 2 < radius)
101
if (height / 2 < radius)
103
cairo_move_to (cr, x0, (y0 + y1) / 2);
104
cairo_curve_to (cr, x0, y0, x0, y0, (x0 + x1) / 2, y0);
105
cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1) / 2);
106
cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0) / 2, y1);
107
cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1) / 2);
111
cairo_move_to (cr, x0, y0 + radius);
112
cairo_curve_to (cr, x0, y0, x0, y0, (x0 + x1) / 2, y0);
113
cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
114
cairo_line_to (cr, x1, y1 - radius);
115
cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0) / 2, y1);
116
cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - radius);
121
if (height / 2 < radius)
123
cairo_move_to (cr, x0, (y0 + y1) / 2);
124
cairo_curve_to (cr, x0, y0, x0, y0, x0 + radius, y0);
125
cairo_line_to (cr, x1 - radius, y0);
126
cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1) / 2);
127
cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
128
cairo_line_to (cr, x0 + radius, y1);
129
cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1) / 2);
133
cairo_move_to (cr, x0, y0 + radius);
134
cairo_curve_to (cr, x0, y0, x0, y0, x0 + radius, y0);
135
cairo_line_to (cr, x1 - radius, y0);
136
cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
137
cairo_line_to (cr, x1, y1 - radius);
138
cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
139
cairo_line_to (cr, x0 + radius, y1);
140
cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - radius);
143
cairo_close_path (cr);
147
cheese_cairo_draw_card (cairo_t *cr, const GstEffect *card, gboolean highlight)
150
cairo_surface_t *image;
156
cheese_cairo_rectangle_round (cr, 0, 0, 1.0, 1.0, 0.1);
157
cairo_set_source_rgb (cr, 0, 0, 0);
161
cheese_cairo_rectangle_round (cr, 0, 0, 1.0, 1.0, 0.1);
165
image = cairo_image_surface_create_from_png (card->filename);
166
w = cairo_image_surface_get_width (image);
167
h = cairo_image_surface_get_height (image);
169
cairo_scale (cr, 1.0 / w, 1.0 / h);
171
cairo_set_source_surface (cr, image, 0, 0);
174
cairo_surface_destroy (image);
178
cairo_set_source_rgb (cr, 1, 1, 1);
180
PangoLayout *layout = pango_cairo_create_layout (cr);
181
gchar *name = gettext (card->name);
182
pango_layout_set_text (layout, name, -1);
183
PangoFontDescription *desc = pango_font_description_from_string ("Sans 0.09");
184
pango_layout_set_font_description (layout, desc);
185
pango_font_description_free (desc);
187
pango_layout_get_size (layout, &width, &height);
189
x = 0.5 - ((double)width / PANGO_SCALE) / 2;
190
y = 0.92 - ((double)height / PANGO_SCALE) / 2;
191
cairo_move_to (cr, x, y);
192
pango_cairo_show_layout (cr, layout);
193
g_object_unref (layout);
197
cheese_cairo_rectangle_round (cr, 0, 0, 1.0, 1.0, 0.1);
198
cairo_set_source_rgba (cr, 0, 0, 1, 0.25);
205
cheese_effect_chooser_expose_cb (GtkWidget *widget, GdkEventExpose *expose_event, gpointer data)
207
CheeseEffectChooserPrivate *priv = CHEESE_EFFECT_CHOOSER_GET_PRIVATE (widget);
209
GtkAllocation allocation;
214
gtk_widget_get_allocation (widget, &allocation);
215
width = allocation.width;
216
height = allocation.height;
218
cr = gdk_cairo_create (gtk_widget_get_window (widget));
221
cairo_scale (cr, width, height);
223
for (i = 0; i < NUM_EFFECTS; i++)
226
cairo_translate (cr, 1.0 / BOARD_COLS * (i % BOARD_COLS),
227
1.0 / BOARD_ROWS * (i / BOARD_COLS));
228
cairo_scale (cr, 1.0 / BOARD_COLS, 1.0 / BOARD_ROWS);
229
cheese_cairo_draw_card (cr, &(GST_EFFECT[i]), priv->selected[i]);
237
cheese_effect_chooser_button_press_event_cb (GtkWidget *widget, GdkEventButton *button_event, gpointer data)
239
CheeseEffectChooserPrivate *priv = CHEESE_EFFECT_CHOOSER_GET_PRIVATE (widget);
240
GtkAllocation allocation;
245
gtk_widget_get_allocation (widget, &allocation);
246
col = (int) (button_event->x / allocation.width * BOARD_COLS);
247
row = (int) (button_event->y / allocation.height * BOARD_ROWS);
248
slot = (row * BOARD_COLS + col);
250
priv->selected[slot] = !priv->selected[slot];
252
if (priv->selected[0] == TRUE)
254
for (i = 0; i < NUM_EFFECTS; i++)
255
priv->selected[i] = FALSE;
258
gtk_widget_queue_draw (widget);
264
cheese_effect_chooser_get_selection (CheeseEffectChooser *effect_chooser)
266
CheeseEffectChooserPrivate *priv = CHEESE_EFFECT_CHOOSER_GET_PRIVATE (effect_chooser);
269
CheeseCameraEffect effect = 0;
271
for (i = 0; i < NUM_EFFECTS; i++)
273
if (priv->selected[i])
275
effect |= GST_EFFECT[i].effect;
282
cheese_effect_chooser_get_selection_string (CheeseEffectChooser *effect_chooser)
284
CheeseEffectChooserPrivate *priv = CHEESE_EFFECT_CHOOSER_GET_PRIVATE (effect_chooser);
287
char *effects = NULL;
289
for (i = 0; i < NUM_EFFECTS; i++)
291
if (priv->selected[i])
294
effects = GST_EFFECT[i].name;
296
effects = g_strjoin (",", effects, GST_EFFECT[i].name, NULL);
303
cheese_effect_chooser_finalize (GObject *object)
305
G_OBJECT_CLASS (cheese_effect_chooser_parent_class)->finalize (object);
309
cheese_effect_chooser_class_init (CheeseEffectChooserClass *klass)
311
GObjectClass *object_class = G_OBJECT_CLASS (klass);
313
object_class->finalize = cheese_effect_chooser_finalize;
315
g_type_class_add_private (klass, sizeof (CheeseEffectChooserPrivate));
319
cheese_effect_chooser_init (CheeseEffectChooser *effect_chooser)
321
gtk_widget_add_events (GTK_WIDGET (effect_chooser), GDK_BUTTON_PRESS_MASK);
323
g_signal_connect (G_OBJECT (effect_chooser), "button_press_event",
324
G_CALLBACK (cheese_effect_chooser_button_press_event_cb), NULL);
325
g_signal_connect (G_OBJECT (effect_chooser), "expose-event",
326
G_CALLBACK (cheese_effect_chooser_expose_cb), NULL);
330
cheese_effect_chooser_new (char *selected_effects)
332
CheeseEffectChooser *effect_chooser;
335
effect_chooser = g_object_new (CHEESE_TYPE_EFFECT_CHOOSER, NULL);
337
CheeseEffectChooserPrivate *priv = CHEESE_EFFECT_CHOOSER_GET_PRIVATE (effect_chooser);
339
if (selected_effects != NULL)
341
for (i = 1; i < NUM_EFFECTS; i++)
343
if (strstr (selected_effects, GST_EFFECT[i].name) != NULL)
344
priv->selected[i] = TRUE;
348
return GTK_WIDGET (effect_chooser);