#include <stdio.h>

#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/graphics_protos.h>
#include <clib/feelin_protos.h>

#include <graphics/gfxmacros.h>
#include <libraries/feelin.h>

struct FeelinBase *FeelinBase;

///drawfunc
void ASM SAVEDS drawfunc(REG_A0 struct FeelinRender *Render,REG_A2 struct FeelinRect *Region)
{
   UWORD x1,y1,x2,y2,x3;
   ULONG ap,bp;
   struct RastPort *rp;

   static UWORD pt[] = {0xFF00,0x7F80,0x3FC0,0x1FE0,
                        0x0FF0,0x07F8,0x03FC,0x01FE,
                        0x00FF,0x807F,0xC03F,0xE01F,
                        0xF00F,0xF807,0xFC03,0xFE01};

   static UWORD zr[] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF};

   x1 = Region->x1 ; x3 = Region->x2 ; x2 = (x3 - x1) / 3 + x1;
   y1 = Region->y1 ; y2 = Region->y2 ; rp = Render->psRPort;

   ap = Render->pnPens[FV_Pen_Fill];
   bp = Render->pnPens[FV_Pen_HalfShadow];

   _APen(bp);
   _Boxf(x1,y1,x2,y2);

   SetAfPt(rp,pt,4);
   _APen(ap);
   _BPen(bp);
   _Boxf(x2+1,y1,x3,y2);
   SetAfPt(rp,zr,2);
}
//+

///Main
void main()
{
   APTR c,w;
   static STRPTR font = "Garnet/16";
   static char myback[16];

   sprintf(myback,"F:%lx\0",&drawfunc);

   if (FeelinBase = (struct FeelinBase *)OpenLibrary("feelin.library",3))
   {
      c = ClientObject,
         Child, w = WindowObject, FA_Window_Title, "Feelin with C",
            FA_Back, myback,

            Child, HGroup,
               Child, TextObject, FA_Font,font, FA_Back,"c:FF0000", FA_AltBack,"c:FF8080", FA_Text,"Red",   InputRelease, End,
               Child, TextObject, FA_Font,font, FA_Back,"c:00FF00", FA_AltBack,"c:80FF80", FA_Text,"Green", InputRelease, End,
               Child, TextObject, FA_Font,font, FA_Back,"c:0000FF", FA_AltBack,"c:8080FF", FA_Text,"Blue",  InputRelease, End,
            End,
         End,
      End;

      if (c)
      {
         F_Do(c,FM_Notify, FA_Client_Signal,0x1000, FV_Notify_Self, 2,FM_Client_ReturnID,FV_Client_Quit);
         F_Do(w,FM_Notify, FA_Window_CloseRequest,TRUE, FV_Notify_Client, 2,FM_Client_ReturnID,FV_Client_Quit);

         F_Set(w,FA_Window_Open,TRUE);

         F_DoA(c,FM_Client_Run,NULL);

         F_DisposeObj(c);
      }

      CloseLibrary((struct Library *)FeelinBase);
   }
   else
   {
      Printf("Unable to open feelin.library\n");
   }
}
//+
