home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / MEDIT.LZH / STATUS.CPP < prev    next >
C/C++ Source or Header  |  1996-06-06  |  12KB  |  446 lines

  1. /*  Project medit
  2.     Project Team DoGA
  3.     Copyright (c) 1995. All Rights Reserved.
  4.  
  5.     サブシステム:    medit.apx Application
  6.     ファイル:        status.cpp
  7.     作成者:          Taka2
  8.  
  9.  
  10.     概要
  11.     ====
  12.     TWinStatus (TWindow) のインプリメンテーション用のソースファイル
  13. */
  14.  
  15. #include <owl\owlpch.h>
  16. #pragma hdrstop
  17.  
  18. #include <owl\button.h>
  19. #include <owl\statusba.h>
  20. #include <owl\gadget.h>
  21. #include <owl\textgadg.h>
  22. #include "status.h"
  23. #include "matrix.h"
  24. #include "anim.h"
  25. #include "motion.h"
  26. #include "bezier.h"
  27. #include "mecha.h"
  28. #include "suflib.h"
  29. #include "syscolor.h"
  30. #include "dinput.h"
  31. #include "drange.h"
  32.  
  33. #include "log.h"
  34.  
  35. #define ws (textwidth / 2)
  36. #define hs (textheight-1)
  37. #define ss 1 //(textheight / 4)
  38.  
  39. //
  40. // このアプリケーションで処理するすべてのメッセージ/コマンドの
  41. // 応答テーブルを作成する
  42. //
  43. DEFINE_RESPONSE_TABLE1(TWinStatus, TWindow)
  44. //{{TWinStatusRSP_TBL_BEGIN}}
  45.     EV_WM_LBUTTONDOWN,
  46. //{{TWinStatusRSP_TBL_END}}
  47. END_RESPONSE_TABLE;
  48.  
  49.  
  50. //{{TWinStatus Implementation}}
  51.  
  52.  
  53. TWinStatus::TWinStatus (TWindow* parent, AnimationData *dat, int x, int y, int w, int h):
  54.     TWindow(parent, 0, 0)
  55. {
  56.     SetBkgndColor(TColor::LtGray);
  57.  
  58.     anim = dat;
  59.     nowstatus = STAT_INIT;
  60.     Attr.X = x;
  61.     Attr.Y = y;
  62.     Attr.W = w;
  63.     Attr.H = h;
  64. }
  65.  
  66.  
  67. TWinStatus::~TWinStatus ()
  68. {
  69.     Destroy();
  70.  
  71.     // INSERT>> デストラクタ用のコードはここに
  72.  
  73. }
  74.  
  75. void TWinStatus::VectorOutInt(TDC& dc, int x, int y, Vector &v)
  76. {
  77.     char str[16];
  78.     sprintf(str, "%5.0lf     ", v.x);     dc.TextOut(x, y       , str);
  79.     sprintf(str, "%5.0lf     ", v.y);     dc.TextOut(x, y + hs  , str);
  80.     sprintf(str, "%5.0lf     ", v.z);     dc.TextOut(x, y + hs*2, str);
  81. }
  82.  
  83. void TWinStatus::VectorOutFloat(TDC& dc, int x, int y, Vector &v)
  84. {
  85.     char str[16];
  86.     sprintf(str, "%5.2lf     ", v.x);     dc.TextOut(x, y       , str);
  87.     sprintf(str, "%5.2lf     ", v.y);     dc.TextOut(x, y + hs  , str);
  88.     sprintf(str, "%5.2lf     ", v.z);     dc.TextOut(x, y + hs*2, str);
  89. }
  90.  
  91. void TWinStatus::DisplayPosition(Vector& v)
  92. {
  93.     TClientDC dc(*this);
  94.     dc.SetBkColor(TColor(cTextBG));
  95.     VectorOutInt(dc, textwidth*3, hs* 2+ss*3, v);
  96.  
  97. }
  98.  
  99. void TWinStatus::DisplayTarget(Vector& v)
  100. {
  101.     TClientDC dc(*this);
  102.     dc.SetBkColor(TColor(cTextBG));
  103.     VectorOutInt(dc, textwidth*3, hs* 6+ss*4, v);
  104. }
  105.  
  106. void TWinStatus::DisplayRotation(Vector& v)
  107. {
  108.     TClientDC dc(*this);
  109.     dc.SetBkColor(TColor(cTextBG));
  110.     VectorOutInt(dc, textwidth*3, hs* 6+ss*4, rad(1) * v);
  111. }
  112.  
  113. void TWinStatus::DisplayRotationYZ(Vector& v)
  114. {
  115.     TClientDC dc(*this);
  116.     dc.SetBkColor(TColor(cTextBG));
  117.     char str[16];
  118.     sprintf(str, "%5.0lf     ", rad(v.y));     dc.TextOut(textwidth*3, hs*8+ss*4, str);
  119.     sprintf(str, "%5.0lf     ", rad(v.z));     dc.TextOut(textwidth*3, hs*9+ss*4, str);
  120. }
  121.  
  122. void TWinStatus::DisplayScale(Vector& v)
  123. {
  124.     TClientDC dc(*this);
  125.     dc.SetBkColor(TColor(cTextBG));
  126.     VectorOutFloat(dc, textwidth*3, hs*10+ss*5, v);
  127. }
  128.  
  129. void TWinStatus::Redraw(void)
  130. {
  131.     if (UpdateStatus() == FALSE) {
  132.         DisplayStatus(TRUE);
  133.     }
  134. }
  135.  
  136. void TWinStatus::DisplayStatusObject(TDC& dc, int flag, Motion *m)
  137. {
  138.     if (flag == TRUE) {
  139.         dc.Rectangle(dc.GetClipBox());
  140.         dc.TextOut(ws, hs* 1+ss*3, "位置");
  141.         dc.TextOut(ws, hs* 2+ss*3, "X:");
  142.         dc.TextOut(ws, hs* 3+ss*3, "Y:");
  143.         dc.TextOut(ws, hs* 4+ss*3, "Z:");
  144.         dc.TextOut(ws, hs* 5+ss*4, "回転");
  145.         dc.TextOut(ws, hs* 6+ss*4, "X:");
  146.         dc.TextOut(ws, hs* 7+ss*4, "Y:");
  147.         dc.TextOut(ws, hs* 8+ss*4, "Z:");
  148.         dc.TextOut(ws, hs* 9+ss*5, "拡大");
  149.         dc.TextOut(ws, hs*10+ss*5, "X:");
  150.         dc.TextOut(ws, hs*11+ss*5, "Y:");
  151.         dc.TextOut(ws, hs*12+ss*5, "Z:");
  152.     }
  153.     char str[120];
  154.  
  155.     m->GetName(str);
  156.     sprintf(str + strlen(str), " (%d-%d)     ", m->beginframe, m->endframe);
  157.     dc.TextOut(ws,  ss, str);
  158.     if (m->beginframe <= anim->selectframe && anim->selectframe <= m->endframe) {
  159.         VectorOutInt  (dc, textwidth*3, hs* 2+ss*3, m->position);
  160.         VectorOutInt  (dc, textwidth*3, hs* 6+ss*4, rad(1) * m->rotation);
  161.         VectorOutFloat(dc, textwidth*3, hs*10+ss*5, m->scale);
  162.     } else {
  163.         dc.Rectangle  (    textwidth*3, hs* 2+ss*3, textwidth*15, hs* 5+ss*3);
  164.         dc.Rectangle  (    textwidth*3, hs* 6+ss*4, textwidth*15, hs* 9+ss*4);
  165.         dc.Rectangle  (    textwidth*3, hs*10+ss*5, textwidth*15, hs*13+ss*5);
  166.     }
  167. }
  168.  
  169. void TWinStatus::DisplayStatusCamera(TDC& dc, int flag, CameraMotion *m)
  170. {
  171.     if (flag == TRUE) {
  172.         dc.Rectangle(dc.GetClipBox());
  173.         dc.TextOut(ws,       ss  , "カメラ");
  174.         dc.TextOut(ws, hs *1+ss*3, "カメラ位置");
  175.         dc.TextOut(ws, hs *2+ss*3, "X:");
  176.         dc.TextOut(ws, hs *3+ss*3, "Y:");
  177.         dc.TextOut(ws, hs *4+ss*3, "Z:");
  178.         dc.TextOut(ws, hs *5+ss*4, "ターゲット位置");
  179.         dc.TextOut(ws, hs *6+ss*4, "X:");
  180.         dc.TextOut(ws, hs *7+ss*4, "Y:");
  181.         dc.TextOut(ws, hs *8+ss*4, "Z:");
  182.     }
  183.     if (m->beginframe <= anim->selectframe && anim->selectframe <= m->endframe) {
  184.         VectorOutInt(dc, textwidth*3, hs* 2+ss*3, m->position);
  185.         VectorOutInt(dc, textwidth*3, hs* 6+ss*4, m->target->position);
  186.     }
  187. }
  188.  
  189. void TWinStatus::DisplayStatusTarget(TDC& dc, int flag, CameraMotion *m)
  190. {
  191.     if (flag == TRUE) {
  192.         dc.Rectangle(dc.GetClipBox());
  193.         dc.TextOut(ws,       ss  , "ターゲット");
  194.         dc.TextOut(ws, hs *1+ss*3, "カメラ位置");
  195.         dc.TextOut(ws, hs *2+ss*3, "X:");
  196.         dc.TextOut(ws, hs *3+ss*3, "Y:");
  197.         dc.TextOut(ws, hs *4+ss*3, "Z:");
  198.         dc.TextOut(ws, hs *5+ss*4, "ターゲット位置");
  199.         dc.TextOut(ws, hs *6+ss*4, "X:");
  200.         dc.TextOut(ws, hs *7+ss*4, "Y:");
  201.         dc.TextOut(ws, hs *8+ss*4, "Z:");
  202.     }
  203.     if (m->beginframe <= anim->selectframe && anim->selectframe <= m->endframe) {
  204.         VectorOutInt(dc, textwidth*3, hs* 2+ss*3, m->position);
  205.         VectorOutInt(dc, textwidth*3, hs* 6+ss*4, m->target->position);
  206.     }
  207. }
  208.  
  209. void TWinStatus::DisplayStatusLight(TDC& dc, int flag)
  210. {
  211.     if (flag == TRUE) {
  212.         dc.Rectangle(dc.GetClipBox());
  213.         dc.TextOut(ws,       ss  , "光源方向設定");
  214.         dc.TextOut(ws, hs* 1+ss*3, "方向");
  215.         dc.TextOut(ws, hs* 2+ss*3, "X:");
  216.         dc.TextOut(ws, hs* 3+ss*3, "Y:");
  217.         dc.TextOut(ws, hs* 4+ss*3, "Z:");
  218.         Vector tmpvec = anim->org_point;
  219.         double l = tmpvec.length();
  220.         if (l > minimumdouble) {
  221.             tmpvec *= (100.0/l);
  222.         }
  223.         VectorOutInt(dc, textwidth*3, hs* 2+ss*3, tmpvec);
  224.     }
  225. }
  226.  
  227. void TWinStatus::DisplayStatus(int flag)
  228. {
  229.     char str[128];
  230.     TClientDC dc(*this);
  231.     dc.SelectObject(TPen(cTextBG));
  232.     dc.SelectObject(TBrush(cTextBG));
  233.     dc.SetBkColor(TColor(cTextBG));
  234.     switch (nowstatus) {
  235.     case STAT_NONE:
  236.         if (flag == TRUE) {
  237.             dc.Rectangle(dc.GetClipBox());
  238.         }
  239.         break;
  240.     case STAT_OBJ:
  241.         DisplayStatusObject(dc, flag, anim->select);
  242.         break;
  243.     case STAT_CAMERA:
  244.         DisplayStatusCamera(dc, flag, anim->camera);
  245.         break;
  246.     case STAT_TARGET:
  247.         DisplayStatusTarget(dc, flag, anim->camera);
  248.         break;
  249.     case STAT_LIGHT:
  250.         DisplayStatusLight(dc, flag);
  251.         break;
  252.     case STAT_SELZOOM:
  253.         break;
  254.     case STAT_PLAY:
  255.         if (anim->select == anim->camera) {
  256.             DisplayStatusCamera(dc, flag, anim->camera);
  257.         } else if (anim->select == anim->camera->target) {
  258.             DisplayStatusTarget(dc, flag, anim->camera);
  259.         } else if (anim->select != NULL) {
  260.             DisplayStatusObject(dc, flag, anim->select);
  261.         }
  262.         break;
  263.     }
  264.  
  265. #if 0
  266.     if (flag == TRUE) {
  267.         dc.TextOut(ws,       ss  , "時刻:");
  268.     }
  269.     sprintf(str, "%3d     ", anim->selectframe);
  270.     dc.TextOut(textwidth*4, ss, str);
  271. #endif
  272.     sprintf(str, "時刻: %d", anim->selectframe);
  273.     anim->statusbar_time->SetText(str);
  274.  
  275. }
  276.  
  277. void TWinStatus::DisplayStatusTemp(Motion *m)
  278. {
  279.     TClientDC dc(*this);
  280.     dc.SelectObject(TPen(cTextBG));
  281.     dc.SelectObject(TBrush(cTextBG));
  282.     dc.SetBkColor(TColor(cTextBG));
  283.     if (m == NULL) {
  284.         dc.SelectStockObject(WHITE_PEN);
  285.         dc.Rectangle(dc.GetClipBox());
  286.     } else if (m == anim->camera) {
  287.         DisplayStatusCamera(dc, TRUE, anim->camera);
  288.     } else if (m == anim->camera->target) {
  289.         DisplayStatusTarget(dc, TRUE, anim->camera);
  290.     } else {
  291.         DisplayStatusObject(dc, TRUE, m);
  292.     }
  293. }
  294.  
  295. int TWinStatus::UpdateStatus(void)
  296. {
  297.     StatusMode nstat;
  298.     switch (anim->opstat) {
  299.     case OpDefault:
  300.         if (anim->select == NULL) {
  301.             nstat = STAT_NONE;
  302.             anim->button_ok->Show(SW_HIDE);
  303.             if (anim->motion == NULL) {
  304.                 anim->statusbar->SetText("[物体]/[物体追加] で物体を追加してください");
  305.             } else {
  306.                 anim->statusbar->SetText("さらに物体を追加するか、赤マークをクリックして物体を選択してください");
  307.             }
  308.         } else {
  309.             anim->button_ok->Show(SW_SHOW);
  310.             if (anim->select == anim->camera) {
  311.                 nstat = STAT_CAMERA;
  312.                 if (anim->camera->motiondata == NULL) {
  313.                     anim->statusbar->SetText("赤マークを動かし、カメラ位置、ターゲット位置を変更してください");
  314.                 } else {
  315.                     anim->statusbar->SetText("赤マークを動かし、カメラ位置、移動方向を変更してください");
  316.                 }
  317.             } else if (anim->select == anim->camera->target) {
  318.                 nstat = STAT_TARGET;
  319.                 anim->statusbar->SetText("赤マークを動かし、ターゲット位置、移動方向を変更してください");
  320.             } else {
  321.                 nstat = STAT_OBJ;
  322.                 if (anim->gridflag) {
  323.                     anim->statusbar->SetText("赤:移動 緑:回転 水:拡大 CTRL:グリッド無効 SHIFT赤:平行移動 SHIFT水:相似拡大 右:確定");
  324.                 } else {
  325.                     anim->statusbar->SetText("赤:移動 緑:回転 水:拡大 CTRL:グリッド有効 SHIFT赤:平行移動 SHIFT水:相似拡大 右:確定");
  326.                 }
  327.             }
  328.         }
  329.         break;
  330.     case OpLight:
  331.         anim->statusbar->SetText("黄マークを動かし、光源の方向を設定してください  右クリック:確定");
  332.         anim->button_ok->Show(SW_SHOW);
  333.         nstat = STAT_LIGHT;
  334.         break;
  335.     case OpSelZoom:
  336.         anim->statusbar->SetText("ズームしたい位置をクリックしてください");
  337.         anim->button_ok->Show(SW_HIDE);
  338.         nstat = STAT_SELZOOM;
  339.         break;
  340.     case OpPlay:
  341.         anim->statusbar->SetText("再生を中止するときは左クリックしてください");
  342.         anim->button_ok->Show(SW_HIDE);
  343.         nstat = STAT_PLAY;
  344.         break;
  345.     }
  346.     if (nstat != nowstatus) {
  347.         nowstatus = nstat;
  348.         DisplayStatus(TRUE);
  349.         return TRUE;
  350.     }
  351.     return FALSE;
  352. }
  353.  
  354.  
  355. void TWinStatus::Paint (TDC& dc, BOOL erase, TRect& rect)
  356. {
  357.     TWindow::Paint(dc, erase, rect);
  358.  
  359.     // INSERT>> 追加のコードはここに
  360.  
  361.     Redraw();
  362. }
  363.  
  364.  
  365.  
  366. void TWinStatus::SetupWindow ()
  367. {
  368.     TWindow::SetupWindow();
  369.  
  370.     // INSERT>> 追加のコードはここに
  371.     TClientDC dc(*this);
  372.     TEXTMETRIC metric;
  373.     dc.GetTextMetrics(metric);
  374.     textheight = metric.tmHeight;
  375.     textwidth = metric.tmAveCharWidth;
  376. }
  377.  
  378.  
  379. void TWinStatus::EvLButtonDown (UINT modKeys, TPoint& point)
  380. {
  381.     TWindow::EvLButtonDown(modKeys, point);
  382.  
  383.     // INSERT>> 追加コードはここに
  384.  
  385.     if (anim->opstat == OpPlay) {
  386.         anim->OpModeDefault();
  387.     } else if (anim->select != NULL &&
  388.         (anim->select->motiondata == NULL
  389.       || anim->select->beginframe == anim->selectframe
  390.       || anim->select->endframe   == anim->selectframe)) {
  391.         TDDirectInput dialog(this, anim, 0);
  392.         if (dialog.Execute() == IDOK) {
  393.             if (anim->selectframe < anim->select->beginframe) {
  394.                 anim->SelectFrame(anim->select->beginframe);
  395.             } else if (anim->selectframe > anim->select->endframe) {
  396.                 anim->SelectFrame(anim->select->endframe);
  397.             }
  398.             if (anim->select->motiondata != NULL) {
  399.                 int pos = 0;
  400.                 Motion *m = anim->select;
  401.                 if (m->beginframe != anim->selectframe) {
  402.                     pos = 1;
  403.                 }
  404.                 if (anim->select == anim->camera || anim->select == anim->camera->target) {
  405.                     m = anim->camera;
  406.                     Motion *t = anim->camera->target;
  407.                     m->motiondata->bezier->MovePoint(pos*3, m->position);
  408.                     t->motiondata->bezier->MovePoint(pos*3, t->position);
  409.                 } else {
  410.                     m->motiondata->bezier->MovePoint(pos*3, m->position);
  411.                     m->motiondata->scale[pos] = m->scale;
  412.                     if (m->rotation != m->motiondata->rotation[pos]) {
  413.                         m->SetRotation(m->rotation, pos);
  414.                     } else {
  415.                         m->GetPosition(anim->selectframe);
  416.                     }
  417.                 }
  418.             }
  419.             if (anim->select == anim->camera || anim->select == anim->camera->target) {
  420.                 anim->camera->GetPosition(anim->selectframe);
  421.                 anim->CalcPoints(anim->camera);
  422.                 anim->CalcViewAll();
  423.             } else {
  424.                 anim->CalcPoints(anim->select);
  425.             }
  426.             anim->editflag++;
  427.             anim->Redraw();
  428.         }
  429.     } else if (anim->select != NULL && anim->select != anim->camera) {
  430.         TDRange dialog(GetApplication()->GetMainWindow(), anim, anim->select,
  431.                         "メカの移動速度・出現/消失時刻を設定します");
  432.         if (dialog.Execute() == IDOK) {
  433.             if (anim->selectframe < anim->select->beginframe) {
  434.                 anim->SelectFrame(anim->select->beginframe);
  435.             } else if (anim->selectframe > anim->select->endframe) {
  436.                 anim->SelectFrame(anim->select->endframe);
  437.             }
  438.             anim->editflag++;
  439.             anim->select->GetPosition(anim->selectframe);
  440.             anim->CalcPoints(anim->select);
  441.             anim->Redraw();
  442.         }
  443.     }
  444. }
  445.  
  446.