home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
PASM.LZH
/
WINFRAME.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-10
|
20KB
|
638 lines
/* Project partsasm
Project Team DoGA
Copyright (c) 1995. All Rights Reserved.
サブシステム: partsasm.apx Application
ファイル: winframe.cpp
作成者: Taka2
概要
====
TWinFrame (TWindow) のインプリメンテーション用のソースファイル
*/
#include <owl\owlpch.h>
#pragma hdrstop
#include <owl\opensave.h>
#include <owl\scrollba.h>
#include <owl\button.h>
#include "winframe.h"
#include "matrix.h"
#include "design.h"
#include "display.h"
#include "pers.h"
#include "status.h"
#include "parts.h"
#include "bmpbtn.h"
#include "syscolor.h"
#include "bmpopen.h"
#include "log.h"
//
// このアプリケーションで処理するすべてのメッセージ/コマンドの
// 応答テーブルを作成する
//
DEFINE_RESPONSE_TABLE1(TWinFrame, TWindow)
//{{TWinFrameRSP_TBL_BEGIN}}
EV_WM_KEYDOWN,
EV_CHILD_NOTIFY_ALL_CODES(ID_SCROLL_X, EvScrollX),
EV_CHILD_NOTIFY_ALL_CODES(ID_SCROLL_Y, EvScrollY),
EV_CHILD_NOTIFY_ALL_CODES(ID_SCROLL_Z, EvScrollZ),
EV_WM_PALETTECHANGED,
EV_WM_SIZE,
EV_BN_CLICKED(BUTTON_ZOOM, EvButtonZoom),
EV_BN_CLICKED(BUTTON_OK, EvButtonOk),
EV_BN_CLICKED(BUTTON_CANCEL, EvButtonCancel),
EV_WM_TIMER,
//{{TWinFrameRSP_TBL_END}}
END_RESPONSE_TABLE;
//{{TWinFrame Implementation}}
const int barwidth_org = 16;
//const int scrollunit = 50;
//const int scrolllimit = 20;
const int buttonsize_org = 24;
const double camerarot = 20.0;
const double targetrot = 5.0;
const double cameramove = 300;
TWinFrame::TWinFrame (TWindow* parent, const char far* title, TModule* module):
TWindow(parent, title, module)
{
// INSERT>> コンストラクタ用のコードはここに
SetBkgndColor(TColor::LtGray);
int screenX = GetSystemMetrics(SM_CXSCREEN);
int screenY = GetSystemMetrics(SM_CYSCREEN);
int barwidth = barwidth_org;
int buttonsize = buttonsize_org;
if (Attr.W < 700 || Attr.H < 500) {
barwidth = 12;
buttonsize = 16;
}
int widthX, widthY, widthZ, viewW, viewH;
if (screenX <= 800) {
Attr.W = screenX - 20;
Attr.H = screenY - 60;
Attr.X = 10;
Attr.Y = 10;
} else {
Attr.W = 800;
Attr.H = 600;
}
widthY = (Attr.H - barwidth) / 2;
widthZ = Attr.H - barwidth - widthY;
viewH = widthY + barwidth-1;
// viewH = widthY;
viewW = viewH * 4 / 3;
widthX = Attr.W - barwidth - viewW - buttonsize;
// TScrollBar *bar;
designdata = new DesignData();
designdata->Frame = this;
designdata->TopView = new TWinDisplay(this, designdata, SelXY, 0, 0, widthX, widthY);
designdata->SideView = new TWinDisplay(this, designdata, SelZX, 0, widthY + barwidth, widthX, widthZ);
designdata->FrontView = new TWinDisplay(this, designdata, SelYZ, widthX + barwidth, widthY + barwidth, widthY, widthZ);
designdata->PersView = new TWinPers(this, designdata, widthX+barwidth, 0, viewW, viewH);
designdata->Status = new TWinStatus(this, designdata, widthX + barwidth + widthY+1, widthY + barwidth, Attr.W - widthX - barwidth - widthY, widthZ);
designdata->scrollX = new TScrollBar(this, ID_SCROLL_X, 0, widthY , widthX, barwidth, TRUE);
designdata->scrollY = new TScrollBar(this, ID_SCROLL_Y, widthX, 0, barwidth, widthY, FALSE);
designdata->scrollZ = new TScrollBar(this, ID_SCROLL_Z, widthX, widthY+barwidth, barwidth, widthZ, FALSE);
int i = 0;
designdata->button[i++] = new TBitmapButton(this, designdata, BITMAP_BUTTON_LP, Attr.W-buttonsize-1, buttonsize*0, buttonsize, buttonsize);
designdata->button[i++] = new TBitmapButton(this, designdata, BITMAP_BUTTON_RP, Attr.W-buttonsize-1, buttonsize*1, buttonsize, buttonsize);
designdata->button[i++] = new TBitmapButton(this, designdata, BITMAP_BUTTON_UP, Attr.W-buttonsize-1, buttonsize*2, buttonsize, buttonsize);
designdata->button[i++] = new TBitmapButton(this, designdata, BITMAP_BUTTON_DP, Attr.W-buttonsize-1, buttonsize*3, buttonsize, buttonsize);
designdata->button[i++] = new TBitmapButton(this, designdata, BITMAP_BUTTON_LR, Attr.W-buttonsize-1, buttonsize*4, buttonsize, buttonsize);
designdata->button[i++] = new TBitmapButton(this, designdata, BITMAP_BUTTON_RR, Attr.W-buttonsize-1, buttonsize*5, buttonsize, buttonsize);
designdata->button[i++] = new TBitmapButton(this, designdata, BITMAP_BUTTON_UR, Attr.W-buttonsize-1, buttonsize*6, buttonsize, buttonsize);
designdata->button[i++] = new TBitmapButton(this, designdata, BITMAP_BUTTON_DR, Attr.W-buttonsize-1, buttonsize*7, buttonsize, buttonsize);
designdata->button[i++] = new TBitmapButton(this, designdata, BITMAP_BUTTON_FD, Attr.W-buttonsize-1, buttonsize*8, buttonsize, buttonsize);
designdata->button[i++] = new TBitmapButton(this, designdata, BITMAP_BUTTON_BD, Attr.W-buttonsize-1, buttonsize*9, buttonsize, buttonsize);
designdata->button_ok = new TButton(this, BUTTON_OK, "確定",0,0,0,0);
designdata->button_cancel = new TButton(this, BUTTON_CANCEL, "キャンセル",0,0,0,0);
designdata->button_zoom = new TButton(this, BUTTON_ZOOM, "解除",0,0,0,0);
designdata->CalcPoints(designdata->camera);
}
TWinFrame::~TWinFrame ()
{
Destroy();
// INSERT>> デストラクタ用のコードはここに
}
void TWinFrame::EvScrollX(UINT code)
{
if (code != SB_ENDSCROLL
&& designdata->displayoffset.x != -designdata->scrollX->GetPosition() * designdata->displayscale * scrollstep) {
designdata->displayoffset.x = -designdata->scrollX->GetPosition() * designdata->displayscale * scrollstep;
designdata->Redraw(SelYZ, TRUE);
}
::SetFocus(designdata->Status->HWindow);
}
void TWinFrame::EvScrollY(UINT code)
{
if (code != SB_ENDSCROLL
&& designdata->displayoffset.y != designdata->scrollY->GetPosition() * designdata->displayscale * scrollstep) {
designdata->displayoffset.y = designdata->scrollY->GetPosition() * designdata->displayscale * scrollstep;
designdata->Redraw(SelZX, TRUE);
}
::SetFocus(designdata->Status->HWindow);
}
void TWinFrame::EvScrollZ(UINT code)
{
if (code != SB_ENDSCROLL
&& designdata->displayoffset.z != designdata->scrollZ->GetPosition() * designdata->displayscale * scrollstep) {
designdata->displayoffset.z = designdata->scrollZ->GetPosition() * designdata->displayscale * scrollstep;
designdata->Redraw(SelXY, TRUE);
}
::SetFocus(designdata->Status->HWindow);
}
void TWinFrame::Paint (TDC& dc, BOOL erase, TRect& rect)
{
TWindow::Paint(dc, erase, rect);
// INSERT>> 追加のコードはここに
dc.MoveTo(designdata->PersView->Attr.X,
designdata->PersView->Attr.H);
dc.LineTo(designdata->PersView->Attr.X,
designdata->SideView->Attr.Y - 1);
dc.LineTo(Attr.W,
designdata->SideView->Attr.Y - 1);
dc.MoveTo(designdata->FrontView->Attr.X + designdata->FrontView->Attr.W,
designdata->FrontView->Attr.Y);
dc.LineTo(designdata->FrontView->Attr.X + designdata->FrontView->Attr.W,
Attr.H);
int x = designdata->PersView->Attr.X + designdata->PersView->Attr.W;
int y = designdata->PersView->Attr.H;
dc.MoveTo(x, 0); dc.LineTo(x, y);
dc.SelectObject(TBrush(cTextBG));
dc.SelectObject(TPen(cTextBG));
dc.Rectangle(x, 0, Attr.W, designdata->PersView->Attr.H);
}
void TWinFrame::SetupWindow ()
{
TWindow::SetupWindow();
// INSERT>> 追加のコードはここに
designdata->SetScrollLimit();
// designdata->scrollX->SetRange(-scrolllimit, scrolllimit);
// designdata->scrollY->SetRange(-scrolllimit, scrolllimit);
// designdata->scrollZ->SetRange(-scrolllimit, scrolllimit);
designdata->scrollX->SetPosition(0);
designdata->scrollY->SetPosition(0);
designdata->scrollZ->SetPosition(0);
if (_argc > 1) {
designdata->FileRead(_argv[1]);
}
}
void TWinFrame::EvKeyDown (UINT key, UINT repeatCount, UINT flags)
{
TWindow::EvKeyDown(key, repeatCount, flags);
// INSERT>> 追加コードはここに
}
BOOL TWinFrame::CanClose ()
{
BOOL result;
result = TWindow::CanClose();
// INSERT>> 追加のコードはここに
if (designdata->editflag > 0) {
int response = MessageBox("デザインが変更されています。\n保存しますか?",
designdata->filename[0] ? designdata->filename : "無名",
MB_YESNOCANCEL|MB_ICONQUESTION);
if (response == IDCANCEL) {
return FALSE;
} else if (response == IDYES) {
if (designdata->filename[0] != '\0') {
designdata->FileWrite();
return TRUE;
} else {
#if 0
TOpenSaveDialog::TData FileData(
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"フレームファイル(*.fsc)|*.fsc|",
0, designdata->filedir, "FSC");
if (TFileSaveDialog(GetApplicationObject()->GetMainWindow(), FileData).Execute() == IDOK) {
return designdata->FileWrite(FileData.FileName);
}
#else
char fname[MAX_PATH];
if (FileSaveDialogWithBMP(
GetApplicationObject()->GetMainWindow(), fname,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"フレームファイル(*.fsc)|*.fsc|",
0, designdata->filedir, "FSC") == IDOK) {
return designdata->FileWrite(fname);
}
#endif
return FALSE;
}
}
}
return result;
}
void TWinFrame::EvPaletteChanged (HWND /*hWndPalChg*/)
{
// TWindow::EvPaletteChanged(hWndPalChg);
// INSERT>> 追加コードはここに
}
void TWinFrame::EvSize (UINT sizeType, TSize& size)
{
TWindow::EvSize(sizeType, size);
// INSERT>> 追加コードはここに
int barwidth = barwidth_org;
int buttonsize = buttonsize_org;
if (Attr.W < 700 || Attr.H < 500) {
barwidth = 12;
}
int widthX, widthY, widthZ, viewW, viewH;
widthY = (Attr.H - barwidth) / 2;
widthZ = Attr.H - barwidth - widthY;
viewH = widthY + barwidth-1;
int separater = 2;
if (viewH < buttonsize * 11 + separater * 3) {
buttonsize = (viewH - separater*3) / 11;
} else {
separater = (viewH - buttonsize * 11) / 3;
}
// viewH = widthY;
viewW = viewH * 4 / 3;
widthX = Attr.W - barwidth - viewW -buttonsize;//- (buttonsize*2+1);
viewW -= buttonsize;
// viewW -= buttonsize*2+1;
#if 0
for (int i = 0; i < buttons; ++i) {
designdata->button[i]->MoveWindow(Attr.W-buttonsize-1, i * buttonsize, buttonsize, buttonsize);
}
#endif
int x = Attr.W - buttonsize*2;
int y = 0;
designdata->button[2]->MoveWindow(x + buttonsize/2, y, buttonsize, buttonsize); y += buttonsize;
designdata->button[0]->MoveWindow(x , y, buttonsize, buttonsize);
designdata->button[1]->MoveWindow(x + buttonsize , y, buttonsize, buttonsize); y += buttonsize;
designdata->button[3]->MoveWindow(x + buttonsize/2, y, buttonsize, buttonsize); y += buttonsize+separater;
designdata->button[6]->MoveWindow(x + buttonsize/2, y, buttonsize, buttonsize); y += buttonsize;
designdata->button[4]->MoveWindow(x , y, buttonsize, buttonsize);
designdata->button[5]->MoveWindow(x + buttonsize , y, buttonsize, buttonsize); y += buttonsize;
designdata->button[7]->MoveWindow(x + buttonsize/2, y, buttonsize, buttonsize); y += buttonsize+separater;
designdata->button[8]->MoveWindow(x + buttonsize/2, y, buttonsize, buttonsize); y += buttonsize;
designdata->button[9]->MoveWindow(x + buttonsize/2, y, buttonsize, buttonsize); y += buttonsize+separater;
designdata->button_zoom->MoveWindow(x,y, buttonsize*2, buttonsize); y += buttonsize;
designdata->button_ok->MoveWindow(x,y, buttonsize*2, buttonsize); y += buttonsize;
designdata->button_cancel->MoveWindow(x,y, buttonsize*2, buttonsize);
designdata->scrollX->MoveWindow( 0, widthY , widthX, barwidth, TRUE);
designdata->scrollY->MoveWindow(widthX, 0, barwidth, widthY, FALSE);
designdata->scrollZ->MoveWindow(widthX, widthY+barwidth, barwidth, widthZ, FALSE);
#if 0
designdata->scrollX->PageMagnitude = widthX / scrollunit;
designdata->scrollX->LineMagnitude = (widthX/scrollunit+7) / 8;
designdata->scrollY->PageMagnitude = widthY / scrollunit;
designdata->scrollY->LineMagnitude = (widthY/scrollunit+7) / 8;
designdata->scrollZ->PageMagnitude = widthZ / scrollunit;
designdata->scrollZ->LineMagnitude = (widthZ/scrollunit+7) / 8;
#endif
designdata->TopView ->MoveWindow( 0, 0, widthX, widthY);
designdata->SideView ->MoveWindow( 0, widthY + barwidth, widthX, widthZ);
designdata->FrontView->MoveWindow(widthX + barwidth, widthY + barwidth, widthY, widthZ);
designdata->PersView ->MoveWindow(widthX+barwidth , 0, viewW, viewH);
designdata->SetScrollLimit();
designdata->Status->MoveWindow(widthX + barwidth + widthY+1, widthY + barwidth, Attr.W - widthX - barwidth - widthY, widthZ);
::SetFocus(designdata->Status->HWindow);
Invalidate();
designdata->CalcViewAll();
designdata->Redraw();
}
void TWinFrame::EvButtonLP(SelectType t)
{
double tr = targetrot;
if (GetKeyState(VK_CONTROL) & 0x8000U) {tr *= 0.1;}
CameraParts *p = designdata->camera;
Vector tmpvec = p->target - p->position;
double c = cos(deg(tr)), s = sin(deg(tr));
Vector nvec( tmpvec.x * c - tmpvec.y * s,
tmpvec.x * s + tmpvec.y * c,
tmpvec.z);
p->SetTarget(nvec + p->position);
designdata->CalcPoints(designdata->camera);
designdata->CalcViewAll();
// designdata->editflag++;
designdata->Redraw(t);
}
void TWinFrame::EvButtonRP(SelectType t)
{
double tr = targetrot;
if (GetKeyState(VK_CONTROL) & 0x8000U) {tr *= 0.1;}
CameraParts *p = designdata->camera;
Vector tmpvec = p->target - p->position;
double c = cos(deg(tr)), s = sin(deg(tr));
Vector nvec( tmpvec.x * c + tmpvec.y * s,
-tmpvec.x * s + tmpvec.y * c,
tmpvec.z);
p->SetTarget(nvec + p->position);
designdata->CalcPoints(designdata->camera);
designdata->CalcViewAll();
// designdata->editflag++;
designdata->Redraw(t);
}
void TWinFrame::EvButtonDP(SelectType t)
{
double tr = targetrot;
if (GetKeyState(VK_CONTROL) & 0x8000U) {tr *= 0.1;}
CameraParts *p = designdata->camera;
if (p->rotation.y >= deg(90.0 - tr)) {
return;
}
Vector tmpvec = p->target - p->position;
double len = tmpvec.length();
Matrix rot = Matrix(1).rotz(p->rotation.z).roty(p->rotation.y).rotx(p->rotation.x);
Vector nvec = (cos(deg(tr)) * len) * rot.v[0]
- (sin(deg(tr)) * len) * rot.v[2];
p->SetTarget(nvec + p->position);
designdata->CalcPoints(designdata->camera);
designdata->CalcViewAll();
// designdata->editflag++;
designdata->Redraw(t);
}
void TWinFrame::EvButtonUP(SelectType t)
{
double tr = targetrot;
if (GetKeyState(VK_CONTROL) & 0x8000U) {tr *= 0.1;}
CameraParts *p = designdata->camera;
if (p->rotation.y < -deg(90.0 - tr)) {
return;
}
Vector tmpvec = p->target - p->position;
double len = tmpvec.length();
Matrix rot = Matrix(1).rotz(p->rotation.z).roty(p->rotation.y).rotx(p->rotation.x);
Vector nvec = (cos(deg(tr)) * len) * rot.v[0]
+ (sin(deg(tr)) * len) * rot.v[2];
p->SetTarget(nvec + p->position);
designdata->CalcPoints(designdata->camera);
designdata->CalcViewAll();
// designdata->editflag++;
designdata->Redraw(t);
}
void TWinFrame::EvButtonLR(SelectType t)
{
double cr = camerarot;
if (GetKeyState(VK_CONTROL) & 0x8000U) {cr *= 0.1;}
CameraParts *p = designdata->camera;
Vector tmpvec = p->position - p->target;
double c = cos(deg(cr)), s = sin(deg(cr));
Vector nvec( tmpvec.x * c + tmpvec.y * s,
-tmpvec.x * s + tmpvec.y * c,
tmpvec.z);
p->position = nvec + p->target;
p->SetTarget(p->target);
designdata->CalcPoints(designdata->camera);
designdata->CalcViewAll();
// designdata->editflag++;
designdata->Redraw(t);
}
void TWinFrame::EvButtonRR(SelectType t)
{
double cr = camerarot;
if (GetKeyState(VK_CONTROL) & 0x8000U) {cr *= 0.1;}
CameraParts *p = designdata->camera;
Vector tmpvec = p->position - p->target;
double c = cos(deg(cr)), s = sin(deg(cr));
Vector nvec( tmpvec.x * c - tmpvec.y * s,
tmpvec.x * s + tmpvec.y * c,
tmpvec.z);
p->position = nvec + p->target;
p->SetTarget(p->target);
designdata->CalcPoints(designdata->camera);
designdata->CalcViewAll();
// designdata->editflag++;
designdata->Redraw(t);
}
void TWinFrame::EvButtonDR(SelectType t)
{
double cr = camerarot;
if (GetKeyState(VK_CONTROL) & 0x8000U) {cr *= 0.1;}
CameraParts *p = designdata->camera;
if (p->rotation.y < -deg(90.0 - cr)) {
return;
}
Vector tmpvec = p->position - p->target;
double len = tmpvec.length();
Matrix rot = Matrix(1).rotz(p->rotation.z).roty(p->rotation.y).rotx(p->rotation.x);
Vector nvec = - (cos(deg(cr)) * len) * rot.v[0]
- (sin(deg(cr)) * len) * rot.v[2];
p->position = nvec + p->target;
p->SetTarget(p->target);
designdata->CalcPoints(designdata->camera);
designdata->CalcViewAll();
// designdata->editflag++;
designdata->Redraw(t);
}
void TWinFrame::EvButtonUR(SelectType t)
{
double cr = camerarot;
if (GetKeyState(VK_CONTROL) & 0x8000U) {cr *= 0.1;}
CameraParts *p = designdata->camera;
if (p->rotation.y >= deg(90.0 - cr)) {
return;
}
Vector tmpvec = p->position - p->target;
double len = tmpvec.length();
Matrix rot = Matrix(1).rotz(p->rotation.z).roty(p->rotation.y).rotx(p->rotation.x);
Vector nvec = - (cos(deg(cr)) * len) * rot.v[0]
+ (sin(deg(cr)) * len) * rot.v[2];
p->position = nvec + p->target;
p->SetTarget(p->target);
designdata->CalcPoints(designdata->camera);
designdata->CalcViewAll();
// designdata->editflag++;
designdata->Redraw(t);
}
void TWinFrame::EvButtonBD(SelectType t)
{
double cm = cameramove;
if (GetKeyState(VK_CONTROL) & 0x8000U) {cm *= 0.1;}
CameraParts *p = designdata->camera;
Vector tmpvec = p->position - p->target;
double len = tmpvec.length();
if (len < minimumdouble) {
return;
}
p->position = ((len + cm)/len) * tmpvec + p->target;
p->SetTarget(p->target);
designdata->CalcPoints(designdata->camera);
designdata->CalcViewAll();
// designdata->editflag++;
designdata->Redraw(t);
}
void TWinFrame::EvButtonFD(SelectType t)
{
double cm = cameramove;
if (GetKeyState(VK_CONTROL) & 0x8000U) {cm *= 0.1;}
CameraParts *p = designdata->camera;
Vector tmpvec = p->position - p->target;
double len = tmpvec.length();
if (len <= cm) {
return;
}
p->position = ((len - cm)/len) * tmpvec + p->target;
p->SetTarget(p->target);
designdata->CalcPoints(designdata->camera);
designdata->CalcViewAll();
// designdata->editflag++;
designdata->Redraw(t);
}
void TWinFrame::EvButton(UINT id, SelectType t)
{
if (designdata->hiddenremove) {
KillTimer(0);
SetTimer(0, 600);
}
int h = designdata->hiddenremove;
designdata->hiddenremove = FALSE;
switch (id) {
case BITMAP_BUTTON_LP: EvButtonLP(t); break;
case BITMAP_BUTTON_RP: EvButtonRP(t); break;
case BITMAP_BUTTON_UP: EvButtonUP(t); break;
case BITMAP_BUTTON_DP: EvButtonDP(t); break;
case BITMAP_BUTTON_LR: EvButtonLR(t); break;
case BITMAP_BUTTON_RR: EvButtonRR(t); break;
case BITMAP_BUTTON_UR: EvButtonUR(t); break;
case BITMAP_BUTTON_DR: EvButtonDR(t); break;
case BITMAP_BUTTON_BD: EvButtonBD(t); break;
case BITMAP_BUTTON_FD: EvButtonFD(t); break;
}
designdata->hiddenremove = h;
}
void TWinFrame::EvButtonZoom(void)
{
designdata->SelectZoom();
designdata->SelectParts(NULL);
designdata->Redraw();
}
void TWinFrame::EvButtonOk(void)
{
designdata->SelectParts(NULL);
designdata->Redraw();
}
void TWinFrame::EvButtonCancel(void)
{
designdata->CancelParts();
// designdata->Redraw();
}
void TWinFrame::EvTimer (UINT timerId)
{
TWindow::EvTimer(timerId);
// INSERT>> 追加コードはここに
KillTimer(0);
designdata->BuildWireFrame();
designdata->Redraw(SelPers);
#if 0
designdata->scrollX->SetPosition(designdata->displayoffset.x / scrollunit);
designdata->scrollY->SetPosition(designdata->displayoffset.y / scrollunit);
designdata->scrollZ->SetPosition(designdata->displayoffset.z / scrollunit);
designdata->Redraw(SelAll, TRUE);
KillTimer(0);
#endif
}