# include "Ximage.h"

bDrawBuffer *bDrawIt (png_color *palette, int Npalette, int Nbyte) {

  int i, Nsection;
  bDrawBuffer *buffer;
  bDrawColor black;
  Graphic *graphic;
  Section *section;

  graphic = GetGraphic();

  black = KapaColorByName ("black");

  // SectionMinBoundary (graphic);

  // if we want to trim, we'll need to carry about the start in graphic coords and
  // the dx,dy size.  
  buffer = bDrawBufferCreate (graphic->dxwin, graphic->dywin, Nbyte, palette, Npalette);
  bDrawSetStyle (buffer, black, 0, 0);
  
  // reset the sizes for all sections
  Nsection = GetNumberOfSections ();
  for (i = 0; i < Nsection; i++) {
      section = GetSectionByNumber (i);
      bDrawImage (buffer, section->image, graphic);
      bDrawGraph (buffer, section->graph);
  }

  return (buffer);
}

void bDrawGraph (bDrawBuffer *buffer, KapaGraphWidget *graph) {
  if (graph == NULL) return;
  bDrawFrame (buffer, graph); 
  bDrawObjects (buffer, graph);
  bDrawLabels (buffer, graph);
  bDrawTextlines (buffer, graph);
}
