/* * AlbumArt Banshee Plugin, Copyright (c) 2006 Nick Bargnesi * nick at den-4.com * * THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * Author's note: * AlbumArt, specifically the CoverArtPopup class borrows heavily from the * CoverArtThumbnail.cs class, found in the Banshee.Widgets package. * The original copyright is reproduced here. * * /*************************************************************************** * * CoverArtThumbnail.cs * * * * Copyright (C) 2005 Novell * * Written by Aaron Bockover (aaron@aaronbock.net) * **************************************************************************** */ using System; using Gtk; using Gdk; namespace Banshee.Plugins.AlbumArt { public class CoverArtPopup : Gtk.Window { /// The CD case private Gtk.Image image; /// The horizontal size of the popup private int hSize; /// The vertical size of the popup private int vSize; /// The horizontal gap from the left edge of the cd case to the artwork private int hGap; /// The cd case this popup is using. private int cd; /// Constructs a CoverArtPopup. /// the size of the popup in pixels /// true if the window should stay below others, false otherwise public CoverArtPopup(int size, int cd, bool keepBelow) : base(Gtk.WindowType.Toplevel) { this.cd = cd; int adjustedHSize = (int) (size / 8.7); hGap = (int) (size / 11.3); this.hSize = size + adjustedHSize; this.vSize = size; this.SetDefaultSize(hSize, vSize); VBox vbox = new VBox(); Add(vbox); Decorated = false; Resizable = false; KeepBelow = keepBelow; SkipPagerHint = true; SkipTaskbarHint = true; TypeHint = Gdk.WindowTypeHint.Splashscreen; image = new Gtk.Image(); ModifyBg(StateType.Normal, new Color(0, 0, 0)); ModifyFg(StateType.Normal, new Color(160, 160, 160)); vbox.PackStart(image, true, true, 0); vbox.Spacing = 6; vbox.ShowAll(); } /// Creates a resized CD case and artwork thumbnail Pixbuf from the specified source pixbuf. /// cd Pixbuf /// art Pixbuf private void CreateThumbnails(Pixbuf p1, Pixbuf p2) { // We create four separate layers, layering pixbuf on top of pixbuf: // 1: black, size hSize x vSize // 2: grey, size hSize-2 x vSize-2 Pixbuf c1 = new Pixbuf(Gdk.Colorspace.Rgb, true, 8, hSize, vSize); c1.Fill(0xffffff88); //Pixbuf c2 = new Pixbuf(Gdk.Colorspace.Rgb, true, 8, hSize - 2, vSize - 2); //c2.Fill(0xffffff88); //c2.CopyArea(0, 0, c2.Width, c2.Height, c1, 1, 1); // 3: cd, size hSize-4 x vSize-4 // 4: artwork, size hSize-6 x vSize-6 Pixbuf cd = p1.ScaleSimple(hSize, vSize, InterpType.Hyper); //cd.CopyArea(0, 0, cd.Width, cd.Height, c1, 2, 2); cd.CopyArea(0, 0, cd.Width, cd.Height, c1, 0, 0); if (p2 != null) { //Pixbuf art = p2.ScaleSimple(hSize - (hGap + 12), vSize - 8, InterpType.Hyper); //art.CopyArea(0, 0, art.Width, art.Height, c1, (hGap + 6), 4); Pixbuf art = p2.ScaleSimple(hSize - (hGap + 4), vSize - 4, InterpType.Hyper); art.CopyArea(0, 0, art.Width, art.Height, c1, (hGap + 2), 2); } image.Pixbuf = c1; } /// Sets the CD case and artwork Pixbufs for this CoverArtPopup to the specified pixbufs. /// Pixbuf public void SetPixbufs(Pixbuf p1, Pixbuf p2) { CreateThumbnails(p1, p2); } /// Returns the size of the popup as it was during construction. internal int Size { get { return vSize; } } /// Returns the cd cas of the popup as it was during construction. internal int CD { get { return cd; } } } } // vim:ts=4:sw=4