~ubuntu-branches/ubuntu/natty/gnome-mplayer/natty

« back to all changes in this revision

Viewing changes to src/libgmtk/gmtk_media_tracker.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Tirabassi
  • Date: 2009-06-06 19:49:50 UTC
  • mfrom: (1.1.16 upstream) (0.1.8 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090606194950-r2k3q5heupe2ewq4
Tags: 0.9.6-1
* New upstream release:
  - new media tracker and audio meter
  - new key "use_pulse_flat_volume" to be set if you are using
    Pulse Audio 0.9.15 (see /usr/share/doc/gnome-mplayer/NEWS.Debian.gz
    and /usr/share/doc/gnome-mplayer/changelog.gz for additional info)
  - workaround for opening files on smb shares (LP: #369426)
  - prevent adding an "empty" filename to the playlist (LP: #348864)
  - add new --large_buttons and --always_hide_after_timeout command
    line options to man page
  - update debian/copyright with the newly added upstream source files
  - upstream is now widely using libtool, which is causing rpath and
    dependancies issues. libtool is really not needed for such a simple
    case so it has been patched out in favour of static linking:
    + updated debian/patches/avoid_libtool.patch to patch configure.in
      and Makefile.am instead of directly Makefile.in
    + debian/rules:
      - patch is now applied in the configure target
      - add aclocal/autoconf/automake calls in the configure target
    + debian/control:
      add autoconf and automake as Build-Depends
  - add debian/NEWS
* Update debian/copyright in line with updated proposal specification
* Add patch description to avoid_libtool.patch (thanks lintian)
* Remove deprecated dh_desktop call
* Use new dh_quilt_patch and dh_quilt_unpatch commands
* No change bump of Standards-Version to 3.8.1
* Changed Section to video (and debug for the dbg binary), in line
  with the new sections recently added to the Debian archive
* Use LDFLAGS=-Wl,--as-needed instead of specifying manually all libraries

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
 
2
/*
 
3
 * gmtk_media_tracker.c
 
4
 * Copyright (C) Kevin DeKorte 2009 <kdekorte@gmail.com>
 
5
 * 
 
6
 * gmtk_media_tracker.c is free software.
 
7
 * 
 
8
 * You may redistribute it and/or modify it under the terms of the
 
9
 * GNU General Public License, as published by the Free Software
 
10
 * Foundation; either version 2 of the License, or (at your option)
 
11
 * any later version.
 
12
 * 
 
13
 * gmtk_media_tracker.c is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
16
 * See the GNU General Public License for more details.
 
17
 * 
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with playlist.c.  If not, write to:
 
20
 *      The Free Software Foundation, Inc.,
 
21
 *      51 Franklin Street, Fifth Floor
 
22
 *      Boston, MA  02110-1301, USA.
 
23
 */
 
24
 
 
25
#include "gmtk_media_tracker.h"
 
26
#include "../../pixmaps/media-playback-start.xpm"
 
27
 
 
28
G_DEFINE_TYPE(GmtkMediaTracker, gmtk_media_tracker, GTK_TYPE_DRAWING_AREA);
 
29
 
 
30
static gboolean gmtk_media_tracker_expose(GtkWidget * meter, GdkEventExpose * event);
 
31
static gboolean gmtk_media_tracker_button_press(GtkWidget * tracker, GdkEventButton * event);
 
32
static gboolean gmtk_media_tracker_button_release(GtkWidget * tracker, GdkEventButton * event);
 
33
static gboolean gmtk_media_tracker_motion_notify(GtkWidget * tracker, GdkEventMotion * event);
 
34
static void gmtk_media_tracker_dispose(GObject * object);
 
35
 
 
36
static void gmtk_media_tracker_class_init(GmtkMediaTrackerClass * class)
 
37
{
 
38
    GtkWidgetClass *widget_class;
 
39
 
 
40
    widget_class = GTK_WIDGET_CLASS(class);
 
41
 
 
42
    widget_class->expose_event = gmtk_media_tracker_expose;
 
43
    widget_class->button_press_event = gmtk_media_tracker_button_press;
 
44
    widget_class->button_release_event = gmtk_media_tracker_button_release;
 
45
    widget_class->motion_notify_event = gmtk_media_tracker_motion_notify;
 
46
    G_OBJECT_CLASS(class)->dispose = gmtk_media_tracker_dispose;
 
47
}
 
48
 
 
49
static void gmtk_media_tracker_init(GmtkMediaTracker * tracker)
 
50
{
 
51
    GdkPixbuf *temp;
 
52
    GtkIconTheme *icon_theme;
 
53
    PangoLayout *p;
 
54
    gint pwidth, pheight;
 
55
 
 
56
    gtk_widget_add_events(GTK_WIDGET(tracker),
 
57
                          GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
 
58
                          GDK_POINTER_MOTION_MASK);
 
59
 
 
60
 
 
61
    tracker->text = NULL;
 
62
    tracker->media_percent = 0.0;
 
63
    tracker->cache_percent = 0.0;
 
64
 
 
65
    p = gtk_widget_create_pango_layout(GTK_WIDGET(tracker), "/^q");
 
66
    pango_layout_get_size(p, &pwidth, &pheight);
 
67
    pwidth = pwidth / PANGO_SCALE;
 
68
    pheight = pheight / PANGO_SCALE;
 
69
    GTK_WIDGET(tracker)->requisition.height = pheight + 16;
 
70
    GTK_WIDGET(tracker)->requisition.width = 128;
 
71
    g_object_unref(p);
 
72
 
 
73
    icon_theme = gtk_icon_theme_get_default();
 
74
    if (gtk_icon_theme_has_icon(icon_theme, "media-playback-start")) {
 
75
        temp = gtk_icon_theme_load_icon(icon_theme, "media-playback-start", 16, 0, NULL);
 
76
    } else if (gtk_icon_theme_has_icon(icon_theme, "stock_media-play")) {
 
77
        temp = gtk_icon_theme_load_icon(icon_theme, "stock_media-play", 16, 0, NULL);
 
78
    } else {
 
79
        temp = gdk_pixbuf_new_from_xpm_data((const char **) media_playback_start_xpm);
 
80
    }   
 
81
    tracker->thumb_lower = gdk_pixbuf_rotate_simple(temp, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
 
82
    tracker->thumb_upper = gdk_pixbuf_flip(tracker->thumb_lower, FALSE);
 
83
    gdk_pixbuf_unref(temp);
 
84
 
 
85
    tracker->position = THUMB_ON_BOTTOM;
 
86
        tracker->allow_expand = TRUE;
 
87
}
 
88
 
 
89
static void gmtk_media_tracker_dispose(GObject * object)
 
90
{
 
91
 
 
92
    GmtkMediaTracker *tracker;
 
93
 
 
94
    tracker = GMTK_MEDIA_TRACKER(object);
 
95
    if (tracker->text) {
 
96
        g_free(tracker->text);
 
97
        tracker->text = NULL;
 
98
    }
 
99
 
 
100
    if (GDK_IS_PIXBUF(tracker->thumb_upper)) {
 
101
        gdk_pixbuf_unref(tracker->thumb_upper);
 
102
        gdk_pixbuf_unref(tracker->thumb_lower);
 
103
    }
 
104
 
 
105
}
 
106
 
 
107
void draw(GtkWidget * tracker)
 
108
{
 
109
 
 
110
    gint cache_width = 0;
 
111
    gint handle_left = 0;
 
112
    PangoLayout *p;
 
113
    gint pwidth, pheight;
 
114
    gint ptop, pleft;
 
115
    gint x;
 
116
    gint half_thumb_size;
 
117
    gint bar_width;
 
118
 
 
119
    half_thumb_size = gdk_pixbuf_get_width(GMTK_MEDIA_TRACKER(tracker)->thumb_lower) / 2;
 
120
    bar_width =
 
121
        tracker->allocation.width - gdk_pixbuf_get_width(GMTK_MEDIA_TRACKER(tracker)->thumb_lower);
 
122
 
 
123
        // don't bother if there is nothing to draw
 
124
        if (bar_width < half_thumb_size * 2)
 
125
                return;
 
126
        
 
127
    // draw the cache bar first, everything is over it
 
128
    if (GMTK_MEDIA_TRACKER(tracker)->cache_percent > 0.0) {
 
129
        cache_width = bar_width * GMTK_MEDIA_TRACKER(tracker)->cache_percent;
 
130
 
 
131
        gdk_draw_rectangle(tracker->window,
 
132
                           tracker->style->mid_gc[3],
 
133
                           TRUE, half_thumb_size, 6, cache_width, tracker->allocation.height - 11);
 
134
 
 
135
    }
 
136
 
 
137
    // draw the progress bar next
 
138
    if (GMTK_MEDIA_TRACKER(tracker)->media_percent > 0.0) {
 
139
        cache_width = bar_width * GMTK_MEDIA_TRACKER(tracker)->media_percent;
 
140
 
 
141
        gdk_draw_rectangle(tracker->window,
 
142
                           tracker->style->light_gc[3],
 
143
                           TRUE, half_thumb_size, 6, cache_width, tracker->allocation.height - 11);
 
144
 
 
145
    }
 
146
 
 
147
        // draw the box and tick marks
 
148
    gdk_draw_rectangle(tracker->window,
 
149
                       tracker->style->dark_gc[0],
 
150
                       FALSE, half_thumb_size, 5, bar_width, tracker->allocation.height - 10);
 
151
 
 
152
        // if the thumb is hidden we can't seek so tickmarks are useless
 
153
        if (GMTK_MEDIA_TRACKER(tracker)->position == THUMB_HIDDEN && GMTK_MEDIA_TRACKER(tracker)->cache_percent == 0.0) {
 
154
                // don't draw it
 
155
        } else {
 
156
                for (x = half_thumb_size; x < bar_width; x = x + (bar_width / 10)) {
 
157
                        gdk_draw_line(tracker->window, tracker->style->dark_gc[0], x, 5, x, 8);
 
158
                        gdk_draw_line(tracker->window,
 
159
                                                  tracker->style->dark_gc[0], x, tracker->allocation.height - 5, x,
 
160
                                                  tracker->allocation.height - 8);
 
161
                }
 
162
        }
 
163
 
 
164
    // text over the background
 
165
    if (GMTK_MEDIA_TRACKER(tracker)->text) {
 
166
        p = gtk_widget_create_pango_layout(tracker, GMTK_MEDIA_TRACKER(tracker)->text);
 
167
        pango_layout_get_size(p, &pwidth, &pheight);
 
168
        pwidth = pwidth / PANGO_SCALE;
 
169
        pheight = pheight / PANGO_SCALE;
 
170
                if (pwidth > bar_width)  {
 
171
                        if (GMTK_MEDIA_TRACKER(tracker)->allow_expand) {
 
172
                                gtk_widget_set_size_request(tracker,(pwidth + 2 * half_thumb_size),-1);
 
173
                        } else {
 
174
                                pango_layout_set_width(p, bar_width);
 
175
                                pango_layout_set_ellipsize(p, PANGO_ELLIPSIZE_START);
 
176
                                pwidth = bar_width;
 
177
                        }
 
178
                }
 
179
                
 
180
        ptop = (tracker->allocation.height - pheight) / 2;
 
181
        pleft = (tracker->allocation.width - pwidth) / 2;
 
182
        gdk_draw_layout(tracker->window, tracker->style->text_gc[0], pleft, ptop + 1, p);
 
183
        g_object_unref(p);
 
184
    }
 
185
    // draw handle, draw it last so it sits on top
 
186
    handle_left = bar_width * GMTK_MEDIA_TRACKER(tracker)->media_percent;
 
187
    if (handle_left < 0)
 
188
        handle_left = 0;
 
189
    if (handle_left > bar_width + half_thumb_size)
 
190
        handle_left = bar_width + half_thumb_size;
 
191
    if (cache_width > 0)
 
192
        if ((handle_left) > cache_width)
 
193
            handle_left = cache_width;
 
194
 
 
195
    if (GMTK_MEDIA_TRACKER(tracker)->position == THUMB_ON_TOP ||
 
196
        GMTK_MEDIA_TRACKER(tracker)->position == THUMB_ON_TOP_AND_BOTTOM) {
 
197
 
 
198
        gdk_draw_pixbuf(tracker->window, NULL,
 
199
                        GMTK_MEDIA_TRACKER(tracker)->thumb_upper, 0, 0, handle_left,
 
200
                        0, -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
 
201
    }
 
202
 
 
203
    if (GMTK_MEDIA_TRACKER(tracker)->position == THUMB_ON_BOTTOM ||
 
204
        GMTK_MEDIA_TRACKER(tracker)->position == THUMB_ON_TOP_AND_BOTTOM) {
 
205
 
 
206
        gdk_draw_pixbuf(tracker->window, NULL,
 
207
                        GMTK_MEDIA_TRACKER(tracker)->thumb_lower, 0, 0, handle_left,
 
208
                        tracker->allocation.height -
 
209
                        gdk_pixbuf_get_height(GMTK_MEDIA_TRACKER(tracker)->thumb_lower) + 1, -1, -1,
 
210
                        GDK_RGB_DITHER_NONE, 0, 0);
 
211
    }
 
212
}
 
213
 
 
214
 
 
215
static gboolean gmtk_media_tracker_expose(GtkWidget * tracker, GdkEventExpose * event)
 
216
{
 
217
    draw(tracker);
 
218
    return FALSE;
 
219
}
 
220
 
 
221
static gboolean gmtk_media_tracker_button_press(GtkWidget * tracker, GdkEventButton * event)
 
222
{
 
223
    GMTK_MEDIA_TRACKER(tracker)->mouse_down = TRUE;
 
224
    return FALSE;
 
225
}
 
226
 
 
227
static gboolean gmtk_media_tracker_button_release(GtkWidget * tracker, GdkEventButton * event)
 
228
{
 
229
    gint half_thumb_size;
 
230
    gint bar_width;
 
231
 
 
232
    half_thumb_size = gdk_pixbuf_get_width(GMTK_MEDIA_TRACKER(tracker)->thumb_lower) / 2;
 
233
    bar_width =
 
234
        tracker->allocation.width - gdk_pixbuf_get_width(GMTK_MEDIA_TRACKER(tracker)->thumb_lower);
 
235
 
 
236
        if (GMTK_MEDIA_TRACKER(tracker)->position == THUMB_HIDDEN)
 
237
                return FALSE;
 
238
        
 
239
    GMTK_MEDIA_TRACKER(tracker)->media_percent = (event->x - half_thumb_size) / bar_width;
 
240
 
 
241
    if (GMTK_MEDIA_TRACKER(tracker)->media_percent > 1.0)
 
242
        GMTK_MEDIA_TRACKER(tracker)->media_percent = 1.0;
 
243
 
 
244
    if (GMTK_MEDIA_TRACKER(tracker)->cache_percent > 0.0)
 
245
        if (GMTK_MEDIA_TRACKER(tracker)->media_percent > GMTK_MEDIA_TRACKER(tracker)->cache_percent)
 
246
            GMTK_MEDIA_TRACKER(tracker)->media_percent = GMTK_MEDIA_TRACKER(tracker)->cache_percent;
 
247
 
 
248
    if (GTK_WIDGET(tracker)->window)
 
249
        gdk_window_invalidate_rect(GTK_WIDGET(tracker)->window, NULL, FALSE);
 
250
 
 
251
    GMTK_MEDIA_TRACKER(tracker)->mouse_down = FALSE;
 
252
    return FALSE;
 
253
}
 
254
 
 
255
static gboolean gmtk_media_tracker_motion_notify(GtkWidget * tracker, GdkEventMotion * event)
 
256
{
 
257
    gint half_thumb_size;
 
258
    gint bar_width;
 
259
 
 
260
    half_thumb_size = gdk_pixbuf_get_width(GMTK_MEDIA_TRACKER(tracker)->thumb_lower) / 2;
 
261
    bar_width =
 
262
        tracker->allocation.width - gdk_pixbuf_get_width(GMTK_MEDIA_TRACKER(tracker)->thumb_lower);
 
263
 
 
264
        if (GMTK_MEDIA_TRACKER(tracker)->position == THUMB_HIDDEN)
 
265
                return FALSE;
 
266
 
 
267
        
 
268
    if (GMTK_MEDIA_TRACKER(tracker)->mouse_down) {
 
269
        GMTK_MEDIA_TRACKER(tracker)->media_percent = (event->x - half_thumb_size) / bar_width;
 
270
 
 
271
        if (GMTK_MEDIA_TRACKER(tracker)->media_percent > 1.0)
 
272
            GMTK_MEDIA_TRACKER(tracker)->media_percent = 1.0;
 
273
 
 
274
        if (GMTK_MEDIA_TRACKER(tracker)->cache_percent > 0.0)
 
275
            if (GMTK_MEDIA_TRACKER(tracker)->media_percent >
 
276
                GMTK_MEDIA_TRACKER(tracker)->cache_percent)
 
277
                GMTK_MEDIA_TRACKER(tracker)->media_percent =
 
278
                    GMTK_MEDIA_TRACKER(tracker)->cache_percent;
 
279
 
 
280
        if (GTK_WIDGET(tracker)->window)
 
281
            gdk_window_invalidate_rect(GTK_WIDGET(tracker)->window, NULL, FALSE);
 
282
    }
 
283
    return FALSE;
 
284
}
 
285
 
 
286
GtkWidget *gmtk_media_tracker_new()
 
287
{
 
288
    return g_object_new(GMTK_TYPE_MEDIA_TRACKER, NULL);
 
289
}
 
290
 
 
291
 
 
292
void gmtk_media_tracker_set_percentage(GmtkMediaTracker * tracker, gdouble percentage)
 
293
{
 
294
    tracker->media_percent = percentage;
 
295
    if (tracker->media_percent > 1.0)
 
296
        tracker->media_percent = 1.0;
 
297
    if (tracker->media_percent < 0.0)
 
298
        tracker->media_percent = 0.0;
 
299
 
 
300
    if (GTK_WIDGET(tracker)->window)
 
301
        gdk_window_invalidate_rect(GTK_WIDGET(tracker)->window, NULL, FALSE);
 
302
}
 
303
 
 
304
gdouble gmtk_media_tracker_get_percentage(GmtkMediaTracker * tracker)
 
305
{
 
306
    return tracker->media_percent;
 
307
}
 
308
 
 
309
void gmtk_media_tracker_set_text(GmtkMediaTracker * tracker, const gchar * text)
 
310
{
 
311
    if (tracker->text) {
 
312
        g_free(tracker->text);
 
313
        tracker->text = NULL;
 
314
    }
 
315
 
 
316
    if (text)
 
317
        tracker->text = g_strdup(text);
 
318
 
 
319
    if (GTK_WIDGET(tracker)->window)
 
320
        gdk_window_invalidate_rect(GTK_WIDGET(tracker)->window, NULL, FALSE);
 
321
}
 
322
 
 
323
void gmtk_media_tracker_set_cache_percentage(GmtkMediaTracker * tracker, gdouble percentage)
 
324
{
 
325
    tracker->cache_percent = percentage;
 
326
 
 
327
    if (tracker->cache_percent > 1.0)
 
328
        tracker->cache_percent = 1.0;
 
329
    if (tracker->cache_percent < 0.0)
 
330
        tracker->cache_percent = 0.0;
 
331
 
 
332
    if (GTK_WIDGET(tracker)->window)
 
333
        gdk_window_invalidate_rect(GTK_WIDGET(tracker)->window, NULL, FALSE);
 
334
}
 
335
 
 
336
gdouble gmtk_media_tracker_get_cache_percentage(GmtkMediaTracker * tracker)
 
337
{
 
338
    return tracker->cache_percent;
 
339
}
 
340
 
 
341
void gmtk_media_tracker_set_thumb_position(GmtkMediaTracker * tracker, GmtkThumbPosition position)
 
342
{
 
343
    tracker->position = position;
 
344
}
 
345
 
 
346
void gmtk_media_tracker_set_allow_expand(GmtkMediaTracker * tracker, gboolean allow_expand)
 
347
{
 
348
        tracker->allow_expand = allow_expand;
 
349
}
 
 
b'\\ No newline at end of file'