~dobey/ubuntu/natty/banshee/fix-and-amz

« back to all changes in this revision

Viewing changes to src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-01-28 23:52:53 UTC
  • mto: (6.4.6 sid) (1.14.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20100128235253-qyw3pkf2vw7ld3kg
ImportĀ upstreamĀ versionĀ 1.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
{
49
49
    public abstract class TrackInfoDisplay : Widget
50
50
    {
 
51
        private string current_artwork_id;
 
52
 
51
53
        private ArtworkManager artwork_manager;
52
54
        protected ArtworkManager ArtworkManager {
53
55
            get { return artwork_manager; }
123
125
            WidgetFlags |= WidgetFlags.NoWindow;
124
126
        }
125
127
 
 
128
        public static Widget GetEditable (TrackInfoDisplay display)
 
129
        {
 
130
            return CoverArtEditor.For (display,
 
131
                (x, y) => display.IsWithinCoverart (x, y),
 
132
                () => display.CurrentTrack,
 
133
                () => {}
 
134
            );
 
135
        }
 
136
 
126
137
        public override void Dispose ()
127
138
        {
128
139
            if (idle_timeout_id > 0) {
157
168
        {
158
169
            base.OnSizeAllocated (allocation);
159
170
 
 
171
            if (missing_audio_image != null) {
 
172
                ((IDisposable)missing_audio_image).Dispose ();
 
173
                missing_audio_image = null;
 
174
            }
 
175
 
 
176
            if (missing_video_image != null) {
 
177
                ((IDisposable)missing_video_image).Dispose ();
 
178
                missing_video_image = null;
 
179
            }
 
180
 
160
181
            if (current_track == null) {
161
182
                LoadCurrentTrack ();
162
183
            } else {
163
 
                LoadImage (current_track);
 
184
                Invalidate ();
164
185
            }
165
186
        }
166
187
 
242
263
                return;
243
264
            }
244
265
 
245
 
            // XFade only the cover art
246
 
            RenderCoverArt (cr, incoming_image);
247
 
 
 
266
            // Draw the old cover art more and more translucent
248
267
            CairoExtensions.PushGroup (cr);
249
268
            RenderCoverArt (cr, current_image);
250
269
            CairoExtensions.PopGroupToSource (cr);
251
 
 
252
270
            cr.PaintWithAlpha (1.0 - stage.Actor.Percent);
253
271
 
254
 
            // Fade in/out the text
 
272
            // Draw the new cover art more and more opaque
 
273
            CairoExtensions.PushGroup (cr);
 
274
            RenderCoverArt (cr, incoming_image);
 
275
            CairoExtensions.PopGroupToSource (cr);
 
276
            cr.PaintWithAlpha (stage.Actor.Percent);
 
277
 
255
278
            bool same_artist_album = incoming_track != null ? incoming_track.ArtistAlbumEqual (current_track) : false;
256
279
            bool same_track = incoming_track != null ? incoming_track.Equals (current_track) : false;
257
280
 
259
282
                RenderTrackInfo (cr, incoming_track, same_track, true);
260
283
            }
261
284
 
 
285
            // Don't xfade the text since it'll look bad (overlapping words); instead, fade
 
286
            // the old out, and then the new in
262
287
            if (stage.Actor.Percent <= 0.5) {
263
288
                // Fade out old text
264
289
                CairoExtensions.PushGroup (cr);
286
311
        {
287
312
            ArtworkRenderer.RenderThumbnail (cr, image, false, Allocation.X, Allocation.Y,
288
313
                ArtworkSizeRequest, ArtworkSizeRequest,
289
 
                !IsMissingImage (image), 0,
 
314
                !IsMissingImage (image), 0.0,
290
315
                IsMissingImage (image), BackgroundColor);
291
316
        }
292
317
 
 
318
        protected virtual bool IsWithinCoverart (int x, int y)
 
319
        {
 
320
            return x >= Allocation.X && y >= Allocation.Y &&
 
321
                x <= (Allocation.X + ArtworkSizeRequest) && y <= (Allocation.Y + ArtworkSizeRequest);
 
322
        }
 
323
 
293
324
        protected bool IsMissingImage (ImageSurface pb)
294
325
        {
295
326
            return pb == missing_audio_image || pb == missing_video_image;
306
337
        }
307
338
 
308
339
        protected virtual int MissingIconSizeRequest {
309
 
            get { return 32; }
 
340
            get { return ArtworkSizeRequest; }
310
341
        }
311
342
 
312
343
        private void OnPlayerEvent (PlayerEventArgs args)
329
360
 
330
361
        private bool IdleTimeout ()
331
362
        {
332
 
            if (ServiceManager.PlayerEngine.CurrentTrack == null ||
 
363
            if (ServiceManager.PlayerEngine == null ||
 
364
                ServiceManager.PlayerEngine.CurrentTrack == null ||
333
365
                ServiceManager.PlayerEngine.CurrentState == PlayerState.Idle) {
334
366
                incoming_track = null;
335
367
                incoming_image = null;
362
394
 
363
395
            incoming_track = track;
364
396
 
365
 
            LoadImage (track);
 
397
            LoadImage (track, force_reload);
366
398
 
367
399
            if (stage.Actor == null) {
368
400
                stage.Reset ();
369
401
            }
370
402
        }
371
403
 
372
 
        private void LoadImage (TrackInfo track)
 
404
        private void LoadImage (TrackInfo track, bool force)
373
405
        {
374
 
            ImageSurface image = artwork_manager.LookupScaleSurface (track.ArtworkId, ArtworkSizeRequest);
 
406
            string artwork_id = track.ArtworkId;
 
407
            if (current_artwork_id != artwork_id || force) {
 
408
                current_artwork_id = artwork_id;
 
409
                incoming_image = artwork_manager.LookupScaleSurface (artwork_id, ArtworkSizeRequest);
 
410
            }
375
411
 
376
 
            if (image == null) {
377
 
                LoadMissingImage ((track.MediaAttributes & TrackMediaAttributes.VideoStream) != 0);
378
 
            } else {
379
 
                incoming_image = image;
 
412
            if (incoming_image == null) {
 
413
                incoming_image = MissingImage (track.HasAttribute (TrackMediaAttributes.VideoStream));
380
414
            }
381
415
 
382
416
            if (track == current_track) {
384
418
            }
385
419
        }
386
420
 
387
 
        private void LoadMissingImage (bool is_video)
 
421
        private ImageSurface MissingImage (bool is_video)
388
422
        {
389
 
            incoming_image = is_video ? MissingVideoImage : MissingAudioImage;
 
423
            return is_video ? MissingVideoImage : MissingAudioImage;
390
424
        }
391
425
 
392
426
        private double last_fps = 0.0;