// // Copyright (C) 2008-2009 Jordi Mas i Hernandez, jmas@softcatala.org // // 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. // using System; using System.Runtime.InteropServices; using System.Text; using System.IO; using System.Collections.Generic; using Mistelix.DataModel; using Mistelix.Core; namespace Mistelix.Backends { // // Generates XML file for Spumux command line tool // public class Spumux { const string menu_normal = "menu_normal.png"; const string menu_highlight = "menu_highlight.png"; Project project; public Spumux (Project project) { this.project = project; } public void Create () { StringBuilder sb = new StringBuilder (2048); sb.Append ("\n"); sb.Append (" \n"); sb.Append (" \n"); sb.Append (GenerateMenus ()); sb.Append (" \n"); sb.Append (" \n"); sb.Append (" \n"); try { using (FileStream fs = File.Create (project.FileToFullPath (Defines.SPUMUX_FILE))) { StreamWriter sw = new StreamWriter (fs); sw.Write (sb.ToString ()); sw.Close (); } } catch (IOException) { Logger.Error ("Spumux.Create. Error accessing file {0}", project.FileToFullPath (Defines.SPUMUX_FILE)); } } public void Destroy () { if (Mistelix.Debugging == false) { File.Delete (project.FileToFullPath (menu_normal)); File.Delete (project.FileToFullPath (menu_highlight)); File.Delete (project.FileToFullPath (Defines.SPUMUX_FILE)); } } void DrawButtons (Button button, Cairo.Context high, Cairo.Context normal) { // The coordinates should match what we provide to Spumux DrawImageFromFile (normal, Path.Combine (Defines.DATA_DIR, project.Details.Theme.ButtonSelect), button.X, button.Y, button.DrawingBoxWidth, button.DrawingBoxHeight); DrawImageFromFile (high, Path.Combine (Defines.DATA_DIR, project.Details.Theme.ButtonHighlight), button.X, button.Y, button.DrawingBoxWidth, button.DrawingBoxHeight); } public void DrawImageFromFile (Cairo.Context cr, string filename, double x, double y, double width, double height) { SvgImage image; if (width <= 0 || height <= 0) throw new ArgumentException (String.Format ("Spumux->DrawImageFromFile. DVD menu buttons width {0} and height {1} should be > 0", width, height)); try { image = new SvgImage (filename); } catch (Exception) { Logger.Error ("Spumux.DrawImageFromFile. Error loading file {0}", filename); return; } Logger.Debug ("Spumux.DrawImageFromFile. Loaded file {0}, w:{1} h:{2}", filename, image.Width, image.Height); cr.Save (); // Have to clip for RenderToCairo cr.Rectangle (x, y, width, height); cr.Clip (); cr.Translate (x, y); cr.Scale (width / image.Width, height / image.Height); image.RenderToCairo (cr.Handle); cr.Restore (); image.Dispose (); } string GenerateMenus () { StringBuilder sb = new StringBuilder (2048); Cairo.ImageSurface shigh = new Cairo.ImageSurface (Cairo.Format.ARGB32, project.Details.Width, project.Details.Height); Cairo.Context chight = new Cairo.Context (shigh); Cairo.ImageSurface snormal = new Cairo.ImageSurface (Cairo.Format.ARGB32, project.Details.Width, project.Details.Height); Cairo.Context cnormal = new Cairo.Context (snormal); for (int i = 0; i < project.Buttons.Count; i++) { Button button = (Button)project.Buttons [i]; sb.Append ("