home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
514a.lha
/
TplEdit_v1.00_alpha
/
Src
/
subs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-08
|
3KB
|
170 lines
/*
* SUBS.C
*/
#include "defs.h"
Prototype TplRegion *IdToRegion(long);
Prototype TplRegion *FindRegion(short, short);
Prototype TplRegion *FindRegionByGad(Gadget *);
Prototype void ClearLinks(TplRegion *);
Prototype long RegionToId(TplRegion *);
Prototype void *zalloc(long);
Prototype void DrawBox(Box *);
Prototype void FixBounds(Box *);
Prototype void AddNode(List *, char *, short);
Prototype int GetSaveFile(char *);
TplRegion *
IdToRegion(id)
long id;
{
TplRegion *rg;
for (rg = GetHead(&RegList); rg; rg = GetSucc(&rg->rg_Node)) {
if (rg->rg_Id == id)
break;
}
return(rg);
}
TplRegion *
FindRegion(x, y)
short x;
short y;
{
TplRegion *rg;
for (rg = GetHead(&RegList); rg; rg = GetSucc(&rg->rg_Node)) {
if (rg->rg_Box.bo_Xs - 2 <= x && x <= rg->rg_Box.bo_Xe + 2) {
if (rg->rg_Box.bo_Ys - 2 <= y && y <= rg->rg_Box.bo_Ye + 2)
return(rg);
}
}
return(NULL);
}
TplRegion *
FindRegionByGad(gad)
Gadget *gad;
{
TplRegion *rg;
for (rg = GetHead(&RegList); rg; rg = GetSucc(&rg->rg_Node)) {
if (rg->rg_Gad == gad)
return(rg);
}
return(NULL);
}
long
RegionToId(rg)
TplRegion *rg;
{
if (rg)
return(rg->rg_Id);
return(0);
}
void *
zalloc(bytes)
long bytes;
{
void *ptr;
if (ptr = malloc(bytes)) {
clrmem(ptr, bytes);
return(ptr);
}
puts("No Memory!");
exit(30);
}
void
DrawBox(box)
Box *box;
{
RastPort *rp = Win->RPort;
SetDrMd(rp, COMPLEMENT);
Move(rp, box->bo_Xs, box->bo_Ys);
Draw(rp, box->bo_Xe, box->bo_Ys);
Draw(rp, box->bo_Xe, box->bo_Ye);
Draw(rp, box->bo_Xs, box->bo_Ye);
Draw(rp, box->bo_Xs, box->bo_Ys);
}
void
FixBounds(box)
Box *box;
{
long t;
if (box->bo_Xe < box->bo_Xs) {
t = box->bo_Xe;
box->bo_Xe = box->bo_Xs;
box->bo_Xs = t;
}
if (box->bo_Ye < box->bo_Ys) {
t = box->bo_Ye;
box->bo_Ye = box->bo_Ys;
box->bo_Ys = t;
}
}
void
AddNode(list, str, alloc)
List *list;
char *str;
short alloc;
{
MaxNode *node = zalloc(sizeof(MaxNode));
node->ln_Name = (alloc) ? strdup(str) : str;
AddTail((MaxList *)list, node);
}
int
GetSaveFile(buf)
char *buf;
{
FileRequester *freq;
int r = -1;
if (freq = AllocFileRequest()) {
if (RequestFile(freq)) {
short i = strlen(freq->rf_Dir) - 1;
strcpy(buf, freq->rf_Dir);
if (i >= 0 && buf[i] != '/' && buf[i] != ':')
strcat(buf, "/");
strcat(buf, freq->rf_File);
r = 0;
}
FreeFileRequest(freq);
}
return(r);
}
void
ClearLinks(rn)
TplRegion *rn;
{
TplRegion *rg;
for (rg = GetHead(&RegList); rg; rg = GetSucc(&rg->rg_Node)) {
if (rn == rg->rg_LinkLeft)
rg->rg_LinkLeft = NULL;
if (rn == rg->rg_LinkRight)
rg->rg_LinkRight = NULL;
if (rn == rg->rg_LinkUp)
rg->rg_LinkUp = NULL;
if (rn == rg->rg_LinkDown)
rg->rg_LinkDown = NULL;
if (rn == rg->rg_LockedTo)
rg->rg_LockedTo = NULL;
}
}