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

  1. // 0423-36-6862 taguchi
  2. #define MODULE_COPY
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <winb.h>
  8. #include <te.h>
  9. #include <fntb.h>
  10. #include <gui.h>
  11. #include <egb.h>
  12. #include <wgb.h>
  13. #include <msdos.cf>
  14. #include "art.h"
  15. #include "guisub.h"
  16. #include "wgbmac.H"
  17.  
  18. #include "imagewin.h"
  19. #include "imgwin.h"
  20. #include "pensel.h"
  21. #include "colsel.h"
  22. #include "fifo.h"
  23. #include "subgrp.h"
  24. #include "desktop.h"
  25. #include "copy.h"
  26.  
  27. int input_rectarea(IMWIN *win, EVENT *ev_first)
  28. // first:最初のマウス座標
  29. // type:0=矩形
  30. {
  31.     imagewin_storeUndo(win);
  32.   // クリップ枠の設定
  33.     RM_setClipVisibleAllScr();
  34.     RM_setOriginZero();
  35.   // データ構造の初期化
  36.     int type = 0;
  37.     EVENT *ev = ev_first;
  38.     POINT cp = *(POINT*)&ev->info; // 現在のカーソル位置
  39.     POINT lastp = cp;
  40.     FRAME frSrc;      // コピー元領域を表す PIC 領域 (x,y,wid,ht)
  41.   // コピー元を指定するイベントループ
  42.     // 最初に指定された点が、コピー元の座標1
  43.     POINT srcStartPt;
  44.     imagewin_getPosFromMos(win, &cp, &srcStartPt);
  45.     BOOL fFirst = TRUE;
  46.     for (;;)
  47.     {
  48.       // カーソルの現在位置のオブジェクトID および IMWIN を得る
  49.         int curobj = RM_getObjFromPoint(&cp);
  50.         IMWIN* curwin = imagewin_getWinFromPart(curobj);
  51.       // ラバー描画
  52.         if (curwin == win && imagewin_PtInPic(curwin, &cp))
  53.         {
  54.             POINT p; imagewin_getPosFromMos(win,&cp,&p);
  55.             FRAME fr;
  56.             fr.X = _min(srcStartPt.x, p.x);
  57.             fr.Y = _min(srcStartPt.y, p.y);
  58.             fr.WID = abs(srcStartPt.x - p.x) + 1;
  59.             fr.HT = abs(srcStartPt.y - p.y) + 1;
  60.             imagewin_setBoxRubber(win, &fr);
  61.         }
  62.         else
  63.             imagewin_clearBoxRubber(win);
  64.       // 左ボタンがクリックされたら
  65.         if (!fFirst && ev->what == EVMOSDN && (ev->shift & SLEFTBTN) != 0)
  66.         {
  67.             if (curwin == win && imagewin_PtInPic(win, &cp))
  68.             {
  69.                 imagewin_clearBoxRubber(win);
  70.               // コピー元領域が決定したので次にすすむ
  71.                 POINT p1;
  72.                 imagewin_getPosFromMos(win, &cp, &p1);
  73.                 if (p1.x < srcStartPt.x)
  74.                     SWAP_INT(p1.x, srcStartPt.x)
  75.                 if (p1.y < srcStartPt.y)
  76.                     SWAP_INT(p1.y, srcStartPt.y)
  77.                 frSrc.X = srcStartPt.x;
  78.                 frSrc.Y = srcStartPt.y;
  79.                 frSrc.WID = p1.x - srcStartPt.x + 1;
  80.                 frSrc.HT  = p1.y - srcStartPt.y + 1;
  81.                 lastp = cp;
  82.                 break;
  83.             }
  84.             else if (curwin != NULL)
  85.                 MMI_ExecEvnt(ev);
  86.         }
  87.       // 右ボタンがクリックされたら終了
  88.         else if (ev->what == EVMOSDN && (ev->shift & SRIGHTBTN) != 0)
  89.         {
  90.             imagewin_clearBoxRubber(win);
  91.             goto ENDCOPY;
  92.         }
  93.       // イベントセンス
  94.         do {
  95.             MMI_iosense();
  96.         } while (MMI_GetEvnt(EVALL, &ev) != NOERR);
  97.         fFirst = FALSE;
  98.       // イベント種別、シフト状態、マウス座標を得る
  99.         cp = *(POINT *) &ev->info;
  100.     }
  101.   // コピー先を指定するイベントループ
  102.     // コピー元のラバーを設定
  103.     imagewin_setBoxRubber(win, &frSrc);
  104.     fFirst = TRUE;
  105.     IMWIN* rubberwin = NULL;
  106.       for (;;)
  107.       {
  108.       // カーソルの現在位置のオブジェクトID および IMWIN を得る
  109.         int curobj = RM_getObjFromPoint(&cp);
  110.         IMWIN* curwin = imagewin_getWinFromPart(curobj);
  111.       // ラバー描画
  112.         if (curwin != NULL && imagewin_PtInPic(curwin, &cp))
  113.         {
  114.             POINT p; imagewin_getPosFromMos(curwin,&cp,&p);
  115.             FRAME fr = {p.x, p.y, frSrc.WID, frSrc.HT};
  116.             if (rubberwin != NULL && rubberwin != curwin)
  117.                 imagewin_clearBoxRubber2(rubberwin);
  118.             imagewin_setBoxRubber2(curwin, &fr);
  119.             rubberwin = curwin;
  120.         }
  121.         else if (rubberwin != NULL)
  122.         {
  123.             imagewin_clearBoxRubber2(rubberwin);
  124.             rubberwin = NULL;
  125.         }
  126.       // 左ボタンがクリックされたら
  127.         if (!fFirst && ev->what == EVMOSDN && (ev->shift & SLEFTBTN) != 0)
  128.         {
  129.             if (curwin != NULL && imagewin_PtInPic(curwin,&cp))
  130.             {
  131.                 if (rubberwin != NULL)
  132.                     imagewin_clearBoxRubber2(rubberwin);
  133.                 imagewin_clearBoxRubber(win);
  134.                 POINT ptDest;
  135.                 imagewin_getPosFromMos(curwin, &cp, &ptDest);
  136.                 imagewin_copy(win,&frSrc,curwin,&ptDest);
  137.                 imagewin_setBoxRubber(win, &frSrc);
  138.             }
  139.             else if (curwin != NULL)
  140.                 MMI_ExecEvnt(ev);
  141.         }
  142.       // 右ボタンがクリックされたら終了
  143.         else if (ev->what == EVMOSDN && (ev->shift & SRIGHTBTN) != 0)
  144.         {
  145.             if (rubberwin != NULL)
  146.                 imagewin_clearBoxRubber2(rubberwin);
  147.             imagewin_clearBoxRubber(win);
  148.             goto ENDCOPY;
  149.         }
  150.       // イベントセンス
  151.         do {
  152.             MMI_iosense();
  153.         } while (MMI_GetEvnt(EVALL, &ev) != NOERR);
  154.         fFirst = FALSE;
  155.       // 現在のカーソル位置を得る
  156.         cp = *(POINT *)&ev->info;
  157.       }
  158. ENDCOPY:;
  159.   // クリップ枠の復帰
  160.     RM_recoverOrigin();
  161.     RM_recoverClipVisible() ;
  162.   // 次に続くイベントをキューに積む
  163.     EVENT evbuf;
  164.     evbuf = *ev;
  165.     evbuf.what = EVMOSUP;
  166.     evbuf.shift = (evbuf.shift & (~SRIGHTBTN)) | SLEFTBTN;
  167.     MMI_SetEvnt(&evbuf);
  168.     return NOERR ;
  169. }
  170.  
  171.  
  172. int input_polygonarea(IMWIN *win, EVENT *ev_first)
  173. // first:最初のマウス座標
  174. // type:0=矩形
  175. {
  176.     imagewin_storeUndo(win);
  177.   // クリップ枠の設定
  178.     RM_setClipVisibleAllScr();
  179.     RM_setOriginZero();
  180.   // データ構造の初期化
  181.     int type = 0;
  182.     EVENT *ev = ev_first;
  183.     POINT cp = *(POINT*)&ev->info; // 現在のカーソル位置
  184.     #define MAXPOINT 2000
  185.     POINT *points = TL_calloc(sizeof(POINT), MAXPOINT);
  186.     int nPoint = 0;
  187.     if (points == NULL)
  188.         goto ENDCOPY;
  189.     POINT lastp = cp;
  190.     POINT lastPicPt;  imagewin_getPosFromMos(win, &lastp, &lastPicPt);
  191.     FRAME frSrc = {lastPicPt.x,lastPicPt.y,lastPicPt.x,lastPicPt.y};
  192.     AREA areaSrc = NULL;
  193.     // 更新中は (x1,y1,x2,y2) 形式
  194.     void updateFrSrc(POINT* pt)
  195.     {
  196.         frSrc.X = _min(frSrc.X, pt->x);
  197.         frSrc.Y = _min(frSrc.Y, pt->y);
  198.         frSrc.X2 = _max(frSrc.X2, pt->x);
  199.         frSrc.Y2 = _max(frSrc.Y2, pt->y);
  200.     }
  201.   // 最初の点を座標配列に登録
  202.     points[nPoint++] = lastPicPt;
  203.   // コピー元を指定するイベントループ
  204.     BOOL fFirst = TRUE;
  205.     for (;;)
  206.     {
  207.       // カーソルの現在位置のオブジェクトID および IMWIN を得る
  208.         int curobj = RM_getObjFromPoint(&cp);
  209.         IMWIN* curwin = imagewin_getWinFromPart(curobj);
  210.       // ラバー描画
  211.         if (curwin == win && imagewin_PtInPic(curwin, &cp))
  212.         {
  213.             imagewin_resetLineRubber2(win);
  214.             POINT p2;
  215.             imagewin_getPosFromMos(win, &cp, &p2);
  216.             imagewin_addLineRubber2(win, &lastPicPt, &p2);
  217.         }
  218.         else
  219.         {
  220.             imagewin_resetLineRubber2(win);
  221.             imagewin_updateScr(win);
  222.         }
  223.       // 左ボタンがクリックされたら
  224.         if (!fFirst && (ev->what == EVMOSDN || ev->what == EVMOSDRAG)
  225.             && (ev->shift & SLEFTBTN) != 0)
  226.         {
  227.             if (curwin == win && imagewin_PtInPic(win, &cp))
  228.             {
  229.                 imagewin_resetLineRubber2(win);
  230.               // ラバー追加
  231.                 POINT p2;
  232.                 imagewin_getPosFromMos(win, &cp, &p2);
  233.                 imagewin_addLineRubber(win, &lastPicPt, &p2);
  234.                 updateFrSrc(&p2);
  235.                 points[nPoint++] = p2;
  236.                 lastPicPt = p2;
  237.                 lastp = cp;
  238.             }
  239.             else if (curwin != NULL)
  240.                 MMI_ExecEvnt(ev);
  241.         }
  242.       // 右ボタンがクリックされたら終了
  243.         else if (ev->what == EVMOSDN && (ev->shift & SRIGHTBTN) != 0)
  244.         {
  245.             imagewin_resetLineRubber2(win);
  246.             if (imagewin_nLineRubber(win) >= 2)
  247.             {
  248.               // ラバー追加
  249.                 imagewin_addLineRubber(win, &lastPicPt, NULL);
  250.                 imagewin_updateScr(win);
  251.                 break;
  252.             }
  253.             else
  254.             {
  255.                 imagewin_resetLineRubber(win);
  256.                 imagewin_updateScr(win);
  257.                 goto ENDCOPY;
  258.             }
  259.         }
  260.       // イベントセンス
  261.         do {
  262.             MMI_iosense();
  263.         } while (MMI_GetEvnt(EVALL, &ev) != NOERR);
  264.         fFirst = FALSE;
  265.       // イベント種別、シフト状態、マウス座標を得る
  266.         cp = *(POINT *) &ev->info;
  267.     }
  268.   // frSrc を (x,y,wid,ht) 形式に変更
  269.     SortRect((Rect*)&frSrc);
  270.     frSrc.WID = frSrc.X2 - frSrc.X + 1;
  271.     frSrc.HT  = frSrc.Y2 - frSrc.Y + 1;
  272.   // areaSrc を作成
  273.     areaSrc = area_new(frSrc.X, frSrc.Y, frSrc.WID, frSrc.HT);
  274.     if (areaSrc == NULL)
  275.         goto ENDCOPY;
  276.     area_polygon(areaSrc, points, nPoint);
  277.   // コピー先を指定するイベントループ
  278.     fFirst = TRUE;
  279.     IMWIN* rubberwin = NULL;
  280.       for (;;)
  281.       {
  282.       // カーソルの現在位置のオブジェクトID および IMWIN を得る
  283.         int curobj = RM_getObjFromPoint(&cp);
  284.         IMWIN* curwin = imagewin_getWinFromPart(curobj);
  285.       // ラバー描画
  286.         if (curwin != NULL && imagewin_PtInPic(curwin, &cp))
  287.         {
  288.             POINT p; imagewin_getPosFromMos(curwin,&cp,&p);
  289.             FRAME fr = {p.x, p.y, frSrc.WID, frSrc.HT};
  290.             if (rubberwin != NULL && rubberwin != curwin)
  291.                 imagewin_clearBoxRubber2(rubberwin);
  292.             imagewin_setBoxRubber2(curwin, &fr);
  293.             rubberwin = curwin;
  294.         }
  295.         else if (rubberwin != NULL)
  296.         {
  297.             imagewin_clearBoxRubber2(rubberwin);
  298.             rubberwin = NULL;
  299.         }
  300.       // 左ボタンがクリックされたら
  301.         if (!fFirst && ev->what == EVMOSDN && (ev->shift & SLEFTBTN) != 0)
  302.         {
  303.             if (curwin != NULL && imagewin_PtInPic(curwin,&cp))
  304.             {
  305.                 if (rubberwin != NULL)
  306.                     imagewin_clearBoxRubber2(rubberwin);
  307.                 POINT ptDest;
  308.                 imagewin_getPosFromMos(curwin, &cp, &ptDest);
  309.                 imagewin_copyarea(win, areaSrc, curwin, &ptDest);
  310.             }
  311.             else if (curwin != NULL)
  312.                 MMI_ExecEvnt(ev);
  313.         }
  314.       // 右ボタンがクリックされたら終了
  315.         else if (!fFirst && ev->what==EVMOSDN && (ev->shift & SRIGHTBTN) != 0)
  316.         {
  317.             if (rubberwin != NULL)
  318.                 imagewin_clearBoxRubber2(rubberwin);
  319.             break;
  320.         }
  321.       // イベントセンス
  322.         do {
  323.             MMI_iosense();
  324.         } while (MMI_GetEvnt(EVALL, &ev) != NOERR);
  325.         fFirst = FALSE;
  326.       // 現在のカーソル位置を得る
  327.         cp = *(POINT *)&ev->info;
  328.       }
  329. ENDCOPY:;
  330.     imagewin_resetLineRubber(win);
  331.     imagewin_updateScr(win);
  332.     if (areaSrc != NULL)
  333.         area_delete(areaSrc);
  334.     if (points != NULL)
  335.         TL_free(points);
  336.   // クリップ枠の復帰
  337.     RM_recoverOrigin();
  338.     RM_recoverClipVisible() ;
  339.   // 次に続くイベントをキューに積む
  340.     EVENT evbuf;
  341.     evbuf = *ev;
  342.     evbuf.what = EVMOSUP;
  343.     evbuf.shift = (evbuf.shift & (~SRIGHTBTN)) | SLEFTBTN;
  344.     MMI_SetEvnt(&evbuf);
  345.     return NOERR ;
  346. }
  347.  
  348. int cmd_polygonfill(IMWIN *win, EVENT *ev_first)
  349. // first:最初のマウス座標
  350. // type:0=矩形
  351. {
  352.     imagewin_storeUndo(win);
  353.   // クリップ枠の設定
  354.     RM_setClipVisibleAllScr();
  355.     RM_setOriginZero();
  356.   // データ構造の初期化
  357.     int type = 0;
  358.     EVENT *ev = ev_first;
  359.     POINT cp = *(POINT*)&ev->info; // 現在のカーソル位置
  360.     #define MAXPOINT 2000
  361.     POINT *points = TL_calloc(sizeof(POINT), MAXPOINT);
  362.     int nPoint = 0;
  363.     if (points == NULL)
  364.         goto ENDCOPY;
  365.     POINT lastp = cp;
  366.     POINT lastPicPt;  imagewin_getPosFromMos(win, &lastp, &lastPicPt);
  367.     FRAME frSrc = {lastPicPt.x,lastPicPt.y,lastPicPt.x,lastPicPt.y};
  368.     AREA areaSrc = NULL;
  369.     // 更新中は (x1,y1,x2,y2) 形式
  370.     void updateFrSrc(POINT* pt)
  371.     {
  372.         frSrc.X = _min(frSrc.X, pt->x);
  373.         frSrc.Y = _min(frSrc.Y, pt->y);
  374.         frSrc.X2 = _max(frSrc.X2, pt->x);
  375.         frSrc.Y2 = _max(frSrc.Y2, pt->y);
  376.     }
  377.   // 最初の点を座標配列に登録
  378.     points[nPoint++] = lastPicPt;
  379.   // コピー元を指定するイベントループ
  380.     BOOL fFirst = TRUE;
  381.     for (;;)
  382.     {
  383.       // カーソルの現在位置のオブジェクトID および IMWIN を得る
  384.         int curobj = RM_getObjFromPoint(&cp);
  385.         IMWIN* curwin = imagewin_getWinFromPart(curobj);
  386.       // ラバー描画
  387.         if (curwin == win && imagewin_PtInPic(curwin, &cp))
  388.         {
  389.             imagewin_resetLineRubber2(win);
  390.             POINT p2;
  391.             imagewin_getPosFromMos(win, &cp, &p2);
  392.             imagewin_addLineRubber2(win, &lastPicPt, &p2);
  393.         }
  394.         else
  395.         {
  396.             imagewin_resetLineRubber2(win);
  397.             imagewin_updateScr(win);
  398.         }
  399.       // 左ボタンがクリックされたら
  400.         if (!fFirst && (ev->what == EVMOSDN || ev->what == EVMOSDRAG)
  401.             && (ev->shift & SLEFTBTN) != 0)
  402.         {
  403.             if (curwin == win && imagewin_PtInPic(win, &cp))
  404.             {
  405.                 imagewin_resetLineRubber2(win);
  406.               // ラバー追加
  407.                 POINT p2;
  408.                 imagewin_getPosFromMos(win, &cp, &p2);
  409.                 imagewin_addLineRubber(win, &lastPicPt, &p2);
  410.                 updateFrSrc(&p2);
  411.                 points[nPoint++] = p2;
  412.                 lastPicPt = p2;
  413.                 lastp = cp;
  414.             }
  415.             else if (curwin != NULL)
  416.                 MMI_ExecEvnt(ev);
  417.         }
  418.       // 右ボタンがクリックされたら終了
  419.         else if (ev->what == EVMOSDN && (ev->shift & SRIGHTBTN) != 0)
  420.         {
  421.             imagewin_resetLineRubber2(win);
  422.             if (imagewin_nLineRubber(win) >= 2)
  423.             {
  424.               // ラバー追加
  425.                 imagewin_addLineRubber(win, &lastPicPt, NULL);
  426.                 imagewin_updateScr(win);
  427.                 break;
  428.             }
  429.             else
  430.             {
  431.                 imagewin_resetLineRubber(win);
  432.                 imagewin_updateScr(win);
  433.                 goto ENDCOPY;
  434.             }
  435.         }
  436.       // イベントセンス
  437.         do {
  438.             MMI_iosense();
  439.         } while (MMI_GetEvnt(EVALL, &ev) != NOERR);
  440.         fFirst = FALSE;
  441.       // イベント種別、シフト状態、マウス座標を得る
  442.         cp = *(POINT *) &ev->info;
  443.     }
  444.     imagewin_clearLineRubber(win);
  445.   // frSrc を (x,y,wid,ht) 形式に変更
  446.     SortRect((Rect*)&frSrc);
  447.     frSrc.WID = frSrc.X2 - frSrc.X + 1;
  448.     frSrc.HT  = frSrc.Y2 - frSrc.Y + 1;
  449.   // areaSrc を作成
  450.     areaSrc = area_new(frSrc.X, frSrc.Y, frSrc.WID, frSrc.HT);
  451.     if (areaSrc == NULL)
  452.         goto ENDCOPY;
  453.     area_polygon(areaSrc, points, nPoint);
  454.   // 領域塗りつぶし
  455.     PIXEL pix;
  456.     colsel_getPixel(&pix);
  457.     pic_beginUpDate(win->pic);
  458.     pic_fillarea(win->pic, areaSrc, &pix);
  459.     FRAME frUpdate;
  460.     pic_endUpDate(win->pic, &frUpdate);
  461.     imagewin_updateScrPart(win, &frUpdate);
  462. ENDCOPY:;
  463.     imagewin_resetLineRubber(win);
  464.     imagewin_updateScr(win);
  465.     if (areaSrc != NULL)
  466.         area_delete(areaSrc);
  467.     if (points != NULL)
  468.         TL_free(points);
  469.   // クリップ枠の復帰
  470.     RM_recoverOrigin();
  471.     RM_recoverClipVisible() ;
  472.   // 次に続くイベントをキューに積む
  473.     EVENT evbuf;
  474.     evbuf = *ev;
  475.     evbuf.what = EVMOSUP;
  476.     evbuf.shift = (evbuf.shift & (~SRIGHTBTN)) | SLEFTBTN;
  477.     MMI_SetEvnt(&evbuf);
  478.     return NOERR ;
  479. }
  480.