okey here it is:
void ColorRequester(struct Window *win, uint32 *red, uint32 *green, uint32 *blue)
{
BOOL close = FALSE;
UWORD code;
ULONG eid;
ULONG wait,prq;
uint32 lred=*red, lgreen=*green, lblue=*blue; // Currently selected color
uint32 llred=0, llgreen=0, llblue=0; // Color selected last iteration
uint32 sred=0,sgreen=0,sblue=0; // slider positions last iteration
Object *reqobj;
struct Window *req;
struct MsgPort *appport = IExec->CreateMsgPort();
struct Screen *appscreen = IIntuition->LockPubScreen(NULL);
// Gadgets
enum
{
GID_REQ_MAIN=0,
GID_REQ_WHEEL,
GID_REQ_SLIDER,
GID_REQ_NEWPEN,
GID_REQ_OLDPEN,
GID_REQ_REDSLIDER,
GID_REQ_GREENSLIDER,
GID_REQ_BLUESLIDER,
GID_REQ_SELECT,
GID_REQ_CANCEL,
GID_REQ_END
};
struct Gadget *gadgets[GID_REQ_END];
// Pen storage
uint16 Pen[3]; // For brightness slider
uint16 PenRed[3]; // For red slider
uint16 PenGreen[3]; // For green slider
uint16 PenBlue[3]; // For blue slider
uint16 OldPen; // For old color button
uint16 NewPen; // For new color button
// Color for old pen button
OldPen = IGraphics->ObtainPen(
appscreen->ViewPort.ColorMap, -1,
*red,
*green,
*blue,
PENF_EXCLUSIVE);
// Color for new pen button
NewPen = IGraphics->ObtainPen(
appscreen->ViewPort.ColorMap, -1,
*red,
*green,
*blue,
PENF_EXCLUSIVE);
// Brightness slider
Pen[0] = IGraphics->ObtainPen(
appscreen->ViewPort.ColorMap, -1,
0xffffffff,
0xffffffff,
0xffffffff,
PENF_EXCLUSIVE);
Pen[1] = IGraphics->ObtainPen(
appscreen->ViewPort.ColorMap, -1,
0x00000000,
0x00000000,
0x00000000,
PENF_EXCLUSIVE);
Pen[2]=~0;
//Red Slider
PenRed[1] = IGraphics->ObtainPen(
appscreen->ViewPort.ColorMap, -1,
0xffffffff, 0 , 0,
PENF_EXCLUSIVE);
PenRed[0] = Pen[1];
PenRed[2]=~0;
//Green Slider
PenGreen[1] = IGraphics->ObtainPen(
appscreen->ViewPort.ColorMap, -1,
0, 0xffffffff, 0,
PENF_EXCLUSIVE);
PenGreen[0] = Pen[1];
PenGreen[2]=~0;
//Blue Slider
PenBlue[1] = IGraphics->ObtainPen(
appscreen->ViewPort.ColorMap, -1,
0, 0, 0xffffffff,
PENF_EXCLUSIVE);
PenBlue[0] = Pen[1];
PenBlue[2]=~0;
// Allocate brightness gradient slider.
gadgets[GID_REQ_SLIDER] = GradientObject,
PGA_Freedom, LORIENT_VERT,
GRAD_PenArray, Pen,
End;
reqobj = WindowObject,
WA_Height,160,
WA_Width, 160,
WA_SizeGadget, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_Activate, TRUE,
WA_AutoAdjust, TRUE,
WA_Title, "Select color",
WA_ScreenTitle, (STRPTR)ILocale->GetCatalogStr(Catalog,LOCALE_TITLE_WINDOWSCREEN2,LOCALE_TITLE_WINDOWSCREEN2_STR),
WA_PubScreen, appscreen,
WA_IDCMP, IDCMP_INTUITICKS,
WINDOW_RefWindow, win,
WINDOW_Position, WPOS_CENTERWINDOW,
WINDOW_GadgetHelp, FALSE,
WINDOW_IconifyGadget, FALSE,
WINDOW_SharedPort, appport,
WINDOW_ParentGroup, gadgets[GID_REQ_MAIN] = VGroupObject,
LAYOUT_AddChild, VGroupObject,
LAYOUT_BevelStyle, BVS_GROUP,
LAYOUT_Label, "Select Color",
LAYOUT_AddChild, HGroupObject,
LAYOUT_AddChild, HGroupObject,
LAYOUT_AddChild, gadgets[GID_REQ_WHEEL] = ColorWheelObject,
GA_ID, GID_REQ_WHEEL,
WHEEL_Red, *red,
WHEEL_Green, *green,
WHEEL_Blue, *blue,
WHEEL_Screen, appscreen,
WHEEL_GradientSlider,gadgets[GID_REQ_SLIDER],
ColorWheelEnd,
LAYOUT_AddChild, gadgets[GID_REQ_SLIDER],
LAYOUT_AddChild, gadgets[GID_REQ_NEWPEN] = ButtonObject,
GA_ID, GID_REQ_NEWPEN,
BUTTON_BackgroundPen, NewPen,
GA_RelVerify, TRUE,
ButtonEnd,
LAYOUT_AddChild, gadgets[GID_REQ_OLDPEN] = ButtonObject,
GA_ID, GID_REQ_OLDPEN,
BUTTON_BackgroundPen, OldPen,
GA_RelVerify, TRUE,
ButtonEnd,
LayoutEnd,
LayoutEnd,
LAYOUT_AddChild, VGroupObject,
LAYOUT_FixedVert, FALSE,
LAYOUT_AddChild, gadgets[GID_REQ_REDSLIDER] = GradientObject,
GA_ID, GID_REQ_REDSLIDER,
PGA_Freedom, LORIENT_HORIZ,
GRAD_PenArray, PenRed,
GRAD_CurVal, *red>>16,
GRAD_MaxVal, 0xFFFF,
End,
LAYOUT_AddChild, gadgets[GID_REQ_GREENSLIDER] = GradientObject,
GA_ID, GID_REQ_GREENSLIDER,
PGA_Freedom, LORIENT_HORIZ,
GRAD_PenArray, PenGreen,
GRAD_CurVal, *green>>16,
GRAD_MaxVal, 0xFFFF,
End,
LAYOUT_AddChild, gadgets[GID_REQ_BLUESLIDER] = GradientObject,
GA_ID, GID_REQ_BLUESLIDER,
PGA_Freedom, LORIENT_HORIZ,
GRAD_PenArray, PenBlue,
GRAD_CurVal, *blue>>16,
GRAD_MaxVal, 0xFFFF,
End,
LayoutEnd,
LayoutEnd,
LAYOUT_AddChild, HGroupObject,
LAYOUT_FixedVert, FALSE,
LAYOUT_AddChild, HGroupObject,
LAYOUT_FixedHoriz, FALSE,
LAYOUT_HorizAlignment, LALIGN_LEFT,
LAYOUT_AddChild, gadgets[GID_REQ_SELECT] = ButtonObject,
GA_ID, GID_REQ_SELECT,
GA_RelVerify, TRUE,
GA_Text,"Select",
ButtonEnd,
LayoutEnd,
LAYOUT_AddChild, HGroupObject,
LAYOUT_FixedHoriz, FALSE,
LAYOUT_HorizAlignment, LALIGN_RIGHT,
LAYOUT_AddChild, gadgets[GID_REQ_CANCEL] = ButtonObject,
GA_ID, GID_REQ_CANCEL,
GA_RelVerify, TRUE,
GA_Text,"Cancel",
ButtonEnd,
LayoutEnd,
LayoutEnd,
LayoutEnd,
EndWindow;
if(reqobj!=0)
{
IIntuition->SetWindowAttrs(win, WA_BusyPointer, TRUE, TAG_DONE);
req = (struct Window *) RA_OpenWindow(reqobj);
prq = (1L << appport->mp_SigBit);
while(!close)
{
wait = IExec->Wait( SIGBREAKF_CTRL_C | prq);
if ( wait & prq )
{
while((eid = RA_HandleInput(reqobj, &code)) != WMHI_LASTMSG)
{
switch(eid & WMHI_CLASSMASK)
{
case WMHI_GADGETUP:
switch(eid & WMHI_GADGETMASK)
{
case GID_REQ_CANCEL:
close=TRUE;
break;
case GID_REQ_SELECT: // New color selected
close=TRUE;
IIntuition->GetAttrs(gadgets[GID_REQ_WHEEL],WHEEL_Red,red,TAG_DONE);
IIntuition->GetAttrs(gadgets[GID_REQ_WHEEL],WHEEL_Green,green,TAG_DONE);
IIntuition->GetAttrs(gadgets[GID_REQ_WHEEL],WHEEL_Blue,blue,TAG_DONE);
break;
case GID_REQ_OLDPEN: // Change back to old color
IIntuition->SetGadgetAttrs(gadgets[GID_REQ_WHEEL],req,NULL,
WHEEL_Red, *red,
WHEEL_Green, *green,
WHEEL_Blue, *blue,
TAG_DONE);
break;
}
break;
case WMHI_CLOSEWINDOW:
close = TRUE;
break;
case WMHI_RAWKEY:
switch(code)
{
case 69:
close = TRUE;
break;
}
break;
case WMHI_INTUITICK:
{
BOOL redsel, greensel, bluesel; // Check if any of the rgb sliders are selected
IIntuition->GetAttrs(gadgets[GID_REQ_REDSLIDER],GA_Selected,&redsel,TAG_DONE);
IIntuition->GetAttrs(gadgets[GID_REQ_GREENSLIDER],GA_Selected,&greensel,TAG_DONE);
IIntuition->GetAttrs(gadgets[GID_REQ_BLUESLIDER],GA_Selected,&bluesel,TAG_DONE);
if(redsel || greensel || bluesel)
{ // yepp, rgb sliders are selected
uint32 redval, greenval, blueval;
IIntuition->GetAttrs(gadgets[GID_REQ_REDSLIDER],GRAD_CurVal, &redval,TAG_DONE);
IIntuition->GetAttrs(gadgets[GID_REQ_GREENSLIDER],GRAD_CurVal, &greenval,TAG_DONE);
IIntuition->GetAttrs(gadgets[GID_REQ_BLUESLIDER],GRAD_CurVal, &blueval,TAG_DONE);
lred = redval<<16;
lgreen = greenval<<16;
lblue = blueval<<16;
IIntuition->SetGadgetAttrs(gadgets[GID_REQ_WHEEL],req,NULL,
WHEEL_Red, lred,
WHEEL_Green, lgreen,
WHEEL_Blue, lblue,
TAG_DONE);
sred = redval;
sgreen = greenval;
sblue = blueval;
}
else // Check if colorwheel or gradient slider is affecting color
{
IIntuition->GetAttrs(gadgets[GID_REQ_WHEEL],WHEEL_Red,&lred,TAG_DONE);
IIntuition->GetAttrs(gadgets[GID_REQ_WHEEL],WHEEL_Green,&lgreen,TAG_DONE);
IIntuition->GetAttrs(gadgets[GID_REQ_WHEEL],WHEEL_Blue,&lblue,TAG_DONE);
if(llred!=lred || llgreen!=lgreen || llblue!=lblue) // Only update when changed
{
IIntuition->SetGadgetAttrs(gadgets[GID_REQ_REDSLIDER],req,NULL, GRAD_CurVal, lred>>16, TAG_DONE);
IIntuition->SetGadgetAttrs(gadgets[GID_REQ_GREENSLIDER],req,NULL, GRAD_CurVal, lgreen>>16, TAG_DONE);
IIntuition->SetGadgetAttrs(gadgets[GID_REQ_BLUESLIDER],req,NULL, GRAD_CurVal, lblue>>16, TAG_DONE);
sred = lred>>16; // Keep track of slider values
sgreen = lgreen>>16;
sblue = lblue>>16;
}
else
{
uint32 redval, greenval, blueval;
IIntuition->GetAttrs(gadgets[GID_REQ_REDSLIDER],GRAD_CurVal, &redval,TAG_DONE);
IIntuition->GetAttrs(gadgets[GID_REQ_GREENSLIDER],GRAD_CurVal, &greenval,TAG_DONE);
IIntuition->GetAttrs(gadgets[GID_REQ_BLUESLIDER],GRAD_CurVal, &blueval,TAG_DONE);
if(redval!=sred || greenval!=sgreen || blueval!=sblue) // Has rgb sliders been clicked?
{
lred = redval<<16;
lgreen = greenval<<16;
lblue = blueval<<16;
IIntuition->SetGadgetAttrs(gadgets[GID_REQ_WHEEL],req,NULL,
WHEEL_Red, lred,
WHEEL_Green, lgreen,
WHEEL_Blue, lblue,
TAG_DONE);
sred = redval; // Keep track of slider values
sgreen = greenval;
sblue = blueval;
}
}
}
if(llred!=lred || llgreen!=lgreen || llblue!=lblue) // Only update when changed
{
IGraphics->ReleasePen(appscreen->ViewPort.ColorMap,NewPen);
NewPen = IGraphics->ObtainPen(
appscreen->ViewPort.ColorMap, -1,
lred,
lgreen,
lblue,
PENF_EXCLUSIVE);
IIntuition->RefreshGadgets( gadgets[GID_REQ_NEWPEN], req, NULL );
IIntuition->RefreshGadgets( gadgets[GID_REQ_OLDPEN], req, NULL );
llred = lred;
llgreen = lgreen;
llblue = lblue;
}
}
break;
}
}
}
}
IIntuition->SetWindowAttrs(win, WA_BusyPointer, FALSE, TAG_DONE);
IIntuition->DisposeObject(reqobj);
}
// Clean up
IIntuition->UnlockPubScreen(NULL,appscreen);
IExec->DeleteMsgPort(appport);
// Release pens
IGraphics->ReleasePen(appscreen->ViewPort.ColorMap,Pen[0]);
IGraphics->ReleasePen(appscreen->ViewPort.ColorMap,Pen[1]);
IGraphics->ReleasePen(appscreen->ViewPort.ColorMap,NewPen);
IGraphics->ReleasePen(appscreen->ViewPort.ColorMap,OldPen);
IGraphics->ReleasePen(appscreen->ViewPort.ColorMap,PenRed[1]);
IGraphics->ReleasePen(appscreen->ViewPort.ColorMap,PenGreen[1]);
IGraphics->ReleasePen(appscreen->ViewPort.ColorMap,PenBlue[1]);
}