home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Phoenix Heaven Sunny 2
/
APPARE2.BIN
/
oh_towns
/
install
/
item.c
< prev
next >
Wrap
Text File
|
1995-06-20
|
5KB
|
197 lines
/*************************************************************************
* アイテム登録処理
*************************************************************************/
#define FRM_X1(_frm) _frm[0]
#define FRM_Y1(_frm) _frm[1]
#define FRM_X2(_frm) _frm[2]
#define FRM_Y2(_frm) _frm[3]
int item_get_newpos( char *pathItem, int fposBase, short *newfrm );
int item_chkpos( char *pathItem, int fposStart, short *frmchk );
int item_get_fr( char *pathItem, int fpos, short *fr );
int item_adjust_pos( short *newfrm );
int item_setApl( int drv, int icon, char *ttl, char *path, char *para, int att )
{
char pathItem[64], prog[128];
short fr[4];
int iconGrp;
int fpos;
char *ttlGrp;
ttlGrp = "天晴";
iconGrp = 1059; /* アイコン番号 */
sprintf( pathItem, "%c:\\tmenu.itm", drv + 'A');
if ( FS_isFile(pathItem) != FSISFILE_FILE )
{ /* アイテムファイルの作成 */
ITM_CreateItemFile(pathItem);
}
/* "天晴"アイテムを検索 --------------------------------------------*/
FRM_X1(fr) = FRM_Y1(fr) = FRM_X2(fr) = FRM_Y2(fr) = -1;
fpos = ITM_GetGrpFPos(pathItem,0,-1,-1,ttlGrp,-1,fr);
if ( fpos < 0 )
{ /* ルートに天晴アイテムを作成する */
item_get_newpos( pathItem, 0, fr);
if ( (fpos = ITM_AddGrpItem(pathItem,0,iconGrp,ttlGrp,fr)) < 0 )
return (ERR);
}
/* アイテムを追加 ------------------------------------------------*/
if ( item_get_newpos( pathItem, fpos, fr) < 0 )
return (ERR);
FS_dosFn(prog,path);
FS_strupr(prog);
if ( ITM_AddAplItem( pathItem, fpos, icon, ttl, prog, para, att, fr) < 0 )
return (ERR);
return (NORMAL);
}
int item_get_newpos( char *pathItem, int fposBase, short *newfrm )
{
int area, x, y, x0, y0;
for ( area = 0; area < 9; ++area )
{
x = area;
for ( y = 0; y < area; ++y )
{
x0 = x * 64; FRM_X1(newfrm) = x0+8; FRM_X2(newfrm) = x0 + 63-8;
y0 = y * 48; FRM_Y1(newfrm) = y0+4; FRM_Y2(newfrm) = y0 + 47-4;
if ( item_chkpos( pathItem, fposBase, newfrm ) )
goto _OK;
}
y = area;
for ( x = 0; x <= area; ++x )
{
x0 = x * 64; FRM_X1(newfrm) = x0+8; FRM_X2(newfrm) = x0 + 63-8;
y0 = y * 48; FRM_Y1(newfrm) = y0+4; FRM_Y2(newfrm) = y0 + 47-4;
if ( item_chkpos( pathItem, fposBase, newfrm ) )
goto _OK;
}
}
_OK:
x0 = (FRM_X1(newfrm) + FRM_X2(newfrm) + 1) / 2 - 12;
FRM_X1(newfrm) = (x0+7) & (~7);
FRM_Y1(newfrm) = FRM_Y1(newfrm) + 4;
FRM_X2(newfrm) = FRM_X1(newfrm) + 24;
FRM_Y2(newfrm) = FRM_Y1(newfrm) + 24;
#ifdef _ITEM_DEBUG
printf("item_get_newpos fpos:%d, fr:(%03d,%03d)\n", fposBase, (int)(newfrm[0]), (int)(newfrm[1]) );
#endif
return (item_adjust_pos( newfrm ));
}
int item_chkpos( char *pathItem, int fposStart, short *frmchk )
{
int ret;
int fpos, nextFPos;
int etyNum;
short icnNum;
char ttlStr[128];
int atrInf;
short frm[4];
int numItem;
#ifdef _ITEM_DEBUG
printf("item_chkpos fpos:%d, fr:(%03d,%03d)\n", fposStart, (int)(frmchk[0]), (int)(frmchk[1]) );
fflush(stdout);
#endif
if ( (fpos = fposStart) > 0 )
{
ret = ITM_GetItmType(pathItem,fpos);
if ( ret != 1 ) /* グループアイテムではない */
return (-1);
ITM_GetGrpData(pathItem,fpos,&etyNum,&icnNum,ttlStr,&nextFPos,frm);
/* グループアイテム配下のアイテムをチェック */
#ifdef _ITEM_DEBUG
printf("item num = %d\n", etyNum); fflush(stdout);
#endif
while ( etyNum-- > 0 )
{
if ( (fpos = ITM_GetPhysclNextFPos( pathItem, fpos )) < 0 )
break; /* error */
if ( (ret = item_get_fr( pathItem, fpos, frm )) == 0 )
{
if ( FRM_X1(frm) <= FRM_X2(frmchk) && FRM_X2(frm) >= FRM_X1(frmchk)
&& FRM_Y1(frm) <= FRM_Y2(frmchk) && FRM_Y2(frm) >= FRM_Y1(frmchk) )
return (0); /* FALSE */
}
}
} else
{ /* ルート */
while ( (fpos = ITM_GetPhysclNextFPos( pathItem, fpos )) > 0 )
{
if ( ITM_GetStair( pathItem, fpos ) == 0 )
{
if ( (ret = item_get_fr( pathItem, fpos, frm )) == 0 )
{
if ( FRM_X1(frm) <= FRM_X2(frmchk) && FRM_X2(frm) >= FRM_X1(frmchk)
&& FRM_Y1(frm) <= FRM_Y2(frmchk) && FRM_Y2(frm) >= FRM_Y1(frmchk) )
return (0); /* FALSE */
}
}
}
}
return (1); /* OK */
}
int item_get_fr( char *pathItem, int fpos, short *fr )
{
int ret;
int nextFPos;
int etyNum;
short icnNum;
char ttlStr[128], pathStr[128], paraStr[128];
int atrInf;
#ifdef _ITEM_DEBUG
printf("item_get_fr(fpos;%d)\n", fpos );
#endif
ret = ITM_GetItmType(pathItem,fpos);
#ifdef _ITEM_DEBUG
printf(" item type = %d\n", ret ); fflush(stdout);
#endif
switch ( ret )
{
case 1: /* group */
ITM_GetGrpData(pathItem,fpos,&etyNum,&icnNum,ttlStr,&nextFPos,fr);
#ifdef _ITEM_DEBUG
printf(" group fr:(%03d,%03d)\n", (int)(fr[0]),(int)(fr[1])); fflush(stdout);
#endif
break;
case 2: /* apllication */
ITM_GetAplData(pathItem,fpos,&icnNum,ttlStr,pathStr,paraStr,atrInf,fr);
#ifdef _ITEM_DEBUG
printf(" app fr:(%03d,%03d)\n", (int)(fr[0]),(int)(fr[1])); fflush(stdout);
#endif
break;
case 3: /* v1.1 group */
return (-1);
default:
return (-1);
}
return (0);
}
int item_adjust_pos( short *newfrm )
{
if ( FRM_X2(newfrm) > 621 )
{
FRM_X2(newfrm) = 621;
FRM_X1(newfrm) = FRM_X2(newfrm) - 24;
}
if ( FRM_Y2(newfrm) > 410 )
{
FRM_Y2(newfrm) = 410;
FRM_Y1(newfrm) = FRM_Y2(newfrm) - 24;
}
return (NORMAL);
}