home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MODEL / BUTTLIB.C < prev    next >
C/C++ Source or Header  |  1996-02-28  |  4KB  |  172 lines

  1. /*
  2.  *        ユーザーボタン制御
  3.  *
  4.  *        Copyright    M.Takatsu    1996.1.24
  5.  */
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <ctype.h>
  9.  
  10. #include "ml.h"
  11. #include "strclass.h"
  12. #include "view.h"
  13. #include "button.h"
  14.  
  15. static    char    *SysConstName[] = {
  16.     "BUTTON_WIDTH",
  17.     "BUTTON_HEIGHT",
  18.     "BUTTON_DISABLE",
  19.     "BUTTON_ENABLE",
  20.     "BUTTON_NOREPEAT",
  21.     "BUTTON_REPEAT",
  22.     NULL
  23. };
  24.  
  25. static    IntData        SysConst[] = {
  26.     { TYPE_INT,        0,        BUTTON_WIDTH,        },
  27.     { TYPE_INT,        0,        BUTTON_HEIGHT,        },
  28.     { TYPE_INT,        0,        BUTTON_DISABLE,        },
  29.     { TYPE_INT,        0,        BUTTON_ENABLE,        },
  30.     { TYPE_INT,        0,        BUTTON_NOREPEAT,        },
  31.     { TYPE_INT,        0,        BUTTON_REPEAT,        },
  32. };
  33.  
  34. static    int    StringClassID;
  35.  
  36. static    int        FuncCreateButton( int, int, DataStruct* );
  37. static    int        FuncUpdateButton( int, int, DataStruct* );
  38. static    int        FuncClearButton( int, int, DataStruct* );
  39. static    int        FuncButtonArea( int, int, DataStruct* );
  40. static    int        FuncButtonEnable( int, int, DataStruct* );
  41.  
  42. /*    初期化    */
  43. void    ButtonLibInit()
  44. {
  45.     int i;
  46.     StringClassID = ClassName( "String" );
  47.     for( i = 0 ; SysConstName[i] != NULL ; i++ )
  48.     {
  49.         NewConst( SysConstName[i], (DataStruct*)&SysConst[i] );
  50.     }
  51.     NewFunction( 0, "CreateButton", FuncCreateButton );
  52.     NewFunction( 0, "UpdateButton", FuncUpdateButton );
  53.     NewFunction( 0, "ClearButton", FuncClearButton );
  54.     NewFunction( 0, "ButtonArea", FuncButtonArea );
  55.     NewFunction( 0, "ButtonEnable", FuncButtonEnable );
  56. }
  57.  
  58. static    int        ConvertStringToBitmap(char *dst, char *src)
  59. {
  60.     int i, j;
  61.     unsigned short data, *p;
  62.     p = (unsigned short *)dst;
  63.     for (i = ((BUTTON_BITMAP_WIDTH-1)/16+1)*BUTTON_BITMAP_HEIGHT; i > 0; --i) {
  64.         data = 0;
  65.         for (j = 4; j > 0; --j, src++) {
  66.             data *= 16;
  67.             while (*src != '\0' && !isxdigit(*src)) {
  68.                 src++;
  69.             }
  70.             if (*src == '\0') {
  71.                 return FALSE;
  72.             }
  73.             if (isdigit(*src)) {
  74.                 data += (*src - '0');
  75.             } else if ('A' <= *src && *src <= 'F') {
  76.                 data += (*src - 'A' + 10);
  77.             } else if ('a' <= *src && *src <= 'a') {
  78.                 data += (*src - 'a' + 10);
  79.             }
  80.         }
  81.         *p++ = data;
  82.     }
  83.     return TRUE;
  84. }
  85.  
  86. static    int        FuncCreateButton(int ident, int args, DataStruct *buf)
  87. {
  88.     int x, y, exec;
  89.     int id, enable;
  90.     char *str, bitmap[((BUTTON_BITMAP_WIDTH-1)/16+1)*2*BUTTON_BITMAP_HEIGHT];
  91.     id = -1;
  92.     enable = BUTTON_ENABLE;
  93.     if (args > 4) {
  94.         ArgCheck( "CreateButton", args, buf, TYPE_INT, TYPE_INT, TYPE_OBJECT, TYPE_FUNC, TYPE_INT, TYPE_NOASN );
  95.         enable = buf[4].id.i;
  96.     } else {
  97.         ArgCheck( "CreateButton", args, buf, TYPE_INT, TYPE_INT, TYPE_OBJECT, TYPE_FUNC, TYPE_NOASN );
  98.     }
  99.     if (ObjectCheck(&buf[2], StringClassID) == FALSE) {
  100.         ExecError("SetButtonArea:3番目の引数の型が異なる\n");
  101.     }
  102.     x = buf[0].id.i;
  103.     y = buf[1].id.i;
  104.     exec = buf[3].funcd.ident ;
  105.     str = ((StringClass*)buf[2].od.ptr)->str;
  106.     if (ConvertStringToBitmap(bitmap, str)) {
  107.         id = CreateButton(x, y, bitmap, BUTTON_BITMAP, exec, enable);
  108.     } else {
  109.         id = CreateButton(x, y, str, BUTTON_STRING, exec, enable);
  110.     }
  111.  
  112.     StackPushInt(id);
  113.     return RETURN_RETURN;
  114. }
  115.  
  116. static    int        FuncUpdateButton(int ident, int args, DataStruct *buf)
  117. {
  118.     if (args > 0) {
  119.         ArgCheck( "SetButtonArea", args, buf, TYPE_INT, TYPE_NOASN);
  120.         DrawUserButton(buf[0].id.i);
  121.     } else {
  122.         DrawUserButtonAll();
  123.     }
  124.     return RETURN_VOID;
  125. }
  126.  
  127. static    int        FuncClearButton(int ident, int args, DataStruct *buf)
  128. {
  129.     int i;
  130.     for (i = 0; i < MAX_BUTTON; ++i) {
  131.         UserButton[i].type = BUTTON_UNUSED;
  132.     }
  133.     return RETURN_VOID;
  134. }
  135.  
  136. static    int        FuncButtonArea(int ident, int args, DataStruct *buf)
  137. {
  138.     int w;
  139.     w = ButtonAreaWidth;
  140.     if (args > 0) {
  141.         ArgCheck( "SetButtonArea", args, buf, TYPE_INT, TYPE_NOASN );
  142.         ViewCursor( OFF );
  143.         SetButtonArea(buf[0].id.i);
  144.         ViewFrame();
  145.         ViewLineAll( 0, 0, 4096, 4096, TRUE );
  146.         ViewCursor( ON );
  147.     }
  148.     StackPushInt( w );
  149.     return RETURN_RETURN ;
  150. }
  151.  
  152. static    int        FuncButtonEnable(int ident, int args, DataStruct *buf)
  153. {
  154.     int id, enable = -1;
  155.     if (args > 1) {
  156.         ArgCheck( "ButtonEnable", args, buf, TYPE_INT, TYPE_INT, TYPE_NOASN );
  157.         enable = buf[1].id.i;
  158.     } else {
  159.         ArgCheck( "ButtonEnable", args, buf, TYPE_INT, TYPE_NOASN );
  160.     }
  161.     id = buf[0].id.i;
  162.     if (0 <= id && id < MAX_BUTTON && UserButton[id].type != BUTTON_UNUSED) {
  163.         if (enable < 0) {
  164.             enable = UserButton[id].enable;
  165.         } else {
  166.             UserButton[id].enable = enable;
  167.         }
  168.     }
  169.     StackPushInt( enable );
  170.     return RETURN_RETURN ;
  171. }
  172.