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 >
C/C++ Source or Header  |  1992-10-15  |  3KB  |  129 lines

  1. /*    Copyright 1992 H.Ogasawara (COR.)    */
  2.  
  3. #include    <wlib.h>
  4. #include    <parts.h>
  5.  
  6. #define    PushButton    0
  7. #define    PushButtonStr    1
  8.  
  9. typedef struct mb {
  10.     int    x1, y1, x2, y2;
  11.     struct mb *next;
  12.     short    type;
  13.     int    ret;
  14. } MgButton;
  15.  
  16. typedef struct mbs {
  17.     int    x1, y1, x2, y2;
  18.     struct mb *next;
  19.     short    type;
  20.     int    ret;
  21.     char    *str;
  22.     short    attr;
  23.     short    font;
  24.     short    h;
  25. } MgButtonStr;
  26.  
  27. void
  28. MgButtonInit( mb )
  29. MgButton    *mb;
  30. {
  31.     mb->x1= 0;
  32.     mb->next= NULL;
  33. }
  34.  
  35. MgButtonSet( mb, x, y, h, v, num )
  36. MgButton    *mb;
  37. {
  38.     MgButton    *p;
  39.     if( p= (MgButton*)malloc( sizeof(MgButton) ) ){
  40.         ClipSet( (ClipClass*)p, x, y, h, v );
  41.         p->type= PushButton;
  42.         p->ret= num;
  43.         p->next= mb->next;
  44.         mb->next= p;
  45.         return    TRUE;
  46.     }
  47.     return    FALSE;
  48. }
  49. MgButtonSetSymbol( mb, x, y, h, num, str, attr, font )
  50. MgButton    *mb;
  51. char        *str;
  52. {
  53.     MgButtonStr    *p;
  54.     if( p= (MgButtonStr*)malloc( sizeof(MgButtonStr) ) ){
  55.         p->type= PushButtonStr;
  56.         ClipSet( (ClipClass*)p, x, y, strlen(str)*font/2+h+h, font+h+h );
  57.         p->ret= num;
  58.         p->next= mb->next;
  59.         p->str= str;
  60.         p->attr= attr;
  61.         p->font= font;
  62.         p->h= h;
  63.         mb->next= (MgButton*)p;
  64.         return    TRUE;
  65.     }
  66.     return    FALSE;
  67. }
  68.  
  69. MgButtonSetDraw( mp, dbuf )
  70. MgButtonStr    *mp;
  71. DrawBuf        *dbuf;
  72. {
  73.     DrawBuf    *dp= dbuf;
  74.     for( mp= (MgButtonStr*)mp->next ; mp ; mp= (MgButtonStr*)mp->next ){
  75.         switch( mp->type ){
  76.         case PushButtonStr:
  77.             DrawSetSymbol( dp++, mp->x1+mp->h, mp->y1+mp->h,
  78.                         mp->str, mp->attr, mp->font );
  79.         case PushButton:
  80.             DrawSetLine( dp++, mp->x1, mp->y1, mp->x2, mp->y2,
  81.                         ShadowUp, OptionShadow );
  82.             break;
  83.         }
  84.     }
  85.     return    dp-dbuf;
  86. }
  87.  
  88. MgButtonOperation( wp, info, mp )
  89. WindowID    wp;
  90. EventInfo    *info;
  91. MgButton    *mp;
  92. {
  93.     for( mp= mp->next ; mp ; mp= mp->next ){
  94.         if( ClipInner( (ClipClass*)mp, info->x, info->y ) ){
  95.             DrawBuf    dbuf[2];
  96.             int    press= TRUE;
  97.             int    sx, sy, hx, hy;
  98.             WindowGetScreenPosition( wp, &sx, &sy );
  99.             WindowGetHome( wp, &hx, &hy );
  100.             DrawSetLine( dbuf, mp->x1, mp->y1, mp->x2, mp->y2,
  101.                         ShadowDown, OptionShadow );
  102.             DrawSetLine( dbuf+1, mp->x1, mp->y1, mp->x2, mp->y2,
  103.                         ShadowUp, OptionShadow );
  104.             WindowDraw( wp, dbuf, 1 );
  105.             do{
  106.                 WindowGetEventInfo( info );
  107.                 if( ClipInner( (ClipClass*)mp, info->x-sx+hx, info->y-sy+hy ) ){
  108.                     if( !press ){
  109.                         WindowDraw( wp, dbuf, 1 );
  110.                         press= TRUE;
  111.                     }
  112.                 }else{
  113.                     if( press ){
  114.                         WindowDraw( wp, dbuf+1, 1 );
  115.                         press= FALSE;
  116.                     }
  117.                 }
  118.             }while( info->LeftStat || info->RightStat );
  119.             if( press ){
  120.                 WindowDraw( wp, dbuf+1, 1 );
  121.                 return    mp->ret;
  122.             }
  123.             break;
  124.         }
  125.     }
  126.     return    FALSE;
  127. }
  128.  
  129.