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 >
Wrap
C/C++ Source or Header
|
1996-06-06
|
12KB
|
446 lines
/* Project medit
Project Team DoGA
Copyright (c) 1995. All Rights Reserved.
サブシステム: medit.apx Application
ファイル: status.cpp
作成者: Taka2
概要
====
TWinStatus (TWindow) のインプリメンテーション用のソースファイル
*/
#include <owl\owlpch.h>
#pragma hdrstop
#include <owl\button.h>
#include <owl\statusba.h>
#include <owl\gadget.h>
#include <owl\textgadg.h>
#include "status.h"
#include "matrix.h"
#include "anim.h"
#include "motion.h"
#include "bezier.h"
#include "mecha.h"
#include "suflib.h"
#include "syscolor.h"
#include "dinput.h"
#include "drange.h"
#include "log.h"
#define ws (textwidth / 2)
#define hs (textheight-1)
#define ss 1 //(textheight / 4)
//
// このアプリケーションで処理するすべてのメッセージ/コマンドの
// 応答テーブルを作成する
//
DEFINE_RESPONSE_TABLE1(TWinStatus, TWindow)
//{{TWinStatusRSP_TBL_BEGIN}}
EV_WM_LBUTTONDOWN,
//{{TWinStatusRSP_TBL_END}}
END_RESPONSE_TABLE;
//{{TWinStatus Implementation}}
TWinStatus::TWinStatus (TWindow* parent, AnimationData *dat, int x, int y, int w, int h):
TWindow(parent, 0, 0)
{
SetBkgndColor(TColor::LtGray);
anim = dat;
nowstatus = STAT_INIT;
Attr.X = x;
Attr.Y = y;
Attr.W = w;
Attr.H = h;
}
TWinStatus::~TWinStatus ()
{
Destroy();
// INSERT>> デストラクタ用のコードはここに
}
void TWinStatus::VectorOutInt(TDC& dc, int x, int y, Vector &v)
{
char str[16];
sprintf(str, "%5.0lf ", v.x); dc.TextOut(x, y , str);
sprintf(str, "%5.0lf ", v.y); dc.TextOut(x, y + hs , str);
sprintf(str, "%5.0lf ", v.z); dc.TextOut(x, y + hs*2, str);
}
void TWinStatus::VectorOutFloat(TDC& dc, int x, int y, Vector &v)
{
char str[16];
sprintf(str, "%5.2lf ", v.x); dc.TextOut(x, y , str);
sprintf(str, "%5.2lf ", v.y); dc.TextOut(x, y + hs , str);
sprintf(str, "%5.2lf ", v.z); dc.TextOut(x, y + hs*2, str);
}
void TWinStatus::DisplayPosition(Vector& v)
{
TClientDC dc(*this);
dc.SetBkColor(TColor(cTextBG));
VectorOutInt(dc, textwidth*3, hs* 2+ss*3, v);
}
void TWinStatus::DisplayTarget(Vector& v)
{
TClientDC dc(*this);
dc.SetBkColor(TColor(cTextBG));
VectorOutInt(dc, textwidth*3, hs* 6+ss*4, v);
}
void TWinStatus::DisplayRotation(Vector& v)
{
TClientDC dc(*this);
dc.SetBkColor(TColor(cTextBG));
VectorOutInt(dc, textwidth*3, hs* 6+ss*4, rad(1) * v);
}
void TWinStatus::DisplayRotationYZ(Vector& v)
{
TClientDC dc(*this);
dc.SetBkColor(TColor(cTextBG));
char str[16];
sprintf(str, "%5.0lf ", rad(v.y)); dc.TextOut(textwidth*3, hs*8+ss*4, str);
sprintf(str, "%5.0lf ", rad(v.z)); dc.TextOut(textwidth*3, hs*9+ss*4, str);
}
void TWinStatus::DisplayScale(Vector& v)
{
TClientDC dc(*this);
dc.SetBkColor(TColor(cTextBG));
VectorOutFloat(dc, textwidth*3, hs*10+ss*5, v);
}
void TWinStatus::Redraw(void)
{
if (UpdateStatus() == FALSE) {
DisplayStatus(TRUE);
}
}
void TWinStatus::DisplayStatusObject(TDC& dc, int flag, Motion *m)
{
if (flag == TRUE) {
dc.Rectangle(dc.GetClipBox());
dc.TextOut(ws, hs* 1+ss*3, "位置");
dc.TextOut(ws, hs* 2+ss*3, "X:");
dc.TextOut(ws, hs* 3+ss*3, "Y:");
dc.TextOut(ws, hs* 4+ss*3, "Z:");
dc.TextOut(ws, hs* 5+ss*4, "回転");
dc.TextOut(ws, hs* 6+ss*4, "X:");
dc.TextOut(ws, hs* 7+ss*4, "Y:");
dc.TextOut(ws, hs* 8+ss*4, "Z:");
dc.TextOut(ws, hs* 9+ss*5, "拡大");
dc.TextOut(ws, hs*10+ss*5, "X:");
dc.TextOut(ws, hs*11+ss*5, "Y:");
dc.TextOut(ws, hs*12+ss*5, "Z:");
}
char str[120];
m->GetName(str);
sprintf(str + strlen(str), " (%d-%d) ", m->beginframe, m->endframe);
dc.TextOut(ws, ss, str);
if (m->beginframe <= anim->selectframe && anim->selectframe <= m->endframe) {
VectorOutInt (dc, textwidth*3, hs* 2+ss*3, m->position);
VectorOutInt (dc, textwidth*3, hs* 6+ss*4, rad(1) * m->rotation);
VectorOutFloat(dc, textwidth*3, hs*10+ss*5, m->scale);
} else {
dc.Rectangle ( textwidth*3, hs* 2+ss*3, textwidth*15, hs* 5+ss*3);
dc.Rectangle ( textwidth*3, hs* 6+ss*4, textwidth*15, hs* 9+ss*4);
dc.Rectangle ( textwidth*3, hs*10+ss*5, textwidth*15, hs*13+ss*5);
}
}
void TWinStatus::DisplayStatusCamera(TDC& dc, int flag, CameraMotion *m)
{
if (flag == TRUE) {
dc.Rectangle(dc.GetClipBox());
dc.TextOut(ws, ss , "カメラ");
dc.TextOut(ws, hs *1+ss*3, "カメラ位置");
dc.TextOut(ws, hs *2+ss*3, "X:");
dc.TextOut(ws, hs *3+ss*3, "Y:");
dc.TextOut(ws, hs *4+ss*3, "Z:");
dc.TextOut(ws, hs *5+ss*4, "ターゲット位置");
dc.TextOut(ws, hs *6+ss*4, "X:");
dc.TextOut(ws, hs *7+ss*4, "Y:");
dc.TextOut(ws, hs *8+ss*4, "Z:");
}
if (m->beginframe <= anim->selectframe && anim->selectframe <= m->endframe) {
VectorOutInt(dc, textwidth*3, hs* 2+ss*3, m->position);
VectorOutInt(dc, textwidth*3, hs* 6+ss*4, m->target->position);
}
}
void TWinStatus::DisplayStatusTarget(TDC& dc, int flag, CameraMotion *m)
{
if (flag == TRUE) {
dc.Rectangle(dc.GetClipBox());
dc.TextOut(ws, ss , "ターゲット");
dc.TextOut(ws, hs *1+ss*3, "カメラ位置");
dc.TextOut(ws, hs *2+ss*3, "X:");
dc.TextOut(ws, hs *3+ss*3, "Y:");
dc.TextOut(ws, hs *4+ss*3, "Z:");
dc.TextOut(ws, hs *5+ss*4, "ターゲット位置");
dc.TextOut(ws, hs *6+ss*4, "X:");
dc.TextOut(ws, hs *7+ss*4, "Y:");
dc.TextOut(ws, hs *8+ss*4, "Z:");
}
if (m->beginframe <= anim->selectframe && anim->selectframe <= m->endframe) {
VectorOutInt(dc, textwidth*3, hs* 2+ss*3, m->position);
VectorOutInt(dc, textwidth*3, hs* 6+ss*4, m->target->position);
}
}
void TWinStatus::DisplayStatusLight(TDC& dc, int flag)
{
if (flag == TRUE) {
dc.Rectangle(dc.GetClipBox());
dc.TextOut(ws, ss , "光源方向設定");
dc.TextOut(ws, hs* 1+ss*3, "方向");
dc.TextOut(ws, hs* 2+ss*3, "X:");
dc.TextOut(ws, hs* 3+ss*3, "Y:");
dc.TextOut(ws, hs* 4+ss*3, "Z:");
Vector tmpvec = anim->org_point;
double l = tmpvec.length();
if (l > minimumdouble) {
tmpvec *= (100.0/l);
}
VectorOutInt(dc, textwidth*3, hs* 2+ss*3, tmpvec);
}
}
void TWinStatus::DisplayStatus(int flag)
{
char str[128];
TClientDC dc(*this);
dc.SelectObject(TPen(cTextBG));
dc.SelectObject(TBrush(cTextBG));
dc.SetBkColor(TColor(cTextBG));
switch (nowstatus) {
case STAT_NONE:
if (flag == TRUE) {
dc.Rectangle(dc.GetClipBox());
}
break;
case STAT_OBJ:
DisplayStatusObject(dc, flag, anim->select);
break;
case STAT_CAMERA:
DisplayStatusCamera(dc, flag, anim->camera);
break;
case STAT_TARGET:
DisplayStatusTarget(dc, flag, anim->camera);
break;
case STAT_LIGHT:
DisplayStatusLight(dc, flag);
break;
case STAT_SELZOOM:
break;
case STAT_PLAY:
if (anim->select == anim->camera) {
DisplayStatusCamera(dc, flag, anim->camera);
} else if (anim->select == anim->camera->target) {
DisplayStatusTarget(dc, flag, anim->camera);
} else if (anim->select != NULL) {
DisplayStatusObject(dc, flag, anim->select);
}
break;
}
#if 0
if (flag == TRUE) {
dc.TextOut(ws, ss , "時刻:");
}
sprintf(str, "%3d ", anim->selectframe);
dc.TextOut(textwidth*4, ss, str);
#endif
sprintf(str, "時刻: %d", anim->selectframe);
anim->statusbar_time->SetText(str);
}
void TWinStatus::DisplayStatusTemp(Motion *m)
{
TClientDC dc(*this);
dc.SelectObject(TPen(cTextBG));
dc.SelectObject(TBrush(cTextBG));
dc.SetBkColor(TColor(cTextBG));
if (m == NULL) {
dc.SelectStockObject(WHITE_PEN);
dc.Rectangle(dc.GetClipBox());
} else if (m == anim->camera) {
DisplayStatusCamera(dc, TRUE, anim->camera);
} else if (m == anim->camera->target) {
DisplayStatusTarget(dc, TRUE, anim->camera);
} else {
DisplayStatusObject(dc, TRUE, m);
}
}
int TWinStatus::UpdateStatus(void)
{
StatusMode nstat;
switch (anim->opstat) {
case OpDefault:
if (anim->select == NULL) {
nstat = STAT_NONE;
anim->button_ok->Show(SW_HIDE);
if (anim->motion == NULL) {
anim->statusbar->SetText("[物体]/[物体追加] で物体を追加してください");
} else {
anim->statusbar->SetText("さらに物体を追加するか、赤マークをクリックして物体を選択してください");
}
} else {
anim->button_ok->Show(SW_SHOW);
if (anim->select == anim->camera) {
nstat = STAT_CAMERA;
if (anim->camera->motiondata == NULL) {
anim->statusbar->SetText("赤マークを動かし、カメラ位置、ターゲット位置を変更してください");
} else {
anim->statusbar->SetText("赤マークを動かし、カメラ位置、移動方向を変更してください");
}
} else if (anim->select == anim->camera->target) {
nstat = STAT_TARGET;
anim->statusbar->SetText("赤マークを動かし、ターゲット位置、移動方向を変更してください");
} else {
nstat = STAT_OBJ;
if (anim->gridflag) {
anim->statusbar->SetText("赤:移動 緑:回転 水:拡大 CTRL:グリッド無効 SHIFT赤:平行移動 SHIFT水:相似拡大 右:確定");
} else {
anim->statusbar->SetText("赤:移動 緑:回転 水:拡大 CTRL:グリッド有効 SHIFT赤:平行移動 SHIFT水:相似拡大 右:確定");
}
}
}
break;
case OpLight:
anim->statusbar->SetText("黄マークを動かし、光源の方向を設定してください 右クリック:確定");
anim->button_ok->Show(SW_SHOW);
nstat = STAT_LIGHT;
break;
case OpSelZoom:
anim->statusbar->SetText("ズームしたい位置をクリックしてください");
anim->button_ok->Show(SW_HIDE);
nstat = STAT_SELZOOM;
break;
case OpPlay:
anim->statusbar->SetText("再生を中止するときは左クリックしてください");
anim->button_ok->Show(SW_HIDE);
nstat = STAT_PLAY;
break;
}
if (nstat != nowstatus) {
nowstatus = nstat;
DisplayStatus(TRUE);
return TRUE;
}
return FALSE;
}
void TWinStatus::Paint (TDC& dc, BOOL erase, TRect& rect)
{
TWindow::Paint(dc, erase, rect);
// INSERT>> 追加のコードはここに
Redraw();
}
void TWinStatus::SetupWindow ()
{
TWindow::SetupWindow();
// INSERT>> 追加のコードはここに
TClientDC dc(*this);
TEXTMETRIC metric;
dc.GetTextMetrics(metric);
textheight = metric.tmHeight;
textwidth = metric.tmAveCharWidth;
}
void TWinStatus::EvLButtonDown (UINT modKeys, TPoint& point)
{
TWindow::EvLButtonDown(modKeys, point);
// INSERT>> 追加コードはここに
if (anim->opstat == OpPlay) {
anim->OpModeDefault();
} else if (anim->select != NULL &&
(anim->select->motiondata == NULL
|| anim->select->beginframe == anim->selectframe
|| anim->select->endframe == anim->selectframe)) {
TDDirectInput dialog(this, anim, 0);
if (dialog.Execute() == IDOK) {
if (anim->selectframe < anim->select->beginframe) {
anim->SelectFrame(anim->select->beginframe);
} else if (anim->selectframe > anim->select->endframe) {
anim->SelectFrame(anim->select->endframe);
}
if (anim->select->motiondata != NULL) {
int pos = 0;
Motion *m = anim->select;
if (m->beginframe != anim->selectframe) {
pos = 1;
}
if (anim->select == anim->camera || anim->select == anim->camera->target) {
m = anim->camera;
Motion *t = anim->camera->target;
m->motiondata->bezier->MovePoint(pos*3, m->position);
t->motiondata->bezier->MovePoint(pos*3, t->position);
} else {
m->motiondata->bezier->MovePoint(pos*3, m->position);
m->motiondata->scale[pos] = m->scale;
if (m->rotation != m->motiondata->rotation[pos]) {
m->SetRotation(m->rotation, pos);
} else {
m->GetPosition(anim->selectframe);
}
}
}
if (anim->select == anim->camera || anim->select == anim->camera->target) {
anim->camera->GetPosition(anim->selectframe);
anim->CalcPoints(anim->camera);
anim->CalcViewAll();
} else {
anim->CalcPoints(anim->select);
}
anim->editflag++;
anim->Redraw();
}
} else if (anim->select != NULL && anim->select != anim->camera) {
TDRange dialog(GetApplication()->GetMainWindow(), anim, anim->select,
"メカの移動速度・出現/消失時刻を設定します");
if (dialog.Execute() == IDOK) {
if (anim->selectframe < anim->select->beginframe) {
anim->SelectFrame(anim->select->beginframe);
} else if (anim->selectframe > anim->select->endframe) {
anim->SelectFrame(anim->select->endframe);
}
anim->editflag++;
anim->select->GetPosition(anim->selectframe);
anim->CalcPoints(anim->select);
anim->Redraw();
}
}
}