home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
550b.lha
/
Term_v1.8a
/
Source.LZH
/
ScreenPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-17
|
17KB
|
627 lines
/* $Revision Header * Header built automatically - do not edit! *************
*
* (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
*
* Name .....: ScreenPanel.c
* Created ..: Monday 21-Jan-91 20:12
* Revision .: 0
*
* Date Author Comment
* ========= ======== ====================
* 21-Jan-91 Olsen Created this file!
*
* $Revision Header ********************************************************/
#include "TermGlobal.h"
enum { GAD_MODES,GAD_PALETTE,GAD_RED,GAD_GREEN,GAD_BLUE,GAD_MAKEPUBLIC,GAD_SHANGHAI,GAD_USE,GAD_CANCEL };
#define WIDTH 455
#define HEIGHT 172
/* The names of the 20 display modes. */
STATIC UBYTE *ModeNames[16] =
{
"Hires",
"Hires Interlaced",
"Super Hires",
"Super Hires Interlaced",
"Productivity",
"Productivity Interlaced",
"PAL Hires",
"PAL Hires Interlaced",
"PAL Super Hires",
"PAL Super Hires Interlaced",
"NTSC Hires",
"NTSC Hires Interlaced",
"NTSC Super Hires",
"NTSC Super Hires Interlaced",
"A2024 10 Hz",
"A2024 15 Hz"
};
enum { MEN_NEXT=1,MEN_PREV,MEN_COLOUR,MEN_RED,MEN_GREEN,MEN_BLUE,MEN_MAKEPUBLIC,MEN_SHANGHAI,MEN_USE,MEN_CANCEL,MEN_QUITPANEL };
STATIC struct NewMenu ScreenMenu[] =
{
{ NM_TITLE, "Project", 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Next Mode", "N", 0, 0, (APTR)MEN_NEXT},
{ NM_ITEM, "Previous Mode", "P", 0, 0, (APTR)MEN_PREV},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Colour", "O", 0, 0, (APTR)MEN_COLOUR},
{ NM_ITEM, "Red", "R", 0, 0, (APTR)MEN_RED},
{ NM_ITEM, "Green", "G", 0, 0, (APTR)MEN_GREEN},
{ NM_ITEM, "Blue", "B", 0, 0, (APTR)MEN_BLUE},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Make Screen Public", "M", 0, 0, (APTR)MEN_MAKEPUBLIC},
{ NM_ITEM, "`Shanghai' Windows", "W", 0, 0, (APTR)MEN_SHANGHAI},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Use", "U", 0, 0, (APTR)MEN_USE},
{ NM_ITEM, "Cancel", "C", 0, 0, (APTR)MEN_CANCEL},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Quit", "Q", 0, 0, (APTR)MEN_QUITPANEL},
{ NM_END, 0, 0 , 0, 0, (APTR)0}
};
STATIC struct Node ModeNodes[16];
STATIC struct List ModeList;
STATIC struct Gadget *
CreateAllGadgets(LONG *ModeNumber,LONG *NumModes,struct Configuration *Config,struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge)
{
struct Gadget *Gadget;
struct NewGadget NewGadget;
UWORD Counter = 0;
BYTE Count = 0,i,Mode;
BYTE Limited;
if(Gadget = CreateContext(GadgetList))
{
NewList(&ModeList);
for(i = 0 ; i < 16 ; i++)
if(Config -> DisplayMode == ModeID[i])
Mode = i;
*NumModes = 0;
if(Config -> ColourMode == COLOUR_EIGHT || Config -> ColourMode == COLOUR_SIXTEEN)
Limited = TRUE;
else
Limited = FALSE;
/* This loop runs all possible display modes through `ModeNotAvailable'
* to determine which resolutions are not supported by the current
* monitor spec.
*/
for(i = 0 ; i < 16 ; i++)
{
if(!ModeNotAvailable(ModeID[i]))
{
if(Limited)
{
if(((ModeID[i] & ~MONITOR_ID_MASK) == HIRES_KEY) || ((ModeID[i] & ~MONITOR_ID_MASK) == HIRESLACE_KEY))
{
ModeNodes[Count] . ln_Name = ModeNames[i];
ModeNodes[Count] . ln_Type = i;
AddTail(&ModeList,&ModeNodes[Count++]);
}
}
else
{
ModeNodes[Count] . ln_Name = ModeNames[i];
ModeNodes[Count] . ln_Type = i;
AddTail(&ModeList,&ModeNodes[Count++]);
}
}
else
{
if(i == Mode)
Mode = 0;
}
}
*NumModes = Count;
*ModeNumber = Mode;
NewGadget . ng_Width = 244;
NewGadget . ng_Height = 60;
NewGadget . ng_GadgetText = "Available Display Modes";
NewGadget . ng_TextAttr = &DefaultFont;
NewGadget . ng_VisualInfo = VisualInfo;
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = NG_HIGHLABEL|PLACETEXT_LEFT;
NewGadget . ng_LeftEdge = (strlen(NewGadget . ng_GadgetText) + 2) * 8 + 1;
NewGadget . ng_TopEdge = 1 + TopEdge;
GadgetArray[Counter++] = Gadget = CreateGadget(LISTVIEW_KIND,Gadget,&NewGadget,
GTLV_Labels, &ModeList,
GTLV_ShowSelected, NULL,
GTLV_Selected, Mode,
TAG_DONE);
NewGadget . ng_GadgetText = "Edit Screen Palette";
NewGadget . ng_Width = 244;
NewGadget . ng_Height = 30;
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 14;
GadgetArray[Counter++] = Gadget = CreateGadget(PALETTE_KIND,Gadget,&NewGadget,
GTPA_Depth, Config -> ColourMode == COLOUR_EIGHT ? 3 : Screen -> RastPort . BitMap -> Depth,
GTPA_Color, 0,
GTPA_IndicatorWidth, NewGadget . ng_Width / (1 << 2),
GTPA_IndicatorHeight, NewGadget . ng_Height,
TAG_DONE);
NewGadget . ng_GadgetText = "_Red ";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Height = 10;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 31;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTSL_Min, 0,
GTSL_Max, 15,
GTSL_Level, 0,
GTSL_LevelFormat, "%2ld",
GTSL_MaxLevelLen, 2,
TAG_DONE);
NewGadget . ng_GadgetText = "_Green ";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTSL_Min, 0,
GTSL_Max, 15,
GTSL_Level, 0,
GTSL_LevelFormat, "%2ld",
GTSL_MaxLevelLen, 2,
TAG_DONE);
NewGadget . ng_GadgetText = "_Blue ";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTSL_Min, 0,
GTSL_Max, 15,
GTSL_Level, 0,
GTSL_LevelFormat, "%2ld",
GTSL_MaxLevelLen, 2,
TAG_DONE);
NewGadget . ng_GadgetText = "_Make Screen Public";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 4;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCB_Checked, Config -> MakeScreenPublic,
TAG_DONE);
NewGadget . ng_GadgetText = "`Shanghai' _Windows";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCB_Checked, Config -> ShanghaiWindows,
TAG_DONE);
if(!Config -> MakeScreenPublic)
Gadget -> Flags |= GFLG_DISABLED;
NewGadget . ng_Width = 52;
NewGadget . ng_Height = 12;
NewGadget . ng_GadgetText = "_Use";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = 0;
NewGadget . ng_LeftEdge = 10;
NewGadget . ng_TopEdge = HEIGHT - 3 - NewGadget . ng_Height;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
NewGadget . ng_GadgetText = "_Cancel";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = WIDTH - 10 - NewGadget . ng_Width;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
}
return(Gadget);
}
BYTE
ScreenPanel(struct Configuration *MyConfig)
{
struct Window *PanelWindow;
struct Menu *PanelMenu;
struct Gadget *GadgetList;
struct Gadget *GadgetArray[GAD_CANCEL + 1];
LONG ModeNumber,NumModes;
SHORT i;
CopyMem(MyConfig,&PrivateConfig,sizeof(struct Configuration));
if(CreateAllGadgets(&ModeNumber,&NumModes,MyConfig,&GadgetArray[0],&GadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1))
{
if(PanelMenu = CreateMenus(ScreenMenu,
GTMN_FrontPen, 0,
TAG_DONE))
{
if(LayoutMenus(PanelMenu,VisualInfo,
GTMN_TextAttr,&DefaultFont,
TAG_DONE))
{
if(PanelWindow = OpenWindowTags(NULL,
WA_Left, (Screen -> Width - WIDTH) >> 1,
WA_Top, (Screen -> Height - HEIGHT) >> 1,
WA_Width, WIDTH,
WA_Height, HEIGHT,
WA_Activate, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_RMBTrap, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_CustomScreen,Screen,
WA_IDCMP, IDCMP_CLOSEWINDOW | SLIDERIDCMP | CHECKBOXIDCMP | LISTVIEWIDCMP | IDCMP_MENUPICK,
WA_Title, "Screen Preferences",
TAG_DONE))
{
struct IntuiMessage *Massage;
ULONG Class,Code;
struct Gadget *Gadget;
BYTE Terminated = FALSE;
LONG ColourNumber = 0;
BYTE Red,Green,Blue;
PushWindow(PanelWindow);
Red = (MyConfig -> Colours[ColourNumber] >> 8) & 0xF;
Green = (MyConfig -> Colours[ColourNumber] >> 4) & 0xF;
Blue = (MyConfig -> Colours[ColourNumber] ) & 0xF;
AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
GT_RefreshWindow(PanelWindow,NULL);
GT_SetGadgetAttrs(GadgetArray[GAD_RED],PanelWindow,NULL,
GTSL_Level,Red,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_GREEN],PanelWindow,NULL,
GTSL_Level,Green,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_BLUE],PanelWindow,NULL,
GTSL_Level,Blue,
TAG_DONE);
SetMenuStrip(PanelWindow,PanelMenu);
PanelWindow -> Flags &= ~WFLG_RMBTRAP;
while(!Terminated)
{
WaitPort(PanelWindow -> UserPort);
while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
{
Class = Massage -> Class;
Code = Massage -> Code;
Gadget = (struct Gadget *)Massage -> IAddress;
GT_ReplyIMsg(Massage);
if(Class == IDCMP_MENUPICK)
{
struct MenuItem *MenuItem;
while(Code != MENUNULL)
{
MenuItem = ItemAddress(PanelMenu,Code);
switch((ULONG)MENU_USERDATA(MenuItem))
{
case MEN_QUITPANEL: Class = IDCMP_CLOSEWINDOW;
break;
case MEN_NEXT: if(ModeNumber == NumModes - 1)
ModeNumber = 0;
else
ModeNumber++;
GT_SetGadgetAttrs(GadgetArray[GAD_MODES],PanelWindow,NULL,
GTLV_Selected,ModeNumber,
TAG_DONE);
MyConfig -> DisplayMode = ModeID[ModeNumber];
break;
case MEN_PREV: if(ModeNumber == 0)
ModeNumber = NumModes - 1;
else
ModeNumber--;
GT_SetGadgetAttrs(GadgetArray[GAD_MODES],PanelWindow,NULL,
GTLV_Selected,ModeNumber,
TAG_DONE);
MyConfig -> DisplayMode = ModeID[ModeNumber];
break;
case MEN_COLOUR: switch(MyConfig -> ColourMode)
{
case COLOUR_EIGHT: if(ColourNumber == 7)
ColourNumber = 0;
else
ColourNumber++;
break;
default: if(ColourNumber == (1 << Screen -> RastPort . BitMap -> Depth) - 1)
ColourNumber = 0;
else
ColourNumber++;
break;
}
GT_SetGadgetAttrs(GadgetArray[GAD_PALETTE],PanelWindow,NULL,
GTPA_Color,ColourNumber,
TAG_DONE);
goto SetPalette;
case MEN_RED: if(Red == 15)
Red = 0;
else
Red++;
GT_SetGadgetAttrs(GadgetArray[GAD_RED],PanelWindow,NULL,
GTSL_Level,Red,
TAG_DONE);
SetRGB4(VPort,ColourNumber,Red,Green,Blue);
MyConfig -> Colours[ColourNumber] = (Red << 8) | (Green << 4) | (Blue);
break;
case MEN_GREEN: if(Green == 15)
Green = 0;
else
Green++;
GT_SetGadgetAttrs(GadgetArray[GAD_RED],PanelWindow,NULL,
GTSL_Level,Red,
TAG_DONE);
SetRGB4(VPort,ColourNumber,Red,Green,Blue);
MyConfig -> Colours[ColourNumber] = (Red << 8) | (Green << 4) | (Blue);
break;
case MEN_BLUE: if(Blue == 15)
Blue = 0;
else
Blue++;
GT_SetGadgetAttrs(GadgetArray[GAD_RED],PanelWindow,NULL,
GTSL_Level,Red,
TAG_DONE);
SetRGB4(VPort,ColourNumber,Red,Green,Blue);
MyConfig -> Colours[ColourNumber] = (Red << 8) | (Green << 4) | (Blue);
break;
case MEN_MAKEPUBLIC: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_MAKEPUBLIC];
GT_SetGadgetAttrs(GadgetArray[GAD_MAKEPUBLIC],PanelWindow,NULL,
GTCB_Checked,GadgetArray[GAD_MAKEPUBLIC] -> Flags & GFLG_SELECTED ? FALSE : TRUE,
TAG_DONE);
break;
case MEN_SHANGHAI: if(!(GadgetArray[GAD_SHANGHAI] -> Flags & GFLG_DISABLED))
{
Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_SHANGHAI];
GT_SetGadgetAttrs(GadgetArray[GAD_SHANGHAI],PanelWindow,NULL,
GTCB_Checked,GadgetArray[GAD_SHANGHAI] -> Flags & GFLG_SELECTED ? FALSE : TRUE,
TAG_DONE);
}
break;
case MEN_USE: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_USE];
break;
case MEN_CANCEL: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_CANCEL];
break;
default: break;
}
Code = MenuItem -> NextSelect;
}
}
if(Class == IDCMP_CLOSEWINDOW)
Terminated = TRUE;
if(Class == IDCMP_MOUSEMOVE)
{
switch(Gadget -> GadgetID)
{
case GAD_RED: Red = Code;
SetRGB4(VPort,ColourNumber,Red,Green,Blue);
MyConfig -> Colours[ColourNumber] = (Red << 8) | (Green << 4) | (Blue);
break;
case GAD_GREEN: Green = Code;
SetRGB4(VPort,ColourNumber,Red,Green,Blue);
MyConfig -> Colours[ColourNumber] = (Red << 8) | (Green << 4) | (Blue);
break;
case GAD_BLUE: Blue = Code;
SetRGB4(VPort,ColourNumber,Red,Green,Blue);
MyConfig -> Colours[ColourNumber] = (Red << 8) | (Green << 4) | (Blue);
break;
default: break;
}
}
if(Class == IDCMP_GADGETUP)
{
switch(Gadget -> GadgetID)
{
case GAD_MAKEPUBLIC: if(!(Gadget -> Flags & GFLG_SELECTED))
{
GadgetArray[GAD_SHANGHAI] -> Flags &= ~GFLG_SELECTED;
GT_SetGadgetAttrs(GadgetArray[GAD_SHANGHAI],PanelWindow,NULL,
GA_Disabled,TRUE,
TAG_DONE);
}
else
{
GT_SetGadgetAttrs(GadgetArray[GAD_SHANGHAI],PanelWindow,NULL,
GA_Disabled,FALSE,
TAG_DONE);
}
break;
case GAD_MODES: MyConfig -> DisplayMode = ModeID[Code];
ModeNumber = Code;
break;
case GAD_PALETTE: ColourNumber = Code;
SetPalette: MyConfig -> Colours[ColourNumber] = GetRGB4(VPort -> ColorMap,ColourNumber);
Red = (MyConfig -> Colours[ColourNumber] >> 8) & 0xF;
Green = (MyConfig -> Colours[ColourNumber] >> 4) & 0xF;
Blue = (MyConfig -> Colours[ColourNumber] ) & 0xF;
GT_SetGadgetAttrs(GadgetArray[GAD_RED],PanelWindow,NULL,
GTSL_Level,Red,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_GREEN],PanelWindow,NULL,
GTSL_Level,Green,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_BLUE],PanelWindow,NULL,
GTSL_Level,Blue,
TAG_DONE);
break;
case GAD_USE: Terminated = TRUE;
if(MyConfig -> ColourMode == COLOUR_EIGHT)
{
for(i = 0 ; i < 8 ; i++)
MyConfig -> Colours[i + 8] = MyConfig -> Colours[i];
}
if(MyConfig == &Config)
{
CopyMem(&MyConfig -> Colours[0],&BlinkColours[0],sizeof(UWORD) * 16);
switch(MyConfig -> ColourMode)
{
case COLOUR_EIGHT: for(i = 0 ; i < 8 ; i++)
BlinkColours[i + 8] = BlinkColours[0];
break;
case COLOUR_SIXTEEN: break;
case COLOUR_AMIGA:
default: BlinkColours[3] = BlinkColours[0];
break;
}
}
MyConfig -> MakeScreenPublic = GadgetArray[GAD_MAKEPUBLIC] -> Flags & GFLG_SELECTED;
MyConfig -> ShanghaiWindows = GadgetArray[GAD_SHANGHAI] -> Flags & GFLG_SELECTED;
break;
case GAD_CANCEL: Terminated = TRUE;
CopyMem(&PrivateConfig,MyConfig,sizeof(struct Configuration));
LoadRGB4(VPort,&MyConfig -> Colours[0],16);
break;
default: break;
}
}
}
}
PanelWindow -> Flags |= WFLG_RMBTRAP;
ClearMenuStrip(PanelWindow);
RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
PopWindow();
CloseWindow(PanelWindow);
}
}
FreeMenus(PanelMenu);
}
FreeGadgets(GadgetList);
}
if(PrivateConfig . DisplayMode != MyConfig -> DisplayMode)
return(TRUE);
else
return(FALSE);
}