home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Kyūkyoku!! X68000 Emulator
/
X68000Book.dat
/
mac
/
OLS
/
X68000
/
Ko-Window
/
kow142s.lzh
/
corlib
/
MgButton.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-15
|
3KB
|
129 lines
/* Copyright 1992 H.Ogasawara (COR.) */
#include <wlib.h>
#include <parts.h>
#define PushButton 0
#define PushButtonStr 1
typedef struct mb {
int x1, y1, x2, y2;
struct mb *next;
short type;
int ret;
} MgButton;
typedef struct mbs {
int x1, y1, x2, y2;
struct mb *next;
short type;
int ret;
char *str;
short attr;
short font;
short h;
} MgButtonStr;
void
MgButtonInit( mb )
MgButton *mb;
{
mb->x1= 0;
mb->next= NULL;
}
MgButtonSet( mb, x, y, h, v, num )
MgButton *mb;
{
MgButton *p;
if( p= (MgButton*)malloc( sizeof(MgButton) ) ){
ClipSet( (ClipClass*)p, x, y, h, v );
p->type= PushButton;
p->ret= num;
p->next= mb->next;
mb->next= p;
return TRUE;
}
return FALSE;
}
MgButtonSetSymbol( mb, x, y, h, num, str, attr, font )
MgButton *mb;
char *str;
{
MgButtonStr *p;
if( p= (MgButtonStr*)malloc( sizeof(MgButtonStr) ) ){
p->type= PushButtonStr;
ClipSet( (ClipClass*)p, x, y, strlen(str)*font/2+h+h, font+h+h );
p->ret= num;
p->next= mb->next;
p->str= str;
p->attr= attr;
p->font= font;
p->h= h;
mb->next= (MgButton*)p;
return TRUE;
}
return FALSE;
}
MgButtonSetDraw( mp, dbuf )
MgButtonStr *mp;
DrawBuf *dbuf;
{
DrawBuf *dp= dbuf;
for( mp= (MgButtonStr*)mp->next ; mp ; mp= (MgButtonStr*)mp->next ){
switch( mp->type ){
case PushButtonStr:
DrawSetSymbol( dp++, mp->x1+mp->h, mp->y1+mp->h,
mp->str, mp->attr, mp->font );
case PushButton:
DrawSetLine( dp++, mp->x1, mp->y1, mp->x2, mp->y2,
ShadowUp, OptionShadow );
break;
}
}
return dp-dbuf;
}
MgButtonOperation( wp, info, mp )
WindowID wp;
EventInfo *info;
MgButton *mp;
{
for( mp= mp->next ; mp ; mp= mp->next ){
if( ClipInner( (ClipClass*)mp, info->x, info->y ) ){
DrawBuf dbuf[2];
int press= TRUE;
int sx, sy, hx, hy;
WindowGetScreenPosition( wp, &sx, &sy );
WindowGetHome( wp, &hx, &hy );
DrawSetLine( dbuf, mp->x1, mp->y1, mp->x2, mp->y2,
ShadowDown, OptionShadow );
DrawSetLine( dbuf+1, mp->x1, mp->y1, mp->x2, mp->y2,
ShadowUp, OptionShadow );
WindowDraw( wp, dbuf, 1 );
do{
WindowGetEventInfo( info );
if( ClipInner( (ClipClass*)mp, info->x-sx+hx, info->y-sy+hy ) ){
if( !press ){
WindowDraw( wp, dbuf, 1 );
press= TRUE;
}
}else{
if( press ){
WindowDraw( wp, dbuf+1, 1 );
press= FALSE;
}
}
}while( info->LeftStat || info->RightStat );
if( press ){
WindowDraw( wp, dbuf+1, 1 );
return mp->ret;
}
break;
}
}
return FALSE;
}