home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
os20
/
forceicon-1.2.lha
/
ForceIcon
/
Source
/
Support.c
< prev
Wrap
C/C++ Source or Header
|
1993-12-31
|
29KB
|
1,275 lines
/*
Auto: smake ForceIcon
*/
/* $Revision Header built automatically *************** (do not edit) ************
**
** © Copyright by GuntherSoft
**
** File : SnakeSYS:CPrgs/Utils/ForceIcon/Support.c
** Created on : Friday, 22.10.93 16:38:41
** Created by : Kai Iske
** Current revision : V1.0
**
**
** Purpose
** -------
** - Support-Routines for ForceIcon
**
** Revision V1.0
** --------------
** created on Friday, 22.10.93 16:38:41 by Kai Iske. LogMessage :
** --- Initial release ---
**
*********************************************************************************/
/**********************************************************************/
/* External variables */
/**********************************************************************/
extern struct ExecBase *SysBase;
extern struct SignalSemaphore MySemaphore;
extern struct List VolumeList;
extern struct IClass *GetFileClass;
/**********************************************************************/
/* Global variables */
/**********************************************************************/
static struct RastPort ComputeRPort;
/**********************************************************************/
/* Vars for Busy-Pointer */
/**********************************************************************/
static UWORD __chip BusyPtr[] =
{
0x0000,0x0000,0x0400,0x07C0,0x0000,0x07C0,
0x0100,0x0380,0x0000,0x07E0,0x07C0,0x1FF8,
0x1FF0,0x3FEC,0x3FF8,0x7FDE,0x3FF8,0x7FBE,
0x7FFC,0xFF7F,0x7EFC,0xFFFF,0x7FFC,0xFFFF,
0x3FF8,0x7FFE,0x3FF8,0x7FFE,0x1FF0,0x3FFC,
0x07C0,0x1FF8,0x0000,0x07E0,0x0000,0x0000
};
/**********************************************************************/
/* Calc X-Position */
/**********************************************************************/
UWORD ComputeX(UWORD value, UWORD FontX)
{
return((UWORD)(((FontX * value) + 2) / 8));
}
/**********************************************************************/
/* Calc Y-Position */
/**********************************************************************/
UWORD ComputeY(UWORD value, UWORD FontY)
{
return(( UWORD )((( FontY * value ) + 2 ) / 8 ));
}
/**********************************************************************/
/* Calc resolution and correct font */
/**********************************************************************/
void __stdargs ComputeFont(struct Screen *WorkScreen, UWORD width, UWORD height, struct TextAttr *Font, char *FontName, UWORD *OffX, UWORD *OffY, UWORD *FontX, UWORD *FontY)
{
// Get Font-Structure
strcpy(FontName, WorkScreen->RastPort.Font->tf_Message.mn_Node.ln_Name);
Font->ta_Name = FontName;
Font->ta_YSize = *FontY = WorkScreen->RastPort.Font->tf_YSize;
Font->ta_Style = FS_NORMAL;
Font->ta_Flags = 0;
*FontX = WorkScreen->RastPort.Font->tf_XSize;
// Calc offsets
*OffX = WorkScreen->WBorLeft;
*OffY = WorkScreen->RastPort.TxHeight + WorkScreen->WBorTop + 1;
// A Ok ???
if(width && height)
{
if((ComputeX(width, *FontX) + *OffX + WorkScreen->WBorRight) > WorkScreen->Width)
goto UseTopaz;
if((ComputeY(height, *FontY) + *OffY + WorkScreen->WBorBottom) > WorkScreen->Height)
goto UseTopaz;
}
return;
// FallBack to Topaz8
UseTopaz:
strcpy(FontName, "topaz.font");
*FontX = *FontY = Font->ta_YSize = 8;
}
/**********************************************************************/
/* Open a window with a background pattern */
/**********************************************************************/
BOOL OpenWin(
UWORD Left,
UWORD Top,
UWORD Width,
UWORD Height,
struct Gadget **BaseGadget,
UWORD NumGads,
struct _Object **GetFile,
struct NewGadget *NewGads,
UWORD *GTypes,
ULONG *GTags,
struct Gadget **MyGads,
struct Window **Handle,
char *Title,
ULONG IDCMP,
ULONG FLAGS,
UWORD MLeft,
UWORD MTop,
UWORD MWidth,
UWORD MHeight,
struct TextAttr *WinTxtAttr,
char *WinTxtFontName,
struct VisualInfo **VisInfo)
{
UWORD Raster[4] =
{
0xAAAA,
0x5555,
};
struct Screen *MyScreen;
struct Rectangle ScrRec;
struct NewGadget ng;
struct Gadget *g;
struct TextFont *MyFont = NULL;
UWORD lc, tc;
UWORD wleft, wtop, ww, wh, OffX, OffY, FontX, FontY,
swidth, sheight;
if(!(MyScreen = LockPubScreen("Workbench")))
return(FALSE);
if(!(*VisInfo = GetVisualInfo(MyScreen, TAG_DONE)))
goto error;
// Get Font and dimensions
ComputeFont(MyScreen, Width, Height, WinTxtAttr, WinTxtFontName, &OffX, &OffY, &FontX, &FontY);
// Set RastPort Font
InitRastPort(&ComputeRPort);
if(!(MyFont = OpenFont(WinTxtAttr)))
{
if(!(MyFont = OpenDiskFont(WinTxtAttr)))
goto error;
}
SetFont(&ComputeRPort, MyFont);
// Get size of window
ww = ComputeX(Width, FontX);
wh = ComputeY(Height, FontY);
// Get info about Screenmode
if(!QueryOverscan(GetVPModeID(&MyScreen->ViewPort), &ScrRec, OSCAN_TEXT))
goto error;
// Center window
swidth = min((ScrRec.MaxX + 1), MyScreen->Width);
sheight = min((ScrRec.MaxY + 1), MyScreen->Height);
wleft = ((swidth - ww - 1) >> 1) - ((MyScreen->LeftEdge < 0) ? MyScreen->LeftEdge : 0);
wtop = ((sheight - wh - 1) >> 1) - ((MyScreen->TopEdge < 0) ? MyScreen->TopEdge : 0);
// Build GetFile image
if(GetFile)
{
if(!(*GetFile = NewObject(GetFileClass, NULL, GT_VisualInfo, *VisInfo, IA_Width, ComputeX(20, FontX), IA_Height, ComputeY(14, FontY), TAG_DONE)))
goto error;
}
// Create gadgets
if(!(g = CreateContext(BaseGadget)))
goto error;
for(lc = 0, tc = 0; lc < NumGads; lc++)
{
CopyMem((char *)&NewGads[lc], (char *)&ng, (long)sizeof(struct NewGadget));
ng.ng_VisualInfo = *VisInfo;
ng.ng_TextAttr = WinTxtAttr;
ng.ng_LeftEdge = OffX + ComputeX(ng.ng_LeftEdge, FontX);
ng.ng_TopEdge = OffY + ComputeY(ng.ng_TopEdge, FontY);
ng.ng_Width = ComputeX(ng.ng_Width, FontX);
ng.ng_Height = ComputeY(ng.ng_Height, FontY);
// Set gadget`s shortcut
SetGadShortCut(GTypes[lc], &ng);
// Check for ListView
if(GTypes[lc] == LISTVIEW_KIND)
{
struct TagItem *tmp;
if(tmp = FindTagItem(GTLV_ShowSelected, (struct TagItem *)>ags[tc]))
{
if(tmp->ti_Data)
tmp->ti_Data = (ULONG)g;
else
{
// With a normal ShowSelected,
// adjust width according to version of OS
if(((struct Library *)SysBase)->lib_Version < 39)
ng.ng_Height -= 8;
}
}
}
// Create gadget
MyGads[lc] = g = CreateGadgetA(GTypes[lc], g, &ng, (struct TagItem *)>ags[tc]);
// Error ???
if(!g)
goto error;
// Set GetFile image
if(GTypes[lc] == GENERIC_KIND && GetFile)
{
struct TagItem *tmp;
BOOL Disabled = FALSE;
if((tmp = FindTagItem(GA_Disabled, (struct TagItem *)>ags[tc])))
Disabled = (BOOL)tmp->ti_Data;
g->Flags |= GFLG_GADGIMAGE | GFLG_GADGHIMAGE | ((Disabled) ? GFLG_DISABLED : 0);
g->Activation |= GACT_RELVERIFY;
g->GadgetType |= GTYP_BOOLGADGET;
g->GadgetRender = (APTR)*GetFile;
g->SelectRender = (APTR)*GetFile;
}
// Patch String/Integer Gadgets
if(GTypes[lc] == STRING_KIND || GTypes[lc] == INTEGER_KIND)
{
((struct StringInfo *)g->SpecialInfo)->Extension->ActivePens[0] = 1;
((struct StringInfo *)g->SpecialInfo)->Extension->ActivePens[1] = 2;
}
while(GTags[tc])
tc += 2;
tc++;
}
// Close Font
CloseFont(MyFont);
// Open window
if(!(*Handle = OpenWindowTags(NULL,
WA_Left, wleft,
WA_Top, wtop,
WA_Width, ww + OffX + MyScreen->WBorRight,
WA_Height, wh + OffY + MyScreen->WBorBottom,
WA_IDCMP, IDCMP,
WA_Flags, FLAGS,
WA_Title, Title,
WA_CustomScreen, MyScreen,
TAG_DONE)))
goto error;
// Clear userdata-field
(*Handle)->UserData = NULL;
// Unlock Pub screen
UnlockPubScreen(NULL, MyScreen);
if(MLeft && MTop && MWidth && MHeight)
{
// Draw Raster
SetAPen((*Handle)->RPort, 2);
SetAfPt((*Handle)->RPort, Raster, 1);
RectFill((*Handle)->