#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>                   // Windows.
#include "iup.h"
#include "cd.h"
#include "cdiup.h"


/*
---prototypes()
*/

int cdImagePreviewRedraw
(
   Ihandle *self, float x, float y
);

/*
---GLOBALS()
*/

cdCanvas       *cd     = NULL;

/*
...main()
*/
int main
(
   int   iArgs    ,
   char *apsArgs[]
)
{
   Ihandle *dlg       = NULL;
   Ihandle *cdPreview = NULL;


   // Initialize the IUP libraries

   if (IUP_ERROR == IupOpen (&iArgs, &apsArgs))
  	   exit (printf ("IupOpen() failed"));



   cdPreview = IupCanvas ("cdPreview");
   if (NULL == cdPreview)
  	   return (printf ("IupCanvas() failed"));
   IupSetCallback   (cdPreview, "ACTION", (Icallback) cdImagePreviewRedraw);
   IupSetAttributes (cdPreview, "EXPAND=YES, SIZE=100x100" );


   dlg = IupDialog (IupVbox( cdPreview, NULL ));


   IupSetAttribute ( dlg, "TITLE", "Canvas Test");
   IupSetAttributes( dlg, "RESIZE=YES, MINSIZE=450x300" );
   IupMap( dlg );

   cd = cdCreateCanvas (CD_IUP, cdPreview);
   cdCanvasForeground  (cd, CD_BLUE);

   IupShowXY       ( dlg, IUP_CENTER, IUP_CENTER );

   // Start the application event system.

   IupMainLoop();
   IupDestroy (dlg);
   IupClose();


   return (0);
}

/*
...cdImagePreviewRedraw()

  Update the canvas with the gdimage pointer data.

*/
int cdImagePreviewRedraw
(
   Ihandle *self,
   float    x,
   float    y
)
{
   printf ("redraw\n");

   cdCanvasActivate  (cd);
   cdCanvasClear     (cd);
   cdCanvasForeground(cd, CD_BLUE);
   cdCanvasBox       (cd, 0, 100, 0, 100);

   return (0);
}
