
#c_source

#include <proto/graphics.h>

#define RED   1
#define GREEN 2
#define BLUE  3

int PaletteHook(struct IntuiMessage *msg);
int RedHook(struct IntuiMessage *msg);
int GreenHook(struct IntuiMessage *msg);
int BlueHook(struct IntuiMessage *msg);

/* We cannot write this function here, since some values of the GUI are
   not declared/defined yet, but we need the prototype */

int ActiveColor=0;
int Red;
int Green;
int Blue;

#end_source

ProjectName InnerField

HBox
   XSpace INTERWIDTH
   YSpace INTERHEIGHT

   vbox
      xchar 3*2
      xpix  2*INTERWIDTH+3*4  // 2 * Spacing + 3 Sliders

      hbox
         Slider
            xchar 2
            xpix  4
            id RED
            hook RedHook
            tags PGA_Freedom,LORIENT_VERT
            tags GTSL_LevelPlace,PLACETEXT_BELOW
            tags GTSL_LevelFormat,(ULONG)"%2ld"
            tags GTSL_MaxLevelLen,2
         end
         Slider
            xchar 2
            xpix  4
            id GREEN
            hook GreenHook
            tags PGA_Freedom,LORIENT_VERT
            tags GTSL_LevelPlace,PLACETEXT_BELOW
            tags GTSL_LevelFormat,(ULONG)"%2ld"
            tags GTSL_MaxLevelLen,2
         end
         Slider
            xchar 2
            xpix  4
            id BLUE
            hook BlueHook
            tags PGA_Freedom,LORIENT_VERT
            tags GTSL_LevelPlace,PLACETEXT_BELOW
            tags GTSL_LevelFormat,(ULONG)"%2ld"
            tags GTSL_MaxLevelLen,2
         end
      end
      vbox
         stdline 1
      end
   end
   palette
      id 0
      hook PaletteHook
      tags GTPA_Depth,2
      tags GTPA_IndicatorWidth,20
   end
end


#c_source

int PaletteHook(struct IntuiMessage *msg)
{
   ULONG rgb;

   if(msg) ActiveColor=msg->Code; // This function is also called from
                                  // Custom(), then msg is 0

   rgb=GetRGB4(InnerField.Window->WScreen->ViewPort.ColorMap,ActiveColor);

   Red=rgb>>8;
   rgb&=0xff;
   Green=rgb>>4;
   rgb&=0xf;
   Blue=rgb;

   Gui_SetGadgetAttrs(InnerField_Gadgets[InnerField_RED],InnerField.Window,NULL,
                     GTSL_Level,Red,TAG_DONE);
   Gui_SetGadgetAttrs(InnerField_Gadgets[InnerField_GREEN],InnerField.Window,NULL,
                     GTSL_Level,Green,TAG_DONE);
   Gui_SetGadgetAttrs(InnerField_Gadgets[InnerField_BLUE],InnerField.Window,NULL,
                     GTSL_Level,Blue,TAG_DONE);

   /* IMPORTANT! You must store the values also in the "Code" field of the
      Gadinfo structure, or it would not be vailable for resizing */

#if 0
   GetInfo(InnerField_Gadgets[InnerField_RED])->Code=Red;
   GetInfo(InnerField_Gadgets[InnerField_GREEN])->Code=Green;
   GetInfo(InnerField_Gadgets[InnerField_BLUE])->Code=Blue;
#endif

   return(1);
}

int RedHook(struct IntuiMessage *msg)
{
   Red=msg->Code;
   SetRGB4(&InnerField.Window->WScreen->ViewPort,ActiveColor,Red,Green,Blue);
   return(1);
}


int GreenHook(struct IntuiMessage *msg)
{
   Green=msg->Code;
   SetRGB4(&InnerField.Window->WScreen->ViewPort,ActiveColor,Red,Green,Blue);
   return(1);
}

int BlueHook(struct IntuiMessage *msg)
{
   Blue=msg->Code;
   SetRGB4(&InnerField.Window->WScreen->ViewPort,ActiveColor,Red,Green,Blue);
   return(1);
}


#end_source

#c_source

int Custom(struct WinInfo *winfo,
                     struct NewGadget *ng,
                     struct GadInfo *gad,
                     int left, int top, int width, int height)
{
   int ret;

   if(winfo->Render) {
            SetAPen(winfo->Window->RPort,0);
            RectFill(winfo->Window->RPort,ng->ng_LeftEdge,ng->ng_TopEdge,
                                     ng->ng_LeftEdge+ng->ng_Width-1,
                                     ng->ng_TopEdge+ng->ng_Height-1);
            DrawBevelBox(winfo->Window->RPort,ng->ng_LeftEdge,ng->ng_TopEdge,
                                     ng->ng_Width,ng->ng_Height,
                                     GT_VisualInfo,winfo->Visual,TAG_DONE);
   }

   ret=SubGui(winfo,&InnerField,ng->ng_LeftEdge,ng->ng_TopEdge,
                                        ng->ng_Width,ng->ng_Height);
   if(ret==0 && winfo->Mode==MODE_NEW) { // additional initialisation
      PaletteHook(NULL);
   }
   return(ret);
}

#end_source


projectname TestPro

vbox
   custom
      custom Custom
      id 99
   end

   hbox
      stdline 1
      button
         text "OK"
         id 4
      end
      vbox
      end
      button
         text "Cancel"
         id 5
      end
   end
end


