home *** CD-ROM | disk | FTP | other *** search
/ Phoenix Heaven Sunny 2 / APPARE2.BIN / oh_towns / art2 / src.lzh / IMGBTN.C < prev    next >
C/C++ Source or Header  |  1995-06-17  |  4KB  |  150 lines

  1. /*====================================================
  2.                       ARTemis
  3.                    (version 1.3)
  4.              FM-TOWNS 用ペイントツール
  5.  
  6.                  by 松内 良介 1994
  7. ====================================================*/
  8. /*
  9.     imgbtn.c  :  イメージボタン型部品・実現モジュール
  10.     
  11.     外部関数:
  12.         int MMI_initImageBtn(void)
  13. */
  14.  
  15. #define    MODULE_IMGBTN
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <winb.h>
  21. #include <te.h>
  22. #include <fntb.h>
  23. #include <gui.h>
  24. #include "art.h"
  25. #include "imgbtn.h"
  26.  
  27. int        MJ_IMGBTN = -1;
  28.  
  29. extern int    ML_DspDrawBtnL40(int kobj, int messId, int argc);
  30.  
  31. /*    表示処理    */
  32.  
  33.     static int ML_IMGBTNdisp(kobj, messId, argc)
  34.     int        kobj ;
  35.     int        messId ;
  36.     int        argc ;
  37.     {
  38.         register IMGBTN *pbtn ;  IMGBTN btn ;
  39.         ML_DspDrawBtnL40(kobj, messId, argc);
  40.         btn = *(pbtn = ((IMGBTN *)(TL_getObjectPtr(kobj)->data))) ;
  41.         if (btn.func == (int(*)())NULL)
  42.             return NOERR;
  43.       /* 部品の位置を得る */
  44.         MG_CorrectPositionL40(&(btn.fr), (HYPER *)pbtn) ;
  45.       /* 最描画する必要があるか? */
  46.         if (MMI_CheckUpdateFrame(&(btn.fr)) && btn.func!=0)
  47.         {
  48.             POINT new,old;
  49.             WINCLIP *clip;
  50.             MG_mosDisp(2) ;
  51.             WIN_beginUpDateObj(kobj, &clip);
  52.             new.x = new.y = 0;
  53.             MG_PushOrigin(&new, &old);
  54.             if (btn.func != (int(*)())NULL)
  55.                 (*btn.func)(kobj, MM_SHOW, 0);
  56.             MG_PopOrigin(&old);
  57.             WIN_endUpDateObj(clip);
  58.             MG_mosDisp(3) ;
  59.         }
  60.       /* おわり */
  61.         return NOERR ;
  62.     }
  63.  
  64. /*    呼び出し関数の登録  */
  65.     
  66.     static int ML_IMGBTNsetexec(kobj, messId, argc, func)
  67.     int        kobj ;
  68.     int        messId ;
  69.     int        argc ;
  70.     int        (*func)();
  71.     {
  72.         IMGBTN *plbl ;
  73.         plbl = (IMGBTN *) ( TL_getObjectPtr(kobj) -> data ) ;
  74.         plbl->func = func ;
  75.         return NOERR ;
  76.     }
  77.  
  78. /* マウスボタンが押されたときの呼び出し関数 */
  79.  
  80.     static int ML_IMGBTNmouseon(kobj, messId, argc, pev)
  81.     int        kobj ;
  82.     int        messId ;
  83.     int        argc ;
  84.     EVENT    *pev;
  85.     {
  86.         IMGBTN *plbl ;
  87.         plbl = (IMGBTN *) ( TL_getObjectPtr(kobj) -> data ) ;
  88.       /* 属性MS_BTLEFTL40,MS_BTRIGHTL40 のいずれも非設定だったり、
  89.          あるいはボタンが左右とも押されていない場合はなにもしない */
  90.         if (((plbl->atr &(MS_BTLEFTL40|MS_BTRIGHTL40)) & 
  91.                                         ((pev->shift) << 22)) == 0)
  92.             return NOERR ;
  93.       /* 実行関数の起動 */
  94.         if (plbl->func != (int(*)())NULL)
  95.             (*plbl->func)(kobj, MM_MOUSEON, 1, pev);
  96.         return NOERR ;
  97.     }
  98.  
  99. /* メッセージに対する関数の対応 */
  100.  
  101.     #define    NMET_IMGBTN    3
  102.     
  103.     static int (*MF_IMGBTNmethod[NMET_IMGBTN])() = {
  104.         ML_IMGBTNdisp,
  105.         ML_IMGBTNmouseon,
  106.         ML_IMGBTNsetexec
  107.     } ;
  108.     
  109.     static char *MM_IMGBTNmessage[NMET_IMGBTN] = {
  110.         MT_SHOW,
  111.         MT_MOUSEON,
  112.         MT_SETEXEC
  113.     };
  114.  
  115. /* 初期化関数 */
  116.  
  117.     int MMI_initImageBtn(void)
  118.     {
  119.         MJ_IMGBTN = MMI_AddType(MJ_HYPER, NMET_IMGBTN,
  120.                                 sizeof(IMGBTN),
  121.                                 MF_IMGBTNmethod,
  122.                                 MM_IMGBTNmessage) ;
  123.         if (MJ_IMGBTN < NOERR)
  124.             return MJ_IMGBTN ;
  125.         return NOERR ;
  126.     }
  127.  
  128. /* プロトタイプの生成 */
  129.  
  130.     #define ALIGN    4
  131.     #define OFFSET(type) \
  132.             (sizeof(MMIPACKET) + (sizeof(type)+ALIGN-1)/ALIGN*ALIGN)
  133.  
  134.     int IMGBTN_makePrototype(int *objId)
  135.     {
  136.         static int tempId;
  137.         static MMIINIT initDataIMGBTN = { "MmiInit",   1, 0 } ;
  138.         static MMIPACKET d001 = { &tempId, NULL, &MJ_IMGBTN,
  139.                                   OFFSET(IMGBTN), MS_NONE };
  140.         static IMGBTN    d001d = { MS_EVMOSONL40 | MS_BTLEFTL40,
  141.                                    0,0,47,47, 0,0,0,
  142.                                    MS_NONEL40, (int(*)())NULL };
  143.         int ret;
  144.         if ((ret = MMI_Init(&initDataIMGBTN)) < NOERR)
  145.             return ret ;
  146.         *objId = tempId;
  147.         return NOERR;
  148.     }
  149.  
  150.