home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / WIREVIEW.LZH / VIEW.CPP < prev    next >
C/C++ Source or Header  |  1996-07-10  |  4KB  |  202 lines

  1. #include <owl\owlpch.h>
  2. #pragma hdrstop
  3.  
  4. #include <toolhelp.h>
  5. #include "view.h"
  6. #include "matrix.h"
  7. #include "anim.h"
  8. #include "syscolor.h"
  9. #include "motion.h"
  10. #include "mecha.h"
  11. #include "winframe.h"
  12. #include "log.h"
  13.  
  14. //
  15. // このアプリケーションで処理するすべてのメッセージ/コマンドの
  16. // 応答テーブルを作成する
  17. //
  18. DEFINE_RESPONSE_TABLE1(TWinView, TWindow)
  19. //{{TWinViewRSP_TBL_BEGIN}}
  20.     EV_WM_SIZE,
  21. //{{TWinViewRSP_TBL_END}}
  22. END_RESPONSE_TABLE;
  23.  
  24.  
  25. //{{TWinView Implementation}}
  26.  
  27.  
  28. TWinView::TWinView (TWindow* parent, AnimationData *a, int x, int y, int w, int h):
  29.     TWindow(parent, 0, 0)
  30. {
  31.     // INSERT>> コンストラクタ用のコードはここに
  32.     anim = a;
  33.     Attr.X = x;
  34.     Attr.Y = y;
  35.     Attr.W = w;
  36.     Attr.H = h;
  37. }
  38.  
  39.  
  40. TWinView::~TWinView ()
  41. {
  42.     Destroy();
  43.  
  44.     // INSERT>> デストラクタ用のコードはここに
  45.  
  46. }
  47.  
  48.  
  49. void TWinView::SetupWindow ()
  50. {
  51.     TWindow::SetupWindow();
  52.  
  53.     // INSERT>> 追加のコードはここに
  54.  
  55.     if (_argc > 1) {
  56.         anim->ReadFile(_argv[1]);
  57.     }
  58. }
  59.  
  60.  
  61. void TWinView::Paint (TDC& dc, BOOL erase, TRect& rect)
  62. {
  63.     TWindow::Paint(dc, erase, rect);
  64.  
  65.     // INSERT>> 追加のコードはここに
  66.     if (anim->wireframe != NULL) {
  67.         Redraw();
  68.     }
  69. }
  70.  
  71. void TWinView::Animation(void)
  72. {
  73.     if (anim->wireframe == NULL
  74.      || anim->opstat == OpPause
  75.      || anim->playmode == PmTimer) return;
  76.  
  77.     TClientDC dc(*this);
  78.  
  79.     TMemoryDC mdc(dc);
  80.     TBitmap bitmap(dc, Attr.W, Attr.H);
  81.     mdc.SelectObject(bitmap);
  82.     mdc.SelectObject(TBrush(cBackGround));
  83. //    mdc.SelectObject(TPen(cBackGround));
  84.     mdc.SelectObject(TPen(cWireNormal));
  85.  
  86. #ifdef __WIN32__
  87.     unsigned long last = GetTickCount(), now;
  88. #else
  89.     TIMERINFO info;
  90.     unsigned long last;
  91.     info.dwSize = sizeof(TIMERINFO);
  92.     TimerCount(&info);
  93.     last = info.dwmsThisVM;
  94. #endif
  95.  
  96. #define TICK 33
  97.  
  98.     volatile WireFrame **wireframe = (volatile WireFrame **)&anim->wireframe;
  99.     while (1) {
  100.         if (*wireframe == NULL) {
  101.             break;
  102.                                                     }
  103.         mdc.Rectangle(dc.GetClipBox());
  104.         if ((*wireframe)[anim->selectframe-BEGIN].line == NULL) {
  105.             anim->Frame->SetTimer(OpPlay, 100);
  106.             return;
  107.         }
  108.         LineSegment *l = anim->wireframe[anim->selectframe - BEGIN].line;
  109.         for (int i = anim->wireframe[anim->selectframe - BEGIN].lines; i > 0; --i) {
  110.             mdc.MoveTo(l->x1, l->y1);
  111.             mdc.LineTo(l->x2, l->y2);
  112.             l++;
  113.         }
  114.         dc.BitBlt(0,0,Attr.W, Attr.H, mdc, 0, 0, SRCCOPY);
  115.         if (anim->selectframe >= anim->maxframe) {
  116.             anim->SelectFrame(BEGIN);
  117.         } else {
  118.             anim->SelectFrame(anim->selectframe+1);
  119.         }
  120.         MSG msg;
  121.         do {
  122.             if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
  123.                 if (msg.message == WM_QUIT) {
  124.                     return;
  125.                 } else {
  126.                     GetMessage(&msg, NULL, 0, 0);
  127.                     TranslateMessage(&msg);
  128.                     DispatchMessage(&msg);
  129.                 }
  130.             }
  131.             if (anim->playmode== PmTimer) {
  132.                 anim->Frame->SetTimer(OpPause, 100);
  133.                 return;
  134.             }
  135.             if (anim->opstat != OpPlay) {
  136.                 return;
  137.             }
  138. #ifdef __WIN32__
  139.         } while (now = GetTickCount(), (last + TICK > now && last < now) );
  140.         last = now;
  141. #else
  142.         } while (TimerCount(&info), last + TICK >  info.dwmsThisVM);
  143.         last = info.dwmsThisVM;
  144. #endif
  145.         if (anim->opstat != OpPlay) {
  146.             return;
  147.         }
  148.     }
  149. }
  150.  
  151.  
  152. void TWinView::Redraw(void)
  153. {
  154.     if (anim->wireframe == NULL) {
  155.         TClientDC dc(*this);
  156.         dc.SelectObject(TBrush(cBackGround));
  157.         dc.Rectangle(dc.GetClipBox());
  158.         return;
  159.     }
  160.  
  161.     TClientDC dc(*this);
  162.  
  163.     TMemoryDC mdc(dc);
  164.     TBitmap bitmap(dc, Attr.W, Attr.H);
  165.     mdc.SelectObject(bitmap);
  166.     mdc.SelectObject(TPen(cBackGround));
  167.     mdc.SelectObject(TBrush(cBackGround));
  168.     mdc.Rectangle(dc.GetClipBox());
  169.  
  170.     mdc.SelectObject(TPen(cWireNormal));
  171.     if (anim->wireframe[anim->selectframe-BEGIN].line == NULL) {
  172.         char str[32];
  173.         sprintf(str, "%d/%d...", anim->selectframe, anim->maxframe);
  174.         dc.TextOut(0,0,str);
  175.         anim->BuildWireFrame(anim->selectframe);
  176.     }
  177.     LineSegment *l = anim->wireframe[anim->selectframe - BEGIN].line;
  178.     for (int i = anim->wireframe[anim->selectframe - BEGIN].lines; i > 0; --i) {
  179.         mdc.MoveTo(l->x1, l->y1);
  180.         mdc.LineTo(l->x2, l->y2);
  181.         l++;
  182.     }
  183.     dc.BitBlt(0,0,Attr.W, Attr.H, mdc, 0, 0, SRCCOPY);
  184. }
  185.  
  186.  
  187.  
  188.  
  189. void TWinView::EvSize (UINT sizeType, TSize& size)
  190. {
  191.  
  192.     // INSERT>> 追加コードはここに
  193.     if (sizeType != SIZE_MINIMIZED) {
  194.         anim->Resize(size.cx, size.cy, Attr.W, Attr.H);
  195.         Attr.W = size.cx;
  196.         Attr.H = size.cy;
  197.     }
  198.  
  199.     TWindow::EvSize(sizeType, size);
  200. }
  201.  
  202.