public static void AdjustWindowSize(HuffLibrary.Tree HTree, DrawingArea Canvas)
 {
     int ImageWidth, ImageHeight;
     Canvas.SetSizeRequest (0, 0);
     //Reduce window size in case our tree is small
     GetAreaSize (HTree.GetRootNode (), out ImageWidth, out ImageHeight, cellsize);
     int width, height;
     Canvas.GdkWindow.GetSize (out width, out height);
     Canvas.SetSizeRequest (ImageWidth, ImageHeight);
     if (height > ImageHeight)
         Canvas.GdkWindow.Resize (width, ImageHeight);
 }
 void SaveToFile(HuffLibrary.Tree HTree, string title)
 {
     Gtk.FileChooserDialog dlg = new Gtk.FileChooserDialog (title, this, FileChooserAction.Save, Gtk.Stock.Cancel, ResponseType.Cancel, Gtk.Stock.Ok, ResponseType.Ok);
     Gtk.FileFilter filter = new Gtk.FileFilter ();
     filter.AddPattern ("*.png");
     dlg.Filter = filter;
     int ret = dlg.Run ();
     if (ret == (int)Gtk.ResponseType.Ok) {
         string filename = dlg.Filename;
         if (!filename.ToLower ().Contains (".png"))
             filename += ".png";
         TreeGraphics.DrawToFile (HTree, draw_options, filename);
     }
     dlg.Destroy ();
 }
 public static void DrawToFile(HuffLibrary.Tree HTree, DrawSettings Options, string FileName)
 {
     int width, height;
     GetAreaSize (HTree.GetRootNode (), out width, out height, 30);
     Gdk.Pixmap canvas = new Pixmap (null, width, height, 24);
     var bg_gc = new Gdk.GC (canvas);
     bg_gc.RgbFgColor = new Color (0, 0, 0);
     canvas.DrawRectangle (bg_gc, true, 0, 0, width, height);
     if (Options.draw_grid)
         DrawGrid (canvas, 30);
     var gc = new Gdk.GC (canvas);
     gc.RgbFgColor = new Color (255, 255, 0);
     priv_DrawList (gc, canvas, HTree.GetRootNode (), 0, 0, 0);
     Gdk.Pixbuf buffer = Gdk.Pixbuf.FromDrawable (canvas, Screen.Default.RgbColormap, 0, 0, 0, 0, width, height);
     buffer.Save (FileName, "png");
 }
 private static int priv_GetAreaSize(HuffLibrary.Node Root, int Padding, int Level, int Parent, ref int Width, ref int Height, int CellSize)
 {
     int ret = Level;
     Width = Math.Max (Width, (Padding + 1) * CellSize);
     Height = Math.Max (Height, (Level - Parent + 1) * 2 * CellSize);
     if (Root.right != null)
         ret = priv_GetAreaSize (Root.right, Padding + 1, Level + 1, Level, ref Width, ref Height, CellSize);
     if (Root.left != null)
         ret = priv_GetAreaSize (Root.left, Padding + 1, ret + 1, Level, ref Width, ref Height, CellSize);
     return ret;
 }
 public static void GetAreaSize(HuffLibrary.Node Root, out int Width, out int Height, int CellSize)
 {
     Width = Height = 0;
     priv_GetAreaSize (Root, 0, 0, 0, ref Width, ref Height, CellSize);
 }
 public static void DrawTree(HuffLibrary.Tree HTree, Gtk.DrawingArea Canvas, DrawSettings Options)
 {
     Canvas.GdkWindow.BeginPaintRegion (Canvas.GdkWindow.ClipRegion);
     Canvas.GdkWindow.Background = new Color (0, 0, 0);
     if (Options.draw_grid)
         DrawGrid (Canvas.GdkWindow, cellsize);
     DrawList (Canvas.GdkWindow, HTree.GetRootNode ());
     Canvas.GdkWindow.EndPaint ();
 }