home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
fish
/
text
/
editors
/
'liner_394
/
source
/
color.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-28
|
5KB
|
191 lines
/*Color.c*/
/*Puts up a color requestor to get the screen colors for 'Liner*/
#include <exec/types.h>
#include <intuition/intuition.h>
#include <exec/exec.h>
#include "ColorWdw.h"
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Window *Wdw;
#define Rp Wdw->RPort
#define Vp Wdw->WScreen->ViewPort
#define RED 1
#define GREEN 2
#define BLUE 3
extern ColorReq();
void UpdateColorReg();
void RestoreColors();
ColorReq(Scrn)
struct Screen *Scrn;
{
struct Gadget *it;
struct PropInfo *prop;
ULONG Class;
SHORT MouseX;
USHORT color=0;
struct IntuiMessage *mesg;
USHORT CurrentGadget;
USHORT Colors[4];
ULONG OldColors[4];
BYTE c;
ULONG rgb;
if(Scrn == NULL)
NewWindowStructure1.Type=WBENCHSCREEN;
else
{
NewWindowStructure1.Type=CUSTOMSCREEN;
NewWindowStructure1.Screen=(struct Screen *)Scrn;
}
Wdw=(struct Window *)OpenWindow(&NewWindowStructure1);
if(Wdw==NULL)
return(FALSE);
SetAPen(Rp,1);
RectFill(Rp,9+64,53,9+127,64);
SetAPen(Rp,2);
RectFill(Rp,9+128,53,9+191,64);
SetAPen(Rp,3);
RectFill(Rp,9+192,53,9+255,64);
PrintIText(Rp,&IntuiTextList1,0,0);
/*Store the colors before we do anything*/
for(c=0;c<4;c++)
OldColors[c]=GetRGB4(Vp.ColorMap,c);
rgb=GetRGB4(Vp.ColorMap,0);
RedSliderSInfo.HorizPot=(Colors[RED]=(rgb >> 8) & 0xF)<<12;
GreenSliderSInfo.HorizPot=(Colors[GREEN]=(rgb >> 4) & 0xF)<<12;
BlueSliderSInfo.HorizPot=(Colors[BLUE]=rgb & 0xF)<<12;
UpdateNum(RED,Colors[RED]);
UpdateNum(GREEN,Colors[GREEN]);
UpdateNum(BLUE,Colors[BLUE]);
RefreshGadgets(&RedSlider,Wdw,NULL);
for(;;)
{
Wait(1<<Wdw->UserPort->mp_SigBit);
while((mesg=(struct IntuiMessage *)GetMsg(Wdw->UserPort))!=NULL)
{
it=(APTR)mesg->IAddress;
Class=mesg->Class;
MouseX=mesg->MouseX;
ReplyMsg(mesg);
switch(Class)
{
case GADGETUP:
RestoreColors(OldColors,color,Colors);
break;
case CLOSEWINDOW:
CloseWindow(Wdw);
return(TRUE);
case MOUSEMOVE:
UpdateNum(CurrentGadget,
(Colors[CurrentGadget]=(prop->HorizPot >> 12)));
UpdateColorReg(color,Colors,&Vp);
break;
case GADGETDOWN:
CurrentGadget=it->GadgetID;
if(CurrentGadget < 4)
{
prop=(APTR)it->SpecialInfo;
UpdateNum(CurrentGadget,(Colors[CurrentGadget]=
(prop->HorizPot) >> 12 ));
UpdateColorReg(color,Colors,&Vp);
}
else
{
color=(MouseX-9)/64;
rgb=GetRGB4(Vp.ColorMap,color);
RedSliderSInfo.HorizPot=(Colors[RED]=(rgb >> 8) & 0xF)<<12;
GreenSliderSInfo.HorizPot=(Colors[GREEN]=(rgb >> 4) & 0xF)<<12;
BlueSliderSInfo.HorizPot=(Colors[BLUE]=rgb & 0xF)<<12;
UpdateNum(RED,Colors[RED]);
UpdateNum(GREEN,Colors[GREEN]);
UpdateNum(BLUE,Colors[BLUE]);
RefreshGadgets(&RedSlider,Wdw,NULL);
SetAPen(Rp,color);
RectFill(Rp,290,17,310,47);
}
}
}
}
}
UpdateNum(Color,value)
USHORT Color,value;
{
char Num[4];
if(value > 15)
return(FALSE); /*Get rid of funny answers*/
SetAPen(Rp,1);
Move(Rp,15,15+(Color*10));
if(value > 9)
stci_d(Num,value);
else
{
stci_d(&Num[1],value);
Num[0]=' ';
}
Text(Rp,Num,2);
return(TRUE);
}
void UpdateColorReg(reg,colors,ViewPort)
USHORT reg,*colors;
struct ViewPort *ViewPort;
{
SetRGB4(ViewPort,reg,colors[RED],colors[GREEN],colors[BLUE]);
}
void RestoreColors(OldColors,curreg,Colors)
ULONG *OldColors;
BYTE curreg;
USHORT *Colors;
{
BYTE c;
USHORT red,green,blue;
for(c=0;c<4;c++)
{
red = (OldColors[c]>>8) & 0xF;
green = (OldColors[c]>>4) & 0xF;
blue = OldColors[c] & 0xF;
SetRGB4(&Vp,c,red,green,blue);
if(c==curreg)
{
RedSliderSInfo.HorizPot=(Colors[RED]=red)<<12;
GreenSliderSInfo.HorizPot=(Colors[GREEN]=green)<<12;
BlueSliderSInfo.HorizPot=(Colors[BLUE]=blue)<<12;
UpdateNum(RED,Colors[RED]);
UpdateNum(GREEN,Colors[GREEN]);
UpdateNum(BLUE,Colors[BLUE]);
RefreshGadgets(&RedSlider,Wdw,NULL);
}
}
}
/*End of color.c*/