1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* On-screen-display (OSD) for Totem's video widget
5
* Copyright (C) 2012 Red Hat, Inc.
8
* Bastien Nocera <hadess@hadess.net>
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public
12
* License as published by the Free Software Foundation; either
13
* version 2, or (at your option) any later version.
15
* This program is distributed in the hope that it will be
16
* useful, but WITHOUT ANY WARRANTY; without even the implied
17
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18
* PURPOSE. See the GNU Lesser General Public License for more
21
* You should have received a copy of the GNU Lesser General
22
* Public License along with this program; if not, write to the
23
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24
* Boston, MA 02111-1307, USA.
33
#include <glib/gi18n.h>
34
#include <clutter/clutter.h>
37
#include "bacon-video-osd-actor.h"
38
#include "gsd-osd-window.h"
39
#include "gsd-osd-window-private.h"
41
#define BACON_VIDEO_OSD_ACTOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BACON_TYPE_VIDEO_OSD_ACTOR, BaconVideoOsdActorPrivate))
43
struct BaconVideoOsdActorPrivate
45
ClutterCanvas *canvas;
47
GtkStyleContext *style;
48
GsdOsdDrawContext *ctx;
50
guint hide_timeout_id;
51
guint fade_timeout_id;
52
double fade_out_alpha;
55
G_DEFINE_TYPE (BaconVideoOsdActor, bacon_video_osd_actor, CLUTTER_TYPE_ACTOR);
58
fade_timeout (BaconVideoOsdActor *osd)
60
if (osd->priv->fade_out_alpha <= 0.0) {
61
bacon_video_osd_actor_hide (osd);
64
clutter_actor_set_opacity (CLUTTER_ACTOR (osd),
65
0xff * osd->priv->fade_out_alpha);
66
osd->priv->fade_out_alpha -= 0.10;
73
hide_timeout (BaconVideoOsdActor *osd)
75
osd->priv->hide_timeout_id = 0;
76
osd->priv->fade_timeout_id = g_timeout_add (FADE_FRAME_TIMEOUT,
77
(GSourceFunc) fade_timeout,
84
remove_hide_timeout (BaconVideoOsdActor *osd)
86
if (osd->priv->hide_timeout_id != 0) {
87
g_source_remove (osd->priv->hide_timeout_id);
88
osd->priv->hide_timeout_id = 0;
91
if (osd->priv->fade_timeout_id != 0) {
92
g_source_remove (osd->priv->fade_timeout_id);
93
osd->priv->fade_timeout_id = 0;
94
osd->priv->fade_out_alpha = 1.0;
99
add_hide_timeout (BaconVideoOsdActor *osd)
101
osd->priv->hide_timeout_id = g_timeout_add (DIALOG_FADE_TIMEOUT,
102
(GSourceFunc) hide_timeout,
107
bacon_video_osd_actor_finalize (GObject *object)
109
BaconVideoOsdActor *osd;
111
osd = BACON_VIDEO_OSD_ACTOR (object);
112
if (osd->priv->ctx) {
113
g_free (osd->priv->ctx);
114
osd->priv->ctx = NULL;
116
if (osd->priv->style) {
117
g_object_unref (osd->priv->style);
118
osd->priv->style = NULL;
121
g_free (osd->priv->icon_name);
122
osd->priv->icon_name = NULL;
124
G_OBJECT_CLASS (bacon_video_osd_actor_parent_class)->finalize (object);
128
bacon_video_osd_actor_class_init (BaconVideoOsdActorClass *klass)
130
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
132
// gobject_class->constructor = bacon_video_osd_actor_constructor;
133
gobject_class->finalize = bacon_video_osd_actor_finalize;
135
g_type_class_add_private (klass, sizeof (BaconVideoOsdActorPrivate));
139
bacon_video_osd_actor_draw (ClutterCanvas *canvas,
143
BaconVideoOsdActor *osd)
145
GsdOsdDrawContext *ctx;
147
g_return_val_if_fail (osd->priv->icon_name != NULL, FALSE);
149
ctx = osd->priv->ctx;
152
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
156
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
158
ctx->size = MIN(width, height);
159
ctx->icon_name = osd->priv->icon_name;
161
gsd_osd_window_draw (ctx, cr);
167
bacon_video_osd_actor_init (BaconVideoOsdActor *osd)
170
GtkWidgetPath *widget_path;
172
self = CLUTTER_ACTOR (osd);
173
osd->priv = BACON_VIDEO_OSD_ACTOR_GET_PRIVATE (osd);
175
osd->priv->canvas = CLUTTER_CANVAS (clutter_canvas_new ());
176
g_object_bind_property (self, "width",
177
osd->priv->canvas, "width",
179
g_object_bind_property (self, "height",
180
osd->priv->canvas, "height",
182
clutter_actor_set_content (self, CLUTTER_CONTENT (osd->priv->canvas));
183
g_object_unref (osd->priv->canvas);
185
osd->priv->icon_name = g_strdup ("media-playback-pause-symbolic");
187
osd->priv->ctx = g_new0 (GsdOsdDrawContext, 1);
189
widget_path = gtk_widget_path_new ();
190
gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
191
osd->priv->style = gtk_style_context_new ();
192
gtk_style_context_set_path (osd->priv->style, widget_path);
193
gtk_widget_path_free (widget_path);
195
osd->priv->ctx->direction = clutter_get_default_text_direction ();
196
osd->priv->ctx->theme = gtk_icon_theme_get_default ();
197
osd->priv->ctx->action = GSD_OSD_WINDOW_ACTION_CUSTOM;
198
osd->priv->ctx->style = osd->priv->style;
200
g_signal_connect (osd->priv->canvas, "draw", G_CALLBACK (bacon_video_osd_actor_draw), osd);
201
osd->priv->fade_out_alpha = 1.0;
205
bacon_video_osd_actor_new (void)
207
return g_object_new (BACON_TYPE_VIDEO_OSD_ACTOR, NULL);
211
bacon_video_osd_actor_set_icon_name (BaconVideoOsdActor *osd,
212
const char *icon_name)
214
g_return_if_fail (BACON_IS_VIDEO_OSD_ACTOR (osd));
216
g_free (osd->priv->icon_name);
217
osd->priv->icon_name = g_strdup (icon_name);
219
if (icon_name != NULL)
220
clutter_content_invalidate (CLUTTER_CONTENT (osd->priv->canvas));
224
bacon_video_osd_actor_hide (BaconVideoOsdActor *osd)
226
g_return_if_fail (BACON_IS_VIDEO_OSD_ACTOR (osd));
228
clutter_actor_hide (CLUTTER_ACTOR (osd));
230
/* Reset it for the next time */
231
osd->priv->fade_out_alpha = 1.0;
232
osd->priv->fade_timeout_id = 0;
236
bacon_video_osd_actor_show (BaconVideoOsdActor *osd)
238
g_return_if_fail (BACON_IS_VIDEO_OSD_ACTOR (osd));
240
remove_hide_timeout (osd);
241
clutter_actor_set_opacity (CLUTTER_ACTOR (osd), 0xff);
242
clutter_actor_show (CLUTTER_ACTOR (osd));
246
bacon_video_osd_actor_show_and_fade (BaconVideoOsdActor *osd)
248
g_return_if_fail (BACON_IS_VIDEO_OSD_ACTOR (osd));
250
remove_hide_timeout (osd);
251
clutter_actor_set_opacity (CLUTTER_ACTOR (osd), 0xff);
252
clutter_actor_show (CLUTTER_ACTOR (osd));
253
add_hide_timeout (osd);